Skip to content

Commit d74f444

Browse files
committed
Refactors Git provider into sub-providers
- Config operations - Diff operations - Ref operations
1 parent a827093 commit d74f444

Some content is hidden

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

56 files changed

+1726
-1767
lines changed

src/ai/aiProviderService.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,10 @@ export class AIProviderService implements Disposable {
559559
} else if (Array.isArray(changesOrRepo)) {
560560
changes = changesOrRepo.join('\n');
561561
} else {
562-
let diff = await this.container.git.getDiff(changesOrRepo.uri, uncommittedStaged);
562+
const diffProvider = this.container.git.diff(changesOrRepo.uri);
563+
let diff = await diffProvider.getDiff?.(uncommittedStaged);
563564
if (!diff?.contents) {
564-
diff = await this.container.git.getDiff(changesOrRepo.uri, uncommitted);
565+
diff = await diffProvider.getDiff?.(uncommitted);
565566
if (!diff?.contents) throw new Error('No changes to generate a commit message from.');
566567
}
567568
if (options?.cancellation?.isCancellationRequested) return undefined;
@@ -577,7 +578,7 @@ export class AIProviderService implements Disposable {
577578
sourceContext: { source: Sources; type: TelemetryEvents['ai/explain']['changeType'] },
578579
options?: { cancellation?: CancellationToken; progress?: ProgressOptions },
579580
): Promise<AIResult | undefined> {
580-
const diff = await this.container.git.getDiff(commitOrRevision.repoPath, commitOrRevision.ref);
581+
const diff = await this.container.git.diff(commitOrRevision.repoPath).getDiff?.(commitOrRevision.ref);
581582
if (!diff?.contents) throw new Error('No changes found to explain.');
582583

583584
const { confirmed, model } = await getModelAndConfirmAIProviderToS('diff', this, this.container.storage);

src/annotations/gutterChangesAnnotationProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export class GutterChangesAnnotationProvider extends AnnotationProviderBase<Chan
131131
.getStatusForFile?.(this.trackedDocument.uri);
132132
const commits = status?.getPseudoCommits(
133133
this.container,
134-
await this.container.git.getCurrentUser(this.trackedDocument.uri.repoPath!),
134+
await this.container.git.config(this.trackedDocument.uri.repoPath!).getCurrentUser(),
135135
);
136136
if (commits?.length) {
137137
commit = await commitsProvider.getCommitForFile(this.trackedDocument.uri);

src/commands/browseRepoAtRevision.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class BrowseRepoAtRevisionCommand extends ActiveEditorCommand {
6060
if (gitUri.sha == null) return;
6161

6262
const sha = args?.before
63-
? await this.container.git.resolveReference(gitUri.repoPath!, `${gitUri.sha}^`)
63+
? await this.container.git.refs(gitUri.repoPath!).resolveReference(`${gitUri.sha}^`)
6464
: gitUri.sha;
6565
uri = this.container.git.getRevisionUri(sha, gitUri.repoPath!, gitUri.repoPath!);
6666
gitUri = GitUri.fromRevisionUri(uri);

src/commands/diffLineWithPrevious.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,9 @@ export class DiffLineWithPreviousCommand extends ActiveEditorCommand {
4444
const gitUri = args.commit?.getGitUri() ?? (await GitUri.fromUri(uri));
4545

4646
try {
47-
const diffUris = await this.container.git.getPreviousComparisonUrisForLine(
48-
gitUri.repoPath!,
49-
gitUri,
50-
args.line,
51-
gitUri.sha,
52-
);
47+
const diffUris = await this.container.git
48+
.diff(gitUri.repoPath!)
49+
.getPreviousComparisonUrisForLine(gitUri, args.line, gitUri.sha);
5350

5451
if (diffUris?.previous == null) {
5552
void showCommitHasNoPreviousCommitWarningMessage();

src/commands/diffWith.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ export class DiffWithCommand extends GlCommandBase {
9999
let rhsSha = args.rhs.sha;
100100

101101
[args.lhs.sha, args.rhs.sha] = await Promise.all([
102-
await this.container.git.resolveReference(args.repoPath, args.lhs.sha, args.lhs.uri, {
102+
await this.container.git.refs(args.repoPath).resolveReference(args.lhs.sha, args.lhs.uri, {
103103
// If the ref looks like a sha, don't wait too long, since it should work
104104
timeout: isShaLike(args.lhs.sha) ? 100 : undefined,
105105
}),
106-
await this.container.git.resolveReference(args.repoPath, args.rhs.sha, args.rhs.uri, {
106+
await this.container.git.refs(args.repoPath).resolveReference(args.rhs.sha, args.rhs.uri, {
107107
// If the ref looks like a sha, don't wait too long, since it should work
108108
timeout: isShaLike(args.rhs.sha) ? 100 : undefined,
109109
}),

src/commands/diffWithNext.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ export class DiffWithNextCommand extends ActiveEditorCommand {
4545

4646
const gitUri = args.commit?.getGitUri() ?? (await GitUri.fromUri(uri));
4747
try {
48-
const diffUris = await this.container.git.getNextComparisonUris(
49-
gitUri.repoPath!,
48+
const diffUris = await this.container.git.diff(gitUri.repoPath!).getNextComparisonUris(
5049
gitUri,
5150
gitUri.sha,
5251
// If we are in the left-side of the diff editor, we need to skip forward 1 more revision

src/commands/diffWithPrevious.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand {
8585
// }
8686

8787
try {
88-
const diffUris = await this.container.git.getPreviousComparisonUris(
89-
gitUri.repoPath!,
88+
const diffUris = await this.container.git.diff(gitUri.repoPath!).getPreviousComparisonUris(
9089
gitUri,
9190
gitUri.sha,
9291
// If we are in the right-side of the diff editor, we need to skip back 1 more revision

src/commands/diffWithRevisionFrom.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ export class DiffWithRevisionFromCommand extends ActiveEditorCommand {
8585
let renamedTitle: string | undefined;
8686

8787
// Check to see if this file has been renamed
88-
const files = await this.container.git.getDiffStatus(gitUri.repoPath, 'HEAD', ref, { filters: ['R', 'C'] });
88+
const files = await this.container.git
89+
.diff(gitUri.repoPath)
90+
.getDiffStatus('HEAD', ref, { filters: ['R', 'C'] });
8991
if (files != null) {
9092
const rename = files.find(s => s.path === path);
9193
if (rename?.originalPath != null) {

src/commands/diffWithWorking.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand {
4545

4646
if (args.inDiffRightEditor) {
4747
try {
48-
const diffUris = await this.container.git.getPreviousComparisonUris(
49-
gitUri.repoPath!,
50-
gitUri,
51-
gitUri.sha,
52-
);
48+
const diffUris = await this.container.git
49+
.diff(gitUri.repoPath!)
50+
.getPreviousComparisonUris(gitUri, gitUri.sha);
5351
gitUri = diffUris?.previous ?? gitUri;
5452
} catch (ex) {
5553
Logger.error(

src/commands/externalDiff.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ export class ExternalDiffCommand extends GlCommandBase {
151151
}
152152

153153
const tool =
154-
configuration.get('advanced.externalDiffTool') || (await this.container.git.getDiffTool(repoPath));
154+
configuration.get('advanced.externalDiffTool') ||
155+
(await this.container.git.diff(repoPath).getDiffTool?.());
155156
if (!tool) {
156157
const viewDocs = 'View Git Docs';
157158
const result = await window.showWarningMessage(
@@ -168,7 +169,7 @@ export class ExternalDiffCommand extends GlCommandBase {
168169
}
169170

170171
for (const file of args.files) {
171-
void this.container.git.openDiffTool(repoPath, file.uri, {
172+
void this.container.git.diff(repoPath).openDiffTool?.(file.uri, {
172173
ref1: file.ref1,
173174
ref2: file.ref2,
174175
staged: file.staged,

0 commit comments

Comments
 (0)