cvsexportcommit - add -a (add author line) flag, cleanup warnings
This patch adds support for -a which will add an "Author: " line, and possibly a "Committer: " line to the bottom of the commit message for CVS. The commit message parser is now a little bit better, and some warnings have been cleaned up. Signed-off-by: Junio C Hamano <junkio@cox.net>
Martin Langhoff committed
Jul 18, 2006 at 14:22 UTC
1b91abe35079f3d6e6440b9a49766de06f3f1659
2 files changed
+44
-14
Documentation/git-cvsexportcommit.txt
+6
-2
@@ -8,7 +8,7 @@ git-cvsexportcommit - Export a commit to a CVS checkout
8
9
SYNOPSIS
10
--------
11
-'git-cvsexportcommit' [-h] [-v] [-c] [-p] [-f] [-m msgprefix] [PARENTCOMMIT] COMMITID
11
+'git-cvsexportcommit' [-h] [-v] [-c] [-p] [-a] [-f] [-m msgprefix] [PARENTCOMMIT] COMMITID
12
13
14
DESCRIPTION
@@ -36,9 +36,13 @@ OPTIONS
36
commit if any hunks fail to apply or there were other problems.
37
38
-p::
39
- Be pedantic (paranoid) when applying patches. Invokes patch with
39
+ Be pedantic (paranoid) when applying patches. Invokes patch with
40
--fuzz=0
41
42
+-a::
43
+ Add authorship information. Adds Author line, and Committer (if
44
+ different from Author) to the message.
45
+
46
-f::
47
Force the merge even if the files are not up to date.
48
git-cvsexportcommit.perl
+38
-12
@@ -16,9 +16,9 @@ unless ($ENV{GIT_DIR} && -r $ENV{GIT_DIR}){
16
die "GIT_DIR is not defined or is unreadable";
17
}
18
19
-our ($opt_h, $opt_p, $opt_v, $opt_c, $opt_f, $opt_m );
19
+our ($opt_h, $opt_p, $opt_v, $opt_c, $opt_f, $opt_a, $opt_m );
20
21
-getopts('hpvcfm:');
21
+getopts('hpvcfam:');
22
23
$opt_h && usage();
24
@@ -29,7 +29,6 @@ our ($tmpdir, $tmpdirname) = tempdir('git-cvsapplycommit-XXXXXX',
29
TMPDIR => 1,
30
CLEANUP => 1);
31
32
-print Dumper(@ARGV);
32
# resolve target commit
33
my $commit;
34
$commit = pop @ARGV;
@@ -53,12 +52,32 @@ if (@ARGV) {
52
# find parents from the commit itself
53
my @commit = safe_pipe_capture('git-cat-file', 'commit', $commit);
54
my @parents;
56
-foreach my $p (@commit) {
57
- if ($p =~ m/^$/) { # end of commit headers, we're done
58
- last;
55
+my $committer;
56
+my $author;
57
+my $stage = 'headers'; # headers, msg
58
+my $title;
59
+my $msg = '';
60
+
61
+foreach my $line (@commit) {
62
+ chomp $line;
63
+ if ($stage eq 'headers' && $line eq '') {
64
+ $stage = 'msg';
65
+ next;
66
}
60
- if ($p =~ m/^parent (\w{40})$/) { # found a parent
61
- push @parents, $1;
67
+
68
+ if ($stage eq 'headers') {
69
+ if ($line =~ m/^parent (\w{40})$/) { # found a parent
70
+ push @parents, $1;
71
+ } elsif ($line =~ m/^author (.+) \d+ \+\d+$/) {
72
+ $author = $1;
73
+ } elsif ($line =~ m/^committer (.+) \d+ \+\d+$/) {
74
+ $committer = $1;
75
+ }
76
+ } else {
77
+ $msg .= $line . "\n";
78
+ unless ($title) {
79
+ $title = $line;
80
+ }
81
}
82
}
83
@@ -84,12 +103,18 @@ $opt_v && print "Applying to CVS commit $commit from parent $parent\n";
103
104
# grab the commit message
105
open(MSG, ">.msg") or die "Cannot open .msg for writing";
87
-print MSG $opt_m;
106
+if ($opt_m) {
107
+ print MSG $opt_m;
108
+}
109
+print MSG $msg;
110
+if ($opt_a) {
111
+ print MSG "\n\nAuthor: $author\n";
112
+ if ($author ne $committer) {
113
+ print MSG "Committer: $committer\n";
114
+ }
115
+}
116
close MSG;
117
90
-`git-cat-file commit $commit | sed -e '1,/^\$/d' >> .msg`;
91
-$? && die "Error extracting the commit message";
92
-
118
my (@afiles, @dfiles, @mfiles, @dirs);
119
my @files = safe_pipe_capture('git-diff-tree', '-r', $parent, $commit);
120
#print @files;
@@ -233,6 +258,7 @@ foreach my $f (@dfiles) {
258
}
259
260
print "Commit to CVS\n";
261
+print "Patch: $title\n";
262
my $commitfiles = join(' ', @afiles, @mfiles, @dfiles);
263
my $cmd = "cvs commit -F .msg $commitfiles";
264