Parcourir la source

Uses Uris to avoid extra regex processing

main
Eric Amodio il y a 1 an
Parent
révision
f538920310
2 fichiers modifiés avec 61 ajouts et 59 suppressions
  1. +19
    -12
      src/git/gitProviderService.ts
  2. +42
    -47
      src/git/models/repository.ts

+ 19
- 12
src/git/gitProviderService.ts Voir le fichier

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

+ 42
- 47
src/git/models/repository.ts Voir le fichier

@ -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 { ForcePushMode } from '../../@types/vscode.git.enums';
import type { CreatePullRequestActionContext } from '../../api/gitlens';
@ -474,19 +474,19 @@ export class Repository implements Disposable {
@log()
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 });
return remote;
}
@log()
pruneRemote(name: string): Promise<void> {
return this.container.git.pruneRemote(this.path, name);
return this.container.git.pruneRemote(this.uri, name);
}
@log()
removeRemote(name: string): Promise<void> {
return this.container.git.removeRemote(this.path, name);
return this.container.git.removeRemote(this.uri, name);
}
@log()
@ -583,7 +583,7 @@ export class Repository implements Disposable {
options?.branch != null ||
(configuration.get('experimental.nativeGit') ?? this.container.prereleaseOrDebugging)
) {
await this.container.git.fetch(this.path, options);
await this.container.git.fetch(this.uri, options);
} else {
void (await executeCoreGitCommand('git.fetch', this.path));
}
@ -604,7 +604,7 @@ export class Repository implements Disposable {
}
if (this._branch == null) {
this._branch = this.container.git.getBranch(this.path);
this._branch = this.container.git.getBranch(this.uri);
}
return this._branch;
}
@ -614,26 +614,26 @@ export class Repository implements Disposable {
paging?: { cursor?: string; limit?: number };
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> {
return this.container.git.getChangedFilesCount(this.path, ref);
return this.container.git.getChangedFilesCount(this.uri, ref);
}
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[]> {
return this.container.git.getContributors(this.path, options);
return this.container.git.getContributors(this.uri, options);
}
private _gitDir: GitDir | undefined;
private _gitDirPromise: Promise<GitDir | undefined> | undefined;
private getGitDir(): Promise<GitDir | undefined> {
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;
}
@ -646,7 +646,7 @@ export class Repository implements Disposable {
}
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 (lastFetched != null) {
this._lastFetched = lastFetched;
@ -673,11 +673,11 @@ export class Repository implements Disposable {
}
getMergeStatus(): Promise<GitMergeStatus | undefined> {
return this.container.git.getMergeStatus(this.path);
return this.container.git.getMergeStatus(this.uri);
}
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> {
@ -687,7 +687,7 @@ export class Repository implements Disposable {
async getRemotes(options?: { filter?: (remote: GitRemote) => boolean; sort?: boolean }): Promise<GitRemote[]> {
if (this._remotes == null) {
// 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);
}
@ -714,11 +714,11 @@ export class Repository implements Disposable {
}
getStash(): Promise<GitStash | undefined> {
return this.container.git.getStash(this.path);
return this.container.git.getStash(this.uri);
}
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> {
@ -729,7 +729,7 @@ export class Repository implements Disposable {
}
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()
@ -737,21 +737,21 @@ export class Repository implements Disposable {
uri: Uri,
options?: { commitish?: string; createBranch?: string; detach?: boolean; force?: boolean },
): 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();
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[]> {
return this.container.git.getWorktrees(this.path);
return this.container.git.getWorktrees(this.uri);
}
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> {
return this.container.git.deleteWorktree(this.path, uri.fsPath, options);
return this.container.git.deleteWorktree(this.uri, uri.fsPath, options);
}
async hasRemotes(): Promise<boolean> {
@ -802,23 +802,18 @@ export class Repository implements Disposable {
private async pullCore(options?: { rebase?: boolean }) {
try {
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 {
const upstream = await this.hasUpstreamBranch();
if (upstream) {
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 {
if (configuration.get('experimental.nativeGit') ?? this.container.prereleaseOrDebugging) {
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,
branch: isBranchReference(options?.reference) ? options?.reference : branch,
...(options?.publish && { publish: options.publish }),
});
} 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 (options?.publish != null) {
@ -918,7 +913,7 @@ export class Repository implements Disposable {
);
}
} 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;
const branch = await this.getBranch();
@ -993,7 +988,7 @@ export class Repository implements Disposable {
search: SearchQuery,
options?: { limit?: number; ordering?: 'date' | 'author-date' | 'topo'; skip?: number },
): Promise<GitLog | undefined> {
return this.container.git.richSearchCommits(this.path, search, options);
return this.container.git.richSearchCommits(this.uri, search, options);
}
@debug()
@ -1001,7 +996,7 @@ export class Repository implements Disposable {
search: SearchQuery,
options?: { cancellation?: CancellationToken; limit?: number; ordering?: 'date' | 'author-date' | 'topo' },
): 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) {
@ -1022,7 +1017,7 @@ export class Repository implements Disposable {
@gate()
@log()
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);
}
@ -1030,7 +1025,7 @@ export class Repository implements Disposable {
@gate()
@log()
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);
}
@ -1038,7 +1033,7 @@ export class Repository implements Disposable {
@gate()
@log()
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);
}
@ -1050,7 +1045,7 @@ export class Repository implements Disposable {
uris?: Uri[],
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);
}
@ -1073,7 +1068,7 @@ export class Repository implements Disposable {
private async switchCore(ref: string, options?: { createBranch?: string }) {
try {
await this.container.git.checkout(this.path, ref, options);
await this.container.git.checkout(this.uri, ref, options);
this.fireChange(RepositoryChange.Unknown);
} catch (ex) {
@ -1083,7 +1078,7 @@ export class Repository implements Disposable {
}
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;
}
@ -1225,7 +1220,7 @@ export class Repository implements Disposable {
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 !== e.uris.length) {

Chargement…
Annuler
Enregistrer