Skip to content

Commit

Permalink
contrib/git-svn: allow --authors-file to be specified
Browse files Browse the repository at this point in the history
Syntax is compatible with git-svnimport and git-cvsimport:

	normalperson = Eric Wong <normalperson@yhbt.net>

If this option is specified and git-svn encounters an SVN
committer name that it cannot parse, it git-svn will abort.

Signed-off-by: Eric Wong <normalperson@yhbt.net>
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Eric Wong authored and Junio C Hamano committed Mar 3, 2006
1 parent df746c5 commit a9612be
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions contrib/git-svn/git-svn.perl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
my $sha1 = qr/[a-f\d]{40}/;
my $sha1_short = qr/[a-f\d]{4,40}/;
my ($_revision,$_stdin,$_no_ignore_ext,$_no_stop_copy,$_help,$_rmdir,$_edit,
$_find_copies_harder, $_l, $_version, $_upgrade);
my (@_branch_from, %tree_map);
$_find_copies_harder, $_l, $_version, $_upgrade, $_authors);
my (@_branch_from, %tree_map, %users);

GetOptions( 'revision|r=s' => \$_revision,
'no-ignore-externals' => \$_no_ignore_ext,
Expand All @@ -46,6 +46,7 @@
'help|H|h' => \$_help,
'branch|b=s' => \@_branch_from,
'find-copies-harder' => \$_find_copies_harder,
'authors-file|authors|A=s' => \$_authors,
'l=i' => \$_l,
'version|V' => \$_version,
'no-stop-on-copy' => \$_no_stop_copy );
Expand Down Expand Up @@ -73,6 +74,19 @@
last;
}
}

# '<svn username> = real-name <email address>' mapping based on git-svnimport:
if ($_authors) {
open my $authors, '<', $_authors or die "Can't open $_authors $!\n";
while (<$authors>) {
chomp;
next unless /^(\S+?)\s*=\s*(.+?)\s*<(.+)>\s*$/;
my ($user, $name, $email) = ($1, $2, $3);
$users{$user} = [$name, $email];
}
close $authors or croak $!;
}

usage(0) if $_help;
version() if $_version;
usage(1) unless (defined $cmd);
Expand Down Expand Up @@ -740,6 +754,10 @@ sub svn_log_raw {
author => $author,
lines => $lines,
msg => '' );
if (defined $_authors && ! defined $users{$author}) {
die "Author: $author not defined in ",
"$_authors file\n";
}
push @svn_log, \%log_msg;
$state = 'msg_start';
next;
Expand Down Expand Up @@ -884,12 +902,8 @@ sub git_commit {
$msg_fh->flush == 0 or croak $!;
seek $msg_fh, 0, 0 or croak $!;

$ENV{GIT_AUTHOR_NAME} = $ENV{GIT_COMMITTER_NAME} =
$log_msg->{author};
$ENV{GIT_AUTHOR_EMAIL} = $ENV{GIT_COMMITTER_EMAIL} =
$log_msg->{author}."\@$uuid";
$ENV{GIT_AUTHOR_DATE} = $ENV{GIT_COMMITTER_DATE} =
$log_msg->{date};
set_commit_env($log_msg, $uuid);

my @exec = ('git-commit-tree',$tree);
push @exec, '-p', $_ foreach @exec_parents;
open STDIN, '<&', $msg_fh or croak $!;
Expand All @@ -915,6 +929,16 @@ sub git_commit {
return $commit;
}

sub set_commit_env {
my ($log_msg, $uuid) = @_;
my $author = $log_msg->{author};
my ($name,$email) = defined $users{$author} ? @{$users{$author}}
: ($author,"$author\@$uuid");
$ENV{GIT_AUTHOR_NAME} = $ENV{GIT_COMMITTER_NAME} = $name;
$ENV{GIT_AUTHOR_EMAIL} = $ENV{GIT_COMMITTER_EMAIL} = $email;
$ENV{GIT_AUTHOR_DATE} = $ENV{GIT_COMMITTER_DATE} = $log_msg->{date};
}

sub apply_mod_line_blob {
my $m = shift;
if ($m->{mode_b} =~ /^120/) {
Expand Down

0 comments on commit a9612be

Please sign in to comment.