diff --git a/src/annotations/gutterChangesAnnotationProvider.ts b/src/annotations/gutterChangesAnnotationProvider.ts index fcb8e80..fb0995c 100644 --- a/src/annotations/gutterChangesAnnotationProvider.ts +++ b/src/annotations/gutterChangesAnnotationProvider.ts @@ -80,7 +80,7 @@ export class GutterChangesAnnotationProvider extends AnnotationProviderBase({ 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 { const cc = Logger.getCorrelationContext(); @@ -1175,14 +1183,6 @@ export class LocalGitProvider implements GitProvider, Disposable { .filter((i?: T): i is T => Boolean(i)); } - @log({ 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 { 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 { - const data = await Git.log__file(repoPath, fileName, '@{push}..', { + async getOldestUnpushedRefForFile(repoPath: string, uri: Uri): Promise { + 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 { + async getDiffForFile(uri: GitUri, ref1: string | undefined, ref2?: string): Promise { 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, 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({ args: { 1: '' } }) - async getDiffForFileContents( - uri: GitUri, - ref: string, - contents: string, - originalFileName?: string, - ): Promise { + async getDiffForFileContents(uri: GitUri, ref: string, contents: string): Promise { 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, 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 { 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 { + async getFileStatusForCommit(repoPath: string, uri: Uri, ref: string): Promise { 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); diff --git a/src/git/gitProvider.ts b/src/git/gitProvider.ts index 1f0f5f0..1f64a5a 100644 --- a/src/git/gitProvider.ts +++ b/src/git/gitProvider.ts @@ -104,21 +104,23 @@ export interface GitProvider { remote?: string | undefined; }, ): Promise; + 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; /** * 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; /** * 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; /** * 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; - getAheadBehindCommitCount(repoPath: string, refs: string[]): Promise<{ ahead: number; behind: number } | undefined>; getCommitCount(repoPath: string, ref: string): Promise; getCommitForFile( repoPath: string, @@ -164,7 +165,7 @@ export interface GitProvider { reverse?: boolean | undefined; }, ): Promise; - getOldestUnpushedRefForFile(repoPath: string, fileName: string): Promise; + getOldestUnpushedRefForFile(repoPath: string, uri: Uri): Promise; getConfig(key: string, repoPath?: string): Promise; getContributors( repoPath: string, @@ -172,24 +173,32 @@ export interface GitProvider { ): Promise; getCurrentUser(repoPath: string): Promise; getDefaultBranchName(repoPath: string | undefined, remote?: string): Promise; - getDiffForFile( - uri: GitUri, - ref1: string | undefined, - ref2?: string, - originalFileName?: string, - ): Promise; - getDiffForFileContents( - uri: GitUri, - ref: string, - contents: string, - originalFileName?: string, - ): Promise; + /** + * 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; + /** + * 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; + /** + * 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; getDiffStatus( repoPath: string, @@ -197,7 +206,7 @@ export interface GitProvider { ref2?: string, options?: { filters?: GitDiffFilter[] | undefined; similarityThreshold?: number | undefined }, ): Promise; - getFileStatusForCommit(repoPath: string, fileName: string, ref: string): Promise; + getFileStatusForCommit(repoPath: string, uri: Uri, ref: string): Promise; getLog( repoPath: string, options?: { @@ -280,51 +289,6 @@ export interface GitProvider { editorLine?: number, firstParent?: boolean, ): Promise; - // getPullRequestForBranch( - // branch: string, - // remote: GitRemote, - // options?: { - // avatarSize?: number | undefined; - // include?: PullRequestState[] | undefined; - // limit?: number | undefined; - // timeout?: number | undefined; - // }, - // ): Promise; - // getPullRequestForBranch( - // branch: string, - // provider: RichRemoteProvider, - // options?: { - // avatarSize?: number | undefined; - // include?: PullRequestState[] | undefined; - // limit?: number | undefined; - // timeout?: number | undefined; - // }, - // ): Promise; - // getPullRequestForBranch( - // branch: string, - // remoteOrProvider: RichRemoteProvider | GitRemote, - // options?: { - // avatarSize?: number | undefined; - // include?: PullRequestState[] | undefined; - // limit?: number | undefined; - // timeout?: number | undefined; - // }, - // ): Promise; - // getPullRequestForCommit( - // ref: string, - // remote: GitRemote, - // options?: { timeout?: number | undefined }, - // ): Promise; - // getPullRequestForCommit( - // ref: string, - // provider: RichRemoteProvider, - // options?: { timeout?: number | undefined }, - // ): Promise; - // getPullRequestForCommit( - // ref: string, - // remoteOrProvider: RichRemoteProvider | GitRemote, - // { timeout }?: { timeout?: number | undefined }, - // ): Promise; getIncomingActivity( repoPath: string, options?: { @@ -356,39 +320,7 @@ export interface GitProvider { providers?: RemoteProviders, options?: { sort?: boolean | undefined }, ): Promise[]>; - // getRepoPath(filePath: string, options?: { ref?: string | undefined }): Promise; - // getRepoPath(uri: Uri | undefined, options?: { ref?: string | undefined }): Promise; - // getRepoPath( - // filePathOrUri: string | Uri | undefined, - // options?: { ref?: string | undefined }, - // ): Promise; - getRepoPath(filePath: string, isDirectory?: boolean): Promise; - - // getRepoPathOrActive(uri: Uri | undefined, editor: TextEditor | undefined): Promise; - // getRepositories(predicate?: (repo: Repository) => boolean): Promise>; - // getOrderedRepositories(): Promise; - // getRepository( - // repoPath: string, - // options?: { ref?: string | undefined; skipCacheUpdate?: boolean | undefined }, - // ): Promise; - // getRepository( - // uri: Uri, - // options?: { ref?: string | undefined; skipCacheUpdate?: boolean | undefined }, - // ): Promise; - // getRepository( - // repoPathOrUri: string | Uri, - // options?: { ref?: string | undefined; skipCacheUpdate?: boolean | undefined }, - // ): Promise; - // getRepository( - // repoPathOrUri: string | Uri, - // options?: { ref?: string | undefined; skipCacheUpdate?: boolean | undefined }, - // ): Promise; - // getLocalInfoFromRemoteUri( - // uri: Uri, - // options?: { validate?: boolean | undefined }, - // ): Promise<{ uri: Uri; startLine?: number | undefined; endLine?: number | undefined } | undefined>; - // getRepositoryCount(): Promise; getStash(repoPath: string | undefined): Promise; getStatusForFile(repoPath: string, fileName: string): Promise; getStatusForFiles(repoPath: string, pathOrGlob: string): Promise; diff --git a/src/git/gitProviderService.ts b/src/git/gitProviderService.ts index 32d6bc8..c133fb7 100644 --- a/src/git/gitProviderService.ts +++ b/src/git/gitProviderService.ts @@ -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 { const { provider } = this.getProvider(uri); @@ -776,8 +776,8 @@ export class GitProviderService implements Disposable { @log({ args: { 1: '' } }) /** * 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 { 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({ args: { 2: '' } }) /** * 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 { + async getOldestUnpushedRefForFile(repoPath: string | Uri, uri: Uri): Promise { 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 { + /** + * 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 { const { provider } = this.getProvider(uri); - return provider.getDiffForFile(uri, ref1, ref2, originalFileName); + return provider.getDiffForFile(uri, ref1, ref2); } @log({ args: { 1: '' } }) - async getDiffForFileContents( - uri: GitUri, - ref: string, - contents: string, - originalFileName?: string, - ): Promise { + /** + * 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 { 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 { 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 { + async getFileStatusForCommit(repoPath: string | Uri, uri: Uri, ref: string): Promise { 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() diff --git a/src/hovers/hovers.ts b/src/hovers/hovers.ts index b8b8510..6348768 100644 --- a/src/hovers/hovers.ts +++ b/src/hovers/hovers.ts @@ -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, ); } }