mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-02-16 18:48:45 -05:00
Refactors log parsing (a tiny bit)
This commit is contained in:
@@ -13,7 +13,6 @@ export class GitLogCommit extends GitCommit {
|
|||||||
nextSha?: string;
|
nextSha?: string;
|
||||||
nextFileName?: string;
|
nextFileName?: string;
|
||||||
parentShas: string[];
|
parentShas: string[];
|
||||||
status: GitStatusFileStatus;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public type: GitLogType,
|
public type: GitLogType,
|
||||||
@@ -31,7 +30,6 @@ export class GitLogCommit extends GitCommit {
|
|||||||
previousFileName?: string
|
previousFileName?: string
|
||||||
) {
|
) {
|
||||||
super(repoPath, sha, fileName, author, date, message, lines, originalFileName, previousSha, previousFileName);
|
super(repoPath, sha, fileName, author, date, message, lines, originalFileName, previousSha, previousFileName);
|
||||||
this.status = status;
|
|
||||||
|
|
||||||
this.fileNames = this.fileName;
|
this.fileNames = this.fileName;
|
||||||
|
|
||||||
@@ -40,7 +38,7 @@ export class GitLogCommit extends GitCommit {
|
|||||||
this.fileName = this.fileStatuses[0].fileName;
|
this.fileName = this.fileStatuses[0].fileName;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.fileStatuses = [{ status: status, fileName: fileName }];
|
this.fileStatuses = [{ status: status, fileName: fileName, originalFileName: originalFileName }];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ export class GitBlameParser {
|
|||||||
|
|
||||||
if (i === 0 && !repoPath) {
|
if (i === 0 && !repoPath) {
|
||||||
// Try to get the repoPath from the most recent commit
|
// 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));
|
relativeFileName = Git.normalizePath(path.relative(repoPath, fileName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ const diffRegex = /diff --git a\/(.*) b\/(.*)/;
|
|||||||
|
|
||||||
export class GitLogParser {
|
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;
|
if (!data) return undefined;
|
||||||
|
|
||||||
const lines = data.split('\n');
|
const lines = data.split('\n');
|
||||||
@@ -96,7 +96,7 @@ export class GitLogParser {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'filename':
|
case 'filename':
|
||||||
if (isRepoPath) {
|
if (type === 'repo') {
|
||||||
const nextLine = lines[position + 1];
|
const nextLine = lines[position + 1];
|
||||||
// If the next line isn't blank, make sure it isn't starting a new commit
|
// If the next line isn't blank, make sure it isn't starting a new commit
|
||||||
if (nextLine && Git.shaRegex.test(nextLine)) continue;
|
if (nextLine && Git.shaRegex.test(nextLine)) continue;
|
||||||
@@ -164,19 +164,18 @@ export class GitLogParser {
|
|||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
static parse(data: string, type: GitLogType, fileNameOrRepoPath: string, sha: string | undefined, maxCount: number | undefined, isRepoPath: boolean, reverse: boolean, range: Range): IGitLog {
|
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, isRepoPath, maxCount, reverse);
|
const entries = this._parseEntries(data, type, maxCount, reverse);
|
||||||
if (!entries) return undefined;
|
if (!entries) return undefined;
|
||||||
|
|
||||||
const authors: Map<string, IGitAuthor> = new Map();
|
const authors: Map<string, IGitAuthor> = new Map();
|
||||||
const commits: Map<string, GitLogCommit> = new Map();
|
const commits: Map<string, GitLogCommit> = new Map();
|
||||||
|
|
||||||
let repoPath: string;
|
|
||||||
let relativeFileName: string;
|
let relativeFileName: string;
|
||||||
let recentCommit: GitLogCommit;
|
let recentCommit: GitLogCommit;
|
||||||
|
|
||||||
if (isRepoPath) {
|
if (repoPath !== undefined) {
|
||||||
repoPath = Git.normalizePath(fileNameOrRepoPath);
|
repoPath = Git.normalizePath(repoPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0, len = entries.length; i < len; i++) {
|
for (let i = 0, len = entries.length; i < len; i++) {
|
||||||
@@ -185,15 +184,13 @@ export class GitLogParser {
|
|||||||
|
|
||||||
const entry = entries[i];
|
const entry = entries[i];
|
||||||
|
|
||||||
if (i === 0 || isRepoPath) {
|
if (i === 0 && type === 'file' && !repoPath) {
|
||||||
if (isRepoPath) {
|
// Try to get the repoPath from the most recent commit
|
||||||
relativeFileName = entry.fileName;
|
repoPath = Git.normalizePath(fileName.replace(fileName.startsWith('/') ? `/${entry.fileName}` : entry.fileName, ''));
|
||||||
}
|
relativeFileName = Git.normalizePath(path.relative(repoPath, fileName));
|
||||||
else {
|
}
|
||||||
// Try to get the repoPath from the most recent commit
|
else {
|
||||||
repoPath = Git.normalizePath(fileNameOrRepoPath.replace(fileNameOrRepoPath.startsWith('/') ? `/${entry.fileName}` : entry.fileName, ''));
|
relativeFileName = entry.fileName;
|
||||||
relativeFileName = path.relative(repoPath, fileNameOrRepoPath).replace(/\\/g, '/');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let commit = commits.get(entry.sha);
|
let commit = commits.get(entry.sha);
|
||||||
|
|||||||
@@ -544,7 +544,7 @@ export class GitService extends Disposable {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await Git.log(repoPath, sha, maxCount, reverse);
|
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) {
|
catch (ex) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -592,7 +592,7 @@ export class GitService extends Disposable {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await Git.log_file(root, file, sha, maxCount, reverse, range && range.start.line + 1, range && range.end.line + 1);
|
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) {
|
catch (ex) {
|
||||||
// Trap and cache expected log errors
|
// Trap and cache expected log errors
|
||||||
|
|||||||
Reference in New Issue
Block a user