Skip to content

Commit 5f7cecc

Browse files
committed
Adds new GitRepositoryService
- Scoped version of GitProviderService - Replaces multiple proxies for better caching & perf
1 parent 4c4a5da commit 5f7cecc

File tree

160 files changed

+1402
-1412
lines changed

Some content is hidden

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

160 files changed

+1402
-1412
lines changed

src/annotations/gutterBlameAnnotationProvider.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ export class GutterBlameAnnotationProvider extends BlameAnnotationProviderBase {
7171

7272
let getBranchAndTagTips;
7373
if (CommitFormatter.has(cfg.format, 'tips')) {
74-
getBranchAndTagTips = await this.container.git.getBranchesAndTagsTipsLookup(blame.repoPath);
74+
getBranchAndTagTips = await this.container.git
75+
.getRepositoryService(blame.repoPath)
76+
.getBranchesAndTagsTipsLookup();
7577
}
7678

7779
const options: CommitFormatOptions = {

src/annotations/gutterChangesAnnotationProvider.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +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!);
110+
const svc = this.container.git.getRepositoryService(this.trackedDocument.uri.repoPath!);
111111

112112
let localChanges = rev1 == null && rev2 == null;
113113
if (localChanges) {
114-
let rev = await commitsProvider.getOldestUnpushedShaForPath(this.trackedDocument.uri);
114+
let rev = await svc.commits.getOldestUnpushedShaForPath(this.trackedDocument.uri);
115115
if (rev != null) {
116116
rev = `${rev}^`;
117-
commit = await commitsProvider.getCommitForFile(this.trackedDocument.uri, rev);
117+
commit = await svc.commits.getCommitForFile(this.trackedDocument.uri, rev);
118118
if (commit != null) {
119119
if (rev2 != null) {
120120
rev2 = rev;
@@ -126,15 +126,10 @@ export class GutterChangesAnnotationProvider extends AnnotationProviderBase<Chan
126126
localChanges = false;
127127
}
128128
} else {
129-
const status = await this.container.git
130-
.status(this.trackedDocument.uri.repoPath!)
131-
.getStatusForFile?.(this.trackedDocument.uri);
132-
const commits = status?.getPseudoCommits(
133-
this.container,
134-
await this.container.git.config(this.trackedDocument.uri.repoPath!).getCurrentUser(),
135-
);
129+
const status = await svc.status.getStatusForFile?.(this.trackedDocument.uri);
130+
const commits = status?.getPseudoCommits(this.container, await svc.config.getCurrentUser());
136131
if (commits?.length) {
137-
commit = await commitsProvider.getCommitForFile(this.trackedDocument.uri);
132+
commit = await svc.commits.getCommitForFile(this.trackedDocument.uri);
138133
rev1 = 'HEAD';
139134
} else if (this.trackedDocument.dirty) {
140135
rev1 = 'HEAD';
@@ -145,7 +140,7 @@ export class GutterChangesAnnotationProvider extends AnnotationProviderBase<Chan
145140
}
146141

147142
if (!localChanges) {
148-
commit = await commitsProvider.getCommitForFile(this.trackedDocument.uri, rev2 ?? rev1);
143+
commit = await svc.commits.getCommitForFile(this.trackedDocument.uri, rev2 ?? rev1);
149144

150145
if (commit != null) {
151146
if (rev2 != null) {

src/annotations/lineAnnotationController.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export class LineAnnotationController implements Disposable {
157157
const prs = new Map<string, Promise<PullRequest | undefined>>();
158158
if (lines.size === 0) return prs;
159159

160-
const remotePromise = this.container.git.remotes(repoPath).getBestRemoteWithIntegration();
160+
const remotePromise = this.container.git.getRepositoryService(repoPath).remotes.getBestRemoteWithIntegration();
161161

162162
for (const [, state] of lines) {
163163
if (state.commit.isUncommitted) continue;
@@ -288,9 +288,10 @@ export class LineAnnotationController implements Disposable {
288288
this._cancellation = new CancellationTokenSource();
289289
const cancellation = this._cancellation.token;
290290

291-
const getBranchAndTagTipsPromise = CommitFormatter.has(cfg.format, 'tips')
292-
? this.container.git.getBranchesAndTagsTipsLookup(repoPath)
293-
: undefined;
291+
const getBranchAndTagTipsPromise =
292+
repoPath && CommitFormatter.has(cfg.format, 'tips')
293+
? this.container.git.getRepositoryService(repoPath).getBranchesAndTagsTipsLookup()
294+
: undefined;
294295

295296
async function updateDecorations(
296297
container: Container,

src/avatars.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ async function getAvatarUriFromRemoteProvider(
228228
// } else {
229229
if (typeof repoPathOrCommit !== 'string') {
230230
const remote = await Container.instance.git
231-
.remotes(repoPathOrCommit.repoPath)
232-
.getBestRemoteWithIntegration();
231+
.getRepositoryService(repoPathOrCommit.repoPath)
232+
.remotes.getBestRemoteWithIntegration();
233233
if (remote?.hasIntegration()) {
234234
account = await (
235235
await remote.getIntegration()

src/commands/browseRepoAtRevision.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,10 @@ export class BrowseRepoAtRevisionCommand extends ActiveEditorCommand {
5858
let gitUri = await GitUri.fromUri(uri);
5959
if (gitUri.repoPath == null || gitUri.sha == null) throw new Error('No repo or SHA for Uri');
6060

61-
const { git } = this.container;
61+
const svc = this.container.git.getRepositoryService(gitUri.repoPath);
6262

63-
const sha = args?.before
64-
? (await git.revision(gitUri.repoPath).resolveRevision(`${gitUri.sha}^`)).sha
65-
: gitUri.sha;
66-
uri = git.getRevisionUri(gitUri.repoPath, sha, gitUri.repoPath);
63+
const sha = args?.before ? (await svc.revision.resolveRevision(`${gitUri.sha}^`)).sha : gitUri.sha;
64+
uri = svc.getRevisionUri(sha, gitUri.repoPath);
6765
gitUri = GitUri.fromRevisionUri(uri);
6866

6967
openWorkspace(uri, {

src/commands/changeBranchMergeTarget.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,13 @@ export class ChangeBranchMergeTargetCommand extends QuickCommand {
8080
state.branch = branches.name;
8181
}
8282

83+
const svc = this.container.git.getRepositoryService(state.repo.uri);
8384
if (!state.mergeBranch) {
84-
state.mergeBranch = await this.container.git
85-
.branches(state.repo.path)
86-
.getBaseBranchName?.(state.branch);
85+
state.mergeBranch = await svc.branches.getBaseBranchName?.(state.branch);
8786
}
8887

89-
const detectedMergeTarget = await this.container.git
90-
.branches(state.repo.path)
91-
.getStoredDetectedMergeTargetBranchName?.(state.branch);
92-
const userMergeTarget = await this.container.git
93-
.branches(state.repo.path)
94-
.getStoredUserMergeTargetBranchName?.(state.branch);
88+
const detectedMergeTarget = await svc.branches.getStoredDetectedMergeTargetBranchName?.(state.branch);
89+
const userMergeTarget = await svc.branches.getStoredUserMergeTargetBranchName?.(state.branch);
9590

9691
const result = yield* pickOrResetBranchStep(state, context, {
9792
picked: state.mergeBranch,
@@ -106,9 +101,7 @@ export class ChangeBranchMergeTargetCommand extends QuickCommand {
106101
if (result === StepResultBreak) continue;
107102

108103
if (state.branch) {
109-
await this.container.git
110-
.branches(state.repo.path)
111-
.storeUserMergeTargetBranchName?.(state.branch, result?.name);
104+
await svc.branches.storeUserMergeTargetBranchName?.(state.branch, result?.name);
112105
}
113106

114107
endSteps(state);

src/commands/closeUnchangedFiles.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ export class CloseUnchangedFilesCommand extends GlCommandBase {
2323

2424
try {
2525
if (args.uris == null) {
26-
const repository = await getRepositoryOrShowPicker('Close All Unchanged Files');
27-
if (repository == null) return;
26+
const repo = await getRepositoryOrShowPicker('Close All Unchanged Files');
27+
if (repo == null) return;
2828

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

src/commands/copyCurrentBranch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class CopyCurrentBranchCommand extends ActiveEditorCommand {
2424
if (repository == null) return;
2525

2626
try {
27-
const branch = await repository.git.branches().getBranch();
27+
const branch = await repository.git.branches.getBranch();
2828
if (branch?.name) {
2929
await env.clipboard.writeText(branch.name);
3030
}

src/commands/copyDeepLink.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class CopyDeepLinkCommand extends ActiveEditorCommand {
127127

128128
try {
129129
let chosenRemote;
130-
const remotes = await this.container.git.remotes(repoPath).getRemotes({ sort: true });
130+
const remotes = await this.container.git.getRepositoryService(repoPath).remotes.getRemotes({ sort: true });
131131
const defaultRemote = remotes.find(r => r.default);
132132
if (args.remote && !args.prePickRemote) {
133133
chosenRemote = remotes.find(r => r.name === args?.remote);
@@ -290,7 +290,7 @@ export class CopyFileDeepLinkCommand extends ActiveEditorCommand {
290290

291291
try {
292292
let chosenRemote;
293-
const remotes = await this.container.git.remotes(repoPath).getRemotes({ sort: true });
293+
const remotes = await this.container.git.getRepositoryService(repoPath).remotes.getRemotes({ sort: true });
294294
const defaultRemote = remotes.find(r => r.default);
295295
if (args.remote && !args.prePickRemote) {
296296
chosenRemote = remotes.find(r => r.name === args?.remote);

src/commands/copyMessageToClipboard.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,12 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand {
6868
return;
6969
}
7070

71-
let repoPath;
72-
7371
// If we don't have an editor then get the message of the last commit to the branch
7472
if (uri == null) {
75-
repoPath = this.container.git.getBestRepository(editor)?.path;
76-
if (!repoPath) return;
73+
const repo = this.container.git.getBestRepository(editor);
74+
if (repo == null) return;
7775

78-
const log = await this.container.git.commits(repoPath).getLog(undefined, { limit: 1 });
76+
const log = await repo.git.commits.getLog(undefined, { limit: 1 });
7977
if (log == null) return;
8078

8179
const commit = first(log.commits.values());
@@ -84,7 +82,7 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand {
8482
args.message = commit.message;
8583
} else if (args.message == null) {
8684
const gitUri = await GitUri.fromUri(uri);
87-
repoPath = gitUri.repoPath;
85+
const repoPath = gitUri.repoPath;
8886
if (!repoPath) return;
8987

9088
if (args.sha == null) {

0 commit comments

Comments
 (0)