Fixes issue where original filename got lost

Fixes file path normalization
This commit is contained in:
Eric Amodio
2016-09-15 12:33:43 -04:00
parent b617a90c5b
commit 7a604191a7
3 changed files with 18 additions and 8 deletions

View File

@@ -19,9 +19,10 @@ export function activate(context: ExtensionContext) {
return; return;
} }
console.log(`GitLens active: ${workspace.rootPath}`); const rootPath = workspace.rootPath.replace(/\\/g, '/');
console.log(`GitLens active: ${rootPath}`);
Git.repoPath(workspace.rootPath).then(repoPath => { Git.repoPath(rootPath).then(repoPath => {
context.workspaceState.update(WorkspaceState.RepoPath, repoPath); context.workspaceState.update(WorkspaceState.RepoPath, repoPath);
context.workspaceState.update(WorkspaceState.HasGitHistoryExtension, extensions.getExtension('donjayamanne.githistory') !== undefined); context.workspaceState.update(WorkspaceState.HasGitHistoryExtension, extensions.getExtension('donjayamanne.githistory') !== undefined);

View File

@@ -23,11 +23,12 @@ function gitCommand(cwd: string, ...args) {
export default class Git { export default class Git {
static normalizePath(fileName: string, repoPath: string) { static normalizePath(fileName: string, repoPath: string) {
fileName = fileName.replace(/\\/g, '/');
repoPath = repoPath.replace(/\\/g, '/'); repoPath = repoPath.replace(/\\/g, '/');
if (isAbsolute(fileName) && fileName.startsWith(repoPath)) { if (isAbsolute(fileName) && fileName.startsWith(repoPath)) {
fileName = relative(repoPath, fileName); fileName = relative(repoPath, fileName).replace(/\\/g, '/');
} }
return fileName.replace(/\\/g, '/'); return fileName;
} }
static repoPath(cwd: string) { static repoPath(cwd: string) {

View File

@@ -104,7 +104,7 @@ export default class GitProvider extends Disposable {
} }
if (this._blames.delete(cacheKey)) { if (this._blames.delete(cacheKey)) {
console.log('[GitLens]', `Clear blame cache: fileName=${fileName}, reason=${RemoveCacheReason[reason]})`); console.log('[GitLens]', `Clear blame cache: cacheKey=${cacheKey}, reason=${RemoveCacheReason[reason]}`);
// if (reason === RemoveCacheReason.DocumentSaved) { // if (reason === RemoveCacheReason.DocumentSaved) {
// // TODO: Killing the code lens provider is too drastic -- makes the editor jump around, need to figure out how to trigger a refresh // // TODO: Killing the code lens provider is too drastic -- makes the editor jump around, need to figure out how to trigger a refresh
@@ -209,6 +209,7 @@ export default class GitProvider extends Disposable {
blame.catch(ex => { blame.catch(ex => {
const msg = ex && ex.toString(); const msg = ex && ex.toString();
if (msg && (msg.includes('is outside repository') || msg.includes('no such path'))) { if (msg && (msg.includes('is outside repository') || msg.includes('no such path'))) {
console.log('[GitLens]', `Replace blame cache: cacheKey=${cacheKey}`);
this._blames.set(cacheKey, <IBlameCacheEntry>{ this._blames.set(cacheKey, <IBlameCacheEntry>{
//date: new Date(), //date: new Date(),
blame: GitProvider.BlameEmptyPromise, blame: GitProvider.BlameEmptyPromise,
@@ -227,6 +228,7 @@ export default class GitProvider extends Disposable {
}); });
} }
console.log('[GitLens]', `Add blame cache: cacheKey=${cacheKey}`);
this._blames.set(cacheKey, <IBlameCacheEntry> { this._blames.set(cacheKey, <IBlameCacheEntry> {
//date: new Date(), //date: new Date(),
blame: blame blame: blame
@@ -269,7 +271,8 @@ export default class GitProvider extends Disposable {
blame.commits.forEach(c => { blame.commits.forEach(c => {
if (!shas.has(c.sha)) return; if (!shas.has(c.sha)) return;
const commit: IGitCommit = new GitCommit(this.repoPath, c.sha, c.fileName, c.author, c.date, c.message, c.lines.filter(l => l.line >= range.start.line && l.line <= range.end.line)); const commit: IGitCommit = new GitCommit(this.repoPath, c.sha, c.fileName, c.author, c.date, c.message,
c.lines.filter(l => l.line >= range.start.line && l.line <= range.end.line), c.originalFileName, c.previousSha, c.previousFileName);
commits.set(c.sha, commit); commits.set(c.sha, commit);
let author = authors.get(commit.author); let author = authors.get(commit.author);
@@ -304,7 +307,8 @@ export default class GitProvider extends Disposable {
const lines = blame.lines.slice(range.start.line, range.end.line + 1).filter(l => l.sha === sha); const lines = blame.lines.slice(range.start.line, range.end.line + 1).filter(l => l.sha === sha);
let commit = blame.commits.get(sha); let commit = blame.commits.get(sha);
commit = new GitCommit(this.repoPath, commit.sha, commit.fileName, commit.author, commit.date, commit.message, lines); commit = new GitCommit(this.repoPath, commit.sha, commit.fileName, commit.author, commit.date, commit.message,
lines, commit.originalFileName, commit.previousSha, commit.previousFileName);
return { return {
author: Object.assign({}, blame.authors.get(commit.author), { lineCount: commit.lines.length }), author: Object.assign({}, blame.authors.get(commit.author), { lineCount: commit.lines.length }),
commit: commit, commit: commit,
@@ -445,8 +449,12 @@ class GitCommit implements IGitCommit {
previousSha?: string; previousSha?: string;
previousFileName?: string; previousFileName?: string;
constructor(private repoPath: string, public sha: string, public fileName: string, public author: string, public date: Date, public message: string, lines?: IGitCommitLine[]) { constructor(private repoPath: string, public sha: string, public fileName: string, public author: string, public date: Date, public message: string,
lines?: IGitCommitLine[], originalFileName?: string, previousSha?: string, previousFileName?: string) {
this.lines = lines || []; this.lines = lines || [];
this.originalFileName = originalFileName;
this.previousSha = previousSha;
this.previousFileName = previousFileName;
} }
toPreviousUri(): Uri { toPreviousUri(): Uri {