|
8 | 8 | ## perl import-tars.perl *.tar.bz2
|
9 | 9 | ## git whatchanged import-tars
|
10 | 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 |
11 | 17 |
|
12 | 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; |
14 | 25 |
|
15 | 26 | my $branch_name = 'import-tars';
|
16 | 27 | my $branch_ref = "refs/heads/$branch_name";
|
|
109 | 120 | $have_top_dir = 0 if $top_dir ne $1;
|
110 | 121 | }
|
111 | 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 | + |
112 | 154 | print FI <<EOF;
|
113 | 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 |
116 | 158 | data <<END_OF_COMMIT_MESSAGE
|
117 |
| -Imported from $tar_file. |
| 159 | +$commit_msg |
118 | 160 | END_OF_COMMIT_MESSAGE
|
119 | 161 |
|
120 | 162 | deleteall
|
|
0 commit comments