Skip to content

Commit 4caf714

Browse files
KebanFiruCopilot
andcommitted
Refactor contributor stats retrieval to include full commit history and count changes for removed or renamed files
Co-authored-by: Copilot <copilot@github.com>
1 parent d63328b commit 4caf714

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

src/services/StatsService.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -522,12 +522,12 @@ export class StatsService {
522522
private async getContributorStatsFromGit(rootPath: string): Promise<ContributorStat[]> {
523523
// Use author email as the aggregation key to avoid duplicate names
524524
const output = await this.execGit(
525-
['log', 'HEAD', '--first-parent', '--numstat', `--pretty=${GIT_AUTHOR_PREFIX}%an|%aE`],
525+
// Include full history reachable from HEAD (include merges)
526+
['log', 'HEAD', '--numstat', `--pretty=${GIT_AUTHOR_PREFIX}%an|%aE`],
526527
rootPath
527528
);
528529

529530
const stats = new Map<string, { name: string; added: number; deleted: number }>();
530-
const existsCache = new Map<string, boolean>();
531531
let currentKey = 'unknown';
532532
let currentName = 'Unknown';
533533
const lines = output.split(/\r?\n/);
@@ -556,12 +556,8 @@ export class StatsService {
556556
continue;
557557
}
558558

559+
// Count changes even if the file no longer exists in the working tree
559560
const normalizedPath = this.normalizeGitPath(filePath);
560-
const exists = await this.fileExists(rootPath, normalizedPath, existsCache);
561-
if (!exists) {
562-
continue;
563-
}
564-
565561
const added = Number(addedText);
566562
const deleted = Number(deletedText ?? 0);
567563
if (Number.isNaN(added) || Number.isNaN(deleted)) {
@@ -624,6 +620,7 @@ export class StatsService {
624620
continue;
625621
}
626622

623+
// Count changes even when files have been removed or renamed
627624
const current = stats.get(currentKey) ?? { name: currentName, added: 0, deleted: 0 };
628625
current.added += added;
629626
current.deleted += deleted;
@@ -643,7 +640,8 @@ export class StatsService {
643640
): Promise<ContributorLanguageStat[]> {
644641
// Include author email so we can match by name or email when authorName may be an email
645642
const output = await this.execGit(
646-
['log', 'HEAD', '--first-parent', '--numstat', `--pretty=${GIT_AUTHOR_PREFIX}%an|%aE`],
643+
// Include full history reachable from HEAD (include merges)
644+
['log', 'HEAD', '--numstat', `--pretty=${GIT_AUTHOR_PREFIX}%an|%aE`],
647645
rootPath
648646
);
649647

@@ -704,7 +702,7 @@ export class StatsService {
704702
): Promise<ContributorFileStat[]> {
705703
// Include author email so we can match by name or email when authorName may be an email
706704
const output = await this.execGit(
707-
['log', 'HEAD', '--first-parent', '--numstat', `--pretty=${GIT_AUTHOR_PREFIX}%an|%aE`],
705+
['log', 'HEAD', '--numstat', `--pretty=${GIT_AUTHOR_PREFIX}%an|%aE`],
708706
rootPath
709707
);
710708

0 commit comments

Comments
 (0)