2 # Copyright (C) 2006, Eric Wong <normalperson@yhbt.net>
3 # License: GPL v2 or later
7 use vars qw
/ $AUTHOR $VERSION
8 $sha1 $sha1_short $_revision $_repository
9 $_q $_authors $_authors_prog %users/;
10 $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
11 $VERSION = '@@GIT_VERSION@@';
13 # From which subdir have we been invoked?
14 my $cmd_dir_prefix = eval {
15 command_oneline
([qw
/rev-parse --show-prefix/], STDERR
=> 0)
18 my $git_dir_user_set = 1 if defined $ENV{GIT_DIR
};
19 $ENV{GIT_DIR
} ||= '.git';
20 $Git::SVN
::default_repo_id
= 'svn';
21 $Git::SVN
::default_ref_id
= $ENV{GIT_SVN_ID
} || 'git-svn';
22 $Git::SVN
::Ra
::_log_window_size
= 100;
23 $Git::SVN
::_minimize_url
= 'unset';
25 if (! exists $ENV{SVN_SSH
}) {
26 if (exists $ENV{GIT_SSH
}) {
27 $ENV{SVN_SSH
} = $ENV{GIT_SSH
};
29 $ENV{SVN_SSH
} =~ s/\\/\\\\/g;
30 $ENV{SVN_SSH
} =~ s/(.*)/"$1"/;
35 $Git::SVN
::Log
::TZ
= $ENV{TZ
};
37 $| = 1; # unbuffer STDOUT
39 sub fatal
(@
) { print STDERR
"@_\n"; exit 1 }
41 require SVN
::Core
; # use()-ing this causes segfaults for me... *shrug*
44 if ($SVN::Core
::VERSION
lt '1.1.0') {
45 fatal
"Need SVN::Core 1.1.0 or better (got $SVN::Core::VERSION)";
48 my $can_compress = eval { require Compress
::Zlib
; 1};
49 push @Git::SVN
::Ra
::ISA
, 'SVN::Ra';
50 push @SVN::Git
::Editor
::ISA
, 'SVN::Delta::Editor';
51 push @SVN::Git
::Fetcher
::ISA
, 'SVN::Delta::Editor';
55 use File
::Basename qw
/dirname basename/;
56 use File
::Path qw
/mkpath/;
59 use Getopt
::Long qw
/:config gnu_getopt no_ignore_case auto_abbrev/;
62 use Memoize
; # core since 5.8.0, Jul 2002
65 # import functions from Git into our packages, en masse
67 foreach (qw
/command command_oneline command_noisy command_output_pipe
68 command_input_pipe command_close_pipe
69 command_bidi_pipe command_close_bidi_pipe
/) {
70 for my $package ( qw(SVN::Git::Editor SVN::Git::Fetcher
71 Git::SVN::Migration Git::SVN::Log Git::SVN),
73 *{"${package}::$_"} = \
&{"Git::$_"};
76 Memoize
::memoize
'Git::config';
77 Memoize
::memoize
'Git::config_bool';
82 $sha1 = qr/[a-f\d]{40}/;
83 $sha1_short = qr/[a-f\d]{4,40}/;
84 my ($_stdin, $_help, $_edit,
85 $_message, $_file, $_branch_dest,
87 $_version, $_fetch_all, $_no_rebase, $_fetch_parent,
88 $_merge, $_strategy, $_dry_run, $_local,
89 $_prefix, $_no_checkout, $_url, $_verbose,
90 $_git_format, $_commit_url, $_tag, $_merge_info, $_interactive);
91 $Git::SVN
::_follow_parent
= 1;
92 $SVN::Git
::Fetcher
::_placeholder_filename
= ".gitignore";
94 my %remote_opts = ( 'username=s' => \
$Git::SVN
::Prompt
::_username
,
95 'config-dir=s' => \
$Git::SVN
::Ra
::config_dir
,
96 'no-auth-cache' => \
$Git::SVN
::Prompt
::_no_auth_cache
,
97 'ignore-paths=s' => \
$SVN::Git
::Fetcher
::_ignore_regex
);
98 my %fc_opts = ( 'follow-parent|follow!' => \
$Git::SVN
::_follow_parent
,
99 'authors-file|A=s' => \
$_authors,
100 'authors-prog=s' => \
$_authors_prog,
101 'repack:i' => \
$Git::SVN
::_repack
,
102 'noMetadata' => \
$Git::SVN
::_no_metadata
,
103 'useSvmProps' => \
$Git::SVN
::_use_svm_props
,
104 'useSvnsyncProps' => \
$Git::SVN
::_use_svnsync_props
,
105 'log-window-size=i' => \
$Git::SVN
::Ra
::_log_window_size
,
106 'no-checkout' => \
$_no_checkout,
108 'repack-flags|repack-args|repack-opts=s' =>
109 \
$Git::SVN
::_repack_flags
,
110 'use-log-author' => \
$Git::SVN
::_use_log_author
,
111 'add-author-from' => \
$Git::SVN
::_add_author_from
,
112 'localtime' => \
$Git::SVN
::_localtime
,
115 my ($_trunk, @_tags, @_branches, $_stdlayout);
117 my %init_opts = ( 'template=s' => \
$_template, 'shared:s' => \
$_shared,
118 'trunk|T=s' => \
$_trunk, 'tags|t=s@' => \
@_tags,
119 'branches|b=s@' => \
@_branches, 'prefix=s' => \
$_prefix,
120 'stdlayout|s' => \
$_stdlayout,
121 'minimize-url|m!' => \
$Git::SVN
::_minimize_url
,
122 'no-metadata' => sub { $icv{noMetadata
} = 1 },
123 'use-svm-props' => sub { $icv{useSvmProps
} = 1 },
124 'use-svnsync-props' => sub { $icv{useSvnsyncProps
} = 1 },
125 'rewrite-root=s' => sub { $icv{rewriteRoot
} = $_[1] },
126 'rewrite-uuid=s' => sub { $icv{rewriteUUID
} = $_[1] },
128 my %cmt_opts = ( 'edit|e' => \
$_edit,
129 'rmdir' => \
$SVN::Git
::Editor
::_rmdir
,
130 'find-copies-harder' => \
$SVN::Git
::Editor
::_find_copies_harder
,
131 'l=i' => \
$SVN::Git
::Editor
::_rename_limit
,
132 'copy-similarity|C=i'=> \
$SVN::Git
::Editor
::_cp_similarity
136 fetch
=> [ \
&cmd_fetch
, "Download new revisions from SVN",
137 { 'revision|r=s' => \
$_revision,
138 'fetch-all|all' => \
$_fetch_all,
139 'parent|p' => \
$_fetch_parent,
141 clone
=> [ \
&cmd_clone
, "Initialize and fetch revisions",
142 { 'revision|r=s' => \
$_revision,
143 'preserve-empty-dirs' =>
144 \
$SVN::Git
::Fetcher
::_preserve_empty_dirs
,
145 'placeholder-filename=s' =>
146 \
$SVN::Git
::Fetcher
::_placeholder_filename
,
147 %fc_opts, %init_opts } ],
148 init
=> [ \
&cmd_init
, "Initialize a repo for tracking" .
149 " (requires URL argument)",
151 'multi-init' => [ \
&cmd_multi_init
,
152 "Deprecated alias for ".
153 "'$0 init -T<trunk> -b<branches> -t<tags>'",
155 dcommit
=> [ \
&cmd_dcommit
,
156 'Commit several diffs to merge with upstream',
157 { 'merge|m|M' => \
$_merge,
158 'strategy|s=s' => \
$_strategy,
159 'verbose|v' => \
$_verbose,
160 'dry-run|n' => \
$_dry_run,
161 'fetch-all|all' => \
$_fetch_all,
162 'commit-url=s' => \
$_commit_url,
163 'revision|r=i' => \
$_revision,
164 'no-rebase' => \
$_no_rebase,
165 'mergeinfo=s' => \
$_merge_info,
166 'interactive|i' => \
$_interactive,
167 %cmt_opts, %fc_opts } ],
168 branch
=> [ \
&cmd_branch
,
169 'Create a branch in the SVN repository',
170 { 'message|m=s' => \
$_message,
171 'destination|d=s' => \
$_branch_dest,
172 'dry-run|n' => \
$_dry_run,
174 'username=s' => \
$Git::SVN
::Prompt
::_username
,
175 'commit-url=s' => \
$_commit_url } ],
176 tag
=> [ sub { $_tag = 1; cmd_branch
(@_) },
177 'Create a tag in the SVN repository',
178 { 'message|m=s' => \
$_message,
179 'destination|d=s' => \
$_branch_dest,
180 'dry-run|n' => \
$_dry_run,
181 'username=s' => \
$Git::SVN
::Prompt
::_username
,
182 'commit-url=s' => \
$_commit_url } ],
183 'set-tree' => [ \
&cmd_set_tree
,
184 "Set an SVN repository to a git tree-ish",
185 { 'stdin' => \
$_stdin, %cmt_opts, %fc_opts, } ],
186 'create-ignore' => [ \
&cmd_create_ignore
,
187 'Create a .gitignore per svn:ignore',
188 { 'revision|r=i' => \
$_revision
190 'mkdirs' => [ \
&cmd_mkdirs
,
191 "recreate empty directories after a checkout",
192 { 'revision|r=i' => \
$_revision } ],
193 'propget' => [ \
&cmd_propget
,
194 'Print the value of a property on a file or directory',
195 { 'revision|r=i' => \
$_revision } ],
196 'proplist' => [ \
&cmd_proplist
,
197 'List all properties of a file or directory',
198 { 'revision|r=i' => \
$_revision } ],
199 'show-ignore' => [ \
&cmd_show_ignore
, "Show svn:ignore listings",
200 { 'revision|r=i' => \
$_revision
202 'show-externals' => [ \
&cmd_show_externals
, "Show svn:externals listings",
203 { 'revision|r=i' => \
$_revision
205 'multi-fetch' => [ \
&cmd_multi_fetch
,
206 "Deprecated alias for $0 fetch --all",
207 { 'revision|r=s' => \
$_revision, %fc_opts } ],
208 'migrate' => [ sub { },
209 # no-op, we automatically run this anyways,
210 'Migrate configuration/metadata/layout from
211 previous versions of git-svn',
212 { 'minimize' => \
$Git::SVN
::Migration
::_minimize
,
214 'log' => [ \
&Git
::SVN
::Log
::cmd_show_log
, 'Show commit logs',
215 { 'limit=i' => \
$Git::SVN
::Log
::limit
,
216 'revision|r=s' => \
$_revision,
217 'verbose|v' => \
$Git::SVN
::Log
::verbose
,
218 'incremental' => \
$Git::SVN
::Log
::incremental
,
219 'oneline' => \
$Git::SVN
::Log
::oneline
,
220 'show-commit' => \
$Git::SVN
::Log
::show_commit
,
221 'non-recursive' => \
$Git::SVN
::Log
::non_recursive
,
222 'authors-file|A=s' => \
$_authors,
223 'color' => \
$Git::SVN
::Log
::color
,
224 'pager=s' => \
$Git::SVN
::Log
::pager
226 'find-rev' => [ \
&cmd_find_rev
,
227 "Translate between SVN revision numbers and tree-ish",
229 'rebase' => [ \
&cmd_rebase
, "Fetch and rebase your working directory",
230 { 'merge|m|M' => \
$_merge,
231 'verbose|v' => \
$_verbose,
232 'strategy|s=s' => \
$_strategy,
233 'local|l' => \
$_local,
234 'fetch-all|all' => \
$_fetch_all,
235 'dry-run|n' => \
$_dry_run,
237 'commit-diff' => [ \
&cmd_commit_diff
,
238 'Commit a diff between two trees',
239 { 'message|m=s' => \
$_message,
240 'file|F=s' => \
$_file,
241 'revision|r=s' => \
$_revision,
243 'info' => [ \
&cmd_info
,
244 "Show info about the latest SVN revision
245 on the current branch",
246 { 'url' => \
$_url, } ],
247 'blame' => [ \
&Git
::SVN
::Log
::cmd_blame
,
248 "Show what revision and author last modified each line of a file",
249 { 'git-format' => \
$_git_format } ],
250 'reset' => [ \
&cmd_reset
,
251 "Undo fetches back to the specified SVN revision",
252 { 'revision|r=s' => \
$_revision,
253 'parent|p' => \
$_fetch_parent } ],
255 "Compress unhandled.log files in .git/svn and remove " .
256 "index files in .git/svn",
263 my ($class, $reason) = @_;
264 return bless \
$reason, shift;
268 die "Cannot use readline on FakeTerm: $$self";
273 $ENV{"GIT_SVN_NOTTY"}
274 ? new Term
::ReadLine
'git-svn', \
*STDIN
, \
*STDOUT
275 : new Term
::ReadLine
'git-svn';
278 $term = new FakeTerm
"$@: going non-interactive";
282 for (my $i = 0; $i < @ARGV; $i++) {
283 if (defined $cmd{$ARGV[$i]}) {
287 } elsif ($ARGV[$i] eq 'help') {
293 # make sure we're always running at the top-level working directory
294 unless ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) {
295 unless (-d
$ENV{GIT_DIR
}) {
296 if ($git_dir_user_set) {
297 die "GIT_DIR=$ENV{GIT_DIR} explicitly set, ",
298 "but it is not a directory\n";
300 my $git_dir = delete $ENV{GIT_DIR
};
303 $cdup = command_oneline
(qw
/rev-parse --show-cdup/);
304 $git_dir = '.' unless ($cdup);
305 chomp $cdup if ($cdup);
306 $cdup = "." unless ($cdup && length $cdup);
307 } "Already at toplevel, but $git_dir not found\n";
308 chdir $cdup or die "Unable to chdir up to '$cdup'\n";
309 unless (-d
$git_dir) {
310 die "$git_dir still not found after going to ",
313 $ENV{GIT_DIR
} = $git_dir;
315 $_repository = Git
->repository(Repository
=> $ENV{GIT_DIR
});
318 my %opts = %{$cmd{$cmd}->[2]} if (defined $cmd);
320 read_git_config
(\
%opts);
321 if ($cmd && ($cmd eq 'log' || $cmd eq 'blame')) {
322 Getopt
::Long
::Configure
('pass_through');
324 my $rv = GetOptions
(%opts, 'h|H' => \
$_help, 'version|V' => \
$_version,
325 'minimize-connections' => \
$Git::SVN
::Migration
::_minimize
,
326 'id|i=s' => \
$Git::SVN
::default_ref_id
,
327 'svn-remote|remote|R=s' => sub {
328 $Git::SVN
::no_reuse_existing
= 1;
329 $Git::SVN
::default_repo_id
= $_[1] });
330 exit 1 if (!$rv && $cmd && $cmd ne 'log');
333 version
() if $_version;
334 usage
(1) unless defined $cmd;
335 load_authors
() if $_authors;
336 if (defined $_authors_prog) {
337 $_authors_prog = "'" . File
::Spec
->rel2abs($_authors_prog) . "'";
340 unless ($cmd =~ /^(?:clone|init|multi-init|commit-diff)$/) {
341 Git
::SVN
::Migration
::migration_check
();
343 Git
::SVN
::init_vars
();
345 Git
::SVN
::verify_remotes_sanity
();
346 $cmd{$cmd}->[0]->(@ARGV);
349 post_fetch_checkout
();
352 ####################### primary functions ######################
354 my $exit = shift || 0;
355 my $fd = $exit ? \
*STDERR
: \
*STDOUT
;
357 git
-svn
- bidirectional operations between a single Subversion tree
and git
358 Usage
: git svn
<command
> [options
] [arguments
]\n
360 print $fd "Available commands:\n" unless $cmd;
362 foreach (sort keys %cmd) {
363 next if $cmd && $cmd ne $_;
364 next if /^multi-/; # don't show deprecated commands
365 print $fd ' ',pack('A17',$_),$cmd{$_}->[1],"\n";
366 foreach (sort keys %{$cmd{$_}->[2]}) {
367 # mixed-case options are for .git/config only
368 next if /[A-Z]/ && /^[a-z]+$/i;
369 # prints out arguments as they should be passed:
370 my $x = s
#[:=]s$## ? '<arg>' : s#[:=]i$## ? '<num>' : '';
371 print $fd ' ' x
21, join(', ', map { length $_ > 1 ?
373 split /\|/,$_)," $x\n";
377 \nGIT_SVN_ID may be set
in the environment
or via the
--id
/-i switch to an
378 arbitrary identifier
if you
're tracking multiple SVN branches/repositories in
379 one git repository and want to keep them separate. See git-svn(1) for more
387 print "git-svn version $VERSION (svn $SVN::Core::VERSION)\n";
392 my ($prompt, %arg) = @_;
393 my $valid_re = $arg{valid_re};
394 my $default = $arg{default};
398 if ( !( defined($term->IN)
399 && defined( fileno($term->IN) )
400 && defined( $term->OUT )
401 && defined( fileno($term->OUT) ) ) ){
402 return defined($default) ? $default : undef;
406 $resp = $term->readline($prompt);
407 if (!defined $resp) { # EOF
409 return defined $default ? $default : undef;
411 if ($resp eq '' and defined $default) {
414 if (!defined $valid_re or $resp =~ /$valid_re/) {
422 unless (-d $ENV{GIT_DIR}) {
423 my @init_db = ('init
');
424 push @init_db, "--template=$_template" if defined $_template;
425 if (defined $_shared) {
426 if ($_shared =~ /[a-z]/) {
427 push @init_db, "--shared=$_shared";
429 push @init_db, "--shared";
432 command_noisy(@init_db);
433 $_repository = Git->repository(Repository => ".git");
436 my $pfx = "svn-remote.$Git::SVN::default_repo_id";
437 foreach my $i (keys %icv) {
438 die "'$set' and '$i' cannot both be set\n" if $set;
439 next unless defined $icv{$i};
440 command_noisy('config
', "$pfx.$i", $icv{$i});
443 my $ignore_regex = \$SVN::Git::Fetcher::_ignore_regex;
444 command_noisy('config
', "$pfx.ignore-paths", $$ignore_regex)
445 if defined $$ignore_regex;
447 if (defined $SVN::Git::Fetcher::_preserve_empty_dirs) {
448 my $fname = \$SVN::Git::Fetcher::_placeholder_filename;
449 command_noisy('config
', "$pfx.preserve-empty-dirs", 'true
');
450 command_noisy('config
', "$pfx.placeholder-filename", $$fname);
455 my $repo_path = shift or return;
456 mkpath([$repo_path]) unless -d $repo_path;
457 chdir $repo_path or die "Couldn't
chdir to
$repo_path: $!\n";
458 $ENV{GIT_DIR} = '.git';
459 $_repository = Git->repository(Repository => $ENV{GIT_DIR});
463 my ($url, $path) = @_;
464 if (!defined $path &&
465 (defined $_trunk || @_branches || @_tags ||
466 defined $_stdlayout) &&
467 $url !~ m#^[a-z\+]+://#) {
470 $path = basename($url) if !defined $path || !length $path;
471 my $authors_absolute = $_authors ? File::Spec->rel2abs($_authors) : "";
472 cmd_init($url, $path);
473 command_oneline('config', 'svn.authorsfile', $authors_absolute)
475 Git::SVN::fetch_all($Git::SVN::default_repo_id);
479 if (defined $_stdlayout) {
480 $_trunk = 'trunk' if (!defined $_trunk);
481 @_tags = 'tags' if (! @_tags);
482 @_branches = 'branches' if (! @_branches);
484 if (defined $_trunk || @_branches || @_tags) {
485 return cmd_multi_init(@_);
487 my $url = shift or die "SVN repository location required
",
488 "as a command
-line argument
\n";
489 $url = canonicalize_url($url);
493 if ($Git::SVN::_minimize_url eq 'unset') {
494 $Git::SVN::_minimize_url = 0;
497 Git::SVN->init($url);
501 if (grep /^\d+=./, @_) {
502 die "'<rev>=<commit>' fetch arguments are
",
503 "no longer supported
.\n";
507 die "Usage
: $0 fetch
[--all
] [--parent
] [svn
-remote
]\n";
509 $Git::SVN::no_reuse_existing = undef;
510 if ($_fetch_parent) {
511 my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
513 die "Unable to determine upstream SVN information from
",
514 "working tree history
\n";
516 # just fetch, don't checkout.
517 $_no_checkout = 'true';
518 $_fetch_all ? $gs->fetch_all : $gs->fetch;
519 } elsif ($_fetch_all) {
522 $remote ||= $Git::SVN::default_repo_id;
523 Git::SVN::fetch_all($remote, Git::SVN::read_all_remotes());
529 if ($_stdin || !@commits) {
530 print "Reading from stdin
...\n";
533 if (/\b($sha1_short)\b/o) {
534 unshift @commits, $1;
539 foreach my $c (@commits) {
540 my @tmp = command('rev-parse',$c);
541 if (scalar @tmp == 1) {
543 } elsif (scalar @tmp > 1) {
544 push @revs, reverse(command('rev-list',@tmp));
546 fatal "Failed to rev
-parse
$c";
549 my $gs = Git::SVN->new;
550 my ($r_last, $cmt_last) = $gs->last_rev_commit;
552 if (defined $gs->{last_rev} && $r_last != $gs->{last_rev}) {
553 fatal "There are new revisions that were fetched
",
554 "and need to be merged
(or acknowledged
) ",
555 "before committing
.\nlast rev
: $r_last\n",
556 " current
: $gs->{last_rev
}";
558 $gs->set_tree($_) foreach @revs;
559 print "Done committing
",scalar @revs," revisions to SVN
\n";
563 sub split_merge_info_range {
565 if ($range =~ /(\d+)-(\d+)/) {
566 return (int($1), int($2));
568 return (int($range), int($range));
576 my @arr = split(/,/, $in);
577 for my $element (@arr) {
578 my ($start, $end) = split_merge_info_range($element);
582 my @sorted = @arr [ sort {
583 $fnums[$a] <=> $fnums[$b]
589 for my $element (@sorted) {
590 my ($start, $end) = split_merge_info_range($element);
597 if ($start <= $last+1) {
603 if ($first == $last) {
604 push @return, "$first";
606 push @return, "$first-$last";
613 if ($first == $last) {
614 push @return, "$first";
616 push @return, "$first-$last";
620 return join(',', @return);
623 sub merge_revs_into_hash {
624 my ($hash, $minfo) = @_;
625 my @lines = split(' ', $minfo);
627 for my $line (@lines) {
628 my ($branchpath, $revs) = split(/:/, $line);
630 if (exists($hash->{$branchpath})) {
631 # Merge the two revision sets
632 my $combined = "$hash->{$branchpath},$revs";
633 $hash->{$branchpath} = combine_ranges($combined);
635 # Just do range combining for consolidation
636 $hash->{$branchpath} = combine_ranges($revs);
641 sub merge_merge_info {
642 my ($mergeinfo_one, $mergeinfo_two) = @_;
643 my %result_hash = ();
645 merge_revs_into_hash(\%result_hash, $mergeinfo_one);
646 merge_revs_into_hash(\%result_hash, $mergeinfo_two);
649 # Sort below is for consistency's sake
650 for my $branchname (sort keys(%result_hash)) {
651 my $revlist = $result_hash{$branchname};
652 $result .= "$branchname:$revlist\n"
657 sub populate_merge_info {
658 my ($d, $gs, $uuid, $linear_refs, $rewritten_parent) = @_;
661 read_commit_parents(\%parentshash, $d);
662 my @parents = @{$parentshash{$d}};
665 my $all_parents_ok = 1;
666 my $aggregate_mergeinfo = '';
667 my $rooturl = $gs->repos_root;
669 if (defined($rewritten_parent)) {
670 # Replace first parent with newly-rewritten version
672 unshift @parents, $rewritten_parent;
675 foreach my $parent (@parents) {
676 my ($branchurl, $svnrev, $paruuid) =
677 cmt_metadata($parent);
679 unless (defined($svnrev)) {
680 # Should have been caught be preflight check
681 fatal "merge commit
$d has ancestor
$parent, but that change
"
682 ."does
not have git
-svn metadata
!";
684 unless ($branchurl =~ /^$rooturl(.*)/) {
685 fatal "commit
$parent git
-svn metadata changed mid
-run
!";
689 my $ra = Git::SVN::Ra->new($branchurl);
690 my (undef, undef, $props) =
691 $ra->get_dir(canonicalize_path("."), $svnrev);
692 my $par_mergeinfo = $props->{'svn:mergeinfo'};
693 unless (defined $par_mergeinfo) {
696 # Merge previous mergeinfo values
697 $aggregate_mergeinfo =
698 merge_merge_info($aggregate_mergeinfo,
701 next if $parent eq $parents[0]; # Skip first parent
702 # Add new changes being placed in tree by merge
703 my @cmd = (qw/rev-list --reverse/,
705 foreach my $par (@parents) {
706 unless ($par eq $parent) {
711 my ($revlist, $ctx) = command_output_pipe(@cmd);
715 my (undef, $csvnrev, undef) =
717 unless (defined $csvnrev) {
718 # A child is missing SVN annotations...
719 # this might be OK, or might not be.
720 warn "W
:child
$irev is merged into revision
"
721 ."$d but does
not have git
-svn metadata
. "
722 ."This means git
-svn cannot determine the
"
723 ."svn revision numbers to place into the
"
724 ."svn
:mergeinfo property
. You must ensure
"
725 ."a branch is entirely committed to
"
726 ."SVN before merging it
in order
for "
727 ."svn
:mergeinfo population to function
"
730 push @revsin, $csvnrev;
732 command_close_pipe($revlist, $ctx);
734 last unless $all_parents_ok;
736 # We now have a list of all SVN revnos which are
737 # merged by this particular parent. Integrate them.
738 next if $#revsin == -1;
739 my $newmergeinfo = "$branchpath:" . join(',', @revsin);
740 $aggregate_mergeinfo =
741 merge_merge_info($aggregate_mergeinfo,
744 if ($all_parents_ok and $aggregate_mergeinfo) {
745 return $aggregate_mergeinfo;
754 command_noisy(qw/update-index --refresh/);
755 git_cmd_try { command_oneline(qw/diff-index --quiet HEAD/) }
756 'Cannot dcommit with a dirty index. Commit your changes first, '
757 . "or stash them with
`git stash'.\n";
761 if ($head ne 'HEAD') {
763 command_oneline([qw/symbolic-ref -q HEAD/])
766 $old_head =~ s{^refs/heads/}{};
768 $old_head = eval { command_oneline(qw/rev-parse HEAD/) };
770 command(['checkout', $head], STDERR => 0);
774 my ($url, $rev, $uuid, $gs) = working_head_info('HEAD', \@refs);
776 die "Unable to determine upstream SVN information from ",
777 "$head history.\nPerhaps the repository is empty.";
780 if (defined $_commit_url) {
783 $url = eval { command_oneline('config', '--get',
784 "svn-remote.$gs->{repo_id}.commiturl") };
786 $url = $gs->full_pushurl
790 my $last_rev = $_revision if defined $_revision;
792 print "Committing to $url ...\n";
794 my ($linear_refs, $parents) = linearize_history($gs, \@refs);
795 if ($_no_rebase && scalar(@$linear_refs) > 1) {
796 warn "Attempting to commit more than one change while ",
797 "--no-rebase is enabled.\n",
798 "If these changes depend on each other, re-running ",
799 "without --no-rebase may be required."
802 if (defined $_interactive){
803 my $ask_default = "y";
804 foreach my $d (@$linear_refs){
805 my ($fh, $ctx) = command_output_pipe(qw(show --summary), "$d");
809 command_close_pipe
($fh, $ctx);
810 $_ = ask
("Commit this patch to SVN? ([y]es (default)|[n]o|[q]uit|[a]ll): ",
811 valid_re
=> qr/^(?:yes|y|no|n|quit|q|all|a)/i,
812 default => $ask_default);
813 die "Commit this patch reply required" unless defined $_;
822 my $expect_url = $url;
824 my $push_merge_info = eval {
825 command_oneline
(qw
/config --get svn.pushmergeinfo/)
827 if (not defined($push_merge_info)
828 or $push_merge_info eq "false"
829 or $push_merge_info eq "no"
830 or $push_merge_info eq "never") {
831 $push_merge_info = 0;
834 unless (defined($_merge_info) || ! $push_merge_info) {
835 # Preflight check of changes to ensure no issues with mergeinfo
836 # This includes check for uncommitted-to-SVN parents
837 # (other than the first parent, which we will handle),
838 # information from different SVN repos, and paths
839 # which are not underneath this repository root.
840 my $rooturl = $gs->repos_root;
841 foreach my $d (@
$linear_refs) {
843 read_commit_parents
(\
%parentshash, $d);
844 my @realparents = @
{$parentshash{$d}};
845 if ($#realparents > 0) {
847 shift @realparents; # Remove/ignore first parent
848 foreach my $parent (@realparents) {
849 my ($branchurl, $svnrev, $paruuid) = cmt_metadata
($parent);
850 unless (defined $paruuid) {
851 # A parent is missing SVN annotations...
852 # abort the whole operation.
853 fatal
"$parent is merged into revision $d, "
854 ."but does not have git-svn metadata. "
855 ."Either dcommit the branch or use a "
856 ."local cherry-pick, FF merge, or rebase "
857 ."instead of an explicit merge commit.";
860 unless ($paruuid eq $uuid) {
861 # Parent has SVN metadata from different repository
862 fatal
"merge parent $parent for change $d has "
863 ."git-svn uuid $paruuid, while current change "
867 unless ($branchurl =~ /^$rooturl(.*)/) {
868 # This branch is very strange indeed.
869 fatal
"merge parent $parent for $d is on branch "
870 ."$branchurl, which is not under the "
871 ."git-svn root $rooturl!";
878 my $rewritten_parent;
879 Git
::SVN
::remove_username
($expect_url);
880 if (defined($_merge_info)) {
881 $_merge_info =~ tr{ }{\n};
884 my $d = shift @
$linear_refs or last;
885 unless (defined $last_rev) {
886 (undef, $last_rev, undef) = cmt_metadata
("$d~1");
887 unless (defined $last_rev) {
888 fatal
"Unable to extract revision information ",
893 print "diff-tree $d~1 $d\n";
897 unless (defined($_merge_info) || ! $push_merge_info) {
898 $_merge_info = populate_merge_info
($d, $gs,
904 my %ed_opts = ( r
=> $last_rev,
905 log => get_commit_entry
($d)->{log},
906 ra
=> Git
::SVN
::Ra
->new($url),
907 config
=> SVN
::Core
::config_get_config
(
908 $Git::SVN
::Ra
::config_dir
913 print "Committed r$_[0]\n";
916 mergeinfo
=> $_merge_info,
918 if (!SVN
::Git
::Editor
->new(\
%ed_opts)->apply_diff) {
919 print "No changes\n$d~1 == $d\n";
920 } elsif ($parents->{$d} && @
{$parents->{$d}}) {
921 $gs->{inject_parents_dcommit
}->{$cmt_rev} =
924 $_fetch_all ?
$gs->fetch_all : $gs->fetch;
925 $last_rev = $cmt_rev;
928 # we always want to rebase against the current HEAD,
929 # not any head that was passed to us
930 my @diff = command
('diff-tree', $d,
934 @finish = rebase_cmd
();
935 print STDERR
"W: $d and ", $gs->refname,
936 " differ, using @finish:\n",
937 join("\n", @diff), "\n";
939 print "No changes between current HEAD and ",
941 "\nResetting to the latest ",
943 @finish = qw
/reset --mixed/;
945 command_noisy
(@finish, $gs->refname);
947 $rewritten_parent = command_oneline
(qw
/rev-parse HEAD/);
951 my ($url_, $rev_, $uuid_, $gs_) =
952 working_head_info
('HEAD', \
@refs);
953 my ($linear_refs_, $parents_) =
954 linearize_history
($gs_, \
@refs);
955 if (scalar(@
$linear_refs) !=
956 scalar(@
$linear_refs_)) {
957 fatal
"# of revisions changed ",
959 join("\n", @
$linear_refs),
961 join("\n", @
$linear_refs_), "\n",
962 'If you are attempting to commit ',
963 "merges, try running:\n\t",
964 'git rebase --interactive',
965 '--preserve-merges ',
967 "\nBefore dcommitting";
969 if ($url_ ne $expect_url) {
970 if ($url_ eq $gs->metadata_url) {
972 "Accepting rewritten URL:",
976 "URL mismatch after rebase:",
977 " $url_ != $expect_url";
980 if ($uuid_ ne $uuid) {
981 fatal
"uuid mismatch after rebase: ",
986 for ($i = 0; $i < scalar @
$linear_refs; $i++) {
987 my $new = $linear_refs_->[$i] or next;
989 $parents->{$linear_refs->[$i]};
999 my $new_head = command_oneline
(qw
/rev-parse HEAD/);
1000 my $new_is_symbolic = eval {
1001 command_oneline
(qw
/symbolic-ref -q HEAD/);
1003 if ($new_is_symbolic) {
1004 print "dcommitted the branch ", $head, "\n";
1006 print "dcommitted on a detached HEAD because you gave ",
1007 "a revision argument.\n",
1008 "The rewritten commit is: ", $new_head, "\n";
1010 command
(['checkout', $old_head], STDERR
=> 0);
1013 unlink $gs->{index};
1017 my ($branch_name, $head) = @_;
1019 unless (defined $branch_name && length $branch_name) {
1020 die(($_tag ?
"tag" : "branch") . " name required\n");
1024 my (undef, $rev, undef, $gs) = working_head_info
($head);
1025 my $src = $gs->full_pushurl;
1027 my $remote = Git
::SVN
::read_all_remotes
()->{$gs->{repo_id
}};
1028 my $allglobs = $remote->{ $_tag ?
'tags' : 'branches' };
1030 if ($#{$allglobs} == 0) {
1031 $glob = $allglobs->[0];
1033 unless(defined $_branch_dest) {
1035 $_tag ?
"tag" : "branch",
1036 " paths defined for Subversion repository.\n",
1037 "You must specify where you want to create the ",
1038 $_tag ?
"tag" : "branch",
1039 " with the --destination argument.\n";
1041 foreach my $g (@
{$allglobs}) {
1042 # SVN::Git::Editor could probably be moved to Git.pm..
1043 my $re = SVN
::Git
::Editor
::glob2pat
($g->{path
}->{left
});
1044 if ($_branch_dest =~ /$re/) {
1049 unless (defined $glob) {
1050 my $dest_re = qr/\b\Q$_branch_dest\E\b/;
1051 foreach my $g (@
{$allglobs}) {
1052 $g->{path
}->{left
} =~ /$dest_re/ or next;
1053 if (defined $glob) {
1054 die "Ambiguous destination: ",
1055 $_branch_dest, "\nmatches both '",
1056 $glob->{path
}->{left
}, "' and '",
1057 $g->{path
}->{left
}, "'\n";
1061 unless (defined $glob) {
1063 $_tag ?
"tag" : "branch",
1064 " destination $_branch_dest\n";
1068 my ($lft, $rgt) = @
{ $glob->{path
} }{qw
/left right/};
1070 if (defined $_commit_url) {
1071 $url = $_commit_url;
1073 $url = eval { command_oneline
('config', '--get',
1074 "svn-remote.$gs->{repo_id}.commiturl") };
1076 $url = $remote->{pushurl
} || $remote->{url
};
1079 my $dst = join '/', $url, $lft, $branch_name, ($rgt || ());
1081 if ($dst =~ /^https:/ && $src =~ /^http:/) {
1082 $src=~s/^http:/https:/;
1087 my $ctx = SVN
::Client
->new(
1088 auth
=> Git
::SVN
::Ra
::_auth_providers
(),
1090 ${ $_[0] } = defined $_message
1092 : 'Create ' . ($_tag ?
'tag ' : 'branch ' )
1098 $ctx->ls($dst, 'HEAD', 0);
1099 } and die "branch ${branch_name} already exists\n";
1101 print "Copying ${src} at r${rev} to ${dst}...\n";
1102 $ctx->copy($src, $rev, $dst)
1109 my $revision_or_hash = shift or die "SVN or git revision required ",
1110 "as a command-line argument\n";
1112 if ($revision_or_hash =~ /^r\d+$/) {
1116 my (undef, undef, $uuid, $gs) = working_head_info
($head, \
@refs);
1118 die "Unable to determine upstream SVN information from ",
1121 my $desired_revision = substr($revision_or_hash, 1);
1122 $result = $gs->rev_map_get($desired_revision, $uuid);
1124 my (undef, $rev, undef) = cmt_metadata
($revision_or_hash);
1127 print "$result\n" if $result;
1130 sub auto_create_empty_directories
{
1132 my $var = eval { command_oneline
('config', '--get', '--bool',
1133 "svn-remote.$gs->{repo_id}.automkdirs") };
1134 # By default, create empty directories by consulting the unhandled log,
1135 # but allow setting it to 'false' to skip it.
1136 return !($var && $var eq 'false');
1140 command_noisy
(qw
/update-index --refresh/);
1141 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
1143 die "Unable to determine upstream SVN information from ",
1144 "working tree history\n";
1147 print "Remote Branch: " . $gs->refname . "\n";
1148 print "SVN URL: " . $url . "\n";
1151 if (command
(qw
/diff-index HEAD --/)) {
1152 print STDERR
"Cannot rebase with uncommited changes:\n";
1153 command_noisy
('status');
1157 # rebase will checkout for us, so no need to do it explicitly
1158 $_no_checkout = 'true';
1159 $_fetch_all ?
$gs->fetch_all : $gs->fetch;
1161 command_noisy
(rebase_cmd
(), $gs->refname);
1162 if (auto_create_empty_directories
($gs)) {
1167 sub cmd_show_ignore
{
1168 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
1169 $gs ||= Git
::SVN
->new;
1170 my $r = (defined $_revision ?
$_revision : $gs->ra->get_latest_revnum);
1171 $gs->prop_walk($gs->{path
}, $r, sub {
1172 my ($gs, $path, $props) = @_;
1173 print STDOUT
"\n# $path\n";
1174 my $s = $props->{'svn:ignore'} or return;
1175 $s =~ s/[\r\n]+/\n/g;
1179 print STDOUT
"$s\n";
1183 sub cmd_show_externals
{
1184 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
1185 $gs ||= Git
::SVN
->new;
1186 my $r = (defined $_revision ?
$_revision : $gs->ra->get_latest_revnum);
1187 $gs->prop_walk($gs->{path
}, $r, sub {
1188 my ($gs, $path, $props) = @_;
1189 print STDOUT
"\n# $path\n";
1190 my $s = $props->{'svn:externals'} or return;
1191 $s =~ s/[\r\n]+/\n/g;
1194 print STDOUT
"$s\n";
1198 sub cmd_create_ignore
{
1199 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
1200 $gs ||= Git
::SVN
->new;
1201 my $r = (defined $_revision ?
$_revision : $gs->ra->get_latest_revnum);
1202 $gs->prop_walk($gs->{path
}, $r, sub {
1203 my ($gs, $path, $props) = @_;
1204 # $path is of the form /path/to/dir/
1205 $path = '.' . $path;
1206 # SVN can have attributes on empty directories,
1207 # which git won't track
1208 mkpath
([$path]) unless -d
$path;
1209 my $ignore = $path . '.gitignore';
1210 my $s = $props->{'svn:ignore'} or return;
1211 open(GITIGNORE
, '>', $ignore)
1212 or fatal
("Failed to open `$ignore' for writing: $!");
1213 $s =~ s/[\r\n]+/\n/g;
1216 # Prefix all patterns so that the ignore doesn't apply
1217 # to sub-directories.
1219 print GITIGNORE
"$s\n";
1221 or fatal
("Failed to close `$ignore': $!");
1222 command_noisy
('add', '-f', $ignore);
1227 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
1228 $gs ||= Git
::SVN
->new;
1229 $gs->mkemptydirs($_revision);
1232 sub canonicalize_path
{
1234 my $dot_slash_added = 0;
1235 if (substr($path, 0, 1) ne "/") {
1236 $path = "./" . $path;
1237 $dot_slash_added = 1;
1239 # File::Spec->canonpath doesn't collapse x/../y into y (for a
1240 # good reason), so let's do this manually.
1242 $path =~ s
#/\.(?:/|$)#/#g;
1243 $path =~ s
#/[^/]+/\.\.##g;
1245 $path =~ s
#^\./## if $dot_slash_added;
1251 sub canonicalize_url
{
1253 $url =~ s
#^([^:]+://[^/]*/)(.*)$#$1 . canonicalize_path($2)#e;
1257 # get_svnprops(PATH)
1258 # ------------------
1259 # Helper for cmd_propget and cmd_proplist below.
1262 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
1263 $gs ||= Git
::SVN
->new;
1265 # prefix THE PATH by the sub-directory from which the user
1267 $path = $cmd_dir_prefix . $path;
1268 fatal
("No such file or directory: $path") unless -e
$path;
1269 my $is_dir = -d
$path ?
1 : 0;
1270 $path = $gs->{path
} . '/' . $path;
1272 # canonicalize the path (otherwise libsvn will abort or fail to
1274 $path = canonicalize_path
($path);
1276 my $r = (defined $_revision ?
$_revision : $gs->ra->get_latest_revnum);
1279 (undef, undef, $props) = $gs->ra->get_dir($path, $r);
1282 (undef, $props) = $gs->ra->get_file($path, $r, undef);
1287 # cmd_propget (PROP, PATH)
1288 # ------------------------
1289 # Print the SVN property PROP for PATH.
1291 my ($prop, $path) = @_;
1292 $path = '.' if not defined $path;
1293 usage
(1) if not defined $prop;
1294 my $props = get_svnprops
($path);
1295 if (not defined $props->{$prop}) {
1296 fatal
("`$path' does not have a `$prop' SVN property.");
1298 print $props->{$prop} . "\n";
1301 # cmd_proplist (PATH)
1302 # -------------------
1303 # Print the list of SVN properties for PATH.
1306 $path = '.' if not defined $path;
1307 my $props = get_svnprops
($path);
1308 print "Properties on '$path':\n";
1309 foreach (sort keys %{$props}) {
1314 sub cmd_multi_init
{
1316 unless (defined $_trunk || @_branches || @_tags) {
1320 $_prefix = '' unless defined $_prefix;
1322 $url = canonicalize_url
($url);
1326 if (defined $_trunk) {
1328 my $trunk_ref = 'refs/remotes/' . $_prefix . 'trunk';
1329 # try both old-style and new-style lookups:
1330 my $gs_trunk = eval { Git
::SVN
->new($trunk_ref) };
1331 unless ($gs_trunk) {
1332 my ($trunk_url, $trunk_path) =
1333 complete_svn_url
($url, $_trunk);
1334 $gs_trunk = Git
::SVN
->init($trunk_url, $trunk_path,
1338 return unless @_branches || @_tags;
1339 my $ra = $url ? Git
::SVN
::Ra
->new($url) : undef;
1340 foreach my $path (@_branches) {
1341 complete_url_ls_init
($ra, $path, '--branches/-b', $_prefix);
1343 foreach my $path (@_tags) {
1344 complete_url_ls_init
($ra, $path, '--tags/-t', $_prefix.'tags/');
1348 sub cmd_multi_fetch
{
1349 $Git::SVN
::no_reuse_existing
= undef;
1350 my $remotes = Git
::SVN
::read_all_remotes
();
1351 foreach my $repo_id (sort keys %$remotes) {
1352 if ($remotes->{$repo_id}->{url
}) {
1353 Git
::SVN
::fetch_all
($repo_id, $remotes);
1358 # this command is special because it requires no metadata
1359 sub cmd_commit_diff
{
1360 my ($ta, $tb, $url) = @_;
1361 my $usage = "Usage: $0 commit-diff -r<revision> ".
1362 "<tree-ish> <tree-ish> [<URL>]";
1363 fatal
($usage) if (!defined $ta || !defined $tb);
1365 if (!defined $url) {
1366 my $gs = eval { Git
::SVN
->new };
1368 fatal
("Needed URL or usable git-svn --id in ",
1369 "the command-line\n", $usage);
1372 $svn_path = $gs->{path
};
1374 unless (defined $_revision) {
1375 fatal
("-r|--revision is a required argument\n", $usage);
1377 if (defined $_message && defined $_file) {
1378 fatal
("Both --message/-m and --file/-F specified ",
1379 "for the commit message.\n",
1380 "I have no idea what you mean");
1382 if (defined $_file) {
1383 $_message = file_to_s
($_file);
1385 $_message ||= get_commit_entry
($tb)->{log};
1387 my $ra ||= Git
::SVN
::Ra
->new($url);
1390 $r = $ra->get_latest_revnum;
1391 } elsif ($r !~ /^\d+$/) {
1392 die "revision argument: $r not understood by git-svn\n";
1394 my %ed_opts = ( r
=> $r,
1399 editor_cb
=> sub { print "Committed r$_[0]\n" },
1400 svn_path
=> $svn_path );
1401 if (!SVN
::Git
::Editor
->new(\
%ed_opts)->apply_diff) {
1402 print "No changes\n$ta == $tb\n";
1406 sub escape_uri_only
{
1409 foreach (split m{/}, $uri) {
1410 s/([^~\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg;
1418 if ($url =~ m
#^([^:]+)://([^/]*)(.*)$#) {
1419 my ($scheme, $domain, $uri) = ($1, $2, escape_uri_only
($3));
1420 $url = "$scheme://$domain$uri";
1426 my $path = canonicalize_path
(defined($_[0]) ?
$_[0] : ".");
1427 my $fullpath = canonicalize_path
($cmd_dir_prefix . $path);
1429 die "Too many arguments specified\n";
1432 my ($file_type, $diff_status) = find_file_type_and_diff_status
($path);
1434 if (!$file_type && !$diff_status) {
1435 print STDERR
"svn: '$path' is not under version control\n";
1439 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
1441 die "Unable to determine upstream SVN information from ",
1442 "working tree history\n";
1445 # canonicalize_path() will return "" to make libsvn 1.5.x happy,
1446 $path = "." if $path eq "";
1448 my $full_url = $url . ($fullpath eq "" ?
"" : "/$fullpath");
1451 print escape_url
($full_url), "\n";
1455 my $result = "Path: $path\n";
1456 $result .= "Name: " . basename
($path) . "\n" if $file_type ne "dir";
1457 $result .= "URL: " . escape_url
($full_url) . "\n";
1460 my $repos_root = $gs->repos_root;
1461 Git
::SVN
::remove_username
($repos_root);
1462 $result .= "Repository Root: " . escape_url
($repos_root) . "\n";
1465 $result .= "Repository Root: (offline)\n";
1468 $result .= "Repository UUID: $uuid\n" unless $diff_status eq "A" &&
1469 ($SVN::Core
::VERSION
le '1.5.4' || $file_type ne "dir");
1470 $result .= "Revision: " . ($diff_status eq "A" ?
0 : $rev) . "\n";
1472 $result .= "Node Kind: " .
1473 ($file_type eq "dir" ?
"directory" : "file") . "\n";
1475 my $schedule = $diff_status eq "A"
1477 : ($diff_status eq "D" ?
"delete" : "normal");
1478 $result .= "Schedule: $schedule\n";
1480 if ($diff_status eq "A") {
1481 print $result, "\n";
1485 my ($lc_author, $lc_rev, $lc_date_utc);
1486 my @args = Git
::SVN
::Log
::git_svn_log_cmd
($rev, $rev, "--", $fullpath);
1487 my $log = command_output_pipe
(@args);
1488 my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
1490 if (/^${esc_color}author (.+) <[^>]+> (\d+) ([\-\+]?\d+)$/o) {
1492 $lc_date_utc = Git
::SVN
::Log
::parse_git_date
($2, $3);
1493 } elsif (/^${esc_color} (git-svn-id:.+)$/o) {
1494 (undef, $lc_rev, undef) = ::extract_metadata
($1);
1499 Git
::SVN
::Log
::set_local_timezone
();
1501 $result .= "Last Changed Author: $lc_author\n";
1502 $result .= "Last Changed Rev: $lc_rev\n";
1503 $result .= "Last Changed Date: " .
1504 Git
::SVN
::Log
::format_svn_date
($lc_date_utc) . "\n";
1506 if ($file_type ne "dir") {
1507 my $text_last_updated_date =
1508 ($diff_status eq "D" ?
$lc_date_utc : (stat $path)[9]);
1510 "Text Last Updated: " .
1511 Git
::SVN
::Log
::format_svn_date
($text_last_updated_date) .
1514 if ($diff_status eq "D") {
1516 command_output_pipe
(qw(cat-file blob), "HEAD:$path");
1517 if ($file_type eq "link") {
1518 my $file_name = <$fh>;
1519 $checksum = md5sum
("link $file_name");
1521 $checksum = md5sum
($fh);
1523 command_close_pipe
($fh, $ctx);
1524 } elsif ($file_type eq "link") {
1526 command
(qw(cat-file blob), "HEAD:$path");
1528 md5sum
("link " . $file_name);
1530 open FILE
, "<", $path or die $!;
1531 $checksum = md5sum
(\
*FILE
);
1532 close FILE
or die $!;
1534 $result .= "Checksum: " . $checksum . "\n";
1537 print $result, "\n";
1541 my $target = shift || $_revision or die "SVN revision required\n";
1542 $target = $1 if $target =~ /^r(\d+)$/;
1543 $target =~ /^\d+$/ or die "Numeric SVN revision expected\n";
1544 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
1546 die "Unable to determine upstream SVN information from ".
1549 my ($r, $c) = $gs->find_rev_before($target, not $_fetch_parent);
1550 die "Cannot find SVN revision $target\n" unless defined($c);
1551 $gs->rev_map_set($r, $c, 'reset', $uuid);
1552 print "r$r = $c ($gs->{ref_id})\n";
1556 if (!$can_compress) {
1557 warn "Compress::Zlib could not be found; unhandled.log " .
1558 "files will not be compressed.\n";
1560 find
({ wanted
=> \
&gc_directory
, no_chdir
=> 1}, "$ENV{GIT_DIR}/svn");
1563 ########################### utility functions #########################
1566 my @cmd = qw
/rebase/;
1567 push @cmd, '-v' if $_verbose;
1568 push @cmd, qw
/--merge/ if $_merge;
1569 push @cmd, "--strategy=$_strategy" if $_strategy;
1573 sub post_fetch_checkout
{
1574 return if $_no_checkout;
1575 my $gs = $Git::SVN
::_head
or return;
1576 return if verify_ref
('refs/heads/master^0');
1578 # look for "trunk" ref if it exists
1579 my $remote = Git
::SVN
::read_all_remotes
()->{$gs->{repo_id
}};
1580 my $fetch = $remote->{fetch
};
1582 foreach my $p (keys %$fetch) {
1583 basename
($fetch->{$p}) eq 'trunk' or next;
1584 $gs = Git
::SVN
->new($fetch->{$p}, $gs->{repo_id
}, $p);
1589 my $valid_head = verify_ref
('HEAD^0');
1590 command_noisy
(qw(update-ref refs/heads/master), $gs->refname);
1591 return if ($valid_head || !verify_ref
('HEAD^0'));
1593 return if $ENV{GIT_DIR
} !~ m
#^(?:.*/)?\.git$#;
1594 my $index = $ENV{GIT_INDEX_FILE
} || "$ENV{GIT_DIR}/index";
1595 return if -f
$index;
1597 return if command_oneline
(qw
/rev-parse --is-inside-work-tree/) eq 'false';
1598 return if command_oneline
(qw
/rev-parse --is-inside-git-dir/) eq 'true';
1599 command_noisy
(qw
/read-tree -m -u -v HEAD HEAD/);
1600 print STDERR
"Checked out HEAD:\n ",
1601 $gs->full_url, " r", $gs->last_rev, "\n";
1602 if (auto_create_empty_directories
($gs)) {
1603 $gs->mkemptydirs($gs->last_rev);
1607 sub complete_svn_url
{
1608 my ($url, $path) = @_;
1610 if ($path !~ m
#^[a-z\+]+://#) {
1611 if (!defined $url || $url !~ m
#^[a-z\+]+://#) {
1612 fatal
("E: '$path' is not a complete URL ",
1613 "and a separate URL is not specified");
1615 return ($url, $path);
1620 sub complete_url_ls_init
{
1621 my ($ra, $repo_path, $switch, $pfx) = @_;
1622 unless ($repo_path) {
1623 print STDERR
"W: $switch not specified\n";
1626 $repo_path =~ s
#/+$##;
1627 if ($repo_path =~ m
#^[a-z\+]+://#) {
1628 $ra = Git
::SVN
::Ra
->new($repo_path);
1631 $repo_path =~ s
#^/+##;
1633 fatal
("E: '$repo_path' is not a complete URL ",
1634 "and a separate URL is not specified");
1637 my $url = $ra->{url
};
1638 my $gs = Git
::SVN
->init($url, undef, undef, undef, 1);
1639 my $k = "svn-remote.$gs->{repo_id}.url";
1640 my $orig_url = eval { command_oneline
(qw
/config --get/, $k) };
1641 if ($orig_url && ($orig_url ne $gs->{url
})) {
1642 die "$k already set: $orig_url\n",
1643 "wanted to set to: $gs->{url}\n";
1645 command_oneline
('config', $k, $gs->{url
}) unless $orig_url;
1646 my $remote_path = "$gs->{path}/$repo_path";
1647 $remote_path =~ s{%([0-9A-F]{2})}{chr hex($1)}ieg;
1648 $remote_path =~ s
#/+#/#g;
1649 $remote_path =~ s
#^/##g;
1650 $remote_path .= "/*" if $remote_path !~ /\
*/;
1651 my ($n) = ($switch =~ /^--(\w+)/);
1652 if (length $pfx && $pfx !~ m
#/$#) {
1653 die "--prefix='$pfx' must have a trailing slash '/'\n";
1655 command_noisy
('config',
1657 "svn-remote.$gs->{repo_id}.$n",
1658 "$remote_path:refs/remotes/$pfx*" .
1659 ('/*' x
(($remote_path =~ tr
/*/*/) - 1)) );
1664 eval { command_oneline
([ 'rev-parse', '--verify', $ref ],
1665 { STDERR
=> 0 }); };
1668 sub get_tree_from_treeish
{
1670 # $treeish can be a symbolic ref, too:
1671 my $type = command_oneline
(qw
/cat-file -t/, $treeish);
1673 while ($type eq 'tag') {
1674 ($treeish, $type) = command
(qw
/cat-file tag/, $treeish);
1676 if ($type eq 'commit') {
1677 $expected = (grep /^tree /, command
(qw
/cat-file commit/,
1679 ($expected) = ($expected =~ /^tree ($sha1)$/o);
1680 die "Unable to get tree from $treeish\n" unless $expected;
1681 } elsif ($type eq 'tree') {
1682 $expected = $treeish;
1684 die "$treeish is a $type, expected tree, tag or commit\n";
1689 sub get_commit_entry
{
1690 my ($treeish) = shift;
1691 my %log_entry = ( log => '', tree
=> get_tree_from_treeish
($treeish) );
1692 my $commit_editmsg = "$ENV{GIT_DIR}/COMMIT_EDITMSG";
1693 my $commit_msg = "$ENV{GIT_DIR}/COMMIT_MSG";
1694 open my $log_fh, '>', $commit_editmsg or croak
$!;
1696 my $type = command_oneline
(qw
/cat-file -t/, $treeish);
1697 if ($type eq 'commit' || $type eq 'tag') {
1698 my ($msg_fh, $ctx) = command_output_pipe
('cat-file',
1706 $in_msg = 1 if (/^\s*$/);
1707 $author = $1 if (/^author (.*>)/);
1708 } elsif (/^git-svn-id: /) {
1709 # skip this for now, we regenerate the
1710 # correct one on re-fetch anyways
1711 # TODO: set *:merge properties or like...
1713 if (/^From:/ || /^Signed-off-by:/) {
1719 $msgbuf =~ s/\s+$//s;
1720 if ($Git::SVN
::_add_author_from
&& defined($author)
1722 $msgbuf .= "\n\nFrom: $author";
1724 print $log_fh $msgbuf or croak
$!;
1725 command_close_pipe
($msg_fh, $ctx);
1727 close $log_fh or croak
$!;
1729 if ($_edit || ($type eq 'tree')) {
1730 chomp(my $editor = command_oneline
(qw(var GIT_EDITOR)));
1731 system('sh', '-c', $editor.' "$@"', $editor, $commit_editmsg);
1733 rename $commit_editmsg, $commit_msg or croak
$!;
1736 # SVN requires messages to be UTF-8 when entering the repo
1738 open $log_fh, '<', $commit_msg or croak
$!;
1740 chomp($log_entry{log} = <$log_fh>);
1742 my $enc = Git
::config
('i18n.commitencoding') || 'UTF-8';
1743 my $msg = $log_entry{log};
1745 eval { $msg = Encode
::decode
($enc, $msg, 1) };
1747 die "Could not decode as $enc:\n", $msg,
1748 "\nPerhaps you need to set i18n.commitencoding\n";
1751 eval { $msg = Encode
::encode
('UTF-8', $msg, 1) };
1752 die "Could not encode as UTF-8:\n$msg\n" if $@
;
1754 $log_entry{log} = $msg;
1756 close $log_fh or croak
$!;
1763 my ($str, $file, $mode) = @_;
1764 open my $fd,'>',$file or croak
$!;
1765 print $fd $str,"\n" or croak
$!;
1766 close $fd or croak
$!;
1767 chmod ($mode &~ umask, $file) if (defined $mode);
1772 open my $fd,'<',$file or croak
"$!: file: $file\n";
1775 close $fd or croak
$!;
1780 # '<svn username> = real-name <email address>' mapping based on git-svnimport:
1782 open my $authors, '<', $_authors or die "Can't open $_authors $!\n";
1783 my $log = $cmd eq 'log';
1784 while (<$authors>) {
1786 next unless /^(.+?|\(no author\))\s*=\s*(.+?)\s*<(.+)>\s*$/;
1787 my ($user, $name, $email) = ($1, $2, $3);
1789 $Git::SVN
::Log
::rusers
{"$name <$email>"} = $user;
1791 $users{$user} = [$name, $email];
1794 close $authors or croak
$!;
1797 # convert GetOpt::Long specs for use by git-config
1798 sub read_git_config
{
1801 foreach my $o (keys %$opts) {
1802 # if we have mixedCase and a long option-only, then
1803 # it's a config-only variable that we don't need for
1805 push @config_only, $o if ($o =~ /[A-Z]/ && $o =~ /^[a-z]+$/i);
1806 my $v = $opts->{$o};
1807 my ($key) = ($o =~ /^([a-zA-Z\-]+)/);
1809 my $arg = 'git config';
1810 $arg .= ' --int' if ($o =~ /[:=]i$/);
1811 $arg .= ' --bool' if ($o !~ /[:=][sfi]$/);
1812 if (ref $v eq 'ARRAY') {
1813 chomp(my @tmp = `$arg --get-all svn.$key`);
1816 chomp(my $tmp = `$arg --get svn.$key`);
1817 if ($tmp && !($arg =~ / --bool/ && $tmp eq 'false')) {
1822 delete @
$opts{@config_only} if @config_only;
1825 sub extract_metadata
{
1826 my $id = shift or return (undef, undef, undef);
1827 my ($url, $rev, $uuid) = ($id =~ /^\s
*git
-svn
-id
:\s
+(.*)\@
(\d
+)
1828 \s
([a
-f\d\
-]+)$/ix
);
1829 if (!defined $rev || !$uuid || !$url) {
1830 # some of the original repositories I made had
1831 # identifiers like this:
1832 ($rev, $uuid) = ($id =~/^\s*git-svn-id:\s(\d+)\@([a-f\d\-]+)/i);
1834 return ($url, $rev, $uuid);
1838 return extract_metadata
((grep(/^git-svn-id: /,
1839 command
(qw
/cat-file commit/, shift)))[-1]);
1842 sub cmt_sha2rev_batch
{
1844 my ($pid, $in, $out, $ctx) = command_bidi_pipe
(qw
/cat-file --batch/);
1847 foreach my $sha (@
{$list}) {
1850 print $out $sha, "\n";
1852 while (my $line = <$in>) {
1853 if ($first && $line =~ /^[[:xdigit:]]{40}\smissing$/) {
1856 $line =~ /^[[:xdigit:]]{40}\scommit\s(\d+)$/) {
1860 } elsif ($line =~ /^(git-svn-id: )/) {
1861 my (undef, $rev, undef) =
1862 extract_metadata
($line);
1866 $size -= length($line);
1867 last if ($size == 0);
1871 command_close_bidi_pipe
($pid, $in, $out, $ctx);
1876 sub working_head_info
{
1877 my ($head, $refs) = @_;
1878 my @args = qw
/log --no-color
--no-decorate
--first
-parent
1880 my ($fh, $ctx) = command_output_pipe
(@args, $head);
1884 if ( m{^commit ($::sha1)$} ) {
1885 unshift @
$refs, $hash if $hash and $refs;
1889 next unless s{^\s*(git-svn-id:)}{$1};
1890 my ($url, $rev, $uuid) = extract_metadata
($_);
1891 if (defined $url && defined $rev) {
1892 next if $max{$url} and $max{$url} < $rev;
1893 if (my $gs = Git
::SVN
->find_by_url($url)) {
1894 my $c = $gs->rev_map_get($rev, $uuid);
1895 if ($c && $c eq $hash) {
1896 close $fh; # break the pipe
1897 return ($url, $rev, $uuid, $gs);
1899 $max{$url} ||= $gs->rev_map_max;
1904 command_close_pipe
($fh, $ctx);
1905 (undef, undef, undef, undef);
1908 sub read_commit_parents
{
1909 my ($parents, $c) = @_;
1910 chomp(my $p = command_oneline
(qw
/rev-list --parents -1/, $c));
1911 $p =~ s/^($c)\s*// or die "rev-list --parents -1 $c failed!\n";
1912 @
{$parents->{$c}} = split(/ /, $p);
1915 sub linearize_history
{
1916 my ($gs, $refs) = @_;
1918 foreach my $c (@
$refs) {
1919 read_commit_parents
(\
%parents, $c);
1924 my $last_svn_commit = $gs->last_commit;
1925 foreach my $c (reverse @
$refs) {
1926 next if $c eq $last_svn_commit;
1929 unshift @linear_refs, $c;
1932 # we only want the first parent to diff against for linear
1933 # history, we save the rest to inject when we finalize the
1935 my $fp_a = verify_ref
("$c~1");
1936 my $fp_b = shift @
{$parents{$c}} if $parents{$c};
1937 if (!$fp_a || !$fp_b) {
1939 "has no parent commit, and therefore ",
1940 "nothing to diff against.\n",
1941 "You should be working from a repository ",
1942 "originally created by git-svn\n";
1944 if ($fp_a ne $fp_b) {
1945 die "$c~1 = $fp_a, however parsing commit $c ",
1946 "revealed that:\n$c~1 = $fp_b\nBUG!\n";
1949 foreach my $p (@
{$parents{$c}}) {
1953 (\
@linear_refs, \
%parents);
1956 sub find_file_type_and_diff_status
{
1958 return ('dir', '') if $path eq '';
1961 command_oneline
(qw(diff --cached --name-status --), $path) || "";
1962 my $diff_status = (split(' ', $diff_output))[0] || "";
1964 my $ls_tree = command_oneline
(qw(ls-tree HEAD), $path) || "";
1966 return (undef, undef) if !$diff_status && !$ls_tree;
1968 if ($diff_status eq "A") {
1969 return ("link", $diff_status) if -l
$path;
1970 return ("dir", $diff_status) if -d
$path;
1971 return ("file", $diff_status);
1974 my $mode = (split(' ', $ls_tree))[0] || "";
1976 return ("link", $diff_status) if $mode eq "120000";
1977 return ("dir", $diff_status) if $mode eq "040000";
1978 return ("file", $diff_status);
1984 my $md5 = Digest
::MD5
->new();
1985 if ($ref eq 'GLOB' || $ref eq 'IO::File' || $ref eq 'File::Temp') {
1986 $md5->addfile($arg) or croak
$!;
1987 } elsif ($ref eq 'SCALAR') {
1988 $md5->add($$arg) or croak
$!;
1990 $md5->add($arg) or croak
$!;
1992 ::fatal
"Can't provide MD5 hash for unknown ref type: '", $ref, "'";
1994 return $md5->hexdigest();
1998 if ($can_compress && -f
$_ && basename
($_) eq "unhandled.log") {
1999 my $out_filename = $_ . ".gz";
2000 open my $in_fh, "<", $_ or die "Unable to open $_: $!\n";
2002 my $gz = Compress
::Zlib
::gzopen
($out_filename, "ab") or
2003 die "Unable to open $out_filename: $!\n";
2006 while ($res = sysread($in_fh, my $str, 1024)) {
2007 $gz->gzwrite($str) or
2008 die "Unable to write: ".$gz->gzerror()."!\n";
2010 unlink $_ or die "unlink $File::Find::name: $!\n";
2011 } elsif (-f
$_ && basename
($_) eq "index") {
2012 unlink $_ or die "unlink $_: $!\n";
2019 use Fcntl qw
/:DEFAULT :seek/;
2020 use constant rev_map_fmt
=> 'NH40';
2021 use vars qw
/$default_repo_id $default_ref_id $_no_metadata $_follow_parent
2022 $_repack $_repack_flags $_use_svm_props $_head
2023 $_use_svnsync_props $no_reuse_existing $_minimize_url
2024 $_use_log_author $_add_author_from $_localtime/;
2026 use File
::Path qw
/mkpath/;
2027 use File
::Copy qw
/copy/;
2029 use Memoize
; # core since 5.8.0, Jul 2002
2030 use Memoize
::Storable
;
2032 my ($_gc_nr, $_gc_period);
2034 # properties that we do not log:
2037 %SKIP_PROP = map { $_ => 1 } qw
/svn
:wc
:ra_dav
:version
-url
2038 svn
:special svn
:executable
2039 svn
:entry
:committed
-rev
2040 svn
:entry
:last-author
2042 svn
:entry
:committed
-date
/;
2044 # some options are read globally, but can be overridden locally
2045 # per [svn-remote "..."] section. Command-line options will *NOT*
2046 # override options set in an [svn-remote "..."] section
2048 for my $option (qw
/follow_parent no_metadata use_svm_props
2049 use_svnsync_props
/) {
2052 my $prop = "-$option";
2055 return $self->{$prop} if exists $self->{$prop};
2056 my $k = "svn-remote.$self->{repo_id}.$key";
2057 eval { command_oneline
(qw
/config --get/, $k) };
2059 $self->{$prop} = ${"Git::SVN::_$option"};
2061 my $v = command_oneline
(qw
/config --bool/,$k);
2062 $self->{$prop} = $v eq 'false' ?
0 : 1;
2064 return $self->{$prop};
2070 my (%LOCKFILES, %INDEX_FILES);
2072 unlink keys %LOCKFILES if %LOCKFILES;
2073 unlink keys %INDEX_FILES if %INDEX_FILES;
2076 sub resolve_local_globs
{
2077 my ($url, $fetch, $glob_spec) = @_;
2078 return unless defined $glob_spec;
2079 my $ref = $glob_spec->{ref};
2080 my $path = $glob_spec->{path
};
2081 foreach (command
(qw
#for-each-ref --format=%(refname) refs/#)) {
2082 next unless m
#^$ref->{regex}$#;
2084 my $pathname = desanitize_refname
($path->full_path($p));
2085 my $refname = desanitize_refname
($ref->full_path($p));
2086 if (my $existing = $fetch->{$pathname}) {
2087 if ($existing ne $refname) {
2088 die "Refspec conflict:\n",
2089 "existing: $existing\n",
2090 " globbed: $refname\n";
2092 my $u = (::cmt_metadata
("$refname"))[0];
2093 $u =~ s!^\Q$url\E(/|$)!! or die
2094 "$refname: '$url' not found in '$u'\n";
2095 if ($pathname ne $u) {
2096 warn "W: Refspec glob conflict ",
2097 "(ref: $refname):\n",
2098 "expected path: $pathname\n",
2100 "Continuing ahead with $u\n";
2104 $fetch->{$pathname} = $refname;
2109 sub parse_revision_argument
{
2110 my ($base, $head) = @_;
2111 if (!defined $::_revision
|| $::_revision
eq 'BASE:HEAD') {
2112 return ($base, $head);
2114 return ($1, $2) if ($::_revision
=~ /^(\d+):(\d+)$/);
2115 return ($::_revision
, $::_revision
) if ($::_revision
=~ /^\d+$/);
2116 return ($head, $head) if ($::_revision
eq 'HEAD');
2117 return ($base, $1) if ($::_revision
=~ /^BASE:(\d+)$/);
2118 return ($1, $head) if ($::_revision
=~ /^(\d+):HEAD$/);
2119 die "revision argument: $::_revision not understood by git-svn\n";
2123 my ($repo_id, $remotes) = @_;
2127 $repo_id = $gs->{repo_id
};
2129 $remotes ||= read_all_remotes
();
2130 my $remote = $remotes->{$repo_id} or
2131 die "[svn-remote \"$repo_id\"] unknown\n";
2132 my $fetch = $remote->{fetch
};
2133 my $url = $remote->{url
} or die "svn-remote.$repo_id.url not defined\n";
2135 my $ra = Git
::SVN
::Ra
->new($url);
2136 my $uuid = $ra->get_uuid;
2137 my $head = $ra->get_latest_revnum;
2139 # ignore errors, $head revision may not even exist anymore
2140 eval { $ra->get_log("", $head, 0, 1, 0, 1, sub { $head = $_[1] }) };
2141 warn "W: $@\n" if $@
;
2143 my $base = defined $fetch ?
$head : 0;
2145 # read the max revs for wildcard expansion (branches/*, tags/*)
2146 foreach my $t (qw
/branches tags/) {
2147 defined $remote->{$t} or next;
2148 push @globs, @
{$remote->{$t}};
2150 my $max_rev = eval { tmp_config
(qw
/--int --get/,
2151 "svn-remote.$repo_id.${t}-maxRev") };
2152 if (defined $max_rev && ($max_rev < $base)) {
2154 } elsif (!defined $max_rev) {
2160 foreach my $p (sort keys %$fetch) {
2161 my $gs = Git
::SVN
->new($fetch->{$p}, $repo_id, $p);
2162 my $lr = $gs->rev_map_max;
2164 $base = $lr if ($lr < $base);
2170 ($base, $head) = parse_revision_argument
($base, $head);
2171 $ra->gs_fetch_loop_common($base, $head, \
@gs, \
@globs);
2174 sub read_all_remotes
{
2176 my $use_svm_props = eval { command_oneline
(qw
/config
--bool
2177 svn
.useSvmProps
/) };
2178 $use_svm_props = $use_svm_props eq 'true' if $use_svm_props;
2179 my $svn_refspec = qr{\s*(.*?)\s*:\s*(.+?)\s*};
2180 foreach (grep { s/^svn-remote\.// } command
(qw
/config -l/)) {
2181 if (m!^(.+)\.fetch=$svn_refspec$!) {
2182 my ($remote, $local_ref, $remote_ref) = ($1, $2, $3);
2183 die("svn-remote.$remote: remote ref '$remote_ref' "
2184 . "must start with 'refs/'\n")
2185 unless $remote_ref =~ m{^refs/};
2186 $local_ref = uri_decode
($local_ref);
2187 $r->{$remote}->{fetch
}->{$local_ref} = $remote_ref;
2188 $r->{$remote}->{svm
} = {} if $use_svm_props;
2189 } elsif (m!^(.+)\.usesvmprops=\s*(.*)\s*$!) {
2190 $r->{$1}->{svm
} = {};
2191 } elsif (m!^(.+)\.url=\s*(.*)\s*$!) {
2192 $r->{$1}->{url
} = $2;
2193 } elsif (m!^(.+)\.pushurl=\s*(.*)\s*$!) {
2194 $r->{$1}->{pushurl
} = $2;
2195 } elsif (m!^(.+)\.(branches|tags)=$svn_refspec$!) {
2196 my ($remote, $t, $local_ref, $remote_ref) =
2198 die("svn-remote.$remote: remote ref '$remote_ref' ($t) "
2199 . "must start with 'refs/'\n")
2200 unless $remote_ref =~ m{^refs/};
2201 $local_ref = uri_decode
($local_ref);
2205 path
=> Git
::SVN
::GlobSpec
->new($local_ref, 1),
2206 ref => Git
::SVN
::GlobSpec
->new($remote_ref, 0) };
2207 if (length($rs->{ref}->{right
}) != 0) {
2208 die "The '*' glob character must be the last ",
2209 "character of '$remote_ref'\n";
2211 push @
{ $r->{$remote}->{$t} }, $rs;
2216 if (defined $r->{$_}->{svm
}) {
2219 my $section = "svn-remote.$_";
2221 source
=> tmp_config
('--get',
2222 "$section.svm-source"),
2223 replace
=> tmp_config
('--get',
2224 "$section.svm-replace"),
2227 $r->{$_}->{svm
} = $svm;
2235 $_gc_nr = $_gc_period = 1000;
2236 if (defined $_repack || defined $_repack_flags) {
2237 warn "Repack options are obsolete; they have no effect.\n";
2241 sub verify_remotes_sanity
{
2242 return unless -d
$ENV{GIT_DIR
};
2244 foreach (command
(qw
/config -l/)) {
2245 if (m!^svn-remote\.(?:.+)\.fetch=.*:refs/remotes/(\S+)\s*$!) {
2247 die "Remote ref refs/remote/$1 is tracked by",
2248 "\n \"$_\"\nand\n \"$seen{$1}\"\n",
2249 "Please resolve this ambiguity in ",
2250 "your git configuration file before ",
2258 sub find_existing_remote
{
2259 my ($url, $remotes) = @_;
2260 return undef if $no_reuse_existing;
2262 foreach my $repo_id (keys %$remotes) {
2263 my $u = $remotes->{$repo_id}->{url
} or next;
2265 $existing = $repo_id;
2271 sub init_remote_config
{
2272 my ($self, $url, $no_write) = @_;
2273 $url =~ s!/+$!!; # strip trailing slash
2274 my $r = read_all_remotes
();
2275 my $existing = find_existing_remote
($url, $r);
2277 unless ($no_write) {
2278 print STDERR
"Using existing ",
2279 "[svn-remote \"$existing\"]\n";
2281 $self->{repo_id
} = $existing;
2282 } elsif ($_minimize_url) {
2283 my $min_url = Git
::SVN
::Ra
->new($url)->minimize_url;
2284 $existing = find_existing_remote
($min_url, $r);
2286 unless ($no_write) {
2287 print STDERR
"Using existing ",
2288 "[svn-remote \"$existing\"]\n";
2290 $self->{repo_id
} = $existing;
2292 if ($min_url ne $url) {
2293 unless ($no_write) {
2294 print STDERR
"Using higher level of URL: ",
2295 "$url => $min_url\n";
2297 my $old_path = $self->{path
};
2298 $self->{path
} = $url;
2299 $self->{path
} =~ s!^\Q$min_url\E(/|$)!!;
2300 if (length $old_path) {
2301 $self->{path
} .= "/$old_path";
2308 # verify that we aren't overwriting anything:
2310 command_oneline
('config', '--get',
2311 "svn-remote.$self->{repo_id}.url")
2313 if ($orig_url && ($orig_url ne $url)) {
2314 die "svn-remote.$self->{repo_id}.url already set: ",
2315 "$orig_url\nwanted to set to: $url\n";
2318 my ($xrepo_id, $xpath) = find_ref
($self->refname);
2319 if (!$no_write && defined $xpath) {
2320 die "svn-remote.$xrepo_id.fetch already set to track ",
2321 "$xpath:", $self->refname, "\n";
2323 unless ($no_write) {
2324 command_noisy
('config',
2325 "svn-remote.$self->{repo_id}.url", $url);
2326 $self->{path
} =~ s{^/}{};
2327 $self->{path
} =~ s{%([0-9A-F]{2})}{chr hex($1)}ieg;
2328 command_noisy
('config', '--add',
2329 "svn-remote.$self->{repo_id}.fetch",
2330 "$self->{path}:".$self->refname);
2332 $self->{url
} = $url;
2335 sub find_by_url
{ # repos_root and, path are optional
2336 my ($class, $full_url, $repos_root, $path) = @_;
2338 return undef unless defined $full_url;
2339 remove_username
($full_url);
2340 remove_username
($repos_root) if defined $repos_root;
2341 my $remotes = read_all_remotes
();
2342 if (defined $full_url && defined $repos_root && !defined $path) {
2344 $path =~ s
#^\Q$repos_root\E(?:/|$)##;
2346 foreach my $repo_id (keys %$remotes) {
2347 my $u = $remotes->{$repo_id}->{url
} or next;
2348 remove_username
($u);
2349 next if defined $repos_root && $repos_root ne $u;
2351 my $fetch = $remotes->{$repo_id}->{fetch
} || {};
2352 foreach my $t (qw
/branches tags/) {
2353 foreach my $globspec (@
{$remotes->{$repo_id}->{$t}}) {
2354 resolve_local_globs
($u, $fetch, $globspec);
2358 my $rwr = rewrite_root
({repo_id
=> $repo_id});
2359 my $svm = $remotes->{$repo_id}->{svm
}
2360 if defined $remotes->{$repo_id}->{svm
};
2361 unless (defined $p) {
2367 remove_username
($z);
2368 } elsif (defined $svm) {
2369 $z = $svm->{source
};
2370 $prefix = $svm->{replace
};
2371 $prefix =~ s
#^\Q$u\E(?:/|$)##;
2374 $p =~ s
#^\Q$z\E(?:/|$)#$prefix# or next;
2376 foreach my $f (keys %$fetch) {
2378 return Git
::SVN
->new($fetch->{$f}, $repo_id, $f);
2385 my ($class, $url, $path, $repo_id, $ref_id, $no_write) = @_;
2386 my $self = _new
($class, $repo_id, $ref_id, $path);
2388 $self->init_remote_config($url, $no_write);
2395 foreach (command
(qw
/config -l/)) {
2396 next unless m
!^svn
-remote\
.(.+)\
.fetch
=
2397 \s
*(.*?
)\s
*:\s
*(.+?
)\s
*$!x
;
2398 my ($repo_id, $path, $ref) = ($1, $2, $3);
2399 if ($ref eq $ref_id) {
2400 $path = '' if ($path =~ m
#^\./?#);
2401 return ($repo_id, $path);
2404 (undef, undef, undef);
2408 my ($class, $ref_id, $repo_id, $path) = @_;
2409 if (defined $ref_id && !defined $repo_id && !defined $path) {
2410 ($repo_id, $path) = find_ref
($ref_id);
2411 if (!defined $repo_id) {
2412 die "Could not find a \"svn-remote.*.fetch\" key ",
2413 "in the repository configuration matching: ",
2417 my $self = _new
($class, $repo_id, $ref_id, $path);
2418 if (!defined $self->{path
} || !length $self->{path
}) {
2419 my $fetch = command_oneline
('config', '--get',
2420 "svn-remote.$repo_id.fetch",
2422 die "Failed to read \"svn-remote.$repo_id.fetch\" ",
2423 "\":$ref_id\$\" in config\n";
2424 ($self->{path
}, undef) = split(/\s*:\s*/, $fetch);
2426 $self->{path
} =~ s{/+}{/}g;
2427 $self->{path
} =~ s{\A/}{};
2428 $self->{path
} =~ s{/\z}{};
2429 $self->{url
} = command_oneline
('config', '--get',
2430 "svn-remote.$repo_id.url") or
2431 die "Failed to read \"svn-remote.$repo_id.url\" in config\n";
2432 $self->{pushurl
} = eval { command_oneline
('config', '--get',
2433 "svn-remote.$repo_id.pushurl") };
2439 my ($refname) = $_[0]->{ref_id
} ;
2441 # It cannot end with a slash /, we'll throw up on this because
2442 # SVN can't have directories with a slash in their name, either:
2443 if ($refname =~ m{/$}) {
2444 die "ref: '$refname' ends with a trailing slash, this is ",
2445 "not permitted by git nor Subversion\n";
2448 # It cannot have ASCII control character space, tilde ~, caret ^,
2449 # colon :, question-mark ?, asterisk *, space, or open bracket [
2452 # Additionally, % must be escaped because it is used for escaping
2453 # and we want our escaped refname to be reversible
2454 $refname =~ s{([ \%~\^:\?\*\[\t])}{uc sprintf('%%%02x',ord($1))}eg;
2456 # no slash-separated component can begin with a dot .
2458 $refname =~ s{/\.}{/%2E}g;
2460 # It cannot have two consecutive dots .. anywhere
2462 $refname =~ s{\.\.}{%2E%2E}g;
2464 # trailing dots and .lock are not allowed
2465 # .$ becomes %2E and .lock becomes %2Elock
2466 $refname =~ s{\.(?=$|lock$)}{%2E};
2468 # the sequence @{ is used to access the reflog
2470 $refname =~ s{\@\{}{%40\{}g;
2475 sub desanitize_refname
{
2477 $refname =~ s{%(?:([0-9A-F]{2}))}{chr hex($1)}eg;
2483 return $self->{svm
}->{uuid
} if $self->svm;
2485 unless ($self->{svm
}) {
2486 die "SVM UUID not cached, and reading remotely failed\n";
2488 $self->{svm
}->{uuid
};
2493 return $self->{svm
} if $self->{svm
};
2495 # see if we have it in our config, first:
2497 my $section = "svn-remote.$self->{repo_id}";
2499 source
=> tmp_config
('--get', "$section.svm-source"),
2500 uuid
=> tmp_config
('--get', "$section.svm-uuid"),
2501 replace
=> tmp_config
('--get', "$section.svm-replace"),
2504 if ($svm && $svm->{source
} && $svm->{uuid
} && $svm->{replace
}) {
2505 $self->{svm
} = $svm;
2511 my ($self, $ra) = @_;
2512 return $ra if $self->svm;
2514 my @err = ( "useSvmProps set, but failed to read SVM properties\n",
2515 "(svm:source, svm:uuid) ",
2516 "from the following URLs:\n" );
2517 sub read_svm_props
{
2518 my ($self, $ra, $path, $r) = @_;
2519 my $props = ($ra->get_dir($path, $r))[2];
2520 my $src = $props->{'svm:source'};
2521 my $uuid = $props->{'svm:uuid'};
2522 return undef if (!$src || !$uuid);
2526 $uuid =~ m{^[0-9a-f\-]{30,}$}i
2527 or die "doesn't look right - svm:uuid is '$uuid'\n";
2529 # the '!' is used to mark the repos_root!/relative/path
2530 $src =~ s{/?!/?}{/};
2531 $src =~ s{/+$}{}; # no trailing slashes please
2532 # username is of no interest
2533 $src =~ s{(^[a-z\+]*://)[^/@]*@}{$1};
2535 my $replace = $ra->{url
};
2536 $replace .= "/$path" if length $path;
2538 my $section = "svn-remote.$self->{repo_id}";
2539 tmp_config
("$section.svm-source", $src);
2540 tmp_config
("$section.svm-replace", $replace);
2541 tmp_config
("$section.svm-uuid", $uuid);
2549 my $r = $ra->get_latest_revnum;
2550 my $path = $self->{path
};
2552 while (length $path) {
2553 unless ($tried{"$self->{url}/$path"}) {
2554 return $ra if $self->read_svm_props($ra, $path, $r);
2555 $tried{"$self->{url}/$path"} = 1;
2557 $path =~ s
#/?[^/]+$##;
2559 die "Path: '$path' should be ''\n" if $path ne '';
2560 return $ra if $self->read_svm_props($ra, $path, $r);
2561 $tried{"$self->{url}/$path"} = 1;
2563 if ($ra->{repos_root
} eq $self->{url
}) {
2564 die @err, (map { " $_\n" } keys %tried), "\n";
2567 # nope, make sure we're connected to the repository root:
2570 $path = $ra->{svn_path
};
2571 $ra = Git
::SVN
::Ra
->new($ra->{repos_root
});
2572 while (length $path) {
2573 unless ($tried{"$ra->{url}/$path"}) {
2574 $ok = $self->read_svm_props($ra, $path, $r);
2576 $tried{"$ra->{url}/$path"} = 1;
2578 $path =~ s
#/?[^/]+$##;
2580 die "Path: '$path' should be ''\n" if $path ne '';
2581 $ok ||= $self->read_svm_props($ra, $path, $r);
2582 $tried{"$ra->{url}/$path"} = 1;
2584 die @err, (map { " $_\n" } keys %tried), "\n";
2586 Git
::SVN
::Ra
->new($self->{url
});
2591 return $self->{svnsync
} if $self->{svnsync
};
2593 if ($self->no_metadata) {
2594 die "Can't have both 'noMetadata' and ",
2595 "'useSvnsyncProps' options set!\n";
2597 if ($self->rewrite_root) {
2598 die "Can't have both 'useSvnsyncProps' and 'rewriteRoot' ",
2601 if ($self->rewrite_uuid) {
2602 die "Can't have both 'useSvnsyncProps' and 'rewriteUUID' ",
2607 # see if we have it in our config, first:
2609 my $section = "svn-remote.$self->{repo_id}";
2611 my $url = tmp_config
('--get', "$section.svnsync-url");
2612 ($url) = ($url =~ m{^([a-z\+]+://\S+)$}) or
2613 die "doesn't look right - svn:sync-from-url is '$url'\n";
2615 my $uuid = tmp_config
('--get', "$section.svnsync-uuid");
2616 ($uuid) = ($uuid =~ m{^([0-9a-f\-]{30,})$}i
) or
2617 die "doesn't look right - svn:sync-from-uuid is '$uuid'\n";
2619 $svnsync = { url
=> $url, uuid
=> $uuid }
2621 if ($svnsync && $svnsync->{url
} && $svnsync->{uuid
}) {
2622 return $self->{svnsync
} = $svnsync;
2625 my $err = "useSvnsyncProps set, but failed to read " .
2626 "svnsync property: svn:sync-from-";
2627 my $rp = $self->ra->rev_proplist(0);
2629 my $url = $rp->{'svn:sync-from-url'} or die $err . "url\n";
2630 ($url) = ($url =~ m{^([a-z\+]+://\S+)$}) or
2631 die "doesn't look right - svn:sync-from-url is '$url'\n";
2633 my $uuid = $rp->{'svn:sync-from-uuid'} or die $err . "uuid\n";
2634 ($uuid) = ($uuid =~ m{^([0-9a-f\-]{30,})$}i
) or
2635 die "doesn't look right - svn:sync-from-uuid is '$uuid'\n";
2637 my $section = "svn-remote.$self->{repo_id}";
2638 tmp_config
('--add', "$section.svnsync-uuid", $uuid);
2639 tmp_config
('--add', "$section.svnsync-url", $url);
2640 return $self->{svnsync
} = { url
=> $url, uuid
=> $uuid };
2643 # this allows us to memoize our SVN::Ra UUID locally and avoid a
2644 # remote lookup (useful for 'git svn log').
2647 unless ($self->{ra_uuid
}) {
2648 my $key = "svn-remote.$self->{repo_id}.uuid";
2649 my $uuid = eval { tmp_config
('--get', $key) };
2650 if (!$@
&& $uuid && $uuid =~ /^([a-f\d\-]{30,})$/i) {
2651 $self->{ra_uuid
} = $uuid;
2653 die "ra_uuid called without URL\n" unless $self->{url
};
2654 $self->{ra_uuid
} = $self->ra->get_uuid;
2655 tmp_config
('--add', $key, $self->{ra_uuid
});
2661 sub _set_repos_root
{
2662 my ($self, $repos_root) = @_;
2663 my $k = "svn-remote.$self->{repo_id}.reposRoot";
2664 $repos_root ||= $self->ra->{repos_root
};
2665 tmp_config
($k, $repos_root);
2671 my $k = "svn-remote.$self->{repo_id}.reposRoot";
2672 eval { tmp_config
('--get', $k) } || $self->_set_repos_root;
2677 my $ra = Git
::SVN
::Ra
->new($self->{url
});
2678 $self->_set_repos_root($ra->{repos_root
});
2679 if ($self->use_svm_props && !$self->{svm
}) {
2680 if ($self->no_metadata) {
2681 die "Can't have both 'noMetadata' and ",
2682 "'useSvmProps' options set!\n";
2683 } elsif ($self->use_svnsync_props) {
2684 die "Can't have both 'useSvnsyncProps' and ",
2685 "'useSvmProps' options set!\n";
2687 $ra = $self->_set_svm_vars($ra);
2688 $self->{-want_revprops
} = 1;
2693 # prop_walk(PATH, REV, SUB)
2694 # -------------------------
2695 # Recursively traverse PATH at revision REV and invoke SUB for each
2696 # directory that contains a SVN property. SUB will be invoked as
2697 # follows: &SUB(gs, path, props); where `gs' is this instance of
2698 # Git::SVN, `path' the path to the directory where the properties
2699 # `props' were found. The `path' will be relative to point of checkout,
2700 # that is, if url://repo/trunk is the current Git branch, and that
2701 # directory contains a sub-directory `d', SUB will be invoked with `/d/'
2702 # as `path' (note the trailing `/').
2704 my ($self, $path, $rev, $sub) = @_;
2707 my ($dirent, undef, $props) = $self->ra->get_dir($path, $rev);
2710 # Strip the irrelevant part of the path.
2711 $p =~ s
#^/+\Q$self->{path}\E(/|$)#/#;
2712 # Ensure the path is terminated by a `/'.
2715 # The properties contain all the internal SVN stuff nobody
2716 # (usually) cares about.
2717 my $interesting_props = 0;
2718 foreach (keys %{$props}) {
2719 # If it doesn't start with `svn:', it must be a
2720 # user-defined property.
2721 ++$interesting_props and next if $_ !~ /^svn:/;
2722 # FIXME: Fragile, if SVN adds new public properties,
2723 # this needs to be updated.
2724 ++$interesting_props if /^svn
:(?
:ignore
|keywords
|executable
2725 |eol
-style
|mime
-type
2726 |externals
|needs
-lock)$/x
;
2728 &$sub($self, $p, $props) if $interesting_props;
2730 foreach (sort keys %$dirent) {
2731 next if $dirent->{$_}->{kind
} != $SVN::Node
::dir
;
2732 $self->prop_walk($self->{path
} . $p . $_, $rev, $sub);
2736 sub last_rev
{ ($_[0]->last_rev_commit)[0] }
2737 sub last_commit
{ ($_[0]->last_rev_commit)[1] }
2739 # returns the newest SVN revision number and newest commit SHA1
2740 sub last_rev_commit
{
2742 if (defined $self->{last_rev
} && defined $self->{last_commit
}) {
2743 return ($self->{last_rev
}, $self->{last_commit
});
2745 my $c = ::verify_ref
($self->refname.'^0');
2746 if ($c && !$self->use_svm_props && !$self->no_metadata) {
2747 my $rev = (::cmt_metadata
($c))[1];
2749 ($self->{last_rev
}, $self->{last_commit
}) = ($rev, $c);
2753 my $map_path = $self->map_path;
2754 unless (-e
$map_path) {
2755 ($self->{last_rev
}, $self->{last_commit
}) = (undef, undef);
2756 return (undef, undef);
2758 my ($rev, $commit) = $self->rev_map_max(1);
2759 ($self->{last_rev
}, $self->{last_commit
}) = ($rev, $commit);
2760 return ($rev, $commit);
2763 sub get_fetch_range
{
2764 my ($self, $min, $max) = @_;
2765 $max ||= $self->ra->get_latest_revnum;
2766 $min ||= $self->rev_map_max;
2772 my $old_def_config = "$ENV{GIT_DIR}/svn/config";
2773 my $config = "$ENV{GIT_DIR}/svn/.metadata";
2774 if (! -f
$config && -f
$old_def_config) {
2775 rename $old_def_config, $config or
2776 die "Failed rename $old_def_config => $config: $!\n";
2778 my $old_config = $ENV{GIT_CONFIG
};
2779 $ENV{GIT_CONFIG
} = $config;
2782 unless (-f
$config) {
2784 open my $fh, '>', $config or
2785 die "Can't open $config: $!\n";
2786 print $fh "; This file is used internally by ",
2788 "Couldn't write to $config: $!\n";
2789 print $fh "; You should not have to edit it\n" or
2790 die "Couldn't write to $config: $!\n";
2791 close $fh or die "Couldn't close $config: $!\n";
2793 command
('config', @args);
2796 if (defined $old_config) {
2797 $ENV{GIT_CONFIG
} = $old_config;
2799 delete $ENV{GIT_CONFIG
};
2802 wantarray ?
@ret : $ret[0];
2806 my ($self, $sub) = @_;
2807 my $old_index = $ENV{GIT_INDEX_FILE
};
2808 $ENV{GIT_INDEX_FILE
} = $self->{index};
2811 my ($dir, $base) = ($self->{index} =~ m
#^(.*?)/?([^/]+)$#);
2812 mkpath
([$dir]) unless -d
$dir;
2816 if (defined $old_index) {
2817 $ENV{GIT_INDEX_FILE
} = $old_index;
2819 delete $ENV{GIT_INDEX_FILE
};
2822 wantarray ?
@ret : $ret[0];
2825 sub assert_index_clean
{
2826 my ($self, $treeish) = @_;
2828 $self->tmp_index_do(sub {
2829 command_noisy
('read-tree', $treeish) unless -e
$self->{index};
2830 my $x = command_oneline
('write-tree');
2831 my ($y) = (command
(qw
/cat-file commit/, $treeish) =~
2832 /^tree ($::sha1)/mo);
2835 warn "Index mismatch: $y != $x\nrereading $treeish\n";
2836 unlink $self->{index} or die "unlink $self->{index}: $!\n";
2837 command_noisy
('read-tree', $treeish);
2838 $x = command_oneline
('write-tree');
2840 ::fatal
"trees ($treeish) $y != $x\n",
2841 "Something is seriously wrong...";
2846 sub get_commit_parents
{
2847 my ($self, $log_entry) = @_;
2848 my (%seen, @ret, @tmp);
2849 # legacy support for 'set-tree'; this is only used by set_tree_cb:
2850 if (my $ip = $self->{inject_parents
}) {
2851 if (my $commit = delete $ip->{$log_entry->{revision
}}) {
2855 if (my $cur = ::verify_ref
($self->refname.'^0')) {
2858 if (my $ipd = $self->{inject_parents_dcommit
}) {
2859 if (my $commit = delete $ipd->{$log_entry->{revision
}}) {
2860 push @tmp, @
$commit;
2863 push @tmp, $_ foreach (@
{$log_entry->{parents
}}, @tmp);
2864 while (my $p = shift @tmp) {
2874 return $self->{-rewrite_root
} if exists $self->{-rewrite_root
};
2875 my $k = "svn-remote.$self->{repo_id}.rewriteRoot";
2876 my $rwr = eval { command_oneline
(qw
/config --get/, $k) };
2879 if ($rwr !~ m
#^[a-z\+]+://#) {
2880 die "$rwr is not a valid URL (key: $k)\n";
2883 $self->{-rewrite_root
} = $rwr;
2888 return $self->{-rewrite_uuid
} if exists $self->{-rewrite_uuid
};
2889 my $k = "svn-remote.$self->{repo_id}.rewriteUUID";
2890 my $rwid = eval { command_oneline
(qw
/config --get/, $k) };
2893 if ($rwid !~ m
#^[a-f0-9]{8}-(?:[a-f0-9]{4}-){3}[a-f0-9]{12}$#) {
2894 die "$rwid is not a valid UUID (key: $k)\n";
2897 $self->{-rewrite_uuid
} = $rwid;
2902 ($self->rewrite_root || $self->{url
}) .
2903 (length $self->{path
} ?
'/' . $self->{path
} : '');
2908 $self->{url
} . (length $self->{path
} ?
'/' . $self->{path
} : '');
2913 if ($self->{pushurl
}) {
2914 return $self->{pushurl
} . (length $self->{path
} ?
'/' .
2915 $self->{path
} : '');
2917 return $self->full_url;
2921 sub set_commit_header_env
{
2922 my ($log_entry) = @_;
2924 foreach my $ned (qw
/NAME EMAIL DATE/) {
2925 foreach my $ac (qw
/AUTHOR COMMITTER/) {
2926 $env{"GIT_${ac}_${ned}"} = $ENV{"GIT_${ac}_${ned}"};
2930 $ENV{GIT_AUTHOR_NAME
} = $log_entry->{name
};
2931 $ENV{GIT_AUTHOR_EMAIL
} = $log_entry->{email
};
2932 $ENV{GIT_AUTHOR_DATE
} = $ENV{GIT_COMMITTER_DATE
} = $log_entry->{date
};
2934 $ENV{GIT_COMMITTER_NAME
} = (defined $log_entry->{commit_name
})
2935 ?
$log_entry->{commit_name
}
2936 : $log_entry->{name
};
2937 $ENV{GIT_COMMITTER_EMAIL
} = (defined $log_entry->{commit_email
})
2938 ?
$log_entry->{commit_email
}
2939 : $log_entry->{email
};
2943 sub restore_commit_header_env
{
2945 foreach my $ned (qw
/NAME EMAIL DATE/) {
2946 foreach my $ac (qw
/AUTHOR COMMITTER/) {
2947 my $k = "GIT_${ac}_${ned}";
2948 if (defined $env->{$k}) {
2949 $ENV{$k} = $env->{$k};
2958 command_noisy
('gc', '--auto');
2962 my ($self, $log_entry) = @_;
2963 my $lr = $self->last_rev;
2964 if (defined $lr && $lr >= $log_entry->{revision
}) {
2965 die "Last fetched revision of ", $self->refname,
2966 " was r$lr, but we are about to fetch: ",
2967 "r$log_entry->{revision}!\n";
2969 if (my $c = $self->rev_map_get($log_entry->{revision
})) {
2970 croak
"$log_entry->{revision} = $c already exists! ",
2971 "Why are we refetching it?\n";
2973 my $old_env = set_commit_header_env
($log_entry);
2974 my $tree = $log_entry->{tree
};
2975 if (!defined $tree) {
2976 $tree = $self->tmp_index_do(sub {
2977 command_oneline
('write-tree') });
2979 die "Tree is not a valid sha1: $tree\n" if $tree !~ /^$::sha1$/o;
2981 my @exec = ('git', 'commit-tree', $tree);
2982 foreach ($self->get_commit_parents($log_entry)) {
2983 push @exec, '-p', $_;
2985 defined(my $pid = open3
(my $msg_fh, my $out_fh, '>&STDERR', @exec))
2989 # we always get UTF-8 from SVN, but we may want our commits in
2990 # a different encoding.
2991 if (my $enc = Git
::config
('i18n.commitencoding')) {
2993 Encode
::from_to
($log_entry->{log}, 'UTF-8', $enc);
2995 print $msg_fh $log_entry->{log} or croak
$!;
2996 restore_commit_header_env
($old_env);
2997 unless ($self->no_metadata) {
2998 print $msg_fh "\ngit-svn-id: $log_entry->{metadata}\n"
3001 $msg_fh->flush == 0 or croak
$!;
3002 close $msg_fh or croak
$!;
3003 chomp(my $commit = do { local $/; <$out_fh> });
3004 close $out_fh or croak
$!;
3007 if ($commit !~ /^$::sha1$/o) {
3008 die "Failed to commit, invalid sha1: $commit\n";
3011 $self->rev_map_set($log_entry->{revision
}, $commit, 1);
3013 $self->{last_rev
} = $log_entry->{revision
};
3014 $self->{last_commit
} = $commit;
3015 print "r$log_entry->{revision}" unless $::_q
> 1;
3016 if (defined $log_entry->{svm_revision
}) {
3017 print " (\@$log_entry->{svm_revision})" unless $::_q
> 1;
3018 $self->rev_map_set($log_entry->{svm_revision
}, $commit,
3019 0, $self->svm_uuid);
3021 print " = $commit ($self->{ref_id})\n" unless $::_q
> 1;
3022 if (--$_gc_nr == 0) {
3023 $_gc_nr = $_gc_period;
3030 my ($self, $paths, $r) = @_;
3031 return 1 if $self->{path
} eq '';
3032 if (my $path = $paths->{"/$self->{path}"}) {
3033 return ($path->{action
} eq 'D') ?
0 : 1;
3035 $self->{path_regex
} ||= qr/^\/\Q
$self->{path
}\E\
//;
3036 if (grep /$self->{path_regex}/, keys %$paths) {
3040 foreach (split m
#/#, $self->{path}) {
3042 next unless ($paths->{$c} &&
3043 ($paths->{$c}->{action
} =~ /^[AR]$/));
3044 if ($self->ra->check_path($self->{path
}, $r) ==
3052 sub find_parent_branch
{
3053 my ($self, $paths, $rev) = @_;
3054 return undef unless $self->follow_parent;
3055 unless (defined $paths) {
3056 my $err_handler = $SVN::Error
::handler
;
3057 $SVN::Error
::handler
= \
&Git
::SVN
::Ra
::skip_unknown_revs
;
3058 $self->ra->get_log([$self->{path
}], $rev, $rev, 0, 1, 1,
3059 sub { $paths = $_[0] });
3060 $SVN::Error
::handler
= $err_handler;
3062 return undef unless defined $paths;
3064 # look for a parent from another branch:
3065 my @b_path_components = split m
#/#, $self->{path};
3066 my @a_path_components;
3068 while (@b_path_components) {
3069 $i = $paths->{'/'.join('/', @b_path_components)};
3070 last if $i && defined $i->{copyfrom_path
};
3071 unshift(@a_path_components, pop(@b_path_components));
3073 return undef unless defined $i && defined $i->{copyfrom_path
};
3074 my $branch_from = $i->{copyfrom_path
};
3075 if (@a_path_components) {
3076 print STDERR
"branch_from: $branch_from => ";
3077 $branch_from .= '/'.join('/', @a_path_components);
3078 print STDERR
$branch_from, "\n";
3080 my $r = $i->{copyfrom_rev
};
3081 my $repos_root = $self->ra->{repos_root
};
3082 my $url = $self->ra->{url
};
3083 my $new_url = $url . $branch_from;
3084 print STDERR
"Found possible branch point: ",
3085 "$new_url => ", $self->full_url, ", $r\n"
3087 $branch_from =~ s
#^/##;
3088 my $gs = $self->other_gs($new_url, $url,
3089 $branch_from, $r, $self->{ref_id
});
3090 my ($r0, $parent) = $gs->find_rev_before($r, 1);
3093 if (!defined $r0 || !defined $parent) {
3094 ($base, $head) = parse_revision_argument
(0, $r);
3097 $gs->ra->get_log([$gs->{path
}], $r0 + 1, $r, 1,
3098 0, 1, sub { $base = $_[1] - 1 });
3101 if (defined $base && $base <= $r) {
3102 $gs->fetch($base, $r);
3104 ($r0, $parent) = $gs->find_rev_before($r, 1);
3106 if (defined $r0 && defined $parent) {
3107 print STDERR
"Found branch parent: ($self->{ref_id}) $parent\n"
3110 if ($self->ra->can_do_switch) {
3111 $self->assert_index_clean($parent);
3112 print STDERR
"Following parent with do_switch\n"
3114 # do_switch works with svn/trunk >= r22312, but that
3115 # is not included with SVN 1.4.3 (the latest version
3116 # at the moment), so we can't rely on it
3117 $self->{last_rev
} = $r0;
3118 $self->{last_commit
} = $parent;
3119 $ed = SVN
::Git
::Fetcher
->new($self, $gs->{path
});
3120 $gs->ra->gs_do_switch($r0, $rev, $gs,
3121 $self->full_url, $ed)
3122 or die "SVN connection failed somewhere...\n";
3123 } elsif ($self->ra->trees_match($new_url, $r0,
3124 $self->full_url, $rev)) {
3125 print STDERR
"Trees match:\n",
3127 " ${\$self->full_url}\@$rev\n",
3128 "Following parent with no changes\n"
3130 $self->tmp_index_do(sub {
3131 command_noisy
('read-tree', $parent);
3133 $self->{last_commit
} = $parent;
3135 print STDERR
"Following parent with do_update\n"
3137 $ed = SVN
::Git
::Fetcher
->new($self);
3138 $self->ra->gs_do_update($rev, $rev, $self, $ed)
3139 or die "SVN connection failed somewhere...\n";
3141 print STDERR
"Successfully followed parent\n" unless $::_q
> 1;
3142 return $self->make_log_entry($rev, [$parent], $ed);
3148 my ($self, $paths, $rev) = @_;
3150 my ($last_rev, @parents);
3151 if (my $lc = $self->last_commit) {
3152 # we can have a branch that was deleted, then re-added
3153 # under the same name but copied from another path, in
3154 # which case we'll have multiple parents (we don't
3155 # want to break the original ref, nor lose copypath info):
3156 if (my $log_entry = $self->find_parent_branch($paths, $rev)) {
3157 push @
{$log_entry->{parents
}}, $lc;
3160 $ed = SVN
::Git
::Fetcher
->new($self);
3161 $last_rev = $self->{last_rev
};
3166 if (my $log_entry = $self->find_parent_branch($paths, $rev)) {
3169 $ed = SVN
::Git
::Fetcher
->new($self);
3171 unless ($self->ra->gs_do_update($last_rev, $rev, $self, $ed)) {
3172 die "SVN connection failed somewhere...\n";
3174 $self->make_log_entry($rev, \
@parents, $ed);
3178 my ($self, $r) = @_;
3181 my ($r, $empty_dirs, $line) = @_;
3182 if (defined $r && $line =~ /^r(\d+)$/) {
3183 return 0 if $1 > $r;
3184 } elsif ($line =~ /^ \+empty_dir: (.+)$/) {
3185 $empty_dirs->{$1} = 1;
3186 } elsif ($line =~ /^ \-empty_dir: (.+)$/) {
3187 my @d = grep {m
[^\Q
$1\E
(/|$)]} (keys %$empty_dirs);
3188 delete @
$empty_dirs{@d};
3193 my %empty_dirs = ();
3194 my $gz_file = "$self->{dir}/unhandled.log.gz";
3196 if (!$can_compress) {
3197 warn "Compress::Zlib could not be found; ",
3198 "empty directories in $gz_file will not be read\n";
3200 my $gz = Compress
::Zlib
::gzopen
($gz_file, "rb") or
3201 die "Unable to open $gz_file: $!\n";
3203 while ($gz->gzreadline($line) > 0) {
3204 scan
($r, \
%empty_dirs, $line) or last;
3210 if (open my $fh, '<', "$self->{dir}/unhandled.log") {
3211 binmode $fh or croak
"binmode: $!";
3213 scan
($r, \
%empty_dirs, $_) or last;
3218 my $strip = qr/\A\Q$self->{path}\E(?:\/|$)/;
3219 foreach my $d (sort keys %empty_dirs) {
3220 $d = uri_decode
($d);
3222 next unless length($d);
3225 warn "$d exists but is not a directory\n";
3227 print "creating empty directory: $d\n";
3234 my ($self, $ed) = @_;
3236 my $h = $ed->{empty
};
3237 foreach (sort keys %$h) {
3238 my $act = $h->{$_} ?
'+empty_dir' : '-empty_dir';
3239 push @out, " $act: " . uri_encode
($_);
3240 warn "W: $act: $_\n";
3242 foreach my $t (qw
/dir_prop file_prop/) {
3243 $h = $ed->{$t} or next;
3244 foreach my $path (sort keys %$h) {
3245 my $ppath = $path eq '' ?
'.' : $path;
3246 foreach my $prop (sort keys %{$h->{$path}}) {
3247 next if $SKIP_PROP{$prop};
3248 my $v = $h->{$path}->{$prop};
3249 my $t_ppath_prop = "$t: " .
3250 uri_encode
($ppath) . ' ' .
3253 push @out, " +$t_ppath_prop " .
3256 push @out, " -$t_ppath_prop";
3261 foreach my $t (qw
/absent_file absent_directory/) {
3262 $h = $ed->{$t} or next;
3263 foreach my $parent (sort keys %$h) {
3264 foreach my $path (sort @
{$h->{$parent}}) {
3265 push @out, " $t: " .
3266 uri_encode
("$parent/$path");
3267 warn "W: $t: $parent/$path ",
3268 "Insufficient permissions?\n";
3275 # parse_svn_date(DATE)
3276 # --------------------
3277 # Given a date (in UTC) from Subversion, return a string in the format
3278 # "<TZ Offset> <local date/time>" that Git will use.
3280 # By default the parsed date will be in UTC; if $Git::SVN::_localtime
3281 # is true we'll convert it to the local timezone instead.
3282 sub parse_svn_date
{
3283 my $date = shift || return '+0000 1970-01-01 00:00:00';
3284 my ($Y,$m,$d,$H,$M,$S) = ($date =~ /^(\d
{4})\
-(\d\d
)\
-(\d\d
)T
3285 (\d\d
)\
:(\d\d
)\
:(\d\d
)\
.\d
*Z
$/x
) or
3286 croak
"Unable to parse date: $date\n";
3287 my $parsed_date; # Set next.
3289 if ($Git::SVN
::_localtime
) {
3290 # Translate the Subversion datetime to an epoch time.
3291 # Begin by switching ourselves to $date's timezone, UTC.
3292 my $old_env_TZ = $ENV{TZ
};
3296 POSIX
::strftime
('%s', $S, $M, $H, $d, $m - 1, $Y - 1900);
3298 # Determine our local timezone (including DST) at the
3299 # time of $epoch_in_UTC. $Git::SVN::Log::TZ stored the
3300 # value of TZ, if any, at the time we were run.
3301 if (defined $Git::SVN
::Log
::TZ
) {
3302 $ENV{TZ
} = $Git::SVN
::Log
::TZ
;
3308 POSIX
::strftime
('%Z', $S, $M, $H, $d, $m - 1, $Y - 1900);
3310 # This converts $epoch_in_UTC into our local timezone.
3311 my ($sec, $min, $hour, $mday, $mon, $year,
3312 $wday, $yday, $isdst) = localtime($epoch_in_UTC);
3314 $parsed_date = sprintf('%s %04d-%02d-%02d %02d:%02d:%02d',
3315 $our_TZ, $year + 1900, $mon + 1,
3316 $mday, $hour, $min, $sec);
3318 # Reset us to the timezone in effect when we entered
3320 if (defined $old_env_TZ) {
3321 $ENV{TZ
} = $old_env_TZ;
3326 $parsed_date = "+0000 $Y-$m-$d $H:$M:$S";
3329 return $parsed_date;
3333 my ($self, $new_url, $url,
3334 $branch_from, $r, $old_ref_id) = @_;
3335 my $gs = Git
::SVN
->find_by_url($new_url, $url, $branch_from);
3337 my $ref_id = $old_ref_id;
3338 $ref_id =~ s/\@\d+-*$//;
3340 # just grow a tail if we're not unique enough :x
3341 $ref_id .= '-' while find_ref
($ref_id);
3342 my ($u, $p, $repo_id) = ($new_url, '', $ref_id);
3343 if ($u =~ s
#^\Q$url\E(/|$)##) {
3346 $repo_id = $self->{repo_id
};
3349 # It is possible to tag two different subdirectories at
3350 # the same revision. If the url for an existing ref
3351 # does not match, we must either find a ref with a
3352 # matching url or create a new ref by growing a tail.
3353 $gs = Git
::SVN
->init($u, $p, $repo_id, $ref_id, 1);
3354 my (undef, $max_commit) = $gs->rev_map_max(1);
3355 last if (!$max_commit);
3356 my ($url) = ::cmt_metadata
($max_commit);
3357 last if ($url eq $gs->metadata_url);
3360 print STDERR
"Initializing parent: $ref_id\n" unless $::_q
> 1;
3365 sub call_authors_prog
{
3366 my ($orig_author) = @_;
3367 $orig_author = command_oneline
('rev-parse', '--sq-quote', $orig_author);
3368 my $author = `$::_authors_prog $orig_author`;
3370 die "$::_authors_prog failed with exit code $?\n"
3372 if ($author =~ /^\s*(.+?)\s*<(.*)>\s*$/) {
3373 my ($name, $email) = ($1, $2);
3374 $email = undef if length $2 == 0;
3375 return [$name, $email];
3377 die "Author: $orig_author: $::_authors_prog returned "
3378 . "invalid author format: $author\n";
3384 if (!defined $author || length $author == 0) {
3385 $author = '(no author)';
3387 if (!defined $::users
{$author}) {
3388 if (defined $::_authors_prog
) {
3389 $::users
{$author} = call_authors_prog
($author);
3390 } elsif (defined $::_authors
) {
3391 die "Author: $author not defined in $::_authors file\n";
3397 sub find_extra_svk_parents
{
3398 my ($self, $ed, $tickets, $parents) = @_;
3399 # aha! svk:merge property changed...
3400 my @tickets = split "\n", $tickets;
3402 for my $ticket ( @tickets ) {
3403 my ($uuid, $path, $rev) = split /:/, $ticket;
3404 if ( $uuid eq $self->ra_uuid ) {
3405 my $url = $self->{url
};
3406 my $repos_root = $url;
3407 my $branch_from = $path;
3408 $branch_from =~ s{^/}{};
3409 my $gs = $self->other_gs($repos_root."/".$branch_from,
3414 if ( my $commit = $gs->rev_map_get($rev, $uuid) ) {
3415 # wahey! we found it, but it might be
3417 push @known_parents, [ $rev, $commit ];
3421 # Ordering matters; highest-numbered commit merge tickets
3422 # first, as they may account for later merge ticket additions
3424 @known_parents = map {$_->[1]} sort {$b->[0] <=> $a->[0]} @known_parents;
3425 for my $parent ( @known_parents ) {
3426 my @cmd = ('rev-list', $parent, map { "^$_" } @
$parents );
3427 my ($msg_fh, $ctx) = command_output_pipe
(@cmd);
3429 while ( <$msg_fh> ) {
3432 command_close_pipe
($msg_fh, $ctx);
3435 "Found merge parent (svk:merge ticket): $parent\n";
3436 push @
$parents, $parent;
3441 sub lookup_svn_merge
{
3446 my ($source, $revs) = split ":", $merge;
3449 my $gs = Git
::SVN
->find_by_url($url.$source, $url, $path);
3451 warn "Couldn't find revmap for $url$source\n";
3454 my @ranges = split ",", $revs;
3455 my ($tip, $tip_commit);
3456 my @merged_commit_ranges;
3458 for my $range ( @ranges ) {
3459 my ($bottom, $top) = split "-", $range;
3461 my $bottom_commit = $gs->find_rev_after( $bottom, 1, $top );
3462 my $top_commit = $gs->find_rev_before( $top, 1, $bottom );
3464 unless ($top_commit and $bottom_commit) {
3465 warn "W:unknown path/rev in svn:mergeinfo "
3466 ."dirprop: $source:$range\n";
3470 if (scalar(command
('rev-parse', "$bottom_commit^@"))) {
3471 push @merged_commit_ranges,
3472 "$bottom_commit^..$top_commit";
3474 push @merged_commit_ranges, "$top_commit";
3477 if ( !defined $tip or $top > $tip ) {
3479 $tip_commit = $top_commit;
3482 return ($tip_commit, @merged_commit_ranges);
3486 my ($msg_fh, $ctx) = command_output_pipe
(
3490 while ( <$msg_fh> ) {
3494 command_close_pipe
($msg_fh, $ctx);
3498 sub check_cherry_pick
{
3501 my $parents = shift;
3503 my %commits = map { $_ => 1 }
3504 _rev_list
("--no-merges", $tip, "--not", $base, @
$parents, "--");
3505 for my $range ( @ranges ) {
3506 delete @commits{_rev_list
($range, "--")};
3508 for my $commit (keys %commits) {
3509 if (has_no_changes
($commit)) {
3510 delete $commits{$commit};
3513 return (keys %commits);
3516 sub has_no_changes
{
3519 my @revs = split / /, command_oneline
(
3520 qw(rev-list --parents -1 -m), $commit);
3522 # Commits with no parents, e.g. the start of a partial branch,
3523 # have changes by definition.
3524 return 1 if (@revs < 2);
3526 # Commits with multiple parents, e.g a merge, have no changes
3528 return 0 if (@revs > 2);
3530 return (command_oneline
("rev-parse", "$commit^{tree}") eq
3531 command_oneline
("rev-parse", "$commit~1^{tree}"));
3534 # The GIT_DIR environment variable is not always set until after the command
3535 # line arguments are processed, so we can't memoize in a BEGIN block.
3539 sub memoize_svn_mergeinfo_functions
{
3540 return if $memoized;
3543 my $cache_path = "$ENV{GIT_DIR}/svn/.caches/";
3544 mkpath
([$cache_path]) unless -d
$cache_path;
3546 tie
my %lookup_svn_merge_cache => 'Memoize::Storable',
3547 "$cache_path/lookup_svn_merge.db", 'nstore';
3548 memoize
'lookup_svn_merge',
3549 SCALAR_CACHE
=> 'FAULT',
3550 LIST_CACHE
=> ['HASH' => \
%lookup_svn_merge_cache],
3553 tie
my %check_cherry_pick_cache => 'Memoize::Storable',
3554 "$cache_path/check_cherry_pick.db", 'nstore';
3555 memoize
'check_cherry_pick',
3556 SCALAR_CACHE
=> 'FAULT',
3557 LIST_CACHE
=> ['HASH' => \
%check_cherry_pick_cache],
3560 tie
my %has_no_changes_cache => 'Memoize::Storable',
3561 "$cache_path/has_no_changes.db", 'nstore';
3562 memoize
'has_no_changes',
3563 SCALAR_CACHE
=> ['HASH' => \
%has_no_changes_cache],
3564 LIST_CACHE
=> 'FAULT',
3568 sub unmemoize_svn_mergeinfo_functions
{
3569 return if not $memoized;
3572 Memoize
::unmemoize
'lookup_svn_merge';
3573 Memoize
::unmemoize
'check_cherry_pick';
3574 Memoize
::unmemoize
'has_no_changes';
3577 Memoize
::memoize
'Git::SVN::repos_root';
3581 # Force cache writeout explicitly instead of waiting for
3582 # global destruction to avoid segfault in Storable:
3583 # http://rt.cpan.org/Public/Bug/Display.html?id=36087
3584 unmemoize_svn_mergeinfo_functions
();
3587 sub parents_exclude
{
3588 my $parents = shift;
3590 return unless @commits;
3595 my @cmd = ('rev-list', "-1", @commits, "--not", @
$parents );
3596 $excluded = command_oneline
(@cmd);
3600 for my $commit ( @commits ) {
3601 if ( $commit eq $excluded ) {
3602 push @excluded, $commit;
3610 die "saw commit '$excluded' in rev-list output, "
3611 ."but we didn't ask for that commit (wanted: @commits --not @$parents)"
3616 while ($excluded and @commits);
3622 # note: this function should only be called if the various dirprops
3623 # have actually changed
3624 sub find_extra_svn_parents
{
3625 my ($self, $ed, $mergeinfo, $parents) = @_;
3626 # aha! svk:merge property changed...
3628 memoize_svn_mergeinfo_functions
();
3630 # We first search for merged tips which are not in our
3631 # history. Then, we figure out which git revisions are in
3632 # that tip, but not this revision. If all of those revisions
3633 # are now marked as merge, we can add the tip as a parent.
3634 my @merges = split "\n", $mergeinfo;
3636 my $url = $self->{url
};
3637 my $uuid = $self->ra_uuid;
3639 for my $merge ( @merges ) {
3640 my ($tip_commit, @ranges) =
3641 lookup_svn_merge
( $uuid, $url, $merge );
3642 unless (!$tip_commit or
3643 grep { $_ eq $tip_commit } @
$parents ) {
3644 push @merge_tips, $tip_commit;
3645 $ranges{$tip_commit} = \
@ranges;
3647 push @merge_tips, undef;
3651 my %excluded = map { $_ => 1 }
3652 parents_exclude
($parents, grep { defined } @merge_tips);
3654 # check merge tips for new parents
3656 for my $merge_tip ( @merge_tips ) {
3657 my $spec = shift @merges;
3658 next unless $merge_tip and $excluded{$merge_tip};
3660 my $ranges = $ranges{$merge_tip};
3662 # check out 'new' tips
3665 $merge_base = command_oneline
(
3667 @
$parents, $merge_tip,
3671 die "An error occurred during merge-base"
3672 unless $@
->isa("Git::Error::Command");
3674 warn "W: Cannot find common ancestor between ".
3675 "@$parents and $merge_tip. Ignoring merge info.\n";
3679 # double check that there are no missing non-merge commits
3680 my (@incomplete) = check_cherry_pick
(
3681 $merge_base, $merge_tip,
3686 if ( @incomplete ) {
3687 warn "W:svn cherry-pick ignored ($spec) - missing "
3688 .@incomplete." commit(s) (eg $incomplete[0])\n";
3691 "Found merge parent (svn:mergeinfo prop): ",
3693 push @new_parents, $merge_tip;
3697 # cater for merges which merge commits from multiple branches
3698 if ( @new_parents > 1 ) {
3699 for ( my $i = 0; $i <= $#new_parents; $i++ ) {
3700 for ( my $j = 0; $j <= $#new_parents; $j++ ) {
3702 next unless $new_parents[$i];
3703 next unless $new_parents[$j];
3704 my $revs = command_oneline
(
3706 "$new_parents[$i]..$new_parents[$j]",
3709 undef($new_parents[$j]);
3714 push @
$parents, grep { defined } @new_parents;
3717 sub make_log_entry
{
3718 my ($self, $rev, $parents, $ed) = @_;
3719 my $untracked = $self->get_untracked($ed);
3721 my @parents = @
$parents;
3722 my $ps = $ed->{path_strip
} || "";
3723 for my $path ( grep { m/$ps/ } %{$ed->{dir_prop
}} ) {
3724 my $props = $ed->{dir_prop
}{$path};
3725 if ( $props->{"svk:merge"} ) {
3726 $self->find_extra_svk_parents
3727 ($ed, $props->{"svk:merge"}, \
@parents);
3729 if ( $props->{"svn:mergeinfo"} ) {
3730 $self->find_extra_svn_parents
3732 $props->{"svn:mergeinfo"},
3737 open my $un, '>>', "$self->{dir}/unhandled.log" or croak
$!;
3738 print $un "r$rev\n" or croak
$!;
3739 print $un $_, "\n" foreach @
$untracked;
3740 my %log_entry = ( parents
=> \
@parents, revision
=> $rev,
3744 my $logged = delete $self->{logged_rev_props
};
3745 if (!$logged || $self->{-want_revprops
}) {
3746 my $rp = $self->ra->rev_proplist($rev);
3747 foreach (sort keys %$rp) {
3749 if (/^svn:(author|date|log)$/) {
3750 $log_entry{$1} = $v;
3751 } elsif ($_ eq 'svm:headrev') {
3754 print $un " rev_prop: ", uri_encode
($_), ' ',
3755 uri_encode
($v), "\n";
3759 map { $log_entry{$_} = $logged->{$_} } keys %$logged;
3761 close $un or croak
$!;
3763 $log_entry{date
} = parse_svn_date
($log_entry{date
});
3764 $log_entry{log} .= "\n";
3765 my $author = $log_entry{author
} = check_author
($log_entry{author
});
3766 my ($name, $email) = defined $::users
{$author} ? @
{$::users
{$author}}
3769 my ($commit_name, $commit_email) = ($name, $email);
3770 if ($_use_log_author) {
3772 if ($log_entry{log} =~ /From:\s+(.*\S)\s*\n/i) {
3774 } elsif ($log_entry{log} =~ /Signed-off-by:\s+(.*\S)\s*\n/i) {
3777 if (!defined $name_field) {
3778 if (!defined $email) {
3781 } elsif ($name_field =~ /(.*?)\s+<(.*)>/) {
3782 ($name, $email) = ($1, $2);
3783 } elsif ($name_field =~ /(.*)@/) {
3784 ($name, $email) = ($1, $name_field);
3786 ($name, $email) = ($name_field, $name_field);
3789 if (defined $headrev && $self->use_svm_props) {
3790 if ($self->rewrite_root) {
3791 die "Can't have both 'useSvmProps' and 'rewriteRoot' ",
3794 if ($self->rewrite_uuid) {
3795 die "Can't have both 'useSvmProps' and 'rewriteUUID' ",
3798 my ($uuid, $r) = $headrev =~ m{^([a-f\d\-]{30,}):(\d
+)$}i
;
3799 # we don't want "SVM: initializing mirror for junk" ...
3800 return undef if $r == 0;
3801 my $svm = $self->svm;
3802 if ($uuid ne $svm->{uuid
}) {
3803 die "UUID mismatch on SVM path:\n",
3804 "expected: $svm->{uuid}\n",
3807 my $full_url = $self->full_url;
3808 $full_url =~ s
#^\Q$svm->{replace}\E(/|$)#$svm->{source}$1# or
3809 die "Failed to replace '$svm->{replace}' with ",
3810 "'$svm->{source}' in $full_url\n";
3811 # throw away username for storing in records
3812 remove_username
($full_url);
3813 $log_entry{metadata
} = "$full_url\@$r $uuid";
3814 $log_entry{svm_revision
} = $r;
3815 $email ||= "$author\@$uuid";
3816 $commit_email ||= "$author\@$uuid";
3817 } elsif ($self->use_svnsync_props) {
3818 my $full_url = $self->svnsync->{url
};
3819 $full_url .= "/$self->{path}" if length $self->{path
};
3820 remove_username
($full_url);
3821 my $uuid = $self->svnsync->{uuid
};
3822 $log_entry{metadata
} = "$full_url\@$rev $uuid";
3823 $email ||= "$author\@$uuid";
3824 $commit_email ||= "$author\@$uuid";
3826 my $url = $self->metadata_url;
3827 remove_username
($url);
3828 my $uuid = $self->rewrite_uuid || $self->ra->get_uuid;
3829 $log_entry{metadata
} = "$url\@$rev " . $uuid;
3830 $email ||= "$author\@" . $uuid;
3831 $commit_email ||= "$author\@" . $uuid;
3833 $log_entry{name
} = $name;
3834 $log_entry{email
} = $email;
3835 $log_entry{commit_name
} = $commit_name;
3836 $log_entry{commit_email
} = $commit_email;
3841 my ($self, $min_rev, $max_rev, @parents) = @_;
3842 my ($last_rev, $last_commit) = $self->last_rev_commit;
3843 my ($base, $head) = $self->get_fetch_range($min_rev, $max_rev);
3844 $self->ra->gs_fetch_loop_common($base, $head, [$self]);
3848 my ($self, $log_entry, $tree, $rev, $date, $author) = @_;
3849 $self->{inject_parents
} = { $rev => $tree };
3850 $self->fetch(undef, undef);
3854 my ($self, $tree) = (shift, shift);
3855 my $log_entry = ::get_commit_entry
($tree);
3856 unless ($self->{last_rev
}) {
3857 ::fatal
("Must have an existing revision to commit");
3859 my %ed_opts = ( r
=> $self->{last_rev
},
3860 log => $log_entry->{log},
3862 tree_a
=> $self->{last_commit
},
3865 $self->set_tree_cb($log_entry, $tree, @_) },
3866 svn_path
=> $self->{path
} );
3867 if (!SVN
::Git
::Editor
->new(\
%ed_opts)->apply_diff) {
3868 print "No changes\nr$self->{last_rev} = $tree\n";
3872 sub rebuild_from_rev_db
{
3873 my ($self, $path) = @_;
3875 open my $fh, '<', $path or croak
"open: $!";
3876 binmode $fh or croak
"binmode: $!";
3878 length($_) == 41 or croak
"inconsistent size in ($_) != 41";
3881 next if $_ eq ('0' x
40);
3882 $self->rev_map_set($r, $_);
3885 close $fh or croak
"close: $!";
3886 unlink $path or croak
"unlink: $!";
3891 my $map_path = $self->map_path;
3892 my $partial = (-e
$map_path && ! -z
$map_path);
3893 return unless ::verify_ref
($self->refname.'^0');
3894 if (!$partial && ($self->use_svm_props || $self->no_metadata)) {
3895 my $rev_db = $self->rev_db_path;
3896 $self->rebuild_from_rev_db($rev_db);
3897 if ($self->use_svm_props) {
3898 my $svm_rev_db = $self->rev_db_path($self->svm_uuid);
3899 $self->rebuild_from_rev_db($svm_rev_db);
3901 $self->unlink_rev_db_symlink;
3904 print "Rebuilding $map_path ...\n" if (!$partial);
3905 my ($base_rev, $head) = ($partial ?
$self->rev_map_max_norebuild(1) :
3908 command_output_pipe
(qw
/rev-list --pretty=raw --no-color --reverse/,
3909 ($head ?
"$head.." : "") . $self->refname,
3911 my $metadata_url = $self->metadata_url;
3912 remove_username
($metadata_url);
3913 my $svn_uuid = $self->rewrite_uuid || $self->ra_uuid;
3916 if ( m{^commit ($::sha1)$} ) {
3920 next unless s{^\s*(git-svn-id:)}{$1};
3921 my ($url, $rev, $uuid) = ::extract_metadata
($_);
3922 remove_username
($url);
3924 # ignore merges (from set-tree)
3925 next if (!defined $rev || !$uuid);
3927 # if we merged or otherwise started elsewhere, this is
3928 # how we break out of it
3929 if (($uuid ne $svn_uuid) ||
3930 ($metadata_url && $url && ($url ne $metadata_url))) {
3933 if ($partial && $head) {
3934 print "Partial-rebuilding $map_path ...\n";
3935 print "Currently at $base_rev = $head\n";
3939 $self->rev_map_set($rev, $c);
3940 print "r$rev = $c\n";
3942 command_close_pipe
($log, $ctx);
3943 print "Done rebuilding $map_path\n" if (!$partial || !$head);
3944 my $rev_db_path = $self->rev_db_path;
3945 if (-f
$self->rev_db_path) {
3946 unlink $self->rev_db_path or croak
"unlink: $!";
3948 $self->unlink_rev_db_symlink;
3952 # Tie::File seems to be prone to offset errors if revisions get sparse,
3953 # it's not that fast, either. Tie::File is also not in Perl 5.6. So
3954 # one of my favorite modules is out :< Next up would be one of the DBM
3955 # modules, but I'm not sure which is most portable...
3957 # This is the replacement for the rev_db format, which was too big
3958 # and inefficient for large repositories with a lot of sparse history
3961 # The format is this:
3962 # - 24 bytes for every record,
3963 # * 4 bytes for the integer representing an SVN revision number
3964 # * 20 bytes representing the sha1 of a git commit
3965 # - No empty padding records like the old format
3966 # (except the last record, which can be overwritten)
3967 # - new records are written append-only since SVN revision numbers
3968 # increase monotonically
3969 # - lookups on SVN revision number are done via a binary search
3970 # - Piping the file to xxd -c24 is a good way of dumping it for
3971 # viewing or editing (piped back through xxd -r), should the need
3973 # - The last record can be padding revision with an all-zero sha1
3974 # This is used to optimize fetch performance when using multiple
3975 # "fetch" directives in .git/config
3977 # These files are disposable unless noMetadata or useSvmProps is set
3980 my ($fh, $rev, $commit) = @_;
3982 binmode $fh or croak
"binmode: $!";
3983 my $size = (stat($fh))[7];
3984 ($size % 24) == 0 or croak
"inconsistent size: $size";
3988 sysseek($fh, -24, SEEK_END
) or croak
"seek: $!";
3989 my $read = sysread($fh, my $buf, 24) or croak
"read: $!";
3990 $read == 24 or croak
"read only $read bytes (!= 24)";
3991 my ($last_rev, $last_commit) = unpack(rev_map_fmt
, $buf);
3992 if ($last_commit eq ('0' x40
)) {
3994 sysseek($fh, -48, SEEK_END
) or croak
"seek: $!";
3995 $read = sysread($fh, $buf, 24) or
3998 croak
"read only $read bytes (!= 24)";
3999 ($last_rev, $last_commit) =
4000 unpack(rev_map_fmt
, $buf);
4001 if ($last_commit eq ('0' x40
)) {
4002 croak
"inconsistent .rev_map\n";
4005 if ($last_rev >= $rev) {
4006 croak
"last_rev is higher!: $last_rev >= $rev";
4011 sysseek($fh, $wr_offset, SEEK_END
) or croak
"seek: $!";
4012 syswrite($fh, pack(rev_map_fmt
, $rev, $commit), 24) == 24 or
4016 sub _rev_map_reset
{
4017 my ($fh, $rev, $commit) = @_;
4018 my $c = _rev_map_get
($fh, $rev);
4019 $c eq $commit or die "_rev_map_reset(@_) commit $c does not match!\n";
4020 my $offset = sysseek($fh, 0, SEEK_CUR
) or croak
"seek: $!";
4021 truncate $fh, $offset or croak
"truncate: $!";
4027 my ($dir, $base) = ($path =~ m
#^(.*?)/?([^/]+)$#);
4028 mkpath
([$dir]) unless -d
$dir;
4029 open my $fh, '>>', $path or die "Couldn't create $path: $!\n";
4030 close $fh or die "Couldn't close (create) $path: $!\n";
4035 my ($self, $rev, $commit, $update_ref, $uuid) = @_;
4036 defined $commit or die "missing arg3\n";
4037 length $commit == 40 or die "arg3 must be a full SHA1 hexsum\n";
4038 my $db = $self->map_path($uuid);
4039 my $db_lock = "$db.lock";
4043 $SIG{INT
} = $SIG{HUP
} = $SIG{TERM
} = $SIG{ALRM
} = $SIG{PIPE
} =
4044 $SIG{USR1
} = $SIG{USR2
} = sub { $sig = $_[0] };
4048 $LOCKFILES{$db_lock} = 1;
4050 # both of these options make our .rev_db file very, very important
4051 # and we can't afford to lose it because rebuild() won't work
4052 if ($self->use_svm_props || $self->no_metadata) {
4054 copy
($db, $db_lock) or die "rev_map_set(@_): ",
4056 "$db => $db_lock ($!)\n";
4058 rename $db, $db_lock or die "rev_map_set(@_): ",
4059 "Failed to rename: ",
4060 "$db => $db_lock ($!)\n";
4063 sysopen(my $fh, $db_lock, O_RDWR
| O_CREAT
)
4064 or croak
"Couldn't open $db_lock: $!\n";
4065 $update_ref eq 'reset' ? _rev_map_reset
($fh, $rev, $commit) :
4066 _rev_map_set
($fh, $rev, $commit);
4068 $fh->flush or die "Couldn't flush $db_lock: $!\n";
4069 $fh->sync or die "Couldn't sync $db_lock: $!\n";
4071 close $fh or croak
$!;
4075 $note = " ($update_ref)" if ($update_ref !~ /^\d*$/);
4076 command_noisy
('update-ref', '-m', "r$rev$note",
4077 $self->refname, $commit);
4079 rename $db_lock, $db or die "rev_map_set(@_): ", "Failed to rename: ",
4080 "$db_lock => $db ($!)\n";
4081 delete $LOCKFILES{$db_lock};
4083 $SIG{INT
} = $SIG{HUP
} = $SIG{TERM
} = $SIG{ALRM
} = $SIG{PIPE
} =
4084 $SIG{USR1
} = $SIG{USR2
} = 'DEFAULT';
4085 kill $sig, $$ if defined $sig;
4089 # If want_commit, this will return an array of (rev, commit) where
4090 # commit _must_ be a valid commit in the archive.
4091 # Otherwise, it'll return the max revision (whether or not the
4092 # commit is valid or just a 0x40 placeholder).
4094 my ($self, $want_commit) = @_;
4096 my ($r, $c) = $self->rev_map_max_norebuild($want_commit);
4097 $want_commit ?
($r, $c) : $r;
4100 sub rev_map_max_norebuild
{
4101 my ($self, $want_commit) = @_;
4102 my $map_path = $self->map_path;
4103 stat $map_path or return $want_commit ?
(0, undef) : 0;
4104 sysopen(my $fh, $map_path, O_RDONLY
) or croak
"open: $!";
4105 binmode $fh or croak
"binmode: $!";
4106 my $size = (stat($fh))[7];
4107 ($size % 24) == 0 or croak
"inconsistent size: $size";
4110 close $fh or croak
"close: $!";
4111 return $want_commit ?
(0, undef) : 0;
4114 sysseek($fh, -24, SEEK_END
) or croak
"seek: $!";
4115 sysread($fh, my $buf, 24) == 24 or croak
"read: $!";
4116 my ($r, $c) = unpack(rev_map_fmt
, $buf);
4117 if ($want_commit && $c eq ('0' x40
)) {
4119 return $want_commit ?
(0, undef) : 0;
4121 sysseek($fh, -48, SEEK_END
) or croak
"seek: $!";
4122 sysread($fh, $buf, 24) == 24 or croak
"read: $!";
4123 ($r, $c) = unpack(rev_map_fmt
, $buf);
4124 if ($c eq ('0'x40
)) {
4125 croak
"Penultimate record is all-zeroes in $map_path";
4128 close $fh or croak
"close: $!";
4129 $want_commit ?
($r, $c) : $r;
4133 my ($self, $rev, $uuid) = @_;
4134 my $map_path = $self->map_path($uuid);
4135 return undef unless -e
$map_path;
4137 sysopen(my $fh, $map_path, O_RDONLY
) or croak
"open: $!";
4138 my $c = _rev_map_get
($fh, $rev);
4139 close($fh) or croak
"close: $!";
4144 my ($fh, $rev) = @_;
4146 binmode $fh or croak
"binmode: $!";
4147 my $size = (stat($fh))[7];
4148 ($size % 24) == 0 or croak
"inconsistent size: $size";
4154 my ($l, $u) = (0, $size - 24);
4158 my $i = int(($l/24 + $u/24) / 2) * 24;
4159 sysseek($fh, $i, SEEK_SET
) or croak
"seek: $!";
4160 sysread($fh, my $buf, 24) == 24 or croak
"read: $!";
4161 my ($r, $c) = unpack(rev_map_fmt
, $buf);
4165 } elsif ($r > $rev) {
4167 } else { # $r == $rev
4168 return $c eq ('0' x
40) ?
undef : $c;
4174 # Finds the first svn revision that exists on (if $eq_ok is true) or
4175 # before $rev for the current branch. It will not search any lower
4176 # than $min_rev. Returns the git commit hash and svn revision number
4177 # if found, else (undef, undef).
4178 sub find_rev_before
{
4179 my ($self, $rev, $eq_ok, $min_rev) = @_;
4180 --$rev unless $eq_ok;
4182 my $max_rev = $self->rev_map_max;
4183 $rev = $max_rev if ($rev > $max_rev);
4184 while ($rev >= $min_rev) {
4185 if (my $c = $self->rev_map_get($rev)) {
4190 return (undef, undef);
4193 # Finds the first svn revision that exists on (if $eq_ok is true) or
4194 # after $rev for the current branch. It will not search any higher
4195 # than $max_rev. Returns the git commit hash and svn revision number
4196 # if found, else (undef, undef).
4197 sub find_rev_after
{
4198 my ($self, $rev, $eq_ok, $max_rev) = @_;
4199 ++$rev unless $eq_ok;
4200 $max_rev ||= $self->rev_map_max;
4201 while ($rev <= $max_rev) {
4202 if (my $c = $self->rev_map_get($rev)) {
4207 return (undef, undef);
4211 my ($class, $repo_id, $ref_id, $path) = @_;
4212 unless (defined $repo_id && length $repo_id) {
4213 $repo_id = $Git::SVN
::default_repo_id
;
4215 unless (defined $ref_id && length $ref_id) {
4216 $_prefix = '' unless defined($_prefix);
4218 "refs/remotes/$_prefix$Git::SVN::default_ref_id";
4221 my $dir = "$ENV{GIT_DIR}/svn/$ref_id";
4223 # Older repos imported by us used $GIT_DIR/svn/foo instead of
4224 # $GIT_DIR/svn/refs/remotes/foo when tracking refs/remotes/foo
4225 if ($ref_id =~ m{^refs/remotes/(.*)}) {
4226 my $old_dir = "$ENV{GIT_DIR}/svn/$1";
4227 if (-d
$old_dir && ! -d
$dir) {
4232 $_[3] = $path = '' unless (defined $path);
4235 ref_id
=> $ref_id, dir
=> $dir, index => "$dir/index",
4236 path
=> $path, config
=> "$ENV{GIT_DIR}/svn/config",
4237 map_root
=> "$dir/.rev_map", repo_id
=> $repo_id }, $class;
4240 # for read-only access of old .rev_db formats
4241 sub unlink_rev_db_symlink
{
4243 my $link = $self->rev_db_path;
4244 $link =~ s/\.[\w-]+$// or croak
"missing UUID at the end of $link";
4246 unlink $link or croak
"unlink: $link failed!";
4251 my ($self, $uuid) = @_;
4252 my $db_path = $self->map_path($uuid);
4253 $db_path =~ s{/\.rev_map\.}{/\.rev_db\.}
4254 or croak
"map_path: $db_path does not contain '/.rev_map.' !";
4258 # the new replacement for .rev_db
4260 my ($self, $uuid) = @_;
4261 $uuid ||= $self->ra_uuid;
4262 "$self->{map_root}.$uuid";
4267 $f =~ s
#([^a-zA-Z0-9\*!\:_\./\-])#uc sprintf("%%%02x",ord($1))#eg;
4273 $f =~ s
#%([0-9a-fA-F]{2})#chr(hex($1))#eg;
4277 sub remove_username
{
4278 $_[0] =~ s{^([^:]*://)[^@]+@}{$1};
4281 package Git
::SVN
::Prompt
;
4285 use vars qw
/$_no_auth_cache $_username/;
4288 my ($cred, $realm, $default_username, $may_save, $pool) = @_;
4289 $may_save = undef if $_no_auth_cache;
4290 $default_username = $_username if defined $_username;
4291 if (defined $default_username && length $default_username) {
4292 if (defined $realm && length $realm) {
4293 print STDERR
"Authentication realm: $realm\n";
4296 $cred->username($default_username);
4298 username
($cred, $realm, $may_save, $pool);
4300 $cred->password(_read_password
("Password for '" .
4301 $cred->username . "': ", $realm));
4302 $cred->may_save($may_save);
4303 $SVN::_Core
::SVN_NO_ERROR
;
4306 sub ssl_server_trust
{
4307 my ($cred, $realm, $failures, $cert_info, $may_save, $pool) = @_;
4308 $may_save = undef if $_no_auth_cache;
4309 print STDERR
"Error validating server certificate for '$realm':\n";
4312 # All variables SVN::Auth::SSL::* are used only once,
4313 # so we're shutting up Perl warnings about this.
4314 if ($failures & $SVN::Auth
::SSL
::UNKNOWNCA
) {
4315 print STDERR
" - The certificate is not issued ",
4316 "by a trusted authority. Use the\n",
4317 " fingerprint to validate ",
4318 "the certificate manually!\n";
4320 if ($failures & $SVN::Auth
::SSL
::CNMISMATCH
) {
4321 print STDERR
" - The certificate hostname ",
4322 "does not match.\n";
4324 if ($failures & $SVN::Auth
::SSL
::NOTYETVALID
) {
4325 print STDERR
" - The certificate is not yet valid.\n";
4327 if ($failures & $SVN::Auth
::SSL
::EXPIRED
) {
4328 print STDERR
" - The certificate has expired.\n";
4330 if ($failures & $SVN::Auth
::SSL
::OTHER
) {
4331 print STDERR
" - The certificate has ",
4332 "an unknown error.\n";
4334 } # no warnings 'once'
4336 "Certificate information:\n".
4337 " - Hostname: %s\n".
4338 " - Valid: from %s until %s\n".
4340 " - Fingerprint: %s\n",
4341 map $cert_info->$_, qw(hostname valid_from valid_until
4342 issuer_dname fingerprint);
4345 print STDERR
$may_save ?
4346 "(R)eject, accept (t)emporarily or accept (p)ermanently? " :
4347 "(R)eject or accept (t)emporarily? ";
4349 $choice = lc(substr(<STDIN
> || 'R', 0, 1));
4350 if ($choice =~ /^t$/i) {
4351 $cred->may_save(undef);
4352 } elsif ($choice =~ /^r$/i) {
4354 } elsif ($may_save && $choice =~ /^p$/i) {
4355 $cred->may_save($may_save);
4359 $cred->accepted_failures($failures);
4360 $SVN::_Core
::SVN_NO_ERROR
;
4363 sub ssl_client_cert
{
4364 my ($cred, $realm, $may_save, $pool) = @_;
4365 $may_save = undef if $_no_auth_cache;
4366 print STDERR
"Client certificate filename: ";
4368 chomp(my $filename = <STDIN
>);
4369 $cred->cert_file($filename);
4370 $cred->may_save($may_save);
4371 $SVN::_Core
::SVN_NO_ERROR
;
4374 sub ssl_client_cert_pw
{
4375 my ($cred, $realm, $may_save, $pool) = @_;
4376 $may_save = undef if $_no_auth_cache;
4377 $cred->password(_read_password
("Password: ", $realm));
4378 $cred->may_save($may_save);
4379 $SVN::_Core
::SVN_NO_ERROR
;
4383 my ($cred, $realm, $may_save, $pool) = @_;
4384 $may_save = undef if $_no_auth_cache;
4385 if (defined $realm && length $realm) {
4386 print STDERR
"Authentication realm: $realm\n";
4389 if (defined $_username) {
4390 $username = $_username;
4392 print STDERR
"Username: ";
4394 chomp($username = <STDIN
>);
4396 $cred->username($username);
4397 $cred->may_save($may_save);
4398 $SVN::_Core
::SVN_NO_ERROR
;
4401 sub _read_password
{
4402 my ($prompt, $realm) = @_;
4404 if (exists $ENV{GIT_ASKPASS
}) {
4405 open(PH
, "-|", $ENV{GIT_ASKPASS
}, $prompt);
4407 $password =~ s/[\012\015]//; # \n\r
4410 print STDERR
$prompt;
4412 require Term
::ReadKey
;
4413 Term
::ReadKey
::ReadMode
('noecho');
4414 while (defined(my $key = Term
::ReadKey
::ReadKey
(0))) {
4415 last if $key =~ /[\012\015]/; # \n\r
4418 Term
::ReadKey
::ReadMode
('restore');
4425 package SVN
::Git
::Fetcher
;
4426 use vars qw
/@ISA $_ignore_regex $_preserve_empty_dirs $_placeholder_filename
4427 @deleted_gpath %added_placeholder $repo_id/;
4431 use File
::Basename qw
/dirname/;
4434 # file baton members: path, mode_a, mode_b, pool, fh, blob, base
4436 my ($class, $git_svn, $switch_path) = @_;
4437 my $self = SVN
::Delta
::Editor
->new;
4438 bless $self, $class;
4439 if (exists $git_svn->{last_commit
}) {
4440 $self->{c
} = $git_svn->{last_commit
};
4441 $self->{empty_symlinks
} =
4442 _mark_empty_symlinks
($git_svn, $switch_path);
4445 # some options are read globally, but can be overridden locally
4446 # per [svn-remote "..."] section. Command-line options will *NOT*
4447 # override options set in an [svn-remote "..."] section
4448 $repo_id = $git_svn->{repo_id
};
4449 my $k = "svn-remote.$repo_id.ignore-paths";
4450 my $v = eval { command_oneline
('config', '--get', $k) };
4451 $self->{ignore_regex
} = $v;
4453 $k = "svn-remote.$repo_id.preserve-empty-dirs";
4454 $v = eval { command_oneline
('config', '--get', '--bool', $k) };
4455 if ($v && $v eq 'true') {
4456 $_preserve_empty_dirs = 1;
4457 $k = "svn-remote.$repo_id.placeholder-filename";
4458 $v = eval { command_oneline
('config', '--get', $k) };
4459 $_placeholder_filename = $v;
4462 # Load the list of placeholder files added during previous invocations.
4463 $k = "svn-remote.$repo_id.added-placeholder";
4464 $v = eval { command_oneline
('config', '--get-all', $k) };
4465 if ($_preserve_empty_dirs && $v) {
4466 # command() prints errors to stderr, so we only call it if
4467 # command_oneline() succeeded.
4468 my @v = command
('config', '--get-all', $k);
4469 $added_placeholder{ dirname
($_) } = $_ foreach @v;
4472 $self->{empty
} = {};
4473 $self->{dir_prop
} = {};
4474 $self->{file_prop
} = {};
4475 $self->{absent_dir
} = {};
4476 $self->{absent_file
} = {};
4477 $self->{gii
} = $git_svn->tmp_index_do(sub { Git
::IndexInfo
->new });
4478 $self->{pathnameencoding
} = Git
::config
('svn.pathnameencoding');
4482 # this uses the Ra object, so it must be called before do_{switch,update},
4483 # not inside them (when the Git::SVN::Fetcher object is passed) to
4484 # do_{switch,update}
4485 sub _mark_empty_symlinks
{
4486 my ($git_svn, $switch_path) = @_;
4487 my $bool = Git
::config_bool
('svn.brokenSymlinkWorkaround');
4488 return {} if (!defined($bool)) || (defined($bool) && ! $bool);
4491 my ($rev, $cmt) = $git_svn->last_rev_commit;
4492 return {} unless ($rev && $cmt);
4494 # allow the warning to be printed for each revision we fetch to
4495 # ensure the user sees it. The user can also disable the workaround
4496 # on the repository even while git svn is running and the next
4497 # revision fetched will skip this expensive function.
4498 my $printed_warning;
4499 chomp(my $empty_blob = `git hash-object -t blob --stdin < /dev/null`);
4500 my ($ls, $ctx) = command_output_pipe
(qw
/ls-tree -r -z/, $cmt);
4502 my $pfx = defined($switch_path) ?
$switch_path : $git_svn->{path
};
4503 $pfx .= '/' if length($pfx);
4506 s/\A100644 blob $empty_blob\t//o or next;
4507 unless ($printed_warning) {
4508 print STDERR
"Scanning for empty symlinks, ",
4509 "this may take a while if you have ",
4510 "many empty files\n",
4511 "You may disable this with `",
4512 "git config svn.brokenSymlinkWorkaround ",
4514 "This may be done in a different ",
4515 "terminal without restarting ",
4517 $printed_warning = 1;
4520 my (undef, $props) =
4521 $git_svn->ra->get_file($pfx.$path, $rev, undef);
4522 if ($props->{'svn:special'}) {
4526 command_close_pipe
($ls, $ctx);
4530 # returns true if a given path is inside a ".git" directory
4532 $_[0] =~ m{(?:^|/)\.git(?:/|$)};
4535 # return value: 0 -- don't ignore, 1 -- ignore
4536 sub is_path_ignored
{
4537 my ($self, $path) = @_;
4538 return 1 if in_dot_git
($path);
4539 return 1 if defined($self->{ignore_regex
}) &&
4540 $path =~ m!$self->{ignore_regex}!;
4541 return 0 unless defined($_ignore_regex);
4542 return 1 if $path =~ m!$_ignore_regex!o;
4546 sub set_path_strip
{
4547 my ($self, $path) = @_;
4548 $self->{path_strip
} = qr/^\Q$path\E(\/|$)/ if length $path;
4555 sub open_directory
{
4556 my ($self, $path, $pb, $rev) = @_;
4561 my ($self, $path) = @_;
4562 if (my $enc = $self->{pathnameencoding
}) {
4564 Encode
::from_to
($path, 'UTF-8', $enc);
4566 if ($self->{path_strip
}) {
4567 $path =~ s!$self->{path_strip}!! or
4568 die "Failed to strip path '$path' ($self->{path_strip})\n";
4574 my ($self, $path, $rev, $pb) = @_;
4575 return undef if $self->is_path_ignored($path);
4577 my $gpath = $self->git_path($path);
4578 return undef if ($gpath eq '');
4580 # remove entire directories.
4581 my ($tree) = (command
('ls-tree', '-z', $self->{c
}, "./$gpath")
4582 =~ /\A040000 tree ([a-f\d]{40})\t\Q$gpath\E\0/);
4584 my ($ls, $ctx) = command_output_pipe
(qw
/ls
-tree
4590 my $rmpath = "$gpath/$_";
4591 $self->{gii
}->remove($rmpath);
4592 print "\tD\t$rmpath\n" unless $::_q
;
4594 print "\tD\t$gpath/\n" unless $::_q
;
4595 command_close_pipe
($ls, $ctx);
4597 $self->{gii
}->remove($gpath);
4598 print "\tD\t$gpath\n" unless $::_q
;
4600 # Don't add to @deleted_gpath if we're deleting a placeholder file.
4601 push @deleted_gpath, $gpath unless $added_placeholder{dirname
($path)};
4602 $self->{empty
}->{$path} = 0;
4607 my ($self, $path, $pb, $rev) = @_;
4610 goto out
if $self->is_path_ignored($path);
4612 my $gpath = $self->git_path($path);
4613 ($mode, $blob) = (command
('ls-tree', '-z', $self->{c
}, "./$gpath")
4614 =~ /\A(\d{6}) blob ([a-f\d]{40})\t\Q$gpath\E\0/);
4615 unless (defined $mode && defined $blob) {
4616 die "$path was not found in commit $self->{c} (r$rev)\n";
4618 if ($mode eq '100644' && $self->{empty_symlinks
}->{$path}) {
4622 { path
=> $path, mode_a
=> $mode, mode_b
=> $mode, blob
=> $blob,
4623 pool
=> SVN
::Pool
->new, action
=> 'M' };
4627 my ($self, $path, $pb, $cp_path, $cp_rev) = @_;
4630 if (!$self->is_path_ignored($path)) {
4631 my ($dir, $file) = ($path =~ m
#^(.*?)/?([^/]+)$#);
4632 delete $self->{empty
}->{$dir};
4635 if ($added_placeholder{$dir}) {
4636 # Remove our placeholder file, if we created one.
4637 delete_entry
($self, $added_placeholder{$dir})
4638 unless $path eq $added_placeholder{$dir};
4639 delete $added_placeholder{$dir}
4643 { path
=> $path, mode_a
=> $mode, mode_b
=> $mode,
4644 pool
=> SVN
::Pool
->new, action
=> 'A' };
4648 my ($self, $path, $cp_path, $cp_rev) = @_;
4649 goto out
if $self->is_path_ignored($path);
4650 my $gpath = $self->git_path($path);
4652 my ($ls, $ctx) = command_output_pipe
(qw
/ls
-tree
4658 $self->{gii
}->remove($_);
4659 print "\tD\t$_\n" unless $::_q
;
4660 push @deleted_gpath, $gpath;
4662 command_close_pipe
($ls, $ctx);
4663 $self->{empty
}->{$path} = 0;
4665 my ($dir, $file) = ($path =~ m
#^(.*?)/?([^/]+)$#);
4666 delete $self->{empty
}->{$dir};
4667 $self->{empty
}->{$path} = 1;
4669 if ($added_placeholder{$dir}) {
4670 # Remove our placeholder file, if we created one.
4671 delete_entry
($self, $added_placeholder{$dir});
4672 delete $added_placeholder{$dir}
4679 sub change_dir_prop
{
4680 my ($self, $db, $prop, $value) = @_;
4681 return undef if $self->is_path_ignored($db->{path
});
4682 $self->{dir_prop
}->{$db->{path
}} ||= {};
4683 $self->{dir_prop
}->{$db->{path
}}->{$prop} = $value;
4687 sub absent_directory
{
4688 my ($self, $path, $pb) = @_;
4689 return undef if $self->is_path_ignored($path);
4690 $self->{absent_dir
}->{$pb->{path
}} ||= [];
4691 push @
{$self->{absent_dir
}->{$pb->{path
}}}, $path;
4696 my ($self, $path, $pb) = @_;
4697 return undef if $self->is_path_ignored($path);
4698 $self->{absent_file
}->{$pb->{path
}} ||= [];
4699 push @
{$self->{absent_file
}->{$pb->{path
}}}, $path;
4703 sub change_file_prop
{
4704 my ($self, $fb, $prop, $value) = @_;
4705 return undef if $self->is_path_ignored($fb->{path
});
4706 if ($prop eq 'svn:executable') {
4707 if ($fb->{mode_b
} != 120000) {
4708 $fb->{mode_b
} = defined $value ?
100755 : 100644;
4710 } elsif ($prop eq 'svn:special') {
4711 $fb->{mode_b
} = defined $value ?
120000 : 100644;
4713 $self->{file_prop
}->{$fb->{path
}} ||= {};
4714 $self->{file_prop
}->{$fb->{path
}}->{$prop} = $value;
4719 sub apply_textdelta
{
4720 my ($self, $fb, $exp) = @_;
4721 return undef if $self->is_path_ignored($fb->{path
});
4722 my $fh = $::_repository
->temp_acquire('svn_delta');
4723 # $fh gets auto-closed() by SVN::TxDelta::apply(),
4724 # (but $base does not,) so dup() it for reading in close_file
4725 open my $dup, '<&', $fh or croak
$!;
4726 my $base = $::_repository
->temp_acquire('git_blob');
4729 my ($base_is_link, $size);
4731 if ($fb->{mode_a
} eq '120000' &&
4732 ! $self->{empty_symlinks
}->{$fb->{path
}}) {
4733 print $base 'link ' or die "print $!\n";
4737 $size = $::_repository
->cat_blob($fb->{blob
}, $base);
4738 die "Failed to read object $fb->{blob}" if ($size < 0);
4741 seek $base, 0, 0 or croak
$!;
4742 my $got = ::md5sum
($base);
4744 my $err = "Checksum mismatch: ".
4745 "$fb->{path} $fb->{blob}\n" .
4746 "expected: $exp\n" .
4748 if ($base_is_link) {
4750 "Retrying... (possibly ",
4751 "a bad symlink from SVN)\n";
4752 $::_repository
->temp_reset($base);
4760 seek $base, 0, 0 or croak
$!;
4762 $fb->{base
} = $base;
4763 [ SVN
::TxDelta
::apply
($base, $dup, undef, $fb->{path
}, $fb->{pool
}) ];
4767 my ($self, $fb, $exp) = @_;
4768 return undef if $self->is_path_ignored($fb->{path
});
4771 my $path = $self->git_path($fb->{path
});
4772 if (my $fh = $fb->{fh
}) {
4774 seek($fh, 0, 0) or croak
$!;
4775 my $got = ::md5sum
($fh);
4777 die "Checksum mismatch: $path\n",
4778 "expected: $exp\n got: $got\n";
4781 if ($fb->{mode_b
} == 120000) {
4782 sysseek($fh, 0, 0) or croak
$!;
4783 my $rd = sysread($fh, my $buf, 5);
4786 croak
"sysread: $!\n";
4787 } elsif ($rd == 0) {
4788 warn "$path has mode 120000",
4789 " but it points to nothing\n",
4790 "converting to an empty file with mode",
4792 $fb->{mode_b
} = '100644';
4793 } elsif ($buf ne 'link ') {
4794 warn "$path has mode 120000",
4795 " but is not a link\n";
4797 my $tmp_fh = $::_repository
->temp_acquire(
4800 while ($res = sysread($fh, my $str, 1024)) {
4801 my $out = syswrite($tmp_fh, $str, $res);
4802 defined($out) && $out == $res
4804 Git
::temp_path
($tmp_fh),
4807 defined $res or croak
$!;
4809 ($fh, $tmp_fh) = ($tmp_fh, $fh);
4810 Git
::temp_release
($tmp_fh, 1);
4814 $hash = $::_repository
->hash_and_insert_object(
4815 Git
::temp_path
($fh));
4816 $hash =~ /^[a-f\d]{40}$/ or die "not a sha1: $hash\n";
4818 Git
::temp_release
($fb->{base
}, 1);
4819 Git
::temp_release
($fh, 1);
4821 $hash = $fb->{blob
} or die "no blob information\n";
4824 $self->{gii
}->update($fb->{mode_b
}, $hash, $path) or croak
$!;
4825 print "\t$fb->{action}\t$path\n" if $fb->{action
} && ! $::_q
;
4831 $self->{nr
} = $self->{gii
}->{nr
};
4832 delete $self->{gii
};
4833 $self->SUPER::abort_edit
(@_);
4839 if ($_preserve_empty_dirs) {
4842 # Any entry flagged as empty that also has an associated
4843 # dir_prop represents a newly created empty directory.
4844 foreach my $i (keys %{$self->{empty
}}) {
4845 push @empty_dirs, $i if exists $self->{dir_prop
}->{$i};
4848 # Search for directories that have become empty due subsequent
4850 push @empty_dirs, $self->find_empty_directories();
4852 # Finally, add a placeholder file to each empty directory.
4853 $self->add_placeholder_file($_) foreach (@empty_dirs);
4855 $self->stash_placeholder_list();
4858 $self->{git_commit_ok
} = 1;
4859 $self->{nr
} = $self->{gii
}->{nr
};
4860 delete $self->{gii
};
4861 $self->SUPER::close_edit
(@_);
4864 sub find_empty_directories
{
4867 my %dirs = map { dirname
($_) => 1 } @deleted_gpath;
4869 foreach my $dir (sort keys %dirs) {
4870 next if $dir eq ".";
4872 # If there have been any additions to this directory, there is
4873 # no reason to check if it is empty.
4875 foreach my $t (qw
/dir_prop file_prop/) {
4876 foreach my $path (keys %{ $self->{$t} }) {
4877 if (exists $self->{$t}->{dirname
($path)}) {
4882 last if $skip_added;
4884 next if $skip_added;
4886 # Use `git ls-tree` to get the filenames of this directory
4887 # that existed prior to this particular commit.
4888 my $ls = command
('ls-tree', '-z', '--name-only',
4889 $self->{c
}, "$dir/");
4890 my %files = map { $_ => 1 } split(/\0/, $ls);
4892 # Remove the filenames that were deleted during this commit.
4893 delete $files{$_} foreach (@deleted_gpath);
4895 # Report the directory if there are no filenames left.
4896 push @empty_dirs, $dir unless (scalar %files);
4901 sub add_placeholder_file
{
4902 my ($self, $dir) = @_;
4903 my $path = "$dir/$_placeholder_filename";
4904 my $gpath = $self->git_path($path);
4906 my $fh = $::_repository
->temp_acquire($gpath);
4907 my $hash = $::_repository
->hash_and_insert_object(Git
::temp_path
($fh));
4908 Git
::temp_release
($fh, 1);
4909 $self->{gii
}->update('100644', $hash, $gpath) or croak
$!;
4911 # The directory should no longer be considered empty.
4912 delete $self->{empty
}->{$dir} if exists $self->{empty
}->{$dir};
4914 # Keep track of any placeholder files we create.
4915 $added_placeholder{$dir} = $path;
4918 sub stash_placeholder_list
{
4920 my $k = "svn-remote.$repo_id.added-placeholder";
4921 my $v = eval { command_oneline
('config', '--get-all', $k) };
4922 command_noisy
('config', '--unset-all', $k) if $v;
4923 foreach (values %added_placeholder) {
4924 command_noisy
('config', '--add', $k, $_);
4928 package SVN
::Git
::Editor
;
4929 use vars qw
/@ISA $_rmdir $_cp_similarity $_find_copies_harder $_rename_limit/;
4936 my ($class, $opts) = @_;
4937 foreach (qw
/svn_path r ra tree_a tree_b log editor_cb/) {
4938 die "$_ required!\n" unless (defined $opts->{$_});
4941 my $pool = SVN
::Pool
->new;
4942 my $mods = generate_diff
($opts->{tree_a
}, $opts->{tree_b
});
4943 my $types = check_diff_paths
($opts->{ra
}, $opts->{svn_path
},
4946 # $opts->{ra} functions should not be used after this:
4947 my @ce = $opts->{ra
}->get_commit_editor($opts->{log},
4948 $opts->{editor_cb
}, $pool);
4949 my $self = SVN
::Delta
::Editor
->new(@ce, $pool);
4950 bless $self, $class;
4951 foreach (qw
/svn_path r tree_a tree_b/) {
4952 $self->{$_} = $opts->{$_};
4954 $self->{url
} = $opts->{ra
}->{url
};
4955 $self->{mods
} = $mods;
4956 $self->{types
} = $types;
4957 $self->{pool
} = $pool;
4958 $self->{bat
} = { '' => $self->open_root($self->{r
}, $self->{pool
}) };
4960 $self->{path_prefix
} = length $self->{svn_path
} ?
4961 "$self->{svn_path}/" : '';
4962 $self->{config
} = $opts->{config
};
4963 $self->{mergeinfo
} = $opts->{mergeinfo
};
4968 my ($tree_a, $tree_b) = @_;
4969 my @diff_tree = qw(diff-tree -z -r);
4970 if ($_cp_similarity) {
4971 push @diff_tree, "-C$_cp_similarity";
4973 push @diff_tree, '-C';
4975 push @diff_tree, '--find-copies-harder' if $_find_copies_harder;
4976 push @diff_tree, "-l$_rename_limit" if defined $_rename_limit;
4977 push @diff_tree, $tree_a, $tree_b;
4978 my ($diff_fh, $ctx) = command_output_pipe
(@diff_tree);
4982 while (<$diff_fh>) {
4983 chomp $_; # this gets rid of the trailing "\0"
4984 if ($state eq 'meta' && /^:(\d
{6})\s
(\d
{6})\s
4985 ($::sha1
)\s
($::sha1
)\s
4986 ([MTCRAD
])\d
*$/xo
) {
4987 push @mods, { mode_a
=> $1, mode_b
=> $2,
4988 sha1_a
=> $3, sha1_b
=> $4,
4990 if ($5 =~ /^(?:C|R)$/) {
4995 } elsif ($state eq 'file_a') {
4996 my $x = $mods[$#mods] or croak
"Empty array\n";
4997 if ($x->{chg
} !~ /^(?:C|R)$/) {
4998 croak
"Error parsing $_, $x->{chg}\n";
5002 } elsif ($state eq 'file_b') {
5003 my $x = $mods[$#mods] or croak
"Empty array\n";
5004 if (exists $x->{file_a
} && $x->{chg
} !~ /^(?:C|R)$/) {
5005 croak
"Error parsing $_, $x->{chg}\n";
5007 if (!exists $x->{file_a
} && $x->{chg
} =~ /^(?:C|R)$/) {
5008 croak
"Error parsing $_, $x->{chg}\n";
5013 croak
"Error parsing $_\n";
5016 command_close_pipe
($diff_fh, $ctx);
5020 sub check_diff_paths
{
5021 my ($ra, $pfx, $rev, $mods) = @_;
5023 $pfx .= '/' if length $pfx;
5025 sub type_diff_paths
{
5026 my ($ra, $types, $path, $rev) = @_;
5027 my @p = split m
#/+#, $path;
5029 unless (defined $types->{$c}) {
5030 $types->{$c} = $ra->check_path($c, $rev);
5033 $c .= '/' . shift @p;
5034 next if defined $types->{$c};
5035 $types->{$c} = $ra->check_path($c, $rev);
5039 foreach my $m (@
$mods) {
5040 foreach my $f (qw
/file_a file_b/) {
5041 next unless defined $m->{$f};
5042 my ($dir) = ($m->{$f} =~ m
#^(.*?)/?(?:[^/]+)$#);
5043 if (length $pfx.$dir && ! defined $types{$dir}) {
5044 type_diff_paths
($ra, \
%types, $pfx.$dir, $rev);
5052 return ($_[0] =~ m
#^(.*?)/?([^/]+)$#);
5056 my ($self, $path) = @_;
5057 if (my $enc = $self->{pathnameencoding
}) {
5059 Encode
::from_to
($path, $enc, 'UTF-8');
5061 $self->{path_prefix
}.(defined $path ?
$path : '');
5065 my ($self, $path) = @_;
5066 if ($self->{url
} =~ m
#^https?://#) {
5067 $path =~ s!([^~a-zA-Z0-9_./-])!uc sprintf("%%%02x",ord($1))!eg;
5069 $self->{url
} . '/' . $self->repo_path($path);
5074 my $rm = $self->{rm
};
5075 delete $rm->{''}; # we never delete the url we're tracking
5078 foreach (keys %$rm) {
5079 my @d = split m
#/#, $_;
5083 $c .= '/' . shift @d;
5087 delete $rm->{$self->{svn_path
}};
5088 delete $rm->{''}; # we never delete the url we're tracking
5091 my ($fh, $ctx) = command_output_pipe
(qw
/ls-tree --name-only -r -z/,
5096 my @dn = split m
#/#, $_;
5098 delete $rm->{join '/', @dn};
5105 command_close_pipe
($fh, $ctx);
5107 my ($r, $p, $bat) = ($self->{r
}, $self->{pool
}, $self->{bat
});
5108 foreach my $d (sort { $b =~ tr
#/#/# <=> $a =~ tr#/#/# } keys %$rm) {
5109 $self->close_directory($bat->{$d}, $p);
5110 my ($dn) = ($d =~ m
#^(.*?)/?(?:[^/]+)$#);
5111 print "\tD+\t$d/\n" unless $::_q
;
5112 $self->SUPER::delete_entry
($d, $r, $bat->{$dn}, $p);
5117 sub open_or_add_dir
{
5118 my ($self, $full_path, $baton) = @_;
5119 my $t = $self->{types
}->{$full_path};
5121 die "$full_path not known in r$self->{r} or we have a bug!\n";
5125 # SVN::Node::none and SVN::Node::file are used only once,
5126 # so we're shutting up Perl's warnings about them.
5127 if ($t == $SVN::Node
::none
) {
5128 return $self->add_directory($full_path, $baton,
5129 undef, -1, $self->{pool
});
5130 } elsif ($t == $SVN::Node
::dir
) {
5131 return $self->open_directory($full_path, $baton,
5132 $self->{r
}, $self->{pool
});
5133 } # no warnings 'once'
5134 print STDERR
"$full_path already exists in repository at ",
5135 "r$self->{r} and it is not a directory (",
5136 ($t == $SVN::Node
::file ?
'file' : 'unknown'),"/$t)\n";
5137 } # no warnings 'once'
5142 my ($self, $path) = @_;
5143 my $bat = $self->{bat
};
5144 my $repo_path = $self->repo_path($path);
5145 return $bat->{''} unless (length $repo_path);
5146 my @p = split m
#/+#, $repo_path;
5148 $bat->{$c} ||= $self->open_or_add_dir($c, $bat->{''});
5151 $c .= '/' . shift @p;
5152 $bat->{$c} ||= $self->open_or_add_dir($c, $bat->{$c0});
5157 # Subroutine to convert a globbing pattern to a regular expression.
5158 # From perl cookbook.
5160 my $globstr = shift;
5161 my %patmap = ('*' => '.*', '?' => '.', '[' => '[', ']' => ']');
5162 $globstr =~ s{(.)} { $patmap{$1} || "\Q$1" }ge;
5163 return '^' . $globstr . '$';
5166 sub check_autoprop
{
5167 my ($self, $pattern, $properties, $file, $fbat) = @_;
5168 # Convert the globbing pattern to a regular expression.
5169 my $regex = glob2pat
($pattern);
5170 # Check if the pattern matches the file name.
5171 if($file =~ m/($regex)/) {
5172 # Parse the list of properties to set.
5173 my @props = split(/;/, $properties);
5174 foreach my $prop (@props) {
5175 # Parse 'name=value' syntax and set the property.
5176 if ($prop =~ /([^=]+)=(.*)/) {
5177 my ($n,$v) = ($1,$2);
5181 $self->change_file_prop($fbat, $n, $v);
5187 sub apply_autoprops
{
5188 my ($self, $file, $fbat) = @_;
5189 my $conf_t = ${$self->{config
}}{'config'};
5191 # Check [miscellany]/enable-auto-props in svn configuration.
5192 if (SVN
::_Core
::svn_config_get_bool
(
5194 $SVN::_Core
::SVN_CONFIG_SECTION_MISCELLANY
,
5195 $SVN::_Core
::SVN_CONFIG_OPTION_ENABLE_AUTO_PROPS
,
5197 # Auto-props are enabled. Enumerate them to look for matches.
5198 my $callback = sub {
5199 $self->check_autoprop($_[0], $_[1], $file, $fbat);
5201 SVN
::_Core
::svn_config_enumerate
(
5203 $SVN::_Core
::SVN_CONFIG_SECTION_AUTO_PROPS
,
5209 my ($self, $m) = @_;
5210 my ($dir, $file) = split_path
($m->{file_b
});
5211 my $pbat = $self->ensure_path($dir);
5212 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
5214 print "\tA\t$m->{file_b}\n" unless $::_q
;
5215 $self->apply_autoprops($file, $fbat);
5216 $self->chg_file($fbat, $m);
5217 $self->close_file($fbat,undef,$self->{pool
});
5221 my ($self, $m) = @_;
5222 my ($dir, $file) = split_path
($m->{file_b
});
5223 my $pbat = $self->ensure_path($dir);
5224 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
5225 $self->url_path($m->{file_a
}), $self->{r
});
5226 print "\tC\t$m->{file_a} => $m->{file_b}\n" unless $::_q
;
5227 $self->chg_file($fbat, $m);
5228 $self->close_file($fbat,undef,$self->{pool
});
5232 my ($self, $path, $pbat) = @_;
5233 my $rpath = $self->repo_path($path);
5234 my ($dir, $file) = split_path
($rpath);
5235 $self->{rm
}->{$dir} = 1;
5236 $self->SUPER::delete_entry
($rpath, $self->{r
}, $pbat, $self->{pool
});
5240 my ($self, $m) = @_;
5241 my ($dir, $file) = split_path
($m->{file_b
});
5242 my $pbat = $self->ensure_path($dir);
5243 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
5244 $self->url_path($m->{file_a
}), $self->{r
});
5245 print "\tR\t$m->{file_a} => $m->{file_b}\n" unless $::_q
;
5246 $self->apply_autoprops($file, $fbat);
5247 $self->chg_file($fbat, $m);
5248 $self->close_file($fbat,undef,$self->{pool
});
5250 ($dir, $file) = split_path
($m->{file_a
});
5251 $pbat = $self->ensure_path($dir);
5252 $self->delete_entry($m->{file_a
}, $pbat);
5256 my ($self, $m) = @_;
5257 my ($dir, $file) = split_path
($m->{file_b
});
5258 my $pbat = $self->ensure_path($dir);
5259 my $fbat = $self->open_file($self->repo_path($m->{file_b
}),
5260 $pbat,$self->{r
},$self->{pool
});
5261 print "\t$m->{chg}\t$m->{file_b}\n" unless $::_q
;
5262 $self->chg_file($fbat, $m);
5263 $self->close_file($fbat,undef,$self->{pool
});
5266 sub T
{ shift->M(@_) }
5268 sub change_file_prop
{
5269 my ($self, $fbat, $pname, $pval) = @_;
5270 $self->SUPER::change_file_prop
($fbat, $pname, $pval, $self->{pool
});
5273 sub change_dir_prop
{
5274 my ($self, $pbat, $pname, $pval) = @_;
5275 $self->SUPER::change_dir_prop
($pbat, $pname, $pval, $self->{pool
});
5278 sub _chg_file_get_blob
($$$$) {
5279 my ($self, $fbat, $m, $which) = @_;
5280 my $fh = $::_repository
->temp_acquire("git_blob_$which");
5281 if ($m->{"mode_$which"} =~ /^120/) {
5282 print $fh 'link ' or croak
$!;
5283 $self->change_file_prop($fbat,'svn:special','*');
5284 } elsif ($m->{mode_a
} =~ /^120/ && $m->{"mode_$which"} !~ /^120/) {
5285 $self->change_file_prop($fbat,'svn:special',undef);
5287 my $blob = $m->{"sha1_$which"};
5288 return ($fh,) if ($blob =~ /^0{40}$/);
5289 my $size = $::_repository
->cat_blob($blob, $fh);
5290 croak
"Failed to read object $blob" if ($size < 0);
5291 $fh->flush == 0 or croak
$!;
5292 seek $fh, 0, 0 or croak
$!;
5294 my $exp = ::md5sum
($fh);
5295 seek $fh, 0, 0 or croak
$!;
5300 my ($self, $fbat, $m) = @_;
5301 if ($m->{mode_b
} =~ /755$/ && $m->{mode_a
} !~ /755$/) {
5302 $self->change_file_prop($fbat,'svn:executable','*');
5303 } elsif ($m->{mode_b
} !~ /755$/ && $m->{mode_a
} =~ /755$/) {
5304 $self->change_file_prop($fbat,'svn:executable',undef);
5306 my ($fh_a, $exp_a) = _chg_file_get_blob
$self, $fbat, $m, 'a';
5307 my ($fh_b, $exp_b) = _chg_file_get_blob
$self, $fbat, $m, 'b';
5308 my $pool = SVN
::Pool
->new;
5309 my $atd = $self->apply_textdelta($fbat, $exp_a, $pool);
5311 my $txstream = SVN
::TxDelta
::new
($fh_a, $fh_b, $pool);
5312 my $res = SVN
::TxDelta
::send_txstream
($txstream, @
$atd, $pool);
5314 die "Unexpected result from send_txstream: $res\n",
5315 "(SVN::Core::VERSION: $SVN::Core::VERSION)\n";
5318 my $got = SVN
::TxDelta
::send_stream
($fh_b, @
$atd, $pool);
5319 die "Checksum mismatch\nexpected: $exp_b\ngot: $got\n"
5320 if ($got ne $exp_b);
5322 Git
::temp_release
($fh_b, 1);
5323 Git
::temp_release
($fh_a, 1);
5328 my ($self, $m) = @_;
5329 my ($dir, $file) = split_path
($m->{file_b
});
5330 my $pbat = $self->ensure_path($dir);
5331 print "\tD\t$m->{file_b}\n" unless $::_q
;
5332 $self->delete_entry($m->{file_b
}, $pbat);
5337 my ($p,$bat) = ($self->{pool
}, $self->{bat
});
5338 foreach (sort { $b =~ tr
#/#/# <=> $a =~ tr#/#/# } keys %$bat) {
5340 $self->close_directory($bat->{$_}, $p);
5342 $self->close_directory($bat->{''}, $p);
5343 $self->SUPER::close_edit
($p);
5349 $self->SUPER::abort_edit
($self->{pool
});
5354 $self->SUPER::DESTROY
(@_);
5355 $self->{pool
}->clear;
5358 # this drives the editor
5361 my $mods = $self->{mods
};
5362 my %o = ( D
=> 1, R
=> 0, C
=> -1, A
=> 3, M
=> 3, T
=> 3 );
5363 foreach my $m (sort { $o{$a->{chg
}} <=> $o{$b->{chg
}} } @
$mods) {
5365 if (defined $o{$f}) {
5368 fatal
("Invalid change type: $f");
5372 if (defined($self->{mergeinfo
})) {
5373 $self->change_dir_prop($self->{bat
}{''}, "svn:mergeinfo",
5374 $self->{mergeinfo
});
5376 $self->rmdirs if $_rmdir;
5382 return scalar @
$mods;
5385 package Git
::SVN
::Ra
;
5386 use vars qw
/@ISA $config_dir $_log_window_size/;
5389 my ($ra_invalid, $can_do_switch, %ignored_err, $RA);
5392 # enforce temporary pool usage for some simple functions
5394 for my $f (qw
/rev_proplist get_latest_revnum get_uuid get_repos_root
5396 my $SUPER = "SUPER::$f";
5399 my $pool = SVN
::Pool
->new;
5400 my @ret = $self->$SUPER(@_,$pool);
5402 wantarray ?
@ret : $ret[0];
5407 sub _auth_providers
() {
5409 SVN
::Client
::get_simple_provider
(),
5410 SVN
::Client
::get_ssl_server_trust_file_provider
(),
5411 SVN
::Client
::get_simple_prompt_provider
(
5412 \
&Git
::SVN
::Prompt
::simple
, 2),
5413 SVN
::Client
::get_ssl_client_cert_file_provider
(),
5414 SVN
::Client
::get_ssl_client_cert_prompt_provider
(
5415 \
&Git
::SVN
::Prompt
::ssl_client_cert
, 2),
5416 SVN
::Client
::get_ssl_client_cert_pw_file_provider
(),
5417 SVN
::Client
::get_ssl_client_cert_pw_prompt_provider
(
5418 \
&Git
::SVN
::Prompt
::ssl_client_cert_pw
, 2),
5419 SVN
::Client
::get_username_provider
(),
5420 SVN
::Client
::get_ssl_server_trust_prompt_provider
(
5421 \
&Git
::SVN
::Prompt
::ssl_server_trust
),
5422 SVN
::Client
::get_username_prompt_provider
(
5423 \
&Git
::SVN
::Prompt
::username
, 2)
5427 sub escape_uri_only
{
5430 foreach (split m{/}, $uri) {
5431 s/([^~\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg;
5439 if ($url =~ m
#^(https?)://([^/]+)(.*)$#) {
5440 my ($scheme, $domain, $uri) = ($1, $2, escape_uri_only
($3));
5441 $url = "$scheme://$domain$uri";
5447 my ($class, $url) = @_;
5449 return $RA if ($RA && $RA->{url
} eq $url);
5453 SVN
::_Core
::svn_config_ensure
($config_dir, undef);
5454 my ($baton, $callbacks) = SVN
::Core
::auth_open_helper
(_auth_providers
);
5455 my $config = SVN
::Core
::config_get_config
($config_dir);
5457 my $dont_store_passwords = 1;
5458 my $conf_t = ${$config}{'config'};
5461 # The usage of $SVN::_Core::SVN_CONFIG_* variables
5462 # produces warnings that variables are used only once.
5463 # I had not found the better way to shut them up, so
5464 # the warnings of type 'once' are disabled in this block.
5465 if (SVN
::_Core
::svn_config_get_bool
($conf_t,
5466 $SVN::_Core
::SVN_CONFIG_SECTION_AUTH
,
5467 $SVN::_Core
::SVN_CONFIG_OPTION_STORE_PASSWORDS
,
5469 SVN
::_Core
::svn_auth_set_parameter
($baton,
5470 $SVN::_Core
::SVN_AUTH_PARAM_DONT_STORE_PASSWORDS
,
5471 bless (\
$dont_store_passwords, "_p_void"));
5473 if (SVN
::_Core
::svn_config_get_bool
($conf_t,
5474 $SVN::_Core
::SVN_CONFIG_SECTION_AUTH
,
5475 $SVN::_Core
::SVN_CONFIG_OPTION_STORE_AUTH_CREDS
,
5477 $Git::SVN
::Prompt
::_no_auth_cache
= 1;
5479 } # no warnings 'once'
5480 my $self = SVN
::Ra
->new(url
=> escape_url
($url), auth
=> $baton,
5482 pool
=> SVN
::Pool
->new,
5483 auth_provider_callbacks
=> $callbacks);
5484 $self->{url
} = $url;
5485 $self->{svn_path
} = $url;
5486 $self->{repos_root
} = $self->get_repos_root;
5487 $self->{svn_path
} =~ s
#^\Q$self->{repos_root}\E(/|$)##;
5488 $self->{cache
} = { check_path
=> { r
=> 0, data
=> {} },
5489 get_dir
=> { r
=> 0, data
=> {} } };
5490 $RA = bless $self, $class;
5494 my ($self, $path, $r) = @_;
5495 my $cache = $self->{cache
}->{check_path
};
5496 if ($r == $cache->{r
} && exists $cache->{data
}->{$path}) {
5497 return $cache->{data
}->{$path};
5499 my $pool = SVN
::Pool
->new;
5500 my $t = $self->SUPER::check_path
($path, $r, $pool);
5502 if ($r != $cache->{r
}) {
5503 %{$cache->{data
}} = ();
5506 $cache->{data
}->{$path} = $t;
5510 my ($self, $dir, $r) = @_;
5511 my $cache = $self->{cache
}->{get_dir
};
5512 if ($r == $cache->{r
}) {
5513 if (my $x = $cache->{data
}->{$dir}) {
5514 return wantarray ? @
$x : $x->[0];
5517 my $pool = SVN
::Pool
->new;
5518 my ($d, undef, $props) = $self->SUPER::get_dir
($dir, $r, $pool);
5519 my %dirents = map { $_ => { kind
=> $d->{$_}->kind } } keys %$d;
5521 if ($r != $cache->{r
}) {
5522 %{$cache->{data
}} = ();
5525 $cache->{data
}->{$dir} = [ \
%dirents, $r, $props ];
5526 wantarray ?
(\
%dirents, $r, $props) : \
%dirents;
5530 # do not call the real DESTROY since we store ourselves in $RA
5533 # get_log(paths, start, end, limit,
5534 # discover_changed_paths, strict_node_history, receiver)
5536 my ($self, @args) = @_;
5537 my $pool = SVN
::Pool
->new;
5539 # svn_log_changed_path_t objects passed to get_log are likely to be
5540 # overwritten even if only the refs are copied to an external variable,
5541 # so we should dup the structures in their entirety. Using an
5542 # externally passed pool (instead of our temporary and quickly cleared
5543 # pool in Git::SVN::Ra) does not help matters at all...
5544 my $receiver = pop @args;
5545 my $prefix = "/".$self->{svn_path
};
5546 $prefix =~ s
#/+($)##;
5547 my $prefix_regex = qr
#^\Q$prefix\E#;
5549 my ($paths) = $_[0];
5550 return &$receiver(@_) unless $paths;
5552 foreach my $p (keys %$paths) {
5553 my $i = $paths->{$p};
5554 # Make path relative to our url, not repos_root
5555 $p =~ s/$prefix_regex//;
5556 my %s = map { $_ => $i->$_; }
5557 qw
/copyfrom_path copyfrom_rev action/;
5558 if ($s{'copyfrom_path'}) {
5559 $s{'copyfrom_path'} =~ s/$prefix_regex//;
5567 # the limit parameter was not supported in SVN 1.1.x, so we
5568 # drop it. Therefore, the receiver callback passed to it
5569 # is made aware of this limitation by being wrapped if
5570 # the limit passed to is being wrapped.
5571 if ($SVN::Core
::VERSION
le '1.2.0') {
5572 my $limit = splice(@args, 3, 1);
5574 my $receiver = pop @args;
5575 push(@args, sub { &$receiver(@_) if (--$limit >= 0) });
5578 my $ret = $self->SUPER::get_log
(@args, $pool);
5584 my ($self, $url1, $rev1, $url2, $rev2) = @_;
5585 my $ctx = SVN
::Client
->new(auth
=> _auth_providers
);
5586 my $out = IO
::File
->new_tmpfile;
5588 # older SVN (1.1.x) doesn't take $pool as the last parameter for
5589 # $ctx->diff(), so we'll create a default one
5590 my $pool = SVN
::Pool
->new_default_sub;
5592 $ra_invalid = 1; # this will open a new SVN::Ra connection to $url1
5593 $ctx->diff([], $url1, $rev1, $url2, $rev2, 1, 1, 0, $out, $out);
5595 my $ret = (($out->stat)[7] == 0);
5596 close $out or croak
$!;
5601 sub get_commit_editor
{
5602 my ($self, $log, $cb, $pool) = @_;
5603 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef, 0) : ();
5604 $self->SUPER::get_commit_editor
($log, $cb, @lock, $pool);
5608 my ($self, $rev_a, $rev_b, $gs, $editor) = @_;
5609 my $new = ($rev_a == $rev_b);
5610 my $path = $gs->{path
};
5612 if ($new && -e
$gs->{index}) {
5613 unlink $gs->{index} or die
5614 "Couldn't unlink index: $gs->{index}: $!\n";
5616 my $pool = SVN
::Pool
->new;
5617 $editor->set_path_strip($path);
5618 my (@pc) = split m
#/#, $path;
5619 my $reporter = $self->do_update($rev_b, (@pc ?
shift @pc : ''),
5621 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef) : ();
5623 # Since we can't rely on svn_ra_reparent being available, we'll
5624 # just have to do some magic with set_path to make it so
5625 # we only want a partial path.
5627 my $final = join('/', @pc);
5629 $reporter->set_path($sp, $rev_b, 0, @lock, $pool);
5630 $sp .= '/' if length $sp;
5633 die "BUG: '$sp' != '$final'\n" if ($sp ne $final);
5635 $reporter->set_path($sp, $rev_a, $new, @lock, $pool);
5637 $reporter->finish_report($pool);
5639 $editor->{git_commit_ok
};
5642 # this requires SVN 1.4.3 or later (do_switch didn't work before 1.4.3, and
5643 # svn_ra_reparent didn't work before 1.4)
5645 my ($self, $rev_a, $rev_b, $gs, $url_b, $editor) = @_;
5646 my $path = $gs->{path
};
5647 my $pool = SVN
::Pool
->new;
5649 my $full_url = $self->{url
};
5650 my $old_url = $full_url;
5651 $full_url .= '/' . $path if length $path;
5652 my ($ra, $reparented);
5654 if ($old_url =~ m
#^svn(\+ssh)?://# ||
5655 ($full_url =~ m
#^https?://# &&
5656 escape_url
($full_url) ne $full_url)) {
5660 $ra = Git
::SVN
::Ra
->new($full_url);
5662 } elsif ($old_url ne $full_url) {
5663 SVN
::_Ra
::svn_ra_reparent
($self->{session
}, $full_url, $pool);
5664 $self->{url
} = $full_url;
5669 $url_b = escape_url
($url_b);
5670 my $reporter = $ra->do_switch($rev_b, '', 1, $url_b, $editor, $pool);
5671 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef) : ();
5672 $reporter->set_path('', $rev_a, 0, @lock, $pool);
5673 $reporter->finish_report($pool);
5676 SVN
::_Ra
::svn_ra_reparent
($self->{session
}, $old_url, $pool);
5677 $self->{url
} = $old_url;
5681 $editor->{git_commit_ok
};
5684 sub longest_common_path
{
5685 my ($gsv, $globs) = @_;
5687 my $common_max = scalar @
$gsv;
5689 foreach my $gs (@
$gsv) {
5690 my @tmp = split m
#/#, $gs->{path};
5693 $p .= length($p) ?
"/$_" : $_;
5699 $common_max += scalar @
$globs;
5700 foreach my $glob (@
$globs) {
5701 my @tmp = split m
#/#, $glob->{path}->{left};
5704 $p .= length($p) ?
"/$_" : $_;
5710 my $longest_path = '';
5711 foreach (sort {length $b <=> length $a} keys %common) {
5712 if ($common{$_} == $common_max) {
5720 sub gs_fetch_loop_common
{
5721 my ($self, $base, $head, $gsv, $globs) = @_;
5722 return if ($base > $head);
5723 my $inc = $_log_window_size;
5724 my ($min, $max) = ($base, $head < $base + $inc ?
$head : $base + $inc);
5725 my $longest_path = longest_common_path
($gsv, $globs);
5726 my $ra_url = $self->{url
};
5727 my $find_trailing_edge;
5731 my $err_handler = $SVN::Error
::handler
;
5732 $SVN::Error
::handler
= sub {
5734 skip_unknown_revs
($err);
5737 my ($paths, $r, $author, $date, $log) = @_;
5739 { author
=> $author, date
=> $date, log => $log } ];
5741 $self->get_log([$longest_path], $min, $max, 0, 1, 1,
5742 sub { $revs{$_[1]} = _cb
(@_) });
5744 print "Checked through r$max\r";
5746 $find_trailing_edge = 1;
5748 if ($err and $find_trailing_edge) {
5749 print STDERR
"Path '$longest_path' ",
5750 "was probably deleted:\n",
5751 $err->expanded_message,
5752 "\nWill attempt to follow ",
5753 "revisions r$min .. r$max ",
5754 "committed before the deletion\n";
5756 while (--$hi >= $min) {
5758 $self->get_log([$longest_path], $min, $hi,
5761 $revs{$_[1]} = _cb
(@_) });
5763 print STDERR
"r$min .. r$ok OK\n";
5767 $find_trailing_edge = 0;
5769 $SVN::Error
::handler
= $err_handler;
5771 my %exists = map { $_->{path
} => $_ } @
$gsv;
5772 foreach my $r (sort {$a <=> $b} keys %revs) {
5773 my ($paths, $logged) = @
{$revs{$r}};
5775 foreach my $gs ($self->match_globs(\
%exists, $paths,
5777 if ($gs->rev_map_max >= $r) {
5780 next unless $gs->match_paths($paths, $r);
5781 $gs->{logged_rev_props
} = $logged;
5782 if (my $last_commit = $gs->last_commit) {
5783 $gs->assert_index_clean($last_commit);
5785 my $log_entry = $gs->do_fetch($paths, $r);
5787 $gs->do_git_commit($log_entry);
5789 $INDEX_FILES{$gs->{index}} = 1;
5791 foreach my $g (@
$globs) {
5792 my $k = "svn-remote.$g->{remote}." .
5794 Git
::SVN
::tmp_config
($k, $r);
5800 $self = Git
::SVN
::Ra
->new($ra_url);
5801 $ra_invalid = undef;
5804 # pre-fill the .rev_db since it'll eventually get filled in
5805 # with '0' x40 if something new gets committed
5806 foreach my $gs (@
$gsv) {
5807 next if $gs->rev_map_max >= $max;
5808 next if defined $gs->rev_map_get($max);
5809 $gs->rev_map_set($max, 0 x40
);
5811 foreach my $g (@
$globs) {
5812 my $k = "svn-remote.$g->{remote}.$g->{t}-maxRev";
5813 Git
::SVN
::tmp_config
($k, $max);
5815 last if $max >= $head;
5818 $max = $head if ($max > $head);
5823 sub get_dir_globbed
{
5824 my ($self, $left, $depth, $r) = @_;
5826 my @x = eval { $self->get_dir($left, $r) };
5827 return unless scalar @x == 3;
5828 my $dirents = $x[0];
5830 foreach my $de (keys %$dirents) {
5831 next if $dirents->{$de}->{kind
} != $SVN::Node
::dir
;
5833 my @args = ("$left/$de", $depth - 1, $r);
5834 foreach my $dir ($self->get_dir_globbed(@args)) {
5835 push @finalents, "$de/$dir";
5838 push @finalents, $de;
5845 my ($self, $exists, $paths, $globs, $r) = @_;
5848 my ($self, $exists, $g, $r) = @_;
5850 my @dirs = $self->get_dir_globbed($g->{path
}->{left
},
5851 $g->{path
}->{depth
},
5854 foreach my $de (@dirs) {
5855 my $p = $g->{path
}->full_path($de);
5856 next if $exists->{$p};
5857 next if (length $g->{path
}->{right
} &&
5858 ($self->check_path($p, $r) !=
5860 next unless $p =~ /$g->{path}->{regex}/;
5861 $exists->{$p} = Git
::SVN
->init($self->{url
}, $p, undef,
5862 $g->{ref}->full_path($de), 1);
5865 foreach my $g (@
$globs) {
5866 if (my $path = $paths->{"/$g->{path}->{left}"}) {
5867 if ($path->{action
} =~ /^[AR]$/) {
5868 get_dir_check
($self, $exists, $g, $r);
5871 foreach (keys %$paths) {
5872 if (/$g->{path}->{left_regex}/ &&
5873 !/$g->{path}->{regex}/) {
5874 next if $paths->{$_}->{action
} !~ /^[AR]$/;
5875 get_dir_check
($self, $exists, $g, $r);
5877 next unless /$g->{path}->{regex}/;
5879 my $pathname = $g->{path
}->full_path($p);
5880 next if $exists->{$pathname};
5881 next if ($self->check_path($pathname, $r) !=
5883 $exists->{$pathname} = Git
::SVN
->init(
5884 $self->{url
}, $pathname, undef,
5885 $g->{ref}->full_path($p), 1);
5888 foreach (split m
#/#, $g->{path}->{left}) {
5890 next unless ($paths->{$c} &&
5891 ($paths->{$c}->{action
} =~ /^[AR]$/));
5892 get_dir_check
($self, $exists, $g, $r);
5900 return $self->{url
} if ($self->{url
} eq $self->{repos_root
});
5901 my $url = $self->{repos_root
};
5902 my @components = split(m!/!, $self->{svn_path
});
5905 $url .= "/$c" if length $c;
5907 my $ra = (ref $self)->new($url);
5908 my $latest = $ra->get_latest_revnum;
5909 $ra->get_log("", $latest, 0, 1, 0, 1, sub {});
5911 } while ($@
&& ($c = shift @components));
5917 unless (defined $can_do_switch) {
5918 my $pool = SVN
::Pool
->new;
5920 $self->do_switch(1, '', 0, $self->{url
},
5921 SVN
::Delta
::Editor
->new, $pool);
5926 $rep->abort_report($pool);
5934 sub skip_unknown_revs
{
5936 my $errno = $err->apr_err();
5937 # Maybe the branch we're tracking didn't
5938 # exist when the repo started, so it's
5939 # not an error if it doesn't, just continue
5941 # Wonderfully consistent library, eh?
5942 # 160013 - svn:// and file://
5943 # 175002 - http(s)://
5944 # 175007 - http(s):// (this repo required authorization, too...)
5945 # More codes may be discovered later...
5946 if ($errno == 175007 || $errno == 175002 || $errno == 160013) {
5947 my $err_key = $err->expanded_message;
5948 # revision numbers change every time, filter them out
5949 $err_key =~ s/\d+/\0/g;
5950 $err_key = "$errno\0$err_key";
5951 unless ($ignored_err{$err_key}) {
5952 warn "W: Ignoring error from SVN, path probably ",
5953 "does not exist: ($errno): ",
5954 $err->expanded_message,"\n";
5955 warn "W: Do not be alarmed at the above message ",
5956 "git-svn is just searching aggressively for ",
5958 "This may take a while on large repositories\n";
5959 $ignored_err{$err_key} = 1;
5963 die "Error from SVN, ($errno): ", $err->expanded_message,"\n";
5966 package Git
::SVN
::Log
;
5969 use POSIX qw
/strftime/;
5971 use constant commit_log_separator
=> ('-' x
72) . "\n";
5972 use vars qw
/$TZ $limit $color $pager $non_recursive $verbose $oneline
5973 %rusers $show_commit $incremental/;
5978 return 1 if defined $c->{r
};
5980 # big commit message got truncated by the 16k pretty buffer in rev-list
5981 if ($c->{l
} && $c->{l
}->[-1] eq "...\n" &&
5982 $c->{a_raw
} =~ /\@([a-f\d\-]+)>$/) {
5984 my @log = command
(qw
/cat-file commit/, $c->{c
});
5986 # shift off the headers
5987 shift @log while ($log[0] ne '');
5990 # TODO: make $c->{l} not have a trailing newline in the future
5991 @
{$c->{l
}} = map { "$_\n" } grep !/^git-svn-id: /, @log;
5993 (undef, $c->{r
}, undef) = ::extract_metadata
(
5994 (grep(/^git-svn-id: /, @log))[-1]);
5996 return defined $c->{r
};
6000 return $color || Git
->repository->get_colorbool('color.diff');
6003 sub git_svn_log_cmd
{
6004 my ($r_min, $r_max, @args) = @_;
6006 my (@files, @log_opts);
6007 foreach my $x (@args) {
6008 if ($x eq '--' || @files) {
6011 if (::verify_ref
("$x^0")) {
6019 my ($url, $rev, $uuid, $gs) = ::working_head_info
($head);
6020 $gs ||= Git
::SVN
->_new;
6021 my @cmd = (qw
/log --abbrev-commit --pretty=raw --default/,
6023 push @cmd, '-r' unless $non_recursive;
6024 push @cmd, qw
/--raw --name-status/ if $verbose;
6025 push @cmd, '--color' if log_use_color
();
6026 push @cmd, @log_opts;
6027 if (defined $r_max && $r_max == $r_min) {
6028 push @cmd, '--max-count=1';
6029 if (my $c = $gs->rev_map_get($r_max)) {
6032 } elsif (defined $r_max) {
6033 if ($r_max < $r_min) {
6034 ($r_min, $r_max) = ($r_max, $r_min);
6036 my (undef, $c_max) = $gs->find_rev_before($r_max, 1, $r_min);
6037 my (undef, $c_min) = $gs->find_rev_after($r_min, 1, $r_max);
6038 # If there are no commits in the range, both $c_max and $c_min
6039 # will be undefined. If there is at least 1 commit in the
6040 # range, both will be defined.
6041 return () if !defined $c_min || !defined $c_max;
6042 if ($c_min eq $c_max) {
6043 push @cmd, '--max-count=1', $c_min;
6045 push @cmd, '--boundary', "$c_min..$c_max";
6048 return (@cmd, @files);
6051 # adapted from pager.c
6054 $ENV{GIT_PAGER_IN_USE
} = 'false';
6058 chomp($pager = command_oneline
(qw(var GIT_PAGER)));
6059 if ($pager eq 'cat') {
6062 $ENV{GIT_PAGER_IN_USE
} = defined($pager);
6066 return unless defined $pager;
6067 pipe my ($rfd, $wfd) or return;
6068 defined(my $pid = fork) or ::fatal
"Can't fork: $!";
6070 open STDOUT
, '>&', $wfd or
6071 ::fatal
"Can't redirect to stdout: $!";
6074 open STDIN
, '<&', $rfd or ::fatal
"Can't redirect stdin: $!";
6075 $ENV{LESS
} ||= 'FRSX';
6076 exec $pager or ::fatal
"Can't run pager: $! ($pager)";
6079 sub format_svn_date
{
6080 # some systmes don't handle or mishandle %z, so be creative.
6081 my $t = shift || time;
6082 my $gm = timelocal
(gmtime($t));
6083 my $sign = qw( + + - )[ $t <=> $gm ];
6084 my $gmoff = sprintf("%s%02d%02d", $sign, (gmtime(abs($t - $gm)))[2,1]);
6085 return strftime
("%Y-%m-%d %H:%M:%S $gmoff (%a, %d %b %Y)", localtime($t));
6088 sub parse_git_date
{
6090 # Date::Parse isn't in the standard Perl distro :(
6091 if ($tz =~ s/^\+//) {
6092 $t += tz_to_s_offset
($tz);
6093 } elsif ($tz =~ s/^\-//) {
6094 $t -= tz_to_s_offset
($tz);
6099 sub set_local_timezone
{
6107 sub tz_to_s_offset
{
6110 return ($1 * 60) + ($tz * 3600);
6113 sub get_author_info
{
6114 my ($dest, $author, $t, $tz) = @_;
6115 $author =~ s/(?:^\s*|\s*$)//g;
6116 $dest->{a_raw
} = $author;
6119 $au = $rusers{$author} || undef;
6122 ($au) = ($author =~ /<([^>]+)\@[^>]+>$/);
6127 $dest->{t_utc
} = parse_git_date
($t, $tz);
6130 sub process_commit
{
6131 my ($c, $r_min, $r_max, $defer) = @_;
6132 if (defined $r_min && defined $r_max) {
6133 if ($r_min == $c->{r
} && $r_min == $r_max) {
6137 return 1 if $r_min == $r_max;
6138 if ($r_min < $r_max) {
6139 # we need to reverse the print order
6140 return 0 if (defined $limit && --$limit < 0);
6144 if ($r_min != $r_max) {
6145 return 1 if ($r_min < $c->{r
});
6146 return 1 if ($r_max > $c->{r
});
6149 return 0 if (defined $limit && --$limit < 0);
6158 if (my $l = $c->{l
}) {
6159 while ($l->[0] =~ /^\s*$/) { shift @
$l }
6162 $l_fmt ||= 'A' . length($c->{r
});
6163 print 'r',pack($l_fmt, $c->{r
}),' | ';
6164 print "$c->{c} | " if $show_commit;
6167 show_commit_normal
($c);
6171 sub show_commit_changed_paths
{
6173 return unless $c->{changed
};
6174 print "Changed paths:\n", @
{$c->{changed
}};
6177 sub show_commit_normal
{
6179 print commit_log_separator
, "r$c->{r} | ";
6180 print "$c->{c} | " if $show_commit;
6181 print "$c->{a} | ", format_svn_date
($c->{t_utc
}), ' | ';
6184 if (my $l = $c->{l
}) {
6185 while ($l->[$#$l] eq "\n" && $#$l > 0
6186 && $l->[($#$l - 1)] eq "\n") {
6189 $nr_line = scalar @
$l;
6191 print "1 line\n\n\n";
6193 if ($nr_line == 1) {
6194 $nr_line = '1 line';
6196 $nr_line .= ' lines';
6198 print $nr_line, "\n";
6199 show_commit_changed_paths
($c);
6201 print $_ foreach @
$l;
6205 show_commit_changed_paths
($c);
6209 foreach my $x (qw
/raw stat diff/) {
6212 print $_ foreach @
{$c->{$x}}
6219 my ($r_min, $r_max);
6220 my $r_last = -1; # prevent dupes
6221 set_local_timezone
();
6222 if (defined $::_revision
) {
6223 if ($::_revision
=~ /^(\d+):(\d+)$/) {
6224 ($r_min, $r_max) = ($1, $2);
6225 } elsif ($::_revision
=~ /^\d+$/) {
6226 $r_min = $r_max = $::_revision
;
6228 ::fatal
"-r$::_revision is not supported, use ",
6229 "standard 'git log' arguments instead";
6234 @args = git_svn_log_cmd
($r_min, $r_max, @args);
6236 print commit_log_separator
unless $incremental || $oneline;
6239 my $log = command_output_pipe
(@args);
6241 my (@k, $c, $d, $stat);
6242 my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
6244 if (/^${esc_color}commit (?:- )?($::sha1_short)/o) {
6246 if ($c && cmt_showable
($c) && $c->{r
} != $r_last) {
6248 process_commit
($c, $r_min, $r_max, \
@k) or
6253 } elsif (/^${esc_color}author (.+) (\d+) ([\-\+]?\d+)$/o) {
6254 get_author_info
($c, $1, $2, $3);
6255 } elsif (/^${esc_color}(?:tree|parent|committer) /o) {
6257 } elsif (/^${esc_color}:\d{6} \d{6} $::sha1_short/o) {
6258 push @
{$c->{raw
}}, $_;
6259 } elsif (/^${esc_color}[ACRMDT]\t/) {
6260 # we could add $SVN->{svn_path} here, but that requires
6261 # remote access at the moment (repo_path_split)...
6262 s
#^(${esc_color})([ACRMDT])\t#$1 $2 #o;
6263 push @
{$c->{changed
}}, $_;
6264 } elsif (/^${esc_color}diff /o) {
6266 push @
{$c->{diff
}}, $_;
6268 push @
{$c->{diff
}}, $_;
6269 } elsif (/^\
.+\ \
|\s
*\d
+\
$esc_color[\
+\
-]*
6270 $esc_color*[\
+\
-]*$esc_color$/x
) {
6272 push @
{$c->{stat}}, $_;
6273 } elsif ($stat && /^ \d+ files changed, \d+ insertions/) {
6274 push @
{$c->{stat}}, $_;
6276 } elsif (/^${esc_color} (git-svn-id:.+)$/o) {
6277 ($c->{url
}, $c->{r
}, undef) = ::extract_metadata
($1);
6278 } elsif (s/^${esc_color} //o) {
6279 push @
{$c->{l
}}, $_;
6282 if ($c && defined $c->{r
} && $c->{r
} != $r_last) {
6284 process_commit
($c, $r_min, $r_max, \
@k);
6287 ($r_min, $r_max) = ($r_max, $r_min);
6288 process_commit
($_, $r_min, $r_max) foreach reverse @k;
6292 print commit_log_separator
unless $incremental || $oneline;
6301 my ($fh, $ctx, $rev);
6304 ($fh, $ctx) = command_output_pipe
('blame', @_, $path);
6305 while (my $line = <$fh>) {
6306 if ($line =~ /^\^?([[:xdigit:]]+)\s/) {
6307 # Uncommitted edits show up as a rev ID of
6308 # all zeros, which we can't look up with
6311 (undef, $rev, undef) =
6313 $rev = '0' if (!$rev);
6317 $rev = sprintf('%-10s', $rev);
6318 $line =~ s/^\^?[[:xdigit:]]+(\s)/$rev$1/;
6323 ($fh, $ctx) = command_output_pipe
('blame', '-p', @_, 'HEAD',
6328 my %dsha; #distinct sha keys
6330 while (my $line = <$fh>) {
6331 push @buffer, $line;
6332 if ($line =~ /^([[:xdigit:]]{40})\s\d+\s\d+/) {
6337 my $s2r = ::cmt_sha2rev_batch
([keys %dsha]);
6339 foreach my $line (@buffer) {
6340 if ($line =~ /^([[:xdigit:]]{40})\s\d+\s\d+/) {
6342 $rev = '0' if (!$rev)
6344 elsif ($line =~ /^author (.*)/) {
6345 $authors{$rev} = $1;
6346 $authors{$rev} =~ s/\s/_/g;
6348 elsif ($line =~ /^\t(.*)$/) {
6349 printf("%6s %10s %s\n", $rev, $authors{$rev}, $1);
6353 command_close_pipe
($fh, $ctx);
6356 package Git
::SVN
::Migration
;
6357 # these version numbers do NOT correspond to actual version numbers
6358 # of git nor git-svn. They are just relative.
6360 # v0 layout: .git/$id/info/url, refs/heads/$id-HEAD
6362 # v1 layout: .git/$id/info/url, refs/remotes/$id
6364 # v2 layout: .git/svn/$id/info/url, refs/remotes/$id
6366 # v3 layout: .git/svn/$id, refs/remotes/$id
6367 # - info/url may remain for backwards compatibility
6368 # - this is what we migrate up to this layout automatically,
6369 # - this will be used by git svn init on single branches
6370 # v3.1 layout (auto migrated):
6371 # - .rev_db => .rev_db.$UUID, .rev_db will remain as a symlink
6372 # for backwards compatibility
6374 # v4 layout: .git/svn/$repo_id/$id, refs/remotes/$repo_id/$id
6375 # - this is only created for newly multi-init-ed
6376 # repositories. Similar in spirit to the
6377 # --use-separate-remotes option in git-clone (now default)
6378 # - we do not automatically migrate to this (following
6379 # the example set by core git)
6381 # v5 layout: .rev_db.$UUID => .rev_map.$UUID
6382 # - newer, more-efficient format that uses 24-bytes per record
6383 # with no filler space.
6384 # - use xxd -c24 < .rev_map.$UUID to view and debug
6385 # - This is a one-way migration, repositories updated to the
6386 # new format will not be able to use old git-svn without
6387 # rebuilding the .rev_db. Rebuilding the rev_db is not
6388 # possible if noMetadata or useSvmProps are set; but should
6389 # be no problem for users that use the (sensible) defaults.
6393 use File
::Path qw
/mkpath/;
6394 use File
::Basename qw
/dirname basename/;
6395 use vars qw
/$_minimize/;
6397 sub migrate_from_v0
{
6398 my $git_dir = $ENV{GIT_DIR
};
6399 return undef unless -d
$git_dir;
6400 my ($fh, $ctx) = command_output_pipe
(qw
/rev-parse --symbolic --all/);
6404 my ($id, $orig_ref) = ($_, $_);
6405 next unless $id =~ s
#^refs/heads/(.+)-HEAD$#$1#;
6406 next unless -f
"$git_dir/$id/info/url";
6407 my $new_ref = "refs/remotes/$id";
6408 if (::verify_ref
("$new_ref^0")) {
6409 print STDERR
"W: $orig_ref is probably an old ",
6410 "branch used by an ancient version of ",
6412 "However, $new_ref also exists.\n",
6413 "We will not be able ",
6414 "to use this branch until this ",
6415 "ambiguity is resolved.\n";
6418 print STDERR
"Migrating from v0 layout...\n" if !$migrated;
6419 print STDERR
"Renaming ref: $orig_ref => $new_ref\n";
6420 command_noisy
('update-ref', $new_ref, $orig_ref);
6421 command_noisy
('update-ref', '-d', $orig_ref, $orig_ref);
6424 command_close_pipe
($fh, $ctx);
6425 print STDERR
"Done migrating from v0 layout...\n" if $migrated;
6429 sub migrate_from_v1
{
6430 my $git_dir = $ENV{GIT_DIR
};
6432 return $migrated unless -d
$git_dir;
6433 my $svn_dir = "$git_dir/svn";
6435 # just in case somebody used 'svn' as their $id at some point...
6436 return $migrated if -d
$svn_dir && ! -f
"$svn_dir/info/url";
6438 print STDERR
"Migrating from a git-svn v1 layout...\n";
6440 print STDERR
"Data from a previous version of git-svn exists, but\n\t",
6441 "$svn_dir\n\t(required for this version ",
6442 "($::VERSION) of git-svn) does not exist.\n";
6443 my ($fh, $ctx) = command_output_pipe
(qw
/rev-parse --symbolic --all/);
6446 next unless $x =~ s
#^refs/remotes/##;
6448 next unless -f
"$git_dir/$x/info/url";
6449 my $u = eval { ::file_to_s
("$git_dir/$x/info/url") };
6451 my $dn = dirname
("$git_dir/svn/$x");
6452 mkpath
([$dn]) unless -d
$dn;
6453 if ($x eq 'svn') { # they used 'svn' as GIT_SVN_ID:
6454 mkpath
(["$git_dir/svn/svn"]);
6455 print STDERR
" - $git_dir/$x/info => ",
6456 "$git_dir/svn/$x/info\n";
6457 rename "$git_dir/$x/info", "$git_dir/svn/$x/info" or
6459 # don't worry too much about these, they probably
6460 # don't exist with repos this old (save for index,
6461 # and we can easily regenerate that)
6462 foreach my $f (qw
/unhandled.log index .rev_db/) {
6463 rename "$git_dir/$x/$f", "$git_dir/svn/$x/$f";
6466 print STDERR
" - $git_dir/$x => $git_dir/svn/$x\n";
6467 rename "$git_dir/$x", "$git_dir/svn/$x" or
6472 command_close_pipe
($fh, $ctx);
6473 print STDERR
"Done migrating from a git-svn v1 layout\n";
6478 my ($l_map, $pfx, $path) = @_;
6480 foreach (<$path/*>) {
6481 if (-r
"$_/info/url") {
6482 $pfx .= '/' if $pfx && $pfx !~ m
!/$!;
6483 my $ref_id = $pfx . basename
$_;
6484 my $url = ::file_to_s
("$_/info/url");
6485 $l_map->{$ref_id} = $url;
6492 $x =~ s!^\Q$ENV{GIT_DIR}\E/svn/!!o;
6493 read_old_urls
($l_map, $x, $_);
6497 sub migrate_from_v2
{
6498 my @cfg = command
(qw
/config -l/);
6499 return if grep /^svn-remote\..+\.url=/, @cfg;
6501 read_old_urls
(\
%l_map, '', "$ENV{GIT_DIR}/svn");
6504 foreach my $ref_id (sort keys %l_map) {
6505 eval { Git
::SVN
->init($l_map{$ref_id}, '', undef, $ref_id) };
6507 Git
::SVN
->init($l_map{$ref_id}, '', $ref_id, $ref_id);
6514 sub minimize_connections
{
6515 my $r = Git
::SVN
::read_all_remotes
();
6517 my $root_repos = {};
6518 foreach my $repo_id (keys %$r) {
6519 my $url = $r->{$repo_id}->{url
} or next;
6520 my $fetch = $r->{$repo_id}->{fetch
} or next;
6521 my $ra = Git
::SVN
::Ra
->new($url);
6523 # skip existing cases where we already connect to the root
6524 if (($ra->{url
} eq $ra->{repos_root
}) ||
6525 ($ra->{repos_root
} eq $repo_id)) {
6526 $root_repos->{$ra->{url
}} = $repo_id;
6530 my $root_ra = Git
::SVN
::Ra
->new($ra->{repos_root
});
6531 my $root_path = $ra->{url
};
6532 $root_path =~ s
#^\Q$ra->{repos_root}\E(/|$)##;
6533 foreach my $path (keys %$fetch) {
6534 my $ref_id = $fetch->{$path};
6535 my $gs = Git
::SVN
->new($ref_id, $repo_id, $path);
6537 # make sure we can read when connecting to
6538 # a higher level of a repository
6539 my ($last_rev, undef) = $gs->last_rev_commit;
6540 if (!defined $last_rev) {
6542 $root_ra->get_latest_revnum;
6546 my $new = $root_path;
6547 $new .= length $path ?
"/$path" : '';
6549 $root_ra->get_log([$new], $last_rev, $last_rev,
6553 $new_urls->{$ra->{repos_root
}}->{$new} =
6554 { ref_id
=> $ref_id,
6555 old_repo_id
=> $repo_id,
6556 old_path
=> $path };
6561 foreach my $url (keys %$new_urls) {
6562 # see if we can re-use an existing [svn-remote "repo_id"]
6563 # instead of creating a(n ugly) new section:
6564 my $repo_id = $root_repos->{$url} || $url;
6566 my $fetch = $new_urls->{$url};
6567 foreach my $path (keys %$fetch) {
6568 my $x = $fetch->{$path};
6569 Git
::SVN
->init($url, $path, $repo_id, $x->{ref_id
});
6570 my $pfx = "svn-remote.$x->{old_repo_id}";
6572 my $old_fetch = quotemeta("$x->{old_path}:".
6574 command_noisy
(qw
/config --unset/,
6575 "$pfx.fetch", '^'. $old_fetch . '$');
6576 delete $r->{$x->{old_repo_id
}}->
6577 {fetch
}->{$x->{old_path
}};
6578 if (!keys %{$r->{$x->{old_repo_id
}}->{fetch
}}) {
6579 command_noisy
(qw
/config --unset/,
6581 push @emptied, $x->{old_repo_id
}
6586 my $file = $ENV{GIT_CONFIG
} || "$ENV{GIT_DIR}/config";
6588 The following [svn-remote] sections in your config file ($file) are empty
6589 and can be safely removed:
6591 print STDERR
"[svn-remote \"$_\"]\n" foreach @emptied;
6595 sub migration_check
{
6599 minimize_connections
() if $_minimize;
6602 package Git
::IndexInfo
;
6605 use Git qw
/command_input_pipe command_close_pipe/;
6609 my ($gui, $ctx) = command_input_pipe
(qw
/update-index -z --index-info/);
6610 bless { gui
=> $gui, ctx
=> $ctx, nr
=> 0}, $class;
6614 my ($self, $path) = @_;
6615 if (print { $self->{gui
} } '0 ', 0 x
40, "\t", $path, "\0") {
6616 return ++$self->{nr
};
6622 my ($self, $mode, $hash, $path) = @_;
6623 if (print { $self->{gui
} } $mode, ' ', $hash, "\t", $path, "\0") {
6624 return ++$self->{nr
};
6631 command_close_pipe
($self->{gui
}, $self->{ctx
});
6634 package Git
::SVN
::GlobSpec
;
6639 my ($class, $glob, $pattern_ok) = @_;
6641 $re =~ s!/+$!!g; # no need for trailing slashes
6642 my (@left, @right, @patterns);
6644 my $die_msg = "Only one set of wildcard directories " .
6645 "(e.g. '*' or '*/*/*') is supported: '$glob'\n";
6646 for my $part (split(m
|/|, $glob)) {
6647 if ($part =~ /\*/ && $part ne "*") {
6648 die "Invalid pattern in '$glob': $part\n";
6649 } elsif ($pattern_ok && $part =~ /[{}]/ &&
6650 $part !~ /^\{[^{}]+\}/) {
6651 die "Invalid pattern in '$glob': $part\n";
6654 die $die_msg if $state eq "right";
6656 push(@patterns, "[^/]*");
6657 } elsif ($pattern_ok && $part =~ /^\{(.*)\}$/) {
6658 die $die_msg if $state eq "right";
6660 my $p = quotemeta($1);
6662 push(@patterns, "(?:$p)");
6664 if ($state eq "left") {
6667 push(@right, $part);
6672 my $depth = @patterns;
6674 die "One '*' is needed in glob: '$glob'\n";
6676 my $left = join('/', @left);
6677 my $right = join('/', @right);
6678 $re = join('/', @patterns);
6680 grep(length, quotemeta($left), "($re)", quotemeta($right)));
6681 my $left_re = qr/^\/\Q
$left\E
(\
/|$)/;
6682 bless { left
=> $left, right
=> $right, left_regex
=> $left_re,
6683 regex
=> qr/$re/, glob => $glob, depth
=> $depth }, $class;
6687 my ($self, $path) = @_;
6688 return (length $self->{left
} ?
"$self->{left}/" : '') .
6689 $path . (length $self->{right
} ?
"/$self->{right}" : '');
6697 $remotes = { # returned by read_all_remotes()
6699 # svn-remote.svn.url=https://svn.musicpd.org
6700 url
=> 'https://svn.musicpd.org',
6701 # svn-remote.svn.fetch=mpd/trunk:trunk
6703 'mpd/trunk' => 'trunk',
6705 # svn-remote.svn.tags=mpd/tags/*:tags/*
6710 regex
=> qr!mpd/tags/([^/]+)$!,
6716 regex
=> qr!tags/([^/]+)$!,
6723 $log_entry hashref as returned by libsvn_log_entry
()
6725 log => 'whitespace-formatted log entry
6726 ', # trailing newline is preserved
6727 revision
=> '8', # integer
6728 date
=> '2004-02-24T17:01:44.108345Z', # commit date
6729 author
=> 'committer name'
6733 # this is generated by generate_diff();
6734 @mods = array of diff
-index line hashes
, each element represents one line
6735 of diff
-index output
6737 diff
-index line
($m hash
)
6739 mode_a
=> first column of diff
-index output
, no leading
':',
6740 mode_b
=> second column of diff
-index output
,
6741 sha1_b
=> sha1sum of the final blob
,
6742 chg
=> change type
[MCRADT
],
6743 file_a
=> original file name of a file
(iff chg is
'C' or 'R')
6744 file_b
=> new
/current file name of a file
(any chg
)
6748 # retval of read_url_paths{,_all}();
6750 # repository root url
6751 'https://svn.musicpd.org' => {
6752 # repository path # GIT_SVN_ID
6753 'mpd/trunk' => 'trunk',
6754 'mpd/tags/0.11.5' => 'tags/0.11.5',
6759 I don
't trust the each() function on unless I created %hash myself
6760 because the internal iterator may not have started at base.