Browse Source

Converts more file paths to Uris

Adds more docs
Removes unused original file name from diff calls
main
Eric Amodio 2 years ago
parent
commit
d1002c3ed0
6 changed files with 92 additions and 172 deletions
  1. +1
    -1
      src/annotations/gutterChangesAnnotationProvider.ts
  2. +1
    -1
      src/commands/diffWith.ts
  3. +17
    -38
      src/env/node/git/localGitProvider.ts
  4. +33
    -101
      src/git/gitProvider.ts
  5. +39
    -29
      src/git/gitProviderService.ts
  6. +1
    -2
      src/hovers/hovers.ts

+ 1
- 1
src/annotations/gutterChangesAnnotationProvider.ts View File

@ -80,7 +80,7 @@ export class GutterChangesAnnotationProvider extends AnnotationProviderBase
if (localChanges) {
let ref = await this.container.git.getOldestUnpushedRefForFile(
this.trackedDocument.uri.repoPath!,
this.trackedDocument.uri.fsPath,
this.trackedDocument.uri,
);
if (ref != null) {
ref = `${ref}^`;

+ 1
- 1
src/commands/diffWith.ts View File

@ -104,7 +104,7 @@ export class DiffWithCommand extends Command {
// Ensure that the file still exists in this commit
const status = await Container.instance.git.getFileStatusForCommit(
args.repoPath,
args.rhs.uri.fsPath,
args.rhs.uri,
args.rhs.sha,
);
if (status?.status === 'D') {

+ 17
- 38
src/env/node/git/localGitProvider.ts View File

@ -611,6 +611,14 @@ export class LocalGitProvider implements GitProvider, Disposable {
return Git.fetch(repoPath, opts);
}
@log<LocalGitProvider['getAheadBehindCommitCount']>({ args: { 1: refs => refs.join(',') } })
getAheadBehindCommitCount(
repoPath: string,
refs: string[],
): Promise<{ ahead: number; behind: number } | undefined> {
return Git.rev_list__left_right(repoPath, refs);
}
@log()
async getBlameForFile(uri: GitUri): Promise<GitBlame | undefined> {
const cc = Logger.getCorrelationContext();
@ -1175,14 +1183,6 @@ export class LocalGitProvider implements GitProvider, Disposable {
.filter(<T>(i?: T): i is T => Boolean(i));
}
@log<LocalGitProvider['getAheadBehindCommitCount']>({ args: { 1: refs => refs.join(',') } })
getAheadBehindCommitCount(
repoPath: string,
refs: string[],
): Promise<{ ahead: number; behind: number } | undefined> {
return Git.rev_list__left_right(repoPath, refs);
}
@log()
getCommitCount(repoPath: string, ref: string): Promise<number | undefined> {
return Git.rev_list__count(repoPath, ref);
@ -1222,8 +1222,8 @@ export class LocalGitProvider implements GitProvider, Disposable {
}
@log()
async getOldestUnpushedRefForFile(repoPath: string, fileName: string): Promise<string | undefined> {
const data = await Git.log__file(repoPath, fileName, '@{push}..', {
async getOldestUnpushedRefForFile(repoPath: string, uri: Uri): Promise<string | undefined> {
const data = await Git.log__file(repoPath, uri.fsPath, '@{push}..', {
format: 'refs',
ordering: this.container.config.advanced.commitOrdering,
renames: true,
@ -1364,12 +1364,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
}
@log()
async getDiffForFile(
uri: GitUri,
ref1: string | undefined,
ref2?: string,
originalFileName?: string,
): Promise<GitDiff | undefined> {
async getDiffForFile(uri: GitUri, ref1: string | undefined, ref2?: string): Promise<GitDiff | undefined> {
const cc = Logger.getCorrelationContext();
let key = 'diff';
@ -1402,7 +1397,6 @@ export class LocalGitProvider implements GitProvider, Disposable {
uri.fsPath,
ref1,
ref2,
originalFileName,
{ encoding: GitProviderService.getEncoding(uri) },
doc,
key,
@ -1426,7 +1420,6 @@ export class LocalGitProvider implements GitProvider, Disposable {
fileName: string,
ref1: string | undefined,
ref2: string | undefined,
originalFileName: string | undefined,
options: { encoding?: string },
document: TrackedDocument<GitDocumentState>,
key: string,
@ -1435,12 +1428,6 @@ export class LocalGitProvider implements GitProvider, Disposable {
const [file, root] = Paths.splitPath(fileName, repoPath, false);
try {
// let data;
// if (ref2 == null && ref1 != null && !GitRevision.isUncommittedStaged(ref1)) {
// data = await Git.show__diff(root, file, ref1, originalFileName, {
// similarityThreshold: this.container.config.advanced.similarityThreshold,
// });
// } else {
const data = await Git.diff(root, file, ref1, ref2, {
...options,
filters: ['M'],
@ -1472,12 +1459,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
}
@log<LocalGitProvider['getDiffForFileContents']>({ args: { 1: '<contents>' } })
async getDiffForFileContents(
uri: GitUri,
ref: string,
contents: string,
originalFileName?: string,
): Promise<GitDiff | undefined> {
async getDiffForFileContents(uri: GitUri, ref: string, contents: string): Promise<GitDiff | undefined> {
const cc = Logger.getCorrelationContext();
const key = `diff:${Strings.md5(contents)}`;
@ -1504,7 +1486,6 @@ export class LocalGitProvider implements GitProvider, Disposable {
uri.fsPath,
ref,
contents,
originalFileName,
{ encoding: GitProviderService.getEncoding(uri) },
doc,
key,
@ -1523,12 +1504,11 @@ export class LocalGitProvider implements GitProvider, Disposable {
return promise;
}
async getDiffForFileContentsCore(
private async getDiffForFileContentsCore(
repoPath: string | undefined,
fileName: string,
ref: string,
contents: string,
originalFileName: string | undefined,
options: { encoding?: string },
document: TrackedDocument<GitDocumentState>,
key: string,
@ -1567,13 +1547,12 @@ export class LocalGitProvider implements GitProvider, Disposable {
@log()
async getDiffForLine(
uri: GitUri,
editorLine: number, // editor lines are 0-based
editorLine: number,
ref1: string | undefined,
ref2?: string,
originalFileName?: string,
): Promise<GitDiffHunkLine | undefined> {
try {
const diff = await this.getDiffForFile(uri, ref1, ref2, originalFileName);
const diff = await this.getDiffForFile(uri, ref1, ref2);
if (diff == null) return undefined;
const line = editorLine + 1;
@ -1606,10 +1585,10 @@ export class LocalGitProvider implements GitProvider, Disposable {
}
@log()
async getFileStatusForCommit(repoPath: string, fileName: string, ref: string): Promise<GitFile | undefined> {
async getFileStatusForCommit(repoPath: string, uri: Uri, ref: string): Promise<GitFile | undefined> {
if (ref === GitRevision.deletedOrMissing || GitRevision.isUncommitted(ref)) return undefined;
const data = await Git.show__name_status(repoPath, fileName, ref);
const data = await Git.show__name_status(repoPath, uri.fsPath, ref);
if (!data) return undefined;
const files = GitDiffParser.parseNameStatus(data, repoPath);

+ 33
- 101
src/git/gitProvider.ts View File

@ -104,21 +104,23 @@ export interface GitProvider {
remote?: string | undefined;
},
): Promise<void>;
getAheadBehindCommitCount(repoPath: string, refs: string[]): Promise<{ ahead: number; behind: number } | undefined>;
/**
* Returns the blame of a file
* @param uri The uri of the file to blame
* @param uri Uri of the file to blame
*/
getBlameForFile(uri: GitUri): Promise<GitBlame | undefined>;
/**
* Returns the blame of a file, using the editor contents (for dirty editors)
* @param uri The uri of the file to blame
* @param contents The editor contents to use
* @param uri Uri of the file to blame
* @param contents Contents from the editor to use
*/
getBlameForFileContents(uri: GitUri, contents: string): Promise<GitBlame | undefined>;
/**
* Returns the blame of a single line
* @param uri The uri of the file to blame
* @param line The editor line number (0-based) to blame (Git is 1-based)
* @param uri Uri of the file to blame
* @param editorLine Editor line number (0-based) to blame (Git is 1-based)
* @param options.forceSingleLine Forces blame to be for the single line (rather than the whole file)
*/
getBlameForLine(
uri: GitUri,
@ -127,9 +129,9 @@ export interface GitProvider {
): Promise<GitBlameLine | undefined>;
/**
* Returns the blame of a single line, using the editor contents (for dirty editors)
* @param uri The uri of the file to blame
* @param line The editor line number (0-based) to blame (Git is 1-based)
* @param contents The editor contents to use
* @param uri Uri of the file to blame
* @param editorLine Editor line number (0-based) to blame (Git is 1-based)
* @param contents Contents from the editor to use
*/
getBlameForLineContents(
uri: GitUri,
@ -152,7 +154,6 @@ export interface GitProvider {
ref: string,
options?: { mode?: 'contains' | 'pointsAt' | undefined; remotes?: boolean | undefined },
): Promise<string[]>;
getAheadBehindCommitCount(repoPath: string, refs: string[]): Promise<{ ahead: number; behind: number } | undefined>;
getCommitCount(repoPath: string, ref: string): Promise<number | undefined>;
getCommitForFile(
repoPath: string,
@ -164,7 +165,7 @@ export interface GitProvider {
reverse?: boolean | undefined;
},
): Promise<GitLogCommit | undefined>;
getOldestUnpushedRefForFile(repoPath: string, fileName: string): Promise<string | undefined>;
getOldestUnpushedRefForFile(repoPath: string, uri: Uri): Promise<string | undefined>;
getConfig(key: string, repoPath?: string): Promise<string | undefined>;
getContributors(
repoPath: string,
@ -172,24 +173,32 @@ export interface GitProvider {
): Promise<GitContributor[]>;
getCurrentUser(repoPath: string): Promise<GitUser | undefined>;
getDefaultBranchName(repoPath: string | undefined, remote?: string): Promise<string | undefined>;
getDiffForFile(
uri: GitUri,
ref1: string | undefined,
ref2?: string,
originalFileName?: string,
): Promise<GitDiff | undefined>;
getDiffForFileContents(
uri: GitUri,
ref: string,
contents: string,
originalFileName?: string,
): Promise<GitDiff | undefined>;
/**
* Returns a file diff between two commits
* @param uri Uri of the file to diff
* @param ref1 Commit to diff from
* @param ref2 Commit to diff to
*/
getDiffForFile(uri: GitUri, ref1: string | undefined, ref2?: string): Promise<GitDiff | undefined>;
/**
* Returns a file diff between a commit and the specified contents
* @param uri Uri of the file to diff
* @param ref Commit to diff from
* @param contents Contents to use for the diff
*/
getDiffForFileContents(uri: GitUri, ref: string, contents: string): Promise<GitDiff | undefined>;
/**
* Returns a line diff between two commits
* @param uri Uri of the file to diff
* @param editorLine Editor line number (0-based) to blame (Git is 1-based)
* @param ref1 Commit to diff from
* @param ref2 Commit to diff to
*/
getDiffForLine(
uri: GitUri,
editorLine: number,
ref1: string | undefined,
ref2?: string,
originalFileName?: string,
): Promise<GitDiffHunkLine | undefined>;
getDiffStatus(
repoPath: string,
@ -197,7 +206,7 @@ export interface GitProvider {
ref2?: string,
options?: { filters?: GitDiffFilter[] | undefined; similarityThreshold?: number | undefined },
): Promise<GitFile[] | undefined>;
getFileStatusForCommit(repoPath: string, fileName: string, ref: string): Promise<GitFile | undefined>;
getFileStatusForCommit(repoPath: string, uri: Uri, ref: string): Promise<GitFile | undefined>;
getLog(
repoPath: string,
options?: {
@ -280,51 +289,6 @@ export interface GitProvider {
editorLine?: number,
firstParent?: boolean,
): Promise<GitUri | undefined>;
// getPullRequestForBranch(
// branch: string,
// remote: GitRemote<RemoteProvider | RichRemoteProvider | undefined>,
// options?: {
// avatarSize?: number | undefined;
// include?: PullRequestState[] | undefined;
// limit?: number | undefined;
// timeout?: number | undefined;
// },
// ): Promise<PullRequest | undefined>;
// getPullRequestForBranch(
// branch: string,
// provider: RichRemoteProvider,
// options?: {
// avatarSize?: number | undefined;
// include?: PullRequestState[] | undefined;
// limit?: number | undefined;
// timeout?: number | undefined;
// },
// ): Promise<PullRequest | undefined>;
// getPullRequestForBranch(
// branch: string,
// remoteOrProvider: RichRemoteProvider | GitRemote<RemoteProvider | RichRemoteProvider | undefined>,
// options?: {
// avatarSize?: number | undefined;
// include?: PullRequestState[] | undefined;
// limit?: number | undefined;
// timeout?: number | undefined;
// },
// ): Promise<PullRequest | undefined>;
// getPullRequestForCommit(
// ref: string,
// remote: GitRemote<RemoteProvider | RichRemoteProvider | undefined>,
// options?: { timeout?: number | undefined },
// ): Promise<PullRequest | undefined>;
// getPullRequestForCommit(
// ref: string,
// provider: RichRemoteProvider,
// options?: { timeout?: number | undefined },
// ): Promise<PullRequest | undefined>;
// getPullRequestForCommit(
// ref: string,
// remoteOrProvider: RichRemoteProvider | GitRemote<RemoteProvider | RichRemoteProvider | undefined>,
// { timeout }?: { timeout?: number | undefined },
// ): Promise<PullRequest | undefined>;
getIncomingActivity(
repoPath: string,
options?: {
@ -356,39 +320,7 @@ export interface GitProvider {
providers?: RemoteProviders,
options?: { sort?: boolean | undefined },
): Promise<GitRemote<RemoteProvider | RichRemoteProvider | undefined>[]>;
// getRepoPath(filePath: string, options?: { ref?: string | undefined }): Promise<string | undefined>;
// getRepoPath(uri: Uri | undefined, options?: { ref?: string | undefined }): Promise<string | undefined>;
// getRepoPath(
// filePathOrUri: string | Uri | undefined,
// options?: { ref?: string | undefined },
// ): Promise<string | undefined>;
getRepoPath(filePath: string, isDirectory?: boolean): Promise<string | undefined>;
// getRepoPathOrActive(uri: Uri | undefined, editor: TextEditor | undefined): Promise<string | undefined>;
// getRepositories(predicate?: (repo: Repository) => boolean): Promise<Iterable<Repository>>;
// getOrderedRepositories(): Promise<Repository[]>;
// getRepository(
// repoPath: string,
// options?: { ref?: string | undefined; skipCacheUpdate?: boolean | undefined },
// ): Promise<Repository | undefined>;
// getRepository(
// uri: Uri,
// options?: { ref?: string | undefined; skipCacheUpdate?: boolean | undefined },
// ): Promise<Repository | undefined>;
// getRepository(
// repoPathOrUri: string | Uri,
// options?: { ref?: string | undefined; skipCacheUpdate?: boolean | undefined },
// ): Promise<Repository | undefined>;
// getRepository(
// repoPathOrUri: string | Uri,
// options?: { ref?: string | undefined; skipCacheUpdate?: boolean | undefined },
// ): Promise<Repository | undefined>;
// getLocalInfoFromRemoteUri(
// uri: Uri,
// options?: { validate?: boolean | undefined },
// ): Promise<{ uri: Uri; startLine?: number | undefined; endLine?: number | undefined } | undefined>;
// getRepositoryCount(): Promise<number>;
getStash(repoPath: string | undefined): Promise<GitStash | undefined>;
getStatusForFile(repoPath: string, fileName: string): Promise<GitStatusFile | undefined>;
getStatusForFiles(repoPath: string, pathOrGlob: string): Promise<GitStatusFile[] | undefined>;

+ 39
- 29
src/git/gitProviderService.ts View File

@ -766,7 +766,7 @@ export class GitProviderService implements Disposable {
@log()
/**
* Returns the blame of a file
* @param uri The uri of the file to blame
* @param uri Uri of the file to blame
*/
async getBlameForFile(uri: GitUri): Promise<GitBlame | undefined> {
const { provider } = this.getProvider(uri);
@ -776,8 +776,8 @@ export class GitProviderService implements Disposable {
@log<GitProviderService['getBlameForFileContents']>({ args: { 1: '<contents>' } })
/**
* Returns the blame of a file, using the editor contents (for dirty editors)
* @param uri The uri of the file to blame
* @param contents The editor contents to use
* @param uri Uri of the file to blame
* @param contents Contents from the editor to use
*/
async getBlameForFileContents(uri: GitUri, contents: string): Promise<GitBlame | undefined> {
const { provider } = this.getProvider(uri);
@ -787,8 +787,9 @@ export class GitProviderService implements Disposable {
@log()
/**
* Returns the blame of a single line
* @param uri The uri of the file to blame
* @param line The editor line number (0-based) to blame (Git is 1-based)
* @param uri Uri of the file to blame
* @param editorLine Editor line number (0-based) to blame (Git is 1-based)
* @param options.forceSingleLine Forces blame to be for the single line (rather than the whole file)
*/
async getBlameForLine(
uri: GitUri,
@ -802,9 +803,10 @@ export class GitProviderService implements Disposable {
@log<GitProviderService['getBlameForLineContents']>({ args: { 2: '<contents>' } })
/**
* Returns the blame of a single line, using the editor contents (for dirty editors)
* @param uri The uri of the file to blame
* @param line The editor line number (0-based) to blame (Git is 1-based)
* @param contents The editor contents to use
* @param uri Uri of the file to blame
* @param editorLine Editor line number (0-based) to blame (Git is 1-based)
* @param contents Contents from the editor to use
* @param options.forceSingleLine Forces blame to be for the single line (rather than the whole file)
*/
async getBlameForLineContents(
uri: GitUri,
@ -995,9 +997,9 @@ export class GitProviderService implements Disposable {
}
@log()
async getOldestUnpushedRefForFile(repoPath: string | Uri, fileName: string): Promise<string | undefined> {
async getOldestUnpushedRefForFile(repoPath: string | Uri, uri: Uri): Promise<string | undefined> {
const { provider, path } = this.getProvider(repoPath);
return provider.getOldestUnpushedRefForFile(path, fileName);
return provider.getOldestUnpushedRefForFile(path, uri);
}
// eslint-disable-next-line @typescript-eslint/require-await
@ -1034,37 +1036,45 @@ export class GitProviderService implements Disposable {
}
@log()
async getDiffForFile(
uri: GitUri,
ref1: string | undefined,
ref2?: string,
originalFileName?: string,
): Promise<GitDiff | undefined> {
/**
* Returns a file diff between two commits
* @param uri Uri of the file to diff
* @param ref1 Commit to diff from
* @param ref2 Commit to diff to
*/
async getDiffForFile(uri: GitUri, ref1: string | undefined, ref2?: string): Promise<GitDiff | undefined> {
const { provider } = this.getProvider(uri);
return provider.getDiffForFile(uri, ref1, ref2, originalFileName);
return provider.getDiffForFile(uri, ref1, ref2);
}
@log<GitProviderService['getDiffForFileContents']>({ args: { 1: '<contents>' } })
async getDiffForFileContents(
uri: GitUri,
ref: string,
contents: string,
originalFileName?: string,
): Promise<GitDiff | undefined> {
/**
* Returns a file diff between a commit and the specified contents
* @param uri Uri of the file to diff
* @param ref Commit to diff from
* @param contents Contents to use for the diff
*/
async getDiffForFileContents(uri: GitUri, ref: string, contents: string): Promise<GitDiff | undefined> {
const { provider } = this.getProvider(uri);
return provider.getDiffForFile(uri, ref, contents, originalFileName);
return provider.getDiffForFileContents(uri, ref, contents);
}
@log()
/**
* Returns a line diff between two commits
* @param uri Uri of the file to diff
* @param editorLine Editor line number (0-based) to blame (Git is 1-based)
* @param ref1 Commit to diff from
* @param ref2 Commit to diff to
*/
async getDiffForLine(
uri: GitUri,
editorLine: number, // editor lines are 0-based
editorLine: number,
ref1: string | undefined,
ref2?: string,
originalFileName?: string,
): Promise<GitDiffHunkLine | undefined> {
const { provider } = this.getProvider(uri);
return provider.getDiffForLine(uri, editorLine, ref1, ref2, originalFileName);
return provider.getDiffForLine(uri, editorLine, ref1, ref2);
}
@log()
@ -1079,11 +1089,11 @@ export class GitProviderService implements Disposable {
}
@log()
async getFileStatusForCommit(repoPath: string | Uri, fileName: string, ref: string): Promise<GitFile | undefined> {
async getFileStatusForCommit(repoPath: string | Uri, uri: Uri, ref: string): Promise<GitFile | undefined> {
if (ref === GitRevision.deletedOrMissing || GitRevision.isUncommitted(ref)) return undefined;
const { provider, path } = this.getProvider(repoPath);
return provider.getFileStatusForCommit(path, fileName, ref);
return provider.getFileStatusForCommit(path, uri, ref);
}
@log()

+ 1
- 2
src/hovers/hovers.ts View File

@ -51,7 +51,7 @@ export namespace Hovers {
editorLine = commitLine.line - 1;
// TODO: Doesn't work with dirty files -- pass in editor? or contents?
hunkLine = await Container.instance.git.getDiffForLine(uri, editorLine, ref, documentRef, originalFileName);
hunkLine = await Container.instance.git.getDiffForLine(uri, editorLine, ref, documentRef);
// If we didn't find a diff & ref is undefined (meaning uncommitted), check for a staged diff
if (hunkLine == null && ref == null) {
@ -60,7 +60,6 @@ export namespace Hovers {
editorLine,
undefined,
GitRevision.uncommittedStaged,
originalFileName,
);
}
}

Loading…
Cancel
Save