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,
{
all,
argsOrFormat,
// TODO@eamodio remove this in favor of argsOrFormat
fileMode = 'full',
filters,
firstParent = false,
format = 'default',
limit,
ordering,
renames = true,
@ -768,9 +770,11 @@ export class Git {
endLine,
}: {
all?: boolean;
argsOrFormat?: string | string[];
// TODO@eamodio remove this in favor of argsOrFormat
fileMode?: 'full' | 'simple' | 'none';
filters?: GitDiffFilter[];
firstParent?: boolean;
format?: 'default' | 'refs' | 'simple';
limit?: number;
ordering?: string | null;
renames?: boolean;
@ -783,10 +787,15 @@ export class Git {
) {
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) {
params.push(`--${ordering}-order`);
@ -826,10 +835,10 @@ export class Git {
params.push(`--diff-filter=${filters.join('')}`);
}
if (format !== 'refs') {
if (fileMode !== 'none') {
if (startLine == null) {
// 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');
} else {
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
data = await this.git.log__file(repoPath, '.', ref, {
argsOrFormat: GitLogParser.simpleFormat,
fileMode: 'simple',
filters: ['R', 'C', 'D'],
format: 'simple',
limit: 1,
ordering: this.container.config.advanced.commitOrdering,
});
@ -1419,13 +1420,16 @@ export class LocalGitProvider implements GitProvider, Disposable {
const [path, root] = splitPath(uri.fsPath, repoPath);
const data = await this.git.log__file(root, path, '@{push}..', {
format: 'refs',
argsOrFormat: ['-z', '--format=%H'],
fileMode: 'none',
ordering: this.container.config.advanced.commitOrdering,
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()
@ -2709,8 +2713,9 @@ export class LocalGitProvider implements GitProvider, Disposable {
const fileName = GitUri.relativeTo(uri, repoPath);
let data = await this.git.log__file(repoPath, fileName, ref, {
argsOrFormat: GitLogParser.simpleFormat,
fileMode: 'simple',
filters: filters,
format: 'simple',
limit: skip + 1,
ordering: this.container.config.advanced.commitOrdering,
reverse: true,
@ -2722,8 +2727,9 @@ export class LocalGitProvider implements GitProvider, Disposable {
// If the file was deleted, check for a possible rename
if (status === 'D') {
data = await this.git.log__file(repoPath, '.', nextRef, {
argsOrFormat: GitLogParser.simpleFormat,
fileMode: 'simple',
filters: ['R', 'C'],
format: 'simple',
limit: 1,
ordering: this.container.config.advanced.commitOrdering,
// startLine: editorLine != null ? editorLine + 1 : undefined
@ -2962,8 +2968,9 @@ export class LocalGitProvider implements GitProvider, Disposable {
let data;
try {
data = await this.git.log__file(repoPath, path, ref, {
argsOrFormat: GitLogParser.simpleFormat,
fileMode: 'simple',
firstParent: firstParent,
format: 'simple',
limit: skip + 2,
ordering: this.container.config.advanced.commitOrdering,
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 fileStatusAndSummaryRenamedFilePathRegex = /(.*?){(.+?)\s=>\s(.*?)}(.*)/;
const logRefsRegex = /^<r> (.*)/gm;
const logFileSimpleRegex = /^<r> (.*)\s*(?:(?:diff --git a\/(.*) b\/(.*))|(?:(\S)\S*\t([^\t\n]+)(?:\t(.+))?))/gm;
const logFileSimpleRenamedRegex = /^<r> (\S+)\s*(.*)$/s;
const logFileSimpleRenamedFilesRegex = /^(\S)\S*\t([^\t\n]+)(?:\t(.+)?)?$/gm;
@ -645,23 +644,6 @@ export class GitLogParser {
}
@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(
data: string,
skip: number,

Loading…
Cancel
Save