2 # Copyright (C) 2006, Eric Wong <normalperson@yhbt.net>
3 # License: GPL v2 or later
6 use vars qw
/ $AUTHOR $VERSION
7 $sha1 $sha1_short $_revision $_repository
9 $AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
10 $VERSION = '@@GIT_VERSION@@';
12 # From which subdir have we been invoked?
13 my $cmd_dir_prefix = eval {
14 command_oneline
([qw
/rev-parse --show-prefix/], STDERR
=> 0)
17 my $git_dir_user_set = 1 if defined $ENV{GIT_DIR
};
18 $ENV{GIT_DIR
} ||= '.git';
19 $Git::SVN
::default_repo_id
= 'svn';
20 $Git::SVN
::default_ref_id
= $ENV{GIT_SVN_ID
} || 'git-svn';
21 $Git::SVN
::Ra
::_log_window_size
= 100;
23 $Git::SVN
::Log
::TZ
= $ENV{TZ
};
25 $| = 1; # unbuffer STDOUT
27 sub fatal
(@
) { print STDERR
"@_\n"; exit 1 }
28 require SVN
::Core
; # use()-ing this causes segfaults for me... *shrug*
31 if ($SVN::Core
::VERSION
lt '1.1.0') {
32 fatal
"Need SVN::Core 1.1.0 or better (got $SVN::Core::VERSION)";
34 push @Git::SVN
::Ra
::ISA
, 'SVN::Ra';
35 push @SVN::Git
::Editor
::ISA
, 'SVN::Delta::Editor';
36 push @SVN::Git
::Fetcher
::ISA
, 'SVN::Delta::Editor';
40 use File
::Basename qw
/dirname basename/;
41 use File
::Path qw
/mkpath/;
42 use Getopt
::Long qw
/:config gnu_getopt no_ignore_case auto_abbrev/;
47 # import functions from Git into our packages, en masse
49 foreach (qw
/command command_oneline command_noisy command_output_pipe
50 command_input_pipe command_close_pipe
/) {
51 for my $package ( qw(SVN::Git::Editor SVN::Git::Fetcher
52 Git::SVN::Migration Git::SVN::Log Git::SVN),
54 *{"${package}::$_"} = \
&{"Git::$_"};
61 $sha1 = qr/[a-f\d]{40}/;
62 $sha1_short = qr/[a-f\d]{4,40}/;
63 my ($_stdin, $_help, $_edit,
66 $_version, $_fetch_all, $_no_rebase,
67 $_merge, $_strategy, $_dry_run, $_local,
68 $_prefix, $_no_checkout, $_url, $_verbose,
69 $_git_format, $_commit_url, $_tag);
70 $Git::SVN
::_follow_parent
= 1;
71 my %remote_opts = ( 'username=s' => \
$Git::SVN
::Prompt
::_username
,
72 'config-dir=s' => \
$Git::SVN
::Ra
::config_dir
,
73 'no-auth-cache' => \
$Git::SVN
::Prompt
::_no_auth_cache
);
74 my %fc_opts = ( 'follow-parent|follow!' => \
$Git::SVN
::_follow_parent
,
75 'authors-file|A=s' => \
$_authors,
76 'repack:i' => \
$Git::SVN
::_repack
,
77 'noMetadata' => \
$Git::SVN
::_no_metadata
,
78 'useSvmProps' => \
$Git::SVN
::_use_svm_props
,
79 'useSvnsyncProps' => \
$Git::SVN
::_use_svnsync_props
,
80 'log-window-size=i' => \
$Git::SVN
::Ra
::_log_window_size
,
81 'no-checkout' => \
$_no_checkout,
83 'repack-flags|repack-args|repack-opts=s' =>
84 \
$Git::SVN
::_repack_flags
,
85 'use-log-author' => \
$Git::SVN
::_use_log_author
,
86 'add-author-from' => \
$Git::SVN
::_add_author_from
,
89 my ($_trunk, $_tags, $_branches, $_stdlayout);
91 my %init_opts = ( 'template=s' => \
$_template, 'shared:s' => \
$_shared,
92 'trunk|T=s' => \
$_trunk, 'tags|t=s' => \
$_tags,
93 'branches|b=s' => \
$_branches, 'prefix=s' => \
$_prefix,
94 'stdlayout|s' => \
$_stdlayout,
95 'minimize-url|m' => \
$Git::SVN
::_minimize_url
,
96 'no-metadata' => sub { $icv{noMetadata
} = 1 },
97 'use-svm-props' => sub { $icv{useSvmProps
} = 1 },
98 'use-svnsync-props' => sub { $icv{useSvnsyncProps
} = 1 },
99 'rewrite-root=s' => sub { $icv{rewriteRoot
} = $_[1] },
101 my %cmt_opts = ( 'edit|e' => \
$_edit,
102 'rmdir' => \
$SVN::Git
::Editor
::_rmdir
,
103 'find-copies-harder' => \
$SVN::Git
::Editor
::_find_copies_harder
,
104 'l=i' => \
$SVN::Git
::Editor
::_rename_limit
,
105 'copy-similarity|C=i'=> \
$SVN::Git
::Editor
::_cp_similarity
109 fetch
=> [ \
&cmd_fetch
, "Download new revisions from SVN",
110 { 'revision|r=s' => \
$_revision,
111 'fetch-all|all' => \
$_fetch_all,
113 clone
=> [ \
&cmd_clone
, "Initialize and fetch revisions",
114 { 'revision|r=s' => \
$_revision,
115 %fc_opts, %init_opts } ],
116 init
=> [ \
&cmd_init
, "Initialize a repo for tracking" .
117 " (requires URL argument)",
119 'multi-init' => [ \
&cmd_multi_init
,
120 "Deprecated alias for ".
121 "'$0 init -T<trunk> -b<branches> -t<tags>'",
123 dcommit
=> [ \
&cmd_dcommit
,
124 'Commit several diffs to merge with upstream',
125 { 'merge|m|M' => \
$_merge,
126 'strategy|s=s' => \
$_strategy,
127 'verbose|v' => \
$_verbose,
128 'dry-run|n' => \
$_dry_run,
129 'fetch-all|all' => \
$_fetch_all,
130 'commit-url=s' => \
$_commit_url,
131 'revision|r=i' => \
$_revision,
132 'no-rebase' => \
$_no_rebase,
133 %cmt_opts, %fc_opts } ],
134 branch
=> [ \
&cmd_branch
,
135 'Create a branch in the SVN repository',
136 { 'message|m=s' => \
$_message,
137 'dry-run|n' => \
$_dry_run,
138 'tag|t' => \
$_tag } ],
139 tag
=> [ sub { $_tag = 1; cmd_branch
(@_) },
140 'Create a tag in the SVN repository',
141 { 'message|m=s' => \
$_message,
142 'dry-run|n' => \
$_dry_run } ],
143 'set-tree' => [ \
&cmd_set_tree
,
144 "Set an SVN repository to a git tree-ish",
145 { 'stdin|' => \
$_stdin, %cmt_opts, %fc_opts, } ],
146 'create-ignore' => [ \
&cmd_create_ignore
,
147 'Create a .gitignore per svn:ignore',
148 { 'revision|r=i' => \
$_revision
150 'propget' => [ \
&cmd_propget
,
151 'Print the value of a property on a file or directory',
152 { 'revision|r=i' => \
$_revision } ],
153 'proplist' => [ \
&cmd_proplist
,
154 'List all properties of a file or directory',
155 { 'revision|r=i' => \
$_revision } ],
156 'show-ignore' => [ \
&cmd_show_ignore
, "Show svn:ignore listings",
157 { 'revision|r=i' => \
$_revision
159 'show-externals' => [ \
&cmd_show_externals
, "Show svn:externals listings",
160 { 'revision|r=i' => \
$_revision
162 'multi-fetch' => [ \
&cmd_multi_fetch
,
163 "Deprecated alias for $0 fetch --all",
164 { 'revision|r=s' => \
$_revision, %fc_opts } ],
165 'migrate' => [ sub { },
166 # no-op, we automatically run this anyways,
167 'Migrate configuration/metadata/layout from
168 previous versions of git-svn',
169 { 'minimize' => \
$Git::SVN
::Migration
::_minimize
,
171 'log' => [ \
&Git
::SVN
::Log
::cmd_show_log
, 'Show commit logs',
172 { 'limit=i' => \
$Git::SVN
::Log
::limit
,
173 'revision|r=s' => \
$_revision,
174 'verbose|v' => \
$Git::SVN
::Log
::verbose
,
175 'incremental' => \
$Git::SVN
::Log
::incremental
,
176 'oneline' => \
$Git::SVN
::Log
::oneline
,
177 'show-commit' => \
$Git::SVN
::Log
::show_commit
,
178 'non-recursive' => \
$Git::SVN
::Log
::non_recursive
,
179 'authors-file|A=s' => \
$_authors,
180 'color' => \
$Git::SVN
::Log
::color
,
181 'pager=s' => \
$Git::SVN
::Log
::pager
183 'find-rev' => [ \
&cmd_find_rev
,
184 "Translate between SVN revision numbers and tree-ish",
186 'rebase' => [ \
&cmd_rebase
, "Fetch and rebase your working directory",
187 { 'merge|m|M' => \
$_merge,
188 'verbose|v' => \
$_verbose,
189 'strategy|s=s' => \
$_strategy,
190 'local|l' => \
$_local,
191 'fetch-all|all' => \
$_fetch_all,
192 'dry-run|n' => \
$_dry_run,
194 'commit-diff' => [ \
&cmd_commit_diff
,
195 'Commit a diff between two trees',
196 { 'message|m=s' => \
$_message,
197 'file|F=s' => \
$_file,
198 'revision|r=s' => \
$_revision,
200 'info' => [ \
&cmd_info
,
201 "Show info about the latest SVN revision
202 on the current branch",
203 { 'url' => \
$_url, } ],
204 'blame' => [ \
&Git
::SVN
::Log
::cmd_blame
,
205 "Show what revision and author last modified each line of a file",
206 { 'git-format' => \
$_git_format } ],
210 for (my $i = 0; $i < @ARGV; $i++) {
211 if (defined $cmd{$ARGV[$i]}) {
218 # make sure we're always running at the top-level working directory
219 unless ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) {
220 unless (-d
$ENV{GIT_DIR
}) {
221 if ($git_dir_user_set) {
222 die "GIT_DIR=$ENV{GIT_DIR} explicitly set, ",
223 "but it is not a directory\n";
225 my $git_dir = delete $ENV{GIT_DIR
};
228 $cdup = command_oneline
(qw
/rev-parse --show-cdup/);
229 $git_dir = '.' unless ($cdup);
230 chomp $cdup if ($cdup);
231 $cdup = "." unless ($cdup && length $cdup);
232 } "Already at toplevel, but $git_dir not found\n";
233 chdir $cdup or die "Unable to chdir up to '$cdup'\n";
234 unless (-d
$git_dir) {
235 die "$git_dir still not found after going to ",
238 $ENV{GIT_DIR
} = $git_dir;
240 $_repository = Git
->repository(Repository
=> $ENV{GIT_DIR
});
243 my %opts = %{$cmd{$cmd}->[2]} if (defined $cmd);
245 read_repo_config
(\
%opts);
246 if ($cmd && ($cmd eq 'log' || $cmd eq 'blame')) {
247 Getopt
::Long
::Configure
('pass_through');
249 my $rv = GetOptions
(%opts, 'help|H|h' => \
$_help, 'version|V' => \
$_version,
250 'minimize-connections' => \
$Git::SVN
::Migration
::_minimize
,
251 'id|i=s' => \
$Git::SVN
::default_ref_id
,
252 'svn-remote|remote|R=s' => sub {
253 $Git::SVN
::no_reuse_existing
= 1;
254 $Git::SVN
::default_repo_id
= $_[1] });
255 exit 1 if (!$rv && $cmd && $cmd ne 'log');
258 version
() if $_version;
259 usage
(1) unless defined $cmd;
260 load_authors
() if $_authors;
262 unless ($cmd =~ /^(?:clone|init|multi-init|commit-diff)$/) {
263 Git
::SVN
::Migration
::migration_check
();
265 Git
::SVN
::init_vars
();
267 Git
::SVN
::verify_remotes_sanity
();
268 $cmd{$cmd}->[0]->(@ARGV);
271 post_fetch_checkout
();
274 ####################### primary functions ######################
276 my $exit = shift || 0;
277 my $fd = $exit ? \
*STDERR
: \
*STDOUT
;
279 git
-svn
- bidirectional operations between a single Subversion tree
and git
280 Usage
: git svn
<command
> [options
] [arguments
]\n
282 print $fd "Available commands:\n" unless $cmd;
284 foreach (sort keys %cmd) {
285 next if $cmd && $cmd ne $_;
286 next if /^multi-/; # don't show deprecated commands
287 print $fd ' ',pack('A17',$_),$cmd{$_}->[1],"\n";
288 foreach (sort keys %{$cmd{$_}->[2]}) {
289 # mixed-case options are for .git/config only
290 next if /[A-Z]/ && /^[a-z]+$/i;
291 # prints out arguments as they should be passed:
292 my $x = s
#[:=]s$## ? '<arg>' : s#[:=]i$## ? '<num>' : '';
293 print $fd ' ' x
21, join(', ', map { length $_ > 1 ?
295 split /\|/,$_)," $x\n";
299 \nGIT_SVN_ID may be set
in the environment
or via the
--id
/-i switch to an
300 arbitrary identifier
if you
're tracking multiple SVN branches/repositories in
301 one git repository and want to keep them separate. See git-svn(1) for more
308 print "git-svn version $VERSION (svn $SVN::Core::VERSION)\n";
313 unless (-d $ENV{GIT_DIR}) {
314 my @init_db = ('init
');
315 push @init_db, "--template=$_template" if defined $_template;
316 if (defined $_shared) {
317 if ($_shared =~ /[a-z]/) {
318 push @init_db, "--shared=$_shared";
320 push @init_db, "--shared";
323 command_noisy(@init_db);
324 $_repository = Git->repository(Repository => ".git");
327 my $pfx = "svn-remote.$Git::SVN::default_repo_id";
328 foreach my $i (keys %icv) {
329 die "'$set' and '$i' cannot both be set\n" if $set;
330 next unless defined $icv{$i};
331 command_noisy('config
', "$pfx.$i", $icv{$i});
337 my $repo_path = shift or return;
338 mkpath([$repo_path]) unless -d $repo_path;
339 chdir $repo_path or die "Couldn't
chdir to
$repo_path: $!\n";
340 $ENV{GIT_DIR} = '.git';
341 $_repository = Git->repository(Repository => $ENV{GIT_DIR});
345 my ($url, $path) = @_;
346 if (!defined $path &&
347 (defined $_trunk || defined $_branches || defined $_tags ||
348 defined $_stdlayout) &&
349 $url !~ m#^[a-z\+]+://#) {
352 $path = basename($url) if !defined $path || !length $path;
353 cmd_init($url, $path);
354 Git::SVN::fetch_all($Git::SVN::default_repo_id);
358 if (defined $_stdlayout) {
359 $_trunk = 'trunk' if (!defined $_trunk);
360 $_tags = 'tags' if (!defined $_tags);
361 $_branches = 'branches' if (!defined $_branches);
363 if (defined $_trunk || defined $_branches || defined $_tags) {
364 return cmd_multi_init(@_);
366 my $url = shift or die "SVN repository location required
",
367 "as a command
-line argument
\n";
371 Git::SVN->init($url);
375 if (grep /^\d+=./, @_) {
376 die "'<rev>=<commit>' fetch arguments are
",
377 "no longer supported
.\n";
381 die "Usage
: $0 fetch
[--all
] [svn
-remote
]\n";
383 $remote ||= $Git::SVN::default_repo_id;
387 Git::SVN::fetch_all($remote, Git::SVN::read_all_remotes());
393 if ($_stdin || !@commits) {
394 print "Reading from stdin
...\n";
397 if (/\b($sha1_short)\b/o) {
398 unshift @commits, $1;
403 foreach my $c (@commits) {
404 my @tmp = command('rev-parse',$c);
405 if (scalar @tmp == 1) {
407 } elsif (scalar @tmp > 1) {
408 push @revs, reverse(command('rev-list',@tmp));
410 fatal "Failed to rev
-parse
$c";
413 my $gs = Git::SVN->new;
414 my ($r_last, $cmt_last) = $gs->last_rev_commit;
416 if (defined $gs->{last_rev} && $r_last != $gs->{last_rev}) {
417 fatal "There are new revisions that were fetched
",
418 "and need to be merged
(or acknowledged
) ",
419 "before committing
.\nlast rev
: $r_last\n",
420 " current
: $gs->{last_rev
}";
422 $gs->set_tree($_) foreach @revs;
423 print "Done committing
",scalar @revs," revisions to SVN
\n";
429 git_cmd_try { command_oneline(qw/diff-index --quiet HEAD/) }
430 'Cannot dcommit with a dirty index. Commit your changes first, '
431 . "or stash them with
`git stash'.\n";
434 my ($url, $rev, $uuid, $gs) = working_head_info($head, \@refs);
436 die "Unable to determine upstream SVN information from ",
437 "$head history.\nPerhaps the repository is empty.";
439 $url = defined $_commit_url ? $_commit_url : $gs->full_url;
440 my $last_rev = $_revision if defined $_revision;
442 print "Committing to $url ...\n";
444 my ($linear_refs, $parents) = linearize_history($gs, \@refs);
445 if ($_no_rebase && scalar(@$linear_refs) > 1) {
446 warn "Attempting to commit more than one change while ",
447 "--no-rebase is enabled.\n",
448 "If these changes depend on each other, re-running ",
449 "without --no-rebase may be required."
451 my $expect_url = $url;
452 Git::SVN::remove_username($expect_url);
454 my $d = shift @$linear_refs or last;
455 unless (defined $last_rev) {
456 (undef, $last_rev, undef) = cmt_metadata("$d~1");
457 unless (defined $last_rev) {
458 fatal "Unable to extract revision information ",
463 print "diff-tree $d~1 $d\n";
466 my %ed_opts = ( r => $last_rev,
467 log => get_commit_entry($d)->{log},
468 ra => Git::SVN::Ra->new($url),
469 config => SVN::Core::config_get_config(
470 $Git::SVN::Ra::config_dir
475 print "Committed r$_[0]\n";
479 if (!SVN::Git::Editor->new(\%ed_opts)->apply_diff) {
480 print "No changes\n$d~1 == $d\n";
481 } elsif ($parents->{$d} && @{$parents->{$d}}) {
482 $gs->{inject_parents_dcommit}->{$cmt_rev} =
485 $_fetch_all ? $gs->fetch_all : $gs->fetch;
486 $last_rev = $cmt_rev;
489 # we always want to rebase against the current HEAD,
490 # not any head that was passed to us
491 my @diff = command('diff-tree', $d,
495 @finish = rebase_cmd();
496 print STDERR "W: $d and ", $gs->refname,
497 " differ, using @finish:\n",
498 join("\n", @diff), "\n";
500 print "No changes between current HEAD and ",
502 "\nResetting to the latest ",
504 @finish = qw/reset --mixed/;
506 command_noisy(@finish, $gs->refname);
509 my ($url_, $rev_, $uuid_, $gs_) =
510 working_head_info($head, \@refs);
511 my ($linear_refs_, $parents_) =
512 linearize_history($gs_, \@refs);
513 if (scalar(@$linear_refs) !=
514 scalar(@$linear_refs_)) {
515 fatal "# of revisions changed ",
517 join("\n", @$linear_refs),
519 join("\n", @$linear_refs_), "\n",
520 'If you are attempting to commit ',
521 "merges, try running:\n\t",
522 'git rebase --interactive',
523 '--preserve-merges ',
525 "\nBefore dcommitting";
527 if ($url_ ne $expect_url) {
528 fatal "URL mismatch after rebase: ",
529 "$url_ != $expect_url";
531 if ($uuid_ ne $uuid) {
532 fatal "uuid mismatch after rebase: ",
537 for ($i = 0; $i < scalar @$linear_refs; $i++) {
538 my $new = $linear_refs_->[$i] or next;
540 $parents->{$linear_refs->[$i]};
552 my ($branch_name, $head) = @_;
554 unless (defined $branch_name && length $branch_name) {
555 die(($_tag ? "tag" : "branch") . " name required\n");
559 my ($src, $rev, undef, $gs) = working_head_info($head);
561 my $remote = Git::SVN::read_all_remotes()->{$gs->{repo_id}};
562 my $glob = $remote->{ $_tag ? 'tags' : 'branches' };
563 my ($lft, $rgt) = @{ $glob->{path} }{qw/left right/};
564 my $dst = join '/', $remote->{url}, $lft, $branch_name, ($rgt || ());
566 my $ctx = SVN::Client->new(
567 auth => Git::SVN::Ra::_auth_providers(),
569 ${ $_[0] } = defined $_message
571 : 'Create ' . ($_tag ? 'tag ' : 'branch ' )
577 $ctx->ls($dst, 'HEAD', 0);
578 } and die "branch ${branch_name} already exists\n";
580 print "Copying ${src} at r${rev} to ${dst}...\n";
581 $ctx->copy($src, $rev, $dst)
588 my $revision_or_hash = shift or die "SVN or git revision required ",
589 "as a command-line argument\n";
591 if ($revision_or_hash =~ /^r\d+$/) {
595 my (undef, undef, $uuid, $gs) = working_head_info($head, \@refs);
597 die "Unable to determine upstream SVN information from ",
600 my $desired_revision = substr($revision_or_hash, 1);
601 $result = $gs->rev_map_get($desired_revision, $uuid);
603 my (undef, $rev, undef) = cmt_metadata($revision_or_hash);
606 print "$result\n" if $result;
610 command_noisy(qw/update-index --refresh/);
611 my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
613 die "Unable to determine upstream SVN information from ",
614 "working tree history\n";
617 print "Remote Branch: " . $gs->refname . "\n";
618 print "SVN URL: " . $url . "\n";
621 if (command(qw/diff-index HEAD --/)) {
622 print STDERR "Cannot rebase with uncommited changes:\n";
623 command_noisy('status');
627 # rebase will checkout for us, so no need to do it explicitly
628 $_no_checkout = 'true';
629 $_fetch_all ? $gs->fetch_all : $gs->fetch;
631 command_noisy(rebase_cmd(), $gs->refname);
634 sub cmd_show_ignore {
635 my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
636 $gs ||= Git::SVN->new;
637 my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum);
638 $gs->prop_walk($gs->{path}, $r, sub {
639 my ($gs, $path, $props) = @_;
640 print STDOUT "\n# $path\n";
641 my $s = $props->{'svn:ignore'} or return;
642 $s =~ s/[\r\n]+/\n/g;
649 sub cmd_show_externals {
650 my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
651 $gs ||= Git::SVN->new;
652 my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum);
653 $gs->prop_walk($gs->{path}, $r, sub {
654 my ($gs, $path, $props) = @_;
655 print STDOUT "\n# $path\n";
656 my $s = $props->{'svn:externals'} or return;
657 $s =~ s/[\r\n]+/\n/g;
664 sub cmd_create_ignore {
665 my ($url, $rev, $uuid, $gs) = working_head_info('HEAD');
666 $gs ||= Git::SVN->new;
667 my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum);
668 $gs->prop_walk($gs->{path}, $r, sub {
669 my ($gs, $path, $props) = @_;
670 # $path is of the form /path/to/dir/
671 my $ignore = '.' . $path . '.gitignore';
672 my $s = $props->{'svn:ignore'} or return;
673 open(GITIGNORE, '>', $ignore)
674 or fatal("Failed to open `$ignore' for writing: $!");
675 $s =~ s/[\r\n]+/\n/g;
677 # Prefix all patterns so that the ignore doesn't apply
678 # to sub-directories.
680 print GITIGNORE
"$s\n";
682 or fatal
("Failed to close `$ignore': $!");
683 command_noisy
('add', '-f', $ignore);
687 sub canonicalize_path
{
689 my $dot_slash_added = 0;
690 if (substr($path, 0, 1) ne "/") {
691 $path = "./" . $path;
692 $dot_slash_added = 1;
694 # File::Spec->canonpath doesn't collapse x/../y into y (for a
695 # good reason), so let's do this manually.
697 $path =~ s
#/\.(?:/|$)#/#g;
698 $path =~ s
#/[^/]+/\.\.##g;
700 $path =~ s
#^\./## if $dot_slash_added;
708 # Helper for cmd_propget and cmd_proplist below.
711 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
712 $gs ||= Git
::SVN
->new;
714 # prefix THE PATH by the sub-directory from which the user
716 $path = $cmd_dir_prefix . $path;
717 fatal
("No such file or directory: $path") unless -e
$path;
718 my $is_dir = -d
$path ?
1 : 0;
719 $path = $gs->{path
} . '/' . $path;
721 # canonicalize the path (otherwise libsvn will abort or fail to
723 $path = canonicalize_path
($path);
725 my $r = (defined $_revision ?
$_revision : $gs->ra->get_latest_revnum);
728 (undef, undef, $props) = $gs->ra->get_dir($path, $r);
731 (undef, $props) = $gs->ra->get_file($path, $r, undef);
736 # cmd_propget (PROP, PATH)
737 # ------------------------
738 # Print the SVN property PROP for PATH.
740 my ($prop, $path) = @_;
741 $path = '.' if not defined $path;
742 usage
(1) if not defined $prop;
743 my $props = get_svnprops
($path);
744 if (not defined $props->{$prop}) {
745 fatal
("`$path' does not have a `$prop' SVN property.");
747 print $props->{$prop} . "\n";
750 # cmd_proplist (PATH)
751 # -------------------
752 # Print the list of SVN properties for PATH.
755 $path = '.' if not defined $path;
756 my $props = get_svnprops
($path);
757 print "Properties on '$path':\n";
758 foreach (sort keys %{$props}) {
765 unless (defined $_trunk || defined $_branches || defined $_tags) {
769 # there are currently some bugs that prevent multi-init/multi-fetch
770 # setups from working well without this.
771 $Git::SVN
::_minimize_url
= 1;
773 $_prefix = '' unless defined $_prefix;
779 if (defined $_trunk) {
780 my $trunk_ref = $_prefix . 'trunk';
781 # try both old-style and new-style lookups:
782 my $gs_trunk = eval { Git
::SVN
->new($trunk_ref) };
784 my ($trunk_url, $trunk_path) =
785 complete_svn_url
($url, $_trunk);
786 $gs_trunk = Git
::SVN
->init($trunk_url, $trunk_path,
790 return unless defined $_branches || defined $_tags;
791 my $ra = $url ? Git
::SVN
::Ra
->new($url) : undef;
792 complete_url_ls_init
($ra, $_branches, '--branches/-b', $_prefix);
793 complete_url_ls_init
($ra, $_tags, '--tags/-t', $_prefix . 'tags/');
796 sub cmd_multi_fetch
{
797 my $remotes = Git
::SVN
::read_all_remotes
();
798 foreach my $repo_id (sort keys %$remotes) {
799 if ($remotes->{$repo_id}->{url
}) {
800 Git
::SVN
::fetch_all
($repo_id, $remotes);
805 # this command is special because it requires no metadata
806 sub cmd_commit_diff
{
807 my ($ta, $tb, $url) = @_;
808 my $usage = "Usage: $0 commit-diff -r<revision> ".
809 "<tree-ish> <tree-ish> [<URL>]";
810 fatal
($usage) if (!defined $ta || !defined $tb);
813 my $gs = eval { Git
::SVN
->new };
815 fatal
("Needed URL or usable git-svn --id in ",
816 "the command-line\n", $usage);
819 $svn_path = $gs->{path
};
821 unless (defined $_revision) {
822 fatal
("-r|--revision is a required argument\n", $usage);
824 if (defined $_message && defined $_file) {
825 fatal
("Both --message/-m and --file/-F specified ",
826 "for the commit message.\n",
827 "I have no idea what you mean");
829 if (defined $_file) {
830 $_message = file_to_s
($_file);
832 $_message ||= get_commit_entry
($tb)->{log};
834 my $ra ||= Git
::SVN
::Ra
->new($url);
837 $r = $ra->get_latest_revnum;
838 } elsif ($r !~ /^\d+$/) {
839 die "revision argument: $r not understood by git-svn\n";
841 my %ed_opts = ( r
=> $r,
846 editor_cb
=> sub { print "Committed r$_[0]\n" },
847 svn_path
=> $svn_path );
848 if (!SVN
::Git
::Editor
->new(\
%ed_opts)->apply_diff) {
849 print "No changes\n$ta == $tb\n";
853 sub escape_uri_only
{
856 foreach (split m{/}, $uri) {
857 s/([^~\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg;
865 if ($url =~ m
#^([^:]+)://([^/]*)(.*)$#) {
866 my ($scheme, $domain, $uri) = ($1, $2, escape_uri_only
($3));
867 $url = "$scheme://$domain$uri";
873 my $path = canonicalize_path
(defined($_[0]) ?
$_[0] : ".");
874 my $fullpath = canonicalize_path
($cmd_dir_prefix . $path);
876 die "Too many arguments specified\n";
879 my ($file_type, $diff_status) = find_file_type_and_diff_status
($path);
881 if (!$file_type && !$diff_status) {
882 print STDERR
"svn: '$path' is not under version control\n";
886 my ($url, $rev, $uuid, $gs) = working_head_info
('HEAD');
888 die "Unable to determine upstream SVN information from ",
889 "working tree history\n";
892 # canonicalize_path() will return "" to make libsvn 1.5.x happy,
893 $path = "." if $path eq "";
895 my $full_url = $url . ($fullpath eq "" ?
"" : "/$fullpath");
898 print escape_url
($full_url), "\n";
902 my $result = "Path: $path\n";
903 $result .= "Name: " . basename
($path) . "\n" if $file_type ne "dir";
904 $result .= "URL: " . escape_url
($full_url) . "\n";
907 my $repos_root = $gs->repos_root;
908 Git
::SVN
::remove_username
($repos_root);
909 $result .= "Repository Root: " . escape_url
($repos_root) . "\n";
912 $result .= "Repository Root: (offline)\n";
914 $result .= "Repository UUID: $uuid\n" unless $diff_status eq "A";
915 $result .= "Revision: " . ($diff_status eq "A" ?
0 : $rev) . "\n";
917 $result .= "Node Kind: " .
918 ($file_type eq "dir" ?
"directory" : "file") . "\n";
920 my $schedule = $diff_status eq "A"
922 : ($diff_status eq "D" ?
"delete" : "normal");
923 $result .= "Schedule: $schedule\n";
925 if ($diff_status eq "A") {
930 my ($lc_author, $lc_rev, $lc_date_utc);
931 my @args = Git
::SVN
::Log
::git_svn_log_cmd
($rev, $rev, "--", $fullpath);
932 my $log = command_output_pipe
(@args);
933 my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
935 if (/^${esc_color}author (.+) <[^>]+> (\d+) ([\-\+]?\d+)$/o) {
937 $lc_date_utc = Git
::SVN
::Log
::parse_git_date
($2, $3);
938 } elsif (/^${esc_color} (git-svn-id:.+)$/o) {
939 (undef, $lc_rev, undef) = ::extract_metadata
($1);
944 Git
::SVN
::Log
::set_local_timezone
();
946 $result .= "Last Changed Author: $lc_author\n";
947 $result .= "Last Changed Rev: $lc_rev\n";
948 $result .= "Last Changed Date: " .
949 Git
::SVN
::Log
::format_svn_date
($lc_date_utc) . "\n";
951 if ($file_type ne "dir") {
952 my $text_last_updated_date =
953 ($diff_status eq "D" ?
$lc_date_utc : (stat $path)[9]);
955 "Text Last Updated: " .
956 Git
::SVN
::Log
::format_svn_date
($text_last_updated_date) .
959 if ($diff_status eq "D") {
961 command_output_pipe
(qw(cat-file blob), "HEAD:$path");
962 if ($file_type eq "link") {
963 my $file_name = <$fh>;
964 $checksum = md5sum
("link $file_name");
966 $checksum = md5sum
($fh);
968 command_close_pipe
($fh, $ctx);
969 } elsif ($file_type eq "link") {
971 command
(qw(cat-file blob), "HEAD:$path");
973 md5sum
("link " . $file_name);
975 open FILE
, "<", $path or die $!;
976 $checksum = md5sum
(\
*FILE
);
977 close FILE
or die $!;
979 $result .= "Checksum: " . $checksum . "\n";
985 ########################### utility functions #########################
988 my @cmd = qw
/rebase/;
989 push @cmd, '-v' if $_verbose;
990 push @cmd, qw
/--merge/ if $_merge;
991 push @cmd, "--strategy=$_strategy" if $_strategy;
995 sub post_fetch_checkout
{
996 return if $_no_checkout;
997 my $gs = $Git::SVN
::_head
or return;
998 return if verify_ref
('refs/heads/master^0');
1000 my $valid_head = verify_ref
('HEAD^0');
1001 command_noisy
(qw(update-ref refs/heads/master), $gs->refname);
1002 return if ($valid_head || !verify_ref
('HEAD^0'));
1004 return if $ENV{GIT_DIR
} !~ m
#^(?:.*/)?\.git$#;
1005 my $index = $ENV{GIT_INDEX_FILE
} || "$ENV{GIT_DIR}/index";
1006 return if -f
$index;
1008 return if command_oneline
(qw
/rev-parse --is-inside-work-tree/) eq 'false';
1009 return if command_oneline
(qw
/rev-parse --is-inside-git-dir/) eq 'true';
1010 command_noisy
(qw
/read-tree -m -u -v HEAD HEAD/);
1011 print STDERR
"Checked out HEAD:\n ",
1012 $gs->full_url, " r", $gs->last_rev, "\n";
1015 sub complete_svn_url
{
1016 my ($url, $path) = @_;
1018 if ($path !~ m
#^[a-z\+]+://#) {
1019 if (!defined $url || $url !~ m
#^[a-z\+]+://#) {
1020 fatal
("E: '$path' is not a complete URL ",
1021 "and a separate URL is not specified");
1023 return ($url, $path);
1028 sub complete_url_ls_init
{
1029 my ($ra, $repo_path, $switch, $pfx) = @_;
1030 unless ($repo_path) {
1031 print STDERR
"W: $switch not specified\n";
1034 $repo_path =~ s
#/+$##;
1035 if ($repo_path =~ m
#^[a-z\+]+://#) {
1036 $ra = Git
::SVN
::Ra
->new($repo_path);
1039 $repo_path =~ s
#^/+##;
1041 fatal
("E: '$repo_path' is not a complete URL ",
1042 "and a separate URL is not specified");
1045 my $url = $ra->{url
};
1046 my $gs = Git
::SVN
->init($url, undef, undef, undef, 1);
1047 my $k = "svn-remote.$gs->{repo_id}.url";
1048 my $orig_url = eval { command_oneline
(qw
/config --get/, $k) };
1049 if ($orig_url && ($orig_url ne $gs->{url
})) {
1050 die "$k already set: $orig_url\n",
1051 "wanted to set to: $gs->{url}\n";
1053 command_oneline
('config', $k, $gs->{url
}) unless $orig_url;
1054 my $remote_path = "$ra->{svn_path}/$repo_path";
1055 $remote_path =~ s
#/+#/#g;
1056 $remote_path =~ s
#^/##g;
1057 $remote_path .= "/*" if $remote_path !~ /\
*/;
1058 my ($n) = ($switch =~ /^--(\w+)/);
1059 if (length $pfx && $pfx !~ m
#/$#) {
1060 die "--prefix='$pfx' must have a trailing slash '/'\n";
1062 command_noisy
('config',
1063 "svn-remote.$gs->{repo_id}.$n",
1064 "$remote_path:refs/remotes/$pfx*" .
1065 ('/*' x
(($remote_path =~ tr
/*/*/) - 1)) );
1070 eval { command_oneline
([ 'rev-parse', '--verify', $ref ],
1071 { STDERR
=> 0 }); };
1074 sub get_tree_from_treeish
{
1076 # $treeish can be a symbolic ref, too:
1077 my $type = command_oneline
(qw
/cat-file -t/, $treeish);
1079 while ($type eq 'tag') {
1080 ($treeish, $type) = command
(qw
/cat-file tag/, $treeish);
1082 if ($type eq 'commit') {
1083 $expected = (grep /^tree /, command
(qw
/cat-file commit/,
1085 ($expected) = ($expected =~ /^tree ($sha1)$/o);
1086 die "Unable to get tree from $treeish\n" unless $expected;
1087 } elsif ($type eq 'tree') {
1088 $expected = $treeish;
1090 die "$treeish is a $type, expected tree, tag or commit\n";
1095 sub get_commit_entry
{
1096 my ($treeish) = shift;
1097 my %log_entry = ( log => '', tree
=> get_tree_from_treeish
($treeish) );
1098 my $commit_editmsg = "$ENV{GIT_DIR}/COMMIT_EDITMSG";
1099 my $commit_msg = "$ENV{GIT_DIR}/COMMIT_MSG";
1100 open my $log_fh, '>', $commit_editmsg or croak
$!;
1102 my $type = command_oneline
(qw
/cat-file -t/, $treeish);
1103 if ($type eq 'commit' || $type eq 'tag') {
1104 my ($msg_fh, $ctx) = command_output_pipe
('cat-file',
1112 $in_msg = 1 if (/^\s*$/);
1113 $author = $1 if (/^author (.*>)/);
1114 } elsif (/^git-svn-id: /) {
1115 # skip this for now, we regenerate the
1116 # correct one on re-fetch anyways
1117 # TODO: set *:merge properties or like...
1119 if (/^From:/ || /^Signed-off-by:/) {
1125 $msgbuf =~ s/\s+$//s;
1126 if ($Git::SVN
::_add_author_from
&& defined($author)
1128 $msgbuf .= "\n\nFrom: $author";
1130 print $log_fh $msgbuf or croak
$!;
1131 command_close_pipe
($msg_fh, $ctx);
1133 close $log_fh or croak
$!;
1135 if ($_edit || ($type eq 'tree')) {
1136 my $editor = $ENV{VISUAL
} || $ENV{EDITOR
} || 'vi';
1137 # TODO: strip out spaces, comments, like git-commit.sh
1138 system($editor, $commit_editmsg);
1140 rename $commit_editmsg, $commit_msg or croak
$!;
1142 # SVN requires messages to be UTF-8 when entering the repo
1144 open $log_fh, '<', $commit_msg or croak
$!;
1146 chomp($log_entry{log} = <$log_fh>);
1148 if (my $enc = Git
::config
('i18n.commitencoding')) {
1150 Encode
::from_to
($log_entry{log}, $enc, 'UTF-8');
1152 close $log_fh or croak
$!;
1159 my ($str, $file, $mode) = @_;
1160 open my $fd,'>',$file or croak
$!;
1161 print $fd $str,"\n" or croak
$!;
1162 close $fd or croak
$!;
1163 chmod ($mode &~ umask, $file) if (defined $mode);
1168 open my $fd,'<',$file or croak
"$!: file: $file\n";
1171 close $fd or croak
$!;
1176 # '<svn username> = real-name <email address>' mapping based on git-svnimport:
1178 open my $authors, '<', $_authors or die "Can't open $_authors $!\n";
1179 my $log = $cmd eq 'log';
1180 while (<$authors>) {
1182 next unless /^(.+?|\(no author\))\s*=\s*(.+?)\s*<(.+)>\s*$/;
1183 my ($user, $name, $email) = ($1, $2, $3);
1185 $Git::SVN
::Log
::rusers
{"$name <$email>"} = $user;
1187 $users{$user} = [$name, $email];
1190 close $authors or croak
$!;
1193 # convert GetOpt::Long specs for use by git-config
1194 sub read_repo_config
{
1195 return unless -d
$ENV{GIT_DIR
};
1198 foreach my $o (keys %$opts) {
1199 # if we have mixedCase and a long option-only, then
1200 # it's a config-only variable that we don't need for
1202 push @config_only, $o if ($o =~ /[A-Z]/ && $o =~ /^[a-z]+$/i);
1203 my $v = $opts->{$o};
1204 my ($key) = ($o =~ /^([a-zA-Z\-]+)/);
1206 my $arg = 'git config';
1207 $arg .= ' --int' if ($o =~ /[:=]i$/);
1208 $arg .= ' --bool' if ($o !~ /[:=][sfi]$/);
1209 if (ref $v eq 'ARRAY') {
1210 chomp(my @tmp = `$arg --get-all svn.$key`);
1213 chomp(my $tmp = `$arg --get svn.$key`);
1214 if ($tmp && !($arg =~ / --bool/ && $tmp eq 'false')) {
1219 delete @
$opts{@config_only} if @config_only;
1222 sub extract_metadata
{
1223 my $id = shift or return (undef, undef, undef);
1224 my ($url, $rev, $uuid) = ($id =~ /^\s
*git
-svn
-id
:\s
+(.*)\@
(\d
+)
1226 if (!defined $rev || !$uuid || !$url) {
1227 # some of the original repositories I made had
1228 # identifiers like this:
1229 ($rev, $uuid) = ($id =~/^\s*git-svn-id:\s(\d+)\@([a-f\d\-]+)/);
1231 return ($url, $rev, $uuid);
1235 return extract_metadata
((grep(/^git-svn-id: /,
1236 command
(qw
/cat-file commit/, shift)))[-1]);
1239 sub working_head_info
{
1240 my ($head, $refs) = @_;
1241 my @args = ('log', '--no-color', '--first-parent', '--pretty=medium');
1242 my ($fh, $ctx) = command_output_pipe
(@args, $head);
1246 if ( m{^commit ($::sha1)$} ) {
1247 unshift @
$refs, $hash if $hash and $refs;
1251 next unless s{^\s*(git-svn-id:)}{$1};
1252 my ($url, $rev, $uuid) = extract_metadata
($_);
1253 if (defined $url && defined $rev) {
1254 next if $max{$url} and $max{$url} < $rev;
1255 if (my $gs = Git
::SVN
->find_by_url($url)) {
1256 my $c = $gs->rev_map_get($rev, $uuid);
1257 if ($c && $c eq $hash) {
1258 close $fh; # break the pipe
1259 return ($url, $rev, $uuid, $gs);
1261 $max{$url} ||= $gs->rev_map_max;
1266 command_close_pipe
($fh, $ctx);
1267 (undef, undef, undef, undef);
1270 sub read_commit_parents
{
1271 my ($parents, $c) = @_;
1272 chomp(my $p = command_oneline
(qw
/rev-list --parents -1/, $c));
1273 $p =~ s/^($c)\s*// or die "rev-list --parents -1 $c failed!\n";
1274 @
{$parents->{$c}} = split(/ /, $p);
1277 sub linearize_history
{
1278 my ($gs, $refs) = @_;
1280 foreach my $c (@
$refs) {
1281 read_commit_parents
(\
%parents, $c);
1286 my $last_svn_commit = $gs->last_commit;
1287 foreach my $c (reverse @
$refs) {
1288 next if $c eq $last_svn_commit;
1291 unshift @linear_refs, $c;
1294 # we only want the first parent to diff against for linear
1295 # history, we save the rest to inject when we finalize the
1297 my $fp_a = verify_ref
("$c~1");
1298 my $fp_b = shift @
{$parents{$c}} if $parents{$c};
1299 if (!$fp_a || !$fp_b) {
1301 "has no parent commit, and therefore ",
1302 "nothing to diff against.\n",
1303 "You should be working from a repository ",
1304 "originally created by git-svn\n";
1306 if ($fp_a ne $fp_b) {
1307 die "$c~1 = $fp_a, however parsing commit $c ",
1308 "revealed that:\n$c~1 = $fp_b\nBUG!\n";
1311 foreach my $p (@
{$parents{$c}}) {
1315 (\
@linear_refs, \
%parents);
1318 sub find_file_type_and_diff_status
{
1320 return ('dir', '') if $path eq '';
1323 command_oneline
(qw(diff --cached --name-status --), $path) || "";
1324 my $diff_status = (split(' ', $diff_output))[0] || "";
1326 my $ls_tree = command_oneline
(qw(ls-tree HEAD), $path) || "";
1328 return (undef, undef) if !$diff_status && !$ls_tree;
1330 if ($diff_status eq "A") {
1331 return ("link", $diff_status) if -l
$path;
1332 return ("dir", $diff_status) if -d
$path;
1333 return ("file", $diff_status);
1336 my $mode = (split(' ', $ls_tree))[0] || "";
1338 return ("link", $diff_status) if $mode eq "120000";
1339 return ("dir", $diff_status) if $mode eq "040000";
1340 return ("file", $diff_status);
1346 my $md5 = Digest
::MD5
->new();
1347 if ($ref eq 'GLOB' || $ref eq 'IO::File' || $ref eq 'File::Temp') {
1348 $md5->addfile($arg) or croak
$!;
1349 } elsif ($ref eq 'SCALAR') {
1350 $md5->add($$arg) or croak
$!;
1352 $md5->add($arg) or croak
$!;
1354 ::fatal
"Can't provide MD5 hash for unknown ref type: '", $ref, "'";
1356 return $md5->hexdigest();
1362 use Fcntl qw
/:DEFAULT :seek/;
1363 use constant rev_map_fmt
=> 'NH40';
1364 use vars qw
/$default_repo_id $default_ref_id $_no_metadata $_follow_parent
1365 $_repack $_repack_flags $_use_svm_props $_head
1366 $_use_svnsync_props $no_reuse_existing $_minimize_url
1367 $_use_log_author $_add_author_from/;
1369 use File
::Path qw
/mkpath/;
1370 use File
::Copy qw
/copy/;
1373 my ($_gc_nr, $_gc_period);
1375 # properties that we do not log:
1378 %SKIP_PROP = map { $_ => 1 } qw
/svn
:wc
:ra_dav
:version
-url
1379 svn
:special svn
:executable
1380 svn
:entry
:committed
-rev
1381 svn
:entry
:last-author
1383 svn
:entry
:committed
-date
/;
1385 # some options are read globally, but can be overridden locally
1386 # per [svn-remote "..."] section. Command-line options will *NOT*
1387 # override options set in an [svn-remote "..."] section
1389 for my $option (qw
/follow_parent no_metadata use_svm_props
1390 use_svnsync_props
/) {
1393 my $prop = "-$option";
1396 return $self->{$prop} if exists $self->{$prop};
1397 my $k = "svn-remote.$self->{repo_id}.$key";
1398 eval { command_oneline
(qw
/config --get/, $k) };
1400 $self->{$prop} = ${"Git::SVN::_$option"};
1402 my $v = command_oneline
(qw
/config --bool/,$k);
1403 $self->{$prop} = $v eq 'false' ?
0 : 1;
1405 return $self->{$prop};
1411 my (%LOCKFILES, %INDEX_FILES);
1413 unlink keys %LOCKFILES if %LOCKFILES;
1414 unlink keys %INDEX_FILES if %INDEX_FILES;
1417 sub resolve_local_globs
{
1418 my ($url, $fetch, $glob_spec) = @_;
1419 return unless defined $glob_spec;
1420 my $ref = $glob_spec->{ref};
1421 my $path = $glob_spec->{path
};
1422 foreach (command
(qw
#for-each-ref --format=%(refname) refs/remotes#)) {
1423 next unless m
#^refs/remotes/$ref->{regex}$#;
1425 my $pathname = desanitize_refname
($path->full_path($p));
1426 my $refname = desanitize_refname
($ref->full_path($p));
1427 if (my $existing = $fetch->{$pathname}) {
1428 if ($existing ne $refname) {
1429 die "Refspec conflict:\n",
1430 "existing: refs/remotes/$existing\n",
1431 " globbed: refs/remotes/$refname\n";
1433 my $u = (::cmt_metadata
("refs/remotes/$refname"))[0];
1434 $u =~ s!^\Q$url\E(/|$)!! or die
1435 "refs/remotes/$refname: '$url' not found in '$u'\n";
1436 if ($pathname ne $u) {
1437 warn "W: Refspec glob conflict ",
1438 "(ref: refs/remotes/$refname):\n",
1439 "expected path: $pathname\n",
1441 "Continuing ahead with $u\n";
1445 $fetch->{$pathname} = $refname;
1450 sub parse_revision_argument
{
1451 my ($base, $head) = @_;
1452 if (!defined $::_revision
|| $::_revision
eq 'BASE:HEAD') {
1453 return ($base, $head);
1455 return ($1, $2) if ($::_revision
=~ /^(\d+):(\d+)$/);
1456 return ($::_revision
, $::_revision
) if ($::_revision
=~ /^\d+$/);
1457 return ($head, $head) if ($::_revision
eq 'HEAD');
1458 return ($base, $1) if ($::_revision
=~ /^BASE:(\d+)$/);
1459 return ($1, $head) if ($::_revision
=~ /^(\d+):HEAD$/);
1460 die "revision argument: $::_revision not understood by git-svn\n";
1464 my ($repo_id, $remotes) = @_;
1468 $repo_id = $gs->{repo_id
};
1470 $remotes ||= read_all_remotes
();
1471 my $remote = $remotes->{$repo_id} or
1472 die "[svn-remote \"$repo_id\"] unknown\n";
1473 my $fetch = $remote->{fetch
};
1474 my $url = $remote->{url
} or die "svn-remote.$repo_id.url not defined\n";
1476 my $ra = Git
::SVN
::Ra
->new($url);
1477 my $uuid = $ra->get_uuid;
1478 my $head = $ra->get_latest_revnum;
1479 my $base = defined $fetch ?
$head : 0;
1481 # read the max revs for wildcard expansion (branches/*, tags/*)
1482 foreach my $t (qw
/branches tags/) {
1483 defined $remote->{$t} or next;
1484 push @globs, $remote->{$t};
1485 my $max_rev = eval { tmp_config
(qw
/--int --get/,
1486 "svn-remote.$repo_id.${t}-maxRev") };
1487 if (defined $max_rev && ($max_rev < $base)) {
1489 } elsif (!defined $max_rev) {
1495 foreach my $p (sort keys %$fetch) {
1496 my $gs = Git
::SVN
->new($fetch->{$p}, $repo_id, $p);
1497 my $lr = $gs->rev_map_max;
1499 $base = $lr if ($lr < $base);
1505 ($base, $head) = parse_revision_argument
($base, $head);
1506 $ra->gs_fetch_loop_common($base, $head, \
@gs, \
@globs);
1509 sub read_all_remotes
{
1511 my $use_svm_props = eval { command_oneline
(qw
/config
--bool
1512 svn
.useSvmProps
/) };
1513 $use_svm_props = $use_svm_props eq 'true' if $use_svm_props;
1514 foreach (grep { s/^svn-remote\.// } command
(qw
/config -l/)) {
1515 if (m!^(.+)\.fetch=\s*(.*)\s*:\s*(.+)\s*$!) {
1516 my ($remote, $local_ref, $_remote_ref) = ($1, $2, $3);
1517 die("svn-remote.$remote: remote ref '$_remote_ref' "
1518 . "must start with 'refs/remotes/'\n")
1519 unless $_remote_ref =~ m{^refs/remotes/(.+)};
1520 my $remote_ref = $1;
1521 $local_ref =~ s{^/}{};
1522 $r->{$remote}->{fetch
}->{$local_ref} = $remote_ref;
1523 $r->{$remote}->{svm
} = {} if $use_svm_props;
1524 } elsif (m!^(.+)\.usesvmprops=\s*(.*)\s*$!) {
1525 $r->{$1}->{svm
} = {};
1526 } elsif (m!^(.+)\.url=\s*(.*)\s*$!) {
1527 $r->{$1}->{url
} = $2;
1528 } elsif (m
!^(.+)\
.(branches
|tags
)=
1529 (.*):refs
/remotes
/(.+)\s
*$/!x
) {
1530 my ($p, $g) = ($3, $4);
1531 my $rs = $r->{$1}->{$2} = {
1534 path
=> Git
::SVN
::GlobSpec
->new($p),
1535 ref => Git
::SVN
::GlobSpec
->new($g) };
1536 if (length($rs->{ref}->{right
}) != 0) {
1537 die "The '*' glob character must be the last ",
1538 "character of '$g'\n";
1544 if (defined $r->{$_}->{svm
}) {
1547 my $section = "svn-remote.$_";
1549 source
=> tmp_config
('--get',
1550 "$section.svm-source"),
1551 replace
=> tmp_config
('--get',
1552 "$section.svm-replace"),
1555 $r->{$_}->{svm
} = $svm;
1563 $_gc_nr = $_gc_period = 1000;
1564 if (defined $_repack || defined $_repack_flags) {
1565 warn "Repack options are obsolete; they have no effect.\n";
1569 sub verify_remotes_sanity
{
1570 return unless -d
$ENV{GIT_DIR
};
1572 foreach (command
(qw
/config -l/)) {
1573 if (m!^svn-remote\.(?:.+)\.fetch=.*:refs/remotes/(\S+)\s*$!) {
1575 die "Remote ref refs/remote/$1 is tracked by",
1576 "\n \"$_\"\nand\n \"$seen{$1}\"\n",
1577 "Please resolve this ambiguity in ",
1578 "your git configuration file before ",
1586 sub find_existing_remote
{
1587 my ($url, $remotes) = @_;
1588 return undef if $no_reuse_existing;
1590 foreach my $repo_id (keys %$remotes) {
1591 my $u = $remotes->{$repo_id}->{url
} or next;
1593 $existing = $repo_id;
1599 sub init_remote_config
{
1600 my ($self, $url, $no_write) = @_;
1601 $url =~ s!/+$!!; # strip trailing slash
1602 my $r = read_all_remotes
();
1603 my $existing = find_existing_remote
($url, $r);
1605 unless ($no_write) {
1606 print STDERR
"Using existing ",
1607 "[svn-remote \"$existing\"]\n";
1609 $self->{repo_id
} = $existing;
1610 } elsif ($_minimize_url) {
1611 my $min_url = Git
::SVN
::Ra
->new($url)->minimize_url;
1612 $existing = find_existing_remote
($min_url, $r);
1614 unless ($no_write) {
1615 print STDERR
"Using existing ",
1616 "[svn-remote \"$existing\"]\n";
1618 $self->{repo_id
} = $existing;
1620 if ($min_url ne $url) {
1621 unless ($no_write) {
1622 print STDERR
"Using higher level of URL: ",
1623 "$url => $min_url\n";
1625 my $old_path = $self->{path
};
1626 $self->{path
} = $url;
1627 $self->{path
} =~ s!^\Q$min_url\E(/|$)!!;
1628 if (length $old_path) {
1629 $self->{path
} .= "/$old_path";
1636 # verify that we aren't overwriting anything:
1638 command_oneline
('config', '--get',
1639 "svn-remote.$self->{repo_id}.url")
1641 if ($orig_url && ($orig_url ne $url)) {
1642 die "svn-remote.$self->{repo_id}.url already set: ",
1643 "$orig_url\nwanted to set to: $url\n";
1646 my ($xrepo_id, $xpath) = find_ref
($self->refname);
1647 if (defined $xpath) {
1648 die "svn-remote.$xrepo_id.fetch already set to track ",
1649 "$xpath:refs/remotes/", $self->refname, "\n";
1651 unless ($no_write) {
1652 command_noisy
('config',
1653 "svn-remote.$self->{repo_id}.url", $url);
1654 $self->{path
} =~ s{^/}{};
1655 command_noisy
('config', '--add',
1656 "svn-remote.$self->{repo_id}.fetch",
1657 "$self->{path}:".$self->refname);
1659 $self->{url
} = $url;
1662 sub find_by_url
{ # repos_root and, path are optional
1663 my ($class, $full_url, $repos_root, $path) = @_;
1665 return undef unless defined $full_url;
1666 remove_username
($full_url);
1667 remove_username
($repos_root) if defined $repos_root;
1668 my $remotes = read_all_remotes
();
1669 if (defined $full_url && defined $repos_root && !defined $path) {
1671 $path =~ s
#^\Q$repos_root\E(?:/|$)##;
1673 foreach my $repo_id (keys %$remotes) {
1674 my $u = $remotes->{$repo_id}->{url
} or next;
1675 remove_username
($u);
1676 next if defined $repos_root && $repos_root ne $u;
1678 my $fetch = $remotes->{$repo_id}->{fetch
} || {};
1679 foreach (qw
/branches tags/) {
1680 resolve_local_globs
($u, $fetch,
1681 $remotes->{$repo_id}->{$_});
1684 my $rwr = rewrite_root
({repo_id
=> $repo_id});
1685 my $svm = $remotes->{$repo_id}->{svm
}
1686 if defined $remotes->{$repo_id}->{svm
};
1687 unless (defined $p) {
1693 } elsif (defined $svm) {
1694 $z = $svm->{source
};
1695 $prefix = $svm->{replace
};
1696 $prefix =~ s
#^\Q$u\E(?:/|$)##;
1699 $p =~ s
#^\Q$z\E(?:/|$)#$prefix# or next;
1701 foreach my $f (keys %$fetch) {
1703 return Git
::SVN
->new($fetch->{$f}, $repo_id, $f);
1710 my ($class, $url, $path, $repo_id, $ref_id, $no_write) = @_;
1711 my $self = _new
($class, $repo_id, $ref_id, $path);
1713 $self->init_remote_config($url, $no_write);
1720 foreach (command
(qw
/config -l/)) {
1721 next unless m
!^svn
-remote\
.(.+)\
.fetch
=
1722 \s
*(.*)\s
*:\s
*refs
/remotes/(.+)\s
*$!x
;
1723 my ($repo_id, $path, $ref) = ($1, $2, $3);
1724 if ($ref eq $ref_id) {
1725 $path = '' if ($path =~ m
#^\./?#);
1726 return ($repo_id, $path);
1729 (undef, undef, undef);
1733 my ($class, $ref_id, $repo_id, $path) = @_;
1734 if (defined $ref_id && !defined $repo_id && !defined $path) {
1735 ($repo_id, $path) = find_ref
($ref_id);
1736 if (!defined $repo_id) {
1737 die "Could not find a \"svn-remote.*.fetch\" key ",
1738 "in the repository configuration matching: ",
1739 "refs/remotes/$ref_id\n";
1742 my $self = _new
($class, $repo_id, $ref_id, $path);
1743 if (!defined $self->{path
} || !length $self->{path
}) {
1744 my $fetch = command_oneline
('config', '--get',
1745 "svn-remote.$repo_id.fetch",
1746 ":refs/remotes/$ref_id\$") or
1747 die "Failed to read \"svn-remote.$repo_id.fetch\" ",
1748 "\":refs/remotes/$ref_id\$\" in config\n";
1749 ($self->{path
}, undef) = split(/\s*:\s*/, $fetch);
1751 $self->{url
} = command_oneline
('config', '--get',
1752 "svn-remote.$repo_id.url") or
1753 die "Failed to read \"svn-remote.$repo_id.url\" in config\n";
1759 my ($refname) = "refs/remotes/$_[0]->{ref_id}" ;
1761 # It cannot end with a slash /, we'll throw up on this because
1762 # SVN can't have directories with a slash in their name, either:
1763 if ($refname =~ m{/$}) {
1764 die "ref: '$refname' ends with a trailing slash, this is ",
1765 "not permitted by git nor Subversion\n";
1768 # It cannot have ASCII control character space, tilde ~, caret ^,
1769 # colon :, question-mark ?, asterisk *, space, or open bracket [
1772 # Additionally, % must be escaped because it is used for escaping
1773 # and we want our escaped refname to be reversible
1774 $refname =~ s{([ \%~\^:\?\*\[\t])}{uc sprintf('%%%02x',ord($1))}eg;
1776 # no slash-separated component can begin with a dot .
1778 $refname =~ s{/\.}{/%2E}g;
1780 # It cannot have two consecutive dots .. anywhere
1782 $refname =~ s{\.\.}{%2E%2E}g;
1787 sub desanitize_refname
{
1789 $refname =~ s{%(?:([0-9A-F]{2}))}{chr hex($1)}eg;
1795 return $self->{svm
}->{uuid
} if $self->svm;
1797 unless ($self->{svm
}) {
1798 die "SVM UUID not cached, and reading remotely failed\n";
1800 $self->{svm
}->{uuid
};
1805 return $self->{svm
} if $self->{svm
};
1807 # see if we have it in our config, first:
1809 my $section = "svn-remote.$self->{repo_id}";
1811 source
=> tmp_config
('--get', "$section.svm-source"),
1812 uuid
=> tmp_config
('--get', "$section.svm-uuid"),
1813 replace
=> tmp_config
('--get', "$section.svm-replace"),
1816 if ($svm && $svm->{source
} && $svm->{uuid
} && $svm->{replace
}) {
1817 $self->{svm
} = $svm;
1823 my ($self, $ra) = @_;
1824 return $ra if $self->svm;
1826 my @err = ( "useSvmProps set, but failed to read SVM properties\n",
1827 "(svm:source, svm:uuid) ",
1828 "from the following URLs:\n" );
1829 sub read_svm_props
{
1830 my ($self, $ra, $path, $r) = @_;
1831 my $props = ($ra->get_dir($path, $r))[2];
1832 my $src = $props->{'svm:source'};
1833 my $uuid = $props->{'svm:uuid'};
1834 return undef if (!$src || !$uuid);
1838 $uuid =~ m{^[0-9a-f\-]{30,}$}
1839 or die "doesn't look right - svm:uuid is '$uuid'\n";
1841 # the '!' is used to mark the repos_root!/relative/path
1842 $src =~ s{/?!/?}{/};
1843 $src =~ s{/+$}{}; # no trailing slashes please
1844 # username is of no interest
1845 $src =~ s{(^[a-z\+]*://)[^/@]*@}{$1};
1847 my $replace = $ra->{url
};
1848 $replace .= "/$path" if length $path;
1850 my $section = "svn-remote.$self->{repo_id}";
1851 tmp_config
("$section.svm-source", $src);
1852 tmp_config
("$section.svm-replace", $replace);
1853 tmp_config
("$section.svm-uuid", $uuid);
1861 my $r = $ra->get_latest_revnum;
1862 my $path = $self->{path
};
1864 while (length $path) {
1865 unless ($tried{"$self->{url}/$path"}) {
1866 return $ra if $self->read_svm_props($ra, $path, $r);
1867 $tried{"$self->{url}/$path"} = 1;
1869 $path =~ s
#/?[^/]+$##;
1871 die "Path: '$path' should be ''\n" if $path ne '';
1872 return $ra if $self->read_svm_props($ra, $path, $r);
1873 $tried{"$self->{url}/$path"} = 1;
1875 if ($ra->{repos_root
} eq $self->{url
}) {
1876 die @err, (map { " $_\n" } keys %tried), "\n";
1879 # nope, make sure we're connected to the repository root:
1882 $path = $ra->{svn_path
};
1883 $ra = Git
::SVN
::Ra
->new($ra->{repos_root
});
1884 while (length $path) {
1885 unless ($tried{"$ra->{url}/$path"}) {
1886 $ok = $self->read_svm_props($ra, $path, $r);
1888 $tried{"$ra->{url}/$path"} = 1;
1890 $path =~ s
#/?[^/]+$##;
1892 die "Path: '$path' should be ''\n" if $path ne '';
1893 $ok ||= $self->read_svm_props($ra, $path, $r);
1894 $tried{"$ra->{url}/$path"} = 1;
1896 die @err, (map { " $_\n" } keys %tried), "\n";
1898 Git
::SVN
::Ra
->new($self->{url
});
1903 return $self->{svnsync
} if $self->{svnsync
};
1905 if ($self->no_metadata) {
1906 die "Can't have both 'noMetadata' and ",
1907 "'useSvnsyncProps' options set!\n";
1909 if ($self->rewrite_root) {
1910 die "Can't have both 'useSvnsyncProps' and 'rewriteRoot' ",
1915 # see if we have it in our config, first:
1917 my $section = "svn-remote.$self->{repo_id}";
1919 my $url = tmp_config
('--get', "$section.svnsync-url");
1920 ($url) = ($url =~ m{^([a-z\+]+://\S+)$}) or
1921 die "doesn't look right - svn:sync-from-url is '$url'\n";
1923 my $uuid = tmp_config
('--get', "$section.svnsync-uuid");
1924 ($uuid) = ($uuid =~ m{^([0-9a-f\-]{30,})$}) or
1925 die "doesn't look right - svn:sync-from-uuid is '$uuid'\n";
1927 $svnsync = { url
=> $url, uuid
=> $uuid }
1929 if ($svnsync && $svnsync->{url
} && $svnsync->{uuid
}) {
1930 return $self->{svnsync
} = $svnsync;
1933 my $err = "useSvnsyncProps set, but failed to read " .
1934 "svnsync property: svn:sync-from-";
1935 my $rp = $self->ra->rev_proplist(0);
1937 my $url = $rp->{'svn:sync-from-url'} or die $err . "url\n";
1938 ($url) = ($url =~ m{^([a-z\+]+://\S+)$}) or
1939 die "doesn't look right - svn:sync-from-url is '$url'\n";
1941 my $uuid = $rp->{'svn:sync-from-uuid'} or die $err . "uuid\n";
1942 ($uuid) = ($uuid =~ m{^([0-9a-f\-]{30,})$}) or
1943 die "doesn't look right - svn:sync-from-uuid is '$uuid'\n";
1945 my $section = "svn-remote.$self->{repo_id}";
1946 tmp_config
('--add', "$section.svnsync-uuid", $uuid);
1947 tmp_config
('--add', "$section.svnsync-url", $url);
1948 return $self->{svnsync
} = { url
=> $url, uuid
=> $uuid };
1951 # this allows us to memoize our SVN::Ra UUID locally and avoid a
1952 # remote lookup (useful for 'git svn log').
1955 unless ($self->{ra_uuid
}) {
1956 my $key = "svn-remote.$self->{repo_id}.uuid";
1957 my $uuid = eval { tmp_config
('--get', $key) };
1958 if (!$@
&& $uuid && $uuid =~ /^([a-f\d\-]{30,})$/) {
1959 $self->{ra_uuid
} = $uuid;
1961 die "ra_uuid called without URL\n" unless $self->{url
};
1962 $self->{ra_uuid
} = $self->ra->get_uuid;
1963 tmp_config
('--add', $key, $self->{ra_uuid
});
1969 sub _set_repos_root
{
1970 my ($self, $repos_root) = @_;
1971 my $k = "svn-remote.$self->{repo_id}.reposRoot";
1972 $repos_root ||= $self->ra->{repos_root
};
1973 tmp_config
($k, $repos_root);
1979 my $k = "svn-remote.$self->{repo_id}.reposRoot";
1980 eval { tmp_config
('--get', $k) } || $self->_set_repos_root;
1985 my $ra = Git
::SVN
::Ra
->new($self->{url
});
1986 $self->_set_repos_root($ra->{repos_root
});
1987 if ($self->use_svm_props && !$self->{svm
}) {
1988 if ($self->no_metadata) {
1989 die "Can't have both 'noMetadata' and ",
1990 "'useSvmProps' options set!\n";
1991 } elsif ($self->use_svnsync_props) {
1992 die "Can't have both 'useSvnsyncProps' and ",
1993 "'useSvmProps' options set!\n";
1995 $ra = $self->_set_svm_vars($ra);
1996 $self->{-want_revprops
} = 1;
2003 my $repos_root = $self->ra->{repos_root
};
2004 return $self->{path
} if ($self->{url
} eq $repos_root);
2005 my $url = $self->{url
} .
2006 (length $self->{path
} ?
"/$self->{path}" : $self->{path
});
2007 $url =~ s!^\Q$repos_root\E(?:/+|$)!!g;
2011 # prop_walk(PATH, REV, SUB)
2012 # -------------------------
2013 # Recursively traverse PATH at revision REV and invoke SUB for each
2014 # directory that contains a SVN property. SUB will be invoked as
2015 # follows: &SUB(gs, path, props); where `gs' is this instance of
2016 # Git::SVN, `path' the path to the directory where the properties
2017 # `props' were found. The `path' will be relative to point of checkout,
2018 # that is, if url://repo/trunk is the current Git branch, and that
2019 # directory contains a sub-directory `d', SUB will be invoked with `/d/'
2020 # as `path' (note the trailing `/').
2022 my ($self, $path, $rev, $sub) = @_;
2025 my ($dirent, undef, $props) = $self->ra->get_dir($path, $rev);
2028 # Strip the irrelevant part of the path.
2029 $p =~ s
#^/+\Q$self->{path}\E(/|$)#/#;
2030 # Ensure the path is terminated by a `/'.
2033 # The properties contain all the internal SVN stuff nobody
2034 # (usually) cares about.
2035 my $interesting_props = 0;
2036 foreach (keys %{$props}) {
2037 # If it doesn't start with `svn:', it must be a
2038 # user-defined property.
2039 ++$interesting_props and next if $_ !~ /^svn:/;
2040 # FIXME: Fragile, if SVN adds new public properties,
2041 # this needs to be updated.
2042 ++$interesting_props if /^svn
:(?
:ignore
|keywords
|executable
2043 |eol
-style
|mime
-type
2044 |externals
|needs
-lock)$/x
;
2046 &$sub($self, $p, $props) if $interesting_props;
2048 foreach (sort keys %$dirent) {
2049 next if $dirent->{$_}->{kind
} != $SVN::Node
::dir
;
2050 $self->prop_walk($self->{path
} . $p . $_, $rev, $sub);
2054 sub last_rev
{ ($_[0]->last_rev_commit)[0] }
2055 sub last_commit
{ ($_[0]->last_rev_commit)[1] }
2057 # returns the newest SVN revision number and newest commit SHA1
2058 sub last_rev_commit
{
2060 if (defined $self->{last_rev
} && defined $self->{last_commit
}) {
2061 return ($self->{last_rev
}, $self->{last_commit
});
2063 my $c = ::verify_ref
($self->refname.'^0');
2064 if ($c && !$self->use_svm_props && !$self->no_metadata) {
2065 my $rev = (::cmt_metadata
($c))[1];
2067 ($self->{last_rev
}, $self->{last_commit
}) = ($rev, $c);
2071 my $map_path = $self->map_path;
2072 unless (-e
$map_path) {
2073 ($self->{last_rev
}, $self->{last_commit
}) = (undef, undef);
2074 return (undef, undef);
2076 my ($rev, $commit) = $self->rev_map_max(1);
2077 ($self->{last_rev
}, $self->{last_commit
}) = ($rev, $commit);
2078 return ($rev, $commit);
2081 sub get_fetch_range
{
2082 my ($self, $min, $max) = @_;
2083 $max ||= $self->ra->get_latest_revnum;
2084 $min ||= $self->rev_map_max;
2090 my $old_def_config = "$ENV{GIT_DIR}/svn/config";
2091 my $config = "$ENV{GIT_DIR}/svn/.metadata";
2092 if (! -f
$config && -f
$old_def_config) {
2093 rename $old_def_config, $config or
2094 die "Failed rename $old_def_config => $config: $!\n";
2096 my $old_config = $ENV{GIT_CONFIG
};
2097 $ENV{GIT_CONFIG
} = $config;
2100 unless (-f
$config) {
2102 open my $fh, '>', $config or
2103 die "Can't open $config: $!\n";
2104 print $fh "; This file is used internally by ",
2106 "Couldn't write to $config: $!\n";
2107 print $fh "; You should not have to edit it\n" or
2108 die "Couldn't write to $config: $!\n";
2109 close $fh or die "Couldn't close $config: $!\n";
2111 command
('config', @args);
2114 if (defined $old_config) {
2115 $ENV{GIT_CONFIG
} = $old_config;
2117 delete $ENV{GIT_CONFIG
};
2120 wantarray ?
@ret : $ret[0];
2124 my ($self, $sub) = @_;
2125 my $old_index = $ENV{GIT_INDEX_FILE
};
2126 $ENV{GIT_INDEX_FILE
} = $self->{index};
2129 my ($dir, $base) = ($self->{index} =~ m
#^(.*?)/?([^/]+)$#);
2130 mkpath
([$dir]) unless -d
$dir;
2134 if (defined $old_index) {
2135 $ENV{GIT_INDEX_FILE
} = $old_index;
2137 delete $ENV{GIT_INDEX_FILE
};
2140 wantarray ?
@ret : $ret[0];
2143 sub assert_index_clean
{
2144 my ($self, $treeish) = @_;
2146 $self->tmp_index_do(sub {
2147 command_noisy
('read-tree', $treeish) unless -e
$self->{index};
2148 my $x = command_oneline
('write-tree');
2149 my ($y) = (command
(qw
/cat-file commit/, $treeish) =~
2150 /^tree ($::sha1)/mo);
2153 warn "Index mismatch: $y != $x\nrereading $treeish\n";
2154 unlink $self->{index} or die "unlink $self->{index}: $!\n";
2155 command_noisy
('read-tree', $treeish);
2156 $x = command_oneline
('write-tree');
2158 ::fatal
"trees ($treeish) $y != $x\n",
2159 "Something is seriously wrong...";
2164 sub get_commit_parents
{
2165 my ($self, $log_entry) = @_;
2166 my (%seen, @ret, @tmp);
2167 # legacy support for 'set-tree'; this is only used by set_tree_cb:
2168 if (my $ip = $self->{inject_parents
}) {
2169 if (my $commit = delete $ip->{$log_entry->{revision
}}) {
2173 if (my $cur = ::verify_ref
($self->refname.'^0')) {
2176 if (my $ipd = $self->{inject_parents_dcommit
}) {
2177 if (my $commit = delete $ipd->{$log_entry->{revision
}}) {
2178 push @tmp, @
$commit;
2181 push @tmp, $_ foreach (@
{$log_entry->{parents
}}, @tmp);
2182 while (my $p = shift @tmp) {
2186 # MAXPARENT is defined to 16 in commit-tree.c:
2190 die "r$log_entry->{revision}: No room for parents:\n\t",
2191 join("\n\t", @tmp), "\n";
2198 return $self->{-rewrite_root
} if exists $self->{-rewrite_root
};
2199 my $k = "svn-remote.$self->{repo_id}.rewriteRoot";
2200 my $rwr = eval { command_oneline
(qw
/config --get/, $k) };
2203 if ($rwr !~ m
#^[a-z\+]+://#) {
2204 die "$rwr is not a valid URL (key: $k)\n";
2207 $self->{-rewrite_root
} = $rwr;
2212 ($self->rewrite_root || $self->{url
}) .
2213 (length $self->{path
} ?
'/' . $self->{path
} : '');
2218 $self->{url
} . (length $self->{path
} ?
'/' . $self->{path
} : '');
2222 sub set_commit_header_env
{
2223 my ($log_entry) = @_;
2225 foreach my $ned (qw
/NAME EMAIL DATE/) {
2226 foreach my $ac (qw
/AUTHOR COMMITTER/) {
2227 $env{"GIT_${ac}_${ned}"} = $ENV{"GIT_${ac}_${ned}"};
2231 $ENV{GIT_AUTHOR_NAME
} = $log_entry->{name
};
2232 $ENV{GIT_AUTHOR_EMAIL
} = $log_entry->{email
};
2233 $ENV{GIT_AUTHOR_DATE
} = $ENV{GIT_COMMITTER_DATE
} = $log_entry->{date
};
2235 $ENV{GIT_COMMITTER_NAME
} = (defined $log_entry->{commit_name
})
2236 ?
$log_entry->{commit_name
}
2237 : $log_entry->{name
};
2238 $ENV{GIT_COMMITTER_EMAIL
} = (defined $log_entry->{commit_email
})
2239 ?
$log_entry->{commit_email
}
2240 : $log_entry->{email
};
2244 sub restore_commit_header_env
{
2246 foreach my $ned (qw
/NAME EMAIL DATE/) {
2247 foreach my $ac (qw
/AUTHOR COMMITTER/) {
2248 my $k = "GIT_${ac}_${ned}";
2249 if (defined $env->{$k}) {
2250 $ENV{$k} = $env->{$k};
2259 command_noisy
('gc', '--auto');
2263 my ($self, $log_entry) = @_;
2264 my $lr = $self->last_rev;
2265 if (defined $lr && $lr >= $log_entry->{revision
}) {
2266 die "Last fetched revision of ", $self->refname,
2267 " was r$lr, but we are about to fetch: ",
2268 "r$log_entry->{revision}!\n";
2270 if (my $c = $self->rev_map_get($log_entry->{revision
})) {
2271 croak
"$log_entry->{revision} = $c already exists! ",
2272 "Why are we refetching it?\n";
2274 my $old_env = set_commit_header_env
($log_entry);
2275 my $tree = $log_entry->{tree
};
2276 if (!defined $tree) {
2277 $tree = $self->tmp_index_do(sub {
2278 command_oneline
('write-tree') });
2280 die "Tree is not a valid sha1: $tree\n" if $tree !~ /^$::sha1$/o;
2282 my @exec = ('git', 'commit-tree', $tree);
2283 foreach ($self->get_commit_parents($log_entry)) {
2284 push @exec, '-p', $_;
2286 defined(my $pid = open3
(my $msg_fh, my $out_fh, '>&STDERR', @exec))
2290 # we always get UTF-8 from SVN, but we may want our commits in
2291 # a different encoding.
2292 if (my $enc = Git
::config
('i18n.commitencoding')) {
2294 Encode
::from_to
($log_entry->{log}, 'UTF-8', $enc);
2296 print $msg_fh $log_entry->{log} or croak
$!;
2297 restore_commit_header_env
($old_env);
2298 unless ($self->no_metadata) {
2299 print $msg_fh "\ngit-svn-id: $log_entry->{metadata}\n"
2302 $msg_fh->flush == 0 or croak
$!;
2303 close $msg_fh or croak
$!;
2304 chomp(my $commit = do { local $/; <$out_fh> });
2305 close $out_fh or croak
$!;
2308 if ($commit !~ /^$::sha1$/o) {
2309 die "Failed to commit, invalid sha1: $commit\n";
2312 $self->rev_map_set($log_entry->{revision
}, $commit, 1);
2314 $self->{last_rev
} = $log_entry->{revision
};
2315 $self->{last_commit
} = $commit;
2316 print "r$log_entry->{revision}";
2317 if (defined $log_entry->{svm_revision
}) {
2318 print " (\@$log_entry->{svm_revision})";
2319 $self->rev_map_set($log_entry->{svm_revision
}, $commit,
2320 0, $self->svm_uuid);
2322 print " = $commit ($self->{ref_id})\n";
2323 if (--$_gc_nr == 0) {
2324 $_gc_nr = $_gc_period;
2331 my ($self, $paths, $r) = @_;
2332 return 1 if $self->{path
} eq '';
2333 if (my $path = $paths->{"/$self->{path}"}) {
2334 return ($path->{action
} eq 'D') ?
0 : 1;
2336 $self->{path_regex
} ||= qr/^\/\Q
$self->{path
}\E\
//;
2337 if (grep /$self->{path_regex}/, keys %$paths) {
2341 foreach (split m
#/#, $self->{path}) {
2343 next unless ($paths->{$c} &&
2344 ($paths->{$c}->{action
} =~ /^[AR]$/));
2345 if ($self->ra->check_path($self->{path
}, $r) ==
2353 sub find_parent_branch
{
2354 my ($self, $paths, $rev) = @_;
2355 return undef unless $self->follow_parent;
2356 unless (defined $paths) {
2357 my $err_handler = $SVN::Error
::handler
;
2358 $SVN::Error
::handler
= \
&Git
::SVN
::Ra
::skip_unknown_revs
;
2359 $self->ra->get_log([$self->{path
}], $rev, $rev, 0, 1, 1, sub {
2361 Git
::SVN
::Ra
::dup_changed_paths
($_[0]) });
2362 $SVN::Error
::handler
= $err_handler;
2364 return undef unless defined $paths;
2366 # look for a parent from another branch:
2367 my @b_path_components = split m
#/#, $self->rel_path;
2368 my @a_path_components;
2370 while (@b_path_components) {
2371 $i = $paths->{'/'.join('/', @b_path_components)};
2372 last if $i && defined $i->{copyfrom_path
};
2373 unshift(@a_path_components, pop(@b_path_components));
2375 return undef unless defined $i && defined $i->{copyfrom_path
};
2376 my $branch_from = $i->{copyfrom_path
};
2377 if (@a_path_components) {
2378 print STDERR
"branch_from: $branch_from => ";
2379 $branch_from .= '/'.join('/', @a_path_components);
2380 print STDERR
$branch_from, "\n";
2382 my $r = $i->{copyfrom_rev
};
2383 my $repos_root = $self->ra->{repos_root
};
2384 my $url = $self->ra->{url
};
2385 my $new_url = $repos_root . $branch_from;
2386 print STDERR
"Found possible branch point: ",
2387 "$new_url => ", $self->full_url, ", $r\n";
2388 $branch_from =~ s
#^/##;
2389 my $gs = Git
::SVN
->find_by_url($new_url, $repos_root, $branch_from);
2391 my $ref_id = $self->{ref_id
};
2392 $ref_id =~ s/\@\d+$//;
2394 # just grow a tail if we're not unique enough :x
2395 $ref_id .= '-' while find_ref
($ref_id);
2396 print STDERR
"Initializing parent: $ref_id\n";
2397 my ($u, $p, $repo_id) = ($new_url, '', $ref_id);
2398 if ($u =~ s
#^\Q$url\E(/|$)##) {
2401 $repo_id = $self->{repo_id
};
2403 $gs = Git
::SVN
->init($u, $p, $repo_id, $ref_id, 1);
2405 my ($r0, $parent) = $gs->find_rev_before($r, 1);
2406 if (!defined $r0 || !defined $parent) {
2407 my ($base, $head) = parse_revision_argument
(0, $r);
2409 $gs->fetch($base, $r);
2411 ($r0, $parent) = $gs->last_rev_commit;
2413 if (defined $r0 && defined $parent) {
2414 print STDERR
"Found branch parent: ($self->{ref_id}) $parent\n";
2416 if ($self->ra->can_do_switch) {
2417 $self->assert_index_clean($parent);
2418 print STDERR
"Following parent with do_switch\n";
2419 # do_switch works with svn/trunk >= r22312, but that
2420 # is not included with SVN 1.4.3 (the latest version
2421 # at the moment), so we can't rely on it
2422 $self->{last_commit
} = $parent;
2423 $ed = SVN
::Git
::Fetcher
->new($self);
2424 $gs->ra->gs_do_switch($r0, $rev, $gs,
2425 $self->full_url, $ed)
2426 or die "SVN connection failed somewhere...\n";
2427 } elsif ($self->ra->trees_match($new_url, $r0,
2428 $self->full_url, $rev)) {
2429 print STDERR
"Trees match:\n",
2431 " ${\$self->full_url}\@$rev\n",
2432 "Following parent with no changes\n";
2433 $self->tmp_index_do(sub {
2434 command_noisy
('read-tree', $parent);
2436 $self->{last_commit
} = $parent;
2438 print STDERR
"Following parent with do_update\n";
2439 $ed = SVN
::Git
::Fetcher
->new($self);
2440 $self->ra->gs_do_update($rev, $rev, $self, $ed)
2441 or die "SVN connection failed somewhere...\n";
2443 print STDERR
"Successfully followed parent\n";
2444 return $self->make_log_entry($rev, [$parent], $ed);
2450 my ($self, $paths, $rev) = @_;
2452 my ($last_rev, @parents);
2453 if (my $lc = $self->last_commit) {
2454 # we can have a branch that was deleted, then re-added
2455 # under the same name but copied from another path, in
2456 # which case we'll have multiple parents (we don't
2457 # want to break the original ref, nor lose copypath info):
2458 if (my $log_entry = $self->find_parent_branch($paths, $rev)) {
2459 push @
{$log_entry->{parents
}}, $lc;
2462 $ed = SVN
::Git
::Fetcher
->new($self);
2463 $last_rev = $self->{last_rev
};
2468 if (my $log_entry = $self->find_parent_branch($paths, $rev)) {
2471 $ed = SVN
::Git
::Fetcher
->new($self);
2473 unless ($self->ra->gs_do_update($last_rev, $rev, $self, $ed)) {
2474 die "SVN connection failed somewhere...\n";
2476 $self->make_log_entry($rev, \
@parents, $ed);
2480 my ($self, $ed) = @_;
2482 my $h = $ed->{empty
};
2483 foreach (sort keys %$h) {
2484 my $act = $h->{$_} ?
'+empty_dir' : '-empty_dir';
2485 push @out, " $act: " . uri_encode
($_);
2486 warn "W: $act: $_\n";
2488 foreach my $t (qw
/dir_prop file_prop/) {
2489 $h = $ed->{$t} or next;
2490 foreach my $path (sort keys %$h) {
2491 my $ppath = $path eq '' ?
'.' : $path;
2492 foreach my $prop (sort keys %{$h->{$path}}) {
2493 next if $SKIP_PROP{$prop};
2494 my $v = $h->{$path}->{$prop};
2495 my $t_ppath_prop = "$t: " .
2496 uri_encode
($ppath) . ' ' .
2499 push @out, " +$t_ppath_prop " .
2502 push @out, " -$t_ppath_prop";
2507 foreach my $t (qw
/absent_file absent_directory/) {
2508 $h = $ed->{$t} or next;
2509 foreach my $parent (sort keys %$h) {
2510 foreach my $path (sort @
{$h->{$parent}}) {
2511 push @out, " $t: " .
2512 uri_encode
("$parent/$path");
2513 warn "W: $t: $parent/$path ",
2514 "Insufficient permissions?\n";
2521 sub parse_svn_date
{
2522 my $date = shift || return '+0000 1970-01-01 00:00:00';
2523 my ($Y,$m,$d,$H,$M,$S) = ($date =~ /^(\d
{4})\
-(\d\d
)\
-(\d\d
)T
2524 (\d\d
)\
:(\d\d
)\
:(\d\d
).\d
+Z
$/x
) or
2525 croak
"Unable to parse date: $date\n";
2526 "+0000 $Y-$m-$d $H:$M:$S";
2531 if (!defined $author || length $author == 0) {
2532 $author = '(no author)';
2533 } elsif (defined $::_authors
&& ! defined $::users
{$author}) {
2534 die "Author: $author not defined in $::_authors file\n";
2539 sub make_log_entry
{
2540 my ($self, $rev, $parents, $ed) = @_;
2541 my $untracked = $self->get_untracked($ed);
2543 open my $un, '>>', "$self->{dir}/unhandled.log" or croak
$!;
2544 print $un "r$rev\n" or croak
$!;
2545 print $un $_, "\n" foreach @
$untracked;
2546 my %log_entry = ( parents
=> $parents || [], revision
=> $rev,
2550 my $logged = delete $self->{logged_rev_props
};
2551 if (!$logged || $self->{-want_revprops
}) {
2552 my $rp = $self->ra->rev_proplist($rev);
2553 foreach (sort keys %$rp) {
2555 if (/^svn:(author|date|log)$/) {
2556 $log_entry{$1} = $v;
2557 } elsif ($_ eq 'svm:headrev') {
2560 print $un " rev_prop: ", uri_encode
($_), ' ',
2561 uri_encode
($v), "\n";
2565 map { $log_entry{$_} = $logged->{$_} } keys %$logged;
2567 close $un or croak
$!;
2569 $log_entry{date
} = parse_svn_date
($log_entry{date
});
2570 $log_entry{log} .= "\n";
2571 my $author = $log_entry{author
} = check_author
($log_entry{author
});
2572 my ($name, $email) = defined $::users
{$author} ? @
{$::users
{$author}}
2575 my ($commit_name, $commit_email) = ($name, $email);
2576 if ($_use_log_author) {
2578 if ($log_entry{log} =~ /From:\s+(.*\S)\s*\n/i) {
2580 } elsif ($log_entry{log} =~ /Signed-off-by:\s+(.*\S)\s*\n/i) {
2583 if (!defined $name_field) {
2584 if (!defined $email) {
2587 } elsif ($name_field =~ /(.*?)\s+<(.*)>/) {
2588 ($name, $email) = ($1, $2);
2589 } elsif ($name_field =~ /(.*)@/) {
2590 ($name, $email) = ($1, $name_field);
2592 ($name, $email) = ($name_field, $name_field);
2595 if (defined $headrev && $self->use_svm_props) {
2596 if ($self->rewrite_root) {
2597 die "Can't have both 'useSvmProps' and 'rewriteRoot' ",
2600 my ($uuid, $r) = $headrev =~ m{^([a-f\d\-]{30,}):(\d
+)$};
2601 # we don't want "SVM: initializing mirror for junk" ...
2602 return undef if $r == 0;
2603 my $svm = $self->svm;
2604 if ($uuid ne $svm->{uuid
}) {
2605 die "UUID mismatch on SVM path:\n",
2606 "expected: $svm->{uuid}\n",
2609 my $full_url = $self->full_url;
2610 $full_url =~ s
#^\Q$svm->{replace}\E(/|$)#$svm->{source}$1# or
2611 die "Failed to replace '$svm->{replace}' with ",
2612 "'$svm->{source}' in $full_url\n";
2613 # throw away username for storing in records
2614 remove_username
($full_url);
2615 $log_entry{metadata
} = "$full_url\@$r $uuid";
2616 $log_entry{svm_revision
} = $r;
2617 $email ||= "$author\@$uuid";
2618 $commit_email ||= "$author\@$uuid";
2619 } elsif ($self->use_svnsync_props) {
2620 my $full_url = $self->svnsync->{url
};
2621 $full_url .= "/$self->{path}" if length $self->{path
};
2622 remove_username
($full_url);
2623 my $uuid = $self->svnsync->{uuid
};
2624 $log_entry{metadata
} = "$full_url\@$rev $uuid";
2625 $email ||= "$author\@$uuid";
2626 $commit_email ||= "$author\@$uuid";
2628 my $url = $self->metadata_url;
2629 remove_username
($url);
2630 $log_entry{metadata
} = "$url\@$rev " .
2631 $self->ra->get_uuid;
2632 $email ||= "$author\@" . $self->ra->get_uuid;
2633 $commit_email ||= "$author\@" . $self->ra->get_uuid;
2635 $log_entry{name
} = $name;
2636 $log_entry{email
} = $email;
2637 $log_entry{commit_name
} = $commit_name;
2638 $log_entry{commit_email
} = $commit_email;
2643 my ($self, $min_rev, $max_rev, @parents) = @_;
2644 my ($last_rev, $last_commit) = $self->last_rev_commit;
2645 my ($base, $head) = $self->get_fetch_range($min_rev, $max_rev);
2646 $self->ra->gs_fetch_loop_common($base, $head, [$self]);
2650 my ($self, $log_entry, $tree, $rev, $date, $author) = @_;
2651 $self->{inject_parents
} = { $rev => $tree };
2652 $self->fetch(undef, undef);
2656 my ($self, $tree) = (shift, shift);
2657 my $log_entry = ::get_commit_entry
($tree);
2658 unless ($self->{last_rev
}) {
2659 ::fatal
("Must have an existing revision to commit");
2661 my %ed_opts = ( r
=> $self->{last_rev
},
2662 log => $log_entry->{log},
2664 tree_a
=> $self->{last_commit
},
2667 $self->set_tree_cb($log_entry, $tree, @_) },
2668 svn_path
=> $self->{path
} );
2669 if (!SVN
::Git
::Editor
->new(\
%ed_opts)->apply_diff) {
2670 print "No changes\nr$self->{last_rev} = $tree\n";
2674 sub rebuild_from_rev_db
{
2675 my ($self, $path) = @_;
2677 open my $fh, '<', $path or croak
"open: $!";
2678 binmode $fh or croak
"binmode: $!";
2680 length($_) == 41 or croak
"inconsistent size in ($_) != 41";
2683 next if $_ eq ('0' x
40);
2684 $self->rev_map_set($r, $_);
2687 close $fh or croak
"close: $!";
2688 unlink $path or croak
"unlink: $!";
2693 my $map_path = $self->map_path;
2694 my $partial = (-e
$map_path && ! -z
$map_path);
2695 return unless ::verify_ref
($self->refname.'^0');
2696 if (!$partial && ($self->use_svm_props || $self->no_metadata)) {
2697 my $rev_db = $self->rev_db_path;
2698 $self->rebuild_from_rev_db($rev_db);
2699 if ($self->use_svm_props) {
2700 my $svm_rev_db = $self->rev_db_path($self->svm_uuid);
2701 $self->rebuild_from_rev_db($svm_rev_db);
2703 $self->unlink_rev_db_symlink;
2706 print "Rebuilding $map_path ...\n" if (!$partial);
2707 my ($base_rev, $head) = ($partial ?
$self->rev_map_max_norebuild(1) :
2710 command_output_pipe
(qw
/rev-list --pretty=raw --no-color --reverse/,
2711 ($head ?
"$head.." : "") . $self->refname,
2713 my $metadata_url = $self->metadata_url;
2714 remove_username
($metadata_url);
2715 my $svn_uuid = $self->ra_uuid;
2718 if ( m{^commit ($::sha1)$} ) {
2722 next unless s{^\s*(git-svn-id:)}{$1};
2723 my ($url, $rev, $uuid) = ::extract_metadata
($_);
2724 remove_username
($url);
2726 # ignore merges (from set-tree)
2727 next if (!defined $rev || !$uuid);
2729 # if we merged or otherwise started elsewhere, this is
2730 # how we break out of it
2731 if (($uuid ne $svn_uuid) ||
2732 ($metadata_url && $url && ($url ne $metadata_url))) {
2735 if ($partial && $head) {
2736 print "Partial-rebuilding $map_path ...\n";
2737 print "Currently at $base_rev = $head\n";
2741 $self->rev_map_set($rev, $c);
2742 print "r$rev = $c\n";
2744 command_close_pipe
($log, $ctx);
2745 print "Done rebuilding $map_path\n" if (!$partial || !$head);
2746 my $rev_db_path = $self->rev_db_path;
2747 if (-f
$self->rev_db_path) {
2748 unlink $self->rev_db_path or croak
"unlink: $!";
2750 $self->unlink_rev_db_symlink;
2754 # Tie::File seems to be prone to offset errors if revisions get sparse,
2755 # it's not that fast, either. Tie::File is also not in Perl 5.6. So
2756 # one of my favorite modules is out :< Next up would be one of the DBM
2757 # modules, but I'm not sure which is most portable...
2759 # This is the replacement for the rev_db format, which was too big
2760 # and inefficient for large repositories with a lot of sparse history
2763 # The format is this:
2764 # - 24 bytes for every record,
2765 # * 4 bytes for the integer representing an SVN revision number
2766 # * 20 bytes representing the sha1 of a git commit
2767 # - No empty padding records like the old format
2768 # (except the last record, which can be overwritten)
2769 # - new records are written append-only since SVN revision numbers
2770 # increase monotonically
2771 # - lookups on SVN revision number are done via a binary search
2772 # - Piping the file to xxd -c24 is a good way of dumping it for
2773 # viewing or editing (piped back through xxd -r), should the need
2775 # - The last record can be padding revision with an all-zero sha1
2776 # This is used to optimize fetch performance when using multiple
2777 # "fetch" directives in .git/config
2779 # These files are disposable unless noMetadata or useSvmProps is set
2782 my ($fh, $rev, $commit) = @_;
2784 binmode $fh or croak
"binmode: $!";
2785 my $size = (stat($fh))[7];
2786 ($size % 24) == 0 or croak
"inconsistent size: $size";
2790 sysseek($fh, -24, SEEK_END
) or croak
"seek: $!";
2791 my $read = sysread($fh, my $buf, 24) or croak
"read: $!";
2792 $read == 24 or croak
"read only $read bytes (!= 24)";
2793 my ($last_rev, $last_commit) = unpack(rev_map_fmt
, $buf);
2794 if ($last_commit eq ('0' x40
)) {
2796 sysseek($fh, -48, SEEK_END
) or croak
"seek: $!";
2797 $read = sysread($fh, $buf, 24) or
2800 croak
"read only $read bytes (!= 24)";
2801 ($last_rev, $last_commit) =
2802 unpack(rev_map_fmt
, $buf);
2803 if ($last_commit eq ('0' x40
)) {
2804 croak
"inconsistent .rev_map\n";
2807 if ($last_rev >= $rev) {
2808 croak
"last_rev is higher!: $last_rev >= $rev";
2813 sysseek($fh, $wr_offset, SEEK_END
) or croak
"seek: $!";
2814 syswrite($fh, pack(rev_map_fmt
, $rev, $commit), 24) == 24 or
2821 my ($dir, $base) = ($path =~ m
#^(.*?)/?([^/]+)$#);
2822 mkpath
([$dir]) unless -d
$dir;
2823 open my $fh, '>>', $path or die "Couldn't create $path: $!\n";
2824 close $fh or die "Couldn't close (create) $path: $!\n";
2829 my ($self, $rev, $commit, $update_ref, $uuid) = @_;
2830 length $commit == 40 or die "arg3 must be a full SHA1 hexsum\n";
2831 my $db = $self->map_path($uuid);
2832 my $db_lock = "$db.lock";
2835 $SIG{INT
} = $SIG{HUP
} = $SIG{TERM
} = $SIG{ALRM
} = $SIG{PIPE
} =
2836 $SIG{USR1
} = $SIG{USR2
} = sub { $sig = $_[0] };
2840 $LOCKFILES{$db_lock} = 1;
2842 # both of these options make our .rev_db file very, very important
2843 # and we can't afford to lose it because rebuild() won't work
2844 if ($self->use_svm_props || $self->no_metadata) {
2846 copy
($db, $db_lock) or die "rev_map_set(@_): ",
2848 "$db => $db_lock ($!)\n";
2850 rename $db, $db_lock or die "rev_map_set(@_): ",
2851 "Failed to rename: ",
2852 "$db => $db_lock ($!)\n";
2855 sysopen(my $fh, $db_lock, O_RDWR
| O_CREAT
)
2856 or croak
"Couldn't open $db_lock: $!\n";
2857 _rev_map_set
($fh, $rev, $commit);
2859 $fh->flush or die "Couldn't flush $db_lock: $!\n";
2860 $fh->sync or die "Couldn't sync $db_lock: $!\n";
2862 close $fh or croak
$!;
2865 command_noisy
('update-ref', '-m', "r$rev",
2866 $self->refname, $commit);
2868 rename $db_lock, $db or die "rev_map_set(@_): ", "Failed to rename: ",
2869 "$db_lock => $db ($!)\n";
2870 delete $LOCKFILES{$db_lock};
2872 $SIG{INT
} = $SIG{HUP
} = $SIG{TERM
} = $SIG{ALRM
} = $SIG{PIPE
} =
2873 $SIG{USR1
} = $SIG{USR2
} = 'DEFAULT';
2874 kill $sig, $$ if defined $sig;
2878 # If want_commit, this will return an array of (rev, commit) where
2879 # commit _must_ be a valid commit in the archive.
2880 # Otherwise, it'll return the max revision (whether or not the
2881 # commit is valid or just a 0x40 placeholder).
2883 my ($self, $want_commit) = @_;
2885 my ($r, $c) = $self->rev_map_max_norebuild($want_commit);
2886 $want_commit ?
($r, $c) : $r;
2889 sub rev_map_max_norebuild
{
2890 my ($self, $want_commit) = @_;
2891 my $map_path = $self->map_path;
2892 stat $map_path or return $want_commit ?
(0, undef) : 0;
2893 sysopen(my $fh, $map_path, O_RDONLY
) or croak
"open: $!";
2894 binmode $fh or croak
"binmode: $!";
2895 my $size = (stat($fh))[7];
2896 ($size % 24) == 0 or croak
"inconsistent size: $size";
2899 close $fh or croak
"close: $!";
2900 return $want_commit ?
(0, undef) : 0;
2903 sysseek($fh, -24, SEEK_END
) or croak
"seek: $!";
2904 sysread($fh, my $buf, 24) == 24 or croak
"read: $!";
2905 my ($r, $c) = unpack(rev_map_fmt
, $buf);
2906 if ($want_commit && $c eq ('0' x40
)) {
2908 return $want_commit ?
(0, undef) : 0;
2910 sysseek($fh, -48, SEEK_END
) or croak
"seek: $!";
2911 sysread($fh, $buf, 24) == 24 or croak
"read: $!";
2912 ($r, $c) = unpack(rev_map_fmt
, $buf);
2913 if ($c eq ('0'x40
)) {
2914 croak
"Penultimate record is all-zeroes in $map_path";
2917 close $fh or croak
"close: $!";
2918 $want_commit ?
($r, $c) : $r;
2922 my ($self, $rev, $uuid) = @_;
2923 my $map_path = $self->map_path($uuid);
2924 return undef unless -e
$map_path;
2926 sysopen(my $fh, $map_path, O_RDONLY
) or croak
"open: $!";
2927 binmode $fh or croak
"binmode: $!";
2928 my $size = (stat($fh))[7];
2929 ($size % 24) == 0 or croak
"inconsistent size: $size";
2932 close $fh or croak
"close: $fh";
2936 my ($l, $u) = (0, $size - 24);
2940 my $i = int(($l/24 + $u/24) / 2) * 24;
2941 sysseek($fh, $i, SEEK_SET
) or croak
"seek: $!";
2942 sysread($fh, my $buf, 24) == 24 or croak
"read: $!";
2943 my ($r, $c) = unpack('NH40', $buf);
2947 } elsif ($r > $rev) {
2949 } else { # $r == $rev
2950 close($fh) or croak
"close: $!";
2951 return $c eq ('0' x
40) ?
undef : $c;
2954 close($fh) or croak
"close: $!";
2958 # Finds the first svn revision that exists on (if $eq_ok is true) or
2959 # before $rev for the current branch. It will not search any lower
2960 # than $min_rev. Returns the git commit hash and svn revision number
2961 # if found, else (undef, undef).
2962 sub find_rev_before
{
2963 my ($self, $rev, $eq_ok, $min_rev) = @_;
2964 --$rev unless $eq_ok;
2966 while ($rev >= $min_rev) {
2967 if (my $c = $self->rev_map_get($rev)) {
2972 return (undef, undef);
2975 # Finds the first svn revision that exists on (if $eq_ok is true) or
2976 # after $rev for the current branch. It will not search any higher
2977 # than $max_rev. Returns the git commit hash and svn revision number
2978 # if found, else (undef, undef).
2979 sub find_rev_after
{
2980 my ($self, $rev, $eq_ok, $max_rev) = @_;
2981 ++$rev unless $eq_ok;
2982 $max_rev ||= $self->rev_map_max;
2983 while ($rev <= $max_rev) {
2984 if (my $c = $self->rev_map_get($rev)) {
2989 return (undef, undef);
2993 my ($class, $repo_id, $ref_id, $path) = @_;
2994 unless (defined $repo_id && length $repo_id) {
2995 $repo_id = $Git::SVN
::default_repo_id
;
2997 unless (defined $ref_id && length $ref_id) {
2998 $_[2] = $ref_id = $Git::SVN
::default_ref_id
;
3001 my $dir = "$ENV{GIT_DIR}/svn/$ref_id";
3002 $_[3] = $path = '' unless (defined $path);
3003 mkpath
(["$ENV{GIT_DIR}/svn"]);
3005 ref_id
=> $ref_id, dir
=> $dir, index => "$dir/index",
3006 path
=> $path, config
=> "$ENV{GIT_DIR}/svn/config",
3007 map_root
=> "$dir/.rev_map", repo_id
=> $repo_id }, $class;
3010 # for read-only access of old .rev_db formats
3011 sub unlink_rev_db_symlink
{
3013 my $link = $self->rev_db_path;
3014 $link =~ s/\.[\w-]+$// or croak
"missing UUID at the end of $link";
3016 unlink $link or croak
"unlink: $link failed!";
3021 my ($self, $uuid) = @_;
3022 my $db_path = $self->map_path($uuid);
3023 $db_path =~ s{/\.rev_map\.}{/\.rev_db\.}
3024 or croak
"map_path: $db_path does not contain '/.rev_map.' !";
3028 # the new replacement for .rev_db
3030 my ($self, $uuid) = @_;
3031 $uuid ||= $self->ra_uuid;
3032 "$self->{map_root}.$uuid";
3037 $f =~ s
#([^a-zA-Z0-9\*!\:_\./\-])#uc sprintf("%%%02x",ord($1))#eg;
3041 sub remove_username
{
3042 $_[0] =~ s{^([^:]*://)[^@]+@}{$1};
3045 package Git
::SVN
::Prompt
;
3049 use vars qw
/$_no_auth_cache $_username/;
3052 my ($cred, $realm, $default_username, $may_save, $pool) = @_;
3053 $may_save = undef if $_no_auth_cache;
3054 $default_username = $_username if defined $_username;
3055 if (defined $default_username && length $default_username) {
3056 if (defined $realm && length $realm) {
3057 print STDERR
"Authentication realm: $realm\n";
3060 $cred->username($default_username);
3062 username
($cred, $realm, $may_save, $pool);
3064 $cred->password(_read_password
("Password for '" .
3065 $cred->username . "': ", $realm));
3066 $cred->may_save($may_save);
3067 $SVN::_Core
::SVN_NO_ERROR
;
3070 sub ssl_server_trust
{
3071 my ($cred, $realm, $failures, $cert_info, $may_save, $pool) = @_;
3072 $may_save = undef if $_no_auth_cache;
3073 print STDERR
"Error validating server certificate for '$realm':\n";
3076 # All variables SVN::Auth::SSL::* are used only once,
3077 # so we're shutting up Perl warnings about this.
3078 if ($failures & $SVN::Auth
::SSL
::UNKNOWNCA
) {
3079 print STDERR
" - The certificate is not issued ",
3080 "by a trusted authority. Use the\n",
3081 " fingerprint to validate ",
3082 "the certificate manually!\n";
3084 if ($failures & $SVN::Auth
::SSL
::CNMISMATCH
) {
3085 print STDERR
" - The certificate hostname ",
3086 "does not match.\n";
3088 if ($failures & $SVN::Auth
::SSL
::NOTYETVALID
) {
3089 print STDERR
" - The certificate is not yet valid.\n";
3091 if ($failures & $SVN::Auth
::SSL
::EXPIRED
) {
3092 print STDERR
" - The certificate has expired.\n";
3094 if ($failures & $SVN::Auth
::SSL
::OTHER
) {
3095 print STDERR
" - The certificate has ",
3096 "an unknown error.\n";
3098 } # no warnings 'once'
3100 "Certificate information:\n".
3101 " - Hostname: %s\n".
3102 " - Valid: from %s until %s\n".
3104 " - Fingerprint: %s\n",
3105 map $cert_info->$_, qw(hostname valid_from valid_until
3106 issuer_dname fingerprint);
3109 print STDERR
$may_save ?
3110 "(R)eject, accept (t)emporarily or accept (p)ermanently? " :
3111 "(R)eject or accept (t)emporarily? ";
3113 $choice = lc(substr(<STDIN
> || 'R', 0, 1));
3114 if ($choice =~ /^t$/i) {
3115 $cred->may_save(undef);
3116 } elsif ($choice =~ /^r$/i) {
3118 } elsif ($may_save && $choice =~ /^p$/i) {
3119 $cred->may_save($may_save);
3123 $cred->accepted_failures($failures);
3124 $SVN::_Core
::SVN_NO_ERROR
;
3127 sub ssl_client_cert
{
3128 my ($cred, $realm, $may_save, $pool) = @_;
3129 $may_save = undef if $_no_auth_cache;
3130 print STDERR
"Client certificate filename: ";
3132 chomp(my $filename = <STDIN
>);
3133 $cred->cert_file($filename);
3134 $cred->may_save($may_save);
3135 $SVN::_Core
::SVN_NO_ERROR
;
3138 sub ssl_client_cert_pw
{
3139 my ($cred, $realm, $may_save, $pool) = @_;
3140 $may_save = undef if $_no_auth_cache;
3141 $cred->password(_read_password
("Password: ", $realm));
3142 $cred->may_save($may_save);
3143 $SVN::_Core
::SVN_NO_ERROR
;
3147 my ($cred, $realm, $may_save, $pool) = @_;
3148 $may_save = undef if $_no_auth_cache;
3149 if (defined $realm && length $realm) {
3150 print STDERR
"Authentication realm: $realm\n";
3153 if (defined $_username) {
3154 $username = $_username;
3156 print STDERR
"Username: ";
3158 chomp($username = <STDIN
>);
3160 $cred->username($username);
3161 $cred->may_save($may_save);
3162 $SVN::_Core
::SVN_NO_ERROR
;
3165 sub _read_password
{
3166 my ($prompt, $realm) = @_;
3167 print STDERR
$prompt;
3169 require Term
::ReadKey
;
3170 Term
::ReadKey
::ReadMode
('noecho');
3172 while (defined(my $key = Term
::ReadKey
::ReadKey
(0))) {
3173 last if $key =~ /[\012\015]/; # \n\r
3176 Term
::ReadKey
::ReadMode
('restore');
3182 package SVN
::Git
::Fetcher
;
3187 use File
::Temp qw
/tempfile/;
3190 # file baton members: path, mode_a, mode_b, pool, fh, blob, base
3192 my ($class, $git_svn) = @_;
3193 my $self = SVN
::Delta
::Editor
->new;
3194 bless $self, $class;
3195 $self->{c
} = $git_svn->{last_commit
} if exists $git_svn->{last_commit
};
3196 $self->{empty
} = {};
3197 $self->{dir_prop
} = {};
3198 $self->{file_prop
} = {};
3199 $self->{absent_dir
} = {};
3200 $self->{absent_file
} = {};
3201 $self->{gii
} = $git_svn->tmp_index_do(sub { Git
::IndexInfo
->new });
3205 sub set_path_strip
{
3206 my ($self, $path) = @_;
3207 $self->{path_strip
} = qr/^\Q$path\E(\/|$)/ if length $path;
3214 sub open_directory
{
3215 my ($self, $path, $pb, $rev) = @_;
3220 my ($self, $path) = @_;
3221 if ($self->{path_strip
}) {
3222 $path =~ s!$self->{path_strip}!! or
3223 die "Failed to strip path '$path' ($self->{path_strip})\n";
3229 my ($self, $path, $rev, $pb) = @_;
3231 my $gpath = $self->git_path($path);
3232 return undef if ($gpath eq '');
3234 # remove entire directories.
3235 if (command
('ls-tree', $self->{c
}, '--', $gpath) =~ /^040000 tree/) {
3236 my ($ls, $ctx) = command_output_pipe
(qw
/ls
-tree
3238 $self->{c
}, '--', $gpath);
3242 $self->{gii
}->remove($_);
3243 print "\tD\t$_\n" unless $::_q
;
3245 print "\tD\t$gpath/\n" unless $::_q
;
3246 command_close_pipe
($ls, $ctx);
3247 $self->{empty
}->{$path} = 0
3249 $self->{gii
}->remove($gpath);
3250 print "\tD\t$gpath\n" unless $::_q
;
3256 my ($self, $path, $pb, $rev) = @_;
3257 my $gpath = $self->git_path($path);
3258 my ($mode, $blob) = (command
('ls-tree', $self->{c
}, '--', $gpath)
3259 =~ /^(\d{6}) blob ([a-f\d]{40})\t/);
3260 unless (defined $mode && defined $blob) {
3261 die "$path was not found in commit $self->{c} (r$rev)\n";
3263 { path
=> $path, mode_a
=> $mode, mode_b
=> $mode, blob
=> $blob,
3264 pool
=> SVN
::Pool
->new, action
=> 'M' };
3268 my ($self, $path, $pb, $cp_path, $cp_rev) = @_;
3269 my ($dir, $file) = ($path =~ m
#^(.*?)/?([^/]+)$#);
3270 delete $self->{empty
}->{$dir};
3271 { path
=> $path, mode_a
=> 100644, mode_b
=> 100644,
3272 pool
=> SVN
::Pool
->new, action
=> 'A' };
3276 my ($self, $path, $cp_path, $cp_rev) = @_;
3277 my $gpath = $self->git_path($path);
3279 my ($ls, $ctx) = command_output_pipe
(qw
/ls
-tree
3285 $self->{gii
}->remove($_);
3286 print "\tD\t$_\n" unless $::_q
;
3288 command_close_pipe
($ls, $ctx);
3289 $self->{empty
}->{$path} = 0;
3291 my ($dir, $file) = ($path =~ m
#^(.*?)/?([^/]+)$#);
3292 delete $self->{empty
}->{$dir};
3293 $self->{empty
}->{$path} = 1;
3297 sub change_dir_prop
{
3298 my ($self, $db, $prop, $value) = @_;
3299 $self->{dir_prop
}->{$db->{path
}} ||= {};
3300 $self->{dir_prop
}->{$db->{path
}}->{$prop} = $value;
3304 sub absent_directory
{
3305 my ($self, $path, $pb) = @_;
3306 $self->{absent_dir
}->{$pb->{path
}} ||= [];
3307 push @
{$self->{absent_dir
}->{$pb->{path
}}}, $path;
3312 my ($self, $path, $pb) = @_;
3313 $self->{absent_file
}->{$pb->{path
}} ||= [];
3314 push @
{$self->{absent_file
}->{$pb->{path
}}}, $path;
3318 sub change_file_prop
{
3319 my ($self, $fb, $prop, $value) = @_;
3320 if ($prop eq 'svn:executable') {
3321 if ($fb->{mode_b
} != 120000) {
3322 $fb->{mode_b
} = defined $value ?
100755 : 100644;
3324 } elsif ($prop eq 'svn:special') {
3325 $fb->{mode_b
} = defined $value ?
120000 : 100644;
3327 $self->{file_prop
}->{$fb->{path
}} ||= {};
3328 $self->{file_prop
}->{$fb->{path
}}->{$prop} = $value;
3333 sub apply_textdelta
{
3334 my ($self, $fb, $exp) = @_;
3335 my $fh = $::_repository
->temp_acquire('svn_delta');
3336 # $fh gets auto-closed() by SVN::TxDelta::apply(),
3337 # (but $base does not,) so dup() it for reading in close_file
3338 open my $dup, '<&', $fh or croak
$!;
3339 my $base = $::_repository
->temp_acquire('git_blob');
3341 print $base 'link ' if ($fb->{mode_a
} == 120000);
3342 my $size = $::_repository
->cat_blob($fb->{blob
}, $base);
3343 die "Failed to read object $fb->{blob}" if ($size < 0);
3346 seek $base, 0, 0 or croak
$!;
3347 my $got = ::md5sum
($base);
3348 die "Checksum mismatch: $fb->{path} $fb->{blob}\n",
3350 " got: $got\n" if ($got ne $exp);
3353 seek $base, 0, 0 or croak
$!;
3355 $fb->{base
} = $base;
3356 [ SVN
::TxDelta
::apply
($base, $dup, undef, $fb->{path
}, $fb->{pool
}) ];
3360 my ($self, $fb, $exp) = @_;
3362 my $path = $self->git_path($fb->{path
});
3363 if (my $fh = $fb->{fh
}) {
3365 seek($fh, 0, 0) or croak
$!;
3366 my $got = ::md5sum
($fh);
3368 die "Checksum mismatch: $path\n",
3369 "expected: $exp\n got: $got\n";
3372 if ($fb->{mode_b
} == 120000) {
3373 sysseek($fh, 0, 0) or croak
$!;
3374 sysread($fh, my $buf, 5) == 5 or croak
$!;
3376 unless ($buf eq 'link ') {
3377 warn "$path has mode 120000",
3378 " but is not a link\n";
3380 my $tmp_fh = $::_repository
->temp_acquire(
3383 while ($res = sysread($fh, my $str, 1024)) {
3384 my $out = syswrite($tmp_fh, $str, $res);
3385 defined($out) && $out == $res
3387 Git
::temp_path
($tmp_fh),
3390 defined $res or croak
$!;
3392 ($fh, $tmp_fh) = ($tmp_fh, $fh);
3393 Git
::temp_release
($tmp_fh, 1);
3397 $hash = $::_repository
->hash_and_insert_object(
3398 Git
::temp_path
($fh));
3399 $hash =~ /^[a-f\d]{40}$/ or die "not a sha1: $hash\n";
3401 Git
::temp_release
($fb->{base
}, 1);
3402 Git
::temp_release
($fh, 1);
3404 $hash = $fb->{blob
} or die "no blob information\n";
3407 $self->{gii
}->update($fb->{mode_b
}, $hash, $path) or croak
$!;
3408 print "\t$fb->{action}\t$path\n" if $fb->{action
} && ! $::_q
;
3414 $self->{nr
} = $self->{gii
}->{nr
};
3415 delete $self->{gii
};
3416 $self->SUPER::abort_edit
(@_);
3421 $self->{git_commit_ok
} = 1;
3422 $self->{nr
} = $self->{gii
}->{nr
};
3423 delete $self->{gii
};
3424 $self->SUPER::close_edit
(@_);
3427 package SVN
::Git
::Editor
;
3428 use vars qw
/@ISA $_rmdir $_cp_similarity $_find_copies_harder $_rename_limit/;
3435 my ($class, $opts) = @_;
3436 foreach (qw
/svn_path r ra tree_a tree_b log editor_cb/) {
3437 die "$_ required!\n" unless (defined $opts->{$_});
3440 my $pool = SVN
::Pool
->new;
3441 my $mods = generate_diff
($opts->{tree_a
}, $opts->{tree_b
});
3442 my $types = check_diff_paths
($opts->{ra
}, $opts->{svn_path
},
3445 # $opts->{ra} functions should not be used after this:
3446 my @ce = $opts->{ra
}->get_commit_editor($opts->{log},
3447 $opts->{editor_cb
}, $pool);
3448 my $self = SVN
::Delta
::Editor
->new(@ce, $pool);
3449 bless $self, $class;
3450 foreach (qw
/svn_path r tree_a tree_b/) {
3451 $self->{$_} = $opts->{$_};
3453 $self->{url
} = $opts->{ra
}->{url
};
3454 $self->{mods
} = $mods;
3455 $self->{types
} = $types;
3456 $self->{pool
} = $pool;
3457 $self->{bat
} = { '' => $self->open_root($self->{r
}, $self->{pool
}) };
3459 $self->{path_prefix
} = length $self->{svn_path
} ?
3460 "$self->{svn_path}/" : '';
3461 $self->{config
} = $opts->{config
};
3466 my ($tree_a, $tree_b) = @_;
3467 my @diff_tree = qw(diff-tree -z -r);
3468 if ($_cp_similarity) {
3469 push @diff_tree, "-C$_cp_similarity";
3471 push @diff_tree, '-C';
3473 push @diff_tree, '--find-copies-harder' if $_find_copies_harder;
3474 push @diff_tree, "-l$_rename_limit" if defined $_rename_limit;
3475 push @diff_tree, $tree_a, $tree_b;
3476 my ($diff_fh, $ctx) = command_output_pipe
(@diff_tree);
3480 while (<$diff_fh>) {
3481 chomp $_; # this gets rid of the trailing "\0"
3482 if ($state eq 'meta' && /^:(\d
{6})\s
(\d
{6})\s
3483 ($::sha1
)\s
($::sha1
)\s
3484 ([MTCRAD
])\d
*$/xo
) {
3485 push @mods, { mode_a
=> $1, mode_b
=> $2,
3486 sha1_a
=> $3, sha1_b
=> $4,
3488 if ($5 =~ /^(?:C|R)$/) {
3493 } elsif ($state eq 'file_a') {
3494 my $x = $mods[$#mods] or croak
"Empty array\n";
3495 if ($x->{chg
} !~ /^(?:C|R)$/) {
3496 croak
"Error parsing $_, $x->{chg}\n";
3500 } elsif ($state eq 'file_b') {
3501 my $x = $mods[$#mods] or croak
"Empty array\n";
3502 if (exists $x->{file_a
} && $x->{chg
} !~ /^(?:C|R)$/) {
3503 croak
"Error parsing $_, $x->{chg}\n";
3505 if (!exists $x->{file_a
} && $x->{chg
} =~ /^(?:C|R)$/) {
3506 croak
"Error parsing $_, $x->{chg}\n";
3511 croak
"Error parsing $_\n";
3514 command_close_pipe
($diff_fh, $ctx);
3518 sub check_diff_paths
{
3519 my ($ra, $pfx, $rev, $mods) = @_;
3521 $pfx .= '/' if length $pfx;
3523 sub type_diff_paths
{
3524 my ($ra, $types, $path, $rev) = @_;
3525 my @p = split m
#/+#, $path;
3527 unless (defined $types->{$c}) {
3528 $types->{$c} = $ra->check_path($c, $rev);
3531 $c .= '/' . shift @p;
3532 next if defined $types->{$c};
3533 $types->{$c} = $ra->check_path($c, $rev);
3537 foreach my $m (@
$mods) {
3538 foreach my $f (qw
/file_a file_b/) {
3539 next unless defined $m->{$f};
3540 my ($dir) = ($m->{$f} =~ m
#^(.*?)/?(?:[^/]+)$#);
3541 if (length $pfx.$dir && ! defined $types{$dir}) {
3542 type_diff_paths
($ra, \
%types, $pfx.$dir, $rev);
3550 return ($_[0] =~ m
#^(.*?)/?([^/]+)$#);
3554 my ($self, $path) = @_;
3555 $self->{path_prefix
}.(defined $path ?
$path : '');
3559 my ($self, $path) = @_;
3560 if ($self->{url
} =~ m
#^https?://#) {
3561 $path =~ s/([^~a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg;
3563 $self->{url
} . '/' . $self->repo_path($path);
3568 my $rm = $self->{rm
};
3569 delete $rm->{''}; # we never delete the url we're tracking
3572 foreach (keys %$rm) {
3573 my @d = split m
#/#, $_;
3577 $c .= '/' . shift @d;
3581 delete $rm->{$self->{svn_path
}};
3582 delete $rm->{''}; # we never delete the url we're tracking
3585 my ($fh, $ctx) = command_output_pipe
(qw
/ls-tree --name-only -r -z/,
3590 my @dn = split m
#/#, $_;
3592 delete $rm->{join '/', @dn};
3599 command_close_pipe
($fh, $ctx);
3601 my ($r, $p, $bat) = ($self->{r
}, $self->{pool
}, $self->{bat
});
3602 foreach my $d (sort { $b =~ tr
#/#/# <=> $a =~ tr#/#/# } keys %$rm) {
3603 $self->close_directory($bat->{$d}, $p);
3604 my ($dn) = ($d =~ m
#^(.*?)/?(?:[^/]+)$#);
3605 print "\tD+\t$d/\n" unless $::_q
;
3606 $self->SUPER::delete_entry
($d, $r, $bat->{$dn}, $p);
3611 sub open_or_add_dir
{
3612 my ($self, $full_path, $baton) = @_;
3613 my $t = $self->{types
}->{$full_path};
3615 die "$full_path not known in r$self->{r} or we have a bug!\n";
3619 # SVN::Node::none and SVN::Node::file are used only once,
3620 # so we're shutting up Perl's warnings about them.
3621 if ($t == $SVN::Node
::none
) {
3622 return $self->add_directory($full_path, $baton,
3623 undef, -1, $self->{pool
});
3624 } elsif ($t == $SVN::Node
::dir
) {
3625 return $self->open_directory($full_path, $baton,
3626 $self->{r
}, $self->{pool
});
3627 } # no warnings 'once'
3628 print STDERR
"$full_path already exists in repository at ",
3629 "r$self->{r} and it is not a directory (",
3630 ($t == $SVN::Node
::file ?
'file' : 'unknown'),"/$t)\n";
3631 } # no warnings 'once'
3636 my ($self, $path) = @_;
3637 my $bat = $self->{bat
};
3638 my $repo_path = $self->repo_path($path);
3639 return $bat->{''} unless (length $repo_path);
3640 my @p = split m
#/+#, $repo_path;
3642 $bat->{$c} ||= $self->open_or_add_dir($c, $bat->{''});
3645 $c .= '/' . shift @p;
3646 $bat->{$c} ||= $self->open_or_add_dir($c, $bat->{$c0});
3651 # Subroutine to convert a globbing pattern to a regular expression.
3652 # From perl cookbook.
3654 my $globstr = shift;
3655 my %patmap = ('*' => '.*', '?' => '.', '[' => '[', ']' => ']');
3656 $globstr =~ s{(.)} { $patmap{$1} || "\Q$1" }ge;
3657 return '^' . $globstr . '$';
3660 sub check_autoprop
{
3661 my ($self, $pattern, $properties, $file, $fbat) = @_;
3662 # Convert the globbing pattern to a regular expression.
3663 my $regex = glob2pat
($pattern);
3664 # Check if the pattern matches the file name.
3665 if($file =~ m/($regex)/) {
3666 # Parse the list of properties to set.
3667 my @props = split(/;/, $properties);
3668 foreach my $prop (@props) {
3669 # Parse 'name=value' syntax and set the property.
3670 if ($prop =~ /([^=]+)=(.*)/) {
3671 my ($n,$v) = ($1,$2);
3675 $self->change_file_prop($fbat, $n, $v);
3681 sub apply_autoprops
{
3682 my ($self, $file, $fbat) = @_;
3683 my $conf_t = ${$self->{config
}}{'config'};
3685 # Check [miscellany]/enable-auto-props in svn configuration.
3686 if (SVN
::_Core
::svn_config_get_bool
(
3688 $SVN::_Core
::SVN_CONFIG_SECTION_MISCELLANY
,
3689 $SVN::_Core
::SVN_CONFIG_OPTION_ENABLE_AUTO_PROPS
,
3691 # Auto-props are enabled. Enumerate them to look for matches.
3692 my $callback = sub {
3693 $self->check_autoprop($_[0], $_[1], $file, $fbat);
3695 SVN
::_Core
::svn_config_enumerate
(
3697 $SVN::_Core
::SVN_CONFIG_SECTION_AUTO_PROPS
,
3703 my ($self, $m) = @_;
3704 my ($dir, $file) = split_path
($m->{file_b
});
3705 my $pbat = $self->ensure_path($dir);
3706 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
3708 print "\tA\t$m->{file_b}\n" unless $::_q
;
3709 $self->apply_autoprops($file, $fbat);
3710 $self->chg_file($fbat, $m);
3711 $self->close_file($fbat,undef,$self->{pool
});
3715 my ($self, $m) = @_;
3716 my ($dir, $file) = split_path
($m->{file_b
});
3717 my $pbat = $self->ensure_path($dir);
3718 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
3719 $self->url_path($m->{file_a
}), $self->{r
});
3720 print "\tC\t$m->{file_a} => $m->{file_b}\n" unless $::_q
;
3721 $self->chg_file($fbat, $m);
3722 $self->close_file($fbat,undef,$self->{pool
});
3726 my ($self, $path, $pbat) = @_;
3727 my $rpath = $self->repo_path($path);
3728 my ($dir, $file) = split_path
($rpath);
3729 $self->{rm
}->{$dir} = 1;
3730 $self->SUPER::delete_entry
($rpath, $self->{r
}, $pbat, $self->{pool
});
3734 my ($self, $m) = @_;
3735 my ($dir, $file) = split_path
($m->{file_b
});
3736 my $pbat = $self->ensure_path($dir);
3737 my $fbat = $self->add_file($self->repo_path($m->{file_b
}), $pbat,
3738 $self->url_path($m->{file_a
}), $self->{r
});
3739 print "\tR\t$m->{file_a} => $m->{file_b}\n" unless $::_q
;
3740 $self->apply_autoprops($file, $fbat);
3741 $self->chg_file($fbat, $m);
3742 $self->close_file($fbat,undef,$self->{pool
});
3744 ($dir, $file) = split_path
($m->{file_a
});
3745 $pbat = $self->ensure_path($dir);
3746 $self->delete_entry($m->{file_a
}, $pbat);
3750 my ($self, $m) = @_;
3751 my ($dir, $file) = split_path
($m->{file_b
});
3752 my $pbat = $self->ensure_path($dir);
3753 my $fbat = $self->open_file($self->repo_path($m->{file_b
}),
3754 $pbat,$self->{r
},$self->{pool
});
3755 print "\t$m->{chg}\t$m->{file_b}\n" unless $::_q
;
3756 $self->chg_file($fbat, $m);
3757 $self->close_file($fbat,undef,$self->{pool
});
3760 sub T
{ shift->M(@_) }
3762 sub change_file_prop
{
3763 my ($self, $fbat, $pname, $pval) = @_;
3764 $self->SUPER::change_file_prop
($fbat, $pname, $pval, $self->{pool
});
3767 sub _chg_file_get_blob
($$$$) {
3768 my ($self, $fbat, $m, $which) = @_;
3769 my $fh = $::_repository
->temp_acquire("git_blob_$which");
3770 if ($m->{"mode_$which"} =~ /^120/) {
3771 print $fh 'link ' or croak
$!;
3772 $self->change_file_prop($fbat,'svn:special','*');
3773 } elsif ($m->{mode_a
} =~ /^120/ && $m->{"mode_$which"} !~ /^120/) {
3774 $self->change_file_prop($fbat,'svn:special',undef);
3776 my $blob = $m->{"sha1_$which"};
3777 return ($fh,) if ($blob =~ /^0{40}$/);
3778 my $size = $::_repository
->cat_blob($blob, $fh);
3779 croak
"Failed to read object $blob" if ($size < 0);
3780 $fh->flush == 0 or croak
$!;
3781 seek $fh, 0, 0 or croak
$!;
3783 my $exp = ::md5sum
($fh);
3784 seek $fh, 0, 0 or croak
$!;
3789 my ($self, $fbat, $m) = @_;
3790 if ($m->{mode_b
} =~ /755$/ && $m->{mode_a
} !~ /755$/) {
3791 $self->change_file_prop($fbat,'svn:executable','*');
3792 } elsif ($m->{mode_b
} !~ /755$/ && $m->{mode_a
} =~ /755$/) {
3793 $self->change_file_prop($fbat,'svn:executable',undef);
3795 my ($fh_a, $exp_a) = _chg_file_get_blob
$self, $fbat, $m, 'a';
3796 my ($fh_b, $exp_b) = _chg_file_get_blob
$self, $fbat, $m, 'b';
3797 my $pool = SVN
::Pool
->new;
3798 my $atd = $self->apply_textdelta($fbat, $exp_a, $pool);
3800 my $txstream = SVN
::TxDelta
::new
($fh_a, $fh_b, $pool);
3801 my $res = SVN
::TxDelta
::send_txstream
($txstream, @
$atd, $pool);
3803 die "Unexpected result from send_txstream: $res\n",
3804 "(SVN::Core::VERSION: $SVN::Core::VERSION)\n";
3807 my $got = SVN
::TxDelta
::send_stream
($fh_b, @
$atd, $pool);
3808 die "Checksum mismatch\nexpected: $exp_b\ngot: $got\n"
3809 if ($got ne $exp_b);
3811 Git
::temp_release
($fh_b, 1);
3812 Git
::temp_release
($fh_a, 1);
3817 my ($self, $m) = @_;
3818 my ($dir, $file) = split_path
($m->{file_b
});
3819 my $pbat = $self->ensure_path($dir);
3820 print "\tD\t$m->{file_b}\n" unless $::_q
;
3821 $self->delete_entry($m->{file_b
}, $pbat);
3826 my ($p,$bat) = ($self->{pool
}, $self->{bat
});
3827 foreach (sort { $b =~ tr
#/#/# <=> $a =~ tr#/#/# } keys %$bat) {
3829 $self->close_directory($bat->{$_}, $p);
3831 $self->close_directory($bat->{''}, $p);
3832 $self->SUPER::close_edit
($p);
3838 $self->SUPER::abort_edit
($self->{pool
});
3843 $self->SUPER::DESTROY
(@_);
3844 $self->{pool
}->clear;
3847 # this drives the editor
3850 my $mods = $self->{mods
};
3851 my %o = ( D
=> 1, R
=> 0, C
=> -1, A
=> 3, M
=> 3, T
=> 3 );
3852 foreach my $m (sort { $o{$a->{chg
}} <=> $o{$b->{chg
}} } @
$mods) {
3854 if (defined $o{$f}) {
3857 fatal
("Invalid change type: $f");
3860 $self->rmdirs if $_rmdir;
3866 return scalar @
$mods;
3869 package Git
::SVN
::Ra
;
3870 use vars qw
/@ISA $config_dir $_log_window_size/;
3873 my ($ra_invalid, $can_do_switch, %ignored_err, $RA);
3876 # enforce temporary pool usage for some simple functions
3878 for my $f (qw
/rev_proplist get_latest_revnum get_uuid get_repos_root/) {
3879 my $SUPER = "SUPER::$f";
3882 my $pool = SVN
::Pool
->new;
3883 my @ret = $self->$SUPER(@_,$pool);
3885 wantarray ?
@ret : $ret[0];
3890 sub _auth_providers
() {
3892 SVN
::Client
::get_simple_provider
(),
3893 SVN
::Client
::get_ssl_server_trust_file_provider
(),
3894 SVN
::Client
::get_simple_prompt_provider
(
3895 \
&Git
::SVN
::Prompt
::simple
, 2),
3896 SVN
::Client
::get_ssl_client_cert_file_provider
(),
3897 SVN
::Client
::get_ssl_client_cert_prompt_provider
(
3898 \
&Git
::SVN
::Prompt
::ssl_client_cert
, 2),
3899 SVN
::Client
::get_ssl_client_cert_pw_file_provider
(),
3900 SVN
::Client
::get_ssl_client_cert_pw_prompt_provider
(
3901 \
&Git
::SVN
::Prompt
::ssl_client_cert_pw
, 2),
3902 SVN
::Client
::get_username_provider
(),
3903 SVN
::Client
::get_ssl_server_trust_prompt_provider
(
3904 \
&Git
::SVN
::Prompt
::ssl_server_trust
),
3905 SVN
::Client
::get_username_prompt_provider
(
3906 \
&Git
::SVN
::Prompt
::username
, 2)
3910 sub escape_uri_only
{
3913 foreach (split m{/}, $uri) {
3914 s/([^~\w.%+-]|%(?![a-fA-F0-9]{2}))/sprintf("%%%02X",ord($1))/eg;
3922 if ($url =~ m
#^(https?)://([^/]+)(.*)$#) {
3923 my ($scheme, $domain, $uri) = ($1, $2, escape_uri_only
($3));
3924 $url = "$scheme://$domain$uri";
3930 my ($class, $url) = @_;
3932 return $RA if ($RA && $RA->{url
} eq $url);
3934 SVN
::_Core
::svn_config_ensure
($config_dir, undef);
3935 my ($baton, $callbacks) = SVN
::Core
::auth_open_helper
(_auth_providers
);
3936 my $config = SVN
::Core
::config_get_config
($config_dir);
3938 my $dont_store_passwords = 1;
3939 my $conf_t = ${$config}{'config'};
3942 # The usage of $SVN::_Core::SVN_CONFIG_* variables
3943 # produces warnings that variables are used only once.
3944 # I had not found the better way to shut them up, so
3945 # the warnings of type 'once' are disabled in this block.
3946 if (SVN
::_Core
::svn_config_get_bool
($conf_t,
3947 $SVN::_Core
::SVN_CONFIG_SECTION_AUTH
,
3948 $SVN::_Core
::SVN_CONFIG_OPTION_STORE_PASSWORDS
,
3950 SVN
::_Core
::svn_auth_set_parameter
($baton,
3951 $SVN::_Core
::SVN_AUTH_PARAM_DONT_STORE_PASSWORDS
,
3952 bless (\
$dont_store_passwords, "_p_void"));
3954 if (SVN
::_Core
::svn_config_get_bool
($conf_t,
3955 $SVN::_Core
::SVN_CONFIG_SECTION_AUTH
,
3956 $SVN::_Core
::SVN_CONFIG_OPTION_STORE_AUTH_CREDS
,
3958 $Git::SVN
::Prompt
::_no_auth_cache
= 1;
3960 } # no warnings 'once'
3961 my $self = SVN
::Ra
->new(url
=> escape_url
($url), auth
=> $baton,
3963 pool
=> SVN
::Pool
->new,
3964 auth_provider_callbacks
=> $callbacks);
3965 $self->{url
} = $url;
3966 $self->{svn_path
} = $url;
3967 $self->{repos_root
} = $self->get_repos_root;
3968 $self->{svn_path
} =~ s
#^\Q$self->{repos_root}\E(/|$)##;
3969 $self->{cache
} = { check_path
=> { r
=> 0, data
=> {} },
3970 get_dir
=> { r
=> 0, data
=> {} } };
3971 $RA = bless $self, $class;
3975 my ($self, $path, $r) = @_;
3976 my $cache = $self->{cache
}->{check_path
};
3977 if ($r == $cache->{r
} && exists $cache->{data
}->{$path}) {
3978 return $cache->{data
}->{$path};
3980 my $pool = SVN
::Pool
->new;
3981 my $t = $self->SUPER::check_path
($path, $r, $pool);
3983 if ($r != $cache->{r
}) {
3984 %{$cache->{data
}} = ();
3987 $cache->{data
}->{$path} = $t;
3991 my ($self, $dir, $r) = @_;
3992 my $cache = $self->{cache
}->{get_dir
};
3993 if ($r == $cache->{r
}) {
3994 if (my $x = $cache->{data
}->{$dir}) {
3995 return wantarray ? @
$x : $x->[0];
3998 my $pool = SVN
::Pool
->new;
3999 my ($d, undef, $props) = $self->SUPER::get_dir
($dir, $r, $pool);
4000 my %dirents = map { $_ => { kind
=> $d->{$_}->kind } } keys %$d;
4002 if ($r != $cache->{r
}) {
4003 %{$cache->{data
}} = ();
4006 $cache->{data
}->{$dir} = [ \
%dirents, $r, $props ];
4007 wantarray ?
(\
%dirents, $r, $props) : \
%dirents;
4011 # do not call the real DESTROY since we store ourselves in $RA
4015 my ($self, @args) = @_;
4016 my $pool = SVN
::Pool
->new;
4017 splice(@args, 3, 1) if ($SVN::Core
::VERSION
le '1.2.0');
4018 my $ret = $self->SUPER::get_log
(@args, $pool);
4024 my ($self, $url1, $rev1, $url2, $rev2) = @_;
4025 my $ctx = SVN
::Client
->new(auth
=> _auth_providers
);
4026 my $out = IO
::File
->new_tmpfile;
4028 # older SVN (1.1.x) doesn't take $pool as the last parameter for
4029 # $ctx->diff(), so we'll create a default one
4030 my $pool = SVN
::Pool
->new_default_sub;
4032 $ra_invalid = 1; # this will open a new SVN::Ra connection to $url1
4033 $ctx->diff([], $url1, $rev1, $url2, $rev2, 1, 1, 0, $out, $out);
4035 my $ret = (($out->stat)[7] == 0);
4036 close $out or croak
$!;
4041 sub get_commit_editor
{
4042 my ($self, $log, $cb, $pool) = @_;
4043 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef, 0) : ();
4044 $self->SUPER::get_commit_editor
($log, $cb, @lock, $pool);
4048 my ($self, $rev_a, $rev_b, $gs, $editor) = @_;
4049 my $new = ($rev_a == $rev_b);
4050 my $path = $gs->{path
};
4052 if ($new && -e
$gs->{index}) {
4053 unlink $gs->{index} or die
4054 "Couldn't unlink index: $gs->{index}: $!\n";
4056 my $pool = SVN
::Pool
->new;
4057 $editor->set_path_strip($path);
4058 my (@pc) = split m
#/#, $path;
4059 my $reporter = $self->do_update($rev_b, (@pc ?
shift @pc : ''),
4061 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef) : ();
4063 # Since we can't rely on svn_ra_reparent being available, we'll
4064 # just have to do some magic with set_path to make it so
4065 # we only want a partial path.
4067 my $final = join('/', @pc);
4069 $reporter->set_path($sp, $rev_b, 0, @lock, $pool);
4070 $sp .= '/' if length $sp;
4073 die "BUG: '$sp' != '$final'\n" if ($sp ne $final);
4075 $reporter->set_path($sp, $rev_a, $new, @lock, $pool);
4077 $reporter->finish_report($pool);
4079 $editor->{git_commit_ok
};
4082 # this requires SVN 1.4.3 or later (do_switch didn't work before 1.4.3, and
4083 # svn_ra_reparent didn't work before 1.4)
4085 my ($self, $rev_a, $rev_b, $gs, $url_b, $editor) = @_;
4086 my $path = $gs->{path
};
4087 my $pool = SVN
::Pool
->new;
4089 my $full_url = $self->{url
};
4090 my $old_url = $full_url;
4091 $full_url .= '/' . escape_uri_only
($path) if length $path;
4092 my ($ra, $reparented);
4094 if ($old_url =~ m
#^svn(\+ssh)?://#) {
4098 $ra = Git
::SVN
::Ra
->new($full_url);
4100 } elsif ($old_url ne $full_url) {
4101 SVN
::_Ra
::svn_ra_reparent
($self->{session
}, $full_url, $pool);
4102 $self->{url
} = $full_url;
4107 $url_b = escape_url
($url_b);
4108 my $reporter = $ra->do_switch($rev_b, '', 1, $url_b, $editor, $pool);
4109 my @lock = $SVN::Core
::VERSION
ge '1.2.0' ?
(undef) : ();
4110 $reporter->set_path('', $rev_a, 0, @lock, $pool);
4111 $reporter->finish_report($pool);
4114 SVN
::_Ra
::svn_ra_reparent
($self->{session
}, $old_url, $pool);
4115 $self->{url
} = $old_url;
4119 $editor->{git_commit_ok
};
4122 sub longest_common_path
{
4123 my ($gsv, $globs) = @_;
4125 my $common_max = scalar @
$gsv;
4127 foreach my $gs (@
$gsv) {
4128 my @tmp = split m
#/#, $gs->{path};
4131 $p .= length($p) ?
"/$_" : $_;
4137 $common_max += scalar @
$globs;
4138 foreach my $glob (@
$globs) {
4139 my @tmp = split m
#/#, $glob->{path}->{left};
4142 $p .= length($p) ?
"/$_" : $_;
4148 my $longest_path = '';
4149 foreach (sort {length $b <=> length $a} keys %common) {
4150 if ($common{$_} == $common_max) {
4158 sub gs_fetch_loop_common
{
4159 my ($self, $base, $head, $gsv, $globs) = @_;
4160 return if ($base > $head);
4161 my $inc = $_log_window_size;
4162 my ($min, $max) = ($base, $head < $base + $inc ?
$head : $base + $inc);
4163 my $longest_path = longest_common_path
($gsv, $globs);
4164 my $ra_url = $self->{url
};
4168 my $err_handler = $SVN::Error
::handler
;
4169 $SVN::Error
::handler
= sub {
4171 skip_unknown_revs
($err);
4174 my ($paths, $r, $author, $date, $log) = @_;
4175 [ dup_changed_paths
($paths),
4176 { author
=> $author, date
=> $date, log => $log } ];
4178 $self->get_log([$longest_path], $min, $max, 0, 1, 1,
4179 sub { $revs{$_[1]} = _cb
(@_) });
4180 if ($err && $max >= $head) {
4181 print STDERR
"Path '$longest_path' ",
4182 "was probably deleted:\n",
4183 $err->expanded_message,
4184 "\nWill attempt to follow ",
4185 "revisions r$min .. r$max ",
4186 "committed before the deletion\n";
4188 while (--$hi >= $min) {
4190 $self->get_log([$longest_path], $min, $hi,
4193 $revs{$_[1]} = _cb
(@_) });
4195 print STDERR
"r$min .. r$ok OK\n";
4200 $SVN::Error
::handler
= $err_handler;
4202 my %exists = map { $_->{path
} => $_ } @
$gsv;
4203 foreach my $r (sort {$a <=> $b} keys %revs) {
4204 my ($paths, $logged) = @
{$revs{$r}};
4206 foreach my $gs ($self->match_globs(\
%exists, $paths,
4208 if ($gs->rev_map_max >= $r) {
4211 next unless $gs->match_paths($paths, $r);
4212 $gs->{logged_rev_props
} = $logged;
4213 if (my $last_commit = $gs->last_commit) {
4214 $gs->assert_index_clean($last_commit);
4216 my $log_entry = $gs->do_fetch($paths, $r);
4218 $gs->do_git_commit($log_entry);
4220 $INDEX_FILES{$gs->{index}} = 1;
4222 foreach my $g (@
$globs) {
4223 my $k = "svn-remote.$g->{remote}." .
4225 Git
::SVN
::tmp_config
($k, $r);
4231 $self = Git
::SVN
::Ra
->new($ra_url);
4232 $ra_invalid = undef;
4235 # pre-fill the .rev_db since it'll eventually get filled in
4236 # with '0' x40 if something new gets committed
4237 foreach my $gs (@
$gsv) {
4238 next if $gs->rev_map_max >= $max;
4239 next if defined $gs->rev_map_get($max);
4240 $gs->rev_map_set($max, 0 x40
);
4242 foreach my $g (@
$globs) {
4243 my $k = "svn-remote.$g->{remote}.$g->{t}-maxRev";
4244 Git
::SVN
::tmp_config
($k, $max);
4246 last if $max >= $head;
4249 $max = $head if ($max > $head);
4254 sub get_dir_globbed
{
4255 my ($self, $left, $depth, $r) = @_;
4257 my @x = eval { $self->get_dir($left, $r) };
4258 return unless scalar @x == 3;
4259 my $dirents = $x[0];
4261 foreach my $de (keys %$dirents) {
4262 next if $dirents->{$de}->{kind
} != $SVN::Node
::dir
;
4264 my @args = ("$left/$de", $depth - 1, $r);
4265 foreach my $dir ($self->get_dir_globbed(@args)) {
4266 push @finalents, "$de/$dir";
4269 push @finalents, $de;
4276 my ($self, $exists, $paths, $globs, $r) = @_;
4279 my ($self, $exists, $g, $r) = @_;
4281 my @dirs = $self->get_dir_globbed($g->{path
}->{left
},
4282 $g->{path
}->{depth
},
4285 foreach my $de (@dirs) {
4286 my $p = $g->{path
}->full_path($de);
4287 next if $exists->{$p};
4288 next if (length $g->{path
}->{right
} &&
4289 ($self->check_path($p, $r) !=
4291 $exists->{$p} = Git
::SVN
->init($self->{url
}, $p, undef,
4292 $g->{ref}->full_path($de), 1);
4295 foreach my $g (@
$globs) {
4296 if (my $path = $paths->{"/$g->{path}->{left}"}) {
4297 if ($path->{action
} =~ /^[AR]$/) {
4298 get_dir_check
($self, $exists, $g, $r);
4301 foreach (keys %$paths) {
4302 if (/$g->{path}->{left_regex}/ &&
4303 !/$g->{path}->{regex}/) {
4304 next if $paths->{$_}->{action
} !~ /^[AR]$/;
4305 get_dir_check
($self, $exists, $g, $r);
4307 next unless /$g->{path}->{regex}/;
4309 my $pathname = $g->{path
}->full_path($p);
4310 next if $exists->{$pathname};
4311 next if ($self->check_path($pathname, $r) !=
4313 $exists->{$pathname} = Git
::SVN
->init(
4314 $self->{url
}, $pathname, undef,
4315 $g->{ref}->full_path($p), 1);
4318 foreach (split m
#/#, $g->{path}->{left}) {
4320 next unless ($paths->{$c} &&
4321 ($paths->{$c}->{action
} =~ /^[AR]$/));
4322 get_dir_check
($self, $exists, $g, $r);
4330 return $self->{url
} if ($self->{url
} eq $self->{repos_root
});
4331 my $url = $self->{repos_root
};
4332 my @components = split(m!/!, $self->{svn_path
});
4335 $url .= "/$c" if length $c;
4336 eval { (ref $self)->new($url)->get_latest_revnum };
4337 } while ($@
&& ($c = shift @components));
4343 unless (defined $can_do_switch) {
4344 my $pool = SVN
::Pool
->new;
4346 $self->do_switch(1, '', 0, $self->{url
},
4347 SVN
::Delta
::Editor
->new, $pool);
4352 $rep->abort_report($pool);
4360 sub skip_unknown_revs
{
4362 my $errno = $err->apr_err();
4363 # Maybe the branch we're tracking didn't
4364 # exist when the repo started, so it's
4365 # not an error if it doesn't, just continue
4367 # Wonderfully consistent library, eh?
4368 # 160013 - svn:// and file://
4369 # 175002 - http(s)://
4370 # 175007 - http(s):// (this repo required authorization, too...)
4371 # More codes may be discovered later...
4372 if ($errno == 175007 || $errno == 175002 || $errno == 160013) {
4373 my $err_key = $err->expanded_message;
4374 # revision numbers change every time, filter them out
4375 $err_key =~ s/\d+/\0/g;
4376 $err_key = "$errno\0$err_key";
4377 unless ($ignored_err{$err_key}) {
4378 warn "W: Ignoring error from SVN, path probably ",
4379 "does not exist: ($errno): ",
4380 $err->expanded_message,"\n";
4381 warn "W: Do not be alarmed at the above message ",
4382 "git-svn is just searching aggressively for ",
4384 "This may take a while on large repositories\n";
4385 $ignored_err{$err_key} = 1;
4389 die "Error from SVN, ($errno): ", $err->expanded_message,"\n";
4392 # svn_log_changed_path_t objects passed to get_log are likely to be
4393 # overwritten even if only the refs are copied to an external variable,
4394 # so we should dup the structures in their entirety. Using an externally
4395 # passed pool (instead of our temporary and quickly cleared pool in
4396 # Git::SVN::Ra) does not help matters at all...
4397 sub dup_changed_paths
{
4399 return undef unless $paths;
4401 foreach my $p (keys %$paths) {
4402 my $i = $paths->{$p};
4403 my %s = map { $_ => $i->$_ }
4404 qw
/copyfrom_path copyfrom_rev action/;
4410 package Git
::SVN
::Log
;
4413 use POSIX qw
/strftime/;
4414 use constant commit_log_separator
=> ('-' x
72) . "\n";
4415 use vars qw
/$TZ $limit $color $pager $non_recursive $verbose $oneline
4416 %rusers $show_commit $incremental/;
4421 return 1 if defined $c->{r
};
4423 # big commit message got truncated by the 16k pretty buffer in rev-list
4424 if ($c->{l
} && $c->{l
}->[-1] eq "...\n" &&
4425 $c->{a_raw
} =~ /\@([a-f\d\-]+)>$/) {
4427 my @log = command
(qw
/cat-file commit/, $c->{c
});
4429 # shift off the headers
4430 shift @log while ($log[0] ne '');
4433 # TODO: make $c->{l} not have a trailing newline in the future
4434 @
{$c->{l
}} = map { "$_\n" } grep !/^git-svn-id: /, @log;
4436 (undef, $c->{r
}, undef) = ::extract_metadata
(
4437 (grep(/^git-svn-id: /, @log))[-1]);
4439 return defined $c->{r
};
4443 return $color || Git
->repository->get_colorbool('color.diff');
4446 sub git_svn_log_cmd
{
4447 my ($r_min, $r_max, @args) = @_;
4449 my (@files, @log_opts);
4450 foreach my $x (@args) {
4451 if ($x eq '--' || @files) {
4454 if (::verify_ref
("$x^0")) {
4462 my ($url, $rev, $uuid, $gs) = ::working_head_info
($head);
4463 $gs ||= Git
::SVN
->_new;
4464 my @cmd = (qw
/log --abbrev-commit --pretty=raw --default/,
4466 push @cmd, '-r' unless $non_recursive;
4467 push @cmd, qw
/--raw --name-status/ if $verbose;
4468 push @cmd, '--color' if log_use_color
();
4469 push @cmd, @log_opts;
4470 if (defined $r_max && $r_max == $r_min) {
4471 push @cmd, '--max-count=1';
4472 if (my $c = $gs->rev_map_get($r_max)) {
4475 } elsif (defined $r_max) {
4476 if ($r_max < $r_min) {
4477 ($r_min, $r_max) = ($r_max, $r_min);
4479 my (undef, $c_max) = $gs->find_rev_before($r_max, 1, $r_min);
4480 my (undef, $c_min) = $gs->find_rev_after($r_min, 1, $r_max);
4481 # If there are no commits in the range, both $c_max and $c_min
4482 # will be undefined. If there is at least 1 commit in the
4483 # range, both will be defined.
4484 return () if !defined $c_min || !defined $c_max;
4485 if ($c_min eq $c_max) {
4486 push @cmd, '--max-count=1', $c_min;
4488 push @cmd, '--boundary', "$c_min..$c_max";
4491 return (@cmd, @files);
4494 # adapted from pager.c
4496 $pager ||= $ENV{GIT_PAGER
} || $ENV{PAGER
};
4497 if (!defined $pager) {
4499 } elsif (length $pager == 0 || $pager eq 'cat') {
4502 $ENV{GIT_PAGER_IN_USE
} = defined($pager);
4506 return unless -t
*STDOUT
&& defined $pager;
4507 pipe my ($rfd, $wfd) or return;
4508 defined(my $pid = fork) or ::fatal
"Can't fork: $!";
4510 open STDOUT
, '>&', $wfd or
4511 ::fatal
"Can't redirect to stdout: $!";
4514 open STDIN
, '<&', $rfd or ::fatal
"Can't redirect stdin: $!";
4515 $ENV{LESS
} ||= 'FRSX';
4516 exec $pager or ::fatal
"Can't run pager: $! ($pager)";
4519 sub format_svn_date
{
4520 return strftime
("%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)", localtime(shift));
4523 sub parse_git_date
{
4525 # Date::Parse isn't in the standard Perl distro :(
4526 if ($tz =~ s/^\+//) {
4527 $t += tz_to_s_offset
($tz);
4528 } elsif ($tz =~ s/^\-//) {
4529 $t -= tz_to_s_offset
($tz);
4534 sub set_local_timezone
{
4542 sub tz_to_s_offset
{
4545 return ($1 * 60) + ($tz * 3600);
4548 sub get_author_info
{
4549 my ($dest, $author, $t, $tz) = @_;
4550 $author =~ s/(?:^\s*|\s*$)//g;
4551 $dest->{a_raw
} = $author;
4554 $au = $rusers{$author} || undef;
4557 ($au) = ($author =~ /<([^>]+)\@[^>]+>$/);
4562 $dest->{t_utc
} = parse_git_date
($t, $tz);
4565 sub process_commit
{
4566 my ($c, $r_min, $r_max, $defer) = @_;
4567 if (defined $r_min && defined $r_max) {
4568 if ($r_min == $c->{r
} && $r_min == $r_max) {
4572 return 1 if $r_min == $r_max;
4573 if ($r_min < $r_max) {
4574 # we need to reverse the print order
4575 return 0 if (defined $limit && --$limit < 0);
4579 if ($r_min != $r_max) {
4580 return 1 if ($r_min < $c->{r
});
4581 return 1 if ($r_max > $c->{r
});
4584 return 0 if (defined $limit && --$limit < 0);
4593 if (my $l = $c->{l
}) {
4594 while ($l->[0] =~ /^\s*$/) { shift @
$l }
4597 $l_fmt ||= 'A' . length($c->{r
});
4598 print 'r',pack($l_fmt, $c->{r
}),' | ';
4599 print "$c->{c} | " if $show_commit;
4602 show_commit_normal
($c);
4606 sub show_commit_changed_paths
{
4608 return unless $c->{changed
};
4609 print "Changed paths:\n", @
{$c->{changed
}};
4612 sub show_commit_normal
{
4614 print commit_log_separator
, "r$c->{r} | ";
4615 print "$c->{c} | " if $show_commit;
4616 print "$c->{a} | ", format_svn_date
($c->{t_utc
}), ' | ';
4619 if (my $l = $c->{l
}) {
4620 while ($l->[$#$l] eq "\n" && $#$l > 0
4621 && $l->[($#$l - 1)] eq "\n") {
4624 $nr_line = scalar @
$l;
4626 print "1 line\n\n\n";
4628 if ($nr_line == 1) {
4629 $nr_line = '1 line';
4631 $nr_line .= ' lines';
4633 print $nr_line, "\n";
4634 show_commit_changed_paths
($c);
4636 print $_ foreach @
$l;
4640 show_commit_changed_paths
($c);
4644 foreach my $x (qw
/raw stat diff/) {
4647 print $_ foreach @
{$c->{$x}}
4654 my ($r_min, $r_max);
4655 my $r_last = -1; # prevent dupes
4656 set_local_timezone
();
4657 if (defined $::_revision
) {
4658 if ($::_revision
=~ /^(\d+):(\d+)$/) {
4659 ($r_min, $r_max) = ($1, $2);
4660 } elsif ($::_revision
=~ /^\d+$/) {
4661 $r_min = $r_max = $::_revision
;
4663 ::fatal
"-r$::_revision is not supported, use ",
4664 "standard 'git log' arguments instead";
4669 @args = git_svn_log_cmd
($r_min, $r_max, @args);
4671 print commit_log_separator
unless $incremental || $oneline;
4674 my $log = command_output_pipe
(@args);
4676 my (@k, $c, $d, $stat);
4677 my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/;
4679 if (/^${esc_color}commit -?($::sha1_short)/o) {
4681 if ($c && cmt_showable
($c) && $c->{r
} != $r_last) {
4683 process_commit
($c, $r_min, $r_max, \
@k) or
4688 } elsif (/^${esc_color}author (.+) (\d+) ([\-\+]?\d+)$/o) {
4689 get_author_info
($c, $1, $2, $3);
4690 } elsif (/^${esc_color}(?:tree|parent|committer) /o) {
4692 } elsif (/^${esc_color}:\d{6} \d{6} $::sha1_short/o) {
4693 push @
{$c->{raw
}}, $_;
4694 } elsif (/^${esc_color}[ACRMDT]\t/) {
4695 # we could add $SVN->{svn_path} here, but that requires
4696 # remote access at the moment (repo_path_split)...
4697 s
#^(${esc_color})([ACRMDT])\t#$1 $2 #o;
4698 push @
{$c->{changed
}}, $_;
4699 } elsif (/^${esc_color}diff /o) {
4701 push @
{$c->{diff
}}, $_;
4703 push @
{$c->{diff
}}, $_;
4704 } elsif (/^\
.+\ \
|\s
*\d
+\
$esc_color[\
+\
-]*
4705 $esc_color*[\
+\
-]*$esc_color$/x
) {
4707 push @
{$c->{stat}}, $_;
4708 } elsif ($stat && /^ \d+ files changed, \d+ insertions/) {
4709 push @
{$c->{stat}}, $_;
4711 } elsif (/^${esc_color} (git-svn-id:.+)$/o) {
4712 ($c->{url
}, $c->{r
}, undef) = ::extract_metadata
($1);
4713 } elsif (s/^${esc_color} //o) {
4714 push @
{$c->{l
}}, $_;
4717 if ($c && defined $c->{r
} && $c->{r
} != $r_last) {
4719 process_commit
($c, $r_min, $r_max, \
@k);
4722 ($r_min, $r_max) = ($r_max, $r_min);
4723 process_commit
($_, $r_min, $r_max) foreach reverse @k;
4727 print commit_log_separator
unless $incremental || $oneline;
4736 my ($fh, $ctx, $rev);
4739 ($fh, $ctx) = command_output_pipe
('blame', @_, $path);
4740 while (my $line = <$fh>) {
4741 if ($line =~ /^\^?([[:xdigit:]]+)\s/) {
4742 # Uncommitted edits show up as a rev ID of
4743 # all zeros, which we can't look up with
4746 (undef, $rev, undef) =
4748 $rev = '0' if (!$rev);
4752 $rev = sprintf('%-10s', $rev);
4753 $line =~ s/^\^?[[:xdigit:]]+(\s)/$rev$1/;
4758 ($fh, $ctx) = command_output_pipe
('blame', '-p', @_, 'HEAD',
4762 while (my $line = <$fh>) {
4763 if ($line =~ /^([[:xdigit:]]{40})\s\d+\s\d+/) {
4765 (undef, $rev, undef) = ::cmt_metadata
($1);
4766 $rev = '0' if (!$rev);
4768 elsif ($line =~ /^author (.*)/) {
4769 $authors{$rev} = $1;
4770 $authors{$rev} =~ s/\s/_/g;
4772 elsif ($line =~ /^\t(.*)$/) {
4773 printf("%6s %10s %s\n", $rev, $authors{$rev}, $1);
4777 command_close_pipe
($fh, $ctx);
4780 package Git
::SVN
::Migration
;
4781 # these version numbers do NOT correspond to actual version numbers
4782 # of git nor git-svn. They are just relative.
4784 # v0 layout: .git/$id/info/url, refs/heads/$id-HEAD
4786 # v1 layout: .git/$id/info/url, refs/remotes/$id
4788 # v2 layout: .git/svn/$id/info/url, refs/remotes/$id
4790 # v3 layout: .git/svn/$id, refs/remotes/$id
4791 # - info/url may remain for backwards compatibility
4792 # - this is what we migrate up to this layout automatically,
4793 # - this will be used by git svn init on single branches
4794 # v3.1 layout (auto migrated):
4795 # - .rev_db => .rev_db.$UUID, .rev_db will remain as a symlink
4796 # for backwards compatibility
4798 # v4 layout: .git/svn/$repo_id/$id, refs/remotes/$repo_id/$id
4799 # - this is only created for newly multi-init-ed
4800 # repositories. Similar in spirit to the
4801 # --use-separate-remotes option in git-clone (now default)
4802 # - we do not automatically migrate to this (following
4803 # the example set by core git)
4805 # v5 layout: .rev_db.$UUID => .rev_map.$UUID
4806 # - newer, more-efficient format that uses 24-bytes per record
4807 # with no filler space.
4808 # - use xxd -c24 < .rev_map.$UUID to view and debug
4809 # - This is a one-way migration, repositories updated to the
4810 # new format will not be able to use old git-svn without
4811 # rebuilding the .rev_db. Rebuilding the rev_db is not
4812 # possible if noMetadata or useSvmProps are set; but should
4813 # be no problem for users that use the (sensible) defaults.
4817 use File
::Path qw
/mkpath/;
4818 use File
::Basename qw
/dirname basename/;
4819 use vars qw
/$_minimize/;
4821 sub migrate_from_v0
{
4822 my $git_dir = $ENV{GIT_DIR
};
4823 return undef unless -d
$git_dir;
4824 my ($fh, $ctx) = command_output_pipe
(qw
/rev-parse --symbolic --all/);
4828 my ($id, $orig_ref) = ($_, $_);
4829 next unless $id =~ s
#^refs/heads/(.+)-HEAD$#$1#;
4830 next unless -f
"$git_dir/$id/info/url";
4831 my $new_ref = "refs/remotes/$id";
4832 if (::verify_ref
("$new_ref^0")) {
4833 print STDERR
"W: $orig_ref is probably an old ",
4834 "branch used by an ancient version of ",
4836 "However, $new_ref also exists.\n",
4837 "We will not be able ",
4838 "to use this branch until this ",
4839 "ambiguity is resolved.\n";
4842 print STDERR
"Migrating from v0 layout...\n" if !$migrated;
4843 print STDERR
"Renaming ref: $orig_ref => $new_ref\n";
4844 command_noisy
('update-ref', $new_ref, $orig_ref);
4845 command_noisy
('update-ref', '-d', $orig_ref, $orig_ref);
4848 command_close_pipe
($fh, $ctx);
4849 print STDERR
"Done migrating from v0 layout...\n" if $migrated;
4853 sub migrate_from_v1
{
4854 my $git_dir = $ENV{GIT_DIR
};
4856 return $migrated unless -d
$git_dir;
4857 my $svn_dir = "$git_dir/svn";
4859 # just in case somebody used 'svn' as their $id at some point...
4860 return $migrated if -d
$svn_dir && ! -f
"$svn_dir/info/url";
4862 print STDERR
"Migrating from a git-svn v1 layout...\n";
4864 print STDERR
"Data from a previous version of git-svn exists, but\n\t",
4865 "$svn_dir\n\t(required for this version ",
4866 "($::VERSION) of git-svn) does not exist.\n";
4867 my ($fh, $ctx) = command_output_pipe
(qw
/rev-parse --symbolic --all/);
4870 next unless $x =~ s
#^refs/remotes/##;
4872 next unless -f
"$git_dir/$x/info/url";
4873 my $u = eval { ::file_to_s
("$git_dir/$x/info/url") };
4875 my $dn = dirname
("$git_dir/svn/$x");
4876 mkpath
([$dn]) unless -d
$dn;
4877 if ($x eq 'svn') { # they used 'svn' as GIT_SVN_ID:
4878 mkpath
(["$git_dir/svn/svn"]);
4879 print STDERR
" - $git_dir/$x/info => ",
4880 "$git_dir/svn/$x/info\n";
4881 rename "$git_dir/$x/info", "$git_dir/svn/$x/info" or
4883 # don't worry too much about these, they probably
4884 # don't exist with repos this old (save for index,
4885 # and we can easily regenerate that)
4886 foreach my $f (qw
/unhandled.log index .rev_db/) {
4887 rename "$git_dir/$x/$f", "$git_dir/svn/$x/$f";
4890 print STDERR
" - $git_dir/$x => $git_dir/svn/$x\n";
4891 rename "$git_dir/$x", "$git_dir/svn/$x" or
4896 command_close_pipe
($fh, $ctx);
4897 print STDERR
"Done migrating from a git-svn v1 layout\n";
4902 my ($l_map, $pfx, $path) = @_;
4904 foreach (<$path/*>) {
4905 if (-r
"$_/info/url") {
4906 $pfx .= '/' if $pfx && $pfx !~ m
!/$!;
4907 my $ref_id = $pfx . basename
$_;
4908 my $url = ::file_to_s
("$_/info/url");
4909 $l_map->{$ref_id} = $url;
4916 $x =~ s!^\Q$ENV{GIT_DIR}\E/svn/!!o;
4917 read_old_urls
($l_map, $x, $_);
4921 sub migrate_from_v2
{
4922 my @cfg = command
(qw
/config -l/);
4923 return if grep /^svn-remote\..+\.url=/, @cfg;
4925 read_old_urls
(\
%l_map, '', "$ENV{GIT_DIR}/svn");
4928 foreach my $ref_id (sort keys %l_map) {
4929 eval { Git
::SVN
->init($l_map{$ref_id}, '', undef, $ref_id) };
4931 Git
::SVN
->init($l_map{$ref_id}, '', $ref_id, $ref_id);
4938 sub minimize_connections
{
4939 my $r = Git
::SVN
::read_all_remotes
();
4941 my $root_repos = {};
4942 foreach my $repo_id (keys %$r) {
4943 my $url = $r->{$repo_id}->{url
} or next;
4944 my $fetch = $r->{$repo_id}->{fetch
} or next;
4945 my $ra = Git
::SVN
::Ra
->new($url);
4947 # skip existing cases where we already connect to the root
4948 if (($ra->{url
} eq $ra->{repos_root
}) ||
4949 ($ra->{repos_root
} eq $repo_id)) {
4950 $root_repos->{$ra->{url
}} = $repo_id;
4954 my $root_ra = Git
::SVN
::Ra
->new($ra->{repos_root
});
4955 my $root_path = $ra->{url
};
4956 $root_path =~ s
#^\Q$ra->{repos_root}\E(/|$)##;
4957 foreach my $path (keys %$fetch) {
4958 my $ref_id = $fetch->{$path};
4959 my $gs = Git
::SVN
->new($ref_id, $repo_id, $path);
4961 # make sure we can read when connecting to
4962 # a higher level of a repository
4963 my ($last_rev, undef) = $gs->last_rev_commit;
4964 if (!defined $last_rev) {
4966 $root_ra->get_latest_revnum;
4970 my $new = $root_path;
4971 $new .= length $path ?
"/$path" : '';
4973 $root_ra->get_log([$new], $last_rev, $last_rev,
4977 $new_urls->{$ra->{repos_root
}}->{$new} =
4978 { ref_id
=> $ref_id,
4979 old_repo_id
=> $repo_id,
4980 old_path
=> $path };
4985 foreach my $url (keys %$new_urls) {
4986 # see if we can re-use an existing [svn-remote "repo_id"]
4987 # instead of creating a(n ugly) new section:
4988 my $repo_id = $root_repos->{$url} || $url;
4990 my $fetch = $new_urls->{$url};
4991 foreach my $path (keys %$fetch) {
4992 my $x = $fetch->{$path};
4993 Git
::SVN
->init($url, $path, $repo_id, $x->{ref_id
});
4994 my $pfx = "svn-remote.$x->{old_repo_id}";
4996 my $old_fetch = quotemeta("$x->{old_path}:".
4997 "refs/remotes/$x->{ref_id}");
4998 command_noisy
(qw
/config --unset/,
4999 "$pfx.fetch", '^'. $old_fetch . '$');
5000 delete $r->{$x->{old_repo_id
}}->
5001 {fetch
}->{$x->{old_path
}};
5002 if (!keys %{$r->{$x->{old_repo_id
}}->{fetch
}}) {
5003 command_noisy
(qw
/config --unset/,
5005 push @emptied, $x->{old_repo_id
}
5010 my $file = $ENV{GIT_CONFIG
} || $ENV{GIT_CONFIG_LOCAL
} ||
5011 "$ENV{GIT_DIR}/config";
5013 The following [svn-remote] sections in your config file ($file) are empty
5014 and can be safely removed:
5016 print STDERR
"[svn-remote \"$_\"]\n" foreach @emptied;
5020 sub migration_check
{
5024 minimize_connections
() if $_minimize;
5027 package Git
::IndexInfo
;
5030 use Git qw
/command_input_pipe command_close_pipe/;
5034 my ($gui, $ctx) = command_input_pipe
(qw
/update-index -z --index-info/);
5035 bless { gui
=> $gui, ctx
=> $ctx, nr
=> 0}, $class;
5039 my ($self, $path) = @_;
5040 if (print { $self->{gui
} } '0 ', 0 x
40, "\t", $path, "\0") {
5041 return ++$self->{nr
};
5047 my ($self, $mode, $hash, $path) = @_;
5048 if (print { $self->{gui
} } $mode, ' ', $hash, "\t", $path, "\0") {
5049 return ++$self->{nr
};
5056 command_close_pipe
($self->{gui
}, $self->{ctx
});
5059 package Git
::SVN
::GlobSpec
;
5064 my ($class, $glob) = @_;
5066 $re =~ s!/+$!!g; # no need for trailing slashes
5067 $re =~ m!^([^*]*)(\*(?:/\*)*)([^*]*)$!;
5069 my ($left, $right) = ($1, $3);
5071 my $depth = $re =~ tr/*/*/;
5072 if ($depth != $temp =~ tr/*/*/) {
5073 die "Only one set of wildcard directories " .
5074 "(e.g. '*' or '*/*/*') is supported: '$glob'\n";
5077 die "One '*' is needed for glob: '$glob'\n";
5079 $re =~ s!\*!\[^/\]*!g;
5080 $re = quotemeta($left) . "($re)" . quotemeta($right);
5081 if (length $left && !($left =~ s!/+$!!g)) {
5082 die "Missing trailing '/' on left side of: '$glob' ($left)\n";
5084 if (length $right && !($right =~ s!^/+!!g)) {
5085 die "Missing leading '/' on right side of: '$glob' ($right)\n";
5087 my $left_re = qr/^\/\Q
$left\E
(\
/|$)/;
5088 bless { left
=> $left, right
=> $right, left_regex
=> $left_re,
5089 regex
=> qr/$re/, glob => $glob, depth
=> $depth }, $class;
5093 my ($self, $path) = @_;
5094 return (length $self->{left
} ?
"$self->{left}/" : '') .
5095 $path . (length $self->{right
} ?
"/$self->{right}" : '');
5103 $remotes = { # returned by read_all_remotes()
5105 # svn-remote.svn.url=https://svn.musicpd.org
5106 url
=> 'https://svn.musicpd.org',
5107 # svn-remote.svn.fetch=mpd/trunk:trunk
5109 'mpd/trunk' => 'trunk',
5111 # svn-remote.svn.tags=mpd/tags/*:tags/*
5116 regex
=> qr!mpd/tags/([^/]+)$!,
5122 regex
=> qr!tags/([^/]+)$!,
5129 $log_entry hashref as returned by libsvn_log_entry
()
5131 log => 'whitespace-formatted log entry
5132 ', # trailing newline is preserved
5133 revision
=> '8', # integer
5134 date
=> '2004-02-24T17:01:44.108345Z', # commit date
5135 author
=> 'committer name'
5139 # this is generated by generate_diff();
5140 @mods = array of diff
-index line hashes
, each element represents one line
5141 of diff
-index output
5143 diff
-index line
($m hash
)
5145 mode_a
=> first column of diff
-index output
, no leading
':',
5146 mode_b
=> second column of diff
-index output
,
5147 sha1_b
=> sha1sum of the final blob
,
5148 chg
=> change type
[MCRADT
],
5149 file_a
=> original file name of a file
(iff chg is
'C' or 'R')
5150 file_b
=> new
/current file name of a file
(any chg
)
5154 # retval of read_url_paths{,_all}();
5156 # repository root url
5157 'https://svn.musicpd.org' => {
5158 # repository path # GIT_SVN_ID
5159 'mpd/trunk' => 'trunk',
5160 'mpd/tags/0.11.5' => 'tags/0.11.5',
5165 I don
't trust the each() function on unless I created %hash myself
5166 because the internal iterator may not have started at base.