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
} && exists $ENV{GIT_SSH
}) {
26 $ENV{SVN_SSH
} = $ENV{GIT_SSH
};
29 if (exists $ENV{SVN_SSH
} && $^O
eq 'msys') {
30 $ENV{SVN_SSH
} =~ s/\\/\\\\/g;
31 $ENV{SVN_SSH
} =~ s/(.*)/"$1"/;
34 $Git::SVN
::Log
::TZ
= $ENV{TZ
};
36 $| = 1; # unbuffer STDOUT
38 sub fatal
(@
) { print STDERR
"@_\n"; exit 1 }
40 require SVN
::Core
; # use()-ing this causes segfaults for me... *shrug*
43 if ($SVN::Core
::VERSION
lt '1.1.0') {
44 fatal
"Need SVN::Core 1.1.0 or better (got $SVN::Core::VERSION)";
47 my $can_compress = eval { require Compress
::Zlib
; 1};
48 push @Git::SVN
::Ra
::ISA
, 'SVN::Ra';
49 push @SVN::Git
::Editor
::ISA
, 'SVN::Delta::Editor';
50 push @SVN::Git
::Fetcher
::ISA
, 'SVN::Delta::Editor';
54 use File
::Basename qw
/dirname basename/;
55 use File
::Path qw
/mkpath/;
58 use Getopt
::Long qw
/:config gnu_getopt no_ignore_case auto_abbrev/;
61 use Memoize
; # core since 5.8.0, Jul 2002
64 # import functions from Git into our packages, en masse
66 foreach (qw
/command command_oneline command_noisy command_output_pipe
67 command_input_pipe command_close_pipe
68 command_bidi_pipe command_close_bidi_pipe
/) {
69 for my $package ( qw(SVN::Git::Editor SVN::Git::Fetcher
70 Git::SVN::Migration Git::SVN::Log Git::SVN),
72 *{"${package}::$_"} = \
&{"Git::$_"};
75 Memoize
::memoize
'Git::config';
76 Memoize
::memoize
'Git::config_bool';
81 $sha1 = qr/[a-f\d]{40}/;
82 $sha1_short = qr/[a-f\d]{4,40}/;
83 my ($_stdin, $_help, $_edit,
84 $_message, $_file, $_branch_dest,
86 $_version, $_fetch_all, $_no_rebase, $_fetch_parent,
87 $_merge, $_strategy, $_dry_run, $_local,
88 $_prefix, $_no_checkout, $_url, $_verbose,
89 $_git_format, $_commit_url, $_tag, $_merge_info, $_interactive);
90 $Git::SVN
::_follow_parent
= 1;
91 $SVN::Git
::Fetcher
::_placeholder_filename
= ".gitignore";
93 my %remote_opts = ( 'username=s' => \
$Git::SVN
::Prompt
::_username
,
94 'config-dir=s' => \
$Git::SVN
::Ra
::config_dir
,
95 'no-auth-cache' => \
$Git::SVN
::Prompt
::_no_auth_cache
,
96 'ignore-paths=s' => \
$SVN::Git
::Fetcher
::_ignore_regex
,
97 'ignore-refs=s' => \
$Git::SVN
::Ra
::_ignore_refs_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_paths_regex = \$SVN::Git::Fetcher::_ignore_regex;
444 command_noisy('config
', "$pfx.ignore-paths", $$ignore_paths_regex)
445 if defined $$ignore_paths_regex;
446 my $ignore_refs_regex = \$Git::SVN::Ra::_ignore_refs_regex;
447 command_noisy('config
', "$pfx.ignore-refs", $$ignore_refs_regex)
448 if defined $$ignore_refs_regex;
450 if (defined $SVN::Git::Fetcher::_preserve_empty_dirs) {
451 my $fname = \$SVN::Git::Fetcher::_placeholder_filename;
452 command_noisy('config
', "$pfx.preserve-empty-dirs", 'true
');
453 command_noisy('config
', "$pfx.placeholder-filename", $$fname);
458 my $repo_path = shift or return;
459 mkpath([$repo_path]) unless -d $repo_path;
460 chdir $repo_path or die "Couldn't
chdir to
$repo_path: $!\n";
461 $ENV{GIT_DIR} = '.git';
462 $_repository = Git->repository(Repository => $ENV{GIT_DIR});
466 my ($url, $path) = @_;
467 if (!defined $path &&
468 (defined $_trunk || @_branches || @_tags ||
469 defined $_stdlayout) &&
470 $url !~ m#^[a-z\+]+://#) {
473 $path = basename($url) if !defined $path || !length $path;
474 my $authors_absolute = $_authors ? File::Spec->rel2abs($_authors) : "";
475 cmd_init($url, $path);
476 command_oneline('config', 'svn.authorsfile', $authors_absolute)
478 Git::SVN::fetch_all($Git::SVN::default_repo_id);
482 if (defined $_stdlayout) {
483 $_trunk = 'trunk' if (!defined $_trunk);
484 @_tags = 'tags' if (! @_tags);
485 @_branches = 'branches' if (! @_branches);
487 if (defined $_trunk || @_branches || @_tags) {
488 return cmd_multi_init(@_);
490 my $url = shift or die "SVN repository location required
",
491 "as a command
-line argument
\n";
492 $url = canonicalize_url($url);
496 if ($Git::SVN::_minimize_url eq 'unset') {
497 $Git::SVN::_minimize_url = 0;
500 Git::SVN->init($url);
504 if (grep /^\d+=./, @_) {
505 die "'<rev>=<commit>' fetch arguments are
",
506 "no longer supported
.\n";
510 die "Usage
: $0 fetch
[--all
] [--parent
] [svn
-remote
]\n";
512 $Git::SVN::no_reuse_existing = undef;
513 if ($_fetch_parent) {
514 my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
516 die "Unable to determine upstream SVN information from
",
517 "working tree history
\n";
519 # just fetch, don't checkout.
520 $_no_checkout = 'true';
521 $_fetch_all ? $gs->fetch_all : $gs->fetch;
522 } elsif ($_fetch_all) {
525 $remote ||= $Git::SVN::default_repo_id;
526 Git::SVN::fetch_all($remote, Git::SVN::read_all_remotes());
532 if ($_stdin || !@commits) {
533 print "Reading from stdin
...\n";
536 if (/\b($sha1_short)\b/o) {
537 unshift @commits, $1;
542 foreach my $c (@commits) {
543 my @tmp = command('rev-parse',$c);
544 if (scalar @tmp == 1) {
546 } elsif (scalar @tmp > 1) {
547 push @revs, reverse(command('rev-list',@tmp));
549 fatal "Failed to rev
-parse
$c";
552 my $gs = Git::SVN->new;
553 my ($r_last, $cmt_last) = $gs->last_rev_commit;
555 if (defined $gs->{last_rev} && $r_last != $gs->{last_rev}) {
556 fatal "There are new revisions that were fetched
",
557 "and need to be merged
(or acknowledged
) ",
558 "before committing
.\nlast rev
: $r_last\n",
559 " current
: $gs->{last_rev
}";
561 $gs->set_tree($_) foreach @revs;
562 print "Done committing
",scalar @revs," revisions to SVN
\n";
566 sub split_merge_info_range {
568 if ($range =~ /(\d+)-(\d+)/) {
569 return (int($1), int($2));
571 return (int($range), int($range));
579 my @arr = split(/,/, $in);
580 for my $element (@arr) {
581 my ($start, $end) = split_merge_info_range($element);
585 my @sorted = @arr [ sort {
586 $fnums[$a] <=> $fnums[$b]
592 for my $element (@sorted) {
593 my ($start, $end) = split_merge_info_range($element);
600 if ($start <= $last+1) {
606 if ($first == $last) {
607 push @return, "$first";
609 push @return, "$first-$last";
616 if ($first == $last) {
617 push @return, "$first";
619 push @return, "$first-$last";
623 return join(',', @return);
626 sub merge_revs_into_hash {
627 my ($hash, $minfo) = @_;
628 my @lines = split(' ', $minfo);
630 for my $line (@lines) {
631 my ($branchpath, $revs) = split(/:/, $line);
633 if (exists($hash->{$branchpath})) {
634 # Merge the two revision sets
635 my $combined = "$hash->{$branchpath},$revs";
636 $hash->{$branchpath} = combine_ranges($combined);
638 # Just do range combining for consolidation
639 $hash->{$branchpath} = combine_ranges($revs);
644 sub merge_merge_info {
645 my ($mergeinfo_one, $mergeinfo_two) = @_;
646 my %result_hash = ();
648 merge_revs_into_hash(\%result_hash, $mergeinfo_one);
649 merge_revs_into_hash(\%result_hash, $mergeinfo_two);
652 # Sort below is for consistency's sake
653 for my $branchname (sort keys(%result_hash)) {
654 my $revlist = $result_hash{$branchname};
655 $result .= "$branchname:$revlist\n"
660 sub populate_merge_info {
661 my ($d, $gs, $uuid, $linear_refs, $rewritten_parent) = @_;
664 read_commit_parents(\%parentshash, $d);
665 my @parents = @{$parentshash{$d}};
668 my $all_parents_ok = 1;
669 my $aggregate_mergeinfo = '';
670 my $rooturl = $gs->repos_root;
672 if (defined($rewritten_parent)) {
673 # Replace first parent with newly-rewritten version
675 unshift @parents, $rewritten_parent;
678 foreach my $parent (@parents) {
679 my ($branchurl, $svnrev, $paruuid) =
680 cmt_metadata($parent);
682 unless (defined($svnrev)) {
683 # Should have been caught be preflight check
684 fatal "merge commit
$d has ancestor
$parent, but that change
"
685 ."does
not have git
-svn metadata
!";
687 unless ($branchurl =~ /^\Q$rooturl\E(.*)/) {
688 fatal "commit
$parent git
-svn metadata changed mid
-run
!";
692 my $ra = Git::SVN::Ra->new($branchurl);
693 my (undef, undef, $props) =
694 $ra->get_dir(canonicalize_path("."), $svnrev);
695 my $par_mergeinfo = $props->{'svn:mergeinfo'};
696 unless (defined $par_mergeinfo) {
699 # Merge previous mergeinfo values
700 $aggregate_mergeinfo =
701 merge_merge_info($aggregate_mergeinfo,
704 next if $parent eq $parents[0]; # Skip first parent
705 # Add new changes being placed in tree by merge
706 my @cmd = (qw/rev-list --reverse/,
708 foreach my $par (@parents) {
709 unless ($par eq $parent) {
714 my ($revlist, $ctx) = command_output_pipe(@cmd);
718 my (undef, $csvnrev, undef) =
720 unless (defined $csvnrev) {
721 # A child is missing SVN annotations...
722 # this might be OK, or might not be.
723 warn "W
:child
$irev is merged into revision
"
724 ."$d but does
not have git
-svn metadata
. "
725 ."This means git
-svn cannot determine the
"
726 ."svn revision numbers to place into the
"
727 ."svn
:mergeinfo property
. You must ensure
"
728 ."a branch is entirely committed to
"
729 ."SVN before merging it
in order
for "
730 ."svn
:mergeinfo population to function
"
733 push @revsin, $csvnrev;
735 command_close_pipe($revlist, $ctx);
737 last unless $all_parents_ok;
739 # We now have a list of all SVN revnos which are
740 # merged by this particular parent. Integrate them.
741 next if $#revsin == -1;
742 my $newmergeinfo = "$branchpath:" . join(',', @revsin);
743 $aggregate_mergeinfo =
744 merge_merge_info($aggregate_mergeinfo,
747 if ($all_parents_ok and $aggregate_mergeinfo) {
748 return $aggregate_mergeinfo;
757 command_noisy(qw/update-index --refresh/);
758 git_cmd_try { command_oneline(qw/diff-index --quiet HEAD/) }
759 'Cannot dcommit with a dirty index. Commit your changes first, '
760 . "or stash them with
`git stash'.\n";
764 if ($head ne 'HEAD') {
766 command_oneline([qw/symbolic-ref -q HEAD/])
769 $old_head =~ s{^refs/heads/}{};
771 $old_head = eval { command_oneline(qw/rev-parse HEAD/) };
773 command(['checkout', $head], STDERR => 0);
777 my ($url, $rev, $uuid, $gs) = working_head_info('HEAD', \@refs);
779 die "Unable to determine upstream SVN information from ",
780 "$head history.\nPerhaps the repository is empty.";
783 if (defined $_commit_url) {
786 $url = eval { command_oneline('config', '--get',
787 "svn-remote.$gs->{repo_id}.commiturl") };
789 $url = $gs->full_pushurl
793 my $last_rev = $_revision if defined $_revision;
795 print "Committing to $url ...\n";
797 my ($linear_refs, $parents) = linearize_history($gs, \@refs);
798 if ($_no_rebase && scalar(@$linear_refs) > 1) {
799 warn "Attempting to commit more than one change while ",
800 "--no-rebase is enabled.\n",
801 "If these changes depend on each other, re-running ",
802 "without --no-rebase may be required."
805 if (defined $_interactive){
806 my $ask_default = "y";
807 foreach my $d (@$linear_refs){
808 my ($fh, $ctx) = command_output_pipe(qw(show --summary), "$d");
812 command_close_pipe
($fh, $ctx);
813 $_ = ask
("Commit this patch to SVN? ([y]es (default)|[n]o|[q]uit|[a]ll): ",
814 valid_re
=> qr/^(?:yes|y|no|n|quit|q|all|a)/i,
815 default => $ask_default);
816 die "Commit this patch reply required" unless defined $_;
825 my $expect_url = $url;
827 my $push_merge_info = eval {
828 command_oneline
(qw
/config --get svn.pushmergeinfo/)
830 if (not defined($push_merge_info)
831 or $push_merge_info eq "false"
832 or $push_merge_info eq "no"
833 or $push_merge_info eq "never") {
834 $push_merge_info = 0;
837 unless (defined($_merge_info) || ! $push_merge_info) {
838 # Preflight check of changes to ensure no issues with mergeinfo
839 # This includes check for uncommitted-to-SVN parents
840 # (other than the first parent, which we will handle),
841 # information from different SVN repos, and paths
842 # which are not underneath this repository root.
843 my $rooturl = $gs->repos_root;
844 foreach my $d (@
$linear_refs) {
846 read_commit_parents
(\
%parentshash, $d);
847 my @realparents = @
{$parentshash{$d}};
848 if ($#realparents > 0) {
850 shift @realparents; # Remove/ignore first parent
851 foreach my $parent (@realparents) {
852 my ($branchurl, $svnrev, $paruuid) = cmt_metadata
($parent);
853 unless (defined $paruuid) {
854 # A parent is missing SVN annotations...
855 # abort the whole operation.
856 fatal
"$parent is merged into revision $d, "
857 ."but does not have git-svn metadata. "
858 ."Either dcommit the branch or use a "
859 ."local cherry-pick, FF merge, or rebase "
860 ."instead of an explicit merge commit.";
863 unless ($paruuid eq $uuid) {
864 # Parent has SVN metadata from different repository
865 fatal
"merge parent $parent for change $d has "
866 ."git-svn uuid $paruuid, while current change "
870 unless ($branchurl =~ /^\Q$rooturl\E(.*)/) {
871 # This branch is very strange indeed.
872 fatal
"merge parent $parent for $d is on branch "
873 ."$branchurl, which is not under the "
874 ."git-svn root $rooturl!";
881 my $rewritten_parent;
882 Git
::SVN
::remove_username
($expect_url);
883 if (defined($_merge_info)) {
884 $_merge_info =~ tr{ }{\n};
887 my $d = shift @
$linear_refs or last;
888 unless (defined $last_rev) {
889 (undef, $last_rev, undef) = cmt_metadata
("$d~1");
890 unless (defined $last_rev) {
891 fatal
"Unable to extract revision information ",
896 print "diff-tree $d~1 $d\n";
900 unless (defined($_merge_info) || ! $push_merge_info) {
901 $_merge_info = populate_merge_info
($d, $gs,
907 my %ed_opts = ( r
=> $last_rev,
908 log => get_commit_entry
($d)->{log},
909 ra
=> Git
::SVN
::Ra
->new($url),
910 config
=> SVN
::Core
::config_get_config
(
911 $Git::SVN
::Ra
::config_dir
916 print "Committed r$_[0]\n";
919 mergeinfo
=> $_merge_info,
921 if (!SVN
::Git
::Editor
->new(\
%ed_opts)->apply_diff) {
922 print "No changes\n$d~1 == $d\n";
923 } elsif ($parents->{$d} && @
{$parents->{$d}}) {
924 $gs->{inject_parents_dcommit
}->{$cmt_rev} =
927 $_fetch_all ?
$gs->fetch_all : $gs->fetch;
928 $last_rev = $cmt_rev;
931 # we always want to rebase against the current HEAD,
932 # not any head that was passed to us
933 my @diff = command
('diff-tree', $d,
937 @finish = rebase_cmd
();
938 print STDERR
"W: $d and ", $gs->refname,
939 " differ, using @finish:\n",
940 join("\n", @diff), "\n";
942 print "No changes between current HEAD and ",
944 "\nResetting to the latest ",
946 @finish = qw
/reset --mixed/;
948 command_noisy
(@finish, $gs->refname);
950 $rewritten_parent = command_oneline
(qw
/rev-parse HEAD/);
954 my ($url_, $rev_, $uuid_, $gs_) =
955 working_head_info
('HEAD', \
@refs);
956 my ($linear_refs_, $parents_) =
957 linearize_history
($gs_, \
@refs);
958 if (scalar(@
$linear_refs) !=
959 scalar(@
$linear_refs_)) {
960 fatal
"# of revisions changed ",
962 join("\n", @
$linear_refs),
964 join("\n", @
$linear_refs_), "\n",
965 'If you are attempting to commit ',
966 "merges, try running:\n\t",
967 'git rebase --interactive',
968 '--preserve-merges ',
970 "\nBefore dcommitting";
972 if ($url_ ne $expect_url) {
973 if ($url_ eq $gs->metadata_url) {
975 "Accepting rewritten URL:",
979 "URL mismatch after rebase:",
980 " $url_ != $expect_url";
983 if ($uuid_ ne $uuid) {
984 fatal
"uuid mismatch after rebase: ",
989 for ($i = 0; $i < scalar @
$linear_refs; $i++) {
990 my $new = $linear_refs_->[$i] or next;
992 $parents->{$linear_refs->[$i]};
1002 my $new_head = command_oneline
(qw
/rev-parse HEAD/);
1003 my $new_is_symbolic = eval {
1004 command_oneline
(qw
/symbolic-ref -q HEAD/);
1006 if ($new_is_symbolic) {
1007 print "dcommitted the branch ", $head, "\n";
1009 print "dcommitted on a detached HEAD because you gave ",
1010 "a revision argument.\n",
1011 "The rewritten commit is: ", $new_head, "\n";
1013 command
(['checkout', $old_head], STDERR
=> 0);
1016 unlink $gs->{index};
1020 my ($branch_name, $head) = @_;
1022 unless (defined $branch_name && length $branch_name) {
1023 die(($_tag ?
"tag" : "branch") . " name required\n");
1027 my (undef, $rev, undef, $gs) = working_head_info
($head);
1028 my $src = $gs->full_pushurl;
1030 my $remote = Git
::SVN
::read_all_remotes
()->{$gs->{repo_id
}};
1031 my $allglobs = $remote->{ $_tag ?
'tags' : 'branches' };
1033 if ($#{$allglobs} == 0) {
1034 $glob = $allglobs->[0];
1036 unless(defined $_branch_dest) {
1038 $_tag ?
"tag" : "branch",
1039 " paths defined for Subversion repository.\n",
1040 "You must specify where you want to create the ",
1041 $_tag ?
"tag" : "branch",
1042 " with the --destination argument.\n";
1044 foreach my $g (@
{$allglobs}) {
1045 # SVN::Git::Editor could probably be moved to Git.pm..
1046 my $re = SVN
::Git
::Editor
::glob2pat
($g->{path
}->{left
});
1047 if ($_branch_dest =~ /$re/) {
1052 unless (defined $glob) {
1053 my $dest_re = qr/\b\Q$_branch_dest\E\b/;
1054 foreach my $g (@
{$allglobs}) {
1055 $g->{path
}->{left
} =~ /$dest_re/ or next;
1056 if (defined $glob) {
1057 die "Ambiguous destination: ",
1058 $_branch_dest, "\nmatches both '",
1059 $glob->{path
}->{left
}, "' and '",
1060 $g->{path
}->{left
}, "'\n";
1064 unless (defined $glob) {
1066 $_tag ?
"tag" : "branch",
1067 " destination $_branch_dest\n";
1071 my ($lft, $rgt) = @
{ $glob->{path
} }{qw
/left right/};
1073 if (defined $_commit_url) {
1074 $url = $_commit_url;
1076 $url = eval { command_oneline
('config', '--get',
1077 "svn-remote.$gs->{repo_id}.commiturl") };
1079 $url = $remote->{pushurl
} || $remote->{url
};
1082 my $dst = join '/', $url, $lft, $branch_name, ($rgt || ());
1084 if ($dst =~ /^https:/ && $src =~ /^http:/) {
1085 $src=~s/^http:/https:/;
1090 my $ctx = SVN
::Client
->new(
1091 auth
=> Git
::SVN
::Ra
::_auth_providers
(),
1093 ${ $_[0] } = defined $_message
1095 : 'Create ' . ($_tag ?
'tag ' : 'branch ' )
1101 $ctx->ls($dst, 'HEAD', 0);
1102 } and die "branch ${branch_name} already exists\n";
1104 print "Copying ${src} at r${rev} to ${dst}...\n";
1105 $ctx->copy($src, $rev, $dst)
1112 my $revision_or_hash = shift or die "SVN or git revision required ",
1113 "as a command-line argument\n";
1115 if ($revision_or_hash =~ /^r\d+$/) {
1119 my (undef, undef, $uuid, $gs) = working_head_info
($head, \
@refs);
1121 die "Unable to determine upstream SVN information from ",
1124 my $desired_revision = substr($revision_or_hash, 1);
1125 $result = $gs->rev_map_get($desired_revision, $uuid);
1127 my (undef, $rev, undef) = cmt_metadata
($revision_or_hash);
1130 print "$result\n" if $result;
1133 sub auto_create_empty_directories
{
1135 my $var = eval { command_oneline
('config', '--get', '--bool',
1136 "svn-remote.$gs->{repo_id}.automkdirs") };
1137 # By default, create empty directories by consulting the unhandled log,
1138 # but allow setting it to 'false' to skip it.
1139 return !($var && $var eq 'false');
1143 command_noisy
(qw
/update-index --refresh/);
1144 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
1146 die "Unable to determine upstream SVN information from ",
1147 "working tree history\n";
1150 print "Remote Branch: " . $gs->refname . "\n";
1151 print "SVN URL: " . $url . "\n";
1154 if (command
(qw
/diff-index HEAD --/)) {
1155 print STDERR
"Cannot rebase with uncommited changes:\n";
1156 command_noisy
('status');
1160 # rebase will checkout for us, so no need to do it explicitly
1161 $_no_checkout = 'true';
1162 $_fetch_all ?
$gs->fetch_all : $gs->fetch;
1164 command_noisy
(rebase_cmd
(), $gs->refname);
1165 if (auto_create_empty_directories
($gs)) {
1170 sub cmd_show_ignore
{
1171 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
1172 $gs ||= Git
::SVN
->new;
1173 my $r = (defined $_revision ?
$_revision : $gs->ra->get_latest_revnum);
1174 $gs->prop_walk($gs->{path
}, $r, sub {
1175 my ($gs, $path, $props) = @_;
1176 print STDOUT
"\n# $path\n";
1177 my $s = $props->{'svn:ignore'} or return;
1178 $s =~ s/[\r\n]+/\n/g;
1182 print STDOUT
"$s\n";
1186 sub cmd_show_externals
{
1187 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
1188 $gs ||= Git
::SVN
->new;
1189 my $r = (defined $_revision ?
$_revision : $gs->ra->get_latest_revnum);
1190 $gs->prop_walk($gs->{path
}, $r, sub {
1191 my ($gs, $path, $props) = @_;
1192 print STDOUT
"\n# $path\n";
1193 my $s = $props->{'svn:externals'} or return;
1194 $s =~ s/[\r\n]+/\n/g;
1197 print STDOUT
"$s\n";
1201 sub cmd_create_ignore
{
1202 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
1203 $gs ||= Git
::SVN
->new;
1204 my $r = (defined $_revision ?
$_revision : $gs->ra->get_latest_revnum);
1205 $gs->prop_walk($gs->{path
}, $r, sub {
1206 my ($gs, $path, $props) = @_;
1207 # $path is of the form /path/to/dir/
1208 $path = '.' . $path;
1209 # SVN can have attributes on empty directories,
1210 # which git won't track
1211 mkpath
([$path]) unless -d
$path;
1212 my $ignore = $path . '.gitignore';
1213 my $s = $props->{'svn:ignore'} or return;
1214 open(GITIGNORE
, '>', $ignore)
1215 or fatal
("Failed to open `$ignore' for writing: $!");
1216 $s =~ s/[\r\n]+/\n/g;
1219 # Prefix all patterns so that the ignore doesn't apply
1220 # to sub-directories.
1222 print GITIGNORE
"$s\n";
1224 or fatal
("Failed to close `$ignore': $!");
1225 command_noisy
('add', '-f', $ignore);
1230 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
1231 $gs ||= Git
::SVN
->new;
1232 $gs->mkemptydirs($_revision);
1235 sub canonicalize_path
{
1237 my $dot_slash_added = 0;
1238 if (substr($path, 0, 1) ne "/") {
1239 $path = "./" . $path;
1240 $dot_slash_added = 1;
1242 # File::Spec->canonpath doesn't collapse x/../y into y (for a
1243 # good reason), so let's do this manually.
1245 $path =~ s
#/\.(?:/|$)#/#g;
1246 $path =~ s
#/[^/]+/\.\.##g;
1248 $path =~ s
#^\./## if $dot_slash_added;
1254 sub canonicalize_url
{
1256 $url =~ s
#^([^:]+://[^/]*/)(.*)$#$1 . canonicalize_path($2)#e;
1260 # get_svnprops(PATH)
1261 # ------------------
1262 # Helper for cmd_propget and cmd_proplist below.
1265 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
1266 $gs ||= Git
::SVN
->new;
1268 # prefix THE PATH by the sub-directory from which the user
1270 $path = $cmd_dir_prefix . $path;
1271 fatal
("No such file or directory: $path") unless -e
$path;
1272 my $is_dir = -d
$path ?
1 : 0;
1273 $path = $gs->{path
} . '/' . $path;
1275 # canonicalize the path (otherwise libsvn will abort or fail to
1277 $path = canonicalize_path
($path);
1279 my $r = (defined $_revision ?
$_revision : $gs->ra->get_latest_revnum);
1282 (undef, undef, $props) = $gs->ra->get_dir($path, $r);
1285 (undef, $props) = $gs->ra->get_file($path, $r, undef);
1290 # cmd_propget (PROP, PATH)
1291 # ------------------------
1292 # Print the SVN property PROP for PATH.
1294 my ($prop, $path) = @_;
1295 $path = '.' if not defined $path;
1296 usage
(1) if not defined $prop;
1297 my $props = get_svnprops
($path);
1298 if (not defined $props->{$prop}) {
1299 fatal
("`$path' does not have a `$prop' SVN property.");
1301 print $props->{$prop} . "\n";
1304 # cmd_proplist (PATH)
1305 # -------------------
1306 # Print the list of SVN properties for PATH.
1309 $path = '.' if not defined $path;
1310 my $props = get_svnprops
($path);
1311 print "Properties on '$path':\n";
1312 foreach (sort keys %{$props}) {
1317 sub cmd_multi_init
{
1319 unless (defined $_trunk || @_branches || @_tags) {
1323 $_prefix = '' unless defined $_prefix;
1325 $url = canonicalize_url
($url);
1329 if (defined $_trunk) {
1331 my $trunk_ref = 'refs/remotes/' . $_prefix . 'trunk';
1332 # try both old-style and new-style lookups:
1333 my $gs_trunk = eval { Git
::SVN
->new($trunk_ref) };
1334 unless ($gs_trunk) {
1335 my ($trunk_url, $trunk_path) =
1336 complete_svn_url
($url, $_trunk);
1337 $gs_trunk = Git
::SVN
->init($trunk_url, $trunk_path,
1341 return unless @_branches || @_tags;
1342 my $ra = $url ? Git
::SVN
::Ra
->new($url) : undef;
1343 foreach my $path (@_branches) {
1344 complete_url_ls_init
($ra, $path, '--branches/-b', $_prefix);
1346 foreach my $path (@_tags) {
1347 complete_url_ls_init
($ra, $path, '--tags/-t', $_prefix.'tags/');
1351 sub cmd_multi_fetch
{
1352 $Git::SVN
::no_reuse_existing
= undef;
1353 my $remotes = Git
::SVN
::read_all_remotes
();
1354 foreach my $repo_id (sort keys %$remotes) {
1355 if ($remotes->{$repo_id}->{url
}) {
1356 Git
::SVN
::fetch_all
($repo_id, $remotes);
1361 # this command is special because it requires no metadata
1362 sub cmd_commit_diff
{
1363 my ($ta, $tb, $url) = @_;
1364 my $usage = "Usage: $0 commit-diff -r<revision> ".
1365 "<tree-ish> <tree-ish> [<URL>]";
1366 fatal
($usage) if (!defined $ta || !defined $tb);
1368 if (!defined $url) {
1369 my $gs = eval { Git
::SVN
->new };
1371 fatal
("Needed URL or usable git-svn --id in ",
1372 "the command-line\n", $usage);
1375 $svn_path = $gs->{path
};
1377 unless (defined $_revision) {
1378 fatal
("-r|--revision is a required argument\n", $usage);
1380 if (defined $_message && defined $_file) {
1381 fatal
("Both --message/-m and --file/-F specified ",
1382 "for the commit message.\n",
1383 "I have no idea what you mean");
1385 if (defined $_file) {
1386 $_message = file_to_s
($_file);
1388 $_message ||= get_commit_entry
($tb)->{log};
1390 my $ra ||= Git
::SVN
::Ra
->new($url);
1393 $r = $ra->get_latest_revnum;
1394 } elsif ($r !~ /^\d+$/) {
1395 die "revision argument: $r not understood by git-svn\n";
1397 my %ed_opts = ( r
=> $r,
1402 editor_cb
=> sub { print "Committed r$_[0]\n" },
1403 svn_path
=> $svn_path );
1404 if (!SVN
::Git
::Editor
->new(\
%ed_opts)->apply_diff) {
1405 print "No changes\n$ta == $tb\n";
1409 sub escape_uri_only
{
1412 foreach (split m{/}, $uri) {
1413 s/([^~\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg;
1421 if ($url =~ m
#^([^:]+)://([^/]*)(.*)$#) {
1422 my ($scheme, $domain, $uri) = ($1, $2, escape_uri_only
($3));
1423 $url = "$scheme://$domain$uri";
1429 my $path = canonicalize_path
(defined($_[0]) ?
$_[0] : ".");
1430 my $fullpath = canonicalize_path
($cmd_dir_prefix . $path);
1432 die "Too many arguments specified\n";
1435 my ($file_type, $diff_status) = find_file_type_and_diff_status
($path);
1437 if (!$file_type && !$diff_status) {
1438 print STDERR
"svn: '$path' is not under version control\n";
1442 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
1444 die "Unable to determine upstream SVN information from ",
1445 "working tree history\n";
1448 # canonicalize_path() will return "" to make libsvn 1.5.x happy,
1449 $path = "." if $path eq "";
1451 my $full_url = $url . ($fullpath eq "" ?
"" : "/$fullpath");
1454 print escape_url
($full_url), "\n";
1458 my $result = "Path: $path\n";
1459 $result .= "Name: " . basename
($path) . "\n" if $file_type ne "dir";
1460 $result .= "URL: " . escape_url
($full_url) . "\n";
1463 my $repos_root = $gs->repos_root;
1464 Git
::SVN
::remove_username
($repos_root);
1465 $result .= "Repository Root: " . escape_url
($repos_root) . "\n";
1468 $result .= "Repository Root: (offline)\n";
1471 $result .= "Repository UUID: $uuid\n" unless $diff_status eq "A" &&
1472 ($SVN::Core
::VERSION
le '1.5.4' || $file_type ne "dir");
1473 $result .= "Revision: " . ($diff_status eq "A" ?
0 : $rev) . "\n";
1475 $result .= "Node Kind: " .
1476 ($file_type eq "dir" ?
"directory" : "file") . "\n";
1478 my $schedule = $diff_status eq "A"
1480 : ($diff_status eq "D" ?
"delete" : "normal");
1481 $result .= "Schedule: $schedule\n";
1483 if ($diff_status eq "A") {
1484 print $result, "\n";
1488 my ($lc_author, $lc_rev, $lc_date_utc);
1489 my @args = Git
::SVN
::Log
::git_svn_log_cmd
($rev, $rev, "--", $fullpath);
1490 my $log = command_output_pipe
(@args);
1491 my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
1493 if (/^${esc_color}author (.+) <[^>]+> (\d+) ([\-\+]?\d+)$/o) {
1495 $lc_date_utc = Git
::SVN
::Log
::parse_git_date
($2, $3);
1496 } elsif (/^${esc_color} (git-svn-id:.+)$/o) {
1497 (undef, $lc_rev, undef) = ::extract_metadata
($1);
1502 Git
::SVN
::Log
::set_local_timezone
();
1504 $result .= "Last Changed Author: $lc_author\n";
1505 $result .= "Last Changed Rev: $lc_rev\n";
1506 $result .= "Last Changed Date: " .
1507 Git
::SVN
::Log
::format_svn_date
($lc_date_utc) . "\n";
1509 if ($file_type ne "dir") {
1510 my $text_last_updated_date =
1511 ($diff_status eq "D" ?
$lc_date_utc : (stat $path)[9]);
1513 "Text Last Updated: " .
1514 Git
::SVN
::Log
::format_svn_date
($text_last_updated_date) .
1517 if ($diff_status eq "D") {
1519 command_output_pipe
(qw(cat-file blob), "HEAD:$path");
1520 if ($file_type eq "link") {
1521 my $file_name = <$fh>;
1522 $checksum = md5sum
("link $file_name");
1524 $checksum = md5sum
($fh);
1526 command_close_pipe
($fh, $ctx);
1527 } elsif ($file_type eq "link") {
1529 command
(qw(cat-file blob), "HEAD:$path");
1531 md5sum
("link " . $file_name);
1533 open FILE
, "<", $path or die $!;
1534 $checksum = md5sum
(\
*FILE
);
1535 close FILE
or die $!;
1537 $result .= "Checksum: " . $checksum . "\n";
1540 print $result, "\n";
1544 my $target = shift || $_revision or die "SVN revision required\n";
1545 $target = $1 if $target =~ /^r(\d+)$/;
1546 $target =~ /^\d+$/ or die "Numeric SVN revision expected\n";
1547 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
1549 die "Unable to determine upstream SVN information from ".
1552 my ($r, $c) = $gs->find_rev_before($target, not $_fetch_parent);
1553 die "Cannot find SVN revision $target\n" unless defined($c);
1554 $gs->rev_map_set($r, $c, 'reset', $uuid);
1555 print "r$r = $c ($gs->{ref_id})\n";
1559 if (!$can_compress) {
1560 warn "Compress::Zlib could not be found; unhandled.log " .
1561 "files will not be compressed.\n";
1563 find
({ wanted
=> \
&gc_directory
, no_chdir
=> 1}, "$ENV{GIT_DIR}/svn");
1566 ########################### utility functions #########################
1569 my @cmd = qw
/rebase/;
1570 push @cmd, '-v' if $_verbose;
1571 push @cmd, qw
/--merge/ if $_merge;
1572 push @cmd, "--strategy=$_strategy" if $_strategy;
1576 sub post_fetch_checkout
{
1577 return if $_no_checkout;
1578 my $gs = $Git::SVN
::_head
or return;
1579 return if verify_ref
('refs/heads/master^0');
1581 # look for "trunk" ref if it exists
1582 my $remote = Git
::SVN
::read_all_remotes
()->{$gs->{repo_id
}};
1583 my $fetch = $remote->{fetch
};
1585 foreach my $p (keys %$fetch) {
1586 basename
($fetch->{$p}) eq 'trunk' or next;
1587 $gs = Git
::SVN
->new($fetch->{$p}, $gs->{repo_id
}, $p);
1592 my $valid_head = verify_ref
('HEAD^0');
1593 command_noisy
(qw(update-ref refs/heads/master), $gs->refname);
1594 return if ($valid_head || !verify_ref
('HEAD^0'));
1596 return if $ENV{GIT_DIR
} !~ m
#^(?:.*/)?\.git$#;
1597 my $index = $ENV{GIT_INDEX_FILE
} || "$ENV{GIT_DIR}/index";
1598 return if -f
$index;
1600 return if command_oneline
(qw
/rev-parse --is-inside-work-tree/) eq 'false';
1601 return if command_oneline
(qw
/rev-parse --is-inside-git-dir/) eq 'true';
1602 command_noisy
(qw
/read-tree -m -u -v HEAD HEAD/);
1603 print STDERR
"Checked out HEAD:\n ",
1604 $gs->full_url, " r", $gs->last_rev, "\n";
1605 if (auto_create_empty_directories
($gs)) {
1606 $gs->mkemptydirs($gs->last_rev);
1610 sub complete_svn_url
{
1611 my ($url, $path) = @_;
1613 if ($path !~ m
#^[a-z\+]+://#) {
1614 if (!defined $url || $url !~ m
#^[a-z\+]+://#) {
1615 fatal
("E: '$path' is not a complete URL ",
1616 "and a separate URL is not specified");
1618 return ($url, $path);
1623 sub complete_url_ls_init
{
1624 my ($ra, $repo_path, $switch, $pfx) = @_;
1625 unless ($repo_path) {
1626 print STDERR
"W: $switch not specified\n";
1629 $repo_path =~ s
#/+$##;
1630 if ($repo_path =~ m
#^[a-z\+]+://#) {
1631 $ra = Git
::SVN
::Ra
->new($repo_path);
1634 $repo_path =~ s
#^/+##;
1636 fatal
("E: '$repo_path' is not a complete URL ",
1637 "and a separate URL is not specified");
1640 my $url = $ra->{url
};
1641 my $gs = Git
::SVN
->init($url, undef, undef, undef, 1);
1642 my $k = "svn-remote.$gs->{repo_id}.url";
1643 my $orig_url = eval { command_oneline
(qw
/config --get/, $k) };
1644 if ($orig_url && ($orig_url ne $gs->{url
})) {
1645 die "$k already set: $orig_url\n",
1646 "wanted to set to: $gs->{url}\n";
1648 command_oneline
('config', $k, $gs->{url
}) unless $orig_url;
1649 my $remote_path = "$gs->{path}/$repo_path";
1650 $remote_path =~ s{%([0-9A-F]{2})}{chr hex($1)}ieg;
1651 $remote_path =~ s
#/+#/#g;
1652 $remote_path =~ s
#^/##g;
1653 $remote_path .= "/*" if $remote_path !~ /\
*/;
1654 my ($n) = ($switch =~ /^--(\w+)/);
1655 if (length $pfx && $pfx !~ m
#/$#) {
1656 die "--prefix='$pfx' must have a trailing slash '/'\n";
1658 command_noisy
('config',
1660 "svn-remote.$gs->{repo_id}.$n",
1661 "$remote_path:refs/remotes/$pfx*" .
1662 ('/*' x
(($remote_path =~ tr
/*/*/) - 1)) );
1667 eval { command_oneline
([ 'rev-parse', '--verify', $ref ],
1668 { STDERR
=> 0 }); };
1671 sub get_tree_from_treeish
{
1673 # $treeish can be a symbolic ref, too:
1674 my $type = command_oneline
(qw
/cat-file -t/, $treeish);
1676 while ($type eq 'tag') {
1677 ($treeish, $type) = command
(qw
/cat-file tag/, $treeish);
1679 if ($type eq 'commit') {
1680 $expected = (grep /^tree /, command
(qw
/cat-file commit/,
1682 ($expected) = ($expected =~ /^tree ($sha1)$/o);
1683 die "Unable to get tree from $treeish\n" unless $expected;
1684 } elsif ($type eq 'tree') {
1685 $expected = $treeish;
1687 die "$treeish is a $type, expected tree, tag or commit\n";
1692 sub get_commit_entry
{
1693 my ($treeish) = shift;
1694 my %log_entry = ( log => '', tree
=> get_tree_from_treeish
($treeish) );
1695 my $commit_editmsg = "$ENV{GIT_DIR}/COMMIT_EDITMSG";
1696 my $commit_msg = "$ENV{GIT_DIR}/COMMIT_MSG";
1697 open my $log_fh, '>', $commit_editmsg or croak
$!;
1699 my $type = command_oneline
(qw
/cat-file -t/, $treeish);
1700 if ($type eq 'commit' || $type eq 'tag') {
1701 my ($msg_fh, $ctx) = command_output_pipe
('cat-file',
1709 $in_msg = 1 if (/^\s*$/);
1710 $author = $1 if (/^author (.*>)/);
1711 } elsif (/^git-svn-id: /) {
1712 # skip this for now, we regenerate the
1713 # correct one on re-fetch anyways
1714 # TODO: set *:merge properties or like...
1716 if (/^From:/ || /^Signed-off-by:/) {
1722 $msgbuf =~ s/\s+$//s;
1723 if ($Git::SVN
::_add_author_from
&& defined($author)
1725 $msgbuf .= "\n\nFrom: $author";
1727 print $log_fh $msgbuf or croak
$!;
1728 command_close_pipe
($msg_fh, $ctx);
1730 close $log_fh or croak
$!;
1732 if ($_edit || ($type eq 'tree')) {
1733 chomp(my $editor = command_oneline
(qw(var GIT_EDITOR)));
1734 system('sh', '-c', $editor.' "$@"', $editor, $commit_editmsg);
1736 rename $commit_editmsg, $commit_msg or croak
$!;
1739 # SVN requires messages to be UTF-8 when entering the repo
1741 open $log_fh, '<', $commit_msg or croak
$!;
1743 chomp($log_entry{log} = <$log_fh>);
1745 my $enc = Git
::config
('i18n.commitencoding') || 'UTF-8';
1746 my $msg = $log_entry{log};
1748 eval { $msg = Encode
::decode
($enc, $msg, 1) };
1750 die "Could not decode as $enc:\n", $msg,
1751 "\nPerhaps you need to set i18n.commitencoding\n";
1754 eval { $msg = Encode
::encode
('UTF-8', $msg, 1) };
1755 die "Could not encode as UTF-8:\n$msg\n" if $@
;
1757 $log_entry{log} = $msg;
1759 close $log_fh or croak
$!;
1766 my ($str, $file, $mode) = @_;
1767 open my $fd,'>',$file or croak
$!;
1768 print $fd $str,"\n" or croak
$!;
1769 close $fd or croak
$!;
1770 chmod ($mode &~ umask, $file) if (defined $mode);
1775 open my $fd,'<',$file or croak
"$!: file: $file\n";
1778 close $fd or croak
$!;
1783 # '<svn username> = real-name <email address>' mapping based on git-svnimport:
1785 open my $authors, '<', $_authors or die "Can't open $_authors $!\n";
1786 my $log = $cmd eq 'log';
1787 while (<$authors>) {
1789 next unless /^(.+?|\(no author\))\s*=\s*(.+?)\s*<(.+)>\s*$/;
1790 my ($user, $name, $email) = ($1, $2, $3);
1792 $Git::SVN
::Log
::rusers
{"$name <$email>"} = $user;
1794 $users{$user} = [$name, $email];
1797 close $authors or croak
$!;
1800 # convert GetOpt::Long specs for use by git-config
1801 sub read_git_config
{
1804 foreach my $o (keys %$opts) {
1805 # if we have mixedCase and a long option-only, then
1806 # it's a config-only variable that we don't need for
1808 push @config_only, $o if ($o =~ /[A-Z]/ && $o =~ /^[a-z]+$/i);
1809 my $v = $opts->{$o};
1810 my ($key) = ($o =~ /^([a-zA-Z\-]+)/);
1812 my $arg = 'git config';
1813 $arg .= ' --int' if ($o =~ /[:=]i$/);
1814 $arg .= ' --bool' if ($o !~ /[:=][sfi]$/);
1815 if (ref $v eq 'ARRAY') {
1816 chomp(my @tmp = `$arg --get-all svn.$key`);
1819 chomp(my $tmp = `$arg --get svn.$key`);
1820 if ($tmp && !($arg =~ / --bool/ && $tmp eq 'false')) {
1825 delete @
$opts{@config_only} if @config_only;
1828 sub extract_metadata
{
1829 my $id = shift or return (undef, undef, undef);
1830 my ($url, $rev, $uuid) = ($id =~ /^\s
*git
-svn
-id
:\s
+(.*)\@
(\d
+)
1831 \s
([a
-f\d\
-]+)$/ix
);
1832 if (!defined $rev || !$uuid || !$url) {
1833 # some of the original repositories I made had
1834 # identifiers like this:
1835 ($rev, $uuid) = ($id =~/^\s*git-svn-id:\s(\d+)\@([a-f\d\-]+)/i);
1837 return ($url, $rev, $uuid);
1841 return extract_metadata
((grep(/^git-svn-id: /,
1842 command
(qw
/cat-file commit/, shift)))[-1]);
1845 sub cmt_sha2rev_batch
{
1847 my ($pid, $in, $out, $ctx) = command_bidi_pipe
(qw
/cat-file --batch/);
1850 foreach my $sha (@
{$list}) {
1853 print $out $sha, "\n";
1855 while (my $line = <$in>) {
1856 if ($first && $line =~ /^[[:xdigit:]]{40}\smissing$/) {
1859 $line =~ /^[[:xdigit:]]{40}\scommit\s(\d+)$/) {
1863 } elsif ($line =~ /^(git-svn-id: )/) {
1864 my (undef, $rev, undef) =
1865 extract_metadata
($line);
1869 $size -= length($line);
1870 last if ($size == 0);
1874 command_close_bidi_pipe
($pid, $in, $out, $ctx);
1879 sub working_head_info
{
1880 my ($head, $refs) = @_;
1881 my @args = qw
/rev-list --first-parent --pretty=medium/;
1882 my ($fh, $ctx) = command_output_pipe
(@args, $head);
1886 if ( m{^commit ($::sha1)$} ) {
1887 unshift @
$refs, $hash if $hash and $refs;
1891 next unless s{^\s*(git-svn-id:)}{$1};
1892 my ($url, $rev, $uuid) = extract_metadata
($_);
1893 if (defined $url && defined $rev) {
1894 next if $max{$url} and $max{$url} < $rev;
1895 if (my $gs = Git
::SVN
->find_by_url($url)) {
1896 my $c = $gs->rev_map_get($rev, $uuid);
1897 if ($c && $c eq $hash) {
1898 close $fh; # break the pipe
1899 return ($url, $rev, $uuid, $gs);
1901 $max{$url} ||= $gs->rev_map_max;
1906 command_close_pipe
($fh, $ctx);
1907 (undef, undef, undef, undef);
1910 sub read_commit_parents
{
1911 my ($parents, $c) = @_;
1912 chomp(my $p = command_oneline
(qw
/rev-list --parents -1/, $c));
1913 $p =~ s/^($c)\s*// or die "rev-list --parents -1 $c failed!\n";
1914 @
{$parents->{$c}} = split(/ /, $p);
1917 sub linearize_history
{
1918 my ($gs, $refs) = @_;
1920 foreach my $c (@
$refs) {
1921 read_commit_parents
(\
%parents, $c);
1926 my $last_svn_commit = $gs->last_commit;
1927 foreach my $c (reverse @
$refs) {
1928 next if $c eq $last_svn_commit;
1931 unshift @linear_refs, $c;
1934 # we only want the first parent to diff against for linear
1935 # history, we save the rest to inject when we finalize the
1937 my $fp_a = verify_ref
("$c~1");
1938 my $fp_b = shift @
{$parents{$c}} if $parents{$c};
1939 if (!$fp_a || !$fp_b) {
1941 "has no parent commit, and therefore ",
1942 "nothing to diff against.\n",
1943 "You should be working from a repository ",
1944 "originally created by git-svn\n";
1946 if ($fp_a ne $fp_b) {
1947 die "$c~1 = $fp_a, however parsing commit $c ",
1948 "revealed that:\n$c~1 = $fp_b\nBUG!\n";
1951 foreach my $p (@
{$parents{$c}}) {
1955 (\
@linear_refs, \
%parents);
1958 sub find_file_type_and_diff_status
{
1960 return ('dir', '') if $path eq '';
1963 command_oneline
(qw(diff --cached --name-status --), $path) || "";
1964 my $diff_status = (split(' ', $diff_output))[0] || "";
1966 my $ls_tree = command_oneline
(qw(ls-tree HEAD), $path) || "";
1968 return (undef, undef) if !$diff_status && !$ls_tree;
1970 if ($diff_status eq "A") {
1971 return ("link", $diff_status) if -l
$path;
1972 return ("dir", $diff_status) if -d
$path;
1973 return ("file", $diff_status);
1976 my $mode = (split(' ', $ls_tree))[0] || "";
1978 return ("link", $diff_status) if $mode eq "120000";
1979 return ("dir", $diff_status) if $mode eq "040000";
1980 return ("file", $diff_status);
1986 my $md5 = Digest
::MD5
->new();
1987 if ($ref eq 'GLOB' || $ref eq 'IO::File' || $ref eq 'File::Temp') {
1988 $md5->addfile($arg) or croak
$!;
1989 } elsif ($ref eq 'SCALAR') {
1990 $md5->add($$arg) or croak
$!;
1992 $md5->add($arg) or croak
$!;
1994 ::fatal
"Can't provide MD5 hash for unknown ref type: '", $ref, "'";
1996 return $md5->hexdigest();
2000 if ($can_compress && -f
$_ && basename
($_) eq "unhandled.log") {
2001 my $out_filename = $_ . ".gz";
2002 open my $in_fh, "<", $_ or die "Unable to open $_: $!\n";
2004 my $gz = Compress
::Zlib
::gzopen
($out_filename, "ab") or
2005 die "Unable to open $out_filename: $!\n";
2008 while ($res = sysread($in_fh, my $str, 1024)) {
2009 $gz->gzwrite($str) or
2010 die "Unable to write: ".$gz->gzerror()."!\n";
2012 unlink $_ or die "unlink $File::Find::name: $!\n";
2013 } elsif (-f
$_ && basename
($_) eq "index") {
2014 unlink $_ or die "unlink $_: $!\n";
2021 use Fcntl qw
/:DEFAULT :seek/;
2022 use constant rev_map_fmt
=> 'NH40';
2023 use vars qw
/$default_repo_id $default_ref_id $_no_metadata $_follow_parent
2024 $_repack $_repack_flags $_use_svm_props $_head
2025 $_use_svnsync_props $no_reuse_existing $_minimize_url
2026 $_use_log_author $_add_author_from $_localtime/;
2028 use File
::Path qw
/mkpath/;
2029 use File
::Copy qw
/copy/;
2032 use Memoize
; # core since 5.8.0, Jul 2002
2033 use Memoize
::Storable
;
2034 use POSIX
qw(:signal_h);
2036 my ($_gc_nr, $_gc_period);
2038 # properties that we do not log:
2041 %SKIP_PROP = map { $_ => 1 } qw
/svn
:wc
:ra_dav
:version
-url
2042 svn
:special svn
:executable
2043 svn
:entry
:committed
-rev
2044 svn
:entry
:last-author
2046 svn
:entry
:committed
-date
/;
2048 # some options are read globally, but can be overridden locally
2049 # per [svn-remote "..."] section. Command-line options will *NOT*
2050 # override options set in an [svn-remote "..."] section
2052 for my $option (qw
/follow_parent no_metadata use_svm_props
2053 use_svnsync_props
/) {
2056 my $prop = "-$option";
2059 return $self->{$prop} if exists $self->{$prop};
2060 my $k = "svn-remote.$self->{repo_id}.$key";
2061 eval { command_oneline
(qw
/config --get/, $k) };
2063 $self->{$prop} = ${"Git::SVN::_$option"};
2065 my $v = command_oneline
(qw
/config --bool/,$k);
2066 $self->{$prop} = $v eq 'false' ?
0 : 1;
2068 return $self->{$prop};
2074 my (%LOCKFILES, %INDEX_FILES);
2076 unlink keys %LOCKFILES if %LOCKFILES;
2077 unlink keys %INDEX_FILES if %INDEX_FILES;
2080 sub resolve_local_globs
{
2081 my ($url, $fetch, $glob_spec) = @_;
2082 return unless defined $glob_spec;
2083 my $ref = $glob_spec->{ref};
2084 my $path = $glob_spec->{path
};
2085 foreach (command
(qw
#for-each-ref --format=%(refname) refs/#)) {
2086 next unless m
#^$ref->{regex}$#;
2088 my $pathname = desanitize_refname
($path->full_path($p));
2089 my $refname = desanitize_refname
($ref->full_path($p));
2090 if (my $existing = $fetch->{$pathname}) {
2091 if ($existing ne $refname) {
2092 die "Refspec conflict:\n",
2093 "existing: $existing\n",
2094 " globbed: $refname\n";
2096 my $u = (::cmt_metadata
("$refname"))[0];
2097 $u =~ s!^\Q$url\E(/|$)!! or die
2098 "$refname: '$url' not found in '$u'\n";
2099 if ($pathname ne $u) {
2100 warn "W: Refspec glob conflict ",
2101 "(ref: $refname):\n",
2102 "expected path: $pathname\n",
2104 "Continuing ahead with $u\n";
2108 $fetch->{$pathname} = $refname;
2113 sub parse_revision_argument
{
2114 my ($base, $head) = @_;
2115 if (!defined $::_revision
|| $::_revision
eq 'BASE:HEAD') {
2116 return ($base, $head);
2118 return ($1, $2) if ($::_revision
=~ /^(\d+):(\d+)$/);
2119 return ($::_revision
, $::_revision
) if ($::_revision
=~ /^\d+$/);
2120 return ($head, $head) if ($::_revision
eq 'HEAD');
2121 return ($base, $1) if ($::_revision
=~ /^BASE:(\d+)$/);
2122 return ($1, $head) if ($::_revision
=~ /^(\d+):HEAD$/);
2123 die "revision argument: $::_revision not understood by git-svn\n";
2127 my ($repo_id, $remotes) = @_;
2131 $repo_id = $gs->{repo_id
};
2133 $remotes ||= read_all_remotes
();
2134 my $remote = $remotes->{$repo_id} or
2135 die "[svn-remote \"$repo_id\"] unknown\n";
2136 my $fetch = $remote->{fetch
};
2137 my $url = $remote->{url
} or die "svn-remote.$repo_id.url not defined\n";
2139 my $ra = Git
::SVN
::Ra
->new($url);
2140 my $uuid = $ra->get_uuid;
2141 my $head = $ra->get_latest_revnum;
2143 # ignore errors, $head revision may not even exist anymore
2144 eval { $ra->get_log("", $head, 0, 1, 0, 1, sub { $head = $_[1] }) };
2145 warn "W: $@\n" if $@
;
2147 my $base = defined $fetch ?
$head : 0;
2149 # read the max revs for wildcard expansion (branches/*, tags/*)
2150 foreach my $t (qw
/branches tags/) {
2151 defined $remote->{$t} or next;
2152 push @globs, @
{$remote->{$t}};
2154 my $max_rev = eval { tmp_config
(qw
/--int --get/,
2155 "svn-remote.$repo_id.${t}-maxRev") };
2156 if (defined $max_rev && ($max_rev < $base)) {
2158 } elsif (!defined $max_rev) {
2164 foreach my $p (sort keys %$fetch) {
2165 my $gs = Git
::SVN
->new($fetch->{$p}, $repo_id, $p);
2166 my $lr = $gs->rev_map_max;
2168 $base = $lr if ($lr < $base);
2174 ($base, $head) = parse_revision_argument
($base, $head);
2175 $ra->gs_fetch_loop_common($base, $head, \
@gs, \
@globs);
2178 sub read_all_remotes
{
2180 my $use_svm_props = eval { command_oneline
(qw
/config
--bool
2181 svn
.useSvmProps
/) };
2182 $use_svm_props = $use_svm_props eq 'true' if $use_svm_props;
2183 my $svn_refspec = qr{\s*(.*?)\s*:\s*(.+?)\s*};
2184 foreach (grep { s/^svn-remote\.// } command
(qw
/config -l/)) {
2185 if (m!^(.+)\.fetch=$svn_refspec$!) {
2186 my ($remote, $local_ref, $remote_ref) = ($1, $2, $3);
2187 die("svn-remote.$remote: remote ref '$remote_ref' "
2188 . "must start with 'refs/'\n")
2189 unless $remote_ref =~ m{^refs/};
2190 $local_ref = uri_decode
($local_ref);
2191 $r->{$remote}->{fetch
}->{$local_ref} = $remote_ref;
2192 $r->{$remote}->{svm
} = {} if $use_svm_props;
2193 } elsif (m!^(.+)\.usesvmprops=\s*(.*)\s*$!) {
2194 $r->{$1}->{svm
} = {};
2195 } elsif (m!^(.+)\.url=\s*(.*)\s*$!) {
2196 $r->{$1}->{url
} = $2;
2197 } elsif (m!^(.+)\.pushurl=\s*(.*)\s*$!) {
2198 $r->{$1}->{pushurl
} = $2;
2199 } elsif (m!^(.+)\.ignore-refs=\s*(.*)\s*$!) {
2200 $r->{$1}->{ignore_refs_regex
} = $2;
2201 } elsif (m!^(.+)\.(branches|tags)=$svn_refspec$!) {
2202 my ($remote, $t, $local_ref, $remote_ref) =
2204 die("svn-remote.$remote: remote ref '$remote_ref' ($t) "
2205 . "must start with 'refs/'\n")
2206 unless $remote_ref =~ m{^refs/};
2207 $local_ref = uri_decode
($local_ref);
2211 path
=> Git
::SVN
::GlobSpec
->new($local_ref, 1),
2212 ref => Git
::SVN
::GlobSpec
->new($remote_ref, 0) };
2213 if (length($rs->{ref}->{right
}) != 0) {
2214 die "The '*' glob character must be the last ",
2215 "character of '$remote_ref'\n";
2217 push @
{ $r->{$remote}->{$t} }, $rs;
2222 if (defined $r->{$_}->{svm
}) {
2225 my $section = "svn-remote.$_";
2227 source
=> tmp_config
('--get',
2228 "$section.svm-source"),
2229 replace
=> tmp_config
('--get',
2230 "$section.svm-replace"),
2233 $r->{$_}->{svm
} = $svm;
2237 foreach my $remote (keys %$r) {
2238 foreach ( grep { defined $_ }
2239 map { $r->{$remote}->{$_} } qw(branches tags) ) {
2240 foreach my $rs ( @
$_ ) {
2241 $rs->{ignore_refs_regex
} =
2242 $r->{$remote}->{ignore_refs_regex
};
2251 $_gc_nr = $_gc_period = 1000;
2252 if (defined $_repack || defined $_repack_flags) {
2253 warn "Repack options are obsolete; they have no effect.\n";
2257 sub verify_remotes_sanity
{
2258 return unless -d
$ENV{GIT_DIR
};
2260 foreach (command
(qw
/config -l/)) {
2261 if (m!^svn-remote\.(?:.+)\.fetch=.*:refs/remotes/(\S+)\s*$!) {
2263 die "Remote ref refs/remote/$1 is tracked by",
2264 "\n \"$_\"\nand\n \"$seen{$1}\"\n",
2265 "Please resolve this ambiguity in ",
2266 "your git configuration file before ",
2274 sub find_existing_remote
{
2275 my ($url, $remotes) = @_;
2276 return undef if $no_reuse_existing;
2278 foreach my $repo_id (keys %$remotes) {
2279 my $u = $remotes->{$repo_id}->{url
} or next;
2281 $existing = $repo_id;
2287 sub init_remote_config
{
2288 my ($self, $url, $no_write) = @_;
2289 $url =~ s!/+$!!; # strip trailing slash
2290 my $r = read_all_remotes
();
2291 my $existing = find_existing_remote
($url, $r);
2293 unless ($no_write) {
2294 print STDERR
"Using existing ",
2295 "[svn-remote \"$existing\"]\n";
2297 $self->{repo_id
} = $existing;
2298 } elsif ($_minimize_url) {
2299 my $min_url = Git
::SVN
::Ra
->new($url)->minimize_url;
2300 $existing = find_existing_remote
($min_url, $r);
2302 unless ($no_write) {
2303 print STDERR
"Using existing ",
2304 "[svn-remote \"$existing\"]\n";
2306 $self->{repo_id
} = $existing;
2308 if ($min_url ne $url) {
2309 unless ($no_write) {
2310 print STDERR
"Using higher level of URL: ",
2311 "$url => $min_url\n";
2313 my $old_path = $self->{path
};
2314 $self->{path
} = $url;
2315 $self->{path
} =~ s!^\Q$min_url\E(/|$)!!;
2316 if (length $old_path) {
2317 $self->{path
} .= "/$old_path";
2324 # verify that we aren't overwriting anything:
2326 command_oneline
('config', '--get',
2327 "svn-remote.$self->{repo_id}.url")
2329 if ($orig_url && ($orig_url ne $url)) {
2330 die "svn-remote.$self->{repo_id}.url already set: ",
2331 "$orig_url\nwanted to set to: $url\n";
2334 my ($xrepo_id, $xpath) = find_ref
($self->refname);
2335 if (!$no_write && defined $xpath) {
2336 die "svn-remote.$xrepo_id.fetch already set to track ",
2337 "$xpath:", $self->refname, "\n";
2339 unless ($no_write) {
2340 command_noisy
('config',
2341 "svn-remote.$self->{repo_id}.url", $url);
2342 $self->{path
} =~ s{^/}{};
2343 $self->{path
} =~ s{%([0-9A-F]{2})}{chr hex($1)}ieg;
2344 command_noisy
('config', '--add',
2345 "svn-remote.$self->{repo_id}.fetch",
2346 "$self->{path}:".$self->refname);
2348 $self->{url
} = $url;
2351 sub find_by_url
{ # repos_root and, path are optional
2352 my ($class, $full_url, $repos_root, $path) = @_;
2354 return undef unless defined $full_url;
2355 remove_username
($full_url);
2356 remove_username
($repos_root) if defined $repos_root;
2357 my $remotes = read_all_remotes
();
2358 if (defined $full_url && defined $repos_root && !defined $path) {
2360 $path =~ s
#^\Q$repos_root\E(?:/|$)##;
2362 foreach my $repo_id (keys %$remotes) {
2363 my $u = $remotes->{$repo_id}->{url
} or next;
2364 remove_username
($u);
2365 next if defined $repos_root && $repos_root ne $u;
2367 my $fetch = $remotes->{$repo_id}->{fetch
} || {};
2368 foreach my $t (qw
/branches tags/) {
2369 foreach my $globspec (@
{$remotes->{$repo_id}->{$t}}) {
2370 resolve_local_globs
($u, $fetch, $globspec);
2374 my $rwr = rewrite_root
({repo_id
=> $repo_id});
2375 my $svm = $remotes->{$repo_id}->{svm
}
2376 if defined $remotes->{$repo_id}->{svm
};
2377 unless (defined $p) {
2383 remove_username
($z);
2384 } elsif (defined $svm) {
2385 $z = $svm->{source
};
2386 $prefix = $svm->{replace
};
2387 $prefix =~ s
#^\Q$u\E(?:/|$)##;
2390 $p =~ s
#^\Q$z\E(?:/|$)#$prefix# or next;
2392 foreach my $f (keys %$fetch) {
2394 return Git
::SVN
->new($fetch->{$f}, $repo_id, $f);
2401 my ($class, $url, $path, $repo_id, $ref_id, $no_write) = @_;
2402 my $self = _new
($class, $repo_id, $ref_id, $path);
2404 $self->init_remote_config($url, $no_write);
2411 foreach (command
(qw
/config -l/)) {
2412 next unless m
!^svn
-remote\
.(.+)\
.fetch
=
2413 \s
*(.*?
)\s
*:\s
*(.+?
)\s
*$!x
;
2414 my ($repo_id, $path, $ref) = ($1, $2, $3);
2415 if ($ref eq $ref_id) {
2416 $path = '' if ($path =~ m
#^\./?#);
2417 return ($repo_id, $path);
2420 (undef, undef, undef);
2424 my ($class, $ref_id, $repo_id, $path) = @_;
2425 if (defined $ref_id && !defined $repo_id && !defined $path) {
2426 ($repo_id, $path) = find_ref
($ref_id);
2427 if (!defined $repo_id) {
2428 die "Could not find a \"svn-remote.*.fetch\" key ",
2429 "in the repository configuration matching: ",
2433 my $self = _new
($class, $repo_id, $ref_id, $path);
2434 if (!defined $self->{path
} || !length $self->{path
}) {
2435 my $fetch = command_oneline
('config', '--get',
2436 "svn-remote.$repo_id.fetch",
2438 die "Failed to read \"svn-remote.$repo_id.fetch\" ",
2439 "\":$ref_id\$\" in config\n";
2440 ($self->{path
}, undef) = split(/\s*:\s*/, $fetch);
2442 $self->{path
} =~ s{/+}{/}g;
2443 $self->{path
} =~ s{\A/}{};
2444 $self->{path
} =~ s{/\z}{};
2445 $self->{url
} = command_oneline
('config', '--get',
2446 "svn-remote.$repo_id.url") or
2447 die "Failed to read \"svn-remote.$repo_id.url\" in config\n";
2448 $self->{pushurl
} = eval { command_oneline
('config', '--get',
2449 "svn-remote.$repo_id.pushurl") };
2455 my ($refname) = $_[0]->{ref_id
} ;
2457 # It cannot end with a slash /, we'll throw up on this because
2458 # SVN can't have directories with a slash in their name, either:
2459 if ($refname =~ m{/$}) {
2460 die "ref: '$refname' ends with a trailing slash, this is ",
2461 "not permitted by git nor Subversion\n";
2464 # It cannot have ASCII control character space, tilde ~, caret ^,
2465 # colon :, question-mark ?, asterisk *, space, or open bracket [
2468 # Additionally, % must be escaped because it is used for escaping
2469 # and we want our escaped refname to be reversible
2470 $refname =~ s{([ \%~\^:\?\*\[\t])}{uc sprintf('%%%02x',ord($1))}eg;
2472 # no slash-separated component can begin with a dot .
2474 $refname =~ s{/\.}{/%2E}g;
2476 # It cannot have two consecutive dots .. anywhere
2478 $refname =~ s{\.\.}{%2E%2E}g;
2480 # trailing dots and .lock are not allowed
2481 # .$ becomes %2E and .lock becomes %2Elock
2482 $refname =~ s{\.(?=$|lock$)}{%2E};
2484 # the sequence @{ is used to access the reflog
2486 $refname =~ s{\@\{}{%40\{}g;
2491 sub desanitize_refname
{
2493 $refname =~ s{%(?:([0-9A-F]{2}))}{chr hex($1)}eg;
2499 return $self->{svm
}->{uuid
} if $self->svm;
2501 unless ($self->{svm
}) {
2502 die "SVM UUID not cached, and reading remotely failed\n";
2504 $self->{svm
}->{uuid
};
2509 return $self->{svm
} if $self->{svm
};
2511 # see if we have it in our config, first:
2513 my $section = "svn-remote.$self->{repo_id}";
2515 source
=> tmp_config
('--get', "$section.svm-source"),
2516 uuid
=> tmp_config
('--get', "$section.svm-uuid"),
2517 replace
=> tmp_config
('--get', "$section.svm-replace"),
2520 if ($svm && $svm->{source
} && $svm->{uuid
} && $svm->{replace
}) {
2521 $self->{svm
} = $svm;
2527 my ($self, $ra) = @_;
2528 return $ra if $self->svm;
2530 my @err = ( "useSvmProps set, but failed to read SVM properties\n",
2531 "(svm:source, svm:uuid) ",
2532 "from the following URLs:\n" );
2533 sub read_svm_props
{
2534 my ($self, $ra, $path, $r) = @_;
2535 my $props = ($ra->get_dir($path, $r))[2];
2536 my $src = $props->{'svm:source'};
2537 my $uuid = $props->{'svm:uuid'};
2538 return undef if (!$src || !$uuid);
2542 $uuid =~ m{^[0-9a-f\-]{30,}$}i
2543 or die "doesn't look right - svm:uuid is '$uuid'\n";
2545 # the '!' is used to mark the repos_root!/relative/path
2546 $src =~ s{/?!/?}{/};
2547 $src =~ s{/+$}{}; # no trailing slashes please
2548 # username is of no interest
2549 $src =~ s{(^[a-z\+]*://)[^/@]*@}{$1};
2551 my $replace = $ra->{url
};
2552 $replace .= "/$path" if length $path;
2554 my $section = "svn-remote.$self->{repo_id}";
2555 tmp_config
("$section.svm-source", $src);
2556 tmp_config
("$section.svm-replace", $replace);
2557 tmp_config
("$section.svm-uuid", $uuid);
2565 my $r = $ra->get_latest_revnum;
2566 my $path = $self->{path
};
2568 while (length $path) {
2569 unless ($tried{"$self->{url}/$path"}) {
2570 return $ra if $self->read_svm_props($ra, $path, $r);
2571 $tried{"$self->{url}/$path"} = 1;
2573 $path =~ s
#/?[^/]+$##;
2575 die "Path: '$path' should be ''\n" if $path ne '';
2576 return $ra if $self->read_svm_props($ra, $path, $r);
2577 $tried{"$self->{url}/$path"} = 1;
2579 if ($ra->{repos_root
} eq $self->{url
}) {
2580 die @err, (map { " $_\n" } keys %tried), "\n";
2583 # nope, make sure we're connected to the repository root:
2586 $path = $ra->{svn_path
};
2587 $ra = Git
::SVN
::Ra
->new($ra->{repos_root
});
2588 while (length $path) {
2589 unless ($tried{"$ra->{url}/$path"}) {
2590 $ok = $self->read_svm_props($ra, $path, $r);
2592 $tried{"$ra->{url}/$path"} = 1;
2594 $path =~ s
#/?[^/]+$##;
2596 die "Path: '$path' should be ''\n" if $path ne '';
2597 $ok ||= $self->read_svm_props($ra, $path, $r);
2598 $tried{"$ra->{url}/$path"} = 1;
2600 die @err, (map { " $_\n" } keys %tried), "\n";
2602 Git
::SVN
::Ra
->new($self->{url
});
2607 return $self->{svnsync
} if $self->{svnsync
};
2609 if ($self->no_metadata) {
2610 die "Can't have both 'noMetadata' and ",
2611 "'useSvnsyncProps' options set!\n";
2613 if ($self->rewrite_root) {
2614 die "Can't have both 'useSvnsyncProps' and 'rewriteRoot' ",
2617 if ($self->rewrite_uuid) {
2618 die "Can't have both 'useSvnsyncProps' and 'rewriteUUID' ",
2623 # see if we have it in our config, first:
2625 my $section = "svn-remote.$self->{repo_id}";
2627 my $url = tmp_config
('--get', "$section.svnsync-url");
2628 ($url) = ($url =~ m{^([a-z\+]+://\S+)$}) or
2629 die "doesn't look right - svn:sync-from-url is '$url'\n";
2631 my $uuid = tmp_config
('--get', "$section.svnsync-uuid");
2632 ($uuid) = ($uuid =~ m{^([0-9a-f\-]{30,})$}i
) or
2633 die "doesn't look right - svn:sync-from-uuid is '$uuid'\n";
2635 $svnsync = { url
=> $url, uuid
=> $uuid }
2637 if ($svnsync && $svnsync->{url
} && $svnsync->{uuid
}) {
2638 return $self->{svnsync
} = $svnsync;
2641 my $err = "useSvnsyncProps set, but failed to read " .
2642 "svnsync property: svn:sync-from-";
2643 my $rp = $self->ra->rev_proplist(0);
2645 my $url = $rp->{'svn:sync-from-url'} or die $err . "url\n";
2646 ($url) = ($url =~ m{^([a-z\+]+://\S+)$}) or
2647 die "doesn't look right - svn:sync-from-url is '$url'\n";
2649 my $uuid = $rp->{'svn:sync-from-uuid'} or die $err . "uuid\n";
2650 ($uuid) = ($uuid =~ m{^([0-9a-f\-]{30,})$}i
) or
2651 die "doesn't look right - svn:sync-from-uuid is '$uuid'\n";
2653 my $section = "svn-remote.$self->{repo_id}";
2654 tmp_config
('--add', "$section.svnsync-uuid", $uuid);
2655 tmp_config
('--add', "$section.svnsync-url", $url);
2656 return $self->{svnsync
} = { url
=> $url, uuid
=> $uuid };
2659 # this allows us to memoize our SVN::Ra UUID locally and avoid a
2660 # remote lookup (useful for 'git svn log').
2663 unless ($self->{ra_uuid
}) {
2664 my $key = "svn-remote.$self->{repo_id}.uuid";
2665 my $uuid = eval { tmp_config
('--get', $key) };
2666 if (!$@
&& $uuid && $uuid =~ /^([a-f\d\-]{30,})$/i) {
2667 $self->{ra_uuid
} = $uuid;
2669 die "ra_uuid called without URL\n" unless $self->{url
};
2670 $self->{ra_uuid
} = $self->ra->get_uuid;
2671 tmp_config
('--add', $key, $self->{ra_uuid
});
2677 sub _set_repos_root
{
2678 my ($self, $repos_root) = @_;
2679 my $k = "svn-remote.$self->{repo_id}.reposRoot";
2680 $repos_root ||= $self->ra->{repos_root
};
2681 tmp_config
($k, $repos_root);
2687 my $k = "svn-remote.$self->{repo_id}.reposRoot";
2688 eval { tmp_config
('--get', $k) } || $self->_set_repos_root;
2693 my $ra = Git
::SVN
::Ra
->new($self->{url
});
2694 $self->_set_repos_root($ra->{repos_root
});
2695 if ($self->use_svm_props && !$self->{svm
}) {
2696 if ($self->no_metadata) {
2697 die "Can't have both 'noMetadata' and ",
2698 "'useSvmProps' options set!\n";
2699 } elsif ($self->use_svnsync_props) {
2700 die "Can't have both 'useSvnsyncProps' and ",
2701 "'useSvmProps' options set!\n";
2703 $ra = $self->_set_svm_vars($ra);
2704 $self->{-want_revprops
} = 1;
2709 # prop_walk(PATH, REV, SUB)
2710 # -------------------------
2711 # Recursively traverse PATH at revision REV and invoke SUB for each
2712 # directory that contains a SVN property. SUB will be invoked as
2713 # follows: &SUB(gs, path, props); where `gs' is this instance of
2714 # Git::SVN, `path' the path to the directory where the properties
2715 # `props' were found. The `path' will be relative to point of checkout,
2716 # that is, if url://repo/trunk is the current Git branch, and that
2717 # directory contains a sub-directory `d', SUB will be invoked with `/d/'
2718 # as `path' (note the trailing `/').
2720 my ($self, $path, $rev, $sub) = @_;
2723 my ($dirent, undef, $props) = $self->ra->get_dir($path, $rev);
2726 # Strip the irrelevant part of the path.
2727 $p =~ s
#^/+\Q$self->{path}\E(/|$)#/#;
2728 # Ensure the path is terminated by a `/'.
2731 # The properties contain all the internal SVN stuff nobody
2732 # (usually) cares about.
2733 my $interesting_props = 0;
2734 foreach (keys %{$props}) {
2735 # If it doesn't start with `svn:', it must be a
2736 # user-defined property.
2737 ++$interesting_props and next if $_ !~ /^svn:/;
2738 # FIXME: Fragile, if SVN adds new public properties,
2739 # this needs to be updated.
2740 ++$interesting_props if /^svn
:(?
:ignore
|keywords
|executable
2741 |eol
-style
|mime
-type
2742 |externals
|needs
-lock)$/x
;
2744 &$sub($self, $p, $props) if $interesting_props;
2746 foreach (sort keys %$dirent) {
2747 next if $dirent->{$_}->{kind
} != $SVN::Node
::dir
;
2748 $self->prop_walk($self->{path
} . $p . $_, $rev, $sub);
2752 sub last_rev
{ ($_[0]->last_rev_commit)[0] }
2753 sub last_commit
{ ($_[0]->last_rev_commit)[1] }
2755 # returns the newest SVN revision number and newest commit SHA1
2756 sub last_rev_commit
{
2758 if (defined $self->{last_rev
} && defined $self->{last_commit
}) {
2759 return ($self->{last_rev
}, $self->{last_commit
});
2761 my $c = ::verify_ref
($self->refname.'^0');
2762 if ($c && !$self->use_svm_props && !$self->no_metadata) {
2763 my $rev = (::cmt_metadata
($c))[1];
2765 ($self->{last_rev
}, $self->{last_commit
}) = ($rev, $c);
2769 my $map_path = $self->map_path;
2770 unless (-e
$map_path) {
2771 ($self->{last_rev
}, $self->{last_commit
}) = (undef, undef);
2772 return (undef, undef);
2774 my ($rev, $commit) = $self->rev_map_max(1);
2775 ($self->{last_rev
}, $self->{last_commit
}) = ($rev, $commit);
2776 return ($rev, $commit);
2779 sub get_fetch_range
{
2780 my ($self, $min, $max) = @_;
2781 $max ||= $self->ra->get_latest_revnum;
2782 $min ||= $self->rev_map_max;
2788 my $old_def_config = "$ENV{GIT_DIR}/svn/config";
2789 my $config = "$ENV{GIT_DIR}/svn/.metadata";
2790 if (! -f
$config && -f
$old_def_config) {
2791 rename $old_def_config, $config or
2792 die "Failed rename $old_def_config => $config: $!\n";
2794 my $old_config = $ENV{GIT_CONFIG
};
2795 $ENV{GIT_CONFIG
} = $config;
2798 unless (-f
$config) {
2800 open my $fh, '>', $config or
2801 die "Can't open $config: $!\n";
2802 print $fh "; This file is used internally by ",
2804 "Couldn't write to $config: $!\n";
2805 print $fh "; You should not have to edit it\n" or
2806 die "Couldn't write to $config: $!\n";
2807 close $fh or die "Couldn't close $config: $!\n";
2809 command
('config', @args);
2812 if (defined $old_config) {
2813 $ENV{GIT_CONFIG
} = $old_config;
2815 delete $ENV{GIT_CONFIG
};
2818 wantarray ?
@ret : $ret[0];
2822 my ($self, $sub) = @_;
2823 my $old_index = $ENV{GIT_INDEX_FILE
};
2824 $ENV{GIT_INDEX_FILE
} = $self->{index};
2827 my ($dir, $base) = ($self->{index} =~ m
#^(.*?)/?([^/]+)$#);
2828 mkpath
([$dir]) unless -d
$dir;
2832 if (defined $old_index) {
2833 $ENV{GIT_INDEX_FILE
} = $old_index;
2835 delete $ENV{GIT_INDEX_FILE
};
2838 wantarray ?
@ret : $ret[0];
2841 sub assert_index_clean
{
2842 my ($self, $treeish) = @_;
2844 $self->tmp_index_do(sub {
2845 command_noisy
('read-tree', $treeish) unless -e
$self->{index};
2846 my $x = command_oneline
('write-tree');
2847 my ($y) = (command
(qw
/cat-file commit/, $treeish) =~
2848 /^tree ($::sha1)/mo);
2851 warn "Index mismatch: $y != $x\nrereading $treeish\n";
2852 unlink $self->{index} or die "unlink $self->{index}: $!\n";
2853 command_noisy
('read-tree', $treeish);
2854 $x = command_oneline
('write-tree');
2856 ::fatal
"trees ($treeish) $y != $x\n",
2857 "Something is seriously wrong...";
2862 sub get_commit_parents
{
2863 my ($self, $log_entry) = @_;
2864 my (%seen, @ret, @tmp);
2865 # legacy support for 'set-tree'; this is only used by set_tree_cb:
2866 if (my $ip = $self->{inject_parents
}) {
2867 if (my $commit = delete $ip->{$log_entry->{revision
}}) {
2871 if (my $cur = ::verify_ref
($self->refname.'^0')) {
2874 if (my $ipd = $self->{inject_parents_dcommit
}) {
2875 if (my $commit = delete $ipd->{$log_entry->{revision
}}) {
2876 push @tmp, @
$commit;
2879 push @tmp, $_ foreach (@
{$log_entry->{parents
}}, @tmp);
2880 while (my $p = shift @tmp) {
2890 return $self->{-rewrite_root
} if exists $self->{-rewrite_root
};
2891 my $k = "svn-remote.$self->{repo_id}.rewriteRoot";
2892 my $rwr = eval { command_oneline
(qw
/config --get/, $k) };
2895 if ($rwr !~ m
#^[a-z\+]+://#) {
2896 die "$rwr is not a valid URL (key: $k)\n";
2899 $self->{-rewrite_root
} = $rwr;
2904 return $self->{-rewrite_uuid
} if exists $self->{-rewrite_uuid
};
2905 my $k = "svn-remote.$self->{repo_id}.rewriteUUID";
2906 my $rwid = eval { command_oneline
(qw
/config --get/, $k) };
2909 if ($rwid !~ m
#^[a-f0-9]{8}-(?:[a-f0-9]{4}-){3}[a-f0-9]{12}$#) {
2910 die "$rwid is not a valid UUID (key: $k)\n";
2913 $self->{-rewrite_uuid
} = $rwid;
2918 ($self->rewrite_root || $self->{url
}) .
2919 (length $self->{path
} ?
'/' . $self->{path
} : '');
2924 $self->{url
} . (length $self->{path
} ?
'/' . $self->{path
} : '');
2929 if ($self->{pushurl
}) {
2930 return $self->{pushurl
} . (length $self->{path
} ?
'/' .
2931 $self->{path
} : '');
2933 return $self->full_url;
2937 sub set_commit_header_env
{
2938 my ($log_entry) = @_;
2940 foreach my $ned (qw
/NAME EMAIL DATE/) {
2941 foreach my $ac (qw
/AUTHOR COMMITTER/) {
2942 $env{"GIT_${ac}_${ned}"} = $ENV{"GIT_${ac}_${ned}"};
2946 $ENV{GIT_AUTHOR_NAME
} = $log_entry->{name
};
2947 $ENV{GIT_AUTHOR_EMAIL
} = $log_entry->{email
};
2948 $ENV{GIT_AUTHOR_DATE
} = $ENV{GIT_COMMITTER_DATE
} = $log_entry->{date
};
2950 $ENV{GIT_COMMITTER_NAME
} = (defined $log_entry->{commit_name
})
2951 ?
$log_entry->{commit_name
}
2952 : $log_entry->{name
};
2953 $ENV{GIT_COMMITTER_EMAIL
} = (defined $log_entry->{commit_email
})
2954 ?
$log_entry->{commit_email
}
2955 : $log_entry->{email
};
2959 sub restore_commit_header_env
{
2961 foreach my $ned (qw
/NAME EMAIL DATE/) {
2962 foreach my $ac (qw
/AUTHOR COMMITTER/) {
2963 my $k = "GIT_${ac}_${ned}";
2964 if (defined $env->{$k}) {
2965 $ENV{$k} = $env->{$k};
2974 command_noisy
('gc', '--auto');
2978 my ($self, $log_entry) = @_;
2979 my $lr = $self->last_rev;
2980 if (defined $lr && $lr >= $log_entry->{revision
}) {
2981 die "Last fetched revision of ", $self->refname,
2982 " was r$lr, but we are about to fetch: ",
2983 "r$log_entry->{revision}!\n";
2985 if (my $c = $self->rev_map_get($log_entry->{revision
})) {
2986 croak
"$log_entry->{revision} = $c already exists! ",
2987 "Why are we refetching it?\n";
2989 my $old_env = set_commit_header_env
($log_entry);
2990 my $tree = $log_entry->{tree
};
2991 if (!defined $tree) {
2992 $tree = $self->tmp_index_do(sub {
2993 command_oneline
('write-tree') });
2995 die "Tree is not a valid sha1: $tree\n" if $tree !~ /^$::sha1$/o;
2997 my @exec = ('git', 'commit-tree', $tree);
2998 foreach ($self->get_commit_parents($log_entry)) {
2999 push @exec, '-p', $_;
3001 defined(my $pid = open3
(my $msg_fh, my $out_fh, '>&STDERR', @exec))
3005 # we always get UTF-8 from SVN, but we may want our commits in
3006 # a different encoding.
3007 if (my $enc = Git
::config
('i18n.commitencoding')) {
3009 Encode
::from_to
($log_entry->{log}, 'UTF-8', $enc);
3011 print $msg_fh $log_entry->{log} or croak
$!;
3012 restore_commit_header_env
($old_env);
3013 unless ($self->no_metadata) {
3014 print $msg_fh "\ngit-svn-id: $log_entry->{metadata}\n"
3017 $msg_fh->flush == 0 or croak
$!;
3018 close $msg_fh or croak
$!;
3019 chomp(my $commit = do { local $/; <$out_fh> });
3020 close $out_fh or croak
$!;
3023 if ($commit !~ /^$::sha1$/o) {
3024 die "Failed to commit, invalid sha1: $commit\n";
3027 $self->rev_map_set($log_entry->{revision
}, $commit, 1);
3029 $self->{last_rev
} = $log_entry->{revision
};
3030 $self->{last_commit
} = $commit;
3031 print "r$log_entry->{revision}" unless $::_q
> 1;
3032 if (defined $log_entry->{svm_revision
}) {
3033 print " (\@$log_entry->{svm_revision})" unless $::_q
> 1;
3034 $self->rev_map_set($log_entry->{svm_revision
}, $commit,
3035 0, $self->svm_uuid);
3037 print " = $commit ($self->{ref_id})\n" unless $::_q
> 1;
3038 if (--$_gc_nr == 0) {
3039 $_gc_nr = $_gc_period;
3046 my ($self, $paths, $r) = @_;
3047 return 1 if $self->{path
} eq '';
3048 if (my $path = $paths->{"/$self->{path}"}) {
3049 return ($path->{action
} eq 'D') ?
0 : 1;
3051 $self->{path_regex
} ||= qr/^\/\Q
$self->{path
}\E\
//;
3052 if (grep /$self->{path_regex}/, keys %$paths) {
3056 foreach (split m
#/#, $self->{path}) {
3058 next unless ($paths->{$c} &&
3059 ($paths->{$c}->{action
} =~ /^[AR]$/));
3060 if ($self->ra->check_path($self->{path
}, $r) ==
3068 sub find_parent_branch
{
3069 my ($self, $paths, $rev) = @_;
3070 return undef unless $self->follow_parent;
3071 unless (defined $paths) {
3072 my $err_handler = $SVN::Error
::handler
;
3073 $SVN::Error
::handler
= \
&Git
::SVN
::Ra
::skip_unknown_revs
;
3074 $self->ra->get_log([$self->{path
}], $rev, $rev, 0, 1, 1,
3075 sub { $paths = $_[0] });
3076 $SVN::Error
::handler
= $err_handler;
3078 return undef unless defined $paths;
3080 # look for a parent from another branch:
3081 my @b_path_components = split m
#/#, $self->{path};
3082 my @a_path_components;
3084 while (@b_path_components) {
3085 $i = $paths->{'/'.join('/', @b_path_components)};
3086 last if $i && defined $i->{copyfrom_path
};
3087 unshift(@a_path_components, pop(@b_path_components));
3089 return undef unless defined $i && defined $i->{copyfrom_path
};
3090 my $branch_from = $i->{copyfrom_path
};
3091 if (@a_path_components) {
3092 print STDERR
"branch_from: $branch_from => ";
3093 $branch_from .= '/'.join('/', @a_path_components);
3094 print STDERR
$branch_from, "\n";
3096 my $r = $i->{copyfrom_rev
};
3097 my $repos_root = $self->ra->{repos_root
};
3098 my $url = $self->ra->{url
};
3099 my $new_url = $url . $branch_from;
3100 print STDERR
"Found possible branch point: ",
3101 "$new_url => ", $self->full_url, ", $r\n"
3103 $branch_from =~ s
#^/##;
3104 my $gs = $self->other_gs($new_url, $url,
3105 $branch_from, $r, $self->{ref_id
});
3106 my ($r0, $parent) = $gs->find_rev_before($r, 1);
3109 if (!defined $r0 || !defined $parent) {
3110 ($base, $head) = parse_revision_argument
(0, $r);
3113 $gs->ra->get_log([$gs->{path
}], $r0 + 1, $r, 1,
3114 0, 1, sub { $base = $_[1] - 1 });
3117 if (defined $base && $base <= $r) {
3118 $gs->fetch($base, $r);
3120 ($r0, $parent) = $gs->find_rev_before($r, 1);
3122 if (defined $r0 && defined $parent) {
3123 print STDERR
"Found branch parent: ($self->{ref_id}) $parent\n"
3126 if ($self->ra->can_do_switch) {
3127 $self->assert_index_clean($parent);
3128 print STDERR
"Following parent with do_switch\n"
3130 # do_switch works with svn/trunk >= r22312, but that
3131 # is not included with SVN 1.4.3 (the latest version
3132 # at the moment), so we can't rely on it
3133 $self->{last_rev
} = $r0;
3134 $self->{last_commit
} = $parent;
3135 $ed = SVN
::Git
::Fetcher
->new($self, $gs->{path
});
3136 $gs->ra->gs_do_switch($r0, $rev, $gs,
3137 $self->full_url, $ed)
3138 or die "SVN connection failed somewhere...\n";
3139 } elsif ($self->ra->trees_match($new_url, $r0,
3140 $self->full_url, $rev)) {
3141 print STDERR
"Trees match:\n",
3143 " ${\$self->full_url}\@$rev\n",
3144 "Following parent with no changes\n"
3146 $self->tmp_index_do(sub {
3147 command_noisy
('read-tree', $parent);
3149 $self->{last_commit
} = $parent;
3151 print STDERR
"Following parent with do_update\n"
3153 $ed = SVN
::Git
::Fetcher
->new($self);
3154 $self->ra->gs_do_update($rev, $rev, $self, $ed)
3155 or die "SVN connection failed somewhere...\n";
3157 print STDERR
"Successfully followed parent\n" unless $::_q
> 1;
3158 return $self->make_log_entry($rev, [$parent], $ed);
3164 my ($self, $paths, $rev) = @_;
3166 my ($last_rev, @parents);
3167 if (my $lc = $self->last_commit) {
3168 # we can have a branch that was deleted, then re-added
3169 # under the same name but copied from another path, in
3170 # which case we'll have multiple parents (we don't
3171 # want to break the original ref, nor lose copypath info):
3172 if (my $log_entry = $self->find_parent_branch($paths, $rev)) {
3173 push @
{$log_entry->{parents
}}, $lc;
3176 $ed = SVN
::Git
::Fetcher
->new($self);
3177 $last_rev = $self->{last_rev
};
3182 if (my $log_entry = $self->find_parent_branch($paths, $rev)) {
3185 $ed = SVN
::Git
::Fetcher
->new($self);
3187 unless ($self->ra->gs_do_update($last_rev, $rev, $self, $ed)) {
3188 die "SVN connection failed somewhere...\n";
3190 $self->make_log_entry($rev, \
@parents, $ed);
3194 my ($self, $r) = @_;
3197 my ($r, $empty_dirs, $line) = @_;
3198 if (defined $r && $line =~ /^r(\d+)$/) {
3199 return 0 if $1 > $r;
3200 } elsif ($line =~ /^ \+empty_dir: (.+)$/) {
3201 $empty_dirs->{$1} = 1;
3202 } elsif ($line =~ /^ \-empty_dir: (.+)$/) {
3203 my @d = grep {m
[^\Q
$1\E
(/|$)]} (keys %$empty_dirs);
3204 delete @
$empty_dirs{@d};
3209 my %empty_dirs = ();
3210 my $gz_file = "$self->{dir}/unhandled.log.gz";
3212 if (!$can_compress) {
3213 warn "Compress::Zlib could not be found; ",
3214 "empty directories in $gz_file will not be read\n";
3216 my $gz = Compress
::Zlib
::gzopen
($gz_file, "rb") or
3217 die "Unable to open $gz_file: $!\n";
3219 while ($gz->gzreadline($line) > 0) {
3220 scan
($r, \
%empty_dirs, $line) or last;
3226 if (open my $fh, '<', "$self->{dir}/unhandled.log") {
3227 binmode $fh or croak
"binmode: $!";
3229 scan
($r, \
%empty_dirs, $_) or last;
3234 my $strip = qr/\A\Q$self->{path}\E(?:\/|$)/;
3235 foreach my $d (sort keys %empty_dirs) {
3236 $d = uri_decode
($d);
3238 next unless length($d);
3241 warn "$d exists but is not a directory\n";
3243 print "creating empty directory: $d\n";
3250 my ($self, $ed) = @_;
3252 my $h = $ed->{empty
};
3253 foreach (sort keys %$h) {
3254 my $act = $h->{$_} ?
'+empty_dir' : '-empty_dir';
3255 push @out, " $act: " . uri_encode
($_);
3256 warn "W: $act: $_\n";
3258 foreach my $t (qw
/dir_prop file_prop/) {
3259 $h = $ed->{$t} or next;
3260 foreach my $path (sort keys %$h) {
3261 my $ppath = $path eq '' ?
'.' : $path;
3262 foreach my $prop (sort keys %{$h->{$path}}) {
3263 next if $SKIP_PROP{$prop};
3264 my $v = $h->{$path}->{$prop};
3265 my $t_ppath_prop = "$t: " .
3266 uri_encode
($ppath) . ' ' .
3269 push @out, " +$t_ppath_prop " .
3272 push @out, " -$t_ppath_prop";
3277 foreach my $t (qw
/absent_file absent_directory/) {
3278 $h = $ed->{$t} or next;
3279 foreach my $parent (sort keys %$h) {
3280 foreach my $path (sort @
{$h->{$parent}}) {
3281 push @out, " $t: " .
3282 uri_encode
("$parent/$path");
3283 warn "W: $t: $parent/$path ",
3284 "Insufficient permissions?\n";
3292 # some systmes don't handle or mishandle %z, so be creative.
3293 my $t = shift || time;
3294 my $gm = timelocal
(gmtime($t));
3295 my $sign = qw( + + - )[ $t <=> $gm ];
3296 return sprintf("%s%02d%02d", $sign, (gmtime(abs($t - $gm)))[2,1]);
3299 # parse_svn_date(DATE)
3300 # --------------------
3301 # Given a date (in UTC) from Subversion, return a string in the format
3302 # "<TZ Offset> <local date/time>" that Git will use.
3304 # By default the parsed date will be in UTC; if $Git::SVN::_localtime
3305 # is true we'll convert it to the local timezone instead.
3306 sub parse_svn_date
{
3307 my $date = shift || return '+0000 1970-01-01 00:00:00';
3308 my ($Y,$m,$d,$H,$M,$S) = ($date =~ /^(\d
{4})\
-(\d\d
)\
-(\d\d
)T
3309 (\d\d
)\
:(\d\d
)\
:(\d\d
)\
.\d
*Z
$/x
) or
3310 croak
"Unable to parse date: $date\n";
3311 my $parsed_date; # Set next.
3313 if ($Git::SVN
::_localtime
) {
3314 # Translate the Subversion datetime to an epoch time.
3315 # Begin by switching ourselves to $date's timezone, UTC.
3316 my $old_env_TZ = $ENV{TZ
};
3320 POSIX
::strftime
('%s', $S, $M, $H, $d, $m - 1, $Y - 1900);
3322 # Determine our local timezone (including DST) at the
3323 # time of $epoch_in_UTC. $Git::SVN::Log::TZ stored the
3324 # value of TZ, if any, at the time we were run.
3325 if (defined $Git::SVN
::Log
::TZ
) {
3326 $ENV{TZ
} = $Git::SVN
::Log
::TZ
;
3331 my $our_TZ = get_tz
();
3333 # This converts $epoch_in_UTC into our local timezone.
3334 my ($sec, $min, $hour, $mday, $mon, $year,
3335 $wday, $yday, $isdst) = localtime($epoch_in_UTC);
3337 $parsed_date = sprintf('%s %04d-%02d-%02d %02d:%02d:%02d',
3338 $our_TZ, $year + 1900, $mon + 1,
3339 $mday, $hour, $min, $sec);
3341 # Reset us to the timezone in effect when we entered
3343 if (defined $old_env_TZ) {
3344 $ENV{TZ
} = $old_env_TZ;
3349 $parsed_date = "+0000 $Y-$m-$d $H:$M:$S";
3352 return $parsed_date;
3356 my ($self, $new_url, $url,
3357 $branch_from, $r, $old_ref_id) = @_;
3358 my $gs = Git
::SVN
->find_by_url($new_url, $url, $branch_from);
3360 my $ref_id = $old_ref_id;
3361 $ref_id =~ s/\@\d+-*$//;
3363 # just grow a tail if we're not unique enough :x
3364 $ref_id .= '-' while find_ref
($ref_id);
3365 my ($u, $p, $repo_id) = ($new_url, '', $ref_id);
3366 if ($u =~ s
#^\Q$url\E(/|$)##) {
3369 $repo_id = $self->{repo_id
};
3372 # It is possible to tag two different subdirectories at
3373 # the same revision. If the url for an existing ref
3374 # does not match, we must either find a ref with a
3375 # matching url or create a new ref by growing a tail.
3376 $gs = Git
::SVN
->init($u, $p, $repo_id, $ref_id, 1);
3377 my (undef, $max_commit) = $gs->rev_map_max(1);
3378 last if (!$max_commit);
3379 my ($url) = ::cmt_metadata
($max_commit);
3380 last if ($url eq $gs->metadata_url);
3383 print STDERR
"Initializing parent: $ref_id\n" unless $::_q
> 1;
3388 sub call_authors_prog
{
3389 my ($orig_author) = @_;
3390 $orig_author = command_oneline
('rev-parse', '--sq-quote', $orig_author);
3391 my $author = `$::_authors_prog $orig_author`;
3393 die "$::_authors_prog failed with exit code $?\n"
3395 if ($author =~ /^\s*(.+?)\s*<(.*)>\s*$/) {
3396 my ($name, $email) = ($1, $2);
3397 $email = undef if length $2 == 0;
3398 return [$name, $email];
3400 die "Author: $orig_author: $::_authors_prog returned "
3401 . "invalid author format: $author\n";
3407 if (!defined $author || length $author == 0) {
3408 $author = '(no author)';
3410 if (!defined $::users
{$author}) {
3411 if (defined $::_authors_prog
) {
3412 $::users
{$author} = call_authors_prog
($author);
3413 } elsif (defined $::_authors
) {
3414 die "Author: $author not defined in $::_authors file\n";
3420 sub find_extra_svk_parents
{
3421 my ($self, $ed, $tickets, $parents) = @_;
3422 # aha! svk:merge property changed...
3423 my @tickets = split "\n", $tickets;
3425 for my $ticket ( @tickets ) {
3426 my ($uuid, $path, $rev) = split /:/, $ticket;
3427 if ( $uuid eq $self->ra_uuid ) {
3428 my $url = $self->{url
};
3429 my $repos_root = $url;
3430 my $branch_from = $path;
3431 $branch_from =~ s{^/}{};
3432 my $gs = $self->other_gs($repos_root."/".$branch_from,
3437 if ( my $commit = $gs->rev_map_get($rev, $uuid) ) {
3438 # wahey! we found it, but it might be
3440 push @known_parents, [ $rev, $commit ];
3444 # Ordering matters; highest-numbered commit merge tickets
3445 # first, as they may account for later merge ticket additions
3447 @known_parents = map {$_->[1]} sort {$b->[0] <=> $a->[0]} @known_parents;
3448 for my $parent ( @known_parents ) {
3449 my @cmd = ('rev-list', $parent, map { "^$_" } @
$parents );
3450 my ($msg_fh, $ctx) = command_output_pipe
(@cmd);
3452 while ( <$msg_fh> ) {
3455 command_close_pipe
($msg_fh, $ctx);
3458 "Found merge parent (svk:merge ticket): $parent\n";
3459 push @
$parents, $parent;
3464 sub lookup_svn_merge
{
3469 my ($source, $revs) = split ":", $merge;
3472 my $gs = Git
::SVN
->find_by_url($url.$source, $url, $path);
3474 warn "Couldn't find revmap for $url$source\n";
3477 my @ranges = split ",", $revs;
3478 my ($tip, $tip_commit);
3479 my @merged_commit_ranges;
3481 for my $range ( @ranges ) {
3482 my ($bottom, $top) = split "-", $range;
3484 my $bottom_commit = $gs->find_rev_after( $bottom, 1, $top );
3485 my $top_commit = $gs->find_rev_before( $top, 1, $bottom );
3487 unless ($top_commit and $bottom_commit) {
3488 warn "W:unknown path/rev in svn:mergeinfo "
3489 ."dirprop: $source:$range\n";
3493 if (scalar(command
('rev-parse', "$bottom_commit^@"))) {
3494 push @merged_commit_ranges,
3495 "$bottom_commit^..$top_commit";
3497 push @merged_commit_ranges, "$top_commit";
3500 if ( !defined $tip or $top > $tip ) {
3502 $tip_commit = $top_commit;
3505 return ($tip_commit, @merged_commit_ranges);
3509 my ($msg_fh, $ctx) = command_output_pipe
(
3513 while ( <$msg_fh> ) {
3517 command_close_pipe
($msg_fh, $ctx);
3521 sub check_cherry_pick
{
3524 my $parents = shift;
3526 my %commits = map { $_ => 1 }
3527 _rev_list
("--no-merges", $tip, "--not", $base, @
$parents, "--");
3528 for my $range ( @ranges ) {
3529 delete @commits{_rev_list
($range, "--")};
3531 for my $commit (keys %commits) {
3532 if (has_no_changes
($commit)) {
3533 delete $commits{$commit};
3536 return (keys %commits);
3539 sub has_no_changes
{
3542 my @revs = split / /, command_oneline
(
3543 qw(rev-list --parents -1 -m), $commit);
3545 # Commits with no parents, e.g. the start of a partial branch,
3546 # have changes by definition.
3547 return 1 if (@revs < 2);
3549 # Commits with multiple parents, e.g a merge, have no changes
3551 return 0 if (@revs > 2);
3553 return (command_oneline
("rev-parse", "$commit^{tree}") eq
3554 command_oneline
("rev-parse", "$commit~1^{tree}"));
3557 # The GIT_DIR environment variable is not always set until after the command
3558 # line arguments are processed, so we can't memoize in a BEGIN block.
3562 sub memoize_svn_mergeinfo_functions
{
3563 return if $memoized;
3566 my $cache_path = "$ENV{GIT_DIR}/svn/.caches/";
3567 mkpath
([$cache_path]) unless -d
$cache_path;
3569 tie
my %lookup_svn_merge_cache => 'Memoize::Storable',
3570 "$cache_path/lookup_svn_merge.db", 'nstore';
3571 memoize
'lookup_svn_merge',
3572 SCALAR_CACHE
=> 'FAULT',
3573 LIST_CACHE
=> ['HASH' => \
%lookup_svn_merge_cache],
3576 tie
my %check_cherry_pick_cache => 'Memoize::Storable',
3577 "$cache_path/check_cherry_pick.db", 'nstore';
3578 memoize
'check_cherry_pick',
3579 SCALAR_CACHE
=> 'FAULT',
3580 LIST_CACHE
=> ['HASH' => \
%check_cherry_pick_cache],
3583 tie
my %has_no_changes_cache => 'Memoize::Storable',
3584 "$cache_path/has_no_changes.db", 'nstore';
3585 memoize
'has_no_changes',
3586 SCALAR_CACHE
=> ['HASH' => \
%has_no_changes_cache],
3587 LIST_CACHE
=> 'FAULT',
3591 sub unmemoize_svn_mergeinfo_functions
{
3592 return if not $memoized;
3595 Memoize
::unmemoize
'lookup_svn_merge';
3596 Memoize
::unmemoize
'check_cherry_pick';
3597 Memoize
::unmemoize
'has_no_changes';
3600 Memoize
::memoize
'Git::SVN::repos_root';
3604 # Force cache writeout explicitly instead of waiting for
3605 # global destruction to avoid segfault in Storable:
3606 # http://rt.cpan.org/Public/Bug/Display.html?id=36087
3607 unmemoize_svn_mergeinfo_functions
();
3610 sub parents_exclude
{
3611 my $parents = shift;
3613 return unless @commits;
3618 my @cmd = ('rev-list', "-1", @commits, "--not", @
$parents );
3619 $excluded = command_oneline
(@cmd);
3623 for my $commit ( @commits ) {
3624 if ( $commit eq $excluded ) {
3625 push @excluded, $commit;
3633 die "saw commit '$excluded' in rev-list output, "
3634 ."but we didn't ask for that commit (wanted: @commits --not @$parents)"
3639 while ($excluded and @commits);
3645 # note: this function should only be called if the various dirprops
3646 # have actually changed
3647 sub find_extra_svn_parents
{
3648 my ($self, $ed, $mergeinfo, $parents) = @_;
3649 # aha! svk:merge property changed...
3651 memoize_svn_mergeinfo_functions
();
3653 # We first search for merged tips which are not in our
3654 # history. Then, we figure out which git revisions are in
3655 # that tip, but not this revision. If all of those revisions
3656 # are now marked as merge, we can add the tip as a parent.
3657 my @merges = split "\n", $mergeinfo;
3659 my $url = $self->{url
};
3660 my $uuid = $self->ra_uuid;
3662 for my $merge ( @merges ) {
3663 my ($tip_commit, @ranges) =
3664 lookup_svn_merge
( $uuid, $url, $merge );
3665 unless (!$tip_commit or
3666 grep { $_ eq $tip_commit } @
$parents ) {
3667 push @merge_tips, $tip_commit;
3668 $ranges{$tip_commit} = \
@ranges;
3670 push @merge_tips, undef;
3674 my %excluded = map { $_ => 1 }
3675 parents_exclude
($parents, grep { defined } @merge_tips);
3677 # check merge tips for new parents
3679 for my $merge_tip ( @merge_tips ) {
3680 my $spec = shift @merges;
3681 next unless $merge_tip and $excluded{$merge_tip};
3683 my $ranges = $ranges{$merge_tip};
3685 # check out 'new' tips
3688 $merge_base = command_oneline
(
3690 @
$parents, $merge_tip,
3694 die "An error occurred during merge-base"
3695 unless $@
->isa("Git::Error::Command");
3697 warn "W: Cannot find common ancestor between ".
3698 "@$parents and $merge_tip. Ignoring merge info.\n";
3702 # double check that there are no missing non-merge commits
3703 my (@incomplete) = check_cherry_pick
(
3704 $merge_base, $merge_tip,
3709 if ( @incomplete ) {
3710 warn "W:svn cherry-pick ignored ($spec) - missing "
3711 .@incomplete." commit(s) (eg $incomplete[0])\n";
3714 "Found merge parent (svn:mergeinfo prop): ",
3716 push @new_parents, $merge_tip;
3720 # cater for merges which merge commits from multiple branches
3721 if ( @new_parents > 1 ) {
3722 for ( my $i = 0; $i <= $#new_parents; $i++ ) {
3723 for ( my $j = 0; $j <= $#new_parents; $j++ ) {
3725 next unless $new_parents[$i];
3726 next unless $new_parents[$j];
3727 my $revs = command_oneline
(
3729 "$new_parents[$i]..$new_parents[$j]",
3732 undef($new_parents[$j]);
3737 push @
$parents, grep { defined } @new_parents;
3740 sub make_log_entry
{
3741 my ($self, $rev, $parents, $ed) = @_;
3742 my $untracked = $self->get_untracked($ed);
3744 my @parents = @
$parents;
3745 my $ps = $ed->{path_strip
} || "";
3746 for my $path ( grep { m/$ps/ } %{$ed->{dir_prop
}} ) {
3747 my $props = $ed->{dir_prop
}{$path};
3748 if ( $props->{"svk:merge"} ) {
3749 $self->find_extra_svk_parents
3750 ($ed, $props->{"svk:merge"}, \
@parents);
3752 if ( $props->{"svn:mergeinfo"} ) {
3753 $self->find_extra_svn_parents
3755 $props->{"svn:mergeinfo"},
3760 open my $un, '>>', "$self->{dir}/unhandled.log" or croak
$!;
3761 print $un "r$rev\n" or croak
$!;
3762 print $un $_, "\n" foreach @
$untracked;
3763 my %log_entry = ( parents
=> \
@parents, revision
=> $rev,
3767 my $logged = delete $self->{logged_rev_props
};
3768 if (!$logged || $self->{-want_revprops
}) {
3769 my $rp = $self->ra->rev_proplist($rev);
3770 foreach (sort keys %$rp) {
3772 if (/^svn:(author|date|log)$/) {
3773 $log_entry{$1} = $v;
3774 } elsif ($_ eq 'svm:headrev') {
3777 print $un " rev_prop: ", uri_encode
($_), ' ',
3778 uri_encode
($v), "\n";
3782 map { $log_entry{$_} = $logged->{$_} } keys %$logged;
3784 close $un or croak
$!;
3786 $log_entry{date
} = parse_svn_date
($log_entry{date
});
3787 $log_entry{log} .= "\n";
3788 my $author = $log_entry{author
} = check_author
($log_entry{author
});
3789 my ($name, $email) = defined $::users
{$author} ? @
{$::users
{$author}}
3792 my ($commit_name, $commit_email) = ($name, $email);
3793 if ($_use_log_author) {
3795 if ($log_entry{log} =~ /From:\s+(.*\S)\s*\n/i) {
3797 } elsif ($log_entry{log} =~ /Signed-off-by:\s+(.*\S)\s*\n/i) {
3800 if (!defined $name_field) {
3801 if (!defined $email) {
3804 } elsif ($name_field =~ /(.*?)\s+<(.*)>/) {
3805 ($name, $email) = ($1, $2);
3806 } elsif ($name_field =~ /(.*)@/) {
3807 ($name, $email) = ($1, $name_field);
3809 ($name, $email) = ($name_field, $name_field);
3812 if (defined $headrev && $self->use_svm_props) {
3813 if ($self->rewrite_root) {
3814 die "Can't have both 'useSvmProps' and 'rewriteRoot' ",
3817 if ($self->rewrite_uuid) {
3818 die "Can't have both 'useSvmProps' and 'rewriteUUID' ",
3821 my ($uuid, $r) = $headrev =~ m{^([a-f\d\-]{30,}):(\d
+)$}i
;
3822 # we don't want "SVM: initializing mirror for junk" ...
3823 return undef if $r == 0;
3824 my $svm = $self->svm;
3825 if ($uuid ne $svm->{uuid
}) {
3826 die "UUID mismatch on SVM path:\n",
3827 "expected: $svm->{uuid}\n",
3830 my $full_url = $self->full_url;
3831 $full_url =~ s
#^\Q$svm->{replace}\E(/|$)#$svm->{source}$1# or
3832 die "Failed to replace '$svm->{replace}' with ",
3833 "'$svm->{source}' in $full_url\n";
3834 # throw away username for storing in records
3835 remove_username
($full_url);
3836 $log_entry{metadata
} = "$full_url\@$r $uuid";
3837 $log_entry{svm_revision
} = $r;
3838 $email ||= "$author\@$uuid";
3839 $commit_email ||= "$author\@$uuid";
3840 } elsif ($self->use_svnsync_props) {
3841 my $full_url = $self->svnsync->{url
};
3842 $full_url .= "/$self->{path}" if length $self->{path
};
3843 remove_username
($full_url);
3844 my $uuid = $self->svnsync->{uuid
};
3845 $log_entry{metadata
} = "$full_url\@$rev $uuid";
3846 $email ||= "$author\@$uuid";
3847 $commit_email ||= "$author\@$uuid";
3849 my $url = $self->metadata_url;
3850 remove_username
($url);
3851 my $uuid = $self->rewrite_uuid || $self->ra->get_uuid;
3852 $log_entry{metadata
} = "$url\@$rev " . $uuid;
3853 $email ||= "$author\@" . $uuid;
3854 $commit_email ||= "$author\@" . $uuid;
3856 $log_entry{name
} = $name;
3857 $log_entry{email
} = $email;
3858 $log_entry{commit_name
} = $commit_name;
3859 $log_entry{commit_email
} = $commit_email;
3864 my ($self, $min_rev, $max_rev, @parents) = @_;
3865 my ($last_rev, $last_commit) = $self->last_rev_commit;
3866 my ($base, $head) = $self->get_fetch_range($min_rev, $max_rev);
3867 $self->ra->gs_fetch_loop_common($base, $head, [$self]);
3871 my ($self, $log_entry, $tree, $rev, $date, $author) = @_;
3872 $self->{inject_parents
} = { $rev => $tree };
3873 $self->fetch(undef, undef);
3877 my ($self, $tree) = (shift, shift);
3878 my $log_entry = ::get_commit_entry
($tree);
3879 unless ($self->{last_rev
}) {
3880 ::fatal
("Must have an existing revision to commit");
3882 my %ed_opts = ( r
=> $self->{last_rev
},
3883 log => $log_entry->{log},
3885 tree_a
=> $self->{last_commit
},
3888 $self->set_tree_cb($log_entry, $tree, @_) },
3889 svn_path
=> $self->{path
} );
3890 if (!SVN
::Git
::Editor
->new(\
%ed_opts)->apply_diff) {
3891 print "No changes\nr$self->{last_rev} = $tree\n";
3895 sub rebuild_from_rev_db
{
3896 my ($self, $path) = @_;
3898 open my $fh, '<', $path or croak
"open: $!";
3899 binmode $fh or croak
"binmode: $!";
3901 length($_) == 41 or croak
"inconsistent size in ($_) != 41";
3904 next if $_ eq ('0' x
40);
3905 $self->rev_map_set($r, $_);
3908 close $fh or croak
"close: $!";
3909 unlink $path or croak
"unlink: $!";
3914 my $map_path = $self->map_path;
3915 my $partial = (-e
$map_path && ! -z
$map_path);
3916 return unless ::verify_ref
($self->refname.'^0');
3917 if (!$partial && ($self->use_svm_props || $self->no_metadata)) {
3918 my $rev_db = $self->rev_db_path;
3919 $self->rebuild_from_rev_db($rev_db);
3920 if ($self->use_svm_props) {
3921 my $svm_rev_db = $self->rev_db_path($self->svm_uuid);
3922 $self->rebuild_from_rev_db($svm_rev_db);
3924 $self->unlink_rev_db_symlink;
3927 print "Rebuilding $map_path ...\n" if (!$partial);
3928 my ($base_rev, $head) = ($partial ?
$self->rev_map_max_norebuild(1) :
3931 command_output_pipe
(qw
/rev-list --pretty=raw --reverse/,
3932 ($head ?
"$head.." : "") . $self->refname,
3934 my $metadata_url = $self->metadata_url;
3935 remove_username
($metadata_url);
3936 my $svn_uuid = $self->rewrite_uuid || $self->ra_uuid;
3939 if ( m{^commit ($::sha1)$} ) {
3943 next unless s{^\s*(git-svn-id:)}{$1};
3944 my ($url, $rev, $uuid) = ::extract_metadata
($_);
3945 remove_username
($url);
3947 # ignore merges (from set-tree)
3948 next if (!defined $rev || !$uuid);
3950 # if we merged or otherwise started elsewhere, this is
3951 # how we break out of it
3952 if (($uuid ne $svn_uuid) ||
3953 ($metadata_url && $url && ($url ne $metadata_url))) {
3956 if ($partial && $head) {
3957 print "Partial-rebuilding $map_path ...\n";
3958 print "Currently at $base_rev = $head\n";
3962 $self->rev_map_set($rev, $c);
3963 print "r$rev = $c\n";
3965 command_close_pipe
($log, $ctx);
3966 print "Done rebuilding $map_path\n" if (!$partial || !$head);
3967 my $rev_db_path = $self->rev_db_path;
3968 if (-f
$self->rev_db_path) {
3969 unlink $self->rev_db_path or croak
"unlink: $!";
3971 $self->unlink_rev_db_symlink;
3975 # Tie::File seems to be prone to offset errors if revisions get sparse,
3976 # it's not that fast, either. Tie::File is also not in Perl 5.6. So
3977 # one of my favorite modules is out :< Next up would be one of the DBM
3978 # modules, but I'm not sure which is most portable...
3980 # This is the replacement for the rev_db format, which was too big
3981 # and inefficient for large repositories with a lot of sparse history
3984 # The format is this:
3985 # - 24 bytes for every record,
3986 # * 4 bytes for the integer representing an SVN revision number
3987 # * 20 bytes representing the sha1 of a git commit
3988 # - No empty padding records like the old format
3989 # (except the last record, which can be overwritten)
3990 # - new records are written append-only since SVN revision numbers
3991 # increase monotonically
3992 # - lookups on SVN revision number are done via a binary search
3993 # - Piping the file to xxd -c24 is a good way of dumping it for
3994 # viewing or editing (piped back through xxd -r), should the need
3996 # - The last record can be padding revision with an all-zero sha1
3997 # This is used to optimize fetch performance when using multiple
3998 # "fetch" directives in .git/config
4000 # These files are disposable unless noMetadata or useSvmProps is set
4003 my ($fh, $rev, $commit) = @_;
4005 binmode $fh or croak
"binmode: $!";
4006 my $size = (stat($fh))[7];
4007 ($size % 24) == 0 or croak
"inconsistent size: $size";
4011 sysseek($fh, -24, SEEK_END
) or croak
"seek: $!";
4012 my $read = sysread($fh, my $buf, 24) or croak
"read: $!";
4013 $read == 24 or croak
"read only $read bytes (!= 24)";
4014 my ($last_rev, $last_commit) = unpack(rev_map_fmt
, $buf);
4015 if ($last_commit eq ('0' x40
)) {
4017 sysseek($fh, -48, SEEK_END
) or croak
"seek: $!";
4018 $read = sysread($fh, $buf, 24) or
4021 croak
"read only $read bytes (!= 24)";
4022 ($last_rev, $last_commit) =
4023 unpack(rev_map_fmt
, $buf);
4024 if ($last_commit eq ('0' x40
)) {
4025 croak
"inconsistent .rev_map\n";
4028 if ($last_rev >= $rev) {
4029 croak
"last_rev is higher!: $last_rev >= $rev";
4034 sysseek($fh, $wr_offset, SEEK_END
) or croak
"seek: $!";
4035 syswrite($fh, pack(rev_map_fmt
, $rev, $commit), 24) == 24 or
4039 sub _rev_map_reset
{
4040 my ($fh, $rev, $commit) = @_;
4041 my $c = _rev_map_get
($fh, $rev);
4042 $c eq $commit or die "_rev_map_reset(@_) commit $c does not match!\n";
4043 my $offset = sysseek($fh, 0, SEEK_CUR
) or croak
"seek: $!";
4044 truncate $fh, $offset or croak
"truncate: $!";
4050 my ($dir, $base) = ($path =~ m
#^(.*?)/?([^/]+)$#);
4051 mkpath
([$dir]) unless -d
$dir;
4052 open my $fh, '>>', $path or die "Couldn't create $path: $!\n";
4053 close $fh or die "Couldn't close (create) $path: $!\n";
4058 my ($self, $rev, $commit, $update_ref, $uuid) = @_;
4059 defined $commit or die "missing arg3\n";
4060 length $commit == 40 or die "arg3 must be a full SHA1 hexsum\n";
4061 my $db = $self->map_path($uuid);
4062 my $db_lock = "$db.lock";
4066 $sigmask = POSIX
::SigSet
->new();
4067 my $signew = POSIX
::SigSet
->new(SIGINT
, SIGHUP
, SIGTERM
,
4068 SIGALRM
, SIGPIPE
, SIGUSR1
, SIGUSR2
);
4069 sigprocmask
(SIG_BLOCK
, $signew, $sigmask) or
4070 croak
"Can't block signals: $!";
4074 $LOCKFILES{$db_lock} = 1;
4076 # both of these options make our .rev_db file very, very important
4077 # and we can't afford to lose it because rebuild() won't work
4078 if ($self->use_svm_props || $self->no_metadata) {
4080 copy
($db, $db_lock) or die "rev_map_set(@_): ",
4082 "$db => $db_lock ($!)\n";
4084 rename $db, $db_lock or die "rev_map_set(@_): ",
4085 "Failed to rename: ",
4086 "$db => $db_lock ($!)\n";
4089 sysopen(my $fh, $db_lock, O_RDWR
| O_CREAT
)
4090 or croak
"Couldn't open $db_lock: $!\n";
4091 $update_ref eq 'reset' ? _rev_map_reset
($fh, $rev, $commit) :
4092 _rev_map_set
($fh, $rev, $commit);
4094 $fh->flush or die "Couldn't flush $db_lock: $!\n";
4095 $fh->sync or die "Couldn't sync $db_lock: $!\n";
4097 close $fh or croak
$!;
4101 $note = " ($update_ref)" if ($update_ref !~ /^\d*$/);
4102 command_noisy
('update-ref', '-m', "r$rev$note",
4103 $self->refname, $commit);
4105 rename $db_lock, $db or die "rev_map_set(@_): ", "Failed to rename: ",
4106 "$db_lock => $db ($!)\n";
4107 delete $LOCKFILES{$db_lock};
4109 sigprocmask
(SIG_SETMASK
, $sigmask) or
4110 croak
"Can't restore signal mask: $!";
4114 # If want_commit, this will return an array of (rev, commit) where
4115 # commit _must_ be a valid commit in the archive.
4116 # Otherwise, it'll return the max revision (whether or not the
4117 # commit is valid or just a 0x40 placeholder).
4119 my ($self, $want_commit) = @_;
4121 my ($r, $c) = $self->rev_map_max_norebuild($want_commit);
4122 $want_commit ?
($r, $c) : $r;
4125 sub rev_map_max_norebuild
{
4126 my ($self, $want_commit) = @_;
4127 my $map_path = $self->map_path;
4128 stat $map_path or return $want_commit ?
(0, undef) : 0;
4129 sysopen(my $fh, $map_path, O_RDONLY
) or croak
"open: $!";
4130 binmode $fh or croak
"binmode: $!";
4131 my $size = (stat($fh))[7];
4132 ($size % 24) == 0 or croak
"inconsistent size: $size";
4135 close $fh or croak
"close: $!";
4136 return $want_commit ?
(0, undef) : 0;
4139 sysseek($fh, -24, SEEK_END
) or croak
"seek: $!";
4140 sysread($fh, my $buf, 24) == 24 or croak
"read: $!";
4141 my ($r, $c) = unpack(rev_map_fmt
, $buf);
4142 if ($want_commit && $c eq ('0' x40
)) {
4144 return $want_commit ?
(0, undef) : 0;
4146 sysseek($fh, -48, SEEK_END
) or croak
"seek: $!";
4147 sysread($fh, $buf, 24) == 24 or croak
"read: $!";
4148 ($r, $c) = unpack(rev_map_fmt
, $buf);
4149 if ($c eq ('0'x40
)) {
4150 croak
"Penultimate record is all-zeroes in $map_path";
4153 close $fh or croak
"close: $!";
4154 $want_commit ?
($r, $c) : $r;
4158 my ($self, $rev, $uuid) = @_;
4159 my $map_path = $self->map_path($uuid);
4160 return undef unless -e
$map_path;
4162 sysopen(my $fh, $map_path, O_RDONLY
) or croak
"open: $!";
4163 my $c = _rev_map_get
($fh, $rev);
4164 close($fh) or croak
"close: $!";
4169 my ($fh, $rev) = @_;
4171 binmode $fh or croak
"binmode: $!";
4172 my $size = (stat($fh))[7];
4173 ($size % 24) == 0 or croak
"inconsistent size: $size";
4179 my ($l, $u) = (0, $size - 24);
4183 my $i = int(($l/24 + $u/24) / 2) * 24;
4184 sysseek($fh, $i, SEEK_SET
) or croak
"seek: $!";
4185 sysread($fh, my $buf, 24) == 24 or croak
"read: $!";
4186 my ($r, $c) = unpack(rev_map_fmt
, $buf);
4190 } elsif ($r > $rev) {
4192 } else { # $r == $rev
4193 return $c eq ('0' x
40) ?
undef : $c;
4199 # Finds the first svn revision that exists on (if $eq_ok is true) or
4200 # before $rev for the current branch. It will not search any lower
4201 # than $min_rev. Returns the git commit hash and svn revision number
4202 # if found, else (undef, undef).
4203 sub find_rev_before
{
4204 my ($self, $rev, $eq_ok, $min_rev) = @_;
4205 --$rev unless $eq_ok;
4207 my $max_rev = $self->rev_map_max;
4208 $rev = $max_rev if ($rev > $max_rev);
4209 while ($rev >= $min_rev) {
4210 if (my $c = $self->rev_map_get($rev)) {
4215 return (undef, undef);
4218 # Finds the first svn revision that exists on (if $eq_ok is true) or
4219 # after $rev for the current branch. It will not search any higher
4220 # than $max_rev. Returns the git commit hash and svn revision number
4221 # if found, else (undef, undef).
4222 sub find_rev_after
{
4223 my ($self, $rev, $eq_ok, $max_rev) = @_;
4224 ++$rev unless $eq_ok;
4225 $max_rev ||= $self->rev_map_max;
4226 while ($rev <= $max_rev) {
4227 if (my $c = $self->rev_map_get($rev)) {
4232 return (undef, undef);
4236 my ($class, $repo_id, $ref_id, $path) = @_;
4237 unless (defined $repo_id && length $repo_id) {
4238 $repo_id = $Git::SVN
::default_repo_id
;
4240 unless (defined $ref_id && length $ref_id) {
4241 $_prefix = '' unless defined($_prefix);
4243 "refs/remotes/$_prefix$Git::SVN::default_ref_id";
4246 my $dir = "$ENV{GIT_DIR}/svn/$ref_id";
4248 # Older repos imported by us used $GIT_DIR/svn/foo instead of
4249 # $GIT_DIR/svn/refs/remotes/foo when tracking refs/remotes/foo
4250 if ($ref_id =~ m{^refs/remotes/(.*)}) {
4251 my $old_dir = "$ENV{GIT_DIR}/svn/$1";
4252 if (-d
$old_dir && ! -d
$dir) {
4257 $_[3] = $path = '' unless (defined $path);
4260 ref_id
=> $ref_id, dir
=> $dir, index => "$dir/index",
4261 path
=> $path, config
=> "$ENV{GIT_DIR}/svn/config",
4262 map_root
=> "$dir/.rev_map", repo_id
=> $repo_id }, $class;
4265 # for read-only access of old .rev_db formats
4266 sub unlink_rev_db_symlink
{
4268 my $link = $self->rev_db_path;
4269 $link =~ s/\.[\w-]+$// or croak
"missing UUID at the end of $link";
4271 unlink $link or croak
"unlink: $link failed!";
4276 my ($self, $uuid) = @_;
4277 my $db_path = $self->map_path($uuid);
4278 $db_path =~ s{/\.rev_map\.}{/\.rev_db\.}
4279 or croak
"map_path: $db_path does not contain '/.rev_map.' !";
4283 # the new replacement for .rev_db
4285 my ($self, $uuid) = @_;
4286 $uuid ||= $self->ra_uuid;
4287 "$self->{map_root}.$uuid";
4292 $f =~ s
#([^a-zA-Z0-9\*!\:_\./\-])#uc sprintf("%%%02x",ord($1))#eg;
4298 $f =~ s
#%([0-9a-fA-F]{2})#chr(hex($1))#eg;
4302 sub remove_username
{
4303 $_[0] =~ s{^([^:]*://)[^@]+@}{$1};
4306 package Git
::SVN
::Prompt
;
4310 use vars qw
/$_no_auth_cache $_username/;
4313 my ($cred, $realm, $default_username, $may_save, $pool) = @_;
4314 $may_save = undef if $_no_auth_cache;
4315 $default_username = $_username if defined $_username;
4316 if (defined $default_username && length $default_username) {
4317 if (defined $realm && length $realm) {
4318 print STDERR
"Authentication realm: $realm\n";
4321 $cred->username($default_username);
4323 username
($cred, $realm, $may_save, $pool);
4325 $cred->password(_read_password
("Password for '" .
4326 $cred->username . "': ", $realm));
4327 $cred->may_save($may_save);
4328 $SVN::_Core
::SVN_NO_ERROR
;
4331 sub ssl_server_trust
{
4332 my ($cred, $realm, $failures, $cert_info, $may_save, $pool) = @_;
4333 $may_save = undef if $_no_auth_cache;
4334 print STDERR
"Error validating server certificate for '$realm':\n";
4337 # All variables SVN::Auth::SSL::* are used only once,
4338 # so we're shutting up Perl warnings about this.
4339 if ($failures & $SVN::Auth
::SSL
::UNKNOWNCA
) {
4340 print STDERR
" - The certificate is not issued ",
4341 "by a trusted authority. Use the\n",
4342 " fingerprint to validate ",
4343 "the certificate manually!\n";
4345 if ($failures & $SVN::Auth
::SSL
::CNMISMATCH
) {
4346 print STDERR
" - The certificate hostname ",
4347 "does not match.\n";
4349 if ($failures & $SVN::Auth
::SSL
::NOTYETVALID
) {
4350 print STDERR
" - The certificate is not yet valid.\n";
4352 if ($failures & $SVN::Auth
::SSL
::EXPIRED
) {
4353 print STDERR
" - The certificate has expired.\n";
4355 if ($failures & $SVN::Auth
::SSL
::OTHER
) {
4356 print STDERR
" - The certificate has ",
4357 "an unknown error.\n";
4359 } # no warnings 'once'
4361 "Certificate information:\n".
4362 " - Hostname: %s\n".
4363 " - Valid: from %s until %s\n".
4365 " - Fingerprint: %s\n",
4366 map $cert_info->$_, qw(hostname valid_from valid_until
4367 issuer_dname fingerprint);
4370 print STDERR
$may_save ?
4371 "(R)eject, accept (t)emporarily or accept (p)ermanently? " :
4372 "(R)eject or accept (t)emporarily? ";
4374 $choice = lc(substr(<STDIN
> || 'R', 0, 1));
4375 if ($choice =~ /^t$/i) {
4376 $cred->may_save(undef);
4377 } elsif ($choice =~ /^r$/i) {
4379 } elsif ($may_save && $choice =~ /^p$/i) {
4380 $cred->may_save($may_save);
4384 $cred->accepted_failures($failures);
4385 $SVN::_Core
::SVN_NO_ERROR
;
4388 sub ssl_client_cert
{
4389 my ($cred, $realm, $may_save, $pool) = @_;
4390 $may_save = undef if $_no_auth_cache;
4391 print STDERR
"Client certificate filename: ";
4393 chomp(my $filename = <STDIN
>);
4394 $cred->cert_file($filename);
4395 $cred->may_save($may_save);
4396 $SVN::_Core
::SVN_NO_ERROR
;
4399 sub ssl_client_cert_pw
{
4400 my ($cred, $realm, $may_save, $pool) = @_;
4401 $may_save = undef if $_no_auth_cache;
4402 $cred->password(_read_password
("Password: ", $realm));
4403 $cred->may_save($may_save);
4404 $SVN::_Core
::SVN_NO_ERROR
;
4408 my ($cred, $realm, $may_save, $pool) = @_;
4409 $may_save = undef if $_no_auth_cache;
4410 if (defined $realm && length $realm) {
4411 print STDERR
"Authentication realm: $realm\n";
4414 if (defined $_username) {
4415 $username = $_username;
4417 print STDERR
"Username: ";
4419 chomp($username = <STDIN
>);
4421 $cred->username($username);
4422 $cred->may_save($may_save);
4423 $SVN::_Core
::SVN_NO_ERROR
;
4426 sub _read_password
{
4427 my ($prompt, $realm) = @_;
4429 if (exists $ENV{GIT_ASKPASS
}) {
4430 open(PH
, "-|", $ENV{GIT_ASKPASS
}, $prompt);
4432 $password =~ s/[\012\015]//; # \n\r
4435 print STDERR
$prompt;
4437 require Term
::ReadKey
;
4438 Term
::ReadKey
::ReadMode
('noecho');
4439 while (defined(my $key = Term
::ReadKey
::ReadKey
(0))) {
4440 last if $key =~ /[\012\015]/; # \n\r
4443 Term
::ReadKey
::ReadMode
('restore');
4450 package SVN
::Git
::Fetcher
;
4451 use vars qw
/@ISA $_ignore_regex $_preserve_empty_dirs $_placeholder_filename
4452 @deleted_gpath %added_placeholder $repo_id/;
4456 use File
::Basename qw
/dirname/;
4459 # file baton members: path, mode_a, mode_b, pool, fh, blob, base
4461 my ($class, $git_svn, $switch_path) = @_;
4462 my $self = SVN
::Delta
::Editor
->new;
4463 bless $self, $class;
4464 if (exists $git_svn->{last_commit
}) {
4465 $self->{c
} = $git_svn->{last_commit
};
4466 $self->{empty_symlinks
} =
4467 _mark_empty_symlinks
($git_svn, $switch_path);
4470 # some options are read globally, but can be overridden locally
4471 # per [svn-remote "..."] section. Command-line options will *NOT*
4472 # override options set in an [svn-remote "..."] section
4473 $repo_id = $git_svn->{repo_id
};
4474 my $k = "svn-remote.$repo_id.ignore-paths";
4475 my $v = eval { command_oneline
('config', '--get', $k) };
4476 $self->{ignore_regex
} = $v;
4478 $k = "svn-remote.$repo_id.preserve-empty-dirs";
4479 $v = eval { command_oneline
('config', '--get', '--bool', $k) };
4480 if ($v && $v eq 'true') {
4481 $_preserve_empty_dirs = 1;
4482 $k = "svn-remote.$repo_id.placeholder-filename";
4483 $v = eval { command_oneline
('config', '--get', $k) };
4484 $_placeholder_filename = $v;
4487 # Load the list of placeholder files added during previous invocations.
4488 $k = "svn-remote.$repo_id.added-placeholder";
4489 $v = eval { command_oneline
('config', '--get-all', $k) };
4490 if ($_preserve_empty_dirs && $v) {
4491 # command() prints errors to stderr, so we only call it if
4492 # command_oneline() succeeded.
4493 my @v = command
('config', '--get-all', $k);
4494 $added_placeholder{ dirname
($_) } = $_ foreach @v;
4497 $self->{empty
} = {};
4498 $self->{dir_prop
} = {};
4499 $self->{file_prop
} = {};
4500 $self->{absent_dir
} = {};
4501 $self->{absent_file
} = {};
4502 $self->{gii
} = $git_svn->tmp_index_do(sub { Git
::IndexInfo
->new });
4503 $self->{pathnameencoding
} = Git
::config
('svn.pathnameencoding');
4507 # this uses the Ra object, so it must be called before do_{switch,update},
4508 # not inside them (when the Git::SVN::Fetcher object is passed) to
4509 # do_{switch,update}
4510 sub _mark_empty_symlinks
{
4511 my ($git_svn, $switch_path) = @_;
4512 my $bool = Git
::config_bool
('svn.brokenSymlinkWorkaround');
4513 return {} if (!defined($bool)) || (defined($bool) && ! $bool);
4516 my ($rev, $cmt) = $git_svn->last_rev_commit;
4517 return {} unless ($rev && $cmt);
4519 # allow the warning to be printed for each revision we fetch to
4520 # ensure the user sees it. The user can also disable the workaround
4521 # on the repository even while git svn is running and the next
4522 # revision fetched will skip this expensive function.
4523 my $printed_warning;
4524 chomp(my $empty_blob = `git hash-object -t blob --stdin < /dev/null`);
4525 my ($ls, $ctx) = command_output_pipe
(qw
/ls-tree -r -z/, $cmt);
4527 my $pfx = defined($switch_path) ?
$switch_path : $git_svn->{path
};
4528 $pfx .= '/' if length($pfx);
4531 s/\A100644 blob $empty_blob\t//o or next;
4532 unless ($printed_warning) {
4533 print STDERR
"Scanning for empty symlinks, ",
4534 "this may take a while if you have ",
4535 "many empty files\n",
4536 "You may disable this with `",
4537 "git config svn.brokenSymlinkWorkaround ",
4539 "This may be done in a different ",
4540 "terminal without restarting ",
4542 $printed_warning = 1;
4545 my (undef, $props) =
4546 $git_svn->ra->get_file($pfx.$path, $rev, undef);
4547 if ($props->{'svn:special'}) {
4551 command_close_pipe
($ls, $ctx);
4555 # returns true if a given path is inside a ".git" directory
4557 $_[0] =~ m{(?:^|/)\.git(?:/|$)};
4560 # return value: 0 -- don't ignore, 1 -- ignore
4561 sub is_path_ignored
{
4562 my ($self, $path) = @_;
4563 return 1 if in_dot_git
($path);
4564 return 1 if defined($self->{ignore_regex
}) &&
4565 $path =~ m!$self->{ignore_regex}!;
4566 return 0 unless defined($_ignore_regex);
4567 return 1 if $path =~ m!$_ignore_regex!o;
4571 sub set_path_strip
{
4572 my ($self, $path) = @_;
4573 $self->{path_strip
} = qr/^\Q$path\E(\/|$)/ if length $path;
4580 sub open_directory
{
4581 my ($self, $path, $pb, $rev) = @_;
4586 my ($self, $path) = @_;
4587 if (my $enc = $self->{pathnameencoding
}) {
4589 Encode
::from_to
($path, 'UTF-8', $enc);
4591 if ($self->{path_strip
}) {
4592 $path =~ s!$self->{path_strip}!! or
4593 die "Failed to strip path '$path' ($self->{path_strip})\n";
4599 my ($self, $path, $rev, $pb) = @_;
4600 return undef if $self->is_path_ignored($path);
4602 my $gpath = $self->git_path($path);
4603 return undef if ($gpath eq '');
4605 # remove entire directories.
4606 my ($tree) = (command
('ls-tree', '-z', $self->{c
}, "./$gpath")
4607 =~ /\A040000 tree ([a-f\d]{40})\t\Q$gpath\E\0/);
4609 my ($ls, $ctx) = command_output_pipe
(qw
/ls
-tree
4615 my $rmpath = "$gpath/$_";
4616 $self->{gii
}->remove($rmpath);
4617 print "\tD\t$rmpath\n" unless $::_q
;
4619 print "\tD\t$gpath/\n" unless $::_q
;
4620 command_close_pipe
($ls, $ctx);
4622 $self->{gii
}->remove($gpath);
4623 print "\tD\t$gpath\n" unless $::_q
;
4625 # Don't add to @deleted_gpath if we're deleting a placeholder file.
4626 push @deleted_gpath, $gpath unless $added_placeholder{dirname
($path)};
4627 $self->{empty
}->{$path} = 0;
4632 my ($self, $path, $pb, $rev) = @_;
4635 goto out
if $self->is_path_ignored($path);
4637 my $gpath = $self->git_path($path);
4638 ($mode, $blob) = (command
('ls-tree', '-z', $self->{c
}, "./$gpath")
4639 =~ /\A(\d{6}) blob ([a-f\d]{40})\t\Q$gpath\E\0/);
4640 unless (defined $mode && defined $blob) {
4641 die "$path was not found in commit $self->{c} (r$rev)\n";
4643 if ($mode eq '100644' && $self->{empty_symlinks
}->{$path}) {
4647 { path
=> $path, mode_a
=> $mode, mode_b
=> $mode, blob
=> $blob,
4648 pool
=> SVN
::Pool
->new, action
=> 'M' };
4652 my ($self, $path, $pb, $cp_path, $cp_rev) = @_;
4655 if (!$self->is_path_ignored($path)) {
4656 my ($dir, $file) = ($path =~ m
#^(.*?)/?([^/]+)$#);
4657 delete $self->{empty
}->{$dir};
4660 if ($added_placeholder{$dir}) {
4661 # Remove our placeholder file, if we created one.
4662 delete_entry
($self, $added_placeholder{$dir})
4663 unless $path eq $added_placeholder{$dir};
4664 delete $added_placeholder{$dir}
4668 { path
=> $path, mode_a
=> $mode, mode_b
=> $mode,
4669 pool
=> SVN
::Pool
->new, action
=> 'A' };
4673 my ($self, $path, $cp_path, $cp_rev) = @_;
4674 goto out
if $self->is_path_ignored($path);
4675 my $gpath = $self->git_path($path);
4677 my ($ls, $ctx) = command_output_pipe
(qw
/ls
-tree
4683 $self->{gii
}->remove($_);
4684 print "\tD\t$_\n" unless $::_q
;
4685 push @deleted_gpath, $gpath;
4687 command_close_pipe
($ls, $ctx);
4688 $self->{empty
}->{$path} = 0;
4690 my ($dir, $file) = ($path =~ m
#^(.*?)/?([^/]+)$#);
4691 delete $self->{empty
}->{$dir};
4692 $self->{empty
}->{$path} = 1;
4694 if ($added_placeholder{$dir}) {
4695 # Remove our placeholder file, if we created one.
4696 delete_entry
($self, $added_placeholder{$dir});
4697 delete $added_placeholder{$dir}
4704 sub change_dir_prop
{
4705 my ($self, $db, $prop, $value) = @_;
4706 return undef if $self->is_path_ignored($db->{path
});
4707 $self->{dir_prop
}->{$db->{path
}} ||= {};
4708 $self->{dir_prop
}->{$db->{path
}}->{$prop} = $value;
4712 sub absent_directory
{
4713 my ($self, $path, $pb) = @_;
4714 return undef if $self->is_path_ignored($path);
4715 $self->{absent_dir
}->{$pb->{path
}} ||= [];
4716 push @
{$self->{absent_dir
}->{$pb->{path
}}}, $path;
4721 my ($self, $path, $pb) = @_;
4722 return undef if $self->is_path_ignored($path);
4723 $self->{absent_file
}->{$pb->{path
}} ||= [];
4724 push @
{$self->{absent_file
}->{$pb->{path
}}}, $path;
4728 sub change_file_prop
{
4729 my ($self, $fb, $prop, $value) = @_;
4730 return undef if $self->is_path_ignored($fb->{path
});
4731 if ($prop eq 'svn:executable') {
4732 if ($fb->{mode_b
} != 120000) {
4733 $fb->{mode_b
} = defined $value ?
100755 : 100644;
4735 } elsif ($prop eq 'svn:special') {
4736 $fb->{mode_b
} = defined $value ?
120000 : 100644;
4738 $self->{file_prop
}->{$fb->{path
}} ||= {};
4739 $self->{file_prop
}->{$fb->{path
}}->{$prop} = $value;
4744 sub apply_textdelta
{
4745 my ($self, $fb, $exp) = @_;
4746 return undef if $self->is_path_ignored($fb->{path
});
4747 my $fh = $::_repository
->temp_acquire('svn_delta');
4748 # $fh gets auto-closed() by SVN::TxDelta::apply(),
4749 # (but $base does not,) so dup() it for reading in close_file
4750 open my $dup, '<&', $fh or croak
$!;
4751 my $base = $::_repository
->temp_acquire('git_blob');
4754 my ($base_is_link, $size);
4756 if ($fb->{mode_a
} eq '120000' &&
4757 ! $self->{empty_symlinks
}->{$fb->{path
}}) {
4758 print $base 'link ' or die "print $!\n";
4762 $size = $::_repository
->cat_blob($fb->{blob
}, $base);
4763 die "Failed to read object $fb->{blob}" if ($size < 0);
4766 seek $base, 0, 0 or croak
$!;
4767 my $got = ::md5sum
($base);
4769 my $err = "Checksum mismatch: ".
4770 "$fb->{path} $fb->{blob}\n" .
4771 "expected: $exp\n" .
4773 if ($base_is_link) {
4775 "Retrying... (possibly ",
4776 "a bad symlink from SVN)\n";
4777 $::_repository
->temp_reset($base);
4785 seek $base, 0, 0 or croak
$!;
4787 $fb->{base
} = $base;
4788 [ SVN
::TxDelta
::apply
($base, $dup, undef, $fb->{path
}, $fb->{pool
}) ];
4792 my ($self, $fb, $exp) = @_;
4793 return undef if $self->is_path_ignored($fb->{path
});
4796 my $path = $self->git_path($fb->{path
});
4797 if (my $fh = $fb->{fh
}) {
4799 seek($fh, 0, 0) or croak
$!;
4800 my $got = ::md5sum
($fh);
4802 die "Checksum mismatch: $path\n",
4803 "expected: $exp\n got: $got\n";
4806 if ($fb->{mode_b
} == 120000) {
4807 sysseek($fh, 0, 0) or croak
$!;
4808 my $rd = sysread($fh, my $buf, 5);
4811 croak
"sysread: $!\n";
4812 } elsif ($rd == 0) {
4813 warn "$path has mode 120000",
4814 " but it points to nothing\n",
4815 "converting to an empty file with mode",
4817 $fb->{mode_b
} = '100644';
4818 } elsif ($buf ne 'link ') {
4819 warn "$path has mode 120000",
4820 " but is not a link\n";
4822 my $tmp_fh = $::_repository
->temp_acquire(
4825 while ($res = sysread($fh, my $str, 1024)) {
4826 my $out = syswrite($tmp_fh, $str, $res);
4827 defined($out) && $out == $res
4829 Git
::temp_path
($tmp_fh),
4832 defined $res or croak
$!;
4834 ($fh, $tmp_fh) = ($tmp_fh, $fh);
4835 Git
::temp_release
($tmp_fh, 1);
4839 $hash = $::_repository
->hash_and_insert_object(
4840 Git
::temp_path
($fh));
4841 $hash =~ /^[a-f\d]{40}$/ or die "not a sha1: $hash\n";
4843 Git
::temp_release
($fb->{base
}, 1);
4844 Git
::temp_release
($fh, 1);
4846 $hash = $fb->{blob
} or die "no blob information\n";
4849 $self->{gii
}->update($fb->{mode_b
}, $hash, $path) or croak
$!;
4850 print "\t$fb->{action}\t$path\n" if $fb->{action
} && ! $::_q
;
4856 $self->{nr
} = $self->{gii
}->{nr
};
4857 delete $self->{gii
};
4858 $self->SUPER::abort_edit
(@_);
4864 if ($_preserve_empty_dirs) {
4867 # Any entry flagged as empty that also has an associated
4868 # dir_prop represents a newly created empty directory.
4869 foreach my $i (keys %{$self->{empty
}}) {
4870 push @empty_dirs, $i if exists $self->{dir_prop
}->{$i};
4873 # Search for directories that have become empty due subsequent
4875 push @empty_dirs, $self->find_empty_directories();
4877 # Finally, add a placeholder file to each empty directory.
4878 $self->add_placeholder_file($_) foreach (@empty_dirs);
4880 $self->stash_placeholder_list();
4883 $self->{git_commit_ok
} = 1;
4884 $self->{nr
} = $self->{gii
}->{nr
};
4885 delete $self->{gii
};
4886 $self->SUPER::close_edit
(@_);
4889 sub find_empty_directories
{
4892 my %dirs = map { dirname
($_) => 1 } @deleted_gpath;
4894 foreach my $dir (sort keys %dirs) {
4895 next if $dir eq ".";
4897 # If there have been any additions to this directory, there is
4898 # no reason to check if it is empty.
4900 foreach my $t (qw
/dir_prop file_prop/) {
4901 foreach my $path (keys %{ $self->{$t} }) {
4902 if (exists $self->{$t}->{dirname
($path)}) {
4907 last if $skip_added;
4909 next if $skip_added;
4911 # Use `git ls-tree` to get the filenames of this directory
4912 # that existed prior to this particular commit.
4913 my $ls = command
('ls-tree', '-z', '--name-only',
4914 $self->{c
}, "$dir/");
4915 my %files = map { $_ => 1 } split(/\0/, $ls);
4917 # Remove the filenames that were deleted during this commit.
4918 delete $files{$_} foreach (@deleted_gpath);
4920 # Report the directory if there are no filenames left.
4921 push @empty_dirs, $dir unless (scalar %files);
4926 sub add_placeholder_file
{
4927 my ($self, $dir) = @_;
4928 my $path = "$dir/$_placeholder_filename";
4929 my $gpath = $self->git_path($path);
4931 my $fh = $::_repository
->temp_acquire($gpath);
4932 my $hash = $::_repository
->hash_and_insert_object(Git
::temp_path
($fh));
4933 Git
::temp_release
($fh, 1);
4934 $self->{gii
}->update('100644', $hash, $gpath) or croak
$!;
4936 # The directory should no longer be considered empty.
4937 delete $self->{empty
}->{$dir} if exists $self->{empty
}->{$dir};
4939 # Keep track of any placeholder files we create.
4940 $added_placeholder{$dir} = $path;
4943 sub stash_placeholder_list
{
4945 my $k = "svn-remote.$repo_id.added-placeholder";
4946 my $v = eval { command_oneline
('config', '--get-all', $k) };
4947 command_noisy
('config', '--unset-all', $k) if $v;
4948 foreach (values %added_placeholder) {
4949 command_noisy
('config', '--add', $k, $_);
4953 package SVN
::Git
::Editor
;
4954 use vars qw
/@ISA $_rmdir $_cp_similarity $_find_copies_harder $_rename_limit/;
4961 my ($class, $opts) = @_;
4962 foreach (qw
/svn_path r ra tree_a tree_b log editor_cb/) {
4963 die "$_ required!\n" unless (defined $opts->{$_});
4966 my $pool = SVN
::Pool
->new;
4967 my $mods = generate_diff
($opts->{tree_a
}, $opts->{tree_b
});
4968 my $types = check_diff_paths
($opts->{ra
}, $opts->{svn_path
},
4971 # $opts->{ra} functions should not be used after this:
4972 my @ce = $opts->{ra
}->get_commit_editor($opts->{log},
4973 $opts->{editor_cb
}, $pool);
4974 my $self = SVN
::Delta
::Editor
->new(@ce, $pool);
4975 bless $self, $class;
4976 foreach (qw
/svn_path r tree_a tree_b/) {
4977 $self->{$_} = $opts->{$_};
4979 $self->{url
} = $opts->{ra
}->{url
};
4980 $self->{mods
} = $mods;
4981 $self->{types
} = $types;
4982 $self->{pool
} = $pool;
4983 $self->{bat
} = { '' => $self->open_root($self->{r
}, $self->{pool
}) };
4985 $self->{path_prefix
} = length $self->{svn_path
} ?
4986 "$self->{svn_path}/" : '';
4987 $self->{config
} = $opts->{config
};
4988 $self->{mergeinfo
} = $opts->{mergeinfo
};
4993 my ($tree_a, $tree_b) = @_;
4994 my @diff_tree = qw(diff-tree -z -r);
4995 if ($_cp_similarity) {
4996 push @diff_tree, "-C$_cp_similarity";
4998 push @diff_tree, '-C';
5000 push @diff_tree, '--find-copies-harder' if $_find_copies_harder;
5001 push @diff_tree, "-l$_rename_limit" if defined $_rename_limit;
5002 push @diff_tree, $tree_a, $tree_b;
5003 my ($diff_fh, $ctx) = command_output_pipe
(@diff_tree);
5007 while (<$diff_fh>) {
5008 chomp $_; # this gets rid of the trailing "\0"
5009 if ($state eq 'meta' && /^:(\d
{6})\s
(\d
{6})\s
5010 ($::sha1
)\s
($::sha1
)\s
5011 ([MTCRAD
])\d
*$/xo
) {
5012 push @mods, { mode_a
=> $1, mode_b
=> $2,
5013 sha1_a
=> $3, sha1_b
=> $4,
5015 if ($5 =~ /^(?:C|R)$/) {
5020 } elsif ($state eq 'file_a') {
5021 my $x = $mods[$#mods] or croak
"Empty array\n";
5022 if ($x->{chg
} !~ /^(?:C|R)$/) {
5023 croak
"Error parsing $_, $x->{chg}\n";
5027 } elsif ($state eq 'file_b') {
5028 my $x = $mods[$#mods] or croak
"Empty array\n";
5029 if (exists $x->{file_a
} && $x->{chg
} !~ /^(?:C|R)$/) {
5030 croak
"Error parsing $_, $x->{chg}\n";
5032 if (!exists $x->{file_a
} && $x->{chg
} =~ /^(?:C|R)$/) {
5033 croak
"Error parsing $_, $x->{chg}\n";
5038 croak
"Error parsing $_\n";
5041 command_close_pipe
($diff_fh, $ctx);
5045 sub check_diff_paths
{
5046 my ($ra, $pfx, $rev, $mods) = @_;
5048 $pfx .= '/' if length $pfx;
5050 sub type_diff_paths
{
5051 my ($ra, $types, $path, $rev) = @_;
5052 my @p = split m
#/+#, $path;
5054 unless (defined $types->{$c}) {
5055 $types->{$c} = $ra->check_path($c, $rev);
5058 $c .= '/' . shift @p;
5059 next if defined $types->{$c};
5060 $types->{$c} = $ra->check_path($c, $rev);
5064 foreach my $m (@
$mods) {
5065 foreach my $f (qw
/file_a file_b/) {
5066 next unless defined $m->{$f};
5067 my ($dir) = ($m->{$f} =~ m
#^(.*?)/?(?:[^/]+)$#);
5068 if (length $pfx.$dir && ! defined $types{$dir}) {
5069 type_diff_paths
($ra, \
%types, $pfx.$dir, $rev);
5077 return ($_[0] =~ m
#^(.*?)/?([^/]+)$#);
5081 my ($self, $path) = @_;
5082 if (my $enc = $self->{pathnameencoding
}) {
5084 Encode
::from_to
($path, $enc, 'UTF-8');
5086 $self->{path_prefix
}.(defined $path ?
$path : '');
5090 my ($self, $path) = @_;
5091 if ($self->{url
} =~ m
#^https?://#) {
5092 $path =~ s!([^~a-zA-Z0-9_./-])!uc sprintf("%%%02x",ord($1))!eg;
5094 $self->{url
} . '/' . $self->repo_path($path);
5099 my $rm = $self->{rm
};
5100 delete $rm->{''}; # we never delete the url we're tracking
5103 foreach (keys %$rm) {
5104 my @d = split m
#/#, $_;
5108 $c .= '/' . shift @d;
5112 delete $rm->{$self->{svn_path
}};
5113 delete $rm->{''}; # we never delete the url we're tracking
5116 my ($fh, $ctx) = command_output_pipe
(qw
/ls-tree --name-only -r -z/,
5121 my @dn = split m
#/#, $_;
5123 delete $rm->{join '/', @dn};
5130 command_close_pipe
($fh, $ctx);
5132 my ($r, $p, $bat) = ($self->{r
}, $self->{pool
}, $self->{bat
});
5133 foreach my $d (sort { $b =~ tr
#/#/# <=> $a =~ tr#/#/# } keys %$rm) {
5134 $self->close_directory($bat->{$d}, $p);
5135 my ($dn) = ($d =~ m
#^(.*?)/?(?:[^/]+)$#);
5136 print "\tD+\t$d/\n" unless $::_q
;
5137 $self->SUPER::delete_entry
($d, $r, $bat->{$dn}, $p);
5142 sub open_or_add_dir
{
5143 my ($self, $full_path, $baton, $deletions) = @_;
5144 my $t = $self->{types
}->{$full_path};
5146 die "$full_path not known in r$self->{r} or we have a bug!\n";
5150 # SVN::Node::none and SVN::Node::file are used only once,
5151 # so we're shutting up Perl's warnings about them.
5152 if ($t == $SVN::Node
::none
|| defined($deletions->{$full_path})) {
5153 return $self->add_directory($full_path, $baton,
5154 undef, -1, $self->{pool
});
5155 } elsif ($t == $SVN::Node
::dir
) {
5156 return $self->open_directory($full_path, $baton,
5157 $self->{r
}, $self->{pool
});
5158 } # no warnings 'once'
5159 print STDERR
"$full_path already exists in repository at ",
5160 "r$self->{r} and it is not a directory (",
5161 ($t == $SVN::Node
::file ?
'file' : 'unknown'),"/$t)\n";
5162 } # no warnings 'once'
5167 my ($self, $path, $deletions) = @_;
5168 my $bat = $self->{bat
};
5169 my $repo_path = $self->repo_path($path);
5170 return $bat->{''} unless (length $repo_path);
5172 my @p = split m
#/+#, $repo_path;
5174 $bat->{$c} ||= $self->open_or_add_dir($c, $bat->{''}, $deletions);
5177 $c .= '/' . shift @p;
5178 $bat->{$c} ||= $self->open_or_add_dir($c, $bat->{$c0}, $deletions);
5183 # Subroutine to convert a globbing pattern to a regular expression.
5184 # From perl cookbook.
5186 my $globstr = shift;
5187 my %patmap = ('*' => '.*', '?' => '.', '[' => '[', ']' => ']');
5188 $globstr =~ s{(.)} { $patmap{$1} || "\Q$1" }ge;
5189 return '^' . $globstr . '$';
5192 sub check_autoprop
{
5193 my ($self, $pattern, $properties, $file, $fbat) = @_;
5194 # Convert the globbing pattern to a regular expression.
5195 my $regex = glob2pat
($pattern);
5196 # Check if the pattern matches the file name.
5197 if($file =~ m/($regex)/) {
5198 # Parse the list of properties to set.
5199 my @props = split(/;/, $properties);
5200 foreach my $prop (@props) {
5201 # Parse 'name=value' syntax and set the property.
5202 if ($prop =~ /([^=]+)=(.*)/) {
5203 my ($n,$v) = ($1,$2);
5207 $self->change_file_prop($fbat, $n, $v);
5213 sub apply_autoprops
{
5214 my ($self, $file, $fbat) = @_;
5215 my $conf_t = ${$self->{config
}}{'config'};
5217 # Check [miscellany]/enable-auto-props in svn configuration.
5218 if (SVN
::_Core
::svn_config_get_bool
(
5220 $SVN::_Core
::SVN_CONFIG_SECTION_MISCELLANY
,
5221 $SVN::_Core
::SVN_CONFIG_OPTION_ENABLE_AUTO_PROPS
,
5223 # Auto-props are enabled. Enumerate them to look for matches.
5224 my $callback = sub {
5225 $self->check_autoprop($_[0], $_[1], $file, $fbat);
5227 SVN
::_Core
::svn_config_enumerate
(
5229 $SVN::_Core
::SVN_CONFIG_SECTION_AUTO_PROPS
,
5235 my ($self, $m, $deletions) = @_;
5236 my ($dir, $file) = split_path
($m->{file_b
});
5237 my $pbat = $self->ensure_path($dir, $deletions);
5238 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
5240 print "\tA\t$m->{file_b}\n" unless $::_q
;
5241 $self->apply_autoprops($file, $fbat);
5242 $self->chg_file($fbat, $m);
5243 $self->close_file($fbat,undef,$self->{pool
});
5247 my ($self, $m, $deletions) = @_;
5248 my ($dir, $file) = split_path
($m->{file_b
});
5249 my $pbat = $self->ensure_path($dir, $deletions);
5250 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
5251 $self->url_path($m->{file_a
}), $self->{r
});
5252 print "\tC\t$m->{file_a} => $m->{file_b}\n" unless $::_q
;
5253 $self->chg_file($fbat, $m);
5254 $self->close_file($fbat,undef,$self->{pool
});
5258 my ($self, $path, $pbat) = @_;
5259 my $rpath = $self->repo_path($path);
5260 my ($dir, $file) = split_path
($rpath);
5261 $self->{rm
}->{$dir} = 1;
5262 $self->SUPER::delete_entry
($rpath, $self->{r
}, $pbat, $self->{pool
});
5266 my ($self, $m, $deletions) = @_;
5267 my ($dir, $file) = split_path
($m->{file_b
});
5268 my $pbat = $self->ensure_path($dir, $deletions);
5269 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
5270 $self->url_path($m->{file_a
}), $self->{r
});
5271 print "\tR\t$m->{file_a} => $m->{file_b}\n" unless $::_q
;
5272 $self->apply_autoprops($file, $fbat);
5273 $self->chg_file($fbat, $m);
5274 $self->close_file($fbat,undef,$self->{pool
});
5276 ($dir, $file) = split_path
($m->{file_a
});
5277 $pbat = $self->ensure_path($dir, $deletions);
5278 $self->delete_entry($m->{file_a
}, $pbat);
5282 my ($self, $m, $deletions) = @_;
5283 my ($dir, $file) = split_path
($m->{file_b
});
5284 my $pbat = $self->ensure_path($dir, $deletions);
5285 my $fbat = $self->open_file($self->repo_path($m->{file_b
}),
5286 $pbat,$self->{r
},$self->{pool
});
5287 print "\t$m->{chg}\t$m->{file_b}\n" unless $::_q
;
5288 $self->chg_file($fbat, $m);
5289 $self->close_file($fbat,undef,$self->{pool
});
5292 sub T
{ shift->M(@_) }
5294 sub change_file_prop
{
5295 my ($self, $fbat, $pname, $pval) = @_;
5296 $self->SUPER::change_file_prop
($fbat, $pname, $pval, $self->{pool
});
5299 sub change_dir_prop
{
5300 my ($self, $pbat, $pname, $pval) = @_;
5301 $self->SUPER::change_dir_prop
($pbat, $pname, $pval, $self->{pool
});
5304 sub _chg_file_get_blob
($$$$) {
5305 my ($self, $fbat, $m, $which) = @_;
5306 my $fh = $::_repository
->temp_acquire("git_blob_$which");
5307 if ($m->{"mode_$which"} =~ /^120/) {
5308 print $fh 'link ' or croak
$!;
5309 $self->change_file_prop($fbat,'svn:special','*');
5310 } elsif ($m->{mode_a
} =~ /^120/ && $m->{"mode_$which"} !~ /^120/) {
5311 $self->change_file_prop($fbat,'svn:special',undef);
5313 my $blob = $m->{"sha1_$which"};
5314 return ($fh,) if ($blob =~ /^0{40}$/);
5315 my $size = $::_repository
->cat_blob($blob, $fh);
5316 croak
"Failed to read object $blob" if ($size < 0);
5317 $fh->flush == 0 or croak
$!;
5318 seek $fh, 0, 0 or croak
$!;
5320 my $exp = ::md5sum
($fh);
5321 seek $fh, 0, 0 or croak
$!;
5326 my ($self, $fbat, $m) = @_;
5327 if ($m->{mode_b
} =~ /755$/ && $m->{mode_a
} !~ /755$/) {
5328 $self->change_file_prop($fbat,'svn:executable','*');
5329 } elsif ($m->{mode_b
} !~ /755$/ && $m->{mode_a
} =~ /755$/) {
5330 $self->change_file_prop($fbat,'svn:executable',undef);
5332 my ($fh_a, $exp_a) = _chg_file_get_blob
$self, $fbat, $m, 'a';
5333 my ($fh_b, $exp_b) = _chg_file_get_blob
$self, $fbat, $m, 'b';
5334 my $pool = SVN
::Pool
->new;
5335 my $atd = $self->apply_textdelta($fbat, $exp_a, $pool);
5337 my $txstream = SVN
::TxDelta
::new
($fh_a, $fh_b, $pool);
5338 my $res = SVN
::TxDelta
::send_txstream
($txstream, @
$atd, $pool);
5340 die "Unexpected result from send_txstream: $res\n",
5341 "(SVN::Core::VERSION: $SVN::Core::VERSION)\n";
5344 my $got = SVN
::TxDelta
::send_stream
($fh_b, @
$atd, $pool);
5345 die "Checksum mismatch\nexpected: $exp_b\ngot: $got\n"
5346 if ($got ne $exp_b);
5348 Git
::temp_release
($fh_b, 1);
5349 Git
::temp_release
($fh_a, 1);
5354 my ($self, $m, $deletions) = @_;
5355 my ($dir, $file) = split_path
($m->{file_b
});
5356 my $pbat = $self->ensure_path($dir, $deletions);
5357 print "\tD\t$m->{file_b}\n" unless $::_q
;
5358 $self->delete_entry($m->{file_b
}, $pbat);
5363 my ($p,$bat) = ($self->{pool
}, $self->{bat
});
5364 foreach (sort { $b =~ tr
#/#/# <=> $a =~ tr#/#/# } keys %$bat) {
5366 $self->close_directory($bat->{$_}, $p);
5368 $self->close_directory($bat->{''}, $p);
5369 $self->SUPER::close_edit
($p);
5375 $self->SUPER::abort_edit
($self->{pool
});
5380 $self->SUPER::DESTROY
(@_);
5381 $self->{pool
}->clear;
5384 # this drives the editor
5387 my $mods = $self->{mods
};
5388 my %o = ( D
=> 0, C
=> 1, R
=> 2, A
=> 3, M
=> 4, T
=> 5 );
5391 foreach my $m (@
$mods) {
5392 if ($m->{chg
} eq "D") {
5393 $deletions{$m->{file_b
}} = 1;
5397 foreach my $m (sort { $o{$a->{chg
}} <=> $o{$b->{chg
}} } @
$mods) {
5399 if (defined $o{$f}) {
5400 $self->$f($m, \
%deletions);
5402 fatal
("Invalid change type: $f");
5406 if (defined($self->{mergeinfo
})) {
5407 $self->change_dir_prop($self->{bat
}{''}, "svn:mergeinfo",
5408 $self->{mergeinfo
});
5410 $self->rmdirs if $_rmdir;
5411 if (@
$mods == 0 && !defined($self->{mergeinfo
})) {
5416 return scalar @
$mods;
5419 package Git
::SVN
::Ra
;
5420 use vars qw
/@ISA $config_dir $_ignore_refs_regex $_log_window_size/;
5423 my ($ra_invalid, $can_do_switch, %ignored_err, $RA);
5426 # enforce temporary pool usage for some simple functions
5428 for my $f (qw
/rev_proplist get_latest_revnum get_uuid get_repos_root
5430 my $SUPER = "SUPER::$f";
5433 my $pool = SVN
::Pool
->new;
5434 my @ret = $self->$SUPER(@_,$pool);
5436 wantarray ?
@ret : $ret[0];
5441 sub _auth_providers
() {
5443 SVN
::Client
::get_simple_provider
(),
5444 SVN
::Client
::get_ssl_server_trust_file_provider
(),
5445 SVN
::Client
::get_simple_prompt_provider
(
5446 \
&Git
::SVN
::Prompt
::simple
, 2),
5447 SVN
::Client
::get_ssl_client_cert_file_provider
(),
5448 SVN
::Client
::get_ssl_client_cert_prompt_provider
(
5449 \
&Git
::SVN
::Prompt
::ssl_client_cert
, 2),
5450 SVN
::Client
::get_ssl_client_cert_pw_file_provider
(),
5451 SVN
::Client
::get_ssl_client_cert_pw_prompt_provider
(
5452 \
&Git
::SVN
::Prompt
::ssl_client_cert_pw
, 2),
5453 SVN
::Client
::get_username_provider
(),
5454 SVN
::Client
::get_ssl_server_trust_prompt_provider
(
5455 \
&Git
::SVN
::Prompt
::ssl_server_trust
),
5456 SVN
::Client
::get_username_prompt_provider
(
5457 \
&Git
::SVN
::Prompt
::username
, 2)
5461 sub escape_uri_only
{
5464 foreach (split m{/}, $uri) {
5465 s/([^~\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg;
5473 if ($url =~ m
#^(https?)://([^/]+)(.*)$#) {
5474 my ($scheme, $domain, $uri) = ($1, $2, escape_uri_only
($3));
5475 $url = "$scheme://$domain$uri";
5481 my ($class, $url) = @_;
5483 return $RA if ($RA && $RA->{url
} eq $url);
5487 SVN
::_Core
::svn_config_ensure
($config_dir, undef);
5488 my ($baton, $callbacks) = SVN
::Core
::auth_open_helper
(_auth_providers
);
5489 my $config = SVN
::Core
::config_get_config
($config_dir);
5491 my $dont_store_passwords = 1;
5492 my $conf_t = ${$config}{'config'};
5495 # The usage of $SVN::_Core::SVN_CONFIG_* variables
5496 # produces warnings that variables are used only once.
5497 # I had not found the better way to shut them up, so
5498 # the warnings of type 'once' are disabled in this block.
5499 if (SVN
::_Core
::svn_config_get_bool
($conf_t,
5500 $SVN::_Core
::SVN_CONFIG_SECTION_AUTH
,
5501 $SVN::_Core
::SVN_CONFIG_OPTION_STORE_PASSWORDS
,
5503 SVN
::_Core
::svn_auth_set_parameter
($baton,
5504 $SVN::_Core
::SVN_AUTH_PARAM_DONT_STORE_PASSWORDS
,
5505 bless (\
$dont_store_passwords, "_p_void"));
5507 if (SVN
::_Core
::svn_config_get_bool
($conf_t,
5508 $SVN::_Core
::SVN_CONFIG_SECTION_AUTH
,
5509 $SVN::_Core
::SVN_CONFIG_OPTION_STORE_AUTH_CREDS
,
5511 $Git::SVN
::Prompt
::_no_auth_cache
= 1;
5513 } # no warnings 'once'
5514 my $self = SVN
::Ra
->new(url
=> escape_url
($url), auth
=> $baton,
5516 pool
=> SVN
::Pool
->new,
5517 auth_provider_callbacks
=> $callbacks);
5518 $self->{url
} = $url;
5519 $self->{svn_path
} = $url;
5520 $self->{repos_root
} = $self->get_repos_root;
5521 $self->{svn_path
} =~ s
#^\Q$self->{repos_root}\E(/|$)##;
5522 $self->{cache
} = { check_path
=> { r
=> 0, data
=> {} },
5523 get_dir
=> { r
=> 0, data
=> {} } };
5524 $RA = bless $self, $class;
5528 my ($self, $path, $r) = @_;
5529 my $cache = $self->{cache
}->{check_path
};
5530 if ($r == $cache->{r
} && exists $cache->{data
}->{$path}) {
5531 return $cache->{data
}->{$path};
5533 my $pool = SVN
::Pool
->new;
5534 my $t = $self->SUPER::check_path
($path, $r, $pool);
5536 if ($r != $cache->{r
}) {
5537 %{$cache->{data
}} = ();
5540 $cache->{data
}->{$path} = $t;
5544 my ($self, $dir, $r) = @_;
5545 my $cache = $self->{cache
}->{get_dir
};
5546 if ($r == $cache->{r
}) {
5547 if (my $x = $cache->{data
}->{$dir}) {
5548 return wantarray ? @
$x : $x->[0];
5551 my $pool = SVN
::Pool
->new;
5552 my ($d, undef, $props) = $self->SUPER::get_dir
($dir, $r, $pool);
5553 my %dirents = map { $_ => { kind
=> $d->{$_}->kind } } keys %$d;
5555 if ($r != $cache->{r
}) {
5556 %{$cache->{data
}} = ();
5559 $cache->{data
}->{$dir} = [ \
%dirents, $r, $props ];
5560 wantarray ?
(\
%dirents, $r, $props) : \
%dirents;
5564 # do not call the real DESTROY since we store ourselves in $RA
5567 # get_log(paths, start, end, limit,
5568 # discover_changed_paths, strict_node_history, receiver)
5570 my ($self, @args) = @_;
5571 my $pool = SVN
::Pool
->new;
5573 # svn_log_changed_path_t objects passed to get_log are likely to be
5574 # overwritten even if only the refs are copied to an external variable,
5575 # so we should dup the structures in their entirety. Using an
5576 # externally passed pool (instead of our temporary and quickly cleared
5577 # pool in Git::SVN::Ra) does not help matters at all...
5578 my $receiver = pop @args;
5579 my $prefix = "/".$self->{svn_path
};
5580 $prefix =~ s
#/+($)##;
5581 my $prefix_regex = qr
#^\Q$prefix\E#;
5583 my ($paths) = $_[0];
5584 return &$receiver(@_) unless $paths;
5586 foreach my $p (keys %$paths) {
5587 my $i = $paths->{$p};
5588 # Make path relative to our url, not repos_root
5589 $p =~ s/$prefix_regex//;
5590 my %s = map { $_ => $i->$_; }
5591 qw
/copyfrom_path copyfrom_rev action/;
5592 if ($s{'copyfrom_path'}) {
5593 $s{'copyfrom_path'} =~ s/$prefix_regex//;
5601 # the limit parameter was not supported in SVN 1.1.x, so we
5602 # drop it. Therefore, the receiver callback passed to it
5603 # is made aware of this limitation by being wrapped if
5604 # the limit passed to is being wrapped.
5605 if ($SVN::Core
::VERSION
le '1.2.0') {
5606 my $limit = splice(@args, 3, 1);
5608 my $receiver = pop @args;
5609 push(@args, sub { &$receiver(@_) if (--$limit >= 0) });
5612 my $ret = $self->SUPER::get_log
(@args, $pool);
5618 my ($self, $url1, $rev1, $url2, $rev2) = @_;
5619 my $ctx = SVN
::Client
->new(auth
=> _auth_providers
);
5620 my $out = IO
::File
->new_tmpfile;
5622 # older SVN (1.1.x) doesn't take $pool as the last parameter for
5623 # $ctx->diff(), so we'll create a default one
5624 my $pool = SVN
::Pool
->new_default_sub;
5626 $ra_invalid = 1; # this will open a new SVN::Ra connection to $url1
5627 $ctx->diff([], $url1, $rev1, $url2, $rev2, 1, 1, 0, $out, $out);
5629 my $ret = (($out->stat)[7] == 0);
5630 close $out or croak
$!;
5635 sub get_commit_editor
{
5636 my ($self, $log, $cb, $pool) = @_;
5637 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef, 0) : ();
5638 $self->SUPER::get_commit_editor
($log, $cb, @lock, $pool);
5642 my ($self, $rev_a, $rev_b, $gs, $editor) = @_;
5643 my $new = ($rev_a == $rev_b);
5644 my $path = $gs->{path
};
5646 if ($new && -e
$gs->{index}) {
5647 unlink $gs->{index} or die
5648 "Couldn't unlink index: $gs->{index}: $!\n";
5650 my $pool = SVN
::Pool
->new;
5651 $editor->set_path_strip($path);
5652 my (@pc) = split m
#/#, $path;
5653 my $reporter = $self->do_update($rev_b, (@pc ?
shift @pc : ''),
5655 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef) : ();
5657 # Since we can't rely on svn_ra_reparent being available, we'll
5658 # just have to do some magic with set_path to make it so
5659 # we only want a partial path.
5661 my $final = join('/', @pc);
5663 $reporter->set_path($sp, $rev_b, 0, @lock, $pool);
5664 $sp .= '/' if length $sp;
5667 die "BUG: '$sp' != '$final'\n" if ($sp ne $final);
5669 $reporter->set_path($sp, $rev_a, $new, @lock, $pool);
5671 $reporter->finish_report($pool);
5673 $editor->{git_commit_ok
};
5676 # this requires SVN 1.4.3 or later (do_switch didn't work before 1.4.3, and
5677 # svn_ra_reparent didn't work before 1.4)
5679 my ($self, $rev_a, $rev_b, $gs, $url_b, $editor) = @_;
5680 my $path = $gs->{path
};
5681 my $pool = SVN
::Pool
->new;
5683 my $full_url = $self->{url
};
5684 my $old_url = $full_url;
5685 $full_url .= '/' . $path if length $path;
5686 my ($ra, $reparented);
5688 if ($old_url =~ m
#^svn(\+ssh)?://# ||
5689 ($full_url =~ m
#^https?://# &&
5690 escape_url
($full_url) ne $full_url)) {
5694 $ra = Git
::SVN
::Ra
->new($full_url);
5696 } elsif ($old_url ne $full_url) {
5697 SVN
::_Ra
::svn_ra_reparent
($self->{session
}, $full_url, $pool);
5698 $self->{url
} = $full_url;
5703 $url_b = escape_url
($url_b);
5704 my $reporter = $ra->do_switch($rev_b, '', 1, $url_b, $editor, $pool);
5705 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef) : ();
5706 $reporter->set_path('', $rev_a, 0, @lock, $pool);
5707 $reporter->finish_report($pool);
5710 SVN
::_Ra
::svn_ra_reparent
($self->{session
}, $old_url, $pool);
5711 $self->{url
} = $old_url;
5715 $editor->{git_commit_ok
};
5718 sub longest_common_path
{
5719 my ($gsv, $globs) = @_;
5721 my $common_max = scalar @
$gsv;
5723 foreach my $gs (@
$gsv) {
5724 my @tmp = split m
#/#, $gs->{path};
5727 $p .= length($p) ?
"/$_" : $_;
5733 $common_max += scalar @
$globs;
5734 foreach my $glob (@
$globs) {
5735 my @tmp = split m
#/#, $glob->{path}->{left};
5738 $p .= length($p) ?
"/$_" : $_;
5744 my $longest_path = '';
5745 foreach (sort {length $b <=> length $a} keys %common) {
5746 if ($common{$_} == $common_max) {
5754 sub gs_fetch_loop_common
{
5755 my ($self, $base, $head, $gsv, $globs) = @_;
5756 return if ($base > $head);
5757 my $inc = $_log_window_size;
5758 my ($min, $max) = ($base, $head < $base + $inc ?
$head : $base + $inc);
5759 my $longest_path = longest_common_path
($gsv, $globs);
5760 my $ra_url = $self->{url
};
5761 my $find_trailing_edge;
5765 my $err_handler = $SVN::Error
::handler
;
5766 $SVN::Error
::handler
= sub {
5768 skip_unknown_revs
($err);
5771 my ($paths, $r, $author, $date, $log) = @_;
5773 { author
=> $author, date
=> $date, log => $log } ];
5775 $self->get_log([$longest_path], $min, $max, 0, 1, 1,
5776 sub { $revs{$_[1]} = _cb
(@_) });
5778 print "Checked through r$max\r";
5780 $find_trailing_edge = 1;
5782 if ($err and $find_trailing_edge) {
5783 print STDERR
"Path '$longest_path' ",
5784 "was probably deleted:\n",
5785 $err->expanded_message,
5786 "\nWill attempt to follow ",
5787 "revisions r$min .. r$max ",
5788 "committed before the deletion\n";
5790 while (--$hi >= $min) {
5792 $self->get_log([$longest_path], $min, $hi,
5795 $revs{$_[1]} = _cb
(@_) });
5797 print STDERR
"r$min .. r$ok OK\n";
5801 $find_trailing_edge = 0;
5803 $SVN::Error
::handler
= $err_handler;
5805 my %exists = map { $_->{path
} => $_ } @
$gsv;
5806 foreach my $r (sort {$a <=> $b} keys %revs) {
5807 my ($paths, $logged) = @
{$revs{$r}};
5809 foreach my $gs ($self->match_globs(\
%exists, $paths,
5811 if ($gs->rev_map_max >= $r) {
5814 next unless $gs->match_paths($paths, $r);
5815 $gs->{logged_rev_props
} = $logged;
5816 if (my $last_commit = $gs->last_commit) {
5817 $gs->assert_index_clean($last_commit);
5819 my $log_entry = $gs->do_fetch($paths, $r);
5821 $gs->do_git_commit($log_entry);
5823 $INDEX_FILES{$gs->{index}} = 1;
5825 foreach my $g (@
$globs) {
5826 my $k = "svn-remote.$g->{remote}." .
5828 Git
::SVN
::tmp_config
($k, $r);
5834 $self = Git
::SVN
::Ra
->new($ra_url);
5835 $ra_invalid = undef;
5838 # pre-fill the .rev_db since it'll eventually get filled in
5839 # with '0' x40 if something new gets committed
5840 foreach my $gs (@
$gsv) {
5841 next if $gs->rev_map_max >= $max;
5842 next if defined $gs->rev_map_get($max);
5843 $gs->rev_map_set($max, 0 x40
);
5845 foreach my $g (@
$globs) {
5846 my $k = "svn-remote.$g->{remote}.$g->{t}-maxRev";
5847 Git
::SVN
::tmp_config
($k, $max);
5849 last if $max >= $head;
5852 $max = $head if ($max > $head);
5857 sub get_dir_globbed
{
5858 my ($self, $left, $depth, $r) = @_;
5860 my @x = eval { $self->get_dir($left, $r) };
5861 return unless scalar @x == 3;
5862 my $dirents = $x[0];
5864 foreach my $de (keys %$dirents) {
5865 next if $dirents->{$de}->{kind
} != $SVN::Node
::dir
;
5867 my @args = ("$left/$de", $depth - 1, $r);
5868 foreach my $dir ($self->get_dir_globbed(@args)) {
5869 push @finalents, "$de/$dir";
5872 push @finalents, $de;
5878 # return value: 0 -- don't ignore, 1 -- ignore
5879 sub is_ref_ignored
{
5881 my $refname = $g->{ref}->full_path($p);
5882 return 1 if defined($g->{ignore_refs_regex
}) &&
5883 $refname =~ m!$g->{ignore_refs_regex}!;
5884 return 0 unless defined($_ignore_refs_regex);
5885 return 1 if $refname =~ m!$_ignore_refs_regex!o;
5890 my ($self, $exists, $paths, $globs, $r) = @_;
5893 my ($self, $exists, $g, $r) = @_;
5895 my @dirs = $self->get_dir_globbed($g->{path
}->{left
},
5896 $g->{path
}->{depth
},
5899 foreach my $de (@dirs) {
5900 my $p = $g->{path
}->full_path($de);
5901 next if $exists->{$p};
5902 next if (length $g->{path
}->{right
} &&
5903 ($self->check_path($p, $r) !=
5905 next unless $p =~ /$g->{path}->{regex}/;
5906 $exists->{$p} = Git
::SVN
->init($self->{url
}, $p, undef,
5907 $g->{ref}->full_path($de), 1);
5910 foreach my $g (@
$globs) {
5911 if (my $path = $paths->{"/$g->{path}->{left}"}) {
5912 if ($path->{action
} =~ /^[AR]$/) {
5913 get_dir_check
($self, $exists, $g, $r);
5916 foreach (keys %$paths) {
5917 if (/$g->{path}->{left_regex}/ &&
5918 !/$g->{path}->{regex}/) {
5919 next if $paths->{$_}->{action
} !~ /^[AR]$/;
5920 get_dir_check
($self, $exists, $g, $r);
5922 next unless /$g->{path}->{regex}/;
5924 my $pathname = $g->{path
}->full_path($p);
5925 next if is_ref_ignored
($g, $p);
5926 next if $exists->{$pathname};
5927 next if ($self->check_path($pathname, $r) !=
5929 $exists->{$pathname} = Git
::SVN
->init(
5930 $self->{url
}, $pathname, undef,
5931 $g->{ref}->full_path($p), 1);
5934 foreach (split m
#/#, $g->{path}->{left}) {
5936 next unless ($paths->{$c} &&
5937 ($paths->{$c}->{action
} =~ /^[AR]$/));
5938 get_dir_check
($self, $exists, $g, $r);
5946 return $self->{url
} if ($self->{url
} eq $self->{repos_root
});
5947 my $url = $self->{repos_root
};
5948 my @components = split(m!/!, $self->{svn_path
});
5951 $url .= "/$c" if length $c;
5953 my $ra = (ref $self)->new($url);
5954 my $latest = $ra->get_latest_revnum;
5955 $ra->get_log("", $latest, 0, 1, 0, 1, sub {});
5957 } while ($@
&& ($c = shift @components));
5963 unless (defined $can_do_switch) {
5964 my $pool = SVN
::Pool
->new;
5966 $self->do_switch(1, '', 0, $self->{url
},
5967 SVN
::Delta
::Editor
->new, $pool);
5972 $rep->abort_report($pool);
5980 sub skip_unknown_revs
{
5982 my $errno = $err->apr_err();
5983 # Maybe the branch we're tracking didn't
5984 # exist when the repo started, so it's
5985 # not an error if it doesn't, just continue
5987 # Wonderfully consistent library, eh?
5988 # 160013 - svn:// and file://
5989 # 175002 - http(s)://
5990 # 175007 - http(s):// (this repo required authorization, too...)
5991 # More codes may be discovered later...
5992 if ($errno == 175007 || $errno == 175002 || $errno == 160013) {
5993 my $err_key = $err->expanded_message;
5994 # revision numbers change every time, filter them out
5995 $err_key =~ s/\d+/\0/g;
5996 $err_key = "$errno\0$err_key";
5997 unless ($ignored_err{$err_key}) {
5998 warn "W: Ignoring error from SVN, path probably ",
5999 "does not exist: ($errno): ",
6000 $err->expanded_message,"\n";
6001 warn "W: Do not be alarmed at the above message ",
6002 "git-svn is just searching aggressively for ",
6004 "This may take a while on large repositories\n";
6005 $ignored_err{$err_key} = 1;
6009 die "Error from SVN, ($errno): ", $err->expanded_message,"\n";
6012 package Git
::SVN
::Log
;
6015 use POSIX qw
/strftime/;
6016 use constant commit_log_separator
=> ('-' x
72) . "\n";
6017 use vars qw
/$TZ $limit $color $pager $non_recursive $verbose $oneline
6018 %rusers $show_commit $incremental/;
6023 return 1 if defined $c->{r
};
6025 # big commit message got truncated by the 16k pretty buffer in rev-list
6026 if ($c->{l
} && $c->{l
}->[-1] eq "...\n" &&
6027 $c->{a_raw
} =~ /\@([a-f\d\-]+)>$/) {
6029 my @log = command
(qw
/cat-file commit/, $c->{c
});
6031 # shift off the headers
6032 shift @log while ($log[0] ne '');
6035 # TODO: make $c->{l} not have a trailing newline in the future
6036 @
{$c->{l
}} = map { "$_\n" } grep !/^git-svn-id: /, @log;
6038 (undef, $c->{r
}, undef) = ::extract_metadata
(
6039 (grep(/^git-svn-id: /, @log))[-1]);
6041 return defined $c->{r
};
6045 return $color || Git
->repository->get_colorbool('color.diff');
6048 sub git_svn_log_cmd
{
6049 my ($r_min, $r_max, @args) = @_;
6051 my (@files, @log_opts);
6052 foreach my $x (@args) {
6053 if ($x eq '--' || @files) {
6056 if (::verify_ref
("$x^0")) {
6064 my ($url, $rev, $uuid, $gs) = ::working_head_info
($head);
6065 $gs ||= Git
::SVN
->_new;
6066 my @cmd = (qw
/log --abbrev-commit --pretty=raw --default/,
6068 push @cmd, '-r' unless $non_recursive;
6069 push @cmd, qw
/--raw --name-status/ if $verbose;
6070 push @cmd, '--color' if log_use_color
();
6071 push @cmd, @log_opts;
6072 if (defined $r_max && $r_max == $r_min) {
6073 push @cmd, '--max-count=1';
6074 if (my $c = $gs->rev_map_get($r_max)) {
6077 } elsif (defined $r_max) {
6078 if ($r_max < $r_min) {
6079 ($r_min, $r_max) = ($r_max, $r_min);
6081 my (undef, $c_max) = $gs->find_rev_before($r_max, 1, $r_min);
6082 my (undef, $c_min) = $gs->find_rev_after($r_min, 1, $r_max);
6083 # If there are no commits in the range, both $c_max and $c_min
6084 # will be undefined. If there is at least 1 commit in the
6085 # range, both will be defined.
6086 return () if !defined $c_min || !defined $c_max;
6087 if ($c_min eq $c_max) {
6088 push @cmd, '--max-count=1', $c_min;
6090 push @cmd, '--boundary', "$c_min..$c_max";
6093 return (@cmd, @files);
6096 # adapted from pager.c
6099 $ENV{GIT_PAGER_IN_USE
} = 'false';
6103 chomp($pager = command_oneline
(qw(var GIT_PAGER)));
6104 if ($pager eq 'cat') {
6107 $ENV{GIT_PAGER_IN_USE
} = defined($pager);
6111 return unless defined $pager;
6112 pipe my ($rfd, $wfd) or return;
6113 defined(my $pid = fork) or ::fatal
"Can't fork: $!";
6115 open STDOUT
, '>&', $wfd or
6116 ::fatal
"Can't redirect to stdout: $!";
6119 open STDIN
, '<&', $rfd or ::fatal
"Can't redirect stdin: $!";
6120 $ENV{LESS
} ||= 'FRSX';
6121 exec $pager or ::fatal
"Can't run pager: $! ($pager)";
6124 sub format_svn_date
{
6125 my $t = shift || time;
6126 my $gmoff = Git
::SVN
::get_tz
($t);
6127 return strftime
("%Y-%m-%d %H:%M:%S $gmoff (%a, %d %b %Y)", localtime($t));
6130 sub parse_git_date
{
6132 # Date::Parse isn't in the standard Perl distro :(
6133 if ($tz =~ s/^\+//) {
6134 $t += tz_to_s_offset
($tz);
6135 } elsif ($tz =~ s/^\-//) {
6136 $t -= tz_to_s_offset
($tz);
6141 sub set_local_timezone
{
6149 sub tz_to_s_offset
{
6152 return ($1 * 60) + ($tz * 3600);
6155 sub get_author_info
{
6156 my ($dest, $author, $t, $tz) = @_;
6157 $author =~ s/(?:^\s*|\s*$)//g;
6158 $dest->{a_raw
} = $author;
6161 $au = $rusers{$author} || undef;
6164 ($au) = ($author =~ /<([^>]+)\@[^>]+>$/);
6169 $dest->{t_utc
} = parse_git_date
($t, $tz);
6172 sub process_commit
{
6173 my ($c, $r_min, $r_max, $defer) = @_;
6174 if (defined $r_min && defined $r_max) {
6175 if ($r_min == $c->{r
} && $r_min == $r_max) {
6179 return 1 if $r_min == $r_max;
6180 if ($r_min < $r_max) {
6181 # we need to reverse the print order
6182 return 0 if (defined $limit && --$limit < 0);
6186 if ($r_min != $r_max) {
6187 return 1 if ($r_min < $c->{r
});
6188 return 1 if ($r_max > $c->{r
});
6191 return 0 if (defined $limit && --$limit < 0);
6200 if (my $l = $c->{l
}) {
6201 while ($l->[0] =~ /^\s*$/) { shift @
$l }
6204 $l_fmt ||= 'A' . length($c->{r
});
6205 print 'r',pack($l_fmt, $c->{r
}),' | ';
6206 print "$c->{c} | " if $show_commit;
6209 show_commit_normal
($c);
6213 sub show_commit_changed_paths
{
6215 return unless $c->{changed
};
6216 print "Changed paths:\n", @
{$c->{changed
}};
6219 sub show_commit_normal
{
6221 print commit_log_separator
, "r$c->{r} | ";
6222 print "$c->{c} | " if $show_commit;
6223 print "$c->{a} | ", format_svn_date
($c->{t_utc
}), ' | ';
6226 if (my $l = $c->{l
}) {
6227 while ($l->[$#$l] eq "\n" && $#$l > 0
6228 && $l->[($#$l - 1)] eq "\n") {
6231 $nr_line = scalar @
$l;
6233 print "1 line\n\n\n";
6235 if ($nr_line == 1) {
6236 $nr_line = '1 line';
6238 $nr_line .= ' lines';
6240 print $nr_line, "\n";
6241 show_commit_changed_paths
($c);
6243 print $_ foreach @
$l;
6247 show_commit_changed_paths
($c);
6251 foreach my $x (qw
/raw stat diff/) {
6254 print $_ foreach @
{$c->{$x}}
6261 my ($r_min, $r_max);
6262 my $r_last = -1; # prevent dupes
6263 set_local_timezone
();
6264 if (defined $::_revision
) {
6265 if ($::_revision
=~ /^(\d+):(\d+)$/) {
6266 ($r_min, $r_max) = ($1, $2);
6267 } elsif ($::_revision
=~ /^\d+$/) {
6268 $r_min = $r_max = $::_revision
;
6270 ::fatal
"-r$::_revision is not supported, use ",
6271 "standard 'git log' arguments instead";
6276 @args = git_svn_log_cmd
($r_min, $r_max, @args);
6278 print commit_log_separator
unless $incremental || $oneline;
6281 my $log = command_output_pipe
(@args);
6283 my (@k, $c, $d, $stat);
6284 my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
6286 if (/^${esc_color}commit (?:- )?($::sha1_short)/o) {
6288 if ($c && cmt_showable
($c) && $c->{r
} != $r_last) {
6290 process_commit
($c, $r_min, $r_max, \
@k) or
6295 } elsif (/^${esc_color}author (.+) (\d+) ([\-\+]?\d+)$/o) {
6296 get_author_info
($c, $1, $2, $3);
6297 } elsif (/^${esc_color}(?:tree|parent|committer) /o) {
6299 } elsif (/^${esc_color}:\d{6} \d{6} $::sha1_short/o) {
6300 push @
{$c->{raw
}}, $_;
6301 } elsif (/^${esc_color}[ACRMDT]\t/) {
6302 # we could add $SVN->{svn_path} here, but that requires
6303 # remote access at the moment (repo_path_split)...
6304 s
#^(${esc_color})([ACRMDT])\t#$1 $2 #o;
6305 push @
{$c->{changed
}}, $_;
6306 } elsif (/^${esc_color}diff /o) {
6308 push @
{$c->{diff
}}, $_;
6310 push @
{$c->{diff
}}, $_;
6311 } elsif (/^\
.+\ \
|\s
*\d
+\
$esc_color[\
+\
-]*
6312 $esc_color*[\
+\
-]*$esc_color$/x
) {
6314 push @
{$c->{stat}}, $_;
6315 } elsif ($stat && /^ \d+ files changed, \d+ insertions/) {
6316 push @
{$c->{stat}}, $_;
6318 } elsif (/^${esc_color} (git-svn-id:.+)$/o) {
6319 ($c->{url
}, $c->{r
}, undef) = ::extract_metadata
($1);
6320 } elsif (s/^${esc_color} //o) {
6321 push @
{$c->{l
}}, $_;
6324 if ($c && defined $c->{r
} && $c->{r
} != $r_last) {
6326 process_commit
($c, $r_min, $r_max, \
@k);
6329 ($r_min, $r_max) = ($r_max, $r_min);
6330 process_commit
($_, $r_min, $r_max) foreach reverse @k;
6334 print commit_log_separator
unless $incremental || $oneline;
6343 my ($fh, $ctx, $rev);
6346 ($fh, $ctx) = command_output_pipe
('blame', @_, $path);
6347 while (my $line = <$fh>) {
6348 if ($line =~ /^\^?([[:xdigit:]]+)\s/) {
6349 # Uncommitted edits show up as a rev ID of
6350 # all zeros, which we can't look up with
6353 (undef, $rev, undef) =
6355 $rev = '0' if (!$rev);
6359 $rev = sprintf('%-10s', $rev);
6360 $line =~ s/^\^?[[:xdigit:]]+(\s)/$rev$1/;
6365 ($fh, $ctx) = command_output_pipe
('blame', '-p', @_, 'HEAD',
6370 my %dsha; #distinct sha keys
6372 while (my $line = <$fh>) {
6373 push @buffer, $line;
6374 if ($line =~ /^([[:xdigit:]]{40})\s\d+\s\d+/) {
6379 my $s2r = ::cmt_sha2rev_batch
([keys %dsha]);
6381 foreach my $line (@buffer) {
6382 if ($line =~ /^([[:xdigit:]]{40})\s\d+\s\d+/) {
6384 $rev = '0' if (!$rev)
6386 elsif ($line =~ /^author (.*)/) {
6387 $authors{$rev} = $1;
6388 $authors{$rev} =~ s/\s/_/g;
6390 elsif ($line =~ /^\t(.*)$/) {
6391 printf("%6s %10s %s\n", $rev, $authors{$rev}, $1);
6395 command_close_pipe
($fh, $ctx);
6398 package Git
::SVN
::Migration
;
6399 # these version numbers do NOT correspond to actual version numbers
6400 # of git nor git-svn. They are just relative.
6402 # v0 layout: .git/$id/info/url, refs/heads/$id-HEAD
6404 # v1 layout: .git/$id/info/url, refs/remotes/$id
6406 # v2 layout: .git/svn/$id/info/url, refs/remotes/$id
6408 # v3 layout: .git/svn/$id, refs/remotes/$id
6409 # - info/url may remain for backwards compatibility
6410 # - this is what we migrate up to this layout automatically,
6411 # - this will be used by git svn init on single branches
6412 # v3.1 layout (auto migrated):
6413 # - .rev_db => .rev_db.$UUID, .rev_db will remain as a symlink
6414 # for backwards compatibility
6416 # v4 layout: .git/svn/$repo_id/$id, refs/remotes/$repo_id/$id
6417 # - this is only created for newly multi-init-ed
6418 # repositories. Similar in spirit to the
6419 # --use-separate-remotes option in git-clone (now default)
6420 # - we do not automatically migrate to this (following
6421 # the example set by core git)
6423 # v5 layout: .rev_db.$UUID => .rev_map.$UUID
6424 # - newer, more-efficient format that uses 24-bytes per record
6425 # with no filler space.
6426 # - use xxd -c24 < .rev_map.$UUID to view and debug
6427 # - This is a one-way migration, repositories updated to the
6428 # new format will not be able to use old git-svn without
6429 # rebuilding the .rev_db. Rebuilding the rev_db is not
6430 # possible if noMetadata or useSvmProps are set; but should
6431 # be no problem for users that use the (sensible) defaults.
6435 use File
::Path qw
/mkpath/;
6436 use File
::Basename qw
/dirname basename/;
6437 use vars qw
/$_minimize/;
6439 sub migrate_from_v0
{
6440 my $git_dir = $ENV{GIT_DIR
};
6441 return undef unless -d
$git_dir;
6442 my ($fh, $ctx) = command_output_pipe
(qw
/rev-parse --symbolic --all/);
6446 my ($id, $orig_ref) = ($_, $_);
6447 next unless $id =~ s
#^refs/heads/(.+)-HEAD$#$1#;
6448 next unless -f
"$git_dir/$id/info/url";
6449 my $new_ref = "refs/remotes/$id";
6450 if (::verify_ref
("$new_ref^0")) {
6451 print STDERR
"W: $orig_ref is probably an old ",
6452 "branch used by an ancient version of ",
6454 "However, $new_ref also exists.\n",
6455 "We will not be able ",
6456 "to use this branch until this ",
6457 "ambiguity is resolved.\n";
6460 print STDERR
"Migrating from v0 layout...\n" if !$migrated;
6461 print STDERR
"Renaming ref: $orig_ref => $new_ref\n";
6462 command_noisy
('update-ref', $new_ref, $orig_ref);
6463 command_noisy
('update-ref', '-d', $orig_ref, $orig_ref);
6466 command_close_pipe
($fh, $ctx);
6467 print STDERR
"Done migrating from v0 layout...\n" if $migrated;
6471 sub migrate_from_v1
{
6472 my $git_dir = $ENV{GIT_DIR
};
6474 return $migrated unless -d
$git_dir;
6475 my $svn_dir = "$git_dir/svn";
6477 # just in case somebody used 'svn' as their $id at some point...
6478 return $migrated if -d
$svn_dir && ! -f
"$svn_dir/info/url";
6480 print STDERR
"Migrating from a git-svn v1 layout...\n";
6482 print STDERR
"Data from a previous version of git-svn exists, but\n\t",
6483 "$svn_dir\n\t(required for this version ",
6484 "($::VERSION) of git-svn) does not exist.\n";
6485 my ($fh, $ctx) = command_output_pipe
(qw
/rev-parse --symbolic --all/);
6488 next unless $x =~ s
#^refs/remotes/##;
6490 next unless -f
"$git_dir/$x/info/url";
6491 my $u = eval { ::file_to_s
("$git_dir/$x/info/url") };
6493 my $dn = dirname
("$git_dir/svn/$x");
6494 mkpath
([$dn]) unless -d
$dn;
6495 if ($x eq 'svn') { # they used 'svn' as GIT_SVN_ID:
6496 mkpath
(["$git_dir/svn/svn"]);
6497 print STDERR
" - $git_dir/$x/info => ",
6498 "$git_dir/svn/$x/info\n";
6499 rename "$git_dir/$x/info", "$git_dir/svn/$x/info" or
6501 # don't worry too much about these, they probably
6502 # don't exist with repos this old (save for index,
6503 # and we can easily regenerate that)
6504 foreach my $f (qw
/unhandled.log index .rev_db/) {
6505 rename "$git_dir/$x/$f", "$git_dir/svn/$x/$f";
6508 print STDERR
" - $git_dir/$x => $git_dir/svn/$x\n";
6509 rename "$git_dir/$x", "$git_dir/svn/$x" or
6514 command_close_pipe
($fh, $ctx);
6515 print STDERR
"Done migrating from a git-svn v1 layout\n";
6520 my ($l_map, $pfx, $path) = @_;
6522 foreach (<$path/*>) {
6523 if (-r
"$_/info/url") {
6524 $pfx .= '/' if $pfx && $pfx !~ m
!/$!;
6525 my $ref_id = $pfx . basename
$_;
6526 my $url = ::file_to_s
("$_/info/url");
6527 $l_map->{$ref_id} = $url;
6534 $x =~ s!^\Q$ENV{GIT_DIR}\E/svn/!!o;
6535 read_old_urls
($l_map, $x, $_);
6539 sub migrate_from_v2
{
6540 my @cfg = command
(qw
/config -l/);
6541 return if grep /^svn-remote\..+\.url=/, @cfg;
6543 read_old_urls
(\
%l_map, '', "$ENV{GIT_DIR}/svn");
6546 foreach my $ref_id (sort keys %l_map) {
6547 eval { Git
::SVN
->init($l_map{$ref_id}, '', undef, $ref_id) };
6549 Git
::SVN
->init($l_map{$ref_id}, '', $ref_id, $ref_id);
6556 sub minimize_connections
{
6557 my $r = Git
::SVN
::read_all_remotes
();
6559 my $root_repos = {};
6560 foreach my $repo_id (keys %$r) {
6561 my $url = $r->{$repo_id}->{url
} or next;
6562 my $fetch = $r->{$repo_id}->{fetch
} or next;
6563 my $ra = Git
::SVN
::Ra
->new($url);
6565 # skip existing cases where we already connect to the root
6566 if (($ra->{url
} eq $ra->{repos_root
}) ||
6567 ($ra->{repos_root
} eq $repo_id)) {
6568 $root_repos->{$ra->{url
}} = $repo_id;
6572 my $root_ra = Git
::SVN
::Ra
->new($ra->{repos_root
});
6573 my $root_path = $ra->{url
};
6574 $root_path =~ s
#^\Q$ra->{repos_root}\E(/|$)##;
6575 foreach my $path (keys %$fetch) {
6576 my $ref_id = $fetch->{$path};
6577 my $gs = Git
::SVN
->new($ref_id, $repo_id, $path);
6579 # make sure we can read when connecting to
6580 # a higher level of a repository
6581 my ($last_rev, undef) = $gs->last_rev_commit;
6582 if (!defined $last_rev) {
6584 $root_ra->get_latest_revnum;
6588 my $new = $root_path;
6589 $new .= length $path ?
"/$path" : '';
6591 $root_ra->get_log([$new], $last_rev, $last_rev,
6595 $new_urls->{$ra->{repos_root
}}->{$new} =
6596 { ref_id
=> $ref_id,
6597 old_repo_id
=> $repo_id,
6598 old_path
=> $path };
6603 foreach my $url (keys %$new_urls) {
6604 # see if we can re-use an existing [svn-remote "repo_id"]
6605 # instead of creating a(n ugly) new section:
6606 my $repo_id = $root_repos->{$url} || $url;
6608 my $fetch = $new_urls->{$url};
6609 foreach my $path (keys %$fetch) {
6610 my $x = $fetch->{$path};
6611 Git
::SVN
->init($url, $path, $repo_id, $x->{ref_id
});
6612 my $pfx = "svn-remote.$x->{old_repo_id}";
6614 my $old_fetch = quotemeta("$x->{old_path}:".
6616 command_noisy
(qw
/config --unset/,
6617 "$pfx.fetch", '^'. $old_fetch . '$');
6618 delete $r->{$x->{old_repo_id
}}->
6619 {fetch
}->{$x->{old_path
}};
6620 if (!keys %{$r->{$x->{old_repo_id
}}->{fetch
}}) {
6621 command_noisy
(qw
/config --unset/,
6623 push @emptied, $x->{old_repo_id
}
6628 my $file = $ENV{GIT_CONFIG
} || "$ENV{GIT_DIR}/config";
6630 The following [svn-remote] sections in your config file ($file) are empty
6631 and can be safely removed:
6633 print STDERR
"[svn-remote \"$_\"]\n" foreach @emptied;
6637 sub migration_check
{
6641 minimize_connections
() if $_minimize;
6644 package Git
::IndexInfo
;
6647 use Git qw
/command_input_pipe command_close_pipe/;
6651 my ($gui, $ctx) = command_input_pipe
(qw
/update-index -z --index-info/);
6652 bless { gui
=> $gui, ctx
=> $ctx, nr
=> 0}, $class;
6656 my ($self, $path) = @_;
6657 if (print { $self->{gui
} } '0 ', 0 x
40, "\t", $path, "\0") {
6658 return ++$self->{nr
};
6664 my ($self, $mode, $hash, $path) = @_;
6665 if (print { $self->{gui
} } $mode, ' ', $hash, "\t", $path, "\0") {
6666 return ++$self->{nr
};
6673 command_close_pipe
($self->{gui
}, $self->{ctx
});
6676 package Git
::SVN
::GlobSpec
;
6681 my ($class, $glob, $pattern_ok) = @_;
6683 $re =~ s!/+$!!g; # no need for trailing slashes
6684 my (@left, @right, @patterns);
6686 my $die_msg = "Only one set of wildcard directories " .
6687 "(e.g. '*' or '*/*/*') is supported: '$glob'\n";
6688 for my $part (split(m
|/|, $glob)) {
6689 if ($part =~ /\*/ && $part ne "*") {
6690 die "Invalid pattern in '$glob': $part\n";
6691 } elsif ($pattern_ok && $part =~ /[{}]/ &&
6692 $part !~ /^\{[^{}]+\}/) {
6693 die "Invalid pattern in '$glob': $part\n";
6696 die $die_msg if $state eq "right";
6698 push(@patterns, "[^/]*");
6699 } elsif ($pattern_ok && $part =~ /^\{(.*)\}$/) {
6700 die $die_msg if $state eq "right";
6702 my $p = quotemeta($1);
6704 push(@patterns, "(?:$p)");
6706 if ($state eq "left") {
6709 push(@right, $part);
6714 my $depth = @patterns;
6716 die "One '*' is needed in glob: '$glob'\n";
6718 my $left = join('/', @left);
6719 my $right = join('/', @right);
6720 $re = join('/', @patterns);
6722 grep(length, quotemeta($left), "($re)", quotemeta($right)));
6723 my $left_re = qr/^\/\Q
$left\E
(\
/|$)/;
6724 bless { left
=> $left, right
=> $right, left_regex
=> $left_re,
6725 regex
=> qr/$re/, glob => $glob, depth
=> $depth }, $class;
6729 my ($self, $path) = @_;
6730 return (length $self->{left
} ?
"$self->{left}/" : '') .
6731 $path . (length $self->{right
} ?
"/$self->{right}" : '');
6739 $remotes = { # returned by read_all_remotes()
6741 # svn-remote.svn.url=https://svn.musicpd.org
6742 url
=> 'https://svn.musicpd.org',
6743 # svn-remote.svn.fetch=mpd/trunk:trunk
6745 'mpd/trunk' => 'trunk',
6747 # svn-remote.svn.tags=mpd/tags/*:tags/*
6752 regex
=> qr!mpd/tags/([^/]+)$!,
6758 regex
=> qr!tags/([^/]+)$!,
6765 $log_entry hashref as returned by libsvn_log_entry
()
6767 log => 'whitespace-formatted log entry
6768 ', # trailing newline is preserved
6769 revision
=> '8', # integer
6770 date
=> '2004-02-24T17:01:44.108345Z', # commit date
6771 author
=> 'committer name'
6775 # this is generated by generate_diff();
6776 @mods = array of diff
-index line hashes
, each element represents one line
6777 of diff
-index output
6779 diff
-index line
($m hash
)
6781 mode_a
=> first column of diff
-index output
, no leading
':',
6782 mode_b
=> second column of diff
-index output
,
6783 sha1_b
=> sha1sum of the final blob
,
6784 chg
=> change type
[MCRADT
],
6785 file_a
=> original file name of a file
(iff chg is
'C' or 'R')
6786 file_b
=> new
/current file name of a file
(any chg
)
6790 # retval of read_url_paths{,_all}();
6792 # repository root url
6793 'https://svn.musicpd.org' => {
6794 # repository path # GIT_SVN_ID
6795 'mpd/trunk' => 'trunk',
6796 'mpd/tags/0.11.5' => 'tags/0.11.5',
6801 I don
't trust the each() function on unless I created %hash myself
6802 because the internal iterator may not have started at base.