Skip to content

Commit 2b7e01b

Browse files
committed
Refactors Git provider into sub-providers
- Patch operations - Staging operations - Stash operations - Status operations - Worktree operations Adds GitCache to centralize the caching for the git providers
1 parent d0762e5 commit 2b7e01b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2020
-2031
lines changed

src/@types/global.d.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,28 @@ export declare global {
4040
: never;
4141

4242
export type UnwrapCustomEvent<T> = T extends CustomEvent<infer U> ? U : never;
43+
44+
export type RemoveFirstArg<F> = F extends {
45+
(first: any, ...args: infer A1): infer R1;
46+
(first: any, ...args: infer A2): infer R2;
47+
(first: any, ...args: infer A3): infer R3;
48+
(first: any, ...args: infer A4): infer R4;
49+
}
50+
? ((...args: A1) => R1) & ((...args: A2) => R2) & ((...args: A3) => R3) & ((...args: A4) => R4)
51+
: F extends {
52+
(first: any, ...args: infer A1): infer R1;
53+
(first: any, ...args: infer A2): infer R2;
54+
(first: any, ...args: infer A3): infer R3;
55+
}
56+
? ((...args: A1) => R1) & ((...args: A2) => R2) & ((...args: A3) => R3)
57+
: F extends {
58+
(first: any, ...args: infer A1): infer R1;
59+
(first: any, ...args: infer A2): infer R2;
60+
}
61+
? ((...args: A1) => R1) & ((...args: A2) => R2)
62+
: F extends {
63+
(first: any, ...args: infer A1): infer R1;
64+
}
65+
? (...args: A1) => R1
66+
: never;
4367
}

src/annotations/gutterChangesAnnotationProvider.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,9 @@ export class GutterChangesAnnotationProvider extends AnnotationProviderBase<Chan
131131
localChanges = false;
132132
}
133133
} else {
134-
const status = await this.container.git.getStatusForFile(
135-
this.trackedDocument.uri.repoPath!,
136-
this.trackedDocument.uri,
137-
);
134+
const status = await this.container.git
135+
.status(this.trackedDocument.uri.repoPath!)
136+
.getStatusForFile?.(this.trackedDocument.uri);
138137
const commits = status?.getPseudoCommits(
139138
this.container,
140139
await this.container.git.getCurrentUser(this.trackedDocument.uri.repoPath!),

src/commands/closeUnchangedFiles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class CloseUnchangedFilesCommand extends GlCommandBase {
2727
const repository = await getRepositoryOrShowPicker('Close All Unchanged Files');
2828
if (repository == null) return;
2929

30-
const status = await this.container.git.getStatus(repository.uri);
30+
const status = await this.container.git.status(repository.uri).getStatus();
3131
if (status == null) {
3232
void window.showWarningMessage('Unable to close unchanged files');
3333

src/commands/diffLineWithWorking.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class DiffLineWithWorkingCommand extends ActiveEditorCommand {
6363

6464
// If the line is uncommitted, use previous commit (or index if the file is staged)
6565
if (args.commit.isUncommitted) {
66-
const status = await this.container.git.getStatusForFile(gitUri.repoPath!, gitUri);
66+
const status = await this.container.git.status(gitUri.repoPath!).getStatusForFile?.(gitUri);
6767
if (status?.indexStatus != null) {
6868
lhsSha = uncommittedStaged;
6969
lhsUri = this.container.git.getAbsoluteUri(

src/commands/diffWithRevision.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand {
6161
getState: async () => {
6262
const items: (CommandQuickPickItem | DirectiveQuickPickItem)[] = [];
6363

64-
const status = await this.container.git.getStatus(gitUri.repoPath);
64+
const status = await this.container.git.status(gitUri.repoPath!).getStatus();
6565
if (status != null) {
6666
for (const f of status.files) {
6767
if (f.workingTreeStatus === '?' || f.workingTreeStatus === '!') {

src/commands/diffWithRevisionFrom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class DiffWithRevisionFromCommand extends ActiveEditorCommand {
4949
if (args?.stash) {
5050
const title = `Open Changes with Stash${pad(GlyphChars.Dot, 2, 2)}`;
5151
const pick = await showStashPicker(
52-
this.container.git.getStash(gitUri.repoPath),
52+
this.container.git.stash(gitUri.repoPath)?.getStash(),
5353
`${title}${gitUri.getFormattedFileName({ truncateTo: quickPickTitleMaxChars - title.length })}`,
5454
'Choose a stash to compare with',
5555
{

src/commands/diffWithWorking.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand {
7676

7777
// If we are a fake "staged" sha, check the status
7878
if (gitUri.isUncommittedStaged) {
79-
const status = await this.container.git.getStatusForFile(gitUri.repoPath!, gitUri);
79+
const status = await this.container.git.status(gitUri.repoPath!).getStatusForFile?.(gitUri);
8080
if (status?.indexStatus != null) {
8181
void (await executeCommand<DiffWithCommandArgs>(GlCommand.DiffWith, {
8282
repoPath: gitUri.repoPath,

src/commands/externalDiff.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class ExternalDiffCommand extends GlCommandBase {
8888
const repository = await getRepositoryOrShowPicker('Open All Changes (difftool)');
8989
if (repository == null) return undefined;
9090

91-
const status = await this.container.git.getStatus(repository.uri);
91+
const status = await this.container.git.status(repository.uri).getStatus();
9292
if (status == null) {
9393
return window.showInformationMessage("The repository doesn't have any changes");
9494
}
@@ -130,7 +130,7 @@ export class ExternalDiffCommand extends GlCommandBase {
130130
if (!repoPath) return;
131131

132132
const uri = editor.document.uri;
133-
const status = await this.container.git.getStatusForFile(repoPath, uri);
133+
const status = await this.container.git.status(repoPath).getStatusForFile?.(uri);
134134
if (status == null) {
135135
void window.showInformationMessage("The current file doesn't have any changes");
136136

src/commands/git/pull.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export class PullGitCommand extends QuickCommand<State> {
193193
}
194194
} else {
195195
const [repo] = state.repos;
196-
const [status, lastFetched] = await Promise.all([repo.git.getStatus(), repo.getLastFetched()]);
196+
const [status, lastFetched] = await Promise.all([repo.git.status().getStatus(), repo.getLastFetched()]);
197197

198198
let lastFetchedOn = '';
199199
if (lastFetched !== 0) {

src/commands/git/push.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ export class PushGitCommand extends QuickCommand<State> {
294294
}
295295
}
296296
} else {
297-
const status = await repo.git.getStatus();
297+
const status = await repo.git.status().getStatus();
298298

299299
const branch: GitBranchReference = {
300300
refType: 'branch',

0 commit comments

Comments
 (0)