From b047fbc394bcee6c9c75e8736a428d7e66bf2e5d Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 21 Sep 2016 09:46:29 -0400 Subject: [PATCH] Adds catch to blameLine to avoid strange issues Removes Git: from all the commands Removes unused enricher --- package.json | 12 ++--- src/git/enrichers/blameRegExpEnricher.ts | 92 -------------------------------- src/git/git.ts | 7 ++- src/gitProvider.ts | 8 +-- 4 files changed, 16 insertions(+), 103 deletions(-) delete mode 100644 src/git/enrichers/blameRegExpEnricher.ts diff --git a/package.json b/package.json index 20c328f..012bf9d 100644 --- a/package.json +++ b/package.json @@ -145,32 +145,32 @@ }, "commands": [{ "command": "gitlens.diffWithPrevious", - "title": "Git: Open Diff with Previous Commit", + "title": "Open Diff with Previous Commit", "category": "GitLens" }, { "command": "gitlens.diffWithWorking", - "title": "Git: Open Diff with Working Tree", + "title": "Open Diff with Working Tree", "category": "GitLens" }, { "command": "gitlens.showBlame", - "title": "Git: Show Blame", + "title": "Show Git Blame Annotations", "category": "GitLens" }, { "command": "gitlens.toggleBlame", - "title": "Git: Toggle Blame", + "title": "Toggle Git Blame Annotations", "category": "GitLens" }, { "command": "gitlens.toggleCodeLens", - "title": "Git: Toggle CodeLens", + "title": "Toggle Git CodeLens", "category": "GitLens" }, { "command": "gitlens.showBlameHistory", - "title": "Git: Open Blame History", + "title": "Open Git Blame History", "category": "GitLens" }], "menus": { diff --git a/src/git/enrichers/blameRegExpEnricher.ts b/src/git/enrichers/blameRegExpEnricher.ts deleted file mode 100644 index 8543a92..0000000 --- a/src/git/enrichers/blameRegExpEnricher.ts +++ /dev/null @@ -1,92 +0,0 @@ -'use strict' -import {GitBlameFormat, GitCommit, IGitAuthor, IGitBlame, IGitCommit, IGitCommitLine, IGitEnricher} from './../git'; -import * as moment from 'moment'; - -const blamePorcelainMatcher = /^([\^0-9a-fA-F]{40})\s([0-9]+)\s([0-9]+)(?:\s([0-9]+))?$\n(?:^author\s(.*)$\n^author-mail\s(.*)$\n^author-time\s(.*)$\n^author-tz\s(.*)$\n^committer\s(.*)$\n^committer-mail\s(.*)$\n^committer-time\s(.*)$\n^committer-tz\s(.*)$\n^summary\s(.*)$\n(?:^previous\s(.*)?\s(.*)$\n)?^filename\s(.*)$\n)?^(.*)$/gm; -const blameLinePorcelainMatcher = /^([\^0-9a-fA-F]{40})\s([0-9]+)\s([0-9]+)(?:\s([0-9]+))?$\n^author\s(.*)$\n^author-mail\s(.*)$\n^author-time\s(.*)$\n^author-tz\s(.*)$\n^committer\s(.*)$\n^committer-mail\s(.*)$\n^committer-time\s(.*)$\n^committer-tz\s(.*)$\n^summary\s(.*)$\n(?:^previous\s(.*)?\s(.*)$\n)?^filename\s(.*)$\n^(.*)$/gm; - -export class GitBlameRegExpEnricher implements IGitEnricher { - private _matcher: RegExp; - - constructor(public format: GitBlameFormat, private repoPath: string) { - if (format === GitBlameFormat.porcelain) { - this._matcher = blamePorcelainMatcher; - } else if (format === GitBlameFormat.linePorcelain) { - this._matcher = blamePorcelainMatcher; - } else { - throw new Error(`Invalid blame format=${format}`); - } - } - - enrich(data: string, fileName: string): IGitBlame { - if (!data) return null; - - const authors: Map = new Map(); - const commits: Map = new Map(); - const lines: Array = []; - - let m: Array; - while ((m = this._matcher.exec(data)) != null) { - const sha = m[1].substring(0, 8); - const previousSha = m[14]; - let commit = commits.get(sha); - if (!commit) { - const authorName = m[5].trim(); - let author = authors.get(authorName); - if (!author) { - author = { - name: authorName, - lineCount: 0 - }; - authors.set(authorName, author); - } - - commit = new GitCommit(this.repoPath, sha, fileName, authorName, moment(`${m[7]} ${m[8]}`, 'X Z').toDate(), m[13]); - - const originalFileName = m[16]; - if (!fileName.toLowerCase().endsWith(originalFileName.toLowerCase())) { - commit.originalFileName = originalFileName; - } - - if (previousSha) { - commit.previousSha = previousSha.substring(0, 8); - commit.previousFileName = m[15]; - } - - commits.set(sha, commit); - } - - const line: IGitCommitLine = { - sha, - line: parseInt(m[3], 10) - 1, - originalLine: parseInt(m[2], 10) - 1 - //code: m[17] - } - - if (previousSha) { - line.previousSha = previousSha.substring(0, 8); - } - - commit.lines.push(line); - lines.push(line); - } - - commits.forEach(c => authors.get(c.author).lineCount += c.lines.length); - - const sortedAuthors: Map = new Map(); - const values = Array.from(authors.values()) - .sort((a, b) => b.lineCount - a.lineCount) - .forEach(a => sortedAuthors.set(a.name, a)); - - const sortedCommits: Map = new Map(); - Array.from(commits.values()) - .sort((a, b) => b.date.getTime() - a.date.getTime()) - .forEach(c => sortedCommits.set(c.sha, c)); - - return { - authors: sortedAuthors, - commits: sortedCommits, - lines: lines - }; - } -} \ No newline at end of file diff --git a/src/git/git.ts b/src/git/git.ts index 9b6e003..0a621cb 100644 --- a/src/git/git.ts +++ b/src/git/git.ts @@ -5,9 +5,10 @@ import * as tmp from 'tmp'; import {spawnPromise} from 'spawn-rx'; export * from './gitEnrichment'; -//export * from './enrichers/blameRegExpEnricher'; export * from './enrichers/blameParserEnricher'; +const UncommitedRegex = /^[0]+$/; + function gitCommand(cwd: string, ...args) { return spawnPromise('git', args, { cwd: cwd }) .then(s => { @@ -100,4 +101,8 @@ export default class Git { return gitCommand(root, 'show', `${sha}:./${file}`); } + + static isUncommitted(sha: string) { + return UncommitedRegex.test(sha); + } } \ No newline at end of file diff --git a/src/gitProvider.ts b/src/gitProvider.ts index 9d95b97..68dffea 100644 --- a/src/gitProvider.ts +++ b/src/gitProvider.ts @@ -27,8 +27,6 @@ enum RemoveCacheReason { DocumentChanged } -const UncommitedRegex = /^[0]+$/; - export default class GitProvider extends Disposable { private _blameCache: Map|null; private _blameCacheDisposable: Disposable|null; @@ -183,6 +181,7 @@ export default class GitProvider extends Disposable { }); return GitProvider.BlameEmptyPromise; } + return null; }); } @@ -229,7 +228,8 @@ export default class GitProvider extends Disposable { commit: commit, line: blame.lines[line - 1] }; - }); + }) + .catch(ex => null); } getBlameForRange(fileName: string, range: Range): Promise { @@ -355,7 +355,7 @@ export default class GitProvider extends Disposable { } static isUncommitted(sha: string) { - return UncommitedRegex.test(sha); + return Git.isUncommitted(sha); } static fromBlameUri(uri: Uri): IGitBlameUriData {