{"thread":{"id":"30632","subject":"[PATCH] Implement --messages-prog parameter in git-svn","startedAt":"2012-05-26T15:56:42Z","lastAt":"2012-05-26T15:56:42Z","messageCount":1,"participants":["Klaus Reimer"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"192246","messageId":"4FC0FD3A.8080803@ailis.de","threadId":"30632","inReplyTo":null,"subject":"[PATCH] Implement --messages-prog parameter in git-svn","fromName":"Klaus Reimer","fromEmail":"k@ailis.de","sentAt":"2012-05-26T15:56:42Z","receivedAt":"2012-05-26T15:56:42Z","isPatch":true,"sender":{"key":"k@ailis.de","avatar":null},"body":"Some SVN repositories have strange policies for commit messages requiring an\nempty line at the top of the commit message.  When you clone these\nrepositories with Git to mirror them on GitHub then no commit message\nsummaries are displayed at all at GitHub because they use the first line for\nit (Which is empty).  You always have to open the commit message details\ninstead which is pretty annoying.  With the --messages-prog parameter you\ncan specify a program which can modify the SVN commit message before\ncommitting it into the Git repo.  This works like the --authors-prog\nparameter with the only difference that the commit message is piped into the\nspecified program instead of being passed to it as a command-line argument.\n\nThe same could be achieved by a \"trim\" feature but specifying a program\nwhich can modify any aspect of a commit message is much more flexible.\n\nSigned-off-by: Klaus Reimer <k@ailis.de>\n---\n Documentation/git-svn.txt        |  5 +++++\n git-svn.perl                     | 26 +++++++++++++++++++++++++-\n t/t9147-git-svn-messages-prog.sh | 40 ++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 70 insertions(+), 1 deletion(-)\n create mode 100755 t/t9147-git-svn-messages-prog.sh\n\ndiff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt\nindex cfe8d2b..7289246 100644\n--- a/Documentation/git-svn.txt\n+++ b/Documentation/git-svn.txt\n@@ -546,6 +546,11 @@ config key: svn.authorsfile\n \texpected to return a single line of the form \"Name <email>\",\n \twhich will be treated as if included in the authors file.\n \n+--messages-prog=<filename>::\n+\tIf this option is specified, each SVN commit message is piped\n+\tthrough the given program. The output of this program is then\n+\tused as the new commit message instead.\n+\n -q::\n --quiet::\n \tMake 'git svn' less verbose. Specify a second time to make it\ndiff --git a/git-svn.perl b/git-svn.perl\nindex c84842f..514c888 100755\n--- a/git-svn.perl\n+++ b/git-svn.perl\n@@ -6,7 +6,7 @@ use warnings;\n use strict;\n use vars qw/\t$AUTHOR $VERSION\n \t\t$sha1 $sha1_short $_revision $_repository\n-\t\t$_q $_authors $_authors_prog %users/;\n+\t\t$_q $_authors $_authors_prog $_messages_prog %users/;\n $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';\n $VERSION = '@@GIT_VERSION@@';\n \n@@ -120,6 +120,7 @@ my %remote_opts = ( 'username=s' => \\$Git::SVN::Prompt::_username,\n my %fc_opts = ( 'follow-parent|follow!' => \\$Git::SVN::_follow_parent,\n \t\t'authors-file|A=s' => \\$_authors,\n \t\t'authors-prog=s' => \\$_authors_prog,\n+\t\t'messages-prog=s' => \\$_messages_prog,\n \t\t'repack:i' => \\$Git::SVN::_repack,\n \t\t'noMetadata' => \\$Git::SVN::_no_metadata,\n \t\t'useSvmProps' => \\$Git::SVN::_use_svm_props,\n@@ -359,6 +360,9 @@ load_authors() if $_authors;\n if (defined $_authors_prog) {\n \t$_authors_prog = \"'\" . File::Spec->rel2abs($_authors_prog) . \"'\";\n }\n+if (defined $_messages_prog) {\n+\t$_messages_prog = \"'\" . File::Spec->rel2abs($_messages_prog) . \"'\";\n+}\n \n unless ($cmd =~ /^(?:clone|init|multi-init|commit-diff)$/) {\n \tGit::SVN::Migration::migration_check();\n@@ -2051,6 +2055,7 @@ use vars qw/$default_repo_id $default_ref_id $_no_metadata $_follow_parent\n use Carp qw/croak/;\n use File::Path qw/mkpath/;\n use File::Copy qw/copy/;\n+use IPC::Open2;\n use IPC::Open3;\n use Time::Local;\n use Memoize;  # core since 5.8.0, Jul 2002\n@@ -3409,6 +3414,22 @@ sub other_gs {\n \t$gs\n }\n \n+sub call_messages_prog {\n+\tmy ($orig_message) = @_;\n+\tmy ($pid, $in, $out);\n+\t\n+\t$pid = open2($in, $out, $::_messages_prog)\t\n+\t\tor die \"$::_messages_prog failed with exit code $?\\n\";\n+\tprint $out $orig_message;\n+\tclose($out);\n+\tmy ($message) = \"\";\n+\twhile (<$in>) {\n+\t\t$message .= $_;\n+\t}\n+\tclose($in);\n+\treturn $message;    \n+}\n+\n sub call_authors_prog {\n \tmy ($orig_author) = @_;\n \t$orig_author = command_oneline('rev-parse', '--sq-quote', $orig_author);\n@@ -3809,6 +3830,9 @@ sub make_log_entry {\n \n \t$log_entry{date} = parse_svn_date($log_entry{date});\n \t$log_entry{log} .= \"\\n\";\n+\tif (defined $::_messages_prog) {\n+\t\t$log_entry{log} = call_messages_prog($log_entry{log});\n+\t}\n \tmy $author = $log_entry{author} = check_author($log_entry{author});\n \tmy ($name, $email) = defined $::users{$author} ? @{$::users{$author}}\n \t\t\t\t\t\t       : ($author, undef);\ndiff --git a/t/t9147-git-svn-messages-prog.sh b/t/t9147-git-svn-messages-prog.sh\nnew file mode 100755\nindex 0000000..ebb42b0\n--- /dev/null\n+++ b/t/t9147-git-svn-messages-prog.sh\n@@ -0,0 +1,40 @@\n+#!/bin/sh\n+\n+test_description='git svn messages prog tests'\n+\n+. ./lib-git-svn.sh\n+\n+cat > svn-messages-prog <<'EOF'\n+#!/bin/sh\n+sed s/foo/bar/g\n+EOF\n+chmod +x svn-messages-prog\n+\n+test_expect_success 'setup svnrepo' '\n+\tsvn mkdir -m \"Unchanged message\" \"$svnrepo\"/a\n+\tsvn mkdir -m \"Changed message: foo\" \"$svnrepo\"/b\n+\t'\n+\n+test_expect_success 'import messages with prog' '\n+\tgit svn clone --messages-prog=./svn-messages-prog \\\n+\t    \"$svnrepo\" x\n+\t'\n+\n+test_expect_success 'imported 2 revisions successfully' '\n+\t(\n+\t\tcd x\n+\t\ttest \"`git rev-list refs/remotes/git-svn | wc -l`\" -eq 2\n+\t)\n+\t'\n+\n+test_expect_success 'messages-prog ran correctly' '\n+\t(\n+\t\tcd x\n+\t\tgit rev-list -1 --pretty=raw refs/remotes/git-svn~1 | \\\n+\t\t  grep \"^    Unchanged message\" &&\n+\t\tgit rev-list -1 --pretty=raw refs/remotes/git-svn~0 | \\\n+\t\t  grep \"^    Changed message: bar\"\n+\t)\n+\t'\n+\n+test_done\n-- \n1.7.10.2.605.gbefc5ed.dirty\n\n-- \nBye, K <http://www.ailis.de/~k/>\n[A735 47EC D87B 1F15 C1E9 53D3 AA03 6173 A723 E391]\n"}]}