Git - improve code that gets commit count (#201907)

This commit is contained in:
Ladislau Szomoru 2024-01-05 21:55:05 +01:00 committed by GitHub
parent b2809a8d3e
commit bff3ef7651
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View file

@ -2622,7 +2622,13 @@ export class Repository {
}
async getCommitCount(range: string): Promise<{ ahead: number; behind: number }> {
const result = await this.exec(['rev-list', '--count', '--left-right', range]);
const args = ['rev-list', '--count', '--left-right', range];
if (isWindows) {
args.splice(0, 0, '-c', 'core.longpaths=true');
}
const result = await this.exec(args);
const [ahead, behind] = result.stdout.trim().split('\t');
return { ahead: Number(ahead) || 0, behind: Number(behind) || 0 };

View file

@ -186,8 +186,14 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
return undefined;
}
const commitCount = await this.repository.getCommitCount(`${refId1}...${refId2}`);
return { id: ancestor, ahead: commitCount.ahead, behind: commitCount.behind };
try {
const commitCount = await this.repository.getCommitCount(`${refId1}...${refId2}`);
return { id: ancestor, ahead: commitCount.ahead, behind: commitCount.behind };
} catch (err) {
this.logger.error(`Failed to get ahead/behind for '${refId1}...${refId2}': ${err.message}`);
}
return undefined;
}
provideFileDecoration(uri: Uri): FileDecoration | undefined {