Skip to content

Commit a07e85f

Browse files
committed
Increases threshold to avoid extra queries
Adds extra HEAD check to avoid extra lookup
1 parent f2daa11 commit a07e85f

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/env/node/git/git.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,11 @@ export class Git {
12101210
return result;
12111211
}
12121212

1213+
async rev_parse(repoPath: string, ref: string): Promise<string | undefined> {
1214+
const data = await this.git<string>({ cwd: repoPath, errors: GitErrorHandling.Ignore }, 'rev-parse', ref);
1215+
return data.length === 0 ? undefined : data.trim();
1216+
}
1217+
12131218
async rev_parse__currentBranch(
12141219
repoPath: string,
12151220
ordering: 'date' | 'author-date' | 'topo' | null,

src/env/node/git/localGitProvider.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,8 +1614,13 @@ export class LocalGitProvider implements GitProvider, Disposable {
16141614

16151615
let stdin: string | undefined;
16161616

1617-
// // TODO@eamodio this is insanity -- there *HAS* to be a better way to get git log to return stashes
1618-
const stash = await this.getStash(repoPath);
1617+
const [stashResult, headResult] = await Promise.allSettled([
1618+
this.getStash(repoPath),
1619+
options?.ref != null && options.ref !== 'HEAD' ? this.git.rev_parse(repoPath, 'HEAD') : undefined,
1620+
]);
1621+
1622+
// TODO@eamodio this is insanity -- there *HAS* to be a better way to get git log to return stashes
1623+
const stash = getSettledValue(stashResult);
16191624
if (stash != null) {
16201625
stdin = join(
16211626
map(stash.commits.values(), c => c.sha.substring(0, 9)),
@@ -1625,6 +1630,8 @@ export class LocalGitProvider implements GitProvider, Disposable {
16251630

16261631
let getLogForRefFn;
16271632
if (options?.ref != null) {
1633+
const head = getSettledValue(headResult);
1634+
16281635
async function getLogForRef(this: LocalGitProvider): Promise<GitLog | undefined> {
16291636
let log;
16301637

@@ -1637,7 +1644,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
16371644

16381645
let found = false;
16391646
// If we are looking for the HEAD assume that it might be in the first page (so we can avoid extra queries)
1640-
if (options!.ref === 'HEAD') {
1647+
if (options!.ref === 'HEAD' || options!.ref === head) {
16411648
log = await this.getLog(repoPath, {
16421649
all: options!.mode !== 'single',
16431650
ordering: 'date',
@@ -1665,11 +1672,11 @@ export class LocalGitProvider implements GitProvider, Disposable {
16651672
debugger;
16661673
}
16671674

1668-
if (log?.more != null && (!found || log.commits.size < defaultItemLimit)) {
1675+
if (log?.more != null && (!found || log.commits.size < defaultItemLimit / 2)) {
16691676
Logger.debug(scope, 'Loading next page...');
16701677

16711678
log = await log.more(
1672-
(log.commits.size < defaultItemLimit
1679+
(found && log.commits.size < defaultItemLimit / 2
16731680
? defaultItemLimit
16741681
: configuration.get('graph.pageItemLimit')) ?? options?.limit,
16751682
);

0 commit comments

Comments
 (0)