@matheusbsbs / matheus-bagliano / commits / a8ae26235c
Fork 0

git-svn: make dcommit usable for glob users

* dcommit no longer requires the correct -i/GIT_SVN_ID option passed to it. Since you're committing from HEAD (or another commit that is a parent of HEAD), you'll be able to find a commit with metadata information containing the SVN URL that your HEAD was descended from anyways. * I don't think dcommit ever worked for people using the noMetadata option; so I don't think relying on metadata is an issue. * useSvmProps users shouldn't commit to SVN::Mirror created repositories anyways, right? * Users of globbing should automatically be able to commit to paths that are not explicitly set in .git/config Signed-off-by: Eric Wong <normalperson@yhbt.net>

Eric Wong committed Feb 13, 2007 at 14:22 UTC a8ae26235ced15d8ce129a8ff72c558b8a567813
1 file changed +51 -22
git-svn.perl
+51 -22
@@ -276,11 +276,27 @@ sub cmd_set_tree {
276
277 sub cmd_dcommit {
278 my $head = shift;
279 - my $gs = Git::SVN->new;
279 $head ||= 'HEAD';
281 - my @refs = command(qw/rev-list --no-merges/, $gs->refname."..$head");
280 + my ($url, $rev, $uuid);
281 + my ($fh, $ctx) = command_output_pipe(qw/rev-list --no-merges/, $head);
282 + my @refs;
283 + my $c;
284 + while (<$fh>) {
285 + $c = $_;
286 + chomp $c;
287 + ($url, $rev, $uuid) = cmt_metadata($c);
288 + last if (defined $url && defined $rev && defined $uuid);
289 + unshift @refs, $c;
290 + }
291 + close $fh; # most likely breaking the pipe
292 + unless (defined $url && defined $rev && defined $uuid) {
293 + die "Unable to determine upstream SVN information from ",
294 + "$head history:\n $ctx\n";
295 + }
296 + my $gs = Git::SVN->find_by_url($url) or
297 + die "Can't determine fetch information for $url\n";
298 my $last_rev;
283 - foreach my $d (reverse @refs) {
299 + foreach my $d (@refs) {
300 if (!verify_ref("$d~1")) {
301 fatal "Commit $d\n",
302 "has no parent commit, and therefore ",
@@ -300,13 +316,13 @@ sub cmd_dcommit {
316 } else {
317 my %ed_opts = ( r => $last_rev,
318 log => get_commit_entry($d)->{log},
303 - ra => $gs->ra,
319 + ra => Git::SVN::Ra->new($url),
320 tree_a => "$d~1",
321 tree_b => $d,
322 editor_cb => sub {
323 print "Committed r$_[0]\n";
324 $last_rev = $_[0]; },
309 - svn_path => $gs->{path} );
325 + svn_path => '');
326 if (!SVN::Git::Editor->new(\%ed_opts)->apply_diff) {
327 print "No changes\n$d~1 == $d\n";
328 }
@@ -904,6 +920,35 @@ sub init_remote_config {
920 $self->{url} = $url;
921 }
922
923 +sub find_by_url { # repos_root and, path are optional
924 + my ($class, $full_url, $repos_root, $path) = @_;
925 + my $remotes = read_all_remotes();
926 + if (defined $full_url && defined $repos_root && !defined $path) {
927 + $path = $full_url;
928 + $path =~ s#^\Q$repos_root\E(?:/|$)##;
929 + }
930 + foreach my $repo_id (keys %$remotes) {
931 + my $u = $remotes->{$repo_id}->{url} or next;
932 + next if defined $repos_root && $repos_root ne $u;
933 +
934 + my $fetch = $remotes->{$repo_id}->{fetch} || {};
935 + foreach (qw/branches tags/) {
936 + resolve_local_globs($u, $fetch,
937 + $remotes->{$repo_id}->{$_});
938 + }
939 + my $p = $path;
940 + unless (defined $p) {
941 + $p = $full_url;
942 + $p =~ s#^\Q$u\E(?:/|$)## or next;
943 + }
944 + foreach my $f (keys %$fetch) {
945 + next if $f ne $p;
946 + return Git::SVN->new($fetch->{$f}, $repo_id, $f);
947 + }
948 + }
949 + undef;
950 +}
951 +
952 sub init {
953 my ($class, $url, $path, $repo_id, $ref_id, $no_write) = @_;
954 my $self = _new($class, $repo_id, $ref_id, $path);
@@ -1387,23 +1432,7 @@ sub find_parent_branch {
1432 print STDERR "Found possible branch point: ",
1433 "$new_url => ", $self->full_url, ", $r\n";
1434 $branch_from =~ s#^/##;
1390 - my $remotes = read_all_remotes();
1391 - my $gs;
1392 - foreach my $repo_id (keys %$remotes) {
1393 - my $u = $remotes->{$repo_id}->{url} or next;
1394 - next if $url ne $u;
1395 - my $fetch = $remotes->{$repo_id}->{fetch};
1396 - foreach (qw/branches tags/) {
1397 - resolve_local_globs($url, $fetch,
1398 - $remotes->{$repo_id}->{$_});
1399 - }
1400 - foreach my $f (keys %$fetch) {
1401 - next if $f ne $branch_from;
1402 - $gs = Git::SVN->new($fetch->{$f}, $repo_id, $f);
1403 - last;
1404 - }
1405 - last if $gs;
1406 - }
1435 + my $gs = Git::SVN->find_by_url($new_url, $repos_root, $branch_from);
1436 unless ($gs) {
1437 my $ref_id = $self->{ref_id};
1438 $ref_id =~ s/\@\d+$//;