Skip to content

Commit afdb929

Browse files
committed
Improved how the number of uncommitted changes in a repository is fetched.
1 parent f12fa2a commit afdb929

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

src/dataSource.ts

+11-18
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export class DataSource implements vscode.Disposable {
142142
this.getRefs(repo, showRemoteBranches, hideRemotes).then((refData: GitRefData) => refData, (errorMessage: string) => errorMessage),
143143
this.getStashes(repo)
144144
]).then(async (results) => {
145-
let commits: GitCommitRecord[] = results[0], refData: GitRefData | string = results[1], stashes: GitStash[] = results[2], i, unsavedChanges = null;
145+
let commits: GitCommitRecord[] = results[0], refData: GitRefData | string = results[1], stashes: GitStash[] = results[2], i;
146146
let moreCommitsAvailable = commits.length === maxCommits + 1;
147147
if (moreCommitsAvailable) commits.pop();
148148

@@ -158,12 +158,12 @@ export class DataSource implements vscode.Disposable {
158158
}
159159
}
160160

161-
if (refData.head !== null) {
161+
if (refData.head !== null && config.showUncommittedChanges) {
162162
for (i = 0; i < commits.length; i++) {
163163
if (refData.head === commits[i].hash) {
164-
unsavedChanges = config.showUncommittedChanges ? await this.getUnsavedChanges(repo) : null;
165-
if (unsavedChanges !== null) {
166-
commits.unshift({ hash: UNCOMMITTED, parents: [refData.head], author: '*', email: '', date: Math.round((new Date()).getTime() / 1000), message: 'Uncommitted Changes (' + unsavedChanges.changes + ')' });
164+
const numUncommittedChanges = await this.getUncommittedChanges(repo);
165+
if (numUncommittedChanges > 0) {
166+
commits.unshift({ hash: UNCOMMITTED, parents: [refData.head], author: '*', email: '', date: Math.round((new Date()).getTime() / 1000), message: 'Uncommitted Changes (' + numUncommittedChanges + ')' });
167167
}
168168
break;
169169
}
@@ -1287,16 +1287,14 @@ export class DataSource implements vscode.Disposable {
12871287
}
12881288

12891289
/**
1290-
* Get the unsaved changes summary of a repository.
1290+
* Get the number of uncommitted changes in a repository.
12911291
* @param repo The path of the repository.
1292-
* @returns The unsaved changes summary.
1292+
* @returns The number of uncommitted changes.
12931293
*/
1294-
private getUnsavedChanges(repo: string) {
1295-
return this.spawnGit<GitUnsavedChanges | null>(['status', '-s', '--branch', '--untracked-files', '--porcelain'], repo, (stdout) => {
1296-
let lines = stdout.split(EOL_REGEX);
1297-
return lines.length > 2
1298-
? { branch: lines[0].substring(3).split('...')[0], changes: lines.length - 2 }
1299-
: null;
1294+
private getUncommittedChanges(repo: string) {
1295+
return this.spawnGit(['status', '--untracked-files', '--porcelain'], repo, (stdout) => {
1296+
const numLines = stdout.split(EOL_REGEX).length;
1297+
return numLines > 1 ? numLines - 1 : 0;
13001298
});
13011299
}
13021300

@@ -1625,8 +1623,3 @@ interface GitTagDetailsData {
16251623
message: string;
16261624
error: ErrorInfo;
16271625
}
1628-
1629-
interface GitUnsavedChanges {
1630-
branch: string;
1631-
changes: number;
1632-
}

0 commit comments

Comments
 (0)