@matheusbsbs / matheus-bagliano / commits / 328eb9b32f
Fork 0

git-svn: don't append extra newlines at the end of commit messages.

In git, all commits end in exactly one newline character. In svn, commits end in zero or more newlines. Thus, when importing commits from svn into git, git-svn always appends two extra newlines to ensure that the git-svn-id: line is separated from the main commit message by at least one blank line. Combined with the terminating newline that's always present in svn commits produced by git, you usually end up with two blank lines instead of one between the commit message and git-svn-id: line, which is undesirable. Instead, let's remove all trailing whitespace from the git commit on the way through to svn. Signed-off-by: Avery Pennarun <apenwarr@gmail.com> Acked-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Avery Pennarun committed Jun 12, 2008 at 19:10 UTC 328eb9b32f7babfb182bad8655491aa6265e96eb
1 file changed +5 -3
git-svn.perl
+5 -3
@@ -1023,6 +1023,7 @@ sub get_commit_entry {
1023 my $in_msg = 0;
1024 my $author;
1025 my $saw_from = 0;
1026 + my $msgbuf = "";
1027 while (<$msg_fh>) {
1028 if (!$in_msg) {
1029 $in_msg = 1 if (/^\s*$/);
@@ -1035,14 +1036,15 @@ sub get_commit_entry {
1036 if (/^From:/ || /^Signed-off-by:/) {
1037 $saw_from = 1;
1038 }
1038 - print $log_fh $_ or croak $!;
1039 + $msgbuf .= $_;
1040 }
1041 }
1042 + $msgbuf =~ s/\s+$//s;
1043 if ($Git::SVN::_add_author_from && defined($author)
1044 && !$saw_from) {
1043 - print $log_fh "\nFrom: $author\n"
1044 - or croak $!;
1045 + $msgbuf .= "\n\nFrom: $author";
1046 }
1047 + print $log_fh $msgbuf or croak $!;
1048 command_close_pipe($msg_fh, $ctx);
1049 }
1050 close $log_fh or croak $!;