Skip to content

Commit 697536e

Browse files
committed
Fixes GRaph paging issue w/ same timestamps
1 parent 1661a28 commit 697536e

File tree

1 file changed

+55
-38
lines changed

1 file changed

+55
-38
lines changed

src/env/node/git/localGitProvider.ts

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,49 +2578,66 @@ export class LocalGitProvider implements GitProvider, Disposable {
25782578
// Git only allows 1-second precision, so round up to the nearest second
25792579
timestamp = date != null ? Math.ceil(date.getTime() / 1000) + 1 : undefined;
25802580
}
2581-
const moreLog = await this.getLog(log.repoPath, {
2582-
...options,
2583-
limit: moreUntil == null ? moreLimit : 0,
2584-
...(timestamp
2585-
? {
2586-
until: timestamp,
2587-
extraArgs: ['--boundary'],
2588-
}
2589-
: { ref: moreUntil == null ? `${ref}^` : `${moreUntil}^..${ref}^` }),
2590-
});
2591-
// If we can't find any more, assume we have everything
2592-
if (moreLog == null) return { ...log, hasMore: false, more: undefined };
25932581

2594-
if (timestamp != null && ref != null && !moreLog.commits.has(ref)) {
2595-
debugger;
2596-
}
2582+
let moreLogCount;
2583+
let queryLimit = moreUntil == null ? moreLimit : 0;
2584+
do {
2585+
const moreLog = await this.getLog(log.repoPath, {
2586+
...options,
2587+
limit: queryLimit,
2588+
...(timestamp
2589+
? {
2590+
until: timestamp,
2591+
extraArgs: ['--boundary'],
2592+
}
2593+
: { ref: moreUntil == null ? `${ref}^` : `${moreUntil}^..${ref}^` }),
2594+
});
2595+
// If we can't find any more, assume we have everything
2596+
if (moreLog == null) return { ...log, hasMore: false, more: undefined };
25972597

2598-
const commits = new Map([...log.commits, ...moreLog.commits]);
2598+
const currentCount = log.commits.size;
2599+
const commits = new Map([...log.commits, ...moreLog.commits]);
25992600

2600-
const mergedLog: GitLog = {
2601-
repoPath: log.repoPath,
2602-
commits: commits,
2603-
sha: log.sha,
2604-
range: undefined,
2605-
count: commits.size,
2606-
limit: moreUntil == null ? (log.limit ?? 0) + moreLimit : undefined,
2607-
hasMore: moreUntil == null ? moreLog.hasMore : true,
2608-
startingCursor: last(log.commits)?.[0],
2609-
endingCursor: moreLog.endingCursor,
2610-
pagedCommits: () => {
2611-
// Remove any duplicates
2612-
for (const sha of log.commits.keys()) {
2613-
moreLog.commits.delete(sha);
2601+
if (currentCount === commits.size && queryLimit !== 0) {
2602+
// If we didn't find any new commits, we must have them all so return that we have everything
2603+
if (moreLogCount === moreLog.commits.size) {
2604+
return { ...log, hasMore: false, more: undefined };
26142605
}
2615-
return moreLog.commits;
2616-
},
2617-
query: (limit: number | undefined) => this.getLog(log.repoPath, { ...options, limit: limit }),
2618-
};
2619-
if (mergedLog.hasMore) {
2620-
mergedLog.more = this.getLogMoreFn(mergedLog, options);
2621-
}
26222606

2623-
return mergedLog;
2607+
moreLogCount = moreLog.commits.size;
2608+
queryLimit = queryLimit * 2;
2609+
continue;
2610+
}
2611+
2612+
if (timestamp != null && ref != null && !moreLog.commits.has(ref)) {
2613+
debugger;
2614+
}
2615+
2616+
const mergedLog: GitLog = {
2617+
repoPath: log.repoPath,
2618+
commits: commits,
2619+
sha: log.sha,
2620+
range: undefined,
2621+
count: commits.size,
2622+
limit: moreUntil == null ? (log.limit ?? 0) + moreLimit : undefined,
2623+
hasMore: moreUntil == null ? moreLog.hasMore : true,
2624+
startingCursor: last(log.commits)?.[0],
2625+
endingCursor: moreLog.endingCursor,
2626+
pagedCommits: () => {
2627+
// Remove any duplicates
2628+
for (const sha of log.commits.keys()) {
2629+
moreLog.commits.delete(sha);
2630+
}
2631+
return moreLog.commits;
2632+
},
2633+
query: (limit: number | undefined) => this.getLog(log.repoPath, { ...options, limit: limit }),
2634+
};
2635+
if (mergedLog.hasMore) {
2636+
mergedLog.more = this.getLogMoreFn(mergedLog, options);
2637+
}
2638+
2639+
return mergedLog;
2640+
} while (true);
26242641
};
26252642
}
26262643

0 commit comments

Comments
 (0)