Skip to content

Commit 3566927

Browse files
committed
Refactors Git provider into sub-providers
- Commit operations
1 parent 1f93828 commit 3566927

Some content is hidden

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

62 files changed

+1899
-2046
lines changed

src/ai/aiProviderService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ export class AIProviderService implements Disposable {
436436

437437
const commit = isCommit(commitOrRevision)
438438
? commitOrRevision
439-
: await this.container.git.getCommit(commitOrRevision.repoPath, commitOrRevision.ref);
439+
: await this.container.git.commits(commitOrRevision.repoPath).getCommit(commitOrRevision.ref);
440440
if (commit == null) throw new Error('Unable to find commit');
441441

442442
if (!commit.hasFullDetails()) {

src/annotations/gutterChangesAnnotationProvider.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,14 @@ export class GutterChangesAnnotationProvider extends AnnotationProviderBase<Chan
107107

108108
let commit: GitCommit | undefined;
109109

110+
const commitsProvider = this.container.git.commits(this.trackedDocument.uri.repoPath!);
111+
110112
let localChanges = ref1 == null && ref2 == null;
111113
if (localChanges) {
112-
let ref = await this.container.git.getOldestUnpushedRefForFile(
113-
this.trackedDocument.uri.repoPath!,
114-
this.trackedDocument.uri,
115-
);
114+
let ref = await commitsProvider.getOldestUnpushedRefForFile(this.trackedDocument.uri);
116115
if (ref != null) {
117116
ref = `${ref}^`;
118-
commit = await this.container.git.getCommitForFile(
119-
this.trackedDocument.uri.repoPath,
120-
this.trackedDocument.uri,
121-
{ ref: ref },
122-
);
117+
commit = await commitsProvider.getCommitForFile(this.trackedDocument.uri, { ref: ref });
123118
if (commit != null) {
124119
if (ref2 != null) {
125120
ref2 = ref;
@@ -139,10 +134,7 @@ export class GutterChangesAnnotationProvider extends AnnotationProviderBase<Chan
139134
await this.container.git.getCurrentUser(this.trackedDocument.uri.repoPath!),
140135
);
141136
if (commits?.length) {
142-
commit = await this.container.git.getCommitForFile(
143-
this.trackedDocument.uri.repoPath,
144-
this.trackedDocument.uri,
145-
);
137+
commit = await commitsProvider.getCommitForFile(this.trackedDocument.uri);
146138
ref1 = 'HEAD';
147139
} else if (this.trackedDocument.dirty) {
148140
ref1 = 'HEAD';
@@ -153,13 +145,7 @@ export class GutterChangesAnnotationProvider extends AnnotationProviderBase<Chan
153145
}
154146

155147
if (!localChanges) {
156-
commit = await this.container.git.getCommitForFile(
157-
this.trackedDocument.uri.repoPath,
158-
this.trackedDocument.uri,
159-
{
160-
ref: ref2 ?? ref1,
161-
},
162-
);
148+
commit = await commitsProvider.getCommitForFile(this.trackedDocument.uri, { ref: ref2 ?? ref1 });
163149

164150
if (commit != null) {
165151
if (ref2 != null) {

src/commands/copyMessageToClipboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand {
7373
repoPath = this.container.git.getBestRepository(editor)?.path;
7474
if (!repoPath) return;
7575

76-
const log = await this.container.git.getLog(repoPath, { limit: 1 });
76+
const log = await this.container.git.commits(repoPath).getLog({ limit: 1 });
7777
if (log == null) return;
7878

7979
const commit = first(log.commits.values());

src/commands/copyShaToClipboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class CopyShaToClipboardCommand extends ActiveEditorCommand {
6161
const repoPath = this.container.git.getBestRepository(editor)?.path;
6262
if (!repoPath) return;
6363

64-
const log = await this.container.git.getLog(repoPath, { limit: 1 });
64+
const log = await this.container.git.commits(repoPath).getLog({ limit: 1 });
6565
if (log == null) return;
6666

6767
args.sha = first(log.commits.values())?.sha;

src/commands/diffFolderWithRevision.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,13 @@ export class DiffFolderWithRevisionCommand extends ActiveEditorCommand {
4848
?.path;
4949
if (!repoPath) return;
5050

51-
const log = this.container.git
52-
.getLogForFile(gitUri.repoPath, gitUri.fsPath)
51+
const commitsProvider = this.container.git.commits(repoPath);
52+
const log = commitsProvider
53+
.getLogForFile(gitUri.fsPath)
5354
.then(
5455
log =>
5556
log ??
56-
(gitUri.sha
57-
? this.container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { ref: gitUri.sha })
58-
: undefined),
57+
(gitUri.sha ? commitsProvider.getLogForFile(gitUri.fsPath, { ref: gitUri.sha }) : undefined),
5958
);
6059

6160
const relativePath = this.container.git.getRelativePath(uri, repoPath);

src/commands/diffWith.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,9 @@ export class DiffWithCommand extends GlCommandBase {
115115

116116
if (args.rhs.sha && args.rhs.sha !== deletedOrMissing) {
117117
// Ensure that the file still exists in this commit
118-
const status = await this.container.git.getFileStatusForCommit(
119-
args.repoPath,
120-
args.rhs.uri,
121-
args.rhs.sha,
122-
);
118+
const status = await this.container.git
119+
.commits(args.repoPath)
120+
.getFileStatusForCommit(args.rhs.uri, args.rhs.sha);
123121
if (status?.status === 'D') {
124122
args.rhs.sha = deletedOrMissing;
125123
} else {

src/commands/diffWithRevision.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,13 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand {
4141
}
4242

4343
try {
44-
const log = this.container.git
45-
.getLogForFile(gitUri.repoPath, gitUri.fsPath)
44+
const commitsProvider = this.container.git.commits(gitUri.repoPath!);
45+
const log = commitsProvider
46+
.getLogForFile(gitUri.fsPath)
4647
.then(
4748
log =>
4849
log ??
49-
(gitUri.sha
50-
? this.container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { ref: gitUri.sha })
51-
: undefined),
50+
(gitUri.sha ? commitsProvider.getLogForFile(gitUri.fsPath, { ref: gitUri.sha }) : undefined),
5251
);
5352

5453
const title = `Open Changes with Revision${pad(GlyphChars.Dot, 2, 2)}`;

src/commands/git/cherry-pick.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export class CherryPickGitCommand extends QuickCommand<State> {
191191

192192
let log = context.cache.get(ref);
193193
if (log == null) {
194-
log = this.container.git.getLog(state.repo.path, { ref: ref, merges: 'first-parent' });
194+
log = state.repo.git.commits().getLog({ ref: ref, merges: 'first-parent' });
195195
context.cache.set(ref, log);
196196
}
197197

src/commands/git/log.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ export class LogGitCommand extends QuickCommand<State> {
164164
if (log == null) {
165165
log =
166166
state.fileName != null
167-
? this.container.git.getLogForFile(state.repo.path, state.fileName, { ref: ref })
168-
: this.container.git.getLog(state.repo.path, { ref: ref });
167+
? state.repo.git.commits().getLogForFile(state.fileName, { ref: ref })
168+
: state.repo.git.commits().getLog({ ref: ref });
169169
context.cache.set(ref, log);
170170
}
171171

@@ -187,7 +187,7 @@ export class LogGitCommand extends QuickCommand<State> {
187187
}
188188

189189
if (!(state.reference instanceof GitCommit) || state.reference.file != null) {
190-
state.reference = await this.container.git.getCommit(state.repo.path, state.reference.ref);
190+
state.reference = await state.repo.git.commits().getCommit(state.reference.ref);
191191
}
192192

193193
let result: StepResult<ReturnType<typeof getSteps>>;

src/commands/git/merge.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export class MergeGitCommand extends QuickCommand<State> {
175175

176176
let log = context.cache.get(ref);
177177
if (log == null) {
178-
log = this.container.git.getLog(state.repo.path, { ref: ref, merges: 'first-parent' });
178+
log = state.repo.git.commits().getLog({ ref: ref, merges: 'first-parent' });
179179
context.cache.set(ref, log);
180180
}
181181

@@ -211,10 +211,9 @@ export class MergeGitCommand extends QuickCommand<State> {
211211
}
212212

213213
private async *confirmStep(state: MergeStepState, context: Context): AsyncStepResultGenerator<Flags[]> {
214-
const counts = await this.container.git.getLeftRightCommitCount(
215-
state.repo.path,
216-
createRevisionRange(context.destination.ref, state.reference.ref, '...'),
217-
);
214+
const counts = await state.repo.git
215+
.commits()
216+
.getLeftRightCommitCount(createRevisionRange(context.destination.ref, state.reference.ref, '...'));
218217

219218
const title = `Merge ${getReferenceLabel(state.reference, {
220219
icon: false,

0 commit comments

Comments
 (0)