import-tars: Allow per-tar author and commit message.
If the "--metainfo=<ext>" option is given on the command line, a file called "<filename.tar>.<ext>" will be used to create the commit message for "<filename.tar>", instead of using "Imported from filename.tar". The author and committer of the tar ball can also be overridden by embedding an "Author:" or "Committer:" header in the metainfo file. Signed-off-by: Peter Krefting <peter@softwolves.pp.se> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Peter Krefting committed
Sep 3, 2009 at 13:15 UTC
7e787953fb89fbe403060585f7c39f0c75f29318
1 file changed
+46
-4
contrib/fast-import/import-tars.perl
+46
-4
@@ -8,9 +8,20 @@
8
## perl import-tars.perl *.tar.bz2
9
## git whatchanged import-tars
10
##
11
+## Use --metainfo to specify the extension for a meta data file, where
12
+## import-tars can read the commit message and optionally author and
13
+## committer information.
14
+##
15
+## echo 'This is the commit message' > myfile.tar.bz2.msg
16
+## perl import-tars.perl --metainfo=msg myfile.tar.bz2
17
18
use strict;
13
-die "usage: import-tars *.tar.{gz,bz2,Z}\n" unless @ARGV;
19
+use Getopt::Long;
20
+
21
+my $metaext = '';
22
+
23
+die "usage: import-tars [--metainfo=extension] *.tar.{gz,bz2,Z}\n"
24
+ unless GetOptions('metainfo=s' => \$metaext) && @ARGV;
25
26
my $branch_name = 'import-tars';
27
my $branch_ref = "refs/heads/$branch_name";
@@ -109,12 +120,43 @@ foreach my $tar_file (@ARGV)
120
$have_top_dir = 0 if $top_dir ne $1;
121
}
122
123
+ my $commit_msg = "Imported from $tar_file.";
124
+ my $this_committer_name = $committer_name;
125
+ my $this_committer_email = $committer_email;
126
+ my $this_author_name = $author_name;
127
+ my $this_author_email = $author_email;
128
+ if ($metaext ne '') {
129
+ # Optionally read a commit message from <filename.tar>.msg
130
+ # Add a line on the form "Committer: name <e-mail>" to override
131
+ # the committer and "Author: name <e-mail>" to override the
132
+ # author for this tar ball.
133
+ if (open MSG, '<', "${tar_file}.${metaext}") {
134
+ my $header_done = 0;
135
+ $commit_msg = '';
136
+ while (<MSG>) {
137
+ if (!$header_done && /^Committer:\s+([^<>]*)\s+<(.*)>\s*$/i) {
138
+ $this_committer_name = $1;
139
+ $this_committer_email = $2;
140
+ } elsif (!$header_done && /^Author:\s+([^<>]*)\s+<(.*)>\s*$/i) {
141
+ $this_author_name = $1;
142
+ $this_author_email = $2;
143
+ } elsif (!$header_done && /^$/ { # empty line ends header.
144
+ $header_done = 1;
145
+ } else {
146
+ $commit_msg .= $_;
147
+ $header_done = 1;
148
+ }
149
+ }
150
+ close MSG;
151
+ }
152
+ }
153
+
154
print FI <<EOF;
155
commit $branch_ref
114
-author $author_name <$author_email> $author_time +0000
115
-committer $committer_name <$committer_email> $commit_time +0000
156
+author $this_author_name <$this_author_email> $author_time +0000
157
+committer $this_committer_name <$this_committer_email> $commit_time +0000
158
data <<END_OF_COMMIT_MESSAGE
117
-Imported from $tar_file.
159
+$commit_msg
160
END_OF_COMMIT_MESSAGE
161
162
deleteall