@matheusbsbs / matheus-bagliano / commits / 8cd1621149
Fork 0

cvsimport: ease migration from CVSROOT/users format

This fixes a minor bug, which caused the author email to be doubly enclosed in a <> pair (the code gave enclosing <> to GIT_AUTHOR_EMAIL and GIT_COMMITTER_EMAIL environment variable). The read_author_info() subroutine is taught to also understand the user list in CVSROOT/users format. This is primarily done to ease migration for CVS users, who can use the -A option to read from existing CVSROOT/users file. write_author_info() always writes in the git-cvsimport's native format ('=' delimited and value without quotes). Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jan 15, 2006 at 03:30 UTC 8cd162114990a4b36aeefc672dedc597c2eacbf0
1 file changed +20 -9
git-cvsimport.perl
+20 -9
@@ -48,16 +48,28 @@ sub read_author_info($) {
48 open my $f, '<', "$file" or die("Failed to open $file: $!\n");
49
50 while (<$f>) {
51 - chomp;
52 - # Expected format is this;
51 + # Expected format is this:
52 # exon=Andreas Ericsson <ae@op5.se>
54 - if (m/^([^ \t=]*)[ \t=]*([^<]*)(<.*$)\s*/) {
53 + if (m/^(\S+?)\s*=\s*(.+?)\s*<(.+)>\s*$/) {
54 $user = $1;
56 - $conv_author_name{$1} = $2;
57 - $conv_author_email{$1} = $3;
58 - # strip trailing whitespace from author name
59 - $conv_author_name{$1} =~ s/\s*$//;
55 + $conv_author_name{$user} = $2;
56 + $conv_author_email{$user} = $3;
57 }
58 + # However, we also read from CVSROOT/users format
59 + # to ease migration.
60 + elsif (/^(\w+):(['"]?)(.+?)\2\s*$/) {
61 + my $mapped;
62 + ($user, $mapped) = ($1, $3);
63 + if ($mapped =~ /^\s*(.*?)\s*<(.*)>\s*$/) {
64 + $conv_author_name{$user} = $1;
65 + $conv_author_email{$user} = $2;
66 + }
67 + elsif ($mapped =~ /^<?(.*)>?$/) {
68 + $conv_author_name{$user} = $user;
69 + $conv_author_email{$user} = $1;
70 + }
71 + }
72 + # NEEDSWORK: Maybe warn on unrecognized lines?
73 }
74 close ($f);
75 }
@@ -68,8 +80,7 @@ sub write_author_info($) {
80 die("Failed to open $file for writing: $!");
81
82 foreach (keys %conv_author_name) {
71 - print $f "$_=" . $conv_author_name{$_} .
72 - " " . $conv_author_email{$_} . "\n";
83 + print $f "$_=$conv_author_name{$_} <$conv_author_email{$_}>\n";
84 }
85 close ($f);
86 }