Skip to content

Commit 75103e3

Browse files
committed
Improves perf on getting single file status
1 parent fc3f0cf commit 75103e3

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/env/node/git/git.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,6 +2197,7 @@ export class Git {
21972197
repoPath: string,
21982198
porcelainVersion: number = 1,
21992199
options?: { similarityThreshold?: number },
2200+
...pathspecs: string[]
22002201
): Promise<string> {
22012202
const params = [
22022203
'status',
@@ -2214,6 +2215,7 @@ export class Git {
22142215
{ cwd: repoPath, configs: gitStatusDefaultConfigs, env: { GIT_OPTIONAL_LOCKS: '0' } },
22152216
...params,
22162217
'--',
2218+
...pathspecs,
22172219
);
22182220
}
22192221

src/env/node/git/sub-providers/status.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -494,27 +494,27 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
494494
@gate()
495495
@log()
496496
async getStatusForFile(repoPath: string, pathOrUri: string | Uri): Promise<GitStatusFile | undefined> {
497-
const status = await this.getStatus(repoPath);
498-
if (!status?.files.length) return undefined;
499-
500-
const [relativePath] = splitPath(pathOrUri, repoPath);
501-
const file = status.files.find(f => f.path === relativePath);
502-
return file;
497+
const files = await this.getStatusForFiles(repoPath, pathOrUri);
498+
return files?.[0];
503499
}
504500

505501
@gate()
506502
@log()
507-
async getStatusForFiles(repoPath: string, pathOrGlob: Uri): Promise<GitStatusFile[] | undefined> {
508-
let [relativePath] = splitPath(pathOrGlob, repoPath);
509-
if (!relativePath.endsWith('/*')) {
510-
return this.getStatusForFile(repoPath, pathOrGlob).then(f => (f != null ? [f] : undefined));
511-
}
503+
async getStatusForFiles(repoPath: string, pathOrGlob: string | Uri): Promise<GitStatusFile[] | undefined> {
504+
const [relativePath] = splitPath(pathOrGlob, repoPath);
512505

513-
relativePath = relativePath.substring(0, relativePath.length - 1);
514-
const status = await this.getStatus(repoPath);
515-
if (!status?.files.length) return undefined;
506+
const porcelainVersion = (await this.git.isAtLeastVersion('2.11')) ? 2 : 1;
516507

517-
const files = status.files.filter(f => f.path.startsWith(relativePath));
518-
return files;
508+
const data = await this.git.status(
509+
repoPath,
510+
porcelainVersion,
511+
{
512+
similarityThreshold: configuration.get('advanced.similarityThreshold') ?? undefined,
513+
},
514+
relativePath,
515+
);
516+
517+
const status = parseGitStatus(this.container, data, repoPath, porcelainVersion);
518+
return status?.files;
519519
}
520520
}

0 commit comments

Comments
 (0)