mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-14 10:03:15 -05:00
Switches to use GitUris in more places
This commit is contained in:
@@ -299,7 +299,7 @@ export class BlameActiveLineController extends Disposable {
|
||||
hoverMessage = BlameAnnotationFormatter.getAnnotationHover(cfg, blameLine, logCommit || commit);
|
||||
|
||||
// if (commit.previousSha !== undefined) {
|
||||
// const changes = await this.git.getDiffForLine(this._uri.repoPath, this._uri.fsPath, blameLine.line + offset, commit.previousSha);
|
||||
// const changes = await this.git.getDiffForLine(this._uri, blameLine.line + offset, commit.previousSha);
|
||||
// if (changes !== undefined) {
|
||||
// const previous = changes[0];
|
||||
// if (previous !== undefined) {
|
||||
@@ -312,7 +312,7 @@ export class BlameActiveLineController extends Disposable {
|
||||
// }
|
||||
}
|
||||
else if (commit.isUncommitted) {
|
||||
const changes = await this.git.getDiffForLine(this._uri.repoPath, this._uri.fsPath, blameLine.line + offset);
|
||||
const changes = await this.git.getDiffForLine(this._uri, blameLine.line + offset);
|
||||
if (changes !== undefined) {
|
||||
let original = changes[0];
|
||||
if (original !== undefined) {
|
||||
|
||||
@@ -62,8 +62,8 @@ export class GitContextTracker extends Disposable {
|
||||
}
|
||||
|
||||
private _onBlameFailed(key: string) {
|
||||
const fileName = this._editor && this._editor.document && this._editor.document.fileName;
|
||||
if (!fileName || key !== this.git.getCacheEntryKey(fileName)) return;
|
||||
if (this._editor === undefined || this._editor.document === undefined || this._editor.document.uri === undefined) return;
|
||||
if (key !== this.git.getCacheEntryKey(this._editor.document.uri)) return;
|
||||
|
||||
this._updateBlameability(false);
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ export class GitUri extends Uri {
|
||||
if (commit !== undefined) return new GitUri(uri, commit);
|
||||
}
|
||||
|
||||
const gitUri = git.getGitUriForFile(uri.fsPath);
|
||||
const gitUri = git.getGitUriForFile(uri);
|
||||
if (gitUri) return gitUri;
|
||||
|
||||
return new GitUri(uri, (await git.getRepoPathFromFile(uri.fsPath)) || git.repoPath);
|
||||
|
||||
@@ -219,7 +219,7 @@ export class GitService extends Disposable {
|
||||
if (!this.UseCaching) return;
|
||||
if (document.uri.scheme !== DocumentSchemes.File) return;
|
||||
|
||||
const cacheKey = this.getCacheEntryKey(document.fileName);
|
||||
const cacheKey = this.getCacheEntryKey(document.uri);
|
||||
|
||||
if (reason === RemoveCacheReason.DocumentSaved) {
|
||||
// Don't remove broken blame on save (since otherwise we'll have to run the broken blame again)
|
||||
@@ -313,7 +313,7 @@ export class GitService extends Disposable {
|
||||
public async getBlameability(uri: GitUri): Promise<boolean> {
|
||||
if (!this.UseCaching) return await this.isTracked(uri);
|
||||
|
||||
const cacheKey = this.getCacheEntryKey(uri.fsPath);
|
||||
const cacheKey = this.getCacheEntryKey(uri);
|
||||
const entry = this._gitCache.get(cacheKey);
|
||||
if (entry === undefined) return await this.isTracked(uri);
|
||||
|
||||
@@ -326,11 +326,9 @@ export class GitService extends Disposable {
|
||||
key += `:${uri.sha}`;
|
||||
}
|
||||
|
||||
const fileName = uri.fsPath;
|
||||
|
||||
let entry: GitCacheEntry | undefined;
|
||||
if (this.UseCaching) {
|
||||
const cacheKey = this.getCacheEntryKey(fileName);
|
||||
const cacheKey = this.getCacheEntryKey(uri);
|
||||
entry = this._gitCache.get(cacheKey);
|
||||
|
||||
if (entry !== undefined) {
|
||||
@@ -352,7 +350,7 @@ export class GitService extends Disposable {
|
||||
Logger.log(`getBlameForFile('${uri.repoPath}', '${uri.fsPath}', ${uri.sha})`);
|
||||
}
|
||||
|
||||
const promise = this._getBlameForFile(uri, fileName, entry, key);
|
||||
const promise = this._getBlameForFile(uri, entry, key);
|
||||
|
||||
if (entry) {
|
||||
Logger.log(`Add blame cache for '${entry.key}:${key}'`);
|
||||
@@ -365,12 +363,12 @@ export class GitService extends Disposable {
|
||||
return promise;
|
||||
}
|
||||
|
||||
private async _getBlameForFile(uri: GitUri, fileName: string, entry: GitCacheEntry | undefined, key: string): Promise<IGitBlame | undefined> {
|
||||
const [file, root] = Git.splitPath(fileName, uri.repoPath, false);
|
||||
private async _getBlameForFile(uri: GitUri, entry: GitCacheEntry | undefined, key: string): Promise<IGitBlame | undefined> {
|
||||
const [file, root] = Git.splitPath(uri.fsPath, uri.repoPath, false);
|
||||
|
||||
const ignore = await this._gitignore;
|
||||
if (ignore && !ignore.filter([file]).length) {
|
||||
Logger.log(`Skipping blame; '${fileName}' is gitignored`);
|
||||
Logger.log(`Skipping blame; '${uri.fsPath}' is gitignored`);
|
||||
if (entry && entry.key) {
|
||||
this._onDidBlameFail.fire(entry.key);
|
||||
}
|
||||
@@ -537,8 +535,10 @@ export class GitService extends Disposable {
|
||||
return branches;
|
||||
}
|
||||
|
||||
getCacheEntryKey(fileName: string) {
|
||||
return Git.normalizePath(fileName).toLowerCase();
|
||||
getCacheEntryKey(fileName: string): string;
|
||||
getCacheEntryKey(uri: Uri): string;
|
||||
getCacheEntryKey(fileNameOrUri: string | Uri): string {
|
||||
return Git.normalizePath(typeof fileNameOrUri === 'string' ? fileNameOrUri : fileNameOrUri.fsPath).toLowerCase();
|
||||
}
|
||||
|
||||
async getConfig(key: string, repoPath?: string): Promise<string> {
|
||||
@@ -547,13 +547,13 @@ export class GitService extends Disposable {
|
||||
return await Git.config_get(key, repoPath);
|
||||
}
|
||||
|
||||
getGitUriForFile(fileName: string) {
|
||||
const cacheKey = this.getCacheEntryKey(fileName);
|
||||
getGitUriForFile(uri: Uri) {
|
||||
const cacheKey = this.getCacheEntryKey(uri);
|
||||
const entry = this._uriCache.get(cacheKey);
|
||||
return entry && entry.uri;
|
||||
}
|
||||
|
||||
async getDiffForFile(repoPath: string | undefined, fileName: string, sha1?: string, sha2?: string): Promise<IGitDiff | undefined> {
|
||||
async getDiffForFile(uri: GitUri, sha1?: string, sha2?: string): Promise<IGitDiff | undefined> {
|
||||
let key = 'diff';
|
||||
if (sha1 !== undefined) {
|
||||
key += `:${sha1}`;
|
||||
@@ -564,18 +564,18 @@ export class GitService extends Disposable {
|
||||
|
||||
let entry: GitCacheEntry | undefined;
|
||||
if (this.UseCaching) {
|
||||
const cacheKey = this.getCacheEntryKey(fileName);
|
||||
const cacheKey = this.getCacheEntryKey(uri);
|
||||
entry = this._gitCache.get(cacheKey);
|
||||
|
||||
if (entry !== undefined) {
|
||||
const cachedDiff = entry.get<ICachedDiff>(key);
|
||||
if (cachedDiff !== undefined) {
|
||||
Logger.log(`Cached(${key}): getDiffForFile('${repoPath}', '${fileName}', ${sha1}, ${sha2})`);
|
||||
Logger.log(`Cached(${key}): getDiffForFile('${uri.repoPath}', '${uri.fsPath}', ${sha1}, ${sha2})`);
|
||||
return cachedDiff.item;
|
||||
}
|
||||
}
|
||||
|
||||
Logger.log(`Not Cached(${key}): getDiffForFile('${repoPath}', '${fileName}', ${sha1}, ${sha2})`);
|
||||
Logger.log(`Not Cached(${key}): getDiffForFile('${uri.repoPath}', '${uri.fsPath}', ${sha1}, ${sha2})`);
|
||||
|
||||
if (entry === undefined) {
|
||||
entry = new GitCacheEntry(cacheKey);
|
||||
@@ -583,10 +583,10 @@ export class GitService extends Disposable {
|
||||
}
|
||||
}
|
||||
else {
|
||||
Logger.log(`getDiffForFile('${repoPath}', '${fileName}', ${sha1}, ${sha2})`);
|
||||
Logger.log(`getDiffForFile('${uri.repoPath}', '${uri.fsPath}', ${sha1}, ${sha2})`);
|
||||
}
|
||||
|
||||
const promise = this._getDiffForFile(repoPath, fileName, sha1, sha2, entry, key);
|
||||
const promise = this._getDiffForFile(uri.repoPath, uri.fsPath, sha1, sha2, entry, key);
|
||||
|
||||
if (entry) {
|
||||
Logger.log(`Add log cache for '${entry.key}:${key}'`);
|
||||
@@ -624,9 +624,9 @@ export class GitService extends Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
async getDiffForLine(repoPath: string | undefined, fileName: string, line: number, sha1?: string, sha2?: string): Promise<[string | undefined, string | undefined] | undefined> {
|
||||
async getDiffForLine(uri: GitUri, line: number, sha1?: string, sha2?: string): Promise<[string | undefined, string | undefined] | undefined> {
|
||||
try {
|
||||
const diff = await this.getDiffForFile(repoPath, fileName, sha1, sha2);
|
||||
const diff = await this.getDiffForFile(uri, sha1, sha2);
|
||||
if (diff === undefined) return undefined;
|
||||
|
||||
const chunk = diff.chunks.find(_ => Math.min(_.originalStart, _.changesStart) <= line && Math.max(_.originalEnd, _.changesEnd) >= line);
|
||||
@@ -913,19 +913,10 @@ export class GitService extends Disposable {
|
||||
return Git.show(repoPath, fileName, sha);
|
||||
}
|
||||
|
||||
hasGitUriForFile(editor: TextEditor): boolean;
|
||||
hasGitUriForFile(fileName: string): boolean;
|
||||
hasGitUriForFile(fileNameOrEditor: string | TextEditor): boolean {
|
||||
let fileName: string;
|
||||
if (typeof fileNameOrEditor === 'string') {
|
||||
fileName = fileNameOrEditor;
|
||||
}
|
||||
else {
|
||||
if (!fileNameOrEditor || !fileNameOrEditor.document || !fileNameOrEditor.document.uri) return false;
|
||||
fileName = fileNameOrEditor.document.uri.fsPath;
|
||||
}
|
||||
hasGitUriForFile(editor: TextEditor): boolean {
|
||||
if (editor === undefined || editor.document === undefined || editor.document.uri === undefined) return false;
|
||||
|
||||
const cacheKey = this.getCacheEntryKey(fileName);
|
||||
const cacheKey = this.getCacheEntryKey(editor.document.uri);
|
||||
return this._uriCache.has(cacheKey);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user