Ver a proveniência

Refactors log parsing (a tiny bit)

main
Eric Amodio há 7 anos
ascendente
cometimento
073353dcda
4 ficheiros alterados com 17 adições e 22 eliminações
  1. +1
    -3
      src/git/models/logCommit.ts
  2. +1
    -1
      src/git/parsers/blameParser.ts
  3. +13
    -16
      src/git/parsers/logParser.ts
  4. +2
    -2
      src/gitService.ts

+ 1
- 3
src/git/models/logCommit.ts Ver ficheiro

@ -13,7 +13,6 @@ export class GitLogCommit extends GitCommit {
nextSha?: string;
nextFileName?: string;
parentShas: string[];
status: GitStatusFileStatus;
constructor(
public type: GitLogType,
@ -31,7 +30,6 @@ export class GitLogCommit extends GitCommit {
previousFileName?: string
) {
super(repoPath, sha, fileName, author, date, message, lines, originalFileName, previousSha, previousFileName);
this.status = status;
this.fileNames = this.fileName;
@ -40,7 +38,7 @@ export class GitLogCommit extends GitCommit {
this.fileName = this.fileStatuses[0].fileName;
}
else {
this.fileStatuses = [{ status: status, fileName: fileName }];
this.fileStatuses = [{ status: status, fileName: fileName, originalFileName: originalFileName }];
}
}

+ 1
- 1
src/git/parsers/blameParser.ts Ver ficheiro

@ -131,7 +131,7 @@ export class GitBlameParser {
if (i === 0 && !repoPath) {
// Try to get the repoPath from the most recent commit
repoPath = Git.normalizePath(fileName.replace(`/${entry.fileName}`, ''));
repoPath = Git.normalizePath(fileName.replace(fileName.startsWith('/') ? `/${entry.fileName}` : entry.fileName, ''));
relativeFileName = Git.normalizePath(path.relative(repoPath, fileName));
}

+ 13
- 16
src/git/parsers/logParser.ts Ver ficheiro

@ -29,7 +29,7 @@ const diffRegex = /diff --git a\/(.*) b\/(.*)/;
export class GitLogParser {
private static _parseEntries(data: string, isRepoPath: boolean, maxCount: number | undefined, reverse: boolean): ILogEntry[] {
private static _parseEntries(data: string, type: GitLogType, maxCount: number | undefined, reverse: boolean): ILogEntry[] {
if (!data) return undefined;
const lines = data.split('\n');
@ -96,7 +96,7 @@ export class GitLogParser {
break;
case 'filename':
if (isRepoPath) {
if (type === 'repo') {
const nextLine = lines[position + 1];
// If the next line isn't blank, make sure it isn't starting a new commit
if (nextLine && Git.shaRegex.test(nextLine)) continue;
@ -164,19 +164,18 @@ export class GitLogParser {
return entries;
}
static parse(data: string, type: GitLogType, fileNameOrRepoPath: string, sha: string | undefined, maxCount: number | undefined, isRepoPath: boolean, reverse: boolean, range: Range): IGitLog {
const entries = this._parseEntries(data, isRepoPath, maxCount, reverse);
static parse(data: string, type: GitLogType, repoPath: string | undefined, fileName: string | undefined, sha: string | undefined, maxCount: number | undefined, reverse: boolean, range: Range): IGitLog {
const entries = this._parseEntries(data, type, maxCount, reverse);
if (!entries) return undefined;
const authors: Map<string, IGitAuthor> = new Map();
const commits: Map<string, GitLogCommit> = new Map();
let repoPath: string;
let relativeFileName: string;
let recentCommit: GitLogCommit;
if (isRepoPath) {
repoPath = Git.normalizePath(fileNameOrRepoPath);
if (repoPath !== undefined) {
repoPath = Git.normalizePath(repoPath);
}
for (let i = 0, len = entries.length; i < len; i++) {
@ -185,15 +184,13 @@ export class GitLogParser {
const entry = entries[i];
if (i === 0 || isRepoPath) {
if (isRepoPath) {
relativeFileName = entry.fileName;
}
else {
// Try to get the repoPath from the most recent commit
repoPath = Git.normalizePath(fileNameOrRepoPath.replace(fileNameOrRepoPath.startsWith('/') ? `/${entry.fileName}` : entry.fileName, ''));
relativeFileName = path.relative(repoPath, fileNameOrRepoPath).replace(/\\/g, '/');
}
if (i === 0 && type === 'file' && !repoPath) {
// Try to get the repoPath from the most recent commit
repoPath = Git.normalizePath(fileName.replace(fileName.startsWith('/') ? `/${entry.fileName}` : entry.fileName, ''));
relativeFileName = Git.normalizePath(path.relative(repoPath, fileName));
}
else {
relativeFileName = entry.fileName;
}
let commit = commits.get(entry.sha);

+ 2
- 2
src/gitService.ts Ver ficheiro

@ -544,7 +544,7 @@ export class GitService extends Disposable {
try {
const data = await Git.log(repoPath, sha, maxCount, reverse);
return GitLogParser.parse(data, 'repo', repoPath, sha, maxCount, true, reverse, undefined);
return GitLogParser.parse(data, 'repo', repoPath, undefined, sha, maxCount, reverse, undefined);
}
catch (ex) {
return undefined;
@ -592,7 +592,7 @@ export class GitService extends Disposable {
try {
const data = await Git.log_file(root, file, sha, maxCount, reverse, range && range.start.line + 1, range && range.end.line + 1);
return GitLogParser.parse(data, 'file', root || file, sha, maxCount, !!root, reverse, range);
return GitLogParser.parse(data, 'file', root, file, sha, maxCount, reverse, range);
}
catch (ex) {
// Trap and cache expected log errors

Carregando…
Cancelar
Guardar