From: Alex Vandiver <alex@chmrr.net>
To: git@vger.kernel.org
Subject: [PATCH 3/5] git-svn: Strip SVK headers, optionally parsing author information
Date: Wed, 2 Dec 2009 14:07:52 -0500 [thread overview]
Message-ID: <1259780874-14706-4-git-send-email-alex@chmrr.net> (raw)
In-Reply-To: <1259780874-14706-1-git-send-email-alex@chmrr.net>
SVK adds additional headers (often nested arbitrarily) detailing
information on the local commit. When possible, strip these headers
so that the first line of git's commit message is actually descriptive
of the commit.
Additionally, these headers contain information about the original
author's username, and their local commit time. If the
--use-log-author flag is set, use this information to set the
information on the git commit. Note that the username thus extracted
may be a _local_ username, and thus may require additional, somewhat
unexpected, entries in the authors file.
Signed-off-by: Alex Vandiver <alex@chmrr.net>
---
git-svn.perl | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 96 insertions(+), 2 deletions(-)
diff --git a/git-svn.perl b/git-svn.perl
index 5337326..0731425 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -3110,7 +3110,8 @@ sub make_log_entry {
close $un or croak $!;
$log_entry{date} = parse_svn_date($log_entry{date});
- $log_entry{log} .= "\n";
+ parse_svk_log(\%log_entry) if $log_entry{log} =~ svk_header_regex( lenient => 1 );
+
my $author = $log_entry{author} = check_author($log_entry{author});
my ($name, $email) = defined $::users{$author} ? @{$::users{$author}}
: ($author, undef);
@@ -3118,7 +3119,15 @@ sub make_log_entry {
my ($commit_name, $commit_email) = ($name, $email);
if ($_use_log_author) {
my $name_field;
- if ($log_entry{log} =~ /From:\s+(.*\S)\s*\n/i) {
+ if ($log_entry{log_author}) {
+ $log_entry{commit_date} = $log_entry{date};
+ $log_entry{date} = $log_entry{log_author_date};
+ $log_entry{log_author} = check_author($log_entry{log_author});
+ my ($log_author_name, $log_author_email)
+ = defined $::users{$log_entry{log_author}} ? @{$::users{$log_entry{log_author}}}
+ : ($log_entry{log_author}, undef);
+ $name_field = "$log_author_name <$log_author_email>";
+ } elsif ($log_entry{log} =~ /From:\s+(.*\S)\s*\n/i) {
$name_field = $1;
} elsif ($log_entry{log} =~ /Signed-off-by:\s+(.*\S)\s*\n/i) {
$name_field = $1;
@@ -3182,6 +3191,91 @@ sub make_log_entry {
\%log_entry;
}
+sub svk_header_regex {
+ my %args = ( lenient => 0, orig => 0, @_ );
+ my $orig = $args{orig} ? qr/ \(orig r\d+\)/ : "";
+ my $atstart = "";
+ if ($args{lenient}) {
+ $atstart = qr/\s*/;
+ $orig = qr/(?: \(orig r\d+\))?/;
+ }
+ return qr/^${atstart}r\d+\@\S+$orig:\s*(\S+)\s*\|\s*(.*?)\s*([+-]\d+)$/m;
+}
+
+sub parse_svk_log {
+ my $log_entry = shift;
+ my $log = $log_entry->{log};
+
+ # Strip off blank lines at the start and end
+ $log =~ s/^(\s*?\n)+//;
+ $log =~ s/\s*$//;
+
+ # If each line starts with a space, this might be an
+ # unmodified SVK log format. As a side effect, this also
+ # trims the leading space off of the lines.
+ my $lines = $log =~ s/^//mg;
+ my $spaced = $log =~ s/^ //mg;
+ return unless $lines == $spaced;
+
+ my $regex = svk_header_regex( orig => 1 );
+ if ($log =~ /\A$regex/) {
+ # This is either a merge commit, or a base-less merge
+ # (replay from a different repository) The \A assures
+ # that this is an _unedited_ merge commit with no
+ # hand-supplied log message.
+ if (@{$log_entry->{merged_branches} || []}) {
+ # This is a merge with no description; provide
+ # one.
+ $log_entry->{log} = "Merge from @{$log_entry->{merged_branches}}\n\n$log";
+ } else {
+ my $commits = 0;
+ $commits++ while $log =~ /$regex/g;
+ if ($commits == 1) {
+ # This is a baseless merge of one
+ # commit; strip off the original
+ # commit info
+ $log_entry->{log_author} = $1;
+ $log_entry->{log_author_date} = "$3 $2";
+ $log =~ s/\A$regex\n*//;
+ $log_entry->{log} = $log;
+ parse_svk_log($log_entry);
+ } else {
+ # A lump baseless merge? Remove all
+ # of the SVK headers on this level,
+ # and add a summary. Trailing
+ # newlines on the svk header lines are
+ # left unmolested, so they become
+ # blank lines.
+ $log =~ s/$regex//g;
+ $log_entry->{log} = "Lump commit\n$log";
+ }
+ }
+ } else {
+ # Look for svk header lines without the (orig r12345),
+ # which were local commits.
+ $regex = svk_header_regex();
+ my $commits = 0;
+ $commits++ while $log =~ /$regex/g;
+ if ($commits == 0) {
+ # No more svk-like commits; don't change anything.
+ } elsif ($commits == 1) {
+ # Only one top-level commit-like object; strip
+ # it off, recurse down.
+ $log_entry->{log_author} = $1;
+ $log_entry->{log_author_date} = "$3 $2";
+ $log =~ s/$regex\n*//;
+ $log_entry->{log} = $log;
+ parse_svk_log($log_entry);
+ } else {
+ # This is a lump push of local commits. Strip
+ # off all of the svk headers in this level,
+ # and call it quits.
+ $log =~ s/$regex//g;
+ $log_entry->{log} = $log;
+ }
+ }
+}
+
sub fetch {
my ($self, $min_rev, $max_rev, @parents) = @_;
my ($last_rev, $last_commit) = $self->last_rev_commit;
--
1.6.6.rc0.327.g032bc
next prev parent reply other threads:[~2009-12-02 19:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-02 19:07 [PATCH 0/5] git-svn: svk log message cleanup Alex Vandiver
2009-12-02 19:07 ` [PATCH 1/5] git-svn: Allow setting the committer and author date separately Alex Vandiver
2009-12-02 19:07 ` [PATCH 2/5] git-svn: Make merge metadata accessible to make_log_entry Alex Vandiver
2009-12-02 20:46 ` Alex Vandiver
2009-12-05 22:32 ` Eric Wong
2009-12-05 22:51 ` Alex Vandiver
2009-12-05 22:59 ` [spf:guess] " Sam Vilain
2009-12-05 23:10 ` Alex Vandiver
2009-12-19 22:24 ` Alex Vandiver
2009-12-02 19:07 ` Alex Vandiver [this message]
2009-12-02 19:07 ` [PATCH 4/5] git-svn: Provide a default "empty commit message" so the metadata is not the header Alex Vandiver
2009-12-02 19:07 ` [PATCH 5/5] git-svn: Correct a copy-and-pasted misleading comment Alex Vandiver
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1259780874-14706-4-git-send-email-alex@chmrr.net \
--to=alex@chmrr.net \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).