Bläddra i källkod

Adds catch to blameLine to avoid strange issues

Removes Git: from all the commands
Removes unused enricher
main
Eric Amodio 8 år sedan
förälder
incheckning
b047fbc394
4 ändrade filer med 16 tillägg och 103 borttagningar
  1. +6
    -6
      package.json
  2. +0
    -92
      src/git/enrichers/blameRegExpEnricher.ts
  3. +6
    -1
      src/git/git.ts
  4. +4
    -4
      src/gitProvider.ts

+ 6
- 6
package.json Visa fil

@ -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": {

+ 0
- 92
src/git/enrichers/blameRegExpEnricher.ts Visa fil

@ -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<IGitBlame> {
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<string, IGitAuthor> = new Map();
const commits: Map<string, IGitCommit> = new Map();
const lines: Array<IGitCommitLine> = [];
let m: Array<string>;
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<string, IGitAuthor> = 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<string, IGitCommit> = new Map();
Array.from(commits.values())
.sort((a, b) => b.date.getTime() - a.date.getTime())
.forEach(c => sortedCommits.set(c.sha, c));
return <IGitBlame>{
authors: sortedAuthors,
commits: sortedCommits,
lines: lines
};
}
}

+ 6
- 1
src/git/git.ts Visa fil

@ -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);
}
}

+ 4
- 4
src/gitProvider.ts Visa fil

@ -27,8 +27,6 @@ enum RemoveCacheReason {
DocumentChanged
}
const UncommitedRegex = /^[0]+$/;
export default class GitProvider extends Disposable {
private _blameCache: Map<string, IBlameCacheEntry>|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<IGitBlameLines|null> {
@ -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 {

Laddar…
Avbryt
Spara