{"thread":{"id":"3534","subject":"[PATCH 3/9] contrib/git-svn: strip 'git-svn-id:' when commiting to SVN","startedAt":"2006-03-03T09:20:07Z","lastAt":"2006-03-03T09:20:08Z","messageCount":3,"participants":["Eric Wong"],"isPatch":true,"patchVersion":1,"patchTotal":9},"messages":[{"id":"17109","messageId":"114137760733-git-send-email-normalperson@yhbt.net","threadId":"3534","inReplyTo":"11413776074148-git-send-email-normalperson@yhbt.net","subject":"[PATCH 2/9] contrib/git-svn: several small bug fixes and changes","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2006-03-03T09:20:07Z","receivedAt":"2006-03-03T09:20:07Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":" * Fixed manually-edited commit messages not going to\n   remotes/git-svn on sequential commits after the sequential\n   commit optimization.\n * format help correctly after adding 'show-ignore'\n * sha1_short regexp matches down to 4 hex characters\n   (from git-rev-parse --short documentation)\n * Print the first line of the commit message when we commit to\n   SVN next to the sha1.\n * Document 'T' (type change) in the comments\n\nSigned-off-by: Eric Wong <normalperson@yhbt.net>\n\n---\n\n contrib/git-svn/git-svn.perl |   27 +++++++++++++++++----------\n 1 files changed, 17 insertions(+), 10 deletions(-)\n\n43965ace71422148acb1bae488d78cbcfc5ca65e\ndiff --git a/contrib/git-svn/git-svn.perl b/contrib/git-svn/git-svn.perl\nindex 1f9a470..67368a5 100755\n--- a/contrib/git-svn/git-svn.perl\n+++ b/contrib/git-svn/git-svn.perl\n@@ -32,7 +32,7 @@ use Getopt::Long qw/:config gnu_getopt n\n use File::Spec qw//;\n use POSIX qw/strftime/;\n my $sha1 = qr/[a-f\\d]{40}/;\n-my $sha1_short = qr/[a-f\\d]{6,40}/;\n+my $sha1_short = qr/[a-f\\d]{4,40}/;\n my ($_revision,$_stdin,$_no_ignore_ext,$_no_stop_copy,$_help,$_rmdir,$_edit,\n \t$_find_copies_harder, $_l, $_version, $_upgrade);\n my (@_branch_from, %tree_map);\n@@ -90,12 +90,12 @@ Usage: $0 <command> [options] [arguments\n Available commands:\n \n \tforeach (sort keys %cmd) {\n-\t\tprint $fd '  ',pack('A10',$_),$cmd{$_}->[1],\"\\n\";\n+\t\tprint $fd '  ',pack('A13',$_),$cmd{$_}->[1],\"\\n\";\n \t}\n \tprint $fd <<\"\";\n \\nGIT_SVN_ID may be set in the environment to an arbitrary identifier if\n you're tracking multiple SVN branches/repositories in one git repository\n-and want to keep them separate.\n+and want to keep them separate.  See git-svn(1) for more information.\n \n \texit $exit;\n }\n@@ -245,7 +245,7 @@ sub commit {\n \t\tprint \"Reading from stdin...\\n\";\n \t\t@commits = ();\n \t\twhile (<STDIN>) {\n-\t\t\tif (/\\b([a-f\\d]{6,40})\\b/) {\n+\t\t\tif (/\\b($sha1_short)\\b/) {\n \t\t\t\tunshift @commits, $1;\n \t\t\t}\n \t\t}\n@@ -267,7 +267,6 @@ sub commit {\n \tchdir $SVN_WC or croak $!;\n \tmy $svn_current_rev =  svn_info('.')->{'Last Changed Rev'};\n \tforeach my $c (@revs) {\n-\t\tprint \"Committing $c\\n\";\n \t\tmy $mods = svn_checkout_tree($svn_current_rev, $c);\n \t\tif (scalar @$mods == 0) {\n \t\t\tprint \"Skipping, no changes detected\\n\";\n@@ -514,7 +513,7 @@ sub svn_checkout_tree {\n \tmy ($svn_rev, $treeish) = @_;\n \tmy $from = file_to_s(\"$REV_DIR/$svn_rev\");\n \tassert_svn_wc_clean($svn_rev,$from);\n-\tprint \"diff-tree '$from' '$treeish'\\n\";\n+\tprint \"diff-tree $from $treeish\\n\";\n \tmy $pid = open my $diff_fh, '-|';\n \tdefined $pid or croak $!;\n \tif ($pid == 0) {\n@@ -525,7 +524,7 @@ sub svn_checkout_tree {\n \t}\n \tmy $mods = parse_diff_tree($diff_fh);\n \tunless (@$mods) {\n-\t\t# git can do empty commits, SVN doesn't allow it...\n+\t\t# git can do empty commits, but SVN doesn't allow it...\n \t\treturn $mods;\n \t}\n \tmy ($rm, $add) = precommit_check($mods);\n@@ -612,7 +611,7 @@ sub svn_commit_tree {\n \tmy ($svn_rev, $commit) = @_;\n \tmy $commit_msg = \"$GIT_DIR/$GIT_SVN/.svn-commit.tmp.$$\";\n \tmy %log_msg = ( msg => '' );\n-\topen my $msg, '>', $commit_msg  or croak $!;\n+\topen my $msg, '>', $commit_msg or croak $!;\n \n \tchomp(my $type = `git-cat-file -t $commit`);\n \tif ($type eq 'commit') {\n@@ -627,7 +626,6 @@ sub svn_commit_tree {\n \t\t\tif (!$in_msg) {\n \t\t\t\t$in_msg = 1 if (/^\\s*$/);\n \t\t\t} else {\n-\t\t\t\t$log_msg{msg} .= $_;\n \t\t\t\tprint $msg $_ or croak $!;\n \t\t\t}\n \t\t}\n@@ -639,6 +637,15 @@ sub svn_commit_tree {\n \t\tmy $editor = $ENV{VISUAL} || $ENV{EDITOR} || 'vi';\n \t\tsystem($editor, $commit_msg);\n \t}\n+\n+\t# file_to_s removes all trailing newlines, so just use chomp() here:\n+\topen $msg, '<', $commit_msg or croak $!;\n+\t{ local $/; chomp($log_msg{msg} = <$msg>); }\n+\tclose $msg or croak $!;\n+\n+\tmy ($oneline) = ($log_msg{msg} =~ /([^\\n\\r]+)/);\n+\tprint \"Committing $commit: $oneline\\n\";\n+\n \tmy @ci_output = safe_qx(qw(svn commit -F),$commit_msg);\n \tmy ($committed) = grep(/^Committed revision \\d+\\./,@ci_output);\n \tunlink $commit_msg;\n@@ -1037,7 +1044,7 @@ diff-index line ($m hash)\n \tmode_a => first column of diff-index output, no leading ':',\n \tmode_b => second column of diff-index output,\n \tsha1_b => sha1sum of the final blob,\n-\tchg => change type [MCRAD],\n+\tchg => change type [MCRADT],\n \tfile_a => original file name of a file (iff chg is 'C' or 'R')\n \tfile_b => new/current file name of a file (any chg)\n }\n-- \n1.2.3.g4676\n"},{"id":"17103","messageId":"11413776082010-git-send-email-normalperson@yhbt.net","threadId":"3534","inReplyTo":"114137760733-git-send-email-normalperson@yhbt.net","subject":"[PATCH 3/9] contrib/git-svn: strip 'git-svn-id:' when commiting to SVN","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2006-03-03T09:20:08Z","receivedAt":"2006-03-03T09:20:08Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"We regenerate and use git-svn-id: whenever we fetch or otherwise\ncommit to remotes/git-svn.  We don't actually know what revision\nnumber we'll commit to SVN at commit time, so this is useless.\nIt won't throw off things like 'rebuild', though, which knows to\nonly use the last instance of git-svn-id: in a log message\n\nSigned-off-by: Eric Wong <normalperson@yhbt.net>\n\n---\n\n contrib/git-svn/git-svn.perl |    3 +++\n 1 files changed, 3 insertions(+), 0 deletions(-)\n\n15b28ddfc496fa88cffdfddcc9262cae635a34d0\ndiff --git a/contrib/git-svn/git-svn.perl b/contrib/git-svn/git-svn.perl\nindex 67368a5..edae9d4 100755\n--- a/contrib/git-svn/git-svn.perl\n+++ b/contrib/git-svn/git-svn.perl\n@@ -625,6 +625,9 @@ sub svn_commit_tree {\n \t\twhile (<$msg_fh>) {\n \t\t\tif (!$in_msg) {\n \t\t\t\t$in_msg = 1 if (/^\\s*$/);\n+\t\t\t} elsif (/^git-svn-id: /) {\n+\t\t\t\t# skip this, we regenerate the correct one\n+\t\t\t\t# on re-fetch anyways\n \t\t\t} else {\n \t\t\t\tprint $msg $_ or croak $!;\n \t\t\t}\n-- \n1.2.3.g4676\n"},{"id":"17107","messageId":"11413776082506-git-send-email-normalperson@yhbt.net","threadId":"3534","inReplyTo":"11413776082010-git-send-email-normalperson@yhbt.net","subject":"[PATCH 4/9] contrib/git-svn: allow --authors-file to be specified","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2006-03-03T09:20:08Z","receivedAt":"2006-03-03T09:20:08Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"Syntax is compatible with git-svnimport and git-cvsimport:\n\n\tnormalperson = Eric Wong <normalperson@yhbt.net>\n\nIf this option is specified and git-svn encounters an SVN\ncommitter name that it cannot parse, it git-svn will abort.\n\nSigned-off-by: Eric Wong <normalperson@yhbt.net>\n\n---\n\n contrib/git-svn/git-svn.perl |   40 ++++++++++++++++++++++++++++++++--------\n 1 files changed, 32 insertions(+), 8 deletions(-)\n\nc501f8378dfb5529993755caaf99ca632418e382\ndiff --git a/contrib/git-svn/git-svn.perl b/contrib/git-svn/git-svn.perl\nindex edae9d4..c2b4ee9 100755\n--- a/contrib/git-svn/git-svn.perl\n+++ b/contrib/git-svn/git-svn.perl\n@@ -34,8 +34,8 @@ use POSIX qw/strftime/;\n my $sha1 = qr/[a-f\\d]{40}/;\n my $sha1_short = qr/[a-f\\d]{4,40}/;\n my ($_revision,$_stdin,$_no_ignore_ext,$_no_stop_copy,$_help,$_rmdir,$_edit,\n-\t$_find_copies_harder, $_l, $_version, $_upgrade);\n-my (@_branch_from, %tree_map);\n+\t$_find_copies_harder, $_l, $_version, $_upgrade, $_authors);\n+my (@_branch_from, %tree_map, %users);\n \n GetOptions(\t'revision|r=s' => \\$_revision,\n \t\t'no-ignore-externals' => \\$_no_ignore_ext,\n@@ -46,6 +46,7 @@ GetOptions(\t'revision|r=s' => \\$_revisio\n \t\t'help|H|h' => \\$_help,\n \t\t'branch|b=s' => \\@_branch_from,\n \t\t'find-copies-harder' => \\$_find_copies_harder,\n+\t\t'authors-file|authors|A=s' => \\$_authors,\n \t\t'l=i' => \\$_l,\n \t\t'version|V' => \\$_version,\n \t\t'no-stop-on-copy' => \\$_no_stop_copy );\n@@ -73,6 +74,19 @@ foreach (keys %cmd) {\n \t\tlast;\n \t}\n }\n+\n+# '<svn username> = real-name <email address>' mapping based on git-svnimport:\n+if ($_authors) {\n+\topen my $authors, '<', $_authors or die \"Can't open $_authors $!\\n\";\n+\twhile (<$authors>) {\n+\t\tchomp;\n+\t\tnext unless /^(\\S+?)\\s*=\\s*(.+?)\\s*<(.+)>\\s*$/;\n+\t\tmy ($user, $name, $email) = ($1, $2, $3);\n+\t\t$users{$user} = [$name, $email];\n+\t}\n+\tclose $authors or croak $!;\n+}\n+\n usage(0) if $_help;\n version() if $_version;\n usage(1) unless (defined $cmd);\n@@ -740,6 +754,10 @@ sub svn_log_raw {\n \t\t\t\t\tauthor => $author,\n \t\t\t\t\tlines => $lines,\n \t\t\t\t\tmsg => '' );\n+\t\t\tif (defined $_authors && ! defined $users{$author}) {\n+\t\t\t\tdie \"Author: $author not defined in \",\n+\t\t\t\t\t\t\"$_authors file\\n\";\n+\t\t\t}\n \t\t\tpush @svn_log, \\%log_msg;\n \t\t\t$state = 'msg_start';\n \t\t\tnext;\n@@ -884,12 +902,8 @@ sub git_commit {\n \t\t$msg_fh->flush == 0 or croak $!;\n \t\tseek $msg_fh, 0, 0 or croak $!;\n \n-\t\t$ENV{GIT_AUTHOR_NAME} = $ENV{GIT_COMMITTER_NAME} =\n-\t\t\t\t\t\t$log_msg->{author};\n-\t\t$ENV{GIT_AUTHOR_EMAIL} = $ENV{GIT_COMMITTER_EMAIL} =\n-\t\t\t\t\t\t$log_msg->{author}.\"\\@$uuid\";\n-\t\t$ENV{GIT_AUTHOR_DATE} = $ENV{GIT_COMMITTER_DATE} =\n-\t\t\t\t\t\t$log_msg->{date};\n+\t\tset_commit_env($log_msg, $uuid);\n+\n \t\tmy @exec = ('git-commit-tree',$tree);\n \t\tpush @exec, '-p', $_  foreach @exec_parents;\n \t\topen STDIN, '<&', $msg_fh or croak $!;\n@@ -915,6 +929,16 @@ sub git_commit {\n \treturn $commit;\n }\n \n+sub set_commit_env {\n+\tmy ($log_msg, $uuid) = @_;\n+\tmy $author = $log_msg->{author};\n+\tmy ($name,$email) = defined $users{$author} ?  @{$users{$author}}\n+\t\t\t\t: ($author,\"$author\\@$uuid\");\n+\t$ENV{GIT_AUTHOR_NAME} = $ENV{GIT_COMMITTER_NAME} = $name;\n+\t$ENV{GIT_AUTHOR_EMAIL} = $ENV{GIT_COMMITTER_EMAIL} = $email;\n+\t$ENV{GIT_AUTHOR_DATE} = $ENV{GIT_COMMITTER_DATE} = $log_msg->{date};\n+}\n+\n sub apply_mod_line_blob {\n \tmy $m = shift;\n \tif ($m->{mode_b} =~ /^120/) {\n-- \n1.2.3.g4676\n"}]}