2 # Copyright (C) 2006, Eric Wong <normalperson@yhbt.net>
3 # License: GPL v2 or later
6 use vars qw
/ $AUTHOR $VERSION
7 $SVN_URL $SVN_INFO $SVN_WC $SVN_UUID
8 $GIT_SVN_INDEX $GIT_SVN
9 $GIT_DIR $GIT_SVN_DIR $REVDB/;
10 $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
11 $VERSION = '1.1.1-broken';
14 $GIT_DIR = abs_path
($ENV{GIT_DIR
} || '.git');
15 $ENV{GIT_DIR
} = $GIT_DIR;
17 my $LC_ALL = $ENV{LC_ALL
};
19 # make sure the svn binary gives consistent output between locales and TZs:
23 # If SVN:: library support is added, please make the dependencies
24 # optional and preserve the capability to use the command-line client.
25 # use eval { require SVN::... } to make it lazy load
26 # We don't use any modules not in the standard Perl distribution:
29 use File
::Basename qw
/dirname basename/;
30 use File
::Path qw
/mkpath/;
31 use Getopt
::Long qw
/:config gnu_getopt no_ignore_case auto_abbrev pass_through/;
33 use POSIX qw
/strftime/;
36 memoize
('revisions_eq');
37 memoize
('cmt_metadata');
38 memoize
('get_commit_time');
40 my ($SVN_PATH, $SVN, $SVN_LOG, $_use_lib);
41 $_use_lib = 1 unless $ENV{GIT_SVN_NO_LIB
};
43 my $_optimize_commits = 1 unless $ENV{GIT_SVN_NO_OPTIMIZE_COMMITS
};
44 my $sha1 = qr/[a-f\d]{40}/;
45 my $sha1_short = qr/[a-f\d]{4,40}/;
46 my ($_revision,$_stdin,$_no_ignore_ext,$_no_stop_copy,$_help,$_rmdir,$_edit,
47 $_find_copies_harder, $_l, $_cp_similarity, $_cp_remote,
48 $_repack, $_repack_nr, $_repack_flags,
49 $_template, $_shared, $_no_default_regex, $_no_graft_copy,
50 $_limit, $_verbose, $_incremental, $_oneline, $_l_fmt, $_show_commit,
51 $_version, $_upgrade, $_authors, $_branch_all_refs, @_opt_m);
52 my (@_branch_from, %tree_map, %users, %rusers, %equiv);
53 my ($_svn_co_url_revs, $_svn_pg_peg_revs);
54 my @repo_path_split_cache;
56 my %fc_opts = ( 'no-ignore-externals' => \
$_no_ignore_ext,
57 'branch|b=s' => \
@_branch_from,
58 'branch-all-refs|B' => \
$_branch_all_refs,
59 'authors-file|A=s' => \
$_authors,
60 'repack:i' => \
$_repack,
61 'repack-flags|repack-args|repack-opts=s' => \
$_repack_flags);
63 my ($_trunk, $_tags, $_branches);
64 my %multi_opts = ( 'trunk|T=s' => \
$_trunk,
65 'tags|t=s' => \
$_tags,
66 'branches|b=s' => \
$_branches );
67 my %init_opts = ( 'template=s' => \
$_template, 'shared' => \
$_shared );
69 # yes, 'native' sets "\n". Patches to fix this for non-*nix systems welcome:
70 my %EOL = ( CR
=> "\015", LF
=> "\012", CRLF
=> "\015\012", native
=> "\012" );
73 fetch
=> [ \
&fetch
, "Download new revisions from SVN",
74 { 'revision|r=s' => \
$_revision, %fc_opts } ],
75 init
=> [ \
&init
, "Initialize a repo for tracking" .
76 " (requires URL argument)",
78 commit
=> [ \
&commit
, "Commit git revisions to SVN",
79 { 'stdin|' => \
$_stdin,
82 'find-copies-harder' => \
$_find_copies_harder,
84 'copy-similarity|C=i'=> \
$_cp_similarity,
87 'show-ignore' => [ \
&show_ignore
, "Show svn:ignore listings",
88 { 'revision|r=i' => \
$_revision } ],
89 rebuild
=> [ \
&rebuild
, "Rebuild git-svn metadata (after git clone)",
90 { 'no-ignore-externals' => \
$_no_ignore_ext,
91 'copy-remote|remote=s' => \
$_cp_remote,
92 'upgrade' => \
$_upgrade } ],
93 'graft-branches' => [ \
&graft_branches
,
94 'Detect merges/branches from already imported history',
95 { 'merge-rx|m' => \
@_opt_m,
96 'branch|b=s' => \
@_branch_from,
97 'branch-all-refs|B' => \
$_branch_all_refs,
98 'no-default-regex' => \
$_no_default_regex,
99 'no-graft-copy' => \
$_no_graft_copy } ],
100 'multi-init' => [ \
&multi_init
,
101 'Initialize multiple trees (like git-svnimport)',
102 { %multi_opts, %fc_opts } ],
103 'multi-fetch' => [ \
&multi_fetch
,
104 'Fetch multiple trees (like git-svnimport)',
106 'log' => [ \
&show_log
, 'Show commit logs',
107 { 'limit=i' => \
$_limit,
108 'revision|r=s' => \
$_revision,
109 'verbose|v' => \
$_verbose,
110 'incremental' => \
$_incremental,
111 'oneline' => \
$_oneline,
112 'show-commit' => \
$_show_commit,
113 'authors-file|A=s' => \
$_authors,
118 for (my $i = 0; $i < @ARGV; $i++) {
119 if (defined $cmd{$ARGV[$i]}) {
126 my %opts = %{$cmd{$cmd}->[2]} if (defined $cmd);
128 read_repo_config
(\
%opts);
129 my $rv = GetOptions
(%opts, 'help|H|h' => \
$_help,
130 'version|V' => \
$_version,
131 'id|i=s' => \
$GIT_SVN);
132 exit 1 if (!$rv && $cmd ne 'log');
136 version
() if $_version;
137 usage
(1) unless defined $cmd;
139 load_authors
() if $_authors;
140 load_all_refs
() if $_branch_all_refs;
141 svn_compat_check
() unless $_use_lib;
142 migration_check
() unless $cmd =~ /^(?:init|rebuild|multi-init)$/;
143 $cmd{$cmd}->[0]->(@ARGV);
146 ####################### primary functions ######################
148 my $exit = shift || 0;
149 my $fd = $exit ? \
*STDERR
: \
*STDOUT
;
151 git
-svn
- bidirectional operations between a single Subversion tree
and git
152 Usage
: $0 <command
> [options
] [arguments
]\n
154 print $fd "Available commands:\n" unless $cmd;
156 foreach (sort keys %cmd) {
157 next if $cmd && $cmd ne $_;
158 print $fd ' ',pack('A13',$_),$cmd{$_}->[1],"\n";
159 foreach (keys %{$cmd{$_}->[2]}) {
160 # prints out arguments as they should be passed:
161 my $x = s
#[:=]s$## ? '<arg>' : s#[:=]i$## ? '<num>' : '';
162 print $fd ' ' x
17, join(', ', map { length $_ > 1 ?
164 split /\|/,$_)," $x\n";
168 \nGIT_SVN_ID may be set
in the environment
or via the
--id
/-i switch to an
169 arbitrary identifier
if you
're tracking multiple SVN branches/repositories in
170 one git repository and want to keep them separate. See git-svn(1) for more
177 print "git-svn version $VERSION\n";
182 if (quiet_run(qw/git-rev-parse --verify/,"refs/remotes/$GIT_SVN^0")) {
185 $SVN_URL = shift or undef;
188 sys('git
-update
-ref',"refs/remotes/$GIT_SVN","$GIT_SVN-HEAD");
190 check_upgrade_needed();
193 my $pid = open(my $rev_list,'-|');
194 defined $pid or croak $!;
196 exec("git-rev-list","refs/remotes/$GIT_SVN") or croak $!;
199 while (<$rev_list>) {
202 croak "Non-SHA1: $c\n" unless $c =~ /^$sha1$/o;
203 my @commit = grep(/^git-svn-id: /,`git-cat-file commit $c`);
204 next if (!@commit); # skip merges
205 my ($url, $rev, $uuid) = extract_metadata($commit[$#commit]);
206 if (!$rev || !$uuid) {
207 croak "Unable to extract revision or UUID from ",
208 "$c, $commit[$#commit]\n";
211 # if we merged or otherwise started elsewhere, this is
212 # how we break out of it
213 next if (defined $SVN_UUID && ($uuid ne $SVN_UUID));
214 next if (defined $SVN_URL && defined $url && ($url ne $SVN_URL));
216 unless (defined $latest) {
217 if (!$SVN_URL && !$url) {
218 croak "SVN repository location required: $url\n";
225 revdb_set($REVDB, $rev, $c);
226 print "r$rev = $c\n";
227 $newest_rev = $rev if ($rev > $newest_rev);
229 close $rev_list or croak $?;
231 goto out if $_use_lib;
232 if (!chdir $SVN_WC) {
233 svn_cmd_checkout($SVN_URL, $latest, $SVN_WC);
234 chdir $SVN_WC or croak $!;
238 defined $pid or croak $!;
240 my @svn_up = qw(svn up);
241 push @svn_up, '--ignore-externals' unless $_no_ignore_ext;
242 sys
(@svn_up,"-r$newest_rev");
243 $ENV{GIT_INDEX_FILE
} = $GIT_SVN_INDEX;
245 exec('git-write-tree') or croak
$!;
252 Keeping deprecated refs
/head/$GIT_SVN-HEAD
for now
. Please remove it
253 when you have upgraded your tools
and habits to
use refs
/remotes/$GIT_SVN
259 $SVN_URL = shift or die "SVN repository location required " .
260 "as a command-line argument\n";
261 $SVN_URL =~ s!/+$!!; # strip trailing slash
262 unless (-d
$GIT_DIR) {
263 my @init_db = ('git-init-db');
264 push @init_db, "--template=$_template" if defined $_template;
265 push @init_db, "--shared" if defined $_shared;
272 check_upgrade_needed
();
273 $SVN_URL ||= file_to_s
("$GIT_SVN_DIR/info/url");
274 my $ret = $_use_lib ? fetch_lib
(@_) : fetch_cmd
(@_);
275 if ($ret->{commit
} && quiet_run
(qw(git-rev-parse --verify
276 refs/heads/master^0))) {
277 sys
(qw(git-update-ref refs/heads/master),$ret->{commit
});
284 my @log_args = -d
$SVN_WC ?
($SVN_WC) : ($SVN_URL);
285 unless ($_revision) {
286 $_revision = -d
$SVN_WC ?
'BASE:HEAD' : '0:HEAD';
288 push @log_args, "-r$_revision";
289 push @log_args, '--stop-on-copy' unless $_no_stop_copy;
291 my $svn_log = svn_log_raw
(@log_args);
293 my $base = next_log_entry
($svn_log) or croak
"No base revision!\n";
294 # don't need last_revision from grab_base_rev() because
295 # user could've specified a different revision to skip (they
296 # didn't want to import certain revisions into git for whatever
297 # reason, so trust $base->{revision} instead.
298 my (undef, $last_commit) = svn_grab_base_rev
();
299 unless (-d
$SVN_WC) {
300 svn_cmd_checkout
($SVN_URL,$base->{revision
},$SVN_WC);
301 chdir $SVN_WC or croak
$!;
303 $last_commit = git_commit
($base, @parents);
304 assert_tree
($last_commit);
306 chdir $SVN_WC or croak
$!;
308 # looks like a user manually cp'd and svn switch'ed
309 unless ($last_commit) {
310 sys
(qw
/svn revert -R ./);
311 assert_svn_wc_clean
($base->{revision
});
312 $last_commit = git_commit
($base, @parents);
313 assert_tree
($last_commit);
316 my @svn_up = qw(svn up);
317 push @svn_up, '--ignore-externals' unless $_no_ignore_ext;
319 while (my $log_msg = next_log_entry
($svn_log)) {
320 if ($last->{revision
} >= $log_msg->{revision
}) {
321 croak
"Out of order: last >= current: ",
322 "$last->{revision} >= $log_msg->{revision}\n";
324 # Revert is needed for cases like:
325 # https://svn.musicpd.org/Jamming/trunk (r166:167), but
326 # I can't seem to reproduce something like that on a test...
327 sys
(qw
/svn revert -R ./);
328 assert_svn_wc_clean
($last->{revision
});
329 sys
(@svn_up,"-r$log_msg->{revision}");
330 $last_commit = git_commit
($log_msg, $last_commit, @parents);
333 close $svn_log->{fh
};
334 $last->{commit
} = $last_commit;
340 $SVN_URL ||= file_to_s
("$GIT_SVN_DIR/info/url");
342 ($repo, $SVN_PATH) = repo_path_split
($SVN_URL);
343 $SVN_LOG ||= libsvn_connect
($repo);
344 $SVN ||= libsvn_connect
($repo);
345 my ($last_rev, $last_commit) = svn_grab_base_rev
();
346 my ($base, $head) = libsvn_parse_revision
($last_rev);
348 return { revision
=> $last_rev, commit
=> $last_commit }
350 my $index = set_index
($GIT_SVN_INDEX);
352 # limit ourselves and also fork() since get_log won't release memory
353 # after processing a revision and SVN stuff seems to leak
355 my ($min, $max) = ($base, $head < $base+$inc ?
$head : $base+$inc);
357 if (defined $last_commit) {
358 unless (-e
$GIT_SVN_INDEX) {
359 sys
(qw
/git-read-tree/, $last_commit);
361 chomp (my $x = `git-write-tree`);
362 my ($y) = (`git-cat-file commit $last_commit`
363 =~ /^tree ($sha1)/m);
365 unlink $GIT_SVN_INDEX or croak
$!;
366 sys
(qw
/git-read-tree/, $last_commit);
368 chomp ($x = `git-write-tree`);
370 print STDERR
"trees ($last_commit) $y != $x\n",
371 "Something is seriously wrong...\n";
375 # fork, because using SVN::Pool with get_log() still doesn't
376 # seem to help enough to keep memory usage down.
377 defined(my $pid = fork) or croak
$!;
379 $SVN::Error
::handler
= \
&libsvn_skip_unknown_revs
;
381 # Yes I'm perfectly aware that the fourth argument
382 # below is the limit revisions number. Unfortunately
383 # performance sucks with it enabled, so it's much
384 # faster to fetch revision ranges instead of relying
386 libsvn_get_log
($SVN_LOG, '/'.$SVN_PATH,
391 $log_msg = libsvn_fetch
(
393 $last_commit = git_commit
(
398 $log_msg = libsvn_new_tree
(@_);
399 $last_commit = git_commit
(
407 ($last_rev, $last_commit) = svn_grab_base_rev
();
408 last if ($max >= $head);
411 $max = $head if ($max > $head);
413 restore_index
($index);
414 return { revision
=> $last_rev, commit
=> $last_commit };
419 check_upgrade_needed
();
420 if ($_stdin || !@commits) {
421 print "Reading from stdin...\n";
424 if (/\b($sha1_short)\b/o) {
425 unshift @commits, $1;
430 foreach my $c (@commits) {
431 chomp(my @tmp = safe_qx
('git-rev-parse',$c));
432 if (scalar @tmp == 1) {
434 } elsif (scalar @tmp > 1) {
435 push @revs, reverse (safe_qx
('git-rev-list',@tmp));
437 die "Failed to rev-parse $c\n";
441 $_use_lib ? commit_lib
(@revs) : commit_cmd
(@revs);
442 print "Done committing ",scalar @revs," revisions to SVN\n";
448 chdir $SVN_WC or croak
"Unable to chdir $SVN_WC: $!\n";
449 my $info = svn_info
('.');
450 my $fetched = fetch
();
451 if ($info->{Revision
} != $fetched->{revision
}) {
452 print STDERR
"There are new revisions that were fetched ",
453 "and need to be merged (or acknowledged) ",
454 "before committing.\n";
457 $info = svn_info
('.');
460 foreach my $c (@revs) {
461 my $mods = svn_checkout_tree
($last, $c);
462 if (scalar @
$mods == 0) {
463 print "Skipping, no changes detected\n";
466 $last = svn_commit_tree
($last, $c);
472 my ($r_last, $cmt_last) = svn_grab_base_rev
();
473 defined $r_last or die "Must have an existing revision to commit\n";
474 my $fetched = fetch
();
475 if ($r_last != $fetched->{revision
}) {
476 print STDERR
"There are new revisions that were fetched ",
477 "and need to be merged (or acknowledged) ",
478 "before committing.\n",
479 "last rev: $r_last\n",
480 " current: $fetched->{revision}\n";
484 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef, 0) : ();
485 my $commit_msg = "$GIT_SVN_DIR/.svn-commit.tmp.$$";
487 if (defined $LC_ALL) {
488 $ENV{LC_ALL
} = $LC_ALL;
492 foreach my $c (@revs) {
493 my $log_msg = get_commit_message
($c, $commit_msg);
495 # fork for each commit because there's a memory leak I
496 # can't track down... (it's probably in the SVN code)
497 defined(my $pid = open my $fh, '-|') or croak
$!;
499 my $ed = SVN
::Git
::Editor
->new(
503 svn_path
=> $SVN_PATH
505 $SVN->get_commit_editor(
516 my $mods = libsvn_checkout_tree
($cmt_last, $c, $ed);
518 print "No changes\nr$r_last = $cmt_last\n";
525 my ($r_new, $cmt_new, $no);
529 if (/^r(\d+) = ($sha1)$/o) {
530 ($r_new, $cmt_new) = ($1, $2);
531 } elsif ($_ eq 'No changes') {
535 close $fh or croak
$?
;
536 if (! defined $r_new && ! defined $cmt_new) {
538 die "Failed to parse revision information\n";
541 ($r_last, $cmt_last) = ($r_new, $cmt_new);
549 $SVN_URL ||= file_to_s
("$GIT_SVN_DIR/info/url");
550 $_use_lib ? show_ignore_lib
() : show_ignore_cmd
();
553 sub show_ignore_cmd
{
554 require File
::Find
or die $!;
555 if (defined $_revision) {
556 die "-r/--revision option doesn't work unless the Perl SVN ",
557 "libraries are used\n";
559 chdir $SVN_WC or croak
$!;
561 File
::Find
::find
({wanted
=>sub{if(lstat $_ && -d _
&& -d
"$_/.svn"){
563 @
{$ign{$_}} = svn_propget_base
('svn:ignore', $_);
564 }}, no_chdir
=>1},'.');
567 foreach (@
{$ign{'.'}}) { print '/',$_ if /\S
/ }
569 foreach my $i (sort keys %ign) {
570 print "\n# ",$i,"\n";
571 foreach (@
{$ign{$i}}) { print '/',$i,'/',$_ if /\S/ }
575 sub show_ignore_lib
{
577 ($repo, $SVN_PATH) = repo_path_split
($SVN_URL);
578 $SVN ||= libsvn_connect
($repo);
579 my $r = defined $_revision ?
$_revision : $SVN->get_latest_revnum;
580 libsvn_traverse_ignore
(\
*STDOUT
, $SVN_PATH, $r);
584 my $gr_file = "$GIT_DIR/info/grafts";
585 my ($grafts, $comments) = read_grafts
($gr_file);
589 # temporarily disable our grafts file to make this idempotent
590 chomp($gr_sha1 = safe_qx
(qw
/git-hash-object -w/,$gr_file));
591 rename $gr_file, "$gr_file~$gr_sha1" or croak
$!;
594 my $l_map = read_url_paths
();
595 my @re = map { qr/$_/is } @_opt_m if @_opt_m;
596 unless ($_no_default_regex) {
597 push @re, (qr/\b(?:merge|merging|merged)\s+with\s+([\w\.\-]+)/i,
598 qr/\b(?:merge|merging|merged)\s+([\w\.\-]+)/i,
599 qr/\b(?:from|of)\s+([\w\.\-]+)/i );
601 foreach my $u (keys %$l_map) {
603 foreach my $p (keys %{$l_map->{$u}}) {
604 graft_merge_msg
($grafts,$l_map,$u,$p,@re);
607 unless ($_no_graft_copy) {
609 graft_file_copy_lib
($grafts,$l_map,$u);
611 graft_file_copy_cmd
($grafts,$l_map,$u);
615 graft_tree_joins
($grafts);
617 write_grafts
($grafts, $comments, $gr_file);
618 unlink "$gr_file~$gr_sha1" if $gr_sha1;
625 $url =~ s
#/+$## if $url;
626 if ($_trunk !~ m
#^[a-z\+]+://#) {
627 $_trunk = '/' . $_trunk if ($_trunk !~ m
#^/#);
629 print STDERR
"E: '$_trunk' is not a complete URL ",
630 "and a separate URL is not specified\n";
633 $_trunk = $url . $_trunk;
635 if ($GIT_SVN eq 'git-svn') {
636 print "GIT_SVN_ID set to 'trunk' for $_trunk\n";
637 $GIT_SVN = $ENV{GIT_SVN_ID
} = 'trunk';
641 complete_url_ls_init
($url, $_branches, '--branches/-b', '');
642 complete_url_ls_init
($url, $_tags, '--tags/-t', 'tags/');
646 # try to do trunk first, since branches/tags
647 # may be descended from it.
648 if (-e
"$GIT_DIR/svn/trunk/info/url") {
649 fetch_child_id
('trunk', @_);
651 rec_fetch
('', "$GIT_DIR/svn", @_);
657 my $r_last = -1; # prevent dupes
658 rload_authors
() if $_authors;
664 if (defined $_revision) {
665 if ($_revision =~ /^(\d+):(\d+)$/) {
666 ($r_min, $r_max) = ($1, $2);
667 } elsif ($_revision =~ /^\d+$/) {
668 $r_min = $r_max = $_revision;
670 print STDERR
"-r$_revision is not supported, use ",
671 "standard \'git log\' arguments instead\n";
676 my $pid = open(my $log,'-|');
677 defined $pid or croak
$!;
679 exec(git_svn_log_cmd
($r_min,$r_max), @args) or croak
$!;
685 if (/^commit ($sha1_short)/o) {
687 if ($c && cmt_showable
($c) && $c->{r
} != $r_last) {
689 process_commit
($c, $r_min, $r_max, \
@k) or
694 } elsif (/^author (.+) (\d+) ([\-\+]?\d+)$/) {
695 get_author_info
($c, $1, $2, $3);
696 } elsif (/^(?:tree|parent|committer) /) {
698 } elsif (/^:\d{6} \d{6} $sha1_short/o) {
699 push @
{$c->{raw
}}, $_;
702 push @
{$c->{diff
}}, $_;
704 push @
{$c->{diff
}}, $_;
705 } elsif (/^ (git-svn-id:.+)$/) {
706 (undef, $c->{r
}, undef) = extract_metadata
($1);
711 if ($c && defined $c->{r
} && $c->{r
} != $r_last) {
713 process_commit
($c, $r_min, $r_max, \
@k);
719 process_commit
($_, $r_min, $r_max) foreach reverse @k;
723 print '-' x72
,"\n" unless $_incremental || $_oneline;
726 ########################### utility functions #########################
730 return 1 if defined $c->{r
};
731 if ($c->{l
} && $c->{l
}->[-1] eq "...\n" &&
732 $c->{a_raw
} =~ /\@([a-f\d\-]+)>$/) {
733 my @msg = safe_qx
(qw
/git-cat-file commit/, $c->{c
});
734 shift @msg while ($msg[0] ne "\n");
736 @
{$c->{l
}} = grep !/^git-svn-id: /, @msg;
738 (undef, $c->{r
}, undef) = extract_metadata
(
739 (grep(/^git-svn-id: /, @msg))[-1]);
741 return defined $c->{r
};
744 sub git_svn_log_cmd
{
745 my ($r_min, $r_max) = @_;
746 my @cmd = (qw
/git
-log --abbrev
-commit
--pretty
=raw
747 --default/, "refs/remotes
/$GIT_SVN");
748 push @cmd, '--summary' if $_verbose;
749 return @cmd unless defined $r_max;
750 if ($r_max == $r_min) {
751 push @cmd, '--max-count=1';
752 if (my $c = revdb_get($REVDB, $r_max)) {
757 $c_max = revdb_get($REVDB, $r_max);
758 $c_min = revdb_get($REVDB, $r_min);
759 if ($c_min && $c_max) {
760 if ($r_max > $r_max) {
761 push @cmd, "$c_min..$c_max";
763 push @cmd, "$c_max..$c_min";
765 } elsif ($r_max > $r_min) {
776 print "Fetching
$id\n";
777 my $ref = "$GIT_DIR/refs/remotes
/$id";
778 my $ca = file_to_s($ref) if (-r $ref);
779 defined(my $pid = fork) or croak $!;
781 $GIT_SVN = $ENV{GIT_SVN_ID} = $id;
788 return unless $_repack || -r $ref;
790 my $cb = file_to_s($ref);
792 defined($pid = open my $fh, '-|') or croak $!;
793 my $url = file_to_s("$GIT_DIR/svn/$id/info/url
");
796 exec qw/git-rev-list --pretty=raw/,
797 $ca ? "$ca..$cb" : $cb or croak $!;
800 if (/^ git-svn-id: $url\@\d+ [a-f0-9\-]+$/) {
802 } elsif (/^ git-svn-id: \S+\@\d+ [a-f0-9\-]+$/) {
810 my ($pfx, $p, @args) = @_;
812 foreach (sort <$p/*>) {
813 if (-r "$_/info/url
") {
814 $pfx .= '/' if $pfx && $pfx !~ m!/$!;
815 my $id = $pfx . basename $_;
816 next if $id eq 'trunk';
817 fetch_child_id($id, @args);
824 $x =~ s!^\Q$GIT_DIR\E/svn/!!;
829 sub complete_url_ls_init {
830 my ($url, $var, $switch, $pfx) = @_;
832 print STDERR "W
: $switch not specified
\n";
836 if ($var !~ m#^[a-z\+]+://#) {
837 $var = '/' . $var if ($var !~ m#^/#);
839 print STDERR "E
: '$var' is
not a complete URL
",
840 "and a separate URL is
not specified
\n";
845 chomp(my @ls = $_use_lib ? libsvn_ls_fullurl($var)
846 : safe_qx(qw/svn ls --non-interactive/, $var));
848 defined(my $pid = fork) or croak $!;
850 foreach my $u (map { "$var/$_" } (grep m!/$!, @ls)) {
852 if ($u !~ m!\Q$var\E/(.+)$!) {
853 print STDERR
"W: Unrecognized URL: $u\n";
854 die "This should never happen\n";
857 print "init $u => $id\n";
858 $GIT_SVN = $ENV{GIT_SVN_ID
} = $id;
872 my @tmp = split m
#/#, $_;
874 while (my $x = shift @tmp) {
880 foreach (sort {length $b <=> length $a} keys %common) {
881 if ($common{$_} == @
$paths) {
888 # grafts set here are 'stronger' in that they're based on actual tree
889 # matches, and won't be deleted from merge-base checking in write_grafts()
890 sub graft_tree_joins
{
892 map_tree_joins
() if (@_branch_from && !%tree_map);
893 return unless %tree_map;
897 defined(my $pid = open my $fh, '-|') or croak
$!;
899 exec qw
/git-rev-list --pretty=raw/,
900 "refs/remotes/$i" or croak
$!;
903 next unless /^commit ($sha1)$/o;
905 my ($t) = (<$fh> =~ /^tree ($sha1)$/o);
906 next unless $tree_map{$t};
911 } until ($l =~ /^committer (?:.+) (\d+) ([\-\+]?\d+)$/);
913 my ($s, $tz) = ($1, $2);
914 if ($tz =~ s/^\+//) {
915 $s += tz_to_s_offset
($tz);
916 } elsif ($tz =~ s/^\-//) {
917 $s -= tz_to_s_offset
($tz);
920 my ($url_a, $r_a, $uuid_a) = cmt_metadata
($c);
922 foreach my $p (@
{$tree_map{$t}}) {
925 safe_qx
('git-merge-base', $c, $p)
927 next unless ($@
|| $?
);
929 # see if SVN says it's a relative
930 my ($url_b, $r_b, $uuid_b) =
932 next if (defined $url_b &&
934 ($url_a eq $url_b) &&
935 ($uuid_a eq $uuid_b));
936 if ($uuid_a eq $uuid_b) {
938 $grafts->{$c}->{$p} = 2;
940 } elsif ($r_b > $r_a) {
941 $grafts->{$p}->{$c} = 2;
946 my $ct = get_commit_time
($p);
948 $grafts->{$c}->{$p} = 2;
950 $grafts->{$p}->{$c} = 2;
952 # what should we do when $ct == $s ?
955 close $fh or croak
$?
;
959 # this isn't funky-filename safe, but good enough for now...
960 sub graft_file_copy_cmd
{
961 my ($grafts, $l_map, $u) = @_;
962 my $paths = $l_map->{$u};
963 my $pfx = common_prefix
([keys %$paths]);
964 $SVN_URL ||= $u.$pfx;
965 my $pid = open my $fh, '-|';
966 defined $pid or croak
$!;
968 my @exec = qw
/svn log -v/;
969 push @exec, "-r$_revision" if defined $_revision;
970 exec @exec, $u.$pfx or croak
$!;
972 my ($r, $mp) = (undef, undef);
977 } elsif (/^r(\d+) \| /) {
978 $r = $1 unless defined $r;
979 } elsif (/^Changed paths:/) {
981 } elsif ($mp && m
#^ [AR] /(\S.*?) \(from /(\S+?):(\d+)\)$#) {
982 my ($p1, $p0, $r0) = ($1, $2, $3);
983 my $c = find_graft_path_commit
($paths, $p1, $r);
985 find_graft_path_parents
($grafts, $paths, $c, $p0, $r0);
990 sub graft_file_copy_lib
{
991 my ($grafts, $l_map, $u) = @_;
992 my $tree_paths = $l_map->{$u};
993 my $pfx = common_prefix
([keys %$tree_paths]);
994 my ($repo, $path) = repo_path_split
($u.$pfx);
995 $SVN_LOG ||= libsvn_connect
($repo);
996 $SVN ||= libsvn_connect
($repo);
998 my ($base, $head) = libsvn_parse_revision
();
1000 my ($min, $max) = ($base, $head < $base+$inc ?
$head : $base+$inc);
1001 my $eh = $SVN::Error
::handler
;
1002 $SVN::Error
::handler
= \
&libsvn_skip_unknown_revs
;
1004 my $pool = SVN
::Pool
->new;
1005 libsvn_get_log
($SVN_LOG, "/$path", $min, $max, 0, 1, 1,
1007 libsvn_graft_file_copies
($grafts, $tree_paths,
1011 last if ($max >= $head);
1014 $max = $head if ($max > $head);
1016 $SVN::Error
::handler
= $eh;
1019 sub process_merge_msg_matches
{
1020 my ($grafts, $l_map, $u, $p, $c, @matches) = @_;
1021 my (@strong, @weak);
1022 foreach (@matches) {
1023 # merging with ourselves is not interesting
1025 if ($l_map->{$u}->{$_}) {
1031 foreach my $w (@weak) {
1033 # no exact match, use branch name as regexp.
1034 my $re = qr/\Q$w\E/i;
1035 foreach (keys %{$l_map->{$u}}) {
1037 push @strong, $l_map->{$u}->{$_};
1044 foreach (keys %{$l_map->{$u}}) {
1046 push @strong, $l_map->{$u}->{$_};
1051 my ($rev) = ($c->{m
} =~ /^git
-svn
-id
:\s
(?
:\S
+?
)\@
(\d
+)
1052 \s
(?
:[a
-f\d\
-]+)$/xsm
);
1053 unless (defined $rev) {
1054 ($rev) = ($c->{m
} =~/^git
-svn
-id
:\s
(\d
+)
1055 \@
(?
:[a
-f\d\
-]+)/xsm
);
1056 return unless defined $rev;
1058 foreach my $m (@strong) {
1059 my ($r0, $s0) = find_rev_before
($rev, $m, 1);
1060 $grafts->{$c->{c
}}->{$s0} = 1 if defined $s0;
1064 sub graft_merge_msg
{
1065 my ($grafts, $l_map, $u, $p, @re) = @_;
1067 my $x = $l_map->{$u}->{$p};
1068 my $rl = rev_list_raw
($x);
1069 while (my $c = next_rev_list_entry
($rl)) {
1070 foreach my $re (@re) {
1071 my (@br) = ($c->{m
} =~ /$re/g);
1073 process_merge_msg_matches
($grafts,$l_map,$u,$p,$c,@br);
1079 return if $SVN_UUID;
1081 my $pool = SVN
::Pool
->new;
1082 $SVN_UUID = $SVN->get_uuid($pool);
1085 my $info = shift || svn_info
('.');
1086 $SVN_UUID = $info->{'Repository UUID'} or
1087 croak
"Repository UUID unreadable\n";
1093 defined $pid or croak
$!;
1095 open my $null, '>', '/dev/null' or croak
$!;
1096 open STDERR
, '>&', $null or croak
$!;
1097 open STDOUT
, '>&', $null or croak
$!;
1098 exec @_ or croak
$!;
1104 sub repo_path_split
{
1105 my $full_url = shift;
1106 $full_url =~ s
#/+$##;
1108 foreach (@repo_path_split_cache) {
1109 if ($full_url =~ s
#$_##) {
1111 $full_url =~ s
#^/+##;
1112 return ($u, $full_url);
1116 my ($url, $path) = ($full_url =~ m!^([a-z\+]+://[^/]*)(.*)$!i);
1118 my @paths = split(m
#/+#, $path);
1122 $SVN = libsvn_connect
($url);
1123 last if (defined $SVN &&
1124 defined eval { $SVN->get_latest_revnum });
1125 my $n = shift @paths || last;
1129 while (quiet_run
(qw
/svn ls --non-interactive/, $url)) {
1130 my $n = shift @paths || last;
1134 push @repo_path_split_cache, qr/^(\Q$url\E)/;
1135 $path = join('/',@paths);
1136 return ($url, $path);
1140 defined $SVN_URL or croak
"SVN repository location required\n";
1141 unless (-d
$GIT_DIR) {
1142 croak
"GIT_DIR=$GIT_DIR does not exist!\n";
1144 mkpath
([$GIT_SVN_DIR]);
1145 mkpath
(["$GIT_SVN_DIR/info"]);
1146 open my $fh, '>>',$REVDB or croak
$!;
1148 s_to_file
($SVN_URL,"$GIT_SVN_DIR/info/url");
1152 sub assert_svn_wc_clean
{
1153 return if $_use_lib;
1155 croak
"$svn_rev is not an integer!\n" unless ($svn_rev =~ /^\d+$/);
1156 my $lcr = svn_info
('.')->{'Last Changed Rev'};
1157 if ($svn_rev != $lcr) {
1158 print STDERR
"Checking for copy-tree ... ";
1159 my @diff = grep(/^Index: /,(safe_qx
(qw(svn diff),
1160 "-r$lcr:$svn_rev")));
1162 croak
"Nope! Expected r$svn_rev, got r$lcr\n";
1164 print STDERR
"OK!\n";
1167 my @status = grep(!/^Performing status on external/,(`svn status`));
1168 @status = grep(!/^\s*$/,@status);
1169 if (scalar @status) {
1170 print STDERR
"Tree ($SVN_WC) is not clean:\n";
1171 print STDERR
$_ foreach @status;
1176 sub get_tree_from_treeish
{
1178 croak
"Not a sha1: $treeish\n" unless $treeish =~ /^$sha1$/o;
1179 chomp(my $type = `git-cat-file -t $treeish`);
1181 while ($type eq 'tag') {
1182 chomp(($treeish, $type) = `git-cat-file tag $treeish`);
1184 if ($type eq 'commit') {
1185 $expected = (grep /^tree /,`git-cat-file commit $treeish`)[0];
1186 ($expected) = ($expected =~ /^tree ($sha1)$/);
1187 die "Unable to get tree from $treeish\n" unless $expected;
1188 } elsif ($type eq 'tree') {
1189 $expected = $treeish;
1191 die "$treeish is a $type, expected tree, tag or commit\n";
1197 return if $_use_lib;
1199 my $expected = get_tree_from_treeish
($treeish);
1201 my $tmpindex = $GIT_SVN_INDEX.'.assert-tmp';
1203 unlink $tmpindex or croak
$!;
1205 my $old_index = set_index
($tmpindex);
1207 chomp(my $tree = `git-write-tree`);
1208 restore_index
($old_index);
1209 if ($tree ne $expected) {
1210 croak
"Tree mismatch, Got: $tree, Expected: $expected\n";
1215 sub parse_diff_tree
{
1216 my $diff_fh = shift;
1220 while (<$diff_fh>) {
1221 chomp $_; # this gets rid of the trailing "\0"
1222 if ($state eq 'meta' && /^:(\d
{6})\s
(\d
{6})\s
1223 $sha1\s
($sha1)\s
([MTCRAD
])\d
*$/xo
) {
1224 push @mods, { mode_a
=> $1, mode_b
=> $2,
1225 sha1_b
=> $3, chg
=> $4 };
1226 if ($4 =~ /^(?:C|R)$/) {
1231 } elsif ($state eq 'file_a') {
1232 my $x = $mods[$#mods] or croak
"Empty array\n";
1233 if ($x->{chg
} !~ /^(?:C|R)$/) {
1234 croak
"Error parsing $_, $x->{chg}\n";
1238 } elsif ($state eq 'file_b') {
1239 my $x = $mods[$#mods] or croak
"Empty array\n";
1240 if (exists $x->{file_a
} && $x->{chg
} !~ /^(?:C|R)$/) {
1241 croak
"Error parsing $_, $x->{chg}\n";
1243 if (!exists $x->{file_a
} && $x->{chg
} =~ /^(?:C|R)$/) {
1244 croak
"Error parsing $_, $x->{chg}\n";
1249 croak
"Error parsing $_\n";
1252 close $diff_fh or croak
$?
;
1257 sub svn_check_prop_executable
{
1259 return if -l
$m->{file_b
};
1260 if ($m->{mode_b
} =~ /755$/) {
1261 chmod((0755 &~ umask),$m->{file_b
}) or croak
$!;
1262 if ($m->{mode_a
} !~ /755$/) {
1263 sys
(qw(svn propset svn:executable 1), $m->{file_b
});
1265 -x
$m->{file_b
} or croak
"$m->{file_b} is not executable!\n";
1266 } elsif ($m->{mode_b
} !~ /755$/ && $m->{mode_a
} =~ /755$/) {
1267 sys
(qw(svn propdel svn:executable), $m->{file_b
});
1268 chmod((0644 &~ umask),$m->{file_b
}) or croak
$!;
1269 -x
$m->{file_b
} and croak
"$m->{file_b} is executable!\n";
1273 sub svn_ensure_parent_path
{
1274 my $dir_b = dirname
(shift);
1275 svn_ensure_parent_path
($dir_b) if ($dir_b ne File
::Spec
->curdir);
1276 mkpath
([$dir_b]) unless (-d
$dir_b);
1277 sys
(qw(svn add -N), $dir_b) unless (-d
"$dir_b/.svn");
1280 sub precommit_check
{
1282 my (%rm_file, %rmdir_check, %added_check);
1284 my %o = ( D
=> 0, R
=> 1, C
=> 2, A
=> 3, M
=> 3, T
=> 3 );
1285 foreach my $m (sort { $o{$a->{chg
}} <=> $o{$b->{chg
}} } @
$mods) {
1286 if ($m->{chg
} eq 'R') {
1287 if (-d
$m->{file_b
}) {
1288 err_dir_to_file
("$m->{file_a} => $m->{file_b}");
1290 # dir/$file => dir/file/$file
1291 my $dirname = dirname
($m->{file_b
});
1292 while ($dirname ne File
::Spec
->curdir) {
1293 if ($dirname ne $m->{file_a
}) {
1294 $dirname = dirname
($dirname);
1297 err_file_to_dir
("$m->{file_a} => $m->{file_b}");
1299 # baz/zzz => baz (baz is a file)
1300 $dirname = dirname
($m->{file_a
});
1301 while ($dirname ne File
::Spec
->curdir) {
1302 if ($dirname ne $m->{file_b
}) {
1303 $dirname = dirname
($dirname);
1306 err_dir_to_file
("$m->{file_a} => $m->{file_b}");
1309 if ($m->{chg
} =~ /^(D|R)$/) {
1310 my $t = $1 eq 'D' ?
'file_b' : 'file_a';
1311 $rm_file{ $m->{$t} } = 1;
1312 my $dirname = dirname
( $m->{$t} );
1313 my $basename = basename
( $m->{$t} );
1314 $rmdir_check{$dirname}->{$basename} = 1;
1315 } elsif ($m->{chg
} =~ /^(?:A|C)$/) {
1316 if (-d
$m->{file_b
}) {
1317 err_dir_to_file
($m->{file_b
});
1319 my $dirname = dirname
( $m->{file_b
} );
1320 my $basename = basename
( $m->{file_b
} );
1321 $added_check{$dirname}->{$basename} = 1;
1322 while ($dirname ne File
::Spec
->curdir) {
1323 if ($rm_file{$dirname}) {
1324 err_file_to_dir
($m->{file_b
});
1326 $dirname = dirname
$dirname;
1330 return (\
%rmdir_check, \
%added_check);
1332 sub err_dir_to_file
{
1334 print STDERR
"Node change from directory to file ",
1335 "is not supported by Subversion: ",$file,"\n";
1338 sub err_file_to_dir
{
1340 print STDERR
"Node change from file to directory ",
1341 "is not supported by Subversion: ",$file,"\n";
1348 my ($from, $treeish) = @_;
1350 print "diff-tree $from $treeish\n";
1351 my $pid = open my $diff_fh, '-|';
1352 defined $pid or croak
$!;
1354 my @diff_tree = qw(git-diff-tree -z -r);
1355 if ($_cp_similarity) {
1356 push @diff_tree, "-C$_cp_similarity";
1358 push @diff_tree, '-C';
1360 push @diff_tree, '--find-copies-harder' if $_find_copies_harder;
1361 push @diff_tree, "-l$_l" if defined $_l;
1362 exec(@diff_tree, $from, $treeish) or croak
$!;
1364 return parse_diff_tree
($diff_fh);
1367 sub svn_checkout_tree
{
1368 my ($from, $treeish) = @_;
1369 my $mods = get_diff
($from->{commit
}, $treeish);
1370 return $mods unless (scalar @
$mods);
1371 my ($rm, $add) = precommit_check
($mods);
1373 my %o = ( D
=> 1, R
=> 0, C
=> -1, A
=> 3, M
=> 3, T
=> 3 );
1374 foreach my $m (sort { $o{$a->{chg
}} <=> $o{$b->{chg
}} } @
$mods) {
1375 if ($m->{chg
} eq 'C') {
1376 svn_ensure_parent_path
( $m->{file_b
} );
1377 sys
(qw(svn cp), $m->{file_a
}, $m->{file_b
});
1378 apply_mod_line_blob
($m);
1379 svn_check_prop_executable
($m);
1380 } elsif ($m->{chg
} eq 'D') {
1381 sys
(qw(svn rm --force), $m->{file_b
});
1382 } elsif ($m->{chg
} eq 'R') {
1383 svn_ensure_parent_path
( $m->{file_b
} );
1384 sys
(qw(svn mv --force), $m->{file_a
}, $m->{file_b
});
1385 apply_mod_line_blob
($m);
1386 svn_check_prop_executable
($m);
1387 } elsif ($m->{chg
} eq 'M') {
1388 apply_mod_line_blob
($m);
1389 svn_check_prop_executable
($m);
1390 } elsif ($m->{chg
} eq 'T') {
1391 sys
(qw(svn rm --force),$m->{file_b
});
1392 apply_mod_line_blob
($m);
1393 sys
(qw(svn add), $m->{file_b
});
1394 svn_check_prop_executable
($m);
1395 } elsif ($m->{chg
} eq 'A') {
1396 svn_ensure_parent_path
( $m->{file_b
} );
1397 apply_mod_line_blob
($m);
1398 sys
(qw(svn add), $m->{file_b
});
1399 svn_check_prop_executable
($m);
1401 croak
"Invalid chg: $m->{chg}\n";
1405 assert_tree
($treeish);
1406 if ($_rmdir) { # remove empty directories
1407 handle_rmdir
($rm, $add);
1409 assert_tree
($treeish);
1413 sub libsvn_checkout_tree
{
1414 my ($from, $treeish, $ed) = @_;
1415 my $mods = get_diff
($from, $treeish);
1416 return $mods unless (scalar @
$mods);
1417 my %o = ( D
=> 1, R
=> 0, C
=> -1, A
=> 3, M
=> 3, T
=> 3 );
1418 foreach my $m (sort { $o{$a->{chg
}} <=> $o{$b->{chg
}} } @
$mods) {
1420 if (defined $o{$f}) {
1423 croak
"Invalid change type: $f\n";
1426 $ed->rmdirs if $_rmdir;
1430 # svn ls doesn't work with respect to the current working tree, but what's
1431 # in the repository. There's not even an option for it... *sigh*
1432 # (added files don't show up and removed files remain in the ls listing)
1433 sub svn_ls_current
{
1434 my ($dir, $rm, $add) = @_;
1435 chomp(my @ls = safe_qx
('svn','ls',$dir));
1438 s
#/$##; # trailing slashes are evil
1439 push @ret, $_ unless $rm->{$dir}->{$_};
1441 if (exists $add->{$dir}) {
1442 push @ret, keys %{$add->{$dir}};
1448 my ($rm, $add) = @_;
1450 foreach my $dir (sort {length $b <=> length $a} keys %$rm) {
1451 my $ls = svn_ls_current
($dir, $rm, $add);
1452 next if (scalar @
$ls);
1453 sys
(qw(svn rm --force),$dir);
1455 my $dn = dirname
$dir;
1456 $rm->{ $dn }->{ basename
$dir } = 1;
1457 $ls = svn_ls_current
($dn, $rm, $add);
1458 while (scalar @
$ls == 0 && $dn ne File
::Spec
->curdir) {
1459 sys
(qw(svn rm --force),$dn);
1460 $dir = basename
$dn;
1462 $rm->{ $dn }->{ $dir } = 1;
1463 $ls = svn_ls_current
($dn, $rm, $add);
1468 sub get_commit_message
{
1469 my ($commit, $commit_msg) = (@_);
1470 my %log_msg = ( msg
=> '' );
1471 open my $msg, '>', $commit_msg or croak
$!;
1473 print "commit: $commit\n";
1474 chomp(my $type = `git-cat-file -t $commit`);
1475 if ($type eq 'commit') {
1476 my $pid = open my $msg_fh, '-|';
1477 defined $pid or croak
$!;
1480 exec(qw(git-cat-file commit), $commit) or croak
$!;
1485 $in_msg = 1 if (/^\s*$/);
1486 } elsif (/^git-svn-id: /) {
1487 # skip this, we regenerate the correct one
1488 # on re-fetch anyways
1490 print $msg $_ or croak
$!;
1493 close $msg_fh or croak
$?
;
1495 close $msg or croak
$!;
1497 if ($_edit || ($type eq 'tree')) {
1498 my $editor = $ENV{VISUAL
} || $ENV{EDITOR
} || 'vi';
1499 system($editor, $commit_msg);
1502 # file_to_s removes all trailing newlines, so just use chomp() here:
1503 open $msg, '<', $commit_msg or croak
$!;
1504 { local $/; chomp($log_msg{msg
} = <$msg>); }
1505 close $msg or croak
$!;
1510 sub svn_commit_tree
{
1511 my ($last, $commit) = @_;
1512 my $commit_msg = "$GIT_SVN_DIR/.svn-commit.tmp.$$";
1513 my $log_msg = get_commit_message
($commit, $commit_msg);
1514 my ($oneline) = ($log_msg->{msg
} =~ /([^\n\r]+)/);
1515 print "Committing $commit: $oneline\n";
1517 if (defined $LC_ALL) {
1518 $ENV{LC_ALL
} = $LC_ALL;
1520 delete $ENV{LC_ALL
};
1522 my @ci_output = safe_qx
(qw(svn commit -F),$commit_msg);
1525 my ($committed) = ($ci_output[$#ci_output] =~ /(\d+)/);
1526 if (!defined $committed) {
1527 my $out = join("\n",@ci_output);
1528 print STDERR
"W: Trouble parsing \`svn commit' output:\n\n",
1529 $out, "\n\nAssuming English locale...";
1530 ($committed) = ($out =~ /^Committed revision \d+\./sm);
1531 defined $committed or die " FAILED!\n",
1532 "Commit output failed to parse committed revision!\n",
1533 print STDERR
" OK\n";
1536 my @svn_up = qw(svn up);
1537 push @svn_up, '--ignore-externals' unless $_no_ignore_ext;
1538 if ($_optimize_commits && ($committed == ($last->{revision
} + 1))) {
1539 push @svn_up, "-r$committed";
1541 my $info = svn_info
('.');
1542 my $date = $info->{'Last Changed Date'} or die "Missing date\n";
1543 if ($info->{'Last Changed Rev'} != $committed) {
1544 croak
"$info->{'Last Changed Rev'} != $committed\n"
1546 my ($Y,$m,$d,$H,$M,$S,$tz) = ($date =~
1547 /(\d
{4})\
-(\d\d
)\
-(\d\d
)\s
1548 (\d\d
)\
:(\d\d
)\
:(\d\d
)\s
([\
-\
+]\d
+)/x
)
1549 or croak
"Failed to parse date: $date\n";
1550 $log_msg->{date
} = "$tz $Y-$m-$d $H:$M:$S";
1551 $log_msg->{author
} = $info->{'Last Changed Author'};
1552 $log_msg->{revision
} = $committed;
1553 $log_msg->{msg
} .= "\n";
1554 $log_msg->{parents
} = [ $last->{commit
} ];
1555 $log_msg->{commit
} = git_commit
($log_msg, $commit);
1558 # resync immediately
1559 push @svn_up, "-r$last->{revision}";
1561 return fetch
("$committed=$commit");
1566 my $pid = open my $fh, '-|';
1567 defined $pid or croak
$!;
1569 exec(qw
/git-rev-list --pretty=raw/, @args) or croak
$!;
1571 return { fh
=> $fh, t
=> { } };
1574 sub next_rev_list_entry
{
1579 if (/^commit ($sha1)$/o) {
1581 $rl->{t
} = { c
=> $1 };
1586 } elsif (/^parent ($sha1)$/o) {
1593 return ($x != $rl->{t
}) ?
$x : undef;
1596 # read the entire log into a temporary file (which is removed ASAP)
1597 # and store the file handle + parser state
1599 my (@log_args) = @_;
1600 my $log_fh = IO
::File
->new_tmpfile or croak
$!;
1602 defined $pid or croak
$!;
1604 open STDOUT
, '>&', $log_fh or croak
$!;
1605 exec (qw(svn log), @log_args) or croak
$!
1609 seek $log_fh, 0, 0 or croak
$!;
1610 return { state => 'sep', fh
=> $log_fh };
1613 sub next_log_entry
{
1614 my $log = shift; # retval of svn_log_raw()
1616 my $fh = $log->{fh
};
1621 if ($log->{state} eq 'msg') {
1622 if ($ret->{lines
}) {
1623 $ret->{msg
} .= $_."\n";
1624 unless(--$ret->{lines
}) {
1625 $log->{state} = 'sep';
1628 croak
"Log parse error at: $_\n",
1634 if ($log->{state} ne 'sep') {
1635 croak
"Log parse error at: $_\n",
1636 "state: $log->{state}\n",
1640 $log->{state} = 'rev';
1642 # if we have an empty log message, put something there:
1644 $ret->{msg
} ||= "\n";
1645 delete $ret->{lines
};
1650 if ($log->{state} eq 'rev' && s/^r(\d+)\s*\|\s*//) {
1652 my ($author, $date, $lines) = split(/\s*\|\s*/, $_, 3);
1653 ($lines) = ($lines =~ /(\d+)/);
1654 my ($Y,$m,$d,$H,$M,$S,$tz) = ($date =~
1655 /(\d
{4})\
-(\d\d
)\
-(\d\d
)\s
1656 (\d\d
)\
:(\d\d
)\
:(\d\d
)\s
([\
-\
+]\d
+)/x
)
1657 or croak
"Failed to parse date: $date\n";
1658 $ret = { revision
=> $rev,
1659 date
=> "$tz $Y-$m-$d $H:$M:$S",
1663 if (defined $_authors && ! defined $users{$author}) {
1664 die "Author: $author not defined in ",
1667 $log->{state} = 'msg_start';
1670 # skip the first blank line of the message:
1671 if ($log->{state} eq 'msg_start' && /^$/) {
1672 $log->{state} = 'msg';
1673 } elsif ($log->{state} eq 'msg') {
1674 if ($ret->{lines
}) {
1675 $ret->{msg
} .= $_."\n";
1676 unless (--$ret->{lines
}) {
1677 $log->{state} = 'sep';
1680 croak
"Log parse error at: $_\n",
1681 $ret->{revision
},"\n";
1689 my $url = shift || $SVN_URL;
1691 my $pid = open my $info_fh, '-|';
1692 defined $pid or croak
$!;
1695 exec(qw(svn info),$url) or croak
$!;
1699 # only single-lines seem to exist in svn info output
1700 while (<$info_fh>) {
1702 if (m
#^([^:]+)\s*:\s*(\S.*)$#) {
1704 push @
{$ret->{-order
}}, $1;
1707 close $info_fh or croak
$?
;
1711 sub sys
{ system(@_) == 0 or croak
$?
}
1714 my ($from, $to) = @_;
1715 my $es = svn_propget_base
('svn:eol-style', $to);
1716 open my $rfd, '<', $from or croak
$!;
1717 binmode $rfd or croak
$!;
1718 open my $wfd, '>', $to or croak
$!;
1719 binmode $wfd or croak
$!;
1720 eol_cp_fd
($rfd, $wfd, $es);
1721 close $rfd or croak
$!;
1722 close $wfd or croak
$!;
1726 my ($rfd, $wfd, $es) = @_;
1727 my $eol = defined $es ?
$EOL{$es} : undef;
1732 defined($r = sysread($rfd, $buf, 4096)) or croak
$!;
1735 if ($buf =~ /\015$/) {
1737 defined($r = sysread($rfd,$c,1)) or croak
$!;
1738 $buf .= $c if $r > 0;
1740 $buf =~ s/(?:\015\012|\015|\012)/$eol/gs;
1743 for ($w = 0; $w < $r; $w += $t) {
1744 $t = syswrite($wfd, $buf, $r - $w, $w) or croak
$!;
1750 sub do_update_index
{
1751 my ($z_cmd, $cmd, $no_text_base) = @_;
1753 my $z = open my $p, '-|';
1754 defined $z or croak
$!;
1755 unless ($z) { exec @
$z_cmd or croak
$! }
1757 my $pid = open my $ui, '|-';
1758 defined $pid or croak
$!;
1760 exec('git-update-index',"--$cmd",'-z','--stdin') or croak
$!;
1763 while (my $x = <$p>) {
1765 if (!$no_text_base && lstat $x && ! -l _
&&
1766 svn_propget_base
('svn:keywords', $x)) {
1767 my $mode = -x _ ?
0755 : 0644;
1768 my ($v,$d,$f) = File
::Spec
->splitpath($x);
1769 my $tb = File
::Spec
->catfile($d, '.svn', 'tmp',
1770 'text-base',"$f.svn-base");
1773 $tb = File
::Spec
->catfile($d, '.svn',
1774 'text-base',"$f.svn-base");
1777 unlink $x or croak
$!;
1779 chmod(($mode &~ umask), $x) or croak
$!;
1783 close $ui or croak
$?
;
1787 return if $_use_lib;
1789 if (!-f
"$GIT_SVN_DIR/info/exclude") {
1790 open my $fd, '>>', "$GIT_SVN_DIR/info/exclude" or croak
$!;
1791 print $fd '.svn',"\n";
1792 close $fd or croak
$!;
1794 my $no_text_base = shift;
1795 do_update_index
([qw
/git-diff-files --name-only -z/],
1798 do_update_index
([qw
/git-ls-files -z --others/,
1799 "--exclude-from=$GIT_SVN_DIR/info/exclude"],
1805 my ($str, $file, $mode) = @_;
1806 open my $fd,'>',$file or croak
$!;
1807 print $fd $str,"\n" or croak
$!;
1808 close $fd or croak
$!;
1809 chmod ($mode &~ umask, $file) if (defined $mode);
1814 open my $fd,'<',$file or croak
"$!: file: $file\n";
1817 close $fd or croak
$!;
1822 sub assert_revision_unknown
{
1824 if (my $c = revdb_get
($REVDB, $r)) {
1825 croak
"$r = $c already exists! Why are we refetching it?";
1831 my @x = safe_qx
('git-cat-file','commit',$x);
1832 my @y = safe_qx
('git-cat-file','commit',$y);
1833 if (($y[0] ne $x[0]) || $x[0] !~ /^tree $sha1\n$/
1834 || $y[0] !~ /^tree $sha1\n$/) {
1835 print STDERR
"Trees not equal: $y[0] != $x[0]\n";
1842 my ($log_msg, @parents) = @_;
1843 assert_revision_unknown
($log_msg->{revision
});
1844 map_tree_joins
() if (@_branch_from && !%tree_map);
1846 my (@tmp_parents, @exec_parents, %seen_parent);
1847 if (my $lparents = $log_msg->{parents
}) {
1848 @tmp_parents = @
$lparents
1850 # commit parents can be conditionally bound to a particular
1851 # svn revision via: "svn_revno=commit_sha1", filter them out here:
1852 foreach my $p (@parents) {
1853 next unless defined $p;
1854 if ($p =~ /^(\d+)=($sha1_short)$/o) {
1855 if ($1 == $log_msg->{revision
}) {
1856 push @tmp_parents, $2;
1859 push @tmp_parents, $p if $p =~ /$sha1_short/o;
1862 my $tree = $log_msg->{tree
};
1863 if (!defined $tree) {
1864 my $index = set_index
($GIT_SVN_INDEX);
1866 chomp($tree = `git-write-tree`);
1868 restore_index
($index);
1870 if (exists $tree_map{$tree}) {
1871 foreach my $p (@
{$tree_map{$tree}}) {
1873 foreach (@tmp_parents) {
1874 # see if a common parent is found
1876 safe_qx
('git-merge-base', $_, $p)
1883 my ($url_p, $r_p, $uuid_p) = cmt_metadata
($p);
1884 next if (($SVN_UUID eq $uuid_p) &&
1885 ($log_msg->{revision
} > $r_p));
1886 next if (defined $url_p && defined $SVN_URL &&
1887 ($SVN_UUID eq $uuid_p) &&
1888 ($url_p eq $SVN_URL));
1889 push @tmp_parents, $p;
1892 foreach (@tmp_parents) {
1893 next if $seen_parent{$_};
1894 $seen_parent{$_} = 1;
1895 push @exec_parents, $_;
1896 # MAXPARENT is defined to 16 in commit-tree.c:
1897 last if @exec_parents > 16;
1900 defined(my $pid = open my $out_fh, '-|') or croak
$!;
1902 my $msg_fh = IO
::File
->new_tmpfile or croak
$!;
1903 print $msg_fh $log_msg->{msg
}, "\ngit-svn-id: ",
1904 "$SVN_URL\@$log_msg->{revision}",
1905 " $SVN_UUID\n" or croak
$!;
1906 $msg_fh->flush == 0 or croak
$!;
1907 seek $msg_fh, 0, 0 or croak
$!;
1908 set_commit_env
($log_msg);
1909 my @exec = ('git-commit-tree',$tree);
1910 push @exec, '-p', $_ foreach @exec_parents;
1911 open STDIN
, '<&', $msg_fh or croak
$!;
1912 exec @exec or croak
$!;
1914 chomp(my $commit = do { local $/; <$out_fh> });
1915 close $out_fh or croak
$?
;
1916 if ($commit !~ /^$sha1$/o) {
1917 croak
"Failed to commit, invalid sha1: $commit\n";
1919 my @update_ref = ('git-update-ref',"refs/remotes/$GIT_SVN",$commit);
1920 if (my $primary_parent = shift @exec_parents) {
1921 quiet_run
(qw
/git-rev-parse --verify/,"refs/remotes/$GIT_SVN^0");
1922 push @update_ref, $primary_parent unless $?
;
1925 revdb_set
($REVDB, $log_msg->{revision
}, $commit);
1927 # this output is read via pipe, do not change:
1928 print "r$log_msg->{revision} = $commit\n";
1934 if ($_repack && (--$_repack_nr == 0)) {
1935 $_repack_nr = $_repack;
1936 sys
("git repack $_repack_flags");
1940 sub set_commit_env
{
1942 my $author = $log_msg->{author
};
1943 if (!defined $author || length $author == 0) {
1944 $author = '(no author)';
1946 my ($name,$email) = defined $users{$author} ? @
{$users{$author}}
1947 : ($author,"$author\@$SVN_UUID");
1948 $ENV{GIT_AUTHOR_NAME
} = $ENV{GIT_COMMITTER_NAME
} = $name;
1949 $ENV{GIT_AUTHOR_EMAIL
} = $ENV{GIT_COMMITTER_EMAIL
} = $email;
1950 $ENV{GIT_AUTHOR_DATE
} = $ENV{GIT_COMMITTER_DATE
} = $log_msg->{date
};
1953 sub apply_mod_line_blob
{
1955 if ($m->{mode_b
} =~ /^120/) {
1956 blob_to_symlink
($m->{sha1_b
}, $m->{file_b
});
1958 blob_to_file
($m->{sha1_b
}, $m->{file_b
});
1962 sub blob_to_symlink
{
1963 my ($blob, $link) = @_;
1964 defined $link or croak
"\$link not defined!\n";
1965 croak
"Not a sha1: $blob\n" unless $blob =~ /^$sha1$/o;
1966 if (-l
$link || -f _
) {
1967 unlink $link or croak
$!;
1970 my $dest = `git-cat-file blob $blob`; # no newline, so no chomp
1971 symlink $dest, $link or croak
$!;
1975 my ($blob, $file) = @_;
1976 defined $file or croak
"\$file not defined!\n";
1977 croak
"Not a sha1: $blob\n" unless $blob =~ /^$sha1$/o;
1978 if (-l
$file || -f _
) {
1979 unlink $file or croak
$!;
1982 open my $blob_fh, '>', $file or croak
"$!: $file\n";
1984 defined $pid or croak
$!;
1987 open STDOUT
, '>&', $blob_fh or croak
$!;
1988 exec('git-cat-file','blob',$blob) or croak
$!;
1993 close $blob_fh or croak
$!;
1997 my $pid = open my $child, '-|';
1998 defined $pid or croak
$!;
2000 exec(@_) or croak
$!;
2002 my @ret = (<$child>);
2003 close $child or croak
$?
;
2004 die $?
if $?
; # just in case close didn't error out
2005 return wantarray ?
@ret : join('',@ret);
2008 sub svn_compat_check
{
2009 my @co_help = safe_qx
(qw(svn co -h));
2010 unless (grep /ignore-externals/,@co_help) {
2011 print STDERR
"W: Installed svn version does not support ",
2012 "--ignore-externals\n";
2013 $_no_ignore_ext = 1;
2015 if (grep /usage: checkout URL\[\@REV\]/,@co_help) {
2016 $_svn_co_url_revs = 1;
2018 if (grep /\[TARGET\[\@REV\]\.\.\.\]/, `svn propget -h`) {
2019 $_svn_pg_peg_revs = 1;
2022 # I really, really hope nobody hits this...
2023 unless (grep /stop-on-copy/, (safe_qx
(qw(svn log -h)))) {
2025 W
: The installed svn version does
not support the
--stop
-on
-copy flag
in
2027 Lets hope the directory you
're tracking is not a branch or tag
2028 and was never moved within the repository...
2034 # *sigh*, new versions of svn won't honor
-r
<rev
> without URL@
<rev
>,
2035 # (and they won't honor URL@<rev> without -r<rev>, too!)
2036 sub svn_cmd_checkout
{
2037 my ($url, $rev, $dir) = @_;
2038 my @cmd = ('svn','co', "-r$rev");
2039 push @cmd, '--ignore-externals' unless $_no_ignore_ext;
2040 $url .= "\@$rev" if $_svn_co_url_revs;
2041 sys
(@cmd, $url, $dir);
2044 sub check_upgrade_needed
{
2046 -d
$GIT_SVN_DIR or mkpath
([$GIT_SVN_DIR]);
2047 open my $fh, '>>',$REVDB or croak
$!;
2051 my $pid = open my $child, '-|';
2052 defined $pid or croak
$!;
2055 exec('git-rev-parse',"$GIT_SVN-HEAD") or croak
$!;
2057 my @ret = (<$child>);
2058 close $child or croak
$?
;
2059 die $?
if $?
; # just in case close didn't error out
2060 return wantarray ?
@ret : join('',@ret);
2063 my $head = eval { safe_qx
('git-rev-parse',"refs/remotes/$GIT_SVN") };
2065 print STDERR
"Please run: $0 rebuild --upgrade\n";
2070 # fills %tree_map with a reverse mapping of trees to commits. Useful
2071 # for finding parents to commit on.
2072 sub map_tree_joins
{
2074 foreach my $br (@_branch_from) {
2075 my $pid = open my $pipe, '-|';
2076 defined $pid or croak
$!;
2078 exec(qw(git-rev-list --topo-order --pretty=raw), $br)
2082 if (/^commit ($sha1)$/o) {
2085 # if we've seen a commit,
2086 # we've seen its parents
2087 last if $seen{$commit};
2088 my ($tree) = (<$pipe> =~ /^tree ($sha1)$/o);
2089 unless (defined $tree) {
2090 die "Failed to parse commit $commit\n";
2092 push @
{$tree_map{$tree}}, $commit;
2096 close $pipe; # we could be breaking the pipe early
2101 if (@_branch_from) {
2102 print STDERR
'--branch|-b parameters are ignored when ',
2103 "--branch-all-refs|-B is passed\n";
2106 # don't worry about rev-list on non-commit objects/tags,
2107 # it shouldn't blow up if a ref is a blob or tree...
2108 chomp(@_branch_from = `git-rev-parse --symbolic --all`);
2111 # '<svn username> = real-name <email address>' mapping based on git-svnimport:
2113 open my $authors, '<', $_authors or die "Can't open $_authors $!\n";
2114 while (<$authors>) {
2116 next unless /^(\S+?)\s*=\s*(.+?)\s*<(.+)>\s*$/;
2117 my ($user, $name, $email) = ($1, $2, $3);
2118 $users{$user} = [$name, $email];
2120 close $authors or croak
$!;
2124 open my $authors, '<', $_authors or die "Can't open $_authors $!\n";
2125 while (<$authors>) {
2127 next unless /^(\S+?)\s*=\s*(.+?)\s*<(.+)>\s*$/;
2128 my ($user, $name, $email) = ($1, $2, $3);
2129 $rusers{"$name <$email>"} = $user;
2131 close $authors or croak
$!;
2134 sub svn_propget_base
{
2136 $f .= '@BASE' if $_svn_pg_peg_revs;
2137 return safe_qx
(qw
/svn propget/, $p, $f);
2142 foreach (`git-rev-parse --symbolic --all`) {
2143 next unless s
#^refs/remotes/##;
2145 next unless -f
"$GIT_DIR/svn/$_/info/url";
2153 defined(my $pid = fork) or croak
$!;
2155 $GIT_SVN = $ENV{GIT_SVN_ID
} = $id;
2157 exit 0 if -r
$REVDB;
2158 print "Upgrading svn => git mapping...\n";
2159 -d
$GIT_SVN_DIR or mkpath
([$GIT_SVN_DIR]);
2160 open my $fh, '>>',$REVDB or croak
$!;
2163 print "Done upgrading. You may now delete the ",
2164 "deprecated $GIT_SVN_DIR/revs directory\n";
2172 sub migration_check
{
2173 migrate_revdb
() unless (-e
$REVDB);
2174 return if (-d
"$GIT_DIR/svn" || !-d
$GIT_DIR);
2175 print "Upgrading repository...\n";
2176 unless (-d
"$GIT_DIR/svn") {
2177 mkdir "$GIT_DIR/svn" or croak
$!;
2179 print "Data from a previous version of git-svn exists, but\n\t",
2180 "$GIT_SVN_DIR\n\t(required for this version ",
2181 "($VERSION) of git-svn) does not.\n";
2183 foreach my $x (`git-rev-parse --symbolic --all`) {
2184 next unless $x =~ s
#^refs/remotes/##;
2186 next unless -f
"$GIT_DIR/$x/info/url";
2187 my $u = eval { file_to_s
("$GIT_DIR/$x/info/url") };
2189 my $dn = dirname
("$GIT_DIR/svn/$x");
2190 mkpath
([$dn]) unless -d
$dn;
2191 rename "$GIT_DIR/$x", "$GIT_DIR/svn/$x" or croak
"$!: $x";
2193 migrate_revdb
() if (-d
$GIT_SVN_DIR && !-w
$REVDB);
2194 print "Done upgrading.\n";
2197 sub find_rev_before
{
2198 my ($r, $id, $eq_ok) = @_;
2199 my $f = "$GIT_DIR/svn/$id/.rev_db";
2200 return (undef,undef) unless -r
$f;
2203 if (my $c = revdb_get
($f, $r)) {
2208 return (undef, undef);
2212 $GIT_SVN ||= $ENV{GIT_SVN_ID
} || 'git-svn';
2213 $GIT_SVN_DIR = "$GIT_DIR/svn/$GIT_SVN";
2214 $REVDB = "$GIT_SVN_DIR/.rev_db";
2215 $GIT_SVN_INDEX = "$GIT_SVN_DIR/index";
2217 $SVN_WC = "$GIT_SVN_DIR/tree";
2221 # convert GetOpt::Long specs for use by git-repo-config
2222 sub read_repo_config
{
2223 return unless -d
$GIT_DIR;
2225 foreach my $o (keys %$opts) {
2226 my $v = $opts->{$o};
2227 my ($key) = ($o =~ /^([a-z\-]+)/);
2229 my $arg = 'git-repo-config';
2230 $arg .= ' --int' if ($o =~ /[:=]i$/);
2231 $arg .= ' --bool' if ($o !~ /[:=][sfi]$/);
2232 if (ref $v eq 'ARRAY') {
2233 chomp(my @tmp = `$arg --get-all svn.$key`);
2236 chomp(my $tmp = `$arg --get svn.$key`);
2237 if ($tmp && !($arg =~ / --bool / && $tmp eq 'false')) {
2244 sub set_default_vals
{
2245 if (defined $_repack) {
2246 $_repack = 1000 if ($_repack <= 0);
2247 $_repack_nr = $_repack;
2248 $_repack_flags ||= '-d';
2253 my $gr_file = shift;
2254 my ($grafts, $comments) = ({}, {});
2255 if (open my $fh, '<', $gr_file) {
2258 if (/^($sha1)\s+/) {
2261 @
{$comments->{$c}} = @tmp;
2264 foreach my $p (split /\s+/, $_) {
2265 $grafts->{$c}->{$p} = 1;
2271 close $fh or croak
$!;
2272 @
{$comments->{'END'}} = @tmp if @tmp;
2274 return ($grafts, $comments);
2278 my ($grafts, $comments, $gr_file) = @_;
2280 open my $fh, '>', $gr_file or croak
$!;
2281 foreach my $c (sort keys %$grafts) {
2282 if ($comments->{$c}) {
2283 print $fh $_ foreach @
{$comments->{$c}};
2285 my $p = $grafts->{$c};
2286 my %x; # real parents
2287 delete $p->{$c}; # commits are not self-reproducing...
2288 my $pid = open my $ch, '-|';
2289 defined $pid or croak
$!;
2291 exec(qw
/git-cat-file commit/, $c) or croak
$!;
2294 if (/^parent ($sha1)/) {
2295 $x{$1} = $p->{$1} = 1;
2300 close $ch; # breaking the pipe
2302 # if real parents are the only ones in the grafts, drop it
2303 next if join(' ',sort keys %$p) eq join(' ',sort keys %x);
2307 @ip = @jp = keys %$p;
2308 foreach my $i (@ip) {
2309 next if $del{$i} || $p->{$i} == 2;
2310 foreach my $j (@jp) {
2311 next if $i eq $j || $del{$j} || $p->{$j} == 2;
2312 $mb = eval { safe_qx
('git-merge-base',$i,$j) };
2319 } elsif ($mb eq $i) {
2326 # if real parents are the only ones in the grafts, drop it
2327 next if join(' ',sort keys %$p) eq join(' ',sort keys %x);
2329 print $fh $c, ' ', join(' ', sort keys %$p),"\n";
2331 if ($comments->{'END'}) {
2332 print $fh $_ foreach @
{$comments->{'END'}};
2334 close $fh or croak
$!;
2337 sub read_url_paths
{
2339 git_svn_each
(sub { my $x = shift;
2340 my $url = file_to_s
("$GIT_DIR/svn/$x/info/url");
2341 my ($u, $p) = repo_path_split
($url);
2342 $l_map->{$u}->{$p} = $x;
2347 sub extract_metadata
{
2348 my $id = shift or return (undef, undef, undef);
2349 my ($url, $rev, $uuid) = ($id =~ /^git
-svn
-id
:\s
(\S
+?
)\@
(\d
+)
2351 if (!$rev || !$uuid || !$url) {
2352 # some of the original repositories I made had
2353 # indentifiers like this:
2354 ($rev, $uuid) = ($id =~/^git-svn-id:\s(\d+)\@([a-f\d\-]+)/);
2356 return ($url, $rev, $uuid);
2360 return extract_metadata
((grep(/^git-svn-id: /,
2361 safe_qx
(qw
/git-cat-file commit/, shift)))[-1]);
2364 sub get_commit_time
{
2366 defined(my $pid = open my $fh, '-|') or croak
$!;
2368 exec qw
/git-rev-list --pretty=raw -n1/, $cmt or croak
$!;
2371 /^committer\s(?:.+) (\d+) ([\-\+]?\d+)$/ or next;
2372 my ($s, $tz) = ($1, $2);
2373 if ($tz =~ s/^\+//) {
2374 $s += tz_to_s_offset
($tz);
2375 } elsif ($tz =~ s/^\-//) {
2376 $s -= tz_to_s_offset
($tz);
2381 die "Can't get commit time for commit: $cmt\n";
2384 sub tz_to_s_offset
{
2387 return ($1 * 60) + ($tz * 3600);
2390 sub setup_pager
{ # translated to Perl from pager.c
2391 return unless (-t
*STDOUT
);
2392 my $pager = $ENV{PAGER
};
2393 if (!defined $pager) {
2395 } elsif (length $pager == 0 || $pager eq 'cat') {
2398 pipe my $rfd, my $wfd or return;
2399 defined(my $pid = fork) or croak
$!;
2401 open STDOUT
, '>&', $wfd or croak
$!;
2404 open STDIN
, '<&', $rfd or croak
$!;
2405 $ENV{LESS
} ||= '-S';
2406 exec $pager or croak
"Can't run pager: $!\n";;
2409 sub get_author_info
{
2410 my ($dest, $author, $t, $tz) = @_;
2411 $author =~ s/(?:^\s*|\s*$)//g;
2412 $dest->{a_raw
} = $author;
2415 $_a = $rusers{$author} || undef;
2418 ($_a) = ($author =~ /<([^>]+)\@[^>]+>$/);
2423 # Date::Parse isn't in the standard Perl distro :(
2424 if ($tz =~ s/^\+//) {
2425 $t += tz_to_s_offset
($tz);
2426 } elsif ($tz =~ s/^\-//) {
2427 $t -= tz_to_s_offset
($tz);
2429 $dest->{t_utc
} = $t;
2432 sub process_commit
{
2433 my ($c, $r_min, $r_max, $defer) = @_;
2434 if (defined $r_min && defined $r_max) {
2435 if ($r_min == $c->{r
} && $r_min == $r_max) {
2439 return 1 if $r_min == $r_max;
2440 if ($r_min < $r_max) {
2441 # we need to reverse the print order
2442 return 0 if (defined $_limit && --$_limit < 0);
2446 if ($r_min != $r_max) {
2447 return 1 if ($r_min < $c->{r
});
2448 return 1 if ($r_max > $c->{r
});
2451 return 0 if (defined $_limit && --$_limit < 0);
2460 if (my $l = $c->{l
}) {
2461 while ($l->[0] =~ /^\s*$/) { shift @
$l }
2464 $_l_fmt ||= 'A' . length($c->{r
});
2465 print 'r',pack($_l_fmt, $c->{r
}),' | ';
2466 print "$c->{c} | " if $_show_commit;
2469 show_commit_normal
($c);
2473 sub show_commit_normal
{
2475 print '-' x72
, "\nr$c->{r} | ";
2476 print "$c->{c} | " if $_show_commit;
2477 print "$c->{a} | ", strftime
("%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)",
2478 localtime($c->{t_utc
})), ' | ';
2481 if (my $l = $c->{l
}) {
2482 while ($l->[$#$l] eq "\n" && $l->[($#$l - 1)] eq "\n") {
2485 $nr_line = scalar @
$l;
2487 print "1 line\n\n\n";
2489 if ($nr_line == 1) {
2490 $nr_line = '1 line';
2492 $nr_line .= ' lines';
2494 print $nr_line, "\n\n";
2495 print $_ foreach @
$l;
2501 foreach my $x (qw
/raw diff/) {
2504 print $_ foreach @
{$c->{$x}}
2510 return unless $_use_lib;
2513 if ($SVN::Core
::VERSION
lt '1.1.0') {
2514 die "Need SVN::Core 1.1.0 or better ",
2515 "(got $SVN::Core::VERSION) ",
2516 "Falling back to command-line svn\n";
2520 push @SVN::Git
::Editor
::ISA
, 'SVN::Delta::Editor';
2521 my $kill_stupid_warnings = $SVN::Node
::none
.$SVN::Node
::file
.
2522 $SVN::Node
::dir
.$SVN::Node
::unknown
.
2523 $SVN::Node
::none
.$SVN::Node
::file
.
2524 $SVN::Node
::dir
.$SVN::Node
::unknown
;
2529 sub libsvn_connect
{
2531 my $auth = SVN
::Core
::auth_open
([SVN
::Client
::get_simple_provider
(),
2532 SVN
::Client
::get_ssl_server_trust_file_provider
(),
2533 SVN
::Client
::get_username_provider
()]);
2534 my $s = eval { SVN
::Ra
->new(url
=> $url, auth
=> $auth) };
2538 sub libsvn_get_file
{
2539 my ($gui, $f, $rev) = @_;
2541 return unless ($p =~ s
#^\Q$SVN_PATH\E/?##);
2543 my ($hash, $pid, $in, $out);
2544 my $pool = SVN
::Pool
->new;
2545 defined($pid = open3
($in, $out, '>&STDERR',
2546 qw
/git-hash-object -w --stdin/)) or croak
$!;
2547 # redirect STDOUT for SVN 1.1.x compatibility
2548 open my $stdout, '>&', \
*STDOUT
or croak
$!;
2549 open STDOUT
, '>&', $in or croak
$!;
2550 $| = 1; # not sure if this is necessary, better safe than sorry...
2551 my ($r, $props) = $SVN->get_file($f, $rev, \
*STDOUT
, $pool);
2552 $in->flush == 0 or croak
$!;
2553 open STDOUT
, '>&', $stdout or croak
$!;
2554 close $in or croak
$!;
2555 close $stdout or croak
$!;
2557 chomp($hash = do { local $/; <$out> });
2558 close $out or croak
$!;
2560 $hash =~ /^$sha1$/o or die "not a sha1: $hash\n";
2562 my $mode = exists $props->{'svn:executable'} ?
'100755' : '100644';
2563 if (exists $props->{'svn:special'}) {
2565 my $link = `git-cat-file blob $hash`;
2566 $link =~ s/^link // or die "svn:special file with contents: <",
2567 $link, "> is not understood\n";
2568 defined($pid = open3
($in, $out, '>&STDERR',
2569 qw
/git-hash-object -w --stdin/)) or croak
$!;
2571 $in->flush == 0 or croak
$!;
2572 close $in or croak
$!;
2573 chomp($hash = do { local $/; <$out> });
2574 close $out or croak
$!;
2576 $hash =~ /^$sha1$/o or die "not a sha1: $hash\n";
2578 print $gui $mode,' ',$hash,"\t",$p,"\0" or croak
$!;
2581 sub libsvn_log_entry
{
2582 my ($rev, $author, $date, $msg, $parents) = @_;
2583 my ($Y,$m,$d,$H,$M,$S) = ($date =~ /^(\d
{4})\
-(\d\d
)\
-(\d\d
)T
2584 (\d\d
)\
:(\d\d
)\
:(\d\d
).\d
+Z
$/x
)
2585 or die "Unable to parse date: $date\n";
2586 if (defined $_authors && ! defined $users{$author}) {
2587 die "Author: $author not defined in $_authors file\n";
2589 return { revision
=> $rev, date
=> "+0000 $Y-$m-$d $H:$M:$S",
2590 author
=> $author, msg
=> $msg."\n", parents
=> $parents || [] }
2594 my ($gui, $last_commit, $f) = @_;
2595 $f =~ s
#^\Q$SVN_PATH\E/?## or return;
2596 # remove entire directories.
2597 if (safe_qx
('git-ls-tree',$last_commit,'--',$f) =~ /^040000 tree/) {
2598 defined(my $pid = open my $ls, '-|') or croak
$!;
2600 exec(qw
/git-ls-tree -r --name-only -z/,
2601 $last_commit,'--',$f) or croak
$!;
2605 print $gui '0 ',0 x
40,"\t",$_ or croak
$!;
2607 close $ls or croak
$?
;
2609 print $gui '0 ',0 x
40,"\t",$f,"\0" or croak
$!;
2614 my ($last_commit, $paths, $rev, $author, $date, $msg) = @_;
2615 open my $gui, '| git-update-index -z --index-info' or croak
$!;
2617 foreach my $f (keys %$paths) {
2618 my $m = $paths->{$f}->action();
2620 if ($m =~ /^[DR]$/) {
2621 process_rm
($gui, $last_commit, $f);
2623 # 'R' can be file replacements, too, right?
2625 my $pool = SVN
::Pool
->new;
2626 my $t = $SVN->check_path($f, $rev, $pool);
2627 if ($t == $SVN::Node
::file
) {
2628 if ($m =~ /^[AMR]$/) {
2631 die "Unrecognized action: $m, ($f r$rev)\n";
2636 libsvn_get_file
($gui, $_, $rev) foreach (@amr);
2637 close $gui or croak
$?
;
2638 return libsvn_log_entry
($rev, $author, $date, $msg, [$last_commit]);
2641 sub svn_grab_base_rev
{
2642 defined(my $pid = open my $fh, '-|') or croak
$!;
2644 open my $null, '>', '/dev/null' or croak
$!;
2645 open STDERR
, '>&', $null or croak
$!;
2646 exec qw
/git-rev-parse --verify/,"refs/remotes/$GIT_SVN^0"
2649 chomp(my $c = do { local $/; <$fh> });
2651 if (defined $c && length $c) {
2652 my ($url, $rev, $uuid) = cmt_metadata
($c);
2655 return (undef, undef);
2658 sub libsvn_parse_revision
{
2660 my $head = $SVN->get_latest_revnum();
2661 if (!defined $_revision || $_revision eq 'BASE:HEAD') {
2662 return ($base + 1, $head) if (defined $base);
2665 return ($1, $2) if ($_revision =~ /^(\d+):(\d+)$/);
2666 return ($_revision, $_revision) if ($_revision =~ /^\d+$/);
2667 if ($_revision =~ /^BASE:(\d+)$/) {
2668 return ($base + 1, $1) if (defined $base);
2671 return ($1, $head) if ($_revision =~ /^(\d+):HEAD$/);
2672 die "revision argument: $_revision not understood by git-svn\n",
2673 "Try using the command-line svn client instead\n";
2676 sub libsvn_traverse
{
2677 my ($gui, $pfx, $path, $rev) = @_;
2678 my $cwd = "$pfx/$path";
2679 my $pool = SVN
::Pool
->new;
2681 my ($dirent, $r, $props) = $SVN->get_dir($cwd, $rev, $pool);
2682 foreach my $d (keys %$dirent) {
2683 my $t = $dirent->{$d}->kind;
2684 if ($t == $SVN::Node
::dir
) {
2685 libsvn_traverse
($gui, $cwd, $d, $rev);
2686 } elsif ($t == $SVN::Node
::file
) {
2687 libsvn_get_file
($gui, "$cwd/$d", $rev);
2693 sub libsvn_traverse_ignore
{
2694 my ($fh, $path, $r) = @_;
2696 my $pool = SVN
::Pool
->new;
2697 my ($dirent, undef, $props) = $SVN->get_dir($path, $r, $pool);
2699 $p =~ s
#^\Q$SVN_PATH\E/?##;
2700 print $fh length $p ?
"\n# $p\n" : "\n# /\n";
2701 if (my $s = $props->{'svn:ignore'}) {
2702 $s =~ s/[\r\n]+/\n/g;
2704 if (length $p == 0) {
2708 $s =~ s
#\n#\n/$p/#g;
2709 print $fh "/$p/$s\n";
2712 foreach (sort keys %$dirent) {
2713 next if $dirent->{$_}->kind != $SVN::Node
::dir
;
2714 libsvn_traverse_ignore
($fh, "$path/$_", $r);
2720 my ($path, $r0, $r1) = @_;
2721 return 1 if $r0 == $r1;
2724 # should be OK to use Pool here (r1 - r0) should be small
2725 my $pool = SVN
::Pool
->new;
2726 libsvn_get_log
($SVN, "/$path", $r0, $r1,
2727 0, 1, 1, sub {$nr++}, $pool);
2730 my ($url, undef) = repo_path_split
($SVN_URL);
2731 my $svn_log = svn_log_raw
("$url/$path","-r$r0:$r1");
2732 while (next_log_entry
($svn_log)) { $nr++ }
2733 close $svn_log->{fh
};
2735 return 0 if ($nr > 1);
2739 sub libsvn_find_parent_branch
{
2740 my ($paths, $rev, $author, $date, $msg) = @_;
2741 my $svn_path = '/'.$SVN_PATH;
2743 # look for a parent from another branch:
2744 my $i = $paths->{$svn_path} or return;
2745 my $branch_from = $i->copyfrom_path or return;
2746 my $r = $i->copyfrom_rev;
2747 print STDERR
"Found possible branch point: ",
2748 "$branch_from => $svn_path, $r\n";
2749 $branch_from =~ s
#^/##;
2750 my $l_map = read_url_paths
();
2751 my $url = $SVN->{url
};
2752 defined $l_map->{$url} or return;
2753 my $id = $l_map->{$url}->{$branch_from} or return;
2754 my ($r0, $parent) = find_rev_before
($r,$id,1);
2755 return unless (defined $r0 && defined $parent);
2756 if (revisions_eq
($branch_from, $r0, $r)) {
2757 unlink $GIT_SVN_INDEX;
2758 print STDERR
"Found branch parent: $parent\n";
2759 sys
(qw
/git-read-tree/, $parent);
2760 return libsvn_fetch
($parent, $paths, $rev,
2761 $author, $date, $msg);
2763 print STDERR
"Nope, branch point not imported or unknown\n";
2767 sub libsvn_get_log
{
2768 my ($ra, @args) = @_;
2769 if ($SVN::Core
::VERSION
le '1.2.0') {
2770 splice(@args, 3, 1);
2772 $ra->get_log(@args);
2775 sub libsvn_new_tree
{
2776 if (my $log_entry = libsvn_find_parent_branch
(@_)) {
2779 my ($paths, $rev, $author, $date, $msg) = @_;
2780 open my $gui, '| git-update-index -z --index-info' or croak
$!;
2781 my $pool = SVN
::Pool
->new;
2782 libsvn_traverse
($gui, '', $SVN_PATH, $rev, $pool);
2784 close $gui or croak
$?
;
2785 return libsvn_log_entry
($rev, $author, $date, $msg);
2788 sub find_graft_path_commit
{
2789 my ($tree_paths, $p1, $r1) = @_;
2790 foreach my $x (keys %$tree_paths) {
2791 next unless ($p1 =~ /^\Q$x\E/);
2792 my $i = $tree_paths->{$x};
2793 my ($r0, $parent) = find_rev_before
($r1,$i,1);
2794 return $parent if (defined $r0 && $r0 == $r1);
2795 print STDERR
"r$r1 of $i not imported\n";
2801 sub find_graft_path_parents
{
2802 my ($grafts, $tree_paths, $c, $p0, $r0) = @_;
2803 foreach my $x (keys %$tree_paths) {
2804 next unless ($p0 =~ /^\Q$x\E/);
2805 my $i = $tree_paths->{$x};
2806 my ($r, $parent) = find_rev_before
($r0, $i, 1);
2807 if (defined $r && defined $parent && revisions_eq
($x,$r,$r0)) {
2808 my ($url_b, undef, $uuid_b) = cmt_metadata
($c);
2809 my ($url_a, undef, $uuid_a) = cmt_metadata
($parent);
2810 next if ($url_a && $url_b && $url_a eq $url_b &&
2811 $uuid_b eq $uuid_a);
2812 $grafts->{$c}->{$parent} = 1;
2817 sub libsvn_graft_file_copies
{
2818 my ($grafts, $tree_paths, $path, $paths, $rev) = @_;
2819 foreach (keys %$paths) {
2820 my $i = $paths->{$_};
2821 my ($m, $p0, $r0) = ($i->action, $i->copyfrom_path,
2823 next unless (defined $p0 && defined $r0);
2828 my $c = find_graft_path_commit
($tree_paths, $p1, $rev);
2830 find_graft_path_parents
($grafts, $tree_paths, $c, $p0, $r0);
2835 my $old = $ENV{GIT_INDEX_FILE
};
2836 $ENV{GIT_INDEX_FILE
} = shift;
2843 $ENV{GIT_INDEX_FILE
} = $old;
2845 delete $ENV{GIT_INDEX_FILE
};
2849 sub libsvn_commit_cb
{
2850 my ($rev, $date, $committer, $c, $msg, $r_last, $cmt_last) = @_;
2851 if ($_optimize_commits && $rev == ($r_last + 1)) {
2852 my $log = libsvn_log_entry
($rev,$committer,$date,$msg);
2853 $log->{tree
} = get_tree_from_treeish
($c);
2854 my $cmt = git_commit
($log, $cmt_last, $c);
2855 my @diff = safe_qx
('git-diff-tree', $cmt, $c);
2857 print STDERR
"Trees differ: $cmt $c\n",
2858 join('',@diff),"\n";
2866 sub libsvn_ls_fullurl
{
2867 my $fullurl = shift;
2868 my ($repo, $path) = repo_path_split
($fullurl);
2869 $SVN ||= libsvn_connect
($repo);
2871 my $pool = SVN
::Pool
->new;
2872 my ($dirent, undef, undef) = $SVN->get_dir($path,
2873 $SVN->get_latest_revnum, $pool);
2874 foreach my $d (keys %$dirent) {
2875 if ($dirent->{$d}->kind == $SVN::Node
::dir
) {
2876 push @ret, "$d/"; # add '/' for compat with cli svn
2884 sub libsvn_skip_unknown_revs
{
2886 my $errno = $err->apr_err();
2887 # Maybe the branch we're tracking didn't
2888 # exist when the repo started, so it's
2889 # not an error if it doesn't, just continue
2891 # Wonderfully consistent library, eh?
2892 # 160013 - svn:// and file://
2893 # 175002 - http(s)://
2894 # More codes may be discovered later...
2895 if ($errno == 175002 || $errno == 160013) {
2898 croak
"Error from SVN, ($errno): ", $err->expanded_message,"\n";
2901 # Tie::File seems to be prone to offset errors if revisions get sparse,
2902 # it's not that fast, either. Tie::File is also not in Perl 5.6. So
2903 # one of my favorite modules is out :< Next up would be one of the DBM
2904 # modules, but I'm not sure which is most portable... So I'll just
2905 # go with something that's plain-text, but still capable of
2906 # being randomly accessed. So here's my ultra-simple fixed-width
2907 # database. All records are 40 characters + "\n", so it's easy to seek
2908 # to a revision: (41 * rev) is the byte offset.
2909 # A record of 40 0s denotes an empty revision.
2910 # And yes, it's still pretty fast (faster than Tie::File).
2912 my ($file, $rev, $commit) = @_;
2913 length $commit == 40 or croak
"arg3 must be a full SHA1 hexsum\n";
2914 open my $fh, '+<', $file or croak
$!;
2915 my $offset = $rev * 41;
2916 # assume that append is the common case:
2917 seek $fh, 0, 2 or croak
$!;
2919 if ($pos < $offset) {
2920 print $fh (('0' x
40),"\n") x
(($offset - $pos) / 41);
2922 seek $fh, $offset, 0 or croak
$!;
2923 print $fh $commit,"\n";
2924 close $fh or croak
$!;
2928 my ($file, $rev) = @_;
2930 my $offset = $rev * 41;
2931 open my $fh, '<', $file or croak
$!;
2932 seek $fh, $offset, 0;
2933 if (tell $fh == $offset) {
2934 $ret = readline $fh;
2937 $ret = undef if ($ret =~ /^0{40}$/);
2940 close $fh or croak
$!;
2944 sub copy_remote_ref
{
2945 my $origin = $_cp_remote ?
$_cp_remote : 'origin';
2946 my $ref = "refs/remotes/$GIT_SVN";
2947 if (safe_qx
('git-ls-remote', $origin, $ref)) {
2948 sys
(qw
/git fetch/, $origin, "$ref:$ref");
2950 die "Unable to find remote reference: ",
2951 "refs/remotes/$GIT_SVN on $origin\n";
2955 package SVN
::Git
::Editor
;
2964 my $git_svn = shift;
2965 my $self = SVN
::Delta
::Editor
->new(@_);
2966 bless $self, $class;
2967 foreach (qw
/svn_path c r ra /) {
2968 die "$_ required!\n" unless (defined $git_svn->{$_});
2969 $self->{$_} = $git_svn->{$_};
2971 $self->{pool
} = SVN
::Pool
->new;
2972 $self->{bat
} = { '' => $self->open_root($self->{r
}, $self->{pool
}) };
2974 require Digest
::MD5
;
2979 return ($_[0] =~ m
#^(.*?)/?([^/]+)$#);
2983 (defined $_[1] && length $_[1]) ?
"$_[0]->{svn_path}/$_[1]"
2988 my ($self, $path) = @_;
2989 $self->{ra
}->{url
} . '/' . $self->repo_path($path);
2994 my $rm = $self->{rm
};
2995 delete $rm->{''}; # we never delete the url we're tracking
2998 foreach (keys %$rm) {
2999 my @d = split m
#/#, $_;
3003 $c .= '/' . shift @d;
3007 delete $rm->{$self->{svn_path
}};
3008 delete $rm->{''}; # we never delete the url we're tracking
3011 defined(my $pid = open my $fh,'-|') or croak
$!;
3013 exec qw
/git-ls-tree --name-only -r -z/, $self->{c
} or croak
$!;
3016 my @svn_path = split m
#/#, $self->{svn_path};
3019 my @dn = (@svn_path, (split m
#/#, $_));
3021 delete $rm->{join '/', @dn};
3030 my ($r, $p, $bat) = ($self->{r
}, $self->{pool
}, $self->{bat
});
3031 foreach my $d (sort { $b =~ tr
#/#/# <=> $a =~ tr#/#/# } keys %$rm) {
3032 $self->close_directory($bat->{$d}, $p);
3033 my ($dn) = ($d =~ m
#^(.*?)/?(?:[^/]+)$#);
3034 $self->SUPER::delete_entry
($d, $r, $bat->{$dn}, $p);
3039 sub open_or_add_dir
{
3040 my ($self, $full_path, $baton) = @_;
3041 my $p = SVN
::Pool
->new;
3042 my $t = $self->{ra
}->check_path($full_path, $self->{r
}, $p);
3044 if ($t == $SVN::Node
::none
) {
3045 return $self->add_directory($full_path, $baton,
3046 undef, -1, $self->{pool
});
3047 } elsif ($t == $SVN::Node
::dir
) {
3048 return $self->open_directory($full_path, $baton,
3049 $self->{r
}, $self->{pool
});
3051 print STDERR
"$full_path already exists in repository at ",
3052 "r$self->{r} and it is not a directory (",
3053 ($t == $SVN::Node
::file ?
'file' : 'unknown'),"/$t)\n";
3058 my ($self, $path) = @_;
3059 my $bat = $self->{bat
};
3060 $path = $self->repo_path($path);
3061 return $bat->{''} unless (length $path);
3062 my @p = split m
#/+#, $path;
3064 $bat->{$c} ||= $self->open_or_add_dir($c, $bat->{''});
3067 $c .= '/' . shift @p;
3068 $bat->{$c} ||= $self->open_or_add_dir($c, $bat->{$c0});
3074 my ($self, $m) = @_;
3075 my ($dir, $file) = split_path
($m->{file_b
});
3076 my $pbat = $self->ensure_path($dir);
3077 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
3079 $self->chg_file($fbat, $m);
3080 $self->close_file($fbat,undef,$self->{pool
});
3084 my ($self, $m) = @_;
3085 my ($dir, $file) = split_path
($m->{file_b
});
3086 my $pbat = $self->ensure_path($dir);
3087 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
3088 $self->url_path($m->{file_a
}), $self->{r
});
3089 $self->chg_file($fbat, $m);
3090 $self->close_file($fbat,undef,$self->{pool
});
3094 my ($self, $path, $pbat) = @_;
3095 my $rpath = $self->repo_path($path);
3096 my ($dir, $file) = split_path
($rpath);
3097 $self->{rm
}->{$dir} = 1;
3098 $self->SUPER::delete_entry
($rpath, $self->{r
}, $pbat, $self->{pool
});
3102 my ($self, $m) = @_;
3103 my ($dir, $file) = split_path
($m->{file_b
});
3104 my $pbat = $self->ensure_path($dir);
3105 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
3106 $self->url_path($m->{file_a
}), $self->{r
});
3107 $self->chg_file($fbat, $m);
3108 $self->close_file($fbat,undef,$self->{pool
});
3110 ($dir, $file) = split_path
($m->{file_a
});
3111 $pbat = $self->ensure_path($dir);
3112 $self->delete_entry($m->{file_a
}, $pbat);
3116 my ($self, $m) = @_;
3117 my ($dir, $file) = split_path
($m->{file_b
});
3118 my $pbat = $self->ensure_path($dir);
3119 my $fbat = $self->open_file($self->repo_path($m->{file_b
}),
3120 $pbat,$self->{r
},$self->{pool
});
3121 $self->chg_file($fbat, $m);
3122 $self->close_file($fbat,undef,$self->{pool
});
3125 sub T
{ shift->M(@_) }
3127 sub change_file_prop
{
3128 my ($self, $fbat, $pname, $pval) = @_;
3129 $self->SUPER::change_file_prop
($fbat, $pname, $pval, $self->{pool
});
3133 my ($self, $fbat, $m) = @_;
3134 if ($m->{mode_b
} =~ /755$/ && $m->{mode_a
} !~ /755$/) {
3135 $self->change_file_prop($fbat,'svn:executable','*');
3136 } elsif ($m->{mode_b
} !~ /755$/ && $m->{mode_a
} =~ /755$/) {
3137 $self->change_file_prop($fbat,'svn:executable',undef);
3139 my $fh = IO
::File
->new_tmpfile or croak
$!;
3140 if ($m->{mode_b
} =~ /^120/) {
3141 print $fh 'link ' or croak
$!;
3142 $self->change_file_prop($fbat,'svn:special','*');
3143 } elsif ($m->{mode_a
} =~ /^120/ && $m->{mode_b
} !~ /^120/) {
3144 $self->change_file_prop($fbat,'svn:special',undef);
3146 defined(my $pid = fork) or croak
$!;
3148 open STDOUT
, '>&', $fh or croak
$!;
3149 exec qw
/git-cat-file blob/, $m->{sha1_b
} or croak
$!;
3153 $fh->flush == 0 or croak
$!;
3154 seek $fh, 0, 0 or croak
$!;
3156 my $md5 = Digest
::MD5
->new;
3157 $md5->addfile($fh) or croak
$!;
3158 seek $fh, 0, 0 or croak
$!;
3160 my $exp = $md5->hexdigest;
3161 my $atd = $self->apply_textdelta($fbat, undef, $self->{pool
});
3162 my $got = SVN
::TxDelta
::send_stream
($fh, @
$atd, $self->{pool
});
3163 die "Checksum mismatch\nexpected: $exp\ngot: $got\n" if ($got ne $exp);
3165 close $fh or croak
$!;
3169 my ($self, $m) = @_;
3170 my ($dir, $file) = split_path
($m->{file_b
});
3171 my $pbat = $self->ensure_path($dir);
3172 $self->delete_entry($m->{file_b
}, $pbat);
3177 my ($p,$bat) = ($self->{pool
}, $self->{bat
});
3178 foreach (sort { $b =~ tr
#/#/# <=> $a =~ tr#/#/# } keys %$bat) {
3179 $self->close_directory($bat->{$_}, $p);
3181 $self->SUPER::close_edit
($p);
3187 $self->SUPER::abort_edit
($self->{pool
});
3188 $self->{pool
}->clear;
3195 $svn_log hashref
(as returned by svn_log_raw
)
3197 fh
=> file handle of the
log file
,
3198 state => state of the
log file parser
(sep
/msg/rev
/msg_start
...)
3201 $log_msg hashref as returned by next_log_entry
($svn_log)
3203 msg
=> 'whitespace-formatted log entry
3204 ', # trailing newline is preserved
3205 revision
=> '8', # integer
3206 date
=> '2004-02-24T17:01:44.108345Z', # commit date
3207 author
=> 'committer name'
3211 @mods = array of diff
-index line hashes
, each element represents one line
3212 of diff
-index output
3214 diff
-index line
($m hash
)
3216 mode_a
=> first column of diff
-index output
, no leading
':',
3217 mode_b
=> second column of diff
-index output
,
3218 sha1_b
=> sha1sum of the final blob
,
3219 chg
=> change type
[MCRADT
],
3220 file_a
=> original file name of a file
(iff chg is
'C' or 'R')
3221 file_b
=> new
/current file name of a file
(any chg
)
3226 I don
't trust the each() function on unless I created %hash myself
3227 because the internal iterator may not have started at base.