Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support [] in author name (fix #197) #298

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions src/commands/loggingCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,7 @@ function parseLog(stdout: string): MagitLogEntry[] {
// Split stdout lines
const lines = stdout.match(/[^\r\n]+/g);
// regex to parse line
const lineRe = new RegExp(
'^([/|\\-_* .o]+)?' + // Graph
'([a-f0-9]{40})' + // Sha
'( \\(([^()]+)\\))?' + // Refs
'( \\[([^\\[\\]]+)\\])' + // Author
'( \\[([^\\[\\]]+)\\])' + // Time
'(.*)$', // Message
'g');
const lineRe = /^(?<graph>[/|\-_* .o]+)?(?<sha>[a-f0-9]{40})(?: \((?<refs>[^()]+)\))?(?: \[(?<author>(?:[^[\]]*\[[^\]]*\])?[^\]]*)\])(?: \[(?<time>[^[\]]+)\])(?<msg>.*)$/g;
// regex to match graph only line
const graphRe = /^[/|\\-_* .o]+$/g;

Expand All @@ -163,17 +156,17 @@ function parseLog(stdout: string): MagitLogEntry[] {
// Add to previous commits
commits[commits.length - 1]?.graph?.push(l);
} else {
const matches = l.matchAll(lineRe).next().value;
if (matches && matches.length > 0) {
const graph = matches[1]; // undefined if graph doesn't exist
const log = {
const matches = lineRe.exec(l)?.groups;
if (matches) {
const graph = matches.graph; // undefined if graph doesn't exist
const log: MagitLogEntry = {
graph: graph ? [graph] : undefined,
refs: (matches[4] ?? '').split(', ').filter((m: string) => m),
author: matches[6],
time: new Date(Number(matches[8]) * 1000), // convert seconds to milliseconds
refs: (matches.refs ?? '').split(', ').filter((m: string) => m),
author: matches.author,
time: new Date(Number(matches.time) * 1000), // convert seconds to milliseconds
commit: {
hash: matches[2],
message: matches[9],
hash: matches.sha,
message: matches.msg,
parents: [],
authorEmail: undefined
}
Expand Down