Switches everything to use full shas

This commit is contained in:
Eric Amodio
2017-03-10 22:26:48 -05:00
parent df838e883a
commit 762fa545c7
20 changed files with 60 additions and 37 deletions

View File

@@ -5,6 +5,7 @@ import * as path from 'path';
interface IBlameEntry {
sha: string;
line: number;
originalLine: number;
lineCount: number;
@@ -53,7 +54,7 @@ export class GitBlameParserEnricher implements IGitEnricher<IGitBlame> {
if (!entry) {
entry = {
sha: lineParts[0].substring(0, 8),
sha: lineParts[0],
originalLine: parseInt(lineParts[1], 10) - 1,
line: parseInt(lineParts[2], 10) - 1,
lineCount: parseInt(lineParts[3], 10)
@@ -102,7 +103,7 @@ export class GitBlameParserEnricher implements IGitEnricher<IGitBlame> {
break;
case 'previous':
entry.previousSha = lineParts[1].substring(0, 8);
entry.previousSha = lineParts[1];
entry.previousFileName = lineParts.slice(2).join(' ');
break;

View File

@@ -21,6 +21,8 @@ interface ILogEntry {
summary?: string;
}
const shaRegex = /^[a-f0-9]{40}$/;
export class GitLogParserEnricher implements IGitEnricher<IGitLog> {
private _parseEntries(data: string, isRepoPath: boolean): ILogEntry[] {
@@ -40,9 +42,9 @@ export class GitLogParserEnricher implements IGitEnricher<IGitLog> {
}
if (!entry) {
if (!/^[a-f0-9]{40}$/.test(lineParts[0])) continue;
if (!shaRegex.test(lineParts[0])) continue;
entry = {
sha: lineParts[0].substring(0, 8)
sha: lineParts[0]
};
continue;

View File

@@ -115,9 +115,10 @@ export default class Git {
static async getVersionedFile(fileName: string, repoPath: string, sha: string) {
const data = await Git.getVersionedFileText(fileName, repoPath, sha);
const shortSha = sha.substring(0, 8);
const ext = path.extname(fileName);
return new Promise<string>((resolve, reject) => {
tmp.file({ prefix: `${path.basename(fileName, ext)}-${sha}__`, postfix: ext },
tmp.file({ prefix: `${path.basename(fileName, ext)}-${shortSha}__`, postfix: ext },
(err, destination, fd, cleanupCallback) => {
if (err) {
reject(err);

View File

@@ -80,6 +80,10 @@ export class GitCommit implements IGitCommit {
this.previousFileName = previousFileName;
}
get shortSha() {
return this.sha.substring(0, 8);
}
get isUncommitted(): boolean {
if (this._isUncommitted === undefined) {
this._isUncommitted = Git.isUncommitted(this.sha);
@@ -87,6 +91,10 @@ export class GitCommit implements IGitCommit {
return this._isUncommitted;
}
get previousShortSha() {
return this.previousSha && this.previousSha.substring(0, 8);
}
get previousUri(): Uri {
return this.previousFileName ? Uri.file(path.join(this.repoPath, this.previousFileName)) : this.uri;
}
@@ -138,6 +146,10 @@ export class GitLogCommit extends GitCommit {
}
}
get nextShortSha() {
return this.nextSha && this.nextSha.substring(0, 8);
}
get nextUri(): Uri {
return this.nextFileName ? Uri.file(path.join(this.repoPath, this.nextFileName)) : this.uri;
}

View File

@@ -49,6 +49,10 @@ export class GitUri extends Uri {
}
}
get shortSha() {
return this.sha && this.sha.substring(0, 8);
}
fileUri() {
return Uri.file(this.sha ? this.path : this.fsPath);
}