Procházet zdrojové kódy

Converts more file paths to Uris

Adds more docs
Removes unused original file name from diff calls
main
Eric Amodio před 2 roky
rodič
revize
d1002c3ed0
6 změnil soubory, kde provedl 92 přidání a 172 odebrání
  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 Zobrazit soubor

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

+ 1
- 1
src/commands/diffWith.ts Zobrazit soubor

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

+ 17
- 38
src/env/node/git/localGitProvider.ts Zobrazit soubor

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

+ 33
- 101
src/git/gitProvider.ts Zobrazit soubor

@ -104,21 +104,23 @@ export interface GitProvider {
remote?: string | undefined; remote?: string | undefined;
}, },
): Promise<void>; ): Promise<void>;
getAheadBehindCommitCount(repoPath: string, refs: string[]): Promise<{ ahead: number; behind: number } | undefined>;
/** /**
* Returns the blame of a file * 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>; getBlameForFile(uri: GitUri): Promise<GitBlame | undefined>;
/** /**
* Returns the blame of a file, using the editor contents (for dirty editors) * 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>; getBlameForFileContents(uri: GitUri, contents: string): Promise<GitBlame | undefined>;
/** /**
* Returns the blame of a single line * 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( getBlameForLine(
uri: GitUri, uri: GitUri,
@ -127,9 +129,9 @@ export interface GitProvider {
): Promise<GitBlameLine | undefined>; ): Promise<GitBlameLine | undefined>;
/** /**
* Returns the blame of a single line, using the editor contents (for dirty editors) * 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( getBlameForLineContents(
uri: GitUri, uri: GitUri,
@ -152,7 +154,6 @@ export interface GitProvider {
ref: string, ref: string,
options?: { mode?: 'contains' | 'pointsAt' | undefined; remotes?: boolean | undefined }, options?: { mode?: 'contains' | 'pointsAt' | undefined; remotes?: boolean | undefined },
): Promise<string[]>; ): Promise<string[]>;
getAheadBehindCommitCount(repoPath: string, refs: string[]): Promise<{ ahead: number; behind: number } | undefined>;
getCommitCount(repoPath: string, ref: string): Promise<number | undefined>; getCommitCount(repoPath: string, ref: string): Promise<number | undefined>;
getCommitForFile( getCommitForFile(
repoPath: string, repoPath: string,
@ -164,7 +165,7 @@ export interface GitProvider {
reverse?: boolean | undefined; reverse?: boolean | undefined;
}, },
): Promise<GitLogCommit | 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>; getConfig(key: string, repoPath?: string): Promise<string | undefined>;
getContributors( getContributors(
repoPath: string, repoPath: string,
@ -172,24 +173,32 @@ export interface GitProvider {
): Promise<GitContributor[]>; ): Promise<GitContributor[]>;
getCurrentUser(repoPath: string): Promise<GitUser | undefined>; getCurrentUser(repoPath: string): Promise<GitUser | undefined>;
getDefaultBranchName(repoPath: string | undefined, remote?: string): Promise<string | 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( getDiffForLine(
uri: GitUri, uri: GitUri,
editorLine: number, editorLine: number,
ref1: string | undefined, ref1: string | undefined,
ref2?: string, ref2?: string,
originalFileName?: string,
): Promise<GitDiffHunkLine | undefined>; ): Promise<GitDiffHunkLine | undefined>;
getDiffStatus( getDiffStatus(
repoPath: string, repoPath: string,
@ -197,7 +206,7 @@ export interface GitProvider {
ref2?: string, ref2?: string,
options?: { filters?: GitDiffFilter[] | undefined; similarityThreshold?: number | undefined }, options?: { filters?: GitDiffFilter[] | undefined; similarityThreshold?: number | undefined },
): Promise<GitFile[] | 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( getLog(
repoPath: string, repoPath: string,
options?: { options?: {
@ -280,51 +289,6 @@ export interface GitProvider {
editorLine?: number, editorLine?: number,
firstParent?: boolean, firstParent?: boolean,
): Promise<GitUri | undefined>; ): 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( getIncomingActivity(
repoPath: string, repoPath: string,
options?: { options?: {
@ -356,39 +320,7 @@ export interface GitProvider {
providers?: RemoteProviders, providers?: RemoteProviders,
options?: { sort?: boolean | undefined }, options?: { sort?: boolean | undefined },
): Promise<GitRemote<RemoteProvider | RichRemoteProvider | 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>; 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>; getStash(repoPath: string | undefined): Promise<GitStash | undefined>;
getStatusForFile(repoPath: string, fileName: string): Promise<GitStatusFile | undefined>; getStatusForFile(repoPath: string, fileName: string): Promise<GitStatusFile | undefined>;
getStatusForFiles(repoPath: string, pathOrGlob: string): Promise<GitStatusFile[] | undefined>; getStatusForFiles(repoPath: string, pathOrGlob: string): Promise<GitStatusFile[] | undefined>;

+ 39
- 29
src/git/gitProviderService.ts Zobrazit soubor

@ -766,7 +766,7 @@ export class GitProviderService implements Disposable {
@log() @log()
/** /**
* Returns the blame of a file * 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> { async getBlameForFile(uri: GitUri): Promise<GitBlame | undefined> {
const { provider } = this.getProvider(uri); const { provider } = this.getProvider(uri);
@ -776,8 +776,8 @@ export class GitProviderService implements Disposable {
@log<GitProviderService['getBlameForFileContents']>({ args: { 1: '<contents>' } }) @log<GitProviderService['getBlameForFileContents']>({ args: { 1: '<contents>' } })
/** /**
* Returns the blame of a file, using the editor contents (for dirty editors) * 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> { async getBlameForFileContents(uri: GitUri, contents: string): Promise<GitBlame | undefined> {
const { provider } = this.getProvider(uri); const { provider } = this.getProvider(uri);
@ -787,8 +787,9 @@ export class GitProviderService implements Disposable {
@log() @log()
/** /**
* Returns the blame of a single line * 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( async getBlameForLine(
uri: GitUri, uri: GitUri,
@ -802,9 +803,10 @@ export class GitProviderService implements Disposable {
@log<GitProviderService['getBlameForLineContents']>({ args: { 2: '<contents>' } }) @log<GitProviderService['getBlameForLineContents']>({ args: { 2: '<contents>' } })
/** /**
* Returns the blame of a single line, using the editor contents (for dirty editors) * 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( async getBlameForLineContents(
uri: GitUri, uri: GitUri,
@ -995,9 +997,9 @@ export class GitProviderService implements Disposable {
} }
@log() @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); const { provider, path } = this.getProvider(repoPath);
return provider.getOldestUnpushedRefForFile(path, fileName);
return provider.getOldestUnpushedRefForFile(path, uri);
} }
// eslint-disable-next-line @typescript-eslint/require-await // eslint-disable-next-line @typescript-eslint/require-await
@ -1034,37 +1036,45 @@ export class GitProviderService implements Disposable {
} }
@log() @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); const { provider } = this.getProvider(uri);
return provider.getDiffForFile(uri, ref1, ref2, originalFileName);
return provider.getDiffForFile(uri, ref1, ref2);
} }
@log<GitProviderService['getDiffForFileContents']>({ args: { 1: '<contents>' } }) @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); const { provider } = this.getProvider(uri);
return provider.getDiffForFile(uri, ref, contents, originalFileName);
return provider.getDiffForFileContents(uri, ref, contents);
} }
@log() @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( async getDiffForLine(
uri: GitUri, uri: GitUri,
editorLine: number, // editor lines are 0-based
editorLine: number,
ref1: string | undefined, ref1: string | undefined,
ref2?: string, ref2?: string,
originalFileName?: string,
): Promise<GitDiffHunkLine | undefined> { ): Promise<GitDiffHunkLine | undefined> {
const { provider } = this.getProvider(uri); const { provider } = this.getProvider(uri);
return provider.getDiffForLine(uri, editorLine, ref1, ref2, originalFileName);
return provider.getDiffForLine(uri, editorLine, ref1, ref2);
} }
@log() @log()
@ -1079,11 +1089,11 @@ export class GitProviderService implements Disposable {
} }
@log() @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; if (ref === GitRevision.deletedOrMissing || GitRevision.isUncommitted(ref)) return undefined;
const { provider, path } = this.getProvider(repoPath); const { provider, path } = this.getProvider(repoPath);
return provider.getFileStatusForCommit(path, fileName, ref);
return provider.getFileStatusForCommit(path, uri, ref);
} }
@log() @log()

+ 1
- 2
src/hovers/hovers.ts Zobrazit soubor

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

Načítá se…
Zrušit
Uložit