import-tars: separate author from committer
The import-tars script is typically employed to (re)create the past history of a project from stored tars. Although assigning authorship in these cases can be a somewhat arbitrary process, it makes sense to set the author to whoever created the tars in the first place (if it's known), and (s)he can in general be different from the committer (whoever is running the script). Implement this by having separate author and committer data, making them settable from the usual GIT_* environment variables. Acked-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Giuseppe Bilotta committed
Mar 20, 2009 at 10:57 UTC
6872f606d9bc9a0ab0b3252bd4175af7732b6135
1 file changed
+11
-5
contrib/fast-import/import-tars.perl
+11
-5
@@ -14,13 +14,18 @@ die "usage: import-tars *.tar.{gz,bz2,Z}\n" unless @ARGV;
14
15
my $branch_name = 'import-tars';
16
my $branch_ref = "refs/heads/$branch_name";
17
-my $committer_name = 'T Ar Creator';
18
-my $committer_email = 'tar@example.com';
17
+my $author_name = $ENV{'GIT_AUTHOR_NAME'} || 'T Ar Creator';
18
+my $author_email = $ENV{'GIT_AUTHOR_EMAIL'} || 'tar@example.com';
19
+my $committer_name = $ENV{'GIT_COMMITTER_NAME'} || `git config --get user.name`;
20
+my $committer_email = $ENV{'GIT_COMMITTER_EMAIL'} || `git config --get user.email`;
21
+
22
+chomp($committer_name, $committer_email);
23
24
open(FI, '|-', 'git', 'fast-import', '--quiet')
25
or die "Unable to start git fast-import: $!\n";
26
foreach my $tar_file (@ARGV)
27
{
28
+ my $commit_time = time;
29
$tar_file =~ m,([^/]+)$,;
30
my $tar_name = $1;
31
@@ -39,7 +44,7 @@ foreach my $tar_file (@ARGV)
44
die "Unrecognized compression format: $tar_file\n";
45
}
46
42
- my $commit_time = 0;
47
+ my $author_time = 0;
48
my $next_mark = 1;
49
my $have_top_dir = 1;
50
my ($top_dir, %files);
@@ -92,7 +97,7 @@ foreach my $tar_file (@ARGV)
97
}
98
$files{$path} = [$next_mark++, $mode];
99
95
- $commit_time = $mtime if $mtime > $commit_time;
100
+ $author_time = $mtime if $mtime > $author_time;
101
$path =~ m,^([^/]+)/,;
102
$top_dir = $1 unless $top_dir;
103
$have_top_dir = 0 if $top_dir ne $1;
@@ -100,6 +105,7 @@ foreach my $tar_file (@ARGV)
105
106
print FI <<EOF;
107
commit $branch_ref
108
+author $author_name <$author_email> $author_time +0000
109
committer $committer_name <$committer_email> $commit_time +0000
110
data <<END_OF_COMMIT_MESSAGE
111
Imported from $tar_file.
@@ -119,7 +125,7 @@ EOF
125
print FI <<EOF;
126
tag $tar_name
127
from $branch_ref
122
-tagger $committer_name <$committer_email> $commit_time +0000
128
+tagger $author_name <$author_email> $author_time +0000
129
data <<END_OF_TAG_MESSAGE
130
Package $tar_name
131
END_OF_TAG_MESSAGE