@matheusbsbs / matheus-bagliano / commits / a9612be245
Fork 0

contrib/git-svn: allow --authors-file to be specified

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>

Eric Wong committed Mar 3, 2006 at 01:20 UTC a9612be245dbb642240e8f20c7215186f1d58b6a
1 file changed +32 -8
contrib/git-svn/git-svn.perl
+32 -8
@@ -34,8 +34,8 @@ use POSIX qw/strftime/;
34 my $sha1 = qr/[a-f\d]{40}/;
35 my $sha1_short = qr/[a-f\d]{4,40}/;
36 my ($_revision,$_stdin,$_no_ignore_ext,$_no_stop_copy,$_help,$_rmdir,$_edit,
37 - $_find_copies_harder, $_l, $_version, $_upgrade);
38 -my (@_branch_from, %tree_map);
37 + $_find_copies_harder, $_l, $_version, $_upgrade, $_authors);
38 +my (@_branch_from, %tree_map, %users);
39
40 GetOptions( 'revision|r=s' => \$_revision,
41 'no-ignore-externals' => \$_no_ignore_ext,
@@ -46,6 +46,7 @@ GetOptions( 'revision|r=s' => \$_revision,
46 'help|H|h' => \$_help,
47 'branch|b=s' => \@_branch_from,
48 'find-copies-harder' => \$_find_copies_harder,
49 + 'authors-file|authors|A=s' => \$_authors,
50 'l=i' => \$_l,
51 'version|V' => \$_version,
52 'no-stop-on-copy' => \$_no_stop_copy );
@@ -73,6 +74,19 @@ foreach (keys %cmd) {
74 last;
75 }
76 }
77 +
78 +# '<svn username> = real-name <email address>' mapping based on git-svnimport:
79 +if ($_authors) {
80 + open my $authors, '<', $_authors or die "Can't open $_authors $!\n";
81 + while (<$authors>) {
82 + chomp;
83 + next unless /^(\S+?)\s*=\s*(.+?)\s*<(.+)>\s*$/;
84 + my ($user, $name, $email) = ($1, $2, $3);
85 + $users{$user} = [$name, $email];
86 + }
87 + close $authors or croak $!;
88 +}
89 +
90 usage(0) if $_help;
91 version() if $_version;
92 usage(1) unless (defined $cmd);
@@ -740,6 +754,10 @@ sub svn_log_raw {
754 author => $author,
755 lines => $lines,
756 msg => '' );
757 + if (defined $_authors && ! defined $users{$author}) {
758 + die "Author: $author not defined in ",
759 + "$_authors file\n";
760 + }
761 push @svn_log, \%log_msg;
762 $state = 'msg_start';
763 next;
@@ -884,12 +902,8 @@ sub git_commit {
902 $msg_fh->flush == 0 or croak $!;
903 seek $msg_fh, 0, 0 or croak $!;
904
887 - $ENV{GIT_AUTHOR_NAME} = $ENV{GIT_COMMITTER_NAME} =
888 - $log_msg->{author};
889 - $ENV{GIT_AUTHOR_EMAIL} = $ENV{GIT_COMMITTER_EMAIL} =
890 - $log_msg->{author}."\@$uuid";
891 - $ENV{GIT_AUTHOR_DATE} = $ENV{GIT_COMMITTER_DATE} =
892 - $log_msg->{date};
905 + set_commit_env($log_msg, $uuid);
906 +
907 my @exec = ('git-commit-tree',$tree);
908 push @exec, '-p', $_ foreach @exec_parents;
909 open STDIN, '<&', $msg_fh or croak $!;
@@ -915,6 +929,16 @@ sub git_commit {
929 return $commit;
930 }
931
932 +sub set_commit_env {
933 + my ($log_msg, $uuid) = @_;
934 + my $author = $log_msg->{author};
935 + my ($name,$email) = defined $users{$author} ? @{$users{$author}}
936 + : ($author,"$author\@$uuid");
937 + $ENV{GIT_AUTHOR_NAME} = $ENV{GIT_COMMITTER_NAME} = $name;
938 + $ENV{GIT_AUTHOR_EMAIL} = $ENV{GIT_COMMITTER_EMAIL} = $email;
939 + $ENV{GIT_AUTHOR_DATE} = $ENV{GIT_COMMITTER_DATE} = $log_msg->{date};
940 +}
941 +
942 sub apply_mod_line_blob {
943 my $m = shift;
944 if ($m->{mode_b} =~ /^120/) {