{"thread":{"id":"4912","subject":"[PATCH] cvsexportcommit - add -a (add author line) flag, cleanup warnings","startedAt":"2006-07-18T02:22:49Z","lastAt":"2006-07-24T06:41:35Z","messageCount":2,"participants":["Martin Langhoff","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"23916","messageId":"11531893692075-git-send-email-martin@catalyst.net.nz","threadId":"4912","inReplyTo":null,"subject":"[PATCH] cvsexportcommit - add -a (add author line) flag, cleanup warnings","fromName":"Martin Langhoff","fromEmail":"martin@catalyst.net.nz","sentAt":"2006-07-18T02:22:49Z","receivedAt":"2006-07-18T02:22:49Z","isPatch":true,"sender":{"key":"martin@laptop.org","avatar":null},"body":"This patch adds support for -a which will add an \"Author: \" line, and possibly\na \"Committer: \" line to the bottom of the commit message for CVS.\n\nThe commit message parser is now a little bit better, and some warnings\nhave been cleaned up.\n---\n Documentation/git-cvsexportcommit.txt |    6 +++-\n git-cvsexportcommit.perl              |   50 +++++++++++++++++++++++++--------\n 2 files changed, 43 insertions(+), 13 deletions(-)\n\ndiff --git a/Documentation/git-cvsexportcommit.txt b/Documentation/git-cvsexportcommit.txt\nindex 27ac72d..b689c1b 100644\n--- a/Documentation/git-cvsexportcommit.txt\n+++ b/Documentation/git-cvsexportcommit.txt\n@@ -8,7 +8,7 @@ git-cvsexportcommit - Export a commit to\n \n SYNOPSIS\n --------\n-'git-cvsexportcommit' [-h] [-v] [-c] [-p] [-f] [-m msgprefix] [PARENTCOMMIT] COMMITID\n+'git-cvsexportcommit' [-h] [-v] [-c] [-p] [-a] [-f] [-m msgprefix] [PARENTCOMMIT] COMMITID\n \n \n DESCRIPTION\n@@ -39,6 +39,10 @@ OPTIONS\n \tBe pedantic (paranoid) when applying patches. Invokes patch with \n \t--fuzz=0\n \n+-a::\n+\tAdd authorship information. Adds Author line, and Committer (if\n+\tdifferent from Author) to the message. \n+\n -f::\n \tForce the merge even if the files are not up to date.\n \ndiff --git a/git-cvsexportcommit.perl b/git-cvsexportcommit.perl\nindex 5d13a54..99b3dc3 100755\n--- a/git-cvsexportcommit.perl\n+++ b/git-cvsexportcommit.perl\n@@ -16,9 +16,9 @@ unless ($ENV{GIT_DIR} && -r $ENV{GIT_DIR\n     die \"GIT_DIR is not defined or is unreadable\";\n }\n \n-our ($opt_h, $opt_p, $opt_v, $opt_c, $opt_f, $opt_m );\n+our ($opt_h, $opt_p, $opt_v, $opt_c, $opt_f, $opt_a, $opt_m );\n \n-getopts('hpvcfm:');\n+getopts('hpvcfam:');\n \n $opt_h && usage();\n \n@@ -29,7 +29,6 @@ our ($tmpdir, $tmpdirname) = tempdir('gi\n \t\t\t\t     TMPDIR => 1,\n \t\t\t\t     CLEANUP => 1);\n \n-print Dumper(@ARGV);\n # resolve target commit\n my $commit;\n $commit = pop @ARGV;\n@@ -53,12 +52,32 @@ if (@ARGV) {\n # find parents from the commit itself\n my @commit  = safe_pipe_capture('git-cat-file', 'commit', $commit);\n my @parents;\n-foreach my $p (@commit) {\n-    if ($p =~ m/^$/) { # end of commit headers, we're done\n-\tlast;\n+my $committer;\n+my $author;\n+my $stage = 'headers'; # headers, msg\n+my $title;\n+my $msg = '';\n+\n+foreach my $line (@commit) {\n+    chomp $line;\n+    if ($stage eq 'headers' && $line eq '') {\n+\t$stage = 'msg';\n+\tnext;\n     }\n-    if ($p =~ m/^parent (\\w{40})$/) { # found a parent\n-\tpush @parents, $1;\n+\n+    if ($stage eq 'headers') {\n+\tif ($line =~ m/^parent (\\w{40})$/) { # found a parent\n+\t    push @parents, $1;\n+\t} elsif ($line =~ m/^author (.+) \\d+ \\+\\d+$/) {\n+\t    $author = $1;\n+\t} elsif ($line =~ m/^committer (.+) \\d+ \\+\\d+$/) {\n+\t    $committer = $1;\n+\t}\n+    } else {\n+\t$msg .= $line . \"\\n\";\n+\tunless ($title) {\n+\t    $title = $line;\n+\t}\n     }\n }\n \n@@ -84,12 +103,18 @@ if ($parent) {\n \n # grab the commit message\n open(MSG, \">.msg\") or die \"Cannot open .msg for writing\";\n-print MSG $opt_m;\n+if ($opt_m) {\n+    print MSG $opt_m;\n+}\n+print MSG $msg;\n+if ($opt_a) {\n+    print MSG \"\\n\\nAuthor: $author\\n\";\n+    if ($author ne $committer) {\n+\tprint MSG \"Committer: $committer\\n\";\n+    }\n+}\n close MSG;\n \n-`git-cat-file commit $commit | sed -e '1,/^\\$/d' >> .msg`;\n-$? && die \"Error extracting the commit message\";\n-\n my (@afiles, @dfiles, @mfiles, @dirs);\n my @files = safe_pipe_capture('git-diff-tree', '-r', $parent, $commit);\n #print @files;\n@@ -233,6 +258,7 @@ foreach my $f (@dfiles) {\n }\n \n print \"Commit to CVS\\n\";\n+print \"Patch: $title\\n\";\n my $commitfiles = join(' ', @afiles, @mfiles, @dfiles);\n my $cmd = \"cvs commit -F .msg $commitfiles\";\n \n-- \n1.4.1.ga3e6\n"},{"id":"24040","messageId":"7vzmezfqsg.fsf@assigned-by-dhcp.cox.net","threadId":"4912","inReplyTo":"11531893692075-git-send-email-martin@catalyst.net.nz","subject":"Re: [PATCH] cvsexportcommit - add -a (add author line) flag, cleanup warnings","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-07-24T06:41:35Z","receivedAt":"2006-07-24T06:41:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks.\n"}]}