contrib/git-svn: several small bug fixes and changes
* Fixed manually-edited commit messages not going to remotes/git-svn on sequential commits after the sequential commit optimization. * format help correctly after adding 'show-ignore' * sha1_short regexp matches down to 4 hex characters (from git-rev-parse --short documentation) * Print the first line of the commit message when we commit to SVN next to the sha1. * Document 'T' (type change) in the comments 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
ac8e0b910c722249b4d21dcf99eea2335f48dfe7
1 file changed
+17
-10
contrib/git-svn/git-svn.perl
+17
-10
@@ -32,7 +32,7 @@ use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
32
use File::Spec qw//;
33
use POSIX qw/strftime/;
34
my $sha1 = qr/[a-f\d]{40}/;
35
-my $sha1_short = qr/[a-f\d]{6,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);
@@ -90,12 +90,12 @@ Usage: $0 <command> [options] [arguments]\n
90
Available commands:
91
92
foreach (sort keys %cmd) {
93
- print $fd ' ',pack('A10',$_),$cmd{$_}->[1],"\n";
93
+ print $fd ' ',pack('A13',$_),$cmd{$_}->[1],"\n";
94
}
95
print $fd <<"";
96
\nGIT_SVN_ID may be set in the environment to an arbitrary identifier if
97
you're tracking multiple SVN branches/repositories in one git repository
98
-and want to keep them separate.
98
+and want to keep them separate. See git-svn(1) for more information.
99
100
exit $exit;
101
}
@@ -245,7 +245,7 @@ sub commit {
245
print "Reading from stdin...\n";
246
@commits = ();
247
while (<STDIN>) {
248
- if (/\b([a-f\d]{6,40})\b/) {
248
+ if (/\b($sha1_short)\b/) {
249
unshift @commits, $1;
250
}
251
}
@@ -267,7 +267,6 @@ sub commit {
267
chdir $SVN_WC or croak $!;
268
my $svn_current_rev = svn_info('.')->{'Last Changed Rev'};
269
foreach my $c (@revs) {
270
- print "Committing $c\n";
270
my $mods = svn_checkout_tree($svn_current_rev, $c);
271
if (scalar @$mods == 0) {
272
print "Skipping, no changes detected\n";
@@ -514,7 +513,7 @@ sub svn_checkout_tree {
513
my ($svn_rev, $treeish) = @_;
514
my $from = file_to_s("$REV_DIR/$svn_rev");
515
assert_svn_wc_clean($svn_rev,$from);
517
- print "diff-tree '$from' '$treeish'\n";
516
+ print "diff-tree $from $treeish\n";
517
my $pid = open my $diff_fh, '-|';
518
defined $pid or croak $!;
519
if ($pid == 0) {
@@ -525,7 +524,7 @@ sub svn_checkout_tree {
524
}
525
my $mods = parse_diff_tree($diff_fh);
526
unless (@$mods) {
528
- # git can do empty commits, SVN doesn't allow it...
527
+ # git can do empty commits, but SVN doesn't allow it...
528
return $mods;
529
}
530
my ($rm, $add) = precommit_check($mods);
@@ -612,7 +611,7 @@ sub svn_commit_tree {
611
my ($svn_rev, $commit) = @_;
612
my $commit_msg = "$GIT_DIR/$GIT_SVN/.svn-commit.tmp.$$";
613
my %log_msg = ( msg => '' );
615
- open my $msg, '>', $commit_msg or croak $!;
614
+ open my $msg, '>', $commit_msg or croak $!;
615
616
chomp(my $type = `git-cat-file -t $commit`);
617
if ($type eq 'commit') {
@@ -627,7 +626,6 @@ sub svn_commit_tree {
626
if (!$in_msg) {
627
$in_msg = 1 if (/^\s*$/);
628
} else {
630
- $log_msg{msg} .= $_;
629
print $msg $_ or croak $!;
630
}
631
}
@@ -639,6 +637,15 @@ sub svn_commit_tree {
637
my $editor = $ENV{VISUAL} || $ENV{EDITOR} || 'vi';
638
system($editor, $commit_msg);
639
}
640
+
641
+ # file_to_s removes all trailing newlines, so just use chomp() here:
642
+ open $msg, '<', $commit_msg or croak $!;
643
+ { local $/; chomp($log_msg{msg} = <$msg>); }
644
+ close $msg or croak $!;
645
+
646
+ my ($oneline) = ($log_msg{msg} =~ /([^\n\r]+)/);
647
+ print "Committing $commit: $oneline\n";
648
+
649
my @ci_output = safe_qx(qw(svn commit -F),$commit_msg);
650
my ($committed) = grep(/^Committed revision \d+\./,@ci_output);
651
unlink $commit_msg;
@@ -1037,7 +1044,7 @@ diff-index line ($m hash)
1044
mode_a => first column of diff-index output, no leading ':',
1045
mode_b => second column of diff-index output,
1046
sha1_b => sha1sum of the final blob,
1040
- chg => change type [MCRAD],
1047
+ chg => change type [MCRADT],
1048
file_a => original file name of a file (iff chg is 'C' or 'R')
1049
file_b => new/current file name of a file (any chg)
1050
}