Merge branch 'maint'
authorShawn O. Pearce <spearce@spearce.org>
Tue, 30 Sep 2008 21:14:09 +0000 (14:14 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Tue, 30 Sep 2008 21:14:09 +0000 (14:14 -0700)
* maint:
git-svn: call 'fatal' correctly in set-tree
Replace svn.foo.org with svn.example.com in git-svn docs (RFC 2606)
t0024: add executable permission

1  2 
git-svn.perl
diff --combined git-svn.perl
index 80a5728371bdcf3ac90716df5705c9bec3edcf29,33e1b503c4d58f5f0a0c109a37968419710fbd11..7609a837419012d94109cf8b4de1b9bbdb969c83
@@@ -421,15 -421,15 +421,15 @@@ sub cmd_dcommit 
        $head ||= 'HEAD';
        my @refs;
        my ($url, $rev, $uuid, $gs) = working_head_info($head, \@refs);
 +      unless ($gs) {
 +              die "Unable to determine upstream SVN information from ",
 +                  "$head history.\nPerhaps the repository is empty.";
 +      }
        $url = defined $_commit_url ? $_commit_url : $gs->full_url;
        my $last_rev = $_revision if defined $_revision;
        if ($url) {
                print "Committing to $url ...\n";
        }
 -      unless ($gs) {
 -              die "Unable to determine upstream SVN information from ",
 -                  "$head history.\nPerhaps the repository is empty.";
 -      }
        my ($linear_refs, $parents) = linearize_history($gs, \@refs);
        if ($_no_rebase && scalar(@$linear_refs) > 1) {
                warn "Attempting to commit more than one change while ",
@@@ -803,28 -803,8 +803,28 @@@ sub cmd_commit_diff 
        }
  }
  
 +sub escape_uri_only {
 +      my ($uri) = @_;
 +      my @tmp;
 +      foreach (split m{/}, $uri) {
 +              s/([^\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg;
 +              push @tmp, $_;
 +      }
 +      join('/', @tmp);
 +}
 +
 +sub escape_url {
 +      my ($url) = @_;
 +      if ($url =~ m#^([^:]+)://([^/]*)(.*)$#) {
 +              my ($scheme, $domain, $uri) = ($1, $2, escape_uri_only($3));
 +              $url = "$scheme://$domain$uri";
 +      }
 +      $url;
 +}
 +
  sub cmd_info {
        my $path = canonicalize_path(defined($_[0]) ? $_[0] : ".");
 +      my $fullpath = canonicalize_path($cmd_dir_prefix . $path);
        if (exists $_[1]) {
                die "Too many arguments specified\n";
        }
        my ($file_type, $diff_status) = find_file_type_and_diff_status($path);
  
        if (!$file_type && !$diff_status) {
 -              print STDERR "$path:  (Not a versioned resource)\n\n";
 -              return;
 +              print STDERR "svn: '$path' is not under version control\n";
 +              exit 1;
        }
  
        my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
        # canonicalize_path() will return "" to make libsvn 1.5.x happy,
        $path = "." if $path eq "";
  
 -      my $full_url = $url . ($path eq "." ? "" : "/$path");
 +      my $full_url = $url . ($fullpath eq "" ? "" : "/$fullpath");
  
        if ($_url) {
 -              print $full_url, "\n";
 +              print escape_url($full_url), "\n";
                return;
        }
  
        my $result = "Path: $path\n";
        $result .= "Name: " . basename($path) . "\n" if $file_type ne "dir";
 -      $result .= "URL: " . $full_url . "\n";
 +      $result .= "URL: " . escape_url($full_url) . "\n";
  
        eval {
                my $repos_root = $gs->repos_root;
                Git::SVN::remove_username($repos_root);
 -              $result .= "Repository Root: $repos_root\n";
 +              $result .= "Repository Root: " . escape_url($repos_root) . "\n";
        };
        if ($@) {
                $result .= "Repository Root: (offline)\n";
        }
  
        my ($lc_author, $lc_rev, $lc_date_utc);
 -      my @args = Git::SVN::Log::git_svn_log_cmd($rev, $rev, "--", $path);
 +      my @args = Git::SVN::Log::git_svn_log_cmd($rev, $rev, "--", $fullpath);
        my $log = command_output_pipe(@args);
        my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
        while (<$log>) {
@@@ -2591,7 -2571,7 +2591,7 @@@ sub set_tree 
        my ($self, $tree) = (shift, shift);
        my $log_entry = ::get_commit_entry($tree);
        unless ($self->{last_rev}) {
-               fatal("Must have an existing revision to commit");
+               ::fatal("Must have an existing revision to commit");
        }
        my %ed_opts = ( r => $self->{last_rev},
                        log => $log_entry->{log},
@@@ -2626,9 -2606,9 +2626,9 @@@ sub rebuild_from_rev_db 
  sub rebuild {
        my ($self) = @_;
        my $map_path = $self->map_path;
 -      return if (-e $map_path && ! -z $map_path);
 +      my $partial = (-e $map_path && ! -z $map_path);
        return unless ::verify_ref($self->refname.'^0');
 -      if ($self->use_svm_props || $self->no_metadata) {
 +      if (!$partial && ($self->use_svm_props || $self->no_metadata)) {
                my $rev_db = $self->rev_db_path;
                $self->rebuild_from_rev_db($rev_db);
                if ($self->use_svm_props) {
                $self->unlink_rev_db_symlink;
                return;
        }
 -      print "Rebuilding $map_path ...\n";
 +      print "Rebuilding $map_path ...\n" if (!$partial);
 +      my ($base_rev, $head) = ($partial ? $self->rev_map_max_norebuild(1) :
 +              (undef, undef));
        my ($log, $ctx) =
            command_output_pipe(qw/rev-list --pretty=raw --no-color --reverse/,
 -                              $self->refname, '--');
 +                              ($head ? "$head.." : "") . $self->refname,
 +                              '--');
        my $metadata_url = $self->metadata_url;
        remove_username($metadata_url);
        my $svn_uuid = $self->ra_uuid;
                    ($metadata_url && $url && ($url ne $metadata_url))) {
                        next;
                }
 +              if ($partial && $head) {
 +                      print "Partial-rebuilding $map_path ...\n";
 +                      print "Currently at $base_rev = $head\n";
 +                      $head = undef;
 +              }
  
                $self->rev_map_set($rev, $c);
                print "r$rev = $c\n";
        }
        command_close_pipe($log, $ctx);
 -      print "Done rebuilding $map_path\n";
 +      print "Done rebuilding $map_path\n" if (!$partial || !$head);
        my $rev_db_path = $self->rev_db_path;
        if (-f $self->rev_db_path) {
                unlink $self->rev_db_path or croak "unlink: $!";
@@@ -2817,12 -2789,6 +2817,12 @@@ sub rev_map_set 
  sub rev_map_max {
        my ($self, $want_commit) = @_;
        $self->rebuild;
 +      my ($r, $c) = $self->rev_map_max_norebuild($want_commit);
 +      $want_commit ? ($r, $c) : $r;
 +}
 +
 +sub rev_map_max_norebuild {
 +      my ($self, $want_commit) = @_;
        my $map_path = $self->map_path;
        stat $map_path or return $want_commit ? (0, undef) : 0;
        sysopen(my $fh, $map_path, O_RDONLY) or croak "open: $!";
@@@ -3414,12 -3380,11 +3414,12 @@@ sub generate_diff 
        while (<$diff_fh>) {
                chomp $_; # this gets rid of the trailing "\0"
                if ($state eq 'meta' && /^:(\d{6})\s(\d{6})\s
 -                                      $::sha1\s($::sha1)\s
 +                                      ($::sha1)\s($::sha1)\s
                                        ([MTCRAD])\d*$/xo) {
                        push @mods, {   mode_a => $1, mode_b => $2,
 -                                      sha1_b => $3, chg => $4 };
 -                      if ($4 =~ /^(?:C|R)$/) {
 +                                      sha1_a => $3, sha1_b => $4,
 +                                      chg => $5 };
 +                      if ($5 =~ /^(?:C|R)$/) {
                                $state = 'file_a';
                        } else {
                                $state = 'file_b';
@@@ -3671,7 -3636,6 +3671,7 @@@ sub R 
        my $fbat = $self->add_file($self->repo_path($m->{file_b}), $pbat,
                                $self->url_path($m->{file_a}), $self->{r});
        print "\tR\t$m->{file_a} => $m->{file_b}\n" unless $::_q;
 +      $self->apply_autoprops($file, $fbat);
        $self->chg_file($fbat, $m);
        $self->close_file($fbat,undef,$self->{pool});
  
@@@ -3698,52 -3662,33 +3698,52 @@@ sub change_file_prop 
        $self->SUPER::change_file_prop($fbat, $pname, $pval, $self->{pool});
  }
  
 -sub chg_file {
 -      my ($self, $fbat, $m) = @_;
 -      if ($m->{mode_b} =~ /755$/ && $m->{mode_a} !~ /755$/) {
 -              $self->change_file_prop($fbat,'svn:executable','*');
 -      } elsif ($m->{mode_b} !~ /755$/ && $m->{mode_a} =~ /755$/) {
 -              $self->change_file_prop($fbat,'svn:executable',undef);
 -      }
 -      my $fh = Git::temp_acquire('git_blob');
 -      if ($m->{mode_b} =~ /^120/) {
 +sub _chg_file_get_blob ($$$$) {
 +      my ($self, $fbat, $m, $which) = @_;
 +      my $fh = Git::temp_acquire("git_blob_$which");
 +      if ($m->{"mode_$which"} =~ /^120/) {
                print $fh 'link ' or croak $!;
                $self->change_file_prop($fbat,'svn:special','*');
 -      } elsif ($m->{mode_a} =~ /^120/ && $m->{mode_b} !~ /^120/) {
 +      } elsif ($m->{mode_a} =~ /^120/ && $m->{"mode_$which"} !~ /^120/) {
                $self->change_file_prop($fbat,'svn:special',undef);
        }
 -      my $size = $::_repository->cat_blob($m->{sha1_b}, $fh);
 -      croak "Failed to read object $m->{sha1_b}" if ($size < 0);
 +      my $blob = $m->{"sha1_$which"};
 +      return ($fh,) if ($blob =~ /^0{40}$/);
 +      my $size = $::_repository->cat_blob($blob, $fh);
 +      croak "Failed to read object $blob" if ($size < 0);
        $fh->flush == 0 or croak $!;
        seek $fh, 0, 0 or croak $!;
  
        my $exp = ::md5sum($fh);
        seek $fh, 0, 0 or croak $!;
 +      return ($fh, $exp);
 +}
  
 +sub chg_file {
 +      my ($self, $fbat, $m) = @_;
 +      if ($m->{mode_b} =~ /755$/ && $m->{mode_a} !~ /755$/) {
 +              $self->change_file_prop($fbat,'svn:executable','*');
 +      } elsif ($m->{mode_b} !~ /755$/ && $m->{mode_a} =~ /755$/) {
 +              $self->change_file_prop($fbat,'svn:executable',undef);
 +      }
 +      my ($fh_a, $exp_a) = _chg_file_get_blob $self, $fbat, $m, 'a';
 +      my ($fh_b, $exp_b) = _chg_file_get_blob $self, $fbat, $m, 'b';
        my $pool = SVN::Pool->new;
 -      my $atd = $self->apply_textdelta($fbat, undef, $pool);
 -      my $got = SVN::TxDelta::send_stream($fh, @$atd, $pool);
 -      die "Checksum mismatch\nexpected: $exp\ngot: $got\n" if ($got ne $exp);
 -      Git::temp_release($fh, 1);
 +      my $atd = $self->apply_textdelta($fbat, $exp_a, $pool);
 +      if (-s $fh_a) {
 +              my $txstream = SVN::TxDelta::new ($fh_a, $fh_b, $pool);
 +              my $res = SVN::TxDelta::send_txstream($txstream, @$atd, $pool);
 +              if (defined $res) {
 +                      die "Unexpected result from send_txstream: $res\n",
 +                          "(SVN::Core::VERSION: $SVN::Core::VERSION)\n";
 +              }
 +      } else {
 +              my $got = SVN::TxDelta::send_stream($fh_b, @$atd, $pool);
 +              die "Checksum mismatch\nexpected: $exp_b\ngot: $got\n"
 +                  if ($got ne $exp_b);
 +      }
 +      Git::temp_release($fh_b, 1);
 +      Git::temp_release($fh_a, 1);
        $pool->clear;
  }