Browse Source

Improves oldest ref parser

main
Eric Amodio 2 years ago
parent
commit
de438a4c8f
3 changed files with 31 additions and 33 deletions
  1. +17
    -8
      src/env/node/git/git.ts
  2. +14
    -7
      src/env/node/git/localGitProvider.ts
  3. +0
    -18
      src/git/parsers/logParser.ts

+ 17
- 8
src/env/node/git/git.ts View File

@ -755,9 +755,11 @@ export class Git {
ref: string | undefined, ref: string | undefined,
{ {
all, all,
argsOrFormat,
// TODO@eamodio remove this in favor of argsOrFormat
fileMode = 'full',
filters, filters,
firstParent = false, firstParent = false,
format = 'default',
limit, limit,
ordering, ordering,
renames = true, renames = true,
@ -768,9 +770,11 @@ export class Git {
endLine, endLine,
}: { }: {
all?: boolean; all?: boolean;
argsOrFormat?: string | string[];
// TODO@eamodio remove this in favor of argsOrFormat
fileMode?: 'full' | 'simple' | 'none';
filters?: GitDiffFilter[]; filters?: GitDiffFilter[];
firstParent?: boolean; firstParent?: boolean;
format?: 'default' | 'refs' | 'simple';
limit?: number; limit?: number;
ordering?: string | null; ordering?: string | null;
renames?: boolean; renames?: boolean;
@ -783,10 +787,15 @@ export class Git {
) { ) {
const [file, root] = splitPath(fileName, repoPath, true); const [file, root] = splitPath(fileName, repoPath, true);
const params = [
'log',
`--format=${format === 'default' ? GitLogParser.defaultFormat : GitLogParser.simpleFormat}`,
];
if (argsOrFormat == null) {
argsOrFormat = [`--format=${GitLogParser.defaultFormat}`];
}
if (typeof argsOrFormat === 'string') {
argsOrFormat = [`--format=${argsOrFormat}`];
}
const params = ['log', ...argsOrFormat];
if (ordering) { if (ordering) {
params.push(`--${ordering}-order`); params.push(`--${ordering}-order`);
@ -826,10 +835,10 @@ export class Git {
params.push(`--diff-filter=${filters.join('')}`); params.push(`--diff-filter=${filters.join('')}`);
} }
if (format !== 'refs') {
if (fileMode !== 'none') {
if (startLine == null) { if (startLine == null) {
// If this is the log of a folder, use `--name-status` to match non-file logs (for parsing) // If this is the log of a folder, use `--name-status` to match non-file logs (for parsing)
if (format === 'simple' || isFolderGlob(file)) {
if (fileMode === 'simple' || isFolderGlob(file)) {
params.push('--name-status'); params.push('--name-status');
} else { } else {
params.push('--numstat', '--summary'); params.push('--numstat', '--summary');

+ 14
- 7
src/env/node/git/localGitProvider.ts View File

@ -633,8 +633,9 @@ export class LocalGitProvider implements GitProvider, Disposable {
// Now check if that commit had any renames // Now check if that commit had any renames
data = await this.git.log__file(repoPath, '.', ref, { data = await this.git.log__file(repoPath, '.', ref, {
argsOrFormat: GitLogParser.simpleFormat,
fileMode: 'simple',
filters: ['R', 'C', 'D'], filters: ['R', 'C', 'D'],
format: 'simple',
limit: 1, limit: 1,
ordering: this.container.config.advanced.commitOrdering, ordering: this.container.config.advanced.commitOrdering,
}); });
@ -1419,13 +1420,16 @@ export class LocalGitProvider implements GitProvider, Disposable {
const [path, root] = splitPath(uri.fsPath, repoPath); const [path, root] = splitPath(uri.fsPath, repoPath);
const data = await this.git.log__file(root, path, '@{push}..', { const data = await this.git.log__file(root, path, '@{push}..', {
format: 'refs',
argsOrFormat: ['-z', '--format=%H'],
fileMode: 'none',
ordering: this.container.config.advanced.commitOrdering, ordering: this.container.config.advanced.commitOrdering,
renames: true, renames: true,
}); });
if (data == null || data.length === 0) return undefined;
if (!data) return undefined;
return GitLogParser.parseLastRefOnly(data);
// -2 to skip the ending null
const index = data.lastIndexOf('\0', data.length - 2);
return index === -1 ? undefined : data.slice(index + 1, data.length - 2);
} }
@log() @log()
@ -2709,8 +2713,9 @@ export class LocalGitProvider implements GitProvider, Disposable {
const fileName = GitUri.relativeTo(uri, repoPath); const fileName = GitUri.relativeTo(uri, repoPath);
let data = await this.git.log__file(repoPath, fileName, ref, { let data = await this.git.log__file(repoPath, fileName, ref, {
argsOrFormat: GitLogParser.simpleFormat,
fileMode: 'simple',
filters: filters, filters: filters,
format: 'simple',
limit: skip + 1, limit: skip + 1,
ordering: this.container.config.advanced.commitOrdering, ordering: this.container.config.advanced.commitOrdering,
reverse: true, reverse: true,
@ -2722,8 +2727,9 @@ export class LocalGitProvider implements GitProvider, Disposable {
// If the file was deleted, check for a possible rename // If the file was deleted, check for a possible rename
if (status === 'D') { if (status === 'D') {
data = await this.git.log__file(repoPath, '.', nextRef, { data = await this.git.log__file(repoPath, '.', nextRef, {
argsOrFormat: GitLogParser.simpleFormat,
fileMode: 'simple',
filters: ['R', 'C'], filters: ['R', 'C'],
format: 'simple',
limit: 1, limit: 1,
ordering: this.container.config.advanced.commitOrdering, ordering: this.container.config.advanced.commitOrdering,
// startLine: editorLine != null ? editorLine + 1 : undefined // startLine: editorLine != null ? editorLine + 1 : undefined
@ -2962,8 +2968,9 @@ export class LocalGitProvider implements GitProvider, Disposable {
let data; let data;
try { try {
data = await this.git.log__file(repoPath, path, ref, { data = await this.git.log__file(repoPath, path, ref, {
argsOrFormat: GitLogParser.simpleFormat,
fileMode: 'simple',
firstParent: firstParent, firstParent: firstParent,
format: 'simple',
limit: skip + 2, limit: skip + 2,
ordering: this.container.config.advanced.commitOrdering, ordering: this.container.config.advanced.commitOrdering,
startLine: editorLine != null ? editorLine + 1 : undefined, startLine: editorLine != null ? editorLine + 1 : undefined,

+ 0
- 18
src/git/parsers/logParser.ts View File

@ -23,7 +23,6 @@ const fileStatusAndSummaryRegex = /^(\d+?|-)\s+?(\d+?|-)\s+?(.*)(?:\n\s(delete|r
const fileStatusAndSummaryRenamedFileRegex = /(.+)\s=>\s(.+)/; const fileStatusAndSummaryRenamedFileRegex = /(.+)\s=>\s(.+)/;
const fileStatusAndSummaryRenamedFilePathRegex = /(.*?){(.+?)\s=>\s(.*?)}(.*)/; const fileStatusAndSummaryRenamedFilePathRegex = /(.*?){(.+?)\s=>\s(.*?)}(.*)/;
const logRefsRegex = /^<r> (.*)/gm;
const logFileSimpleRegex = /^<r> (.*)\s*(?:(?:diff --git a\/(.*) b\/(.*))|(?:(\S)\S*\t([^\t\n]+)(?:\t(.+))?))/gm; const logFileSimpleRegex = /^<r> (.*)\s*(?:(?:diff --git a\/(.*) b\/(.*))|(?:(\S)\S*\t([^\t\n]+)(?:\t(.+))?))/gm;
const logFileSimpleRenamedRegex = /^<r> (\S+)\s*(.*)$/s; const logFileSimpleRenamedRegex = /^<r> (\S+)\s*(.*)$/s;
const logFileSimpleRenamedFilesRegex = /^(\S)\S*\t([^\t\n]+)(?:\t(.+)?)?$/gm; const logFileSimpleRenamedFilesRegex = /^(\S)\S*\t([^\t\n]+)(?:\t(.+)?)?$/gm;
@ -645,23 +644,6 @@ export class GitLogParser {
} }
@debug({ args: false }) @debug({ args: false })
static parseLastRefOnly(data: string): string | undefined {
let ref;
let match;
do {
match = logRefsRegex.exec(data);
if (match == null) break;
[, ref] = match;
} while (true);
// Ensure the regex state is reset
logRefsRegex.lastIndex = 0;
return ref;
}
@debug({ args: false })
static parseSimple( static parseSimple(
data: string, data: string,
skip: number, skip: number,

Loading…
Cancel
Save