Skip to content

Commit 4a452ed

Browse files
committed
Merge branch 'pk/fast-import-tars'
* pk/fast-import-tars: import-tars: Allow per-tar author and commit message.
2 parents d821c00 + 7e78795 commit 4a452ed

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

contrib/fast-import/import-tars.perl

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,20 @@
88
## perl import-tars.perl *.tar.bz2
99
## git whatchanged import-tars
1010
##
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
1117

1218
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;
1425

1526
my $branch_name = 'import-tars';
1627
my $branch_ref = "refs/heads/$branch_name";
@@ -109,12 +120,43 @@
109120
$have_top_dir = 0 if $top_dir ne $1;
110121
}
111122

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+
112154
print FI <<EOF;
113155
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
116158
data <<END_OF_COMMIT_MESSAGE
117-
Imported from $tar_file.
159+
$commit_msg
118160
END_OF_COMMIT_MESSAGE
119161
120162
deleteall

0 commit comments

Comments
 (0)