Browse Source

Uses Uris to avoid extra regex processing

main
Eric Amodio 1 year ago
parent
commit
f538920310
2 changed files with 61 additions and 59 deletions
  1. +19
    -12
      src/git/gitProviderService.ts
  2. +42
    -47
      src/git/models/repository.ts

+ 19
- 12
src/git/gitProviderService.ts View File

@ -1258,7 +1258,11 @@ export class GitProviderService implements Disposable {
} }
@log() @log()
checkout(repoPath: string, ref: string, options?: { createBranch?: string } | { path?: string }): Promise<void> {
checkout(
repoPath: string | Uri,
ref: string,
options?: { createBranch?: string } | { path?: string },
): Promise<void> {
const { provider, path } = this.getProvider(repoPath); const { provider, path } = this.getProvider(repoPath);
return provider.checkout(path, ref, options); return provider.checkout(path, ref, options);
} }
@ -1279,7 +1283,7 @@ export class GitProviderService implements Disposable {
} }
@log<GitProviderService['excludeIgnoredUris']>({ args: { 1: uris => uris.length } }) @log<GitProviderService['excludeIgnoredUris']>({ args: { 1: uris => uris.length } })
excludeIgnoredUris(repoPath: string, uris: Uri[]): Promise<Uri[]> {
excludeIgnoredUris(repoPath: string | Uri, uris: Uri[]): Promise<Uri[]> {
const { provider, path } = this.getProvider(repoPath); const { provider, path } = this.getProvider(repoPath);
return provider.excludeIgnoredUris(path, uris); return provider.excludeIgnoredUris(path, uris);
} }
@ -1287,7 +1291,7 @@ export class GitProviderService implements Disposable {
@gate() @gate()
@log() @log()
fetch( fetch(
repoPath: string,
repoPath: string | Uri,
options?: { all?: boolean; branch?: GitBranchReference; prune?: boolean; pull?: boolean; remote?: string }, options?: { all?: boolean; branch?: GitBranchReference; prune?: boolean; pull?: boolean; remote?: string },
): Promise<void> { ): Promise<void> {
const { provider, path } = this.getProvider(repoPath); const { provider, path } = this.getProvider(repoPath);
@ -1321,7 +1325,10 @@ export class GitProviderService implements Disposable {
@gate() @gate()
@log() @log()
pull(repoPath: string, options?: { branch?: GitBranchReference; rebase?: boolean; tags?: boolean }): Promise<void> {
pull(
repoPath: string | Uri,
options?: { branch?: GitBranchReference; rebase?: boolean; tags?: boolean },
): Promise<void> {
const { provider, path } = this.getProvider(repoPath); const { provider, path } = this.getProvider(repoPath);
return provider.pull(path, options); return provider.pull(path, options);
} }
@ -1354,7 +1361,7 @@ export class GitProviderService implements Disposable {
@gate() @gate()
@log() @log()
push( push(
repoPath: string,
repoPath: string | Uri,
options?: { branch?: GitBranchReference; force?: boolean; publish?: { remote: string } }, options?: { branch?: GitBranchReference; force?: boolean; publish?: { remote: string } },
): Promise<void> { ): Promise<void> {
const { provider, path } = this.getProvider(repoPath); const { provider, path } = this.getProvider(repoPath);
@ -1667,13 +1674,13 @@ export class GitProviderService implements Disposable {
} }
@log() @log()
async getConfig(repoPath: string, key: string): Promise<string | undefined> {
async getConfig(repoPath: string | Uri, key: string): Promise<string | undefined> {
const { provider, path } = this.getProvider(repoPath); const { provider, path } = this.getProvider(repoPath);
return provider.getConfig?.(path, key); return provider.getConfig?.(path, key);
} }
@log() @log()
async setConfig(repoPath: string, key: string, value: string | undefined): Promise<void> {
async setConfig(repoPath: string | Uri, key: string, value: string | undefined): Promise<void> {
const { provider, path } = this.getProvider(repoPath); const { provider, path } = this.getProvider(repoPath);
return provider.setConfig?.(path, key, value); return provider.setConfig?.(path, key, value);
} }
@ -1777,7 +1784,7 @@ export class GitProviderService implements Disposable {
} }
@debug() @debug()
getGitDir(repoPath: string): Promise<GitDir | undefined> {
getGitDir(repoPath: string | Uri): Promise<GitDir | undefined> {
const { provider, path } = this.getProvider(repoPath); const { provider, path } = this.getProvider(repoPath);
return Promise.resolve(provider.getGitDir?.(path)); return Promise.resolve(provider.getGitDir?.(path));
} }
@ -2695,13 +2702,13 @@ export class GitProviderService implements Disposable {
} }
async resolveReference( async resolveReference(
repoPath: string,
repoPath: string | Uri,
ref: string, ref: string,
path?: string, path?: string,
options?: { force?: boolean; timeout?: number }, options?: { force?: boolean; timeout?: number },
): Promise<string>; ): Promise<string>;
async resolveReference( async resolveReference(
repoPath: string,
repoPath: string | Uri,
ref: string, ref: string,
uri?: Uri, uri?: Uri,
options?: { force?: boolean; timeout?: number }, options?: { force?: boolean; timeout?: number },
@ -2913,13 +2920,13 @@ export class GitProviderService implements Disposable {
} }
@log() @log()
getScmRepository(repoPath: string): Promise<ScmRepository | undefined> {
getScmRepository(repoPath: string | Uri): Promise<ScmRepository | undefined> {
const { provider, path } = this.getProvider(repoPath); const { provider, path } = this.getProvider(repoPath);
return provider.getScmRepository(path); return provider.getScmRepository(path);
} }
@log() @log()
getOrOpenScmRepository(repoPath: string): Promise<ScmRepository | undefined> {
getOrOpenScmRepository(repoPath: string | Uri): Promise<ScmRepository | undefined> {
const { provider, path } = this.getProvider(repoPath); const { provider, path } = this.getProvider(repoPath);
return provider.getOrOpenScmRepository(path); return provider.getOrOpenScmRepository(path);
} }

+ 42
- 47
src/git/models/repository.ts View File

@ -1,5 +1,5 @@
import type { CancellationToken, ConfigurationChangeEvent, Event, WorkspaceFolder } from 'vscode';
import { Disposable, EventEmitter, ProgressLocation, RelativePattern, Uri, window, workspace } from 'vscode';
import type { CancellationToken, ConfigurationChangeEvent, Event, Uri, WorkspaceFolder } from 'vscode';
import { Disposable, EventEmitter, ProgressLocation, RelativePattern, window, workspace } from 'vscode';
import { md5 } from '@env/crypto'; import { md5 } from '@env/crypto';
import { ForcePushMode } from '../../@types/vscode.git.enums'; import { ForcePushMode } from '../../@types/vscode.git.enums';
import type { CreatePullRequestActionContext } from '../../api/gitlens'; import type { CreatePullRequestActionContext } from '../../api/gitlens';
@ -474,19 +474,19 @@ export class Repository implements Disposable {
@log() @log()
async addRemote(name: string, url: string, options?: { fetch?: boolean }): Promise<GitRemote | undefined> { async addRemote(name: string, url: string, options?: { fetch?: boolean }): Promise<GitRemote | undefined> {
await this.container.git.addRemote(this.path, name, url, options);
await this.container.git.addRemote(this.uri, name, url, options);
const [remote] = await this.getRemotes({ filter: r => r.url === url }); const [remote] = await this.getRemotes({ filter: r => r.url === url });
return remote; return remote;
} }
@log() @log()
pruneRemote(name: string): Promise<void> { pruneRemote(name: string): Promise<void> {
return this.container.git.pruneRemote(this.path, name);
return this.container.git.pruneRemote(this.uri, name);
} }
@log() @log()
removeRemote(name: string): Promise<void> { removeRemote(name: string): Promise<void> {
return this.container.git.removeRemote(this.path, name);
return this.container.git.removeRemote(this.uri, name);
} }
@log() @log()
@ -583,7 +583,7 @@ export class Repository implements Disposable {
options?.branch != null || options?.branch != null ||
(configuration.get('experimental.nativeGit') ?? this.container.prereleaseOrDebugging) (configuration.get('experimental.nativeGit') ?? this.container.prereleaseOrDebugging)
) { ) {
await this.container.git.fetch(this.path, options);
await this.container.git.fetch(this.uri, options);
} else { } else {
void (await executeCoreGitCommand('git.fetch', this.path)); void (await executeCoreGitCommand('git.fetch', this.path));
} }
@ -604,7 +604,7 @@ export class Repository implements Disposable {
} }
if (this._branch == null) { if (this._branch == null) {
this._branch = this.container.git.getBranch(this.path);
this._branch = this.container.git.getBranch(this.uri);
} }
return this._branch; return this._branch;
} }
@ -614,26 +614,26 @@ export class Repository implements Disposable {
paging?: { cursor?: string; limit?: number }; paging?: { cursor?: string; limit?: number };
sort?: boolean | BranchSortOptions; sort?: boolean | BranchSortOptions;
}) { }) {
return this.container.git.getBranches(this.path, options);
return this.container.git.getBranches(this.uri, options);
} }
getChangedFilesCount(ref?: string): Promise<GitDiffShortStat | undefined> { getChangedFilesCount(ref?: string): Promise<GitDiffShortStat | undefined> {
return this.container.git.getChangedFilesCount(this.path, ref);
return this.container.git.getChangedFilesCount(this.uri, ref);
} }
getCommit(ref: string): Promise<GitCommit | undefined> { getCommit(ref: string): Promise<GitCommit | undefined> {
return this.container.git.getCommit(this.path, ref);
return this.container.git.getCommit(this.uri, ref);
} }
getContributors(options?: { all?: boolean; ref?: string; stats?: boolean }): Promise<GitContributor[]> { getContributors(options?: { all?: boolean; ref?: string; stats?: boolean }): Promise<GitContributor[]> {
return this.container.git.getContributors(this.path, options);
return this.container.git.getContributors(this.uri, options);
} }
private _gitDir: GitDir | undefined; private _gitDir: GitDir | undefined;
private _gitDirPromise: Promise<GitDir | undefined> | undefined; private _gitDirPromise: Promise<GitDir | undefined> | undefined;
private getGitDir(): Promise<GitDir | undefined> { private getGitDir(): Promise<GitDir | undefined> {
if (this._gitDirPromise == null) { if (this._gitDirPromise == null) {
this._gitDirPromise = this.container.git.getGitDir(this.path).then(gd => (this._gitDir = gd));
this._gitDirPromise = this.container.git.getGitDir(this.uri).then(gd => (this._gitDir = gd));
} }
return this._gitDirPromise; return this._gitDirPromise;
} }
@ -646,7 +646,7 @@ export class Repository implements Disposable {
} }
try { try {
const lastFetched = await this.container.git.getLastFetchedTimestamp(this.path);
const lastFetched = await this.container.git.getLastFetchedTimestamp(this.uri);
// If we don't get a number, assume the fetch failed, and don't update the timestamp // If we don't get a number, assume the fetch failed, and don't update the timestamp
if (lastFetched != null) { if (lastFetched != null) {
this._lastFetched = lastFetched; this._lastFetched = lastFetched;
@ -673,11 +673,11 @@ export class Repository implements Disposable {
} }
getMergeStatus(): Promise<GitMergeStatus | undefined> { getMergeStatus(): Promise<GitMergeStatus | undefined> {
return this.container.git.getMergeStatus(this.path);
return this.container.git.getMergeStatus(this.uri);
} }
getRebaseStatus(): Promise<GitRebaseStatus | undefined> { getRebaseStatus(): Promise<GitRebaseStatus | undefined> {
return this.container.git.getRebaseStatus(this.path);
return this.container.git.getRebaseStatus(this.uri);
} }
async getRemote(remote: string): Promise<GitRemote | undefined> { async getRemote(remote: string): Promise<GitRemote | undefined> {
@ -687,7 +687,7 @@ export class Repository implements Disposable {
async getRemotes(options?: { filter?: (remote: GitRemote) => boolean; sort?: boolean }): Promise<GitRemote[]> { async getRemotes(options?: { filter?: (remote: GitRemote) => boolean; sort?: boolean }): Promise<GitRemote[]> {
if (this._remotes == null) { if (this._remotes == null) {
// Since we are caching the results, always sort // Since we are caching the results, always sort
this._remotes = this.container.git.getRemotes(this.path, { sort: true });
this._remotes = this.container.git.getRemotes(this.uri, { sort: true });
void this.subscribeToRemotes(this._remotes); void this.subscribeToRemotes(this._remotes);
} }
@ -714,11 +714,11 @@ export class Repository implements Disposable {
} }
getStash(): Promise<GitStash | undefined> { getStash(): Promise<GitStash | undefined> {
return this.container.git.getStash(this.path);
return this.container.git.getStash(this.uri);
} }
getStatus(): Promise<GitStatus | undefined> { getStatus(): Promise<GitStatus | undefined> {
return this.container.git.getStatusForRepo(this.path);
return this.container.git.getStatusForRepo(this.uri);
} }
async getTag(name: string): Promise<GitTag | undefined> { async getTag(name: string): Promise<GitTag | undefined> {
@ -729,7 +729,7 @@ export class Repository implements Disposable {
} }
getTags(options?: { filter?: (t: GitTag) => boolean; sort?: boolean | TagSortOptions }) { getTags(options?: { filter?: (t: GitTag) => boolean; sort?: boolean | TagSortOptions }) {
return this.container.git.getTags(this.path, options);
return this.container.git.getTags(this.uri, options);
} }
@log() @log()
@ -737,21 +737,21 @@ export class Repository implements Disposable {
uri: Uri, uri: Uri,
options?: { commitish?: string; createBranch?: string; detach?: boolean; force?: boolean }, options?: { commitish?: string; createBranch?: string; detach?: boolean; force?: boolean },
): Promise<GitWorktree | undefined> { ): Promise<GitWorktree | undefined> {
await this.container.git.createWorktree(this.path, uri.fsPath, options);
await this.container.git.createWorktree(this.uri, uri.fsPath, options);
const url = uri.toString(); const url = uri.toString();
return this.container.git.getWorktree(this.path, w => w.uri.toString() === url);
return this.container.git.getWorktree(this.uri, w => w.uri.toString() === url);
} }
getWorktrees(): Promise<GitWorktree[]> { getWorktrees(): Promise<GitWorktree[]> {
return this.container.git.getWorktrees(this.path);
return this.container.git.getWorktrees(this.uri);
} }
async getWorktreesDefaultUri(): Promise<Uri | undefined> { async getWorktreesDefaultUri(): Promise<Uri | undefined> {
return this.container.git.getWorktreesDefaultUri(this.path);
return this.container.git.getWorktreesDefaultUri(this.uri);
} }
deleteWorktree(uri: Uri, options?: { force?: boolean }): Promise<void> { deleteWorktree(uri: Uri, options?: { force?: boolean }): Promise<void> {
return this.container.git.deleteWorktree(this.path, uri.fsPath, options);
return this.container.git.deleteWorktree(this.uri, uri.fsPath, options);
} }
async hasRemotes(): Promise<boolean> { async hasRemotes(): Promise<boolean> {
@ -802,23 +802,18 @@ export class Repository implements Disposable {
private async pullCore(options?: { rebase?: boolean }) { private async pullCore(options?: { rebase?: boolean }) {
try { try {
if (configuration.get('experimental.nativeGit') ?? this.container.prereleaseOrDebugging) { if (configuration.get('experimental.nativeGit') ?? this.container.prereleaseOrDebugging) {
const withTags = configuration.getAny<CoreGitConfiguration, boolean>(
'git.pullTags',
Uri.file(this.path),
);
if (configuration.getAny<CoreGitConfiguration, boolean>('git.fetchOnPull', Uri.file(this.path))) {
await this.container.git.fetch(this.path);
const withTags = configuration.getAny<CoreGitConfiguration, boolean>('git.pullTags', this.uri);
if (configuration.getAny<CoreGitConfiguration, boolean>('git.fetchOnPull', this.uri)) {
await this.container.git.fetch(this.uri);
} }
await this.container.git.pull(this.path, { ...options, tags: withTags });
await this.container.git.pull(this.uri, { ...options, tags: withTags });
} else { } else {
const upstream = await this.hasUpstreamBranch(); const upstream = await this.hasUpstreamBranch();
if (upstream) { if (upstream) {
void (await executeCoreGitCommand(options?.rebase ? 'git.pullRebase' : 'git.pull', this.path)); void (await executeCoreGitCommand(options?.rebase ? 'git.pullRebase' : 'git.pull', this.path));
} else if (
configuration.getAny<CoreGitConfiguration, boolean>('git.fetchOnPull', Uri.file(this.path))
) {
await this.container.git.fetch(this.path);
} else if (configuration.getAny<CoreGitConfiguration, boolean>('git.fetchOnPull', this.uri)) {
await this.container.git.fetch(this.uri);
} }
} }
@ -894,13 +889,13 @@ export class Repository implements Disposable {
try { try {
if (configuration.get('experimental.nativeGit') ?? this.container.prereleaseOrDebugging) { if (configuration.get('experimental.nativeGit') ?? this.container.prereleaseOrDebugging) {
const branch = await this.getBranch(options?.reference?.name); const branch = await this.getBranch(options?.reference?.name);
await this.container.git.push(this.path, {
await this.container.git.push(this.uri, {
force: options?.force, force: options?.force,
branch: isBranchReference(options?.reference) ? options?.reference : branch, branch: isBranchReference(options?.reference) ? options?.reference : branch,
...(options?.publish && { publish: options.publish }), ...(options?.publish && { publish: options.publish }),
}); });
} else if (isBranchReference(options?.reference)) { } else if (isBranchReference(options?.reference)) {
const repo = await this.container.git.getOrOpenScmRepository(this.path);
const repo = await this.container.git.getOrOpenScmRepository(this.uri);
if (repo == null) return; if (repo == null) return;
if (options?.publish != null) { if (options?.publish != null) {
@ -918,7 +913,7 @@ export class Repository implements Disposable {
); );
} }
} else if (options?.reference != null) { } else if (options?.reference != null) {
const repo = await this.container.git.getOrOpenScmRepository(this.path);
const repo = await this.container.git.getOrOpenScmRepository(this.uri);
if (repo == null) return; if (repo == null) return;
const branch = await this.getBranch(); const branch = await this.getBranch();
@ -993,7 +988,7 @@ export class Repository implements Disposable {
search: SearchQuery, search: SearchQuery,
options?: { limit?: number; ordering?: 'date' | 'author-date' | 'topo'; skip?: number }, options?: { limit?: number; ordering?: 'date' | 'author-date' | 'topo'; skip?: number },
): Promise<GitLog | undefined> { ): Promise<GitLog | undefined> {
return this.container.git.richSearchCommits(this.path, search, options);
return this.container.git.richSearchCommits(this.uri, search, options);
} }
@debug() @debug()
@ -1001,7 +996,7 @@ export class Repository implements Disposable {
search: SearchQuery, search: SearchQuery,
options?: { cancellation?: CancellationToken; limit?: number; ordering?: 'date' | 'author-date' | 'topo' }, options?: { cancellation?: CancellationToken; limit?: number; ordering?: 'date' | 'author-date' | 'topo' },
): Promise<GitSearch> { ): Promise<GitSearch> {
return this.container.git.searchCommits(this.path, search, options);
return this.container.git.searchCommits(this.uri, search, options);
} }
async setRemoteAsDefault(remote: GitRemote, value: boolean = true) { async setRemoteAsDefault(remote: GitRemote, value: boolean = true) {
@ -1022,7 +1017,7 @@ export class Repository implements Disposable {
@gate() @gate()
@log() @log()
async stashApply(stashName: string, options?: { deleteAfter?: boolean }) { async stashApply(stashName: string, options?: { deleteAfter?: boolean }) {
await this.container.git.stashApply(this.path, stashName, options);
await this.container.git.stashApply(this.uri, stashName, options);
this.fireChange(RepositoryChange.Stash); this.fireChange(RepositoryChange.Stash);
} }
@ -1030,7 +1025,7 @@ export class Repository implements Disposable {
@gate() @gate()
@log() @log()
async stashDelete(stashName: string, ref?: string) { async stashDelete(stashName: string, ref?: string) {
await this.container.git.stashDelete(this.path, stashName, ref);
await this.container.git.stashDelete(this.uri, stashName, ref);
this.fireChange(RepositoryChange.Stash); this.fireChange(RepositoryChange.Stash);
} }
@ -1038,7 +1033,7 @@ export class Repository implements Disposable {
@gate() @gate()
@log() @log()
async stashRename(stashName: string, ref: string, message: string, stashOnRef?: string) { async stashRename(stashName: string, ref: string, message: string, stashOnRef?: string) {
await this.container.git.stashRename(this.path, stashName, ref, message, stashOnRef);
await this.container.git.stashRename(this.uri, stashName, ref, message, stashOnRef);
this.fireChange(RepositoryChange.Stash); this.fireChange(RepositoryChange.Stash);
} }
@ -1050,7 +1045,7 @@ export class Repository implements Disposable {
uris?: Uri[], uris?: Uri[],
options?: { includeUntracked?: boolean; keepIndex?: boolean; onlyStaged?: boolean }, options?: { includeUntracked?: boolean; keepIndex?: boolean; onlyStaged?: boolean },
) { ) {
await this.container.git.stashSave(this.path, message, uris, options);
await this.container.git.stashSave(this.uri, message, uris, options);
this.fireChange(RepositoryChange.Stash); this.fireChange(RepositoryChange.Stash);
} }
@ -1073,7 +1068,7 @@ export class Repository implements Disposable {
private async switchCore(ref: string, options?: { createBranch?: string }) { private async switchCore(ref: string, options?: { createBranch?: string }) {
try { try {
await this.container.git.checkout(this.path, ref, options);
await this.container.git.checkout(this.uri, ref, options);
this.fireChange(RepositoryChange.Unknown); this.fireChange(RepositoryChange.Unknown);
} catch (ex) { } catch (ex) {
@ -1083,7 +1078,7 @@ export class Repository implements Disposable {
} }
toAbsoluteUri(path: string, options?: { validate?: boolean }): Uri | undefined { toAbsoluteUri(path: string, options?: { validate?: boolean }): Uri | undefined {
const uri = this.container.git.getAbsoluteUri(path, this.path);
const uri = this.container.git.getAbsoluteUri(path, this.uri);
return !(options?.validate ?? true) || this.containsUri(uri) ? uri : undefined; return !(options?.validate ?? true) || this.containsUri(uri) ? uri : undefined;
} }
@ -1225,7 +1220,7 @@ export class Repository implements Disposable {
this._pendingFileSystemChange = undefined; this._pendingFileSystemChange = undefined;
const uris = await this.container.git.excludeIgnoredUris(this.path, e.uris);
const uris = await this.container.git.excludeIgnoredUris(this.uri, e.uris);
if (uris.length === 0) return; if (uris.length === 0) return;
if (uris.length !== e.uris.length) { if (uris.length !== e.uris.length) {

Loading…
Cancel
Save