git-svn: correctly handle revision 0 in SVN repositories
some SVN repositories have a revision 0 (committed by no author and no date) when created; so when we need to ensure that we check any revision variables are defined, and not just non-zero. Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
Eric Wong committed
Nov 23, 2006 at 14:54 UTC
e70dc780a4325138ddfae6786c1eb3ec06233de6
1 file changed
+10
-4
git-svn.perl
+10
-4
@@ -232,7 +232,7 @@ sub rebuild {
232
my @commit = grep(/^git-svn-id: /,`git-cat-file commit $c`);
233
next if (!@commit); # skip merges
234
my ($url, $rev, $uuid) = extract_metadata($commit[$#commit]);
235
- if (!$rev || !$uuid) {
235
+ if (!defined $rev || !$uuid) {
236
croak "Unable to extract revision or UUID from ",
237
"$c, $commit[$#commit]\n";
238
}
@@ -832,8 +832,14 @@ sub commit_diff {
832
print STDERR "Needed URL or usable git-svn id command-line\n";
833
commit_diff_usage();
834
}
835
- my $r = shift || $_revision;
836
- die "-r|--revision is a required argument\n" unless (defined $r);
835
+ my $r = shift;
836
+ unless (defined $r) {
837
+ if (defined $_revision) {
838
+ $r = $_revision
839
+ } else {
840
+ die "-r|--revision is a required argument\n";
841
+ }
842
+ }
843
if (defined $_message && defined $_file) {
844
print STDERR "Both --message/-m and --file/-F specified ",
845
"for the commit message.\n",
@@ -2493,7 +2499,7 @@ sub extract_metadata {
2499
my $id = shift or return (undef, undef, undef);
2500
my ($url, $rev, $uuid) = ($id =~ /^git-svn-id:\s(\S+?)\@(\d+)
2501
\s([a-f\d\-]+)$/x);
2496
- if (!$rev || !$uuid || !$url) {
2502
+ if (!defined $rev || !$uuid || !$url) {
2503
# some of the original repositories I made had
2504
# identifiers like this:
2505
($rev, $uuid) = ($id =~/^git-svn-id:\s(\d+)\@([a-f\d\-]+)/);