]>
Commit | Line | Data |
---|---|---|
3397f9df | 1 | #!/usr/bin/env perl |
551ce28f EW |
2 | # Copyright (C) 2006, Eric Wong <normalperson@yhbt.net> |
3 | # License: GPL v2 or later | |
3397f9df EW |
4 | use warnings; |
5 | use strict; | |
6 | use vars qw/ $AUTHOR $VERSION | |
9760adcc EW |
7 | $sha1 $sha1_short $_revision |
8 | $_q $_authors %users/; | |
3397f9df | 9 | $AUTHOR = 'Eric Wong <normalperson@yhbt.net>'; |
60d02ccc | 10 | $VERSION = '@@GIT_VERSION@@'; |
13ccd6d4 | 11 | |
5253dc33 | 12 | my $git_dir_user_set = 1 if defined $ENV{GIT_DIR}; |
706587fc | 13 | $ENV{GIT_DIR} ||= '.git'; |
9fa00b65 | 14 | $Git::SVN::default_repo_id = 'svn'; |
8b8fc068 | 15 | $Git::SVN::default_ref_id = $ENV{GIT_SVN_ID} || 'git-svn'; |
6af1db44 | 16 | $Git::SVN::Ra::_log_window_size = 100; |
13ccd6d4 | 17 | |
f8c9d1d2 | 18 | $Git::SVN::Log::TZ = $ENV{TZ}; |
3397f9df | 19 | $ENV{TZ} = 'UTC'; |
a00439ac | 20 | $| = 1; # unbuffer STDOUT |
3397f9df | 21 | |
6fda05ae | 22 | sub fatal (@) { print STDERR @_; exit 1 } |
b9c85187 EW |
23 | require SVN::Core; # use()-ing this causes segfaults for me... *shrug* |
24 | require SVN::Ra; | |
25 | require SVN::Delta; | |
26 | if ($SVN::Core::VERSION lt '1.1.0') { | |
27 | fatal "Need SVN::Core 1.1.0 or better (got $SVN::Core::VERSION)\n"; | |
28 | } | |
d81bf827 | 29 | push @Git::SVN::Ra::ISA, 'SVN::Ra'; |
b9c85187 EW |
30 | push @SVN::Git::Editor::ISA, 'SVN::Delta::Editor'; |
31 | push @SVN::Git::Fetcher::ISA, 'SVN::Delta::Editor'; | |
3397f9df EW |
32 | use Carp qw/croak/; |
33 | use IO::File qw//; | |
34 | use File::Basename qw/dirname basename/; | |
35 | use File::Path qw/mkpath/; | |
512b620b | 36 | use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/; |
968bdf1f | 37 | use IPC::Open3; |
336f1714 | 38 | use Git; |
a5e0cedc | 39 | |
336f1714 | 40 | BEGIN { |
c5f71ad0 SV |
41 | # import functions from Git into our packages, en masse |
42 | no strict 'refs'; | |
336f1714 EW |
43 | foreach (qw/command command_oneline command_noisy command_output_pipe |
44 | command_input_pipe command_close_pipe/) { | |
c5f71ad0 SV |
45 | for my $package ( qw(SVN::Git::Editor SVN::Git::Fetcher |
46 | Git::SVN::Migration Git::SVN::Log Git::SVN), | |
47 | __PACKAGE__) { | |
48 | *{"${package}::$_"} = \&{"Git::$_"}; | |
49 | } | |
336f1714 | 50 | } |
336f1714 EW |
51 | } |
52 | ||
b9c85187 | 53 | my ($SVN); |
83e9940a | 54 | |
f8c9d1d2 EW |
55 | $sha1 = qr/[a-f\d]{40}/; |
56 | $sha1_short = qr/[a-f\d]{4,40}/; | |
44320b9e | 57 | my ($_stdin, $_help, $_edit, |
9760adcc | 58 | $_message, $_file, |
d05d72e0 | 59 | $_template, $_shared, |
171af110 | 60 | $_version, $_fetch_all, $_no_rebase, |
dee41f3e | 61 | $_merge, $_strategy, $_dry_run, $_local, |
905f8b7d | 62 | $_prefix, $_no_checkout, $_verbose); |
0bed5eaa | 63 | $Git::SVN::_follow_parent = 1; |
706587fc EW |
64 | my %remote_opts = ( 'username=s' => \$Git::SVN::Prompt::_username, |
65 | 'config-dir=s' => \$Git::SVN::Ra::config_dir, | |
66 | 'no-auth-cache' => \$Git::SVN::Prompt::_no_auth_cache ); | |
0bed5eaa | 67 | my %fc_opts = ( 'follow-parent|follow!' => \$Git::SVN::_follow_parent, |
dc5869c0 | 68 | 'authors-file|A=s' => \$_authors, |
ecc712dd | 69 | 'repack:i' => \$Git::SVN::_repack, |
97ae0911 EW |
70 | 'noMetadata' => \$Git::SVN::_no_metadata, |
71 | 'useSvmProps' => \$Git::SVN::_use_svm_props, | |
62e349d2 | 72 | 'useSvnsyncProps' => \$Git::SVN::_use_svnsync_props, |
6af1db44 | 73 | 'log-window-size=i' => \$Git::SVN::Ra::_log_window_size, |
1e889ef3 | 74 | 'no-checkout' => \$_no_checkout, |
80f50749 | 75 | 'quiet|q' => \$_q, |
ecc712dd EW |
76 | 'repack-flags|repack-args|repack-opts=s' => |
77 | \$Git::SVN::_repack_flags, | |
706587fc | 78 | %remote_opts ); |
36f5b1f0 | 79 | |
9d55b41a | 80 | my ($_trunk, $_tags, $_branches); |
0dfaf0a4 | 81 | my %icv; |
dadc6d2a EW |
82 | my %init_opts = ( 'template=s' => \$_template, 'shared:s' => \$_shared, |
83 | 'trunk|T=s' => \$_trunk, 'tags|t=s' => \$_tags, | |
84 | 'branches|b=s' => \$_branches, 'prefix=s' => \$_prefix, | |
4a1bb4c3 | 85 | 'minimize-url|m' => \$Git::SVN::_minimize_url, |
0dfaf0a4 EW |
86 | 'no-metadata' => sub { $icv{noMetadata} = 1 }, |
87 | 'use-svm-props' => sub { $icv{useSvmProps} = 1 }, | |
88 | 'use-svnsync-props' => sub { $icv{useSvnsyncProps} = 1 }, | |
89 | 'rewrite-root=s' => sub { $icv{rewriteRoot} = $_[1] }, | |
dadc6d2a | 90 | %remote_opts ); |
27e9fb8d | 91 | my %cmt_opts = ( 'edit|e' => \$_edit, |
24e22aa8 EW |
92 | 'rmdir' => \$SVN::Git::Editor::_rmdir, |
93 | 'find-copies-harder' => \$SVN::Git::Editor::_find_copies_harder, | |
94 | 'l=i' => \$SVN::Git::Editor::_rename_limit, | |
95 | 'copy-similarity|C=i'=> \$SVN::Git::Editor::_cp_similarity | |
27e9fb8d | 96 | ); |
9d55b41a | 97 | |
3397f9df | 98 | my %cmd = ( |
2a3240be | 99 | fetch => [ \&cmd_fetch, "Download new revisions from SVN", |
e98671e5 | 100 | { 'revision|r=s' => \$_revision, |
905f8b7d | 101 | 'fetch-all|all' => \$_fetch_all, |
e98671e5 | 102 | %fc_opts } ], |
0425ea90 EW |
103 | clone => [ \&cmd_clone, "Initialize and fetch revisions", |
104 | { 'revision|r=s' => \$_revision, | |
105 | %fc_opts, %init_opts } ], | |
d2866f9e | 106 | init => [ \&cmd_init, "Initialize a repo for tracking" . |
f8ab6b73 | 107 | " (requires URL argument)", |
9d55b41a | 108 | \%init_opts ], |
dadc6d2a EW |
109 | 'multi-init' => [ \&cmd_multi_init, |
110 | "Deprecated alias for ". | |
111 | "'$0 init -T<trunk> -b<branches> -t<tags>'", | |
112 | \%init_opts ], | |
d7ad3bed EW |
113 | dcommit => [ \&cmd_dcommit, |
114 | 'Commit several diffs to merge with upstream', | |
3289e86e EW |
115 | { 'merge|m|M' => \$_merge, |
116 | 'strategy|s=s' => \$_strategy, | |
905f8b7d | 117 | 'verbose|v' => \$_verbose, |
3289e86e | 118 | 'dry-run|n' => \$_dry_run, |
905f8b7d | 119 | 'fetch-all|all' => \$_fetch_all, |
171af110 | 120 | 'no-rebase' => \$_no_rebase, |
4b155223 | 121 | %cmt_opts, %fc_opts } ], |
1ce255dc EW |
122 | 'set-tree' => [ \&cmd_set_tree, |
123 | "Set an SVN repository to a git tree-ish", | |
124 | { 'stdin|' => \$_stdin, %cmt_opts, %fc_opts, } ], | |
5969cbe1 | 125 | 'show-ignore' => [ \&cmd_show_ignore, "Show svn:ignore listings", |
a5e0cedc | 126 | { 'revision|r=i' => \$_revision } ], |
1c8443b0 | 127 | 'multi-fetch' => [ \&cmd_multi_fetch, |
e98671e5 EW |
128 | "Deprecated alias for $0 fetch --all", |
129 | { 'revision|r=s' => \$_revision, %fc_opts } ], | |
706587fc EW |
130 | 'migrate' => [ sub { }, |
131 | # no-op, we automatically run this anyways, | |
706587fc EW |
132 | 'Migrate configuration/metadata/layout from |
133 | previous versions of git-svn', | |
a836a0e1 EW |
134 | { 'minimize' => \$Git::SVN::Migration::_minimize, |
135 | %remote_opts } ], | |
f8c9d1d2 EW |
136 | 'log' => [ \&Git::SVN::Log::cmd_show_log, 'Show commit logs', |
137 | { 'limit=i' => \$Git::SVN::Log::limit, | |
79bb8d88 | 138 | 'revision|r=s' => \$_revision, |
f8c9d1d2 EW |
139 | 'verbose|v' => \$Git::SVN::Log::verbose, |
140 | 'incremental' => \$Git::SVN::Log::incremental, | |
141 | 'oneline' => \$Git::SVN::Log::oneline, | |
142 | 'show-commit' => \$Git::SVN::Log::show_commit, | |
143 | 'non-recursive' => \$Git::SVN::Log::non_recursive, | |
79bb8d88 | 144 | 'authors-file|A=s' => \$_authors, |
f8c9d1d2 EW |
145 | 'color' => \$Git::SVN::Log::color, |
146 | 'pager=s' => \$Git::SVN::Log::pager, | |
79bb8d88 | 147 | } ], |
26e60160 AR |
148 | 'find-rev' => [ \&cmd_find_rev, "Translate between SVN revision numbers and tree-ish", |
149 | { } ], | |
905f8b7d EW |
150 | 'rebase' => [ \&cmd_rebase, "Fetch and rebase your working directory", |
151 | { 'merge|m|M' => \$_merge, | |
152 | 'verbose|v' => \$_verbose, | |
153 | 'strategy|s=s' => \$_strategy, | |
dee41f3e | 154 | 'local|l' => \$_local, |
905f8b7d EW |
155 | 'fetch-all|all' => \$_fetch_all, |
156 | %fc_opts } ], | |
44320b9e EW |
157 | 'commit-diff' => [ \&cmd_commit_diff, |
158 | 'Commit a diff between two trees', | |
27e9fb8d EW |
159 | { 'message|m=s' => \$_message, |
160 | 'file|F=s' => \$_file, | |
45bf473a | 161 | 'revision|r=s' => \$_revision, |
27e9fb8d | 162 | %cmt_opts } ], |
3397f9df | 163 | ); |
9d55b41a | 164 | |
3397f9df EW |
165 | my $cmd; |
166 | for (my $i = 0; $i < @ARGV; $i++) { | |
167 | if (defined $cmd{$ARGV[$i]}) { | |
168 | $cmd = $ARGV[$i]; | |
169 | splice @ARGV, $i, 1; | |
170 | last; | |
171 | } | |
172 | }; | |
173 | ||
448c81b4 | 174 | my %opts = %{$cmd{$cmd}->[2]} if (defined $cmd); |
a9612be2 | 175 | |
b8c92cad | 176 | read_repo_config(\%opts); |
c284914a | 177 | Getopt::Long::Configure('pass_through') if ($cmd && $cmd eq 'log'); |
9760adcc EW |
178 | my $rv = GetOptions(%opts, 'help|H|h' => \$_help, 'version|V' => \$_version, |
179 | 'minimize-connections' => \$Git::SVN::Migration::_minimize, | |
180 | 'id|i=s' => \$Git::SVN::default_ref_id, | |
befc9adc EW |
181 | 'svn-remote|remote|R=s' => sub { |
182 | $Git::SVN::no_reuse_existing = 1; | |
183 | $Git::SVN::default_repo_id = $_[1] }); | |
c284914a | 184 | exit 1 if (!$rv && $cmd && $cmd ne 'log'); |
6f0783cf | 185 | |
3397f9df | 186 | usage(0) if $_help; |
551ce28f | 187 | version() if $_version; |
eeb0abe0 EW |
188 | usage(1) unless defined $cmd; |
189 | load_authors() if $_authors; | |
5253dc33 EW |
190 | |
191 | # make sure we're always running | |
192 | unless ($cmd =~ /(?:clone|init|multi-init)$/) { | |
193 | unless (-d $ENV{GIT_DIR}) { | |
194 | if ($git_dir_user_set) { | |
195 | die "GIT_DIR=$ENV{GIT_DIR} explicitly set, ", | |
196 | "but it is not a directory\n"; | |
197 | } | |
198 | my $git_dir = delete $ENV{GIT_DIR}; | |
199 | chomp(my $cdup = command_oneline(qw/rev-parse --show-cdup/)); | |
200 | unless (length $cdup) { | |
201 | die "Already at toplevel, but $git_dir ", | |
202 | "not found '$cdup'\n"; | |
203 | } | |
204 | chdir $cdup or die "Unable to chdir up to '$cdup'\n"; | |
205 | unless (-d $git_dir) { | |
206 | die "$git_dir still not found after going to ", | |
207 | "'$cdup'\n"; | |
208 | } | |
209 | $ENV{GIT_DIR} = $git_dir; | |
210 | } | |
211 | } | |
0425ea90 | 212 | unless ($cmd =~ /^(?:clone|init|multi-init|commit-diff)$/) { |
706587fc EW |
213 | Git::SVN::Migration::migration_check(); |
214 | } | |
ecc712dd | 215 | Git::SVN::init_vars(); |
b805b44a EW |
216 | eval { |
217 | Git::SVN::verify_remotes_sanity(); | |
218 | $cmd{$cmd}->[0]->(@ARGV); | |
219 | }; | |
220 | fatal $@ if $@; | |
1e889ef3 | 221 | post_fetch_checkout(); |
3397f9df EW |
222 | exit 0; |
223 | ||
224 | ####################### primary functions ###################### | |
225 | sub usage { | |
226 | my $exit = shift || 0; | |
227 | my $fd = $exit ? \*STDERR : \*STDOUT; | |
228 | print $fd <<""; | |
229 | git-svn - bidirectional operations between a single Subversion tree and git | |
230 | Usage: $0 <command> [options] [arguments]\n | |
448c81b4 EW |
231 | |
232 | print $fd "Available commands:\n" unless $cmd; | |
3397f9df EW |
233 | |
234 | foreach (sort keys %cmd) { | |
448c81b4 | 235 | next if $cmd && $cmd ne $_; |
a836a0e1 | 236 | next if /^multi-/; # don't show deprecated commands |
b203b769 | 237 | print $fd ' ',pack('A17',$_),$cmd{$_}->[1],"\n"; |
448c81b4 | 238 | foreach (keys %{$cmd{$_}->[2]}) { |
512b620b EW |
239 | # mixed-case options are for .git/config only |
240 | next if /[A-Z]/ && /^[a-z]+$/i; | |
448c81b4 | 241 | # prints out arguments as they should be passed: |
b8c92cad | 242 | my $x = s#[:=]s$## ? '<arg>' : s#[:=]i$## ? '<num>' : ''; |
b203b769 | 243 | print $fd ' ' x 21, join(', ', map { length $_ > 1 ? |
448c81b4 EW |
244 | "--$_" : "-$_" } |
245 | split /\|/,$_)," $x\n"; | |
246 | } | |
3397f9df EW |
247 | } |
248 | print $fd <<""; | |
448c81b4 EW |
249 | \nGIT_SVN_ID may be set in the environment or via the --id/-i switch to an |
250 | arbitrary identifier if you're tracking multiple SVN branches/repositories in | |
251 | one git repository and want to keep them separate. See git-svn(1) for more | |
252 | information. | |
3397f9df EW |
253 | |
254 | exit $exit; | |
255 | } | |
256 | ||
551ce28f | 257 | sub version { |
7d60ab2c | 258 | print "git-svn version $VERSION (svn $SVN::Core::VERSION)\n"; |
551ce28f EW |
259 | exit 0; |
260 | } | |
261 | ||
8164b652 EW |
262 | sub do_git_init_db { |
263 | unless (-d $ENV{GIT_DIR}) { | |
264 | my @init_db = ('init'); | |
265 | push @init_db, "--template=$_template" if defined $_template; | |
dadc6d2a EW |
266 | if (defined $_shared) { |
267 | if ($_shared =~ /[a-z]/) { | |
268 | push @init_db, "--shared=$_shared"; | |
269 | } else { | |
270 | push @init_db, "--shared"; | |
271 | } | |
272 | } | |
8164b652 EW |
273 | command_noisy(@init_db); |
274 | } | |
0dfaf0a4 EW |
275 | my $set; |
276 | my $pfx = "svn-remote.$Git::SVN::default_repo_id"; | |
277 | foreach my $i (keys %icv) { | |
278 | die "'$set' and '$i' cannot both be set\n" if $set; | |
279 | next unless defined $icv{$i}; | |
280 | command_noisy('config', "$pfx.$i", $icv{$i}); | |
281 | $set = $i; | |
282 | } | |
8164b652 EW |
283 | } |
284 | ||
dadc6d2a EW |
285 | sub init_subdir { |
286 | my $repo_path = shift or return; | |
287 | mkpath([$repo_path]) unless -d $repo_path; | |
288 | chdir $repo_path or die "Couldn't chdir to $repo_path: $!\n"; | |
f30603fc | 289 | $ENV{GIT_DIR} = '.git'; |
dadc6d2a EW |
290 | } |
291 | ||
0425ea90 EW |
292 | sub cmd_clone { |
293 | my ($url, $path) = @_; | |
294 | if (!defined $path && | |
295 | (defined $_trunk || defined $_branches || defined $_tags) && | |
296 | $url !~ m#^[a-z\+]+://#) { | |
297 | $path = $url; | |
298 | } | |
0425ea90 | 299 | $path = basename($url) if !defined $path || !length $path; |
f30603fc | 300 | cmd_init($url, $path); |
0425ea90 EW |
301 | Git::SVN::fetch_all($Git::SVN::default_repo_id); |
302 | } | |
303 | ||
d2866f9e | 304 | sub cmd_init { |
dadc6d2a EW |
305 | if (defined $_trunk || defined $_branches || defined $_tags) { |
306 | return cmd_multi_init(@_); | |
03e0ea87 | 307 | } |
dadc6d2a EW |
308 | my $url = shift or die "SVN repository location required ", |
309 | "as a command-line argument\n"; | |
310 | init_subdir(@_); | |
8164b652 | 311 | do_git_init_db(); |
03e0ea87 | 312 | |
706587fc | 313 | Git::SVN->init($url); |
3397f9df EW |
314 | } |
315 | ||
2a3240be | 316 | sub cmd_fetch { |
e98671e5 EW |
317 | if (grep /^\d+=./, @_) { |
318 | die "'<rev>=<commit>' fetch arguments are ", | |
319 | "no longer supported.\n"; | |
07a1c950 | 320 | } |
e98671e5 EW |
321 | my ($remote) = @_; |
322 | if (@_ > 1) { | |
905f8b7d | 323 | die "Usage: $0 fetch [--all] [svn-remote]\n"; |
e98671e5 EW |
324 | } |
325 | $remote ||= $Git::SVN::default_repo_id; | |
326 | if ($_fetch_all) { | |
327 | cmd_multi_fetch(); | |
328 | } else { | |
329 | Git::SVN::fetch_all($remote, Git::SVN::read_all_remotes()); | |
1c8443b0 | 330 | } |
2a3240be EW |
331 | } |
332 | ||
1ce255dc | 333 | sub cmd_set_tree { |
3397f9df EW |
334 | my (@commits) = @_; |
335 | if ($_stdin || !@commits) { | |
336 | print "Reading from stdin...\n"; | |
337 | @commits = (); | |
338 | while (<STDIN>) { | |
1ca72aef | 339 | if (/\b($sha1_short)\b/o) { |
3397f9df EW |
340 | unshift @commits, $1; |
341 | } | |
342 | } | |
343 | } | |
344 | my @revs; | |
8de010ad | 345 | foreach my $c (@commits) { |
aef4e921 | 346 | my @tmp = command('rev-parse',$c); |
8de010ad EW |
347 | if (scalar @tmp == 1) { |
348 | push @revs, $tmp[0]; | |
349 | } elsif (scalar @tmp > 1) { | |
aef4e921 | 350 | push @revs, reverse(command('rev-list',@tmp)); |
8de010ad | 351 | } else { |
1ce255dc | 352 | fatal "Failed to rev-parse $c\n"; |
8de010ad | 353 | } |
3397f9df | 354 | } |
1ce255dc EW |
355 | my $gs = Git::SVN->new; |
356 | my ($r_last, $cmt_last) = $gs->last_rev_commit; | |
357 | $gs->fetch; | |
97f6987a | 358 | if (defined $gs->{last_rev} && $r_last != $gs->{last_rev}) { |
1ce255dc EW |
359 | fatal "There are new revisions that were fetched ", |
360 | "and need to be merged (or acknowledged) ", | |
361 | "before committing.\nlast rev: $r_last\n", | |
362 | " current: $gs->{last_rev}\n"; | |
a5e0cedc | 363 | } |
1ce255dc EW |
364 | $gs->set_tree($_) foreach @revs; |
365 | print "Done committing ",scalar @revs," revisions to SVN\n"; | |
a5e0cedc | 366 | } |
8f22562c | 367 | |
d7ad3bed EW |
368 | sub cmd_dcommit { |
369 | my $head = shift; | |
d7ad3bed | 370 | $head ||= 'HEAD'; |
a8ae2623 | 371 | my @refs; |
13c823fb EW |
372 | my ($url, $rev, $uuid, $gs) = working_head_info($head, \@refs); |
373 | unless ($gs) { | |
a8ae2623 | 374 | die "Unable to determine upstream SVN information from ", |
905f8b7d | 375 | "$head history\n"; |
a8ae2623 | 376 | } |
45bf473a | 377 | my $last_rev; |
733a65aa EW |
378 | my ($linear_refs, $parents) = linearize_history($gs, \@refs); |
379 | foreach my $d (@$linear_refs) { | |
45bf473a EW |
380 | unless (defined $last_rev) { |
381 | (undef, $last_rev, undef) = cmt_metadata("$d~1"); | |
382 | unless (defined $last_rev) { | |
d7ad3bed EW |
383 | fatal "Unable to extract revision information ", |
384 | "from commit $d~1\n"; | |
45bf473a EW |
385 | } |
386 | } | |
b22d4497 EW |
387 | if ($_dry_run) { |
388 | print "diff-tree $d~1 $d\n"; | |
389 | } else { | |
d7ad3bed | 390 | my %ed_opts = ( r => $last_rev, |
61395354 | 391 | log => get_commit_entry($d)->{log}, |
645833b5 | 392 | ra => Git::SVN::Ra->new($gs->full_url), |
61395354 EW |
393 | tree_a => "$d~1", |
394 | tree_b => $d, | |
395 | editor_cb => sub { | |
396 | print "Committed r$_[0]\n"; | |
397 | $last_rev = $_[0]; }, | |
a8ae2623 | 398 | svn_path => ''); |
61395354 | 399 | if (!SVN::Git::Editor->new(\%ed_opts)->apply_diff) { |
d7ad3bed | 400 | print "No changes\n$d~1 == $d\n"; |
733a65aa EW |
401 | } elsif ($parents->{$d} && @{$parents->{$d}}) { |
402 | $gs->{inject_parents_dcommit}->{$last_rev} = | |
403 | $parents->{$d}; | |
d7ad3bed | 404 | } |
b22d4497 EW |
405 | } |
406 | } | |
407 | return if $_dry_run; | |
60d9c97a EW |
408 | unless ($gs) { |
409 | warn "Could not determine fetch information for $url\n", | |
410 | "Will not attempt to fetch and rebase commits.\n", | |
411 | "This probably means you have useSvmProps and should\n", | |
412 | "now resync your SVN::Mirror repository.\n"; | |
413 | return; | |
414 | } | |
905f8b7d | 415 | $_fetch_all ? $gs->fetch_all : $gs->fetch; |
171af110 KW |
416 | unless ($_no_rebase) { |
417 | # we always want to rebase against the current HEAD, not any | |
418 | # head that was passed to us | |
419 | my @diff = command('diff-tree', 'HEAD', $gs->refname, '--'); | |
420 | my @finish; | |
421 | if (@diff) { | |
422 | @finish = rebase_cmd(); | |
423 | print STDERR "W: HEAD and ", $gs->refname, " differ, ", | |
424 | "using @finish:\n", "@diff"; | |
425 | } else { | |
426 | print "No changes between current HEAD and ", | |
427 | $gs->refname, "\nResetting to the latest ", | |
428 | $gs->refname, "\n"; | |
429 | @finish = qw/reset --mixed/; | |
430 | } | |
431 | command_noisy(@finish, $gs->refname); | |
b22d4497 | 432 | } |
b22d4497 EW |
433 | } |
434 | ||
26e60160 AR |
435 | sub cmd_find_rev { |
436 | my $revision_or_hash = shift; | |
437 | my $result; | |
438 | if ($revision_or_hash =~ /^r\d+$/) { | |
b3cb7e45 AR |
439 | my $head = shift; |
440 | $head ||= 'HEAD'; | |
441 | my @refs; | |
442 | my (undef, undef, undef, $gs) = working_head_info($head, \@refs); | |
443 | unless ($gs) { | |
444 | die "Unable to determine upstream SVN information from ", | |
445 | "$head history\n"; | |
26e60160 | 446 | } |
b3cb7e45 AR |
447 | my $desired_revision = substr($revision_or_hash, 1); |
448 | $result = $gs->rev_db_get($desired_revision); | |
26e60160 AR |
449 | } else { |
450 | my (undef, $rev, undef) = cmt_metadata($revision_or_hash); | |
451 | $result = $rev; | |
452 | } | |
453 | print "$result\n" if $result; | |
454 | } | |
455 | ||
905f8b7d EW |
456 | sub cmd_rebase { |
457 | command_noisy(qw/update-index --refresh/); | |
13c823fb EW |
458 | my ($url, $rev, $uuid, $gs) = working_head_info('HEAD'); |
459 | unless ($gs) { | |
905f8b7d EW |
460 | die "Unable to determine upstream SVN information from ", |
461 | "working tree history\n"; | |
462 | } | |
905f8b7d EW |
463 | if (command(qw/diff-index HEAD --/)) { |
464 | print STDERR "Cannot rebase with uncommited changes:\n"; | |
465 | command_noisy('status'); | |
466 | exit 1; | |
467 | } | |
dee41f3e EW |
468 | unless ($_local) { |
469 | $_fetch_all ? $gs->fetch_all : $gs->fetch; | |
470 | } | |
905f8b7d EW |
471 | command_noisy(rebase_cmd(), $gs->refname); |
472 | } | |
473 | ||
5969cbe1 | 474 | sub cmd_show_ignore { |
13c823fb EW |
475 | my ($url, $rev, $uuid, $gs) = working_head_info('HEAD'); |
476 | $gs ||= Git::SVN->new; | |
5969cbe1 | 477 | my $r = (defined $_revision ? $_revision : $gs->ra->get_latest_revnum); |
102a0a2d | 478 | $gs->traverse_ignore(\*STDOUT, $gs->{path}, $r); |
a5e0cedc EW |
479 | } |
480 | ||
8164b652 | 481 | sub cmd_multi_init { |
9d55b41a | 482 | my $url = shift; |
98327e58 EW |
483 | unless (defined $_trunk || defined $_branches || defined $_tags) { |
484 | usage(1); | |
9d55b41a | 485 | } |
dc431666 EW |
486 | |
487 | # there are currently some bugs that prevent multi-init/multi-fetch | |
488 | # setups from working well without this. | |
489 | $Git::SVN::_minimize_url = 1; | |
490 | ||
8164b652 | 491 | $_prefix = '' unless defined $_prefix; |
dadc6d2a EW |
492 | if (defined $url) { |
493 | $url =~ s#/+$##; | |
494 | init_subdir(@_); | |
495 | } | |
f30603fc | 496 | do_git_init_db(); |
98327e58 | 497 | if (defined $_trunk) { |
706587fc EW |
498 | my $trunk_ref = $_prefix . 'trunk'; |
499 | # try both old-style and new-style lookups: | |
500 | my $gs_trunk = eval { Git::SVN->new($trunk_ref) }; | |
8164b652 | 501 | unless ($gs_trunk) { |
706587fc EW |
502 | my ($trunk_url, $trunk_path) = |
503 | complete_svn_url($url, $_trunk); | |
504 | $gs_trunk = Git::SVN->init($trunk_url, $trunk_path, | |
505 | undef, $trunk_ref); | |
98327e58 | 506 | } |
c35b96e7 | 507 | } |
706587fc | 508 | return unless defined $_branches || defined $_tags; |
e7db67e6 EW |
509 | my $ra = $url ? Git::SVN::Ra->new($url) : undef; |
510 | complete_url_ls_init($ra, $_branches, '--branches/-b', $_prefix); | |
511 | complete_url_ls_init($ra, $_tags, '--tags/-t', $_prefix . 'tags/'); | |
9d55b41a EW |
512 | } |
513 | ||
1c8443b0 | 514 | sub cmd_multi_fetch { |
0af9c9f9 EW |
515 | my $remotes = Git::SVN::read_all_remotes(); |
516 | foreach my $repo_id (sort keys %$remotes) { | |
db03cd24 | 517 | if ($remotes->{$repo_id}->{url}) { |
4bb9ed04 EW |
518 | Git::SVN::fetch_all($repo_id, $remotes); |
519 | } | |
9d55b41a | 520 | } |
9d55b41a EW |
521 | } |
522 | ||
44320b9e EW |
523 | # this command is special because it requires no metadata |
524 | sub cmd_commit_diff { | |
525 | my ($ta, $tb, $url) = @_; | |
526 | my $usage = "Usage: $0 commit-diff -r<revision> ". | |
527 | "<tree-ish> <tree-ish> [<URL>]\n"; | |
528 | fatal($usage) if (!defined $ta || !defined $tb); | |
d3a840dc | 529 | my $svn_path; |
44320b9e EW |
530 | if (!defined $url) { |
531 | my $gs = eval { Git::SVN->new }; | |
532 | if (!$gs) { | |
533 | fatal("Needed URL or usable git-svn --id in ", | |
534 | "the command-line\n", $usage); | |
535 | } | |
536 | $url = $gs->{url}; | |
d3a840dc | 537 | $svn_path = $gs->{path}; |
44320b9e EW |
538 | } |
539 | unless (defined $_revision) { | |
540 | fatal("-r|--revision is a required argument\n", $usage); | |
541 | } | |
542 | if (defined $_message && defined $_file) { | |
543 | fatal("Both --message/-m and --file/-F specified ", | |
544 | "for the commit message.\n", | |
545 | "I have no idea what you mean\n"); | |
546 | } | |
547 | if (defined $_file) { | |
548 | $_message = file_to_s($_file); | |
549 | } else { | |
550 | $_message ||= get_commit_entry($tb)->{log}; | |
551 | } | |
552 | my $ra ||= Git::SVN::Ra->new($url); | |
d3a840dc | 553 | $svn_path ||= $ra->{svn_path}; |
44320b9e EW |
554 | my $r = $_revision; |
555 | if ($r eq 'HEAD') { | |
556 | $r = $ra->get_latest_revnum; | |
557 | } elsif ($r !~ /^\d+$/) { | |
558 | die "revision argument: $r not understood by git-svn\n"; | |
559 | } | |
61395354 EW |
560 | my %ed_opts = ( r => $r, |
561 | log => $_message, | |
562 | ra => $ra, | |
563 | tree_a => $ta, | |
564 | tree_b => $tb, | |
565 | editor_cb => sub { print "Committed r$_[0]\n" }, | |
566 | svn_path => $svn_path ); | |
567 | if (!SVN::Git::Editor->new(\%ed_opts)->apply_diff) { | |
44320b9e EW |
568 | print "No changes\n$ta == $tb\n"; |
569 | } | |
44320b9e EW |
570 | } |
571 | ||
3397f9df EW |
572 | ########################### utility functions ######################### |
573 | ||
905f8b7d EW |
574 | sub rebase_cmd { |
575 | my @cmd = qw/rebase/; | |
576 | push @cmd, '-v' if $_verbose; | |
577 | push @cmd, qw/--merge/ if $_merge; | |
578 | push @cmd, "--strategy=$_strategy" if $_strategy; | |
579 | @cmd; | |
580 | } | |
581 | ||
1e889ef3 EW |
582 | sub post_fetch_checkout { |
583 | return if $_no_checkout; | |
584 | my $gs = $Git::SVN::_head or return; | |
585 | return if verify_ref('refs/heads/master^0'); | |
586 | ||
587 | my $valid_head = verify_ref('HEAD^0'); | |
588 | command_noisy(qw(update-ref refs/heads/master), $gs->refname); | |
589 | return if ($valid_head || !verify_ref('HEAD^0')); | |
590 | ||
591 | return if $ENV{GIT_DIR} !~ m#^(?:.*/)?\.git$#; | |
592 | my $index = $ENV{GIT_INDEX_FILE} || "$ENV{GIT_DIR}/index"; | |
593 | return if -f $index; | |
594 | ||
7ae3df8c | 595 | return if command_oneline(qw/rev-parse --is-inside-work-tree/) eq 'false'; |
1e889ef3 EW |
596 | return if command_oneline(qw/rev-parse --is-inside-git-dir/) eq 'true'; |
597 | command_noisy(qw/read-tree -m -u -v HEAD HEAD/); | |
598 | print STDERR "Checked out HEAD:\n ", | |
599 | $gs->full_url, " r", $gs->last_rev, "\n"; | |
600 | } | |
601 | ||
98327e58 EW |
602 | sub complete_svn_url { |
603 | my ($url, $path) = @_; | |
604 | $path =~ s#/+$##; | |
98327e58 | 605 | if ($path !~ m#^[a-z\+]+://#) { |
98327e58 EW |
606 | if (!defined $url || $url !~ m#^[a-z\+]+://#) { |
607 | fatal("E: '$path' is not a complete URL ", | |
608 | "and a separate URL is not specified\n"); | |
609 | } | |
706587fc | 610 | return ($url, $path); |
98327e58 | 611 | } |
706587fc | 612 | return ($path, ''); |
98327e58 EW |
613 | } |
614 | ||
9d55b41a | 615 | sub complete_url_ls_init { |
706587fc EW |
616 | my ($ra, $repo_path, $switch, $pfx) = @_; |
617 | unless ($repo_path) { | |
9d55b41a EW |
618 | print STDERR "W: $switch not specified\n"; |
619 | return; | |
620 | } | |
706587fc EW |
621 | $repo_path =~ s#/+$##; |
622 | if ($repo_path =~ m#^[a-z\+]+://#) { | |
623 | $ra = Git::SVN::Ra->new($repo_path); | |
624 | $repo_path = ''; | |
e7db67e6 | 625 | } else { |
706587fc | 626 | $repo_path =~ s#^/+##; |
e7db67e6 | 627 | unless ($ra) { |
706587fc | 628 | fatal("E: '$repo_path' is not a complete URL ", |
e7db67e6 | 629 | "and a separate URL is not specified\n"); |
8164b652 | 630 | } |
e7db67e6 | 631 | } |
706587fc | 632 | my $url = $ra->{url}; |
b4d57e5e EW |
633 | my $gs = Git::SVN->init($url, undef, undef, undef, 1); |
634 | my $k = "svn-remote.$gs->{repo_id}.url"; | |
635 | my $orig_url = eval { command_oneline(qw/config --get/, $k) }; | |
636 | if ($orig_url && ($orig_url ne $gs->{url})) { | |
637 | die "$k already set: $orig_url\n", | |
638 | "wanted to set to: $gs->{url}\n"; | |
88cf4107 | 639 | } |
b4d57e5e EW |
640 | command_oneline('config', $k, $gs->{url}) unless $orig_url; |
641 | my $remote_path = "$ra->{svn_path}/$repo_path/*"; | |
642 | $remote_path =~ s#/+#/#g; | |
643 | $remote_path =~ s#^/##g; | |
644 | my ($n) = ($switch =~ /^--(\w+)/); | |
645 | if (length $pfx && $pfx !~ m#/$#) { | |
646 | die "--prefix='$pfx' must have a trailing slash '/'\n"; | |
9d55b41a | 647 | } |
b4d57e5e EW |
648 | command_noisy('config', "svn-remote.$gs->{repo_id}.$n", |
649 | "$remote_path:refs/remotes/$pfx*"); | |
9d55b41a EW |
650 | } |
651 | ||
aef4e921 EW |
652 | sub verify_ref { |
653 | my ($ref) = @_; | |
2c5c1d53 EW |
654 | eval { command_oneline([ 'rev-parse', '--verify', $ref ], |
655 | { STDERR => 0 }); }; | |
aef4e921 EW |
656 | } |
657 | ||
a5e0cedc | 658 | sub get_tree_from_treeish { |
cf52b8f0 | 659 | my ($treeish) = @_; |
44320b9e | 660 | # $treeish can be a symbolic ref, too: |
aef4e921 | 661 | my $type = command_oneline(qw/cat-file -t/, $treeish); |
cf52b8f0 EW |
662 | my $expected; |
663 | while ($type eq 'tag') { | |
aef4e921 | 664 | ($treeish, $type) = command(qw/cat-file tag/, $treeish); |
cf52b8f0 EW |
665 | } |
666 | if ($type eq 'commit') { | |
aef4e921 EW |
667 | $expected = (grep /^tree /, command(qw/cat-file commit/, |
668 | $treeish))[0]; | |
44320b9e | 669 | ($expected) = ($expected =~ /^tree ($sha1)$/o); |
cf52b8f0 EW |
670 | die "Unable to get tree from $treeish\n" unless $expected; |
671 | } elsif ($type eq 'tree') { | |
672 | $expected = $treeish; | |
673 | } else { | |
674 | die "$treeish is a $type, expected tree, tag or commit\n"; | |
675 | } | |
a5e0cedc EW |
676 | return $expected; |
677 | } | |
678 | ||
44320b9e EW |
679 | sub get_commit_entry { |
680 | my ($treeish) = shift; | |
681 | my %log_entry = ( log => '', tree => get_tree_from_treeish($treeish) ); | |
682 | my $commit_editmsg = "$ENV{GIT_DIR}/COMMIT_EDITMSG"; | |
683 | my $commit_msg = "$ENV{GIT_DIR}/COMMIT_MSG"; | |
684 | open my $log_fh, '>', $commit_editmsg or croak $!; | |
3397f9df | 685 | |
44320b9e | 686 | my $type = command_oneline(qw/cat-file -t/, $treeish); |
4ad4515d | 687 | if ($type eq 'commit' || $type eq 'tag') { |
aef4e921 | 688 | my ($msg_fh, $ctx) = command_output_pipe('cat-file', |
44320b9e | 689 | $type, $treeish); |
3397f9df EW |
690 | my $in_msg = 0; |
691 | while (<$msg_fh>) { | |
692 | if (!$in_msg) { | |
693 | $in_msg = 1 if (/^\s*$/); | |
df746c5a | 694 | } elsif (/^git-svn-id: /) { |
44320b9e EW |
695 | # skip this for now, we regenerate the |
696 | # correct one on re-fetch anyways | |
697 | # TODO: set *:merge properties or like... | |
3397f9df | 698 | } else { |
44320b9e | 699 | print $log_fh $_ or croak $!; |
3397f9df EW |
700 | } |
701 | } | |
aef4e921 | 702 | command_close_pipe($msg_fh, $ctx); |
3397f9df | 703 | } |
44320b9e | 704 | close $log_fh or croak $!; |
3397f9df EW |
705 | |
706 | if ($_edit || ($type eq 'tree')) { | |
707 | my $editor = $ENV{VISUAL} || $ENV{EDITOR} || 'vi'; | |
44320b9e EW |
708 | # TODO: strip out spaces, comments, like git-commit.sh |
709 | system($editor, $commit_editmsg); | |
3397f9df | 710 | } |
44320b9e EW |
711 | rename $commit_editmsg, $commit_msg or croak $!; |
712 | open $log_fh, '<', $commit_msg or croak $!; | |
713 | { local $/; chomp($log_entry{log} = <$log_fh>); } | |
714 | close $log_fh or croak $!; | |
715 | unlink $commit_msg; | |
716 | \%log_entry; | |
a5e0cedc EW |
717 | } |
718 | ||
3397f9df EW |
719 | sub s_to_file { |
720 | my ($str, $file, $mode) = @_; | |
721 | open my $fd,'>',$file or croak $!; | |
722 | print $fd $str,"\n" or croak $!; | |
723 | close $fd or croak $!; | |
724 | chmod ($mode &~ umask, $file) if (defined $mode); | |
725 | } | |
726 | ||
727 | sub file_to_s { | |
728 | my $file = shift; | |
729 | open my $fd,'<',$file or croak "$!: file: $file\n"; | |
730 | local $/; | |
731 | my $ret = <$fd>; | |
732 | close $fd or croak $!; | |
733 | $ret =~ s/\s*$//s; | |
734 | return $ret; | |
735 | } | |
736 | ||
eeb0abe0 EW |
737 | # '<svn username> = real-name <email address>' mapping based on git-svnimport: |
738 | sub load_authors { | |
739 | open my $authors, '<', $_authors or die "Can't open $_authors $!\n"; | |
f8c9d1d2 | 740 | my $log = $cmd eq 'log'; |
eeb0abe0 EW |
741 | while (<$authors>) { |
742 | chomp; | |
575d025c | 743 | next unless /^(.+?|\(no author\))\s*=\s*(.+?)\s*<(.+)>\s*$/; |
eeb0abe0 | 744 | my ($user, $name, $email) = ($1, $2, $3); |
f8c9d1d2 EW |
745 | if ($log) { |
746 | $Git::SVN::Log::rusers{"$name <$email>"} = $user; | |
747 | } else { | |
748 | $users{$user} = [$name, $email]; | |
749 | } | |
79bb8d88 EW |
750 | } |
751 | close $authors or croak $!; | |
752 | } | |
753 | ||
e0d10e1c | 754 | # convert GetOpt::Long specs for use by git-config |
b8c92cad | 755 | sub read_repo_config { |
706587fc | 756 | return unless -d $ENV{GIT_DIR}; |
b8c92cad | 757 | my $opts = shift; |
97ae0911 | 758 | my @config_only; |
b8c92cad | 759 | foreach my $o (keys %$opts) { |
97ae0911 EW |
760 | # if we have mixedCase and a long option-only, then |
761 | # it's a config-only variable that we don't need for | |
762 | # the command-line. | |
763 | push @config_only, $o if ($o =~ /[A-Z]/ && $o =~ /^[a-z]+$/i); | |
b8c92cad | 764 | my $v = $opts->{$o}; |
97ae0911 | 765 | my ($key) = ($o =~ /^([a-zA-Z\-]+)/); |
b8c92cad | 766 | $key =~ s/-//g; |
e0d10e1c | 767 | my $arg = 'git-config'; |
b8c92cad EW |
768 | $arg .= ' --int' if ($o =~ /[:=]i$/); |
769 | $arg .= ' --bool' if ($o !~ /[:=][sfi]$/); | |
770 | if (ref $v eq 'ARRAY') { | |
771 | chomp(my @tmp = `$arg --get-all svn.$key`); | |
772 | @$v = @tmp if @tmp; | |
773 | } else { | |
774 | chomp(my $tmp = `$arg --get svn.$key`); | |
7774284a | 775 | if ($tmp && !($arg =~ / --bool/ && $tmp eq 'false')) { |
b8c92cad EW |
776 | $$v = $tmp; |
777 | } | |
778 | } | |
779 | } | |
97ae0911 | 780 | delete @$opts{@config_only} if @config_only; |
b8c92cad EW |
781 | } |
782 | ||
79bb8d88 | 783 | sub extract_metadata { |
c1927a85 | 784 | my $id = shift or return (undef, undef, undef); |
3dfab993 | 785 | my ($url, $rev, $uuid) = ($id =~ /^\s*git-svn-id:\s+(.*)\@(\d+) |
79bb8d88 | 786 | \s([a-f\d\-]+)$/x); |
e70dc780 | 787 | if (!defined $rev || !$uuid || !$url) { |
79bb8d88 | 788 | # some of the original repositories I made had |
82e5a82f | 789 | # identifiers like this: |
3dfab993 | 790 | ($rev, $uuid) = ($id =~/^\s*git-svn-id:\s(\d+)\@([a-f\d\-]+)/); |
79bb8d88 EW |
791 | } |
792 | return ($url, $rev, $uuid); | |
793 | } | |
794 | ||
c1927a85 EW |
795 | sub cmt_metadata { |
796 | return extract_metadata((grep(/^git-svn-id: /, | |
aef4e921 | 797 | command(qw/cat-file commit/, shift)))[-1]); |
c1927a85 EW |
798 | } |
799 | ||
905f8b7d EW |
800 | sub working_head_info { |
801 | my ($head, $refs) = @_; | |
3dfab993 SV |
802 | my ($fh, $ctx) = command_output_pipe('log', $head); |
803 | my $hash; | |
40cb8f8f | 804 | my %max; |
3dfab993 SV |
805 | while (<$fh>) { |
806 | if ( m{^commit ($::sha1)$} ) { | |
807 | unshift @$refs, $hash if $hash and $refs; | |
808 | $hash = $1; | |
809 | next; | |
810 | } | |
811 | next unless s{^\s*(git-svn-id:)}{$1}; | |
812 | my ($url, $rev, $uuid) = extract_metadata($_); | |
13c823fb | 813 | if (defined $url && defined $rev) { |
40cb8f8f | 814 | next if $max{$url} and $max{$url} < $rev; |
13c823fb EW |
815 | if (my $gs = Git::SVN->find_by_url($url)) { |
816 | my $c = $gs->rev_db_get($rev); | |
b03c7a63 | 817 | if ($c && $c eq $hash) { |
13c823fb EW |
818 | close $fh; # break the pipe |
819 | return ($url, $rev, $uuid, $gs); | |
40cb8f8f SV |
820 | } else { |
821 | $max{$url} ||= $gs->rev_db_max; | |
13c823fb EW |
822 | } |
823 | } | |
824 | } | |
905f8b7d | 825 | } |
13c823fb EW |
826 | command_close_pipe($fh, $ctx); |
827 | (undef, undef, undef, undef); | |
905f8b7d EW |
828 | } |
829 | ||
733a65aa EW |
830 | sub read_commit_parents { |
831 | my ($parents, $c) = @_; | |
832 | my ($fh, $ctx) = command_output_pipe(qw/cat-file commit/, $c); | |
833 | while (<$fh>) { | |
834 | chomp; | |
835 | last if ''; | |
836 | /^parent ($sha1)/ or next; | |
837 | push @{$parents->{$c}}, $1; | |
838 | } | |
839 | close $fh; # break the pipe | |
840 | } | |
841 | ||
842 | sub linearize_history { | |
843 | my ($gs, $refs) = @_; | |
844 | my %parents; | |
845 | foreach my $c (@$refs) { | |
846 | read_commit_parents(\%parents, $c); | |
847 | } | |
848 | ||
849 | my @linear_refs; | |
850 | my %skip = (); | |
851 | my $last_svn_commit = $gs->last_commit; | |
852 | foreach my $c (reverse @$refs) { | |
853 | next if $c eq $last_svn_commit; | |
854 | last if $skip{$c}; | |
855 | ||
856 | unshift @linear_refs, $c; | |
857 | $skip{$c} = 1; | |
858 | ||
859 | # we only want the first parent to diff against for linear | |
860 | # history, we save the rest to inject when we finalize the | |
861 | # svn commit | |
862 | my $fp_a = verify_ref("$c~1"); | |
863 | my $fp_b = shift @{$parents{$c}} if $parents{$c}; | |
864 | if (!$fp_a || !$fp_b) { | |
865 | die "Commit $c\n", | |
866 | "has no parent commit, and therefore ", | |
867 | "nothing to diff against.\n", | |
868 | "You should be working from a repository ", | |
869 | "originally created by git-svn\n"; | |
870 | } | |
871 | if ($fp_a ne $fp_b) { | |
872 | die "$c~1 = $fp_a, however parsing commit $c ", | |
873 | "revealed that:\n$c~1 = $fp_b\nBUG!\n"; | |
874 | } | |
875 | ||
876 | foreach my $p (@{$parents{$c}}) { | |
877 | $skip{$p} = 1; | |
878 | } | |
879 | } | |
880 | (\@linear_refs, \%parents); | |
881 | } | |
882 | ||
9b981fc6 EW |
883 | package Git::SVN; |
884 | use strict; | |
885 | use warnings; | |
ecc712dd | 886 | use vars qw/$default_repo_id $default_ref_id $_no_metadata $_follow_parent |
62e349d2 | 887 | $_repack $_repack_flags $_use_svm_props $_head |
4a1bb4c3 | 888 | $_use_svnsync_props $no_reuse_existing $_minimize_url/; |
9b981fc6 EW |
889 | use Carp qw/croak/; |
890 | use File::Path qw/mkpath/; | |
373274f9 | 891 | use File::Copy qw/copy/; |
9b981fc6 EW |
892 | use IPC::Open3; |
893 | ||
ecc712dd | 894 | my $_repack_nr; |
9b981fc6 EW |
895 | # properties that we do not log: |
896 | my %SKIP_PROP; | |
897 | BEGIN { | |
898 | %SKIP_PROP = map { $_ => 1 } qw/svn:wc:ra_dav:version-url | |
899 | svn:special svn:executable | |
900 | svn:entry:committed-rev | |
901 | svn:entry:last-author | |
902 | svn:entry:uuid | |
903 | svn:entry:committed-date/; | |
91b03282 EW |
904 | |
905 | # some options are read globally, but can be overridden locally | |
906 | # per [svn-remote "..."] section. Command-line options will *NOT* | |
907 | # override options set in an [svn-remote "..."] section | |
c5f71ad0 SV |
908 | no strict 'refs'; |
909 | for my $option (qw/follow_parent no_metadata use_svm_props | |
910 | use_svnsync_props/) { | |
911 | my $key = $option; | |
91b03282 | 912 | $key =~ tr/_//d; |
c5f71ad0 SV |
913 | my $prop = "-$option"; |
914 | *$option = sub { | |
915 | my ($self) = @_; | |
916 | return $self->{$prop} if exists $self->{$prop}; | |
917 | my $k = "svn-remote.$self->{repo_id}.$key"; | |
918 | eval { command_oneline(qw/config --get/, $k) }; | |
919 | if ($@) { | |
920 | $self->{$prop} = ${"Git::SVN::_$option"}; | |
91b03282 | 921 | } else { |
c5f71ad0 SV |
922 | my $v = command_oneline(qw/config --bool/,$k); |
923 | $self->{$prop} = $v eq 'false' ? 0 : 1; | |
91b03282 | 924 | } |
c5f71ad0 SV |
925 | return $self->{$prop}; |
926 | } | |
91b03282 | 927 | } |
9b981fc6 EW |
928 | } |
929 | ||
373274f9 EW |
930 | my %LOCKFILES; |
931 | END { unlink keys %LOCKFILES if %LOCKFILES } | |
932 | ||
4bb9ed04 EW |
933 | sub resolve_local_globs { |
934 | my ($url, $fetch, $glob_spec) = @_; | |
935 | return unless defined $glob_spec; | |
936 | my $ref = $glob_spec->{ref}; | |
937 | my $path = $glob_spec->{path}; | |
938 | foreach (command(qw#for-each-ref --format=%(refname) refs/remotes#)) { | |
939 | next unless m#^refs/remotes/$ref->{regex}$#; | |
940 | my $p = $1; | |
bf655fd7 RE |
941 | my $pathname = desanitize_refname($path->full_path($p)); |
942 | my $refname = desanitize_refname($ref->full_path($p)); | |
4bb9ed04 EW |
943 | if (my $existing = $fetch->{$pathname}) { |
944 | if ($existing ne $refname) { | |
945 | die "Refspec conflict:\n", | |
946 | "existing: refs/remotes/$existing\n", | |
947 | " globbed: refs/remotes/$refname\n"; | |
948 | } | |
949 | my $u = (::cmt_metadata("refs/remotes/$refname"))[0]; | |
4e9f6cc7 | 950 | $u =~ s!^\Q$url\E(/|$)!! or die |
4bb9ed04 EW |
951 | "refs/remotes/$refname: '$url' not found in '$u'\n"; |
952 | if ($pathname ne $u) { | |
953 | warn "W: Refspec glob conflict ", | |
954 | "(ref: refs/remotes/$refname):\n", | |
955 | "expected path: $pathname\n", | |
956 | " real path: $u\n", | |
957 | "Continuing ahead with $u\n"; | |
958 | next; | |
959 | } | |
960 | } else { | |
4bb9ed04 EW |
961 | $fetch->{$pathname} = $refname; |
962 | } | |
963 | } | |
964 | } | |
965 | ||
e98671e5 EW |
966 | sub parse_revision_argument { |
967 | my ($base, $head) = @_; | |
968 | if (!defined $::_revision || $::_revision eq 'BASE:HEAD') { | |
969 | return ($base, $head); | |
970 | } | |
971 | return ($1, $2) if ($::_revision =~ /^(\d+):(\d+)$/); | |
972 | return ($::_revision, $::_revision) if ($::_revision =~ /^\d+$/); | |
973 | return ($head, $head) if ($::_revision eq 'HEAD'); | |
974 | return ($base, $1) if ($::_revision =~ /^BASE:(\d+)$/); | |
975 | return ($1, $head) if ($::_revision =~ /^(\d+):HEAD$/); | |
976 | die "revision argument: $::_revision not understood by git-svn\n"; | |
977 | } | |
978 | ||
0af9c9f9 | 979 | sub fetch_all { |
4bb9ed04 | 980 | my ($repo_id, $remotes) = @_; |
905f8b7d EW |
981 | if (ref $repo_id) { |
982 | my $gs = $repo_id; | |
983 | $repo_id = undef; | |
984 | $repo_id = $gs->{repo_id}; | |
985 | } | |
986 | $remotes ||= read_all_remotes(); | |
7447b4bc EW |
987 | my $remote = $remotes->{$repo_id} or |
988 | die "[svn-remote \"$repo_id\"] unknown\n"; | |
e518192f | 989 | my $fetch = $remote->{fetch}; |
7447b4bc | 990 | my $url = $remote->{url} or die "svn-remote.$repo_id.url not defined\n"; |
e518192f | 991 | my (@gs, @globs); |
0af9c9f9 | 992 | my $ra = Git::SVN::Ra->new($url); |
26a62d57 | 993 | my $uuid = $ra->get_uuid; |
0af9c9f9 | 994 | my $head = $ra->get_latest_revnum; |
28710f74 | 995 | my $base = defined $fetch ? $head : 0; |
e518192f EW |
996 | |
997 | # read the max revs for wildcard expansion (branches/*, tags/*) | |
998 | foreach my $t (qw/branches tags/) { | |
999 | defined $remote->{$t} or next; | |
1000 | push @globs, $remote->{$t}; | |
93f2689c EW |
1001 | my $max_rev = eval { tmp_config(qw/--int --get/, |
1002 | "svn-remote.$repo_id.${t}-maxRev") }; | |
1003 | if (defined $max_rev && ($max_rev < $base)) { | |
1004 | $base = $max_rev; | |
d6d3346b EW |
1005 | } elsif (!defined $max_rev) { |
1006 | $base = 0; | |
e518192f EW |
1007 | } |
1008 | } | |
1009 | ||
db03cd24 EW |
1010 | if ($fetch) { |
1011 | foreach my $p (sort keys %$fetch) { | |
1012 | my $gs = Git::SVN->new($fetch->{$p}, $repo_id, $p); | |
1013 | my $lr = $gs->rev_db_max; | |
1014 | if (defined $lr) { | |
1015 | $base = $lr if ($lr < $base); | |
1016 | } | |
1017 | push @gs, $gs; | |
0af9c9f9 | 1018 | } |
0af9c9f9 | 1019 | } |
e98671e5 EW |
1020 | |
1021 | ($base, $head) = parse_revision_argument($base, $head); | |
e518192f | 1022 | $ra->gs_fetch_loop_common($base, $head, \@gs, \@globs); |
0af9c9f9 EW |
1023 | } |
1024 | ||
47e39c55 EW |
1025 | sub read_all_remotes { |
1026 | my $r = {}; | |
8b8fc068 | 1027 | foreach (grep { s/^svn-remote\.// } command(qw/config -l/)) { |
47e39c55 | 1028 | if (m!^(.+)\.fetch=\s*(.*)\s*:\s*refs/remotes/(.+)\s*$!) { |
46cf98ba EW |
1029 | my ($remote, $local_ref, $remote_ref) = ($1, $2, $3); |
1030 | $local_ref =~ s{^/}{}; | |
1031 | $r->{$remote}->{fetch}->{$local_ref} = $remote_ref; | |
47e39c55 EW |
1032 | } elsif (m!^(.+)\.url=\s*(.*)\s*$!) { |
1033 | $r->{$1}->{url} = $2; | |
4bb9ed04 EW |
1034 | } elsif (m!^(.+)\.(branches|tags)= |
1035 | (.*):refs/remotes/(.+)\s*$/!x) { | |
1036 | my ($p, $g) = ($3, $4); | |
1037 | my $rs = $r->{$1}->{$2} = { | |
e518192f | 1038 | t => $2, |
93f2689c | 1039 | remote => $1, |
4bb9ed04 EW |
1040 | path => Git::SVN::GlobSpec->new($p), |
1041 | ref => Git::SVN::GlobSpec->new($g) }; | |
1042 | if (length($rs->{ref}->{right}) != 0) { | |
1043 | die "The '*' glob character must be the last ", | |
1044 | "character of '$g'\n"; | |
1045 | } | |
47e39c55 EW |
1046 | } |
1047 | } | |
1048 | $r; | |
1049 | } | |
1050 | ||
ecc712dd EW |
1051 | sub init_vars { |
1052 | if (defined $_repack) { | |
1053 | $_repack = 1000 if ($_repack <= 0); | |
1054 | $_repack_nr = $_repack; | |
1055 | $_repack_flags ||= '-d'; | |
1056 | } | |
1057 | } | |
1058 | ||
b805b44a | 1059 | sub verify_remotes_sanity { |
536c4b09 | 1060 | return unless -d $ENV{GIT_DIR}; |
b805b44a EW |
1061 | my %seen; |
1062 | foreach (command(qw/config -l/)) { | |
1063 | if (m!^svn-remote\.(?:.+)\.fetch=.*:refs/remotes/(\S+)\s*$!) { | |
1064 | if ($seen{$1}) { | |
1065 | die "Remote ref refs/remote/$1 is tracked by", | |
1066 | "\n \"$_\"\nand\n \"$seen{$1}\"\n", | |
1067 | "Please resolve this ambiguity in ", | |
1068 | "your git configuration file before ", | |
1069 | "continuing\n"; | |
1070 | } | |
1071 | $seen{$1} = $_; | |
1072 | } | |
1073 | } | |
1074 | } | |
1075 | ||
47e39c55 | 1076 | # we allow more chars than remotes2config.sh... |
706587fc EW |
1077 | sub sanitize_remote_name { |
1078 | my ($name) = @_; | |
47e39c55 | 1079 | $name =~ tr{A-Za-z0-9:,/+-}{.}c; |
706587fc EW |
1080 | $name; |
1081 | } | |
1082 | ||
e6434f87 EW |
1083 | sub find_existing_remote { |
1084 | my ($url, $remotes) = @_; | |
befc9adc | 1085 | return undef if $no_reuse_existing; |
e6434f87 EW |
1086 | my $existing; |
1087 | foreach my $repo_id (keys %$remotes) { | |
1088 | my $u = $remotes->{$repo_id}->{url} or next; | |
1089 | next if $u ne $url; | |
1090 | $existing = $repo_id; | |
1091 | last; | |
1092 | } | |
1093 | $existing; | |
1094 | } | |
b805b44a | 1095 | |
e6434f87 | 1096 | sub init_remote_config { |
d8115c51 | 1097 | my ($self, $url, $no_write) = @_; |
e6434f87 EW |
1098 | $url =~ s!/+$!!; # strip trailing slash |
1099 | my $r = read_all_remotes(); | |
1100 | my $existing = find_existing_remote($url, $r); | |
1101 | if ($existing) { | |
e518192f EW |
1102 | unless ($no_write) { |
1103 | print STDERR "Using existing ", | |
1104 | "[svn-remote \"$existing\"]\n"; | |
1105 | } | |
e6434f87 | 1106 | $self->{repo_id} = $existing; |
4a1bb4c3 | 1107 | } elsif ($_minimize_url) { |
e6434f87 EW |
1108 | my $min_url = Git::SVN::Ra->new($url)->minimize_url; |
1109 | $existing = find_existing_remote($min_url, $r); | |
1110 | if ($existing) { | |
e518192f EW |
1111 | unless ($no_write) { |
1112 | print STDERR "Using existing ", | |
1113 | "[svn-remote \"$existing\"]\n"; | |
1114 | } | |
e6434f87 EW |
1115 | $self->{repo_id} = $existing; |
1116 | } | |
1117 | if ($min_url ne $url) { | |
e518192f EW |
1118 | unless ($no_write) { |
1119 | print STDERR "Using higher level of URL: ", | |
1120 | "$url => $min_url\n"; | |
1121 | } | |
e6434f87 EW |
1122 | my $old_path = $self->{path}; |
1123 | $self->{path} = $url; | |
4e9f6cc7 | 1124 | $self->{path} =~ s!^\Q$min_url\E(/|$)!!; |
e6434f87 EW |
1125 | if (length $old_path) { |
1126 | $self->{path} .= "/$old_path"; | |
1127 | } | |
1128 | $url = $min_url; | |
1129 | } | |
1130 | } | |
1131 | my $orig_url; | |
1132 | if (!$existing) { | |
b805b44a | 1133 | # verify that we aren't overwriting anything: |
e6434f87 | 1134 | $orig_url = eval { |
706587fc | 1135 | command_oneline('config', '--get', |
e6434f87 | 1136 | "svn-remote.$self->{repo_id}.url") |
706587fc | 1137 | }; |
b805b44a | 1138 | if ($orig_url && ($orig_url ne $url)) { |
e6434f87 | 1139 | die "svn-remote.$self->{repo_id}.url already set: ", |
b805b44a EW |
1140 | "$orig_url\nwanted to set to: $url\n"; |
1141 | } | |
9b981fc6 | 1142 | } |
e6434f87 EW |
1143 | my ($xrepo_id, $xpath) = find_ref($self->refname); |
1144 | if (defined $xpath) { | |
1145 | die "svn-remote.$xrepo_id.fetch already set to track ", | |
1146 | "$xpath:refs/remotes/", $self->refname, "\n"; | |
1147 | } | |
d8115c51 EW |
1148 | unless ($no_write) { |
1149 | command_noisy('config', | |
1150 | "svn-remote.$self->{repo_id}.url", $url); | |
46cf98ba | 1151 | $self->{path} =~ s{^/}{}; |
d8115c51 EW |
1152 | command_noisy('config', '--add', |
1153 | "svn-remote.$self->{repo_id}.fetch", | |
1154 | "$self->{path}:".$self->refname); | |
1155 | } | |
9b981fc6 | 1156 | $self->{url} = $url; |
e6434f87 EW |
1157 | } |
1158 | ||
a8ae2623 EW |
1159 | sub find_by_url { # repos_root and, path are optional |
1160 | my ($class, $full_url, $repos_root, $path) = @_; | |
56973d20 | 1161 | |
1a97a506 | 1162 | return undef unless defined $full_url; |
56973d20 AR |
1163 | remove_username($full_url); |
1164 | remove_username($repos_root) if defined $repos_root; | |
a8ae2623 EW |
1165 | my $remotes = read_all_remotes(); |
1166 | if (defined $full_url && defined $repos_root && !defined $path) { | |
1167 | $path = $full_url; | |
1168 | $path =~ s#^\Q$repos_root\E(?:/|$)##; | |
1169 | } | |
1170 | foreach my $repo_id (keys %$remotes) { | |
1171 | my $u = $remotes->{$repo_id}->{url} or next; | |
56973d20 | 1172 | remove_username($u); |
a8ae2623 EW |
1173 | next if defined $repos_root && $repos_root ne $u; |
1174 | ||
1175 | my $fetch = $remotes->{$repo_id}->{fetch} || {}; | |
1176 | foreach (qw/branches tags/) { | |
1177 | resolve_local_globs($u, $fetch, | |
1178 | $remotes->{$repo_id}->{$_}); | |
1179 | } | |
1180 | my $p = $path; | |
1181 | unless (defined $p) { | |
1182 | $p = $full_url; | |
1183 | $p =~ s#^\Q$u\E(?:/|$)## or next; | |
1184 | } | |
1185 | foreach my $f (keys %$fetch) { | |
1186 | next if $f ne $p; | |
1187 | return Git::SVN->new($fetch->{$f}, $repo_id, $f); | |
1188 | } | |
1189 | } | |
1190 | undef; | |
1191 | } | |
1192 | ||
e6434f87 | 1193 | sub init { |
d8115c51 | 1194 | my ($class, $url, $path, $repo_id, $ref_id, $no_write) = @_; |
e6434f87 EW |
1195 | my $self = _new($class, $repo_id, $ref_id, $path); |
1196 | if (defined $url) { | |
d8115c51 | 1197 | $self->init_remote_config($url, $no_write); |
e6434f87 | 1198 | } |
9b981fc6 EW |
1199 | $self; |
1200 | } | |
1201 | ||
706587fc EW |
1202 | sub find_ref { |
1203 | my ($ref_id) = @_; | |
1204 | foreach (command(qw/config -l/)) { | |
1205 | next unless m!^svn-remote\.(.+)\.fetch= | |
1206 | \s*(.*)\s*:\s*refs/remotes/(.+)\s*$!x; | |
1207 | my ($repo_id, $path, $ref) = ($1, $2, $3); | |
1208 | if ($ref eq $ref_id) { | |
1209 | $path = '' if ($path =~ m#^\./?#); | |
1210 | return ($repo_id, $path); | |
1211 | } | |
1212 | } | |
1213 | (undef, undef, undef); | |
1214 | } | |
1215 | ||
9b981fc6 | 1216 | sub new { |
706587fc EW |
1217 | my ($class, $ref_id, $repo_id, $path) = @_; |
1218 | if (defined $ref_id && !defined $repo_id && !defined $path) { | |
1219 | ($repo_id, $path) = find_ref($ref_id); | |
1220 | if (!defined $repo_id) { | |
1221 | die "Could not find a \"svn-remote.*.fetch\" key ", | |
1222 | "in the repository configuration matching: ", | |
1223 | "refs/remotes/$ref_id\n"; | |
1224 | } | |
1225 | } | |
1226 | my $self = _new($class, $repo_id, $ref_id, $path); | |
8b8fc068 EW |
1227 | if (!defined $self->{path} || !length $self->{path}) { |
1228 | my $fetch = command_oneline('config', '--get', | |
1229 | "svn-remote.$repo_id.fetch", | |
1230 | ":refs/remotes/$ref_id\$") or | |
1231 | die "Failed to read \"svn-remote.$repo_id.fetch\" ", | |
1232 | "\":refs/remotes/$ref_id\$\" in config\n"; | |
1233 | ($self->{path}, undef) = split(/\s*:\s*/, $fetch); | |
1234 | } | |
706587fc EW |
1235 | $self->{url} = command_oneline('config', '--get', |
1236 | "svn-remote.$repo_id.url") or | |
1237 | die "Failed to read \"svn-remote.$repo_id.url\" in config\n"; | |
d6d3346b | 1238 | $self->rebuild; |
9b981fc6 EW |
1239 | $self; |
1240 | } | |
1241 | ||
bf655fd7 RE |
1242 | sub refname { |
1243 | my ($refname) = "refs/remotes/$_[0]->{ref_id}" ; | |
1244 | ||
1245 | # It cannot end with a slash /, we'll throw up on this because | |
1246 | # SVN can't have directories with a slash in their name, either: | |
1247 | if ($refname =~ m{/$}) { | |
1248 | die "ref: '$refname' ends with a trailing slash, this is ", | |
1249 | "not permitted by git nor Subversion\n"; | |
1250 | } | |
1251 | ||
1252 | # It cannot have ASCII control character space, tilde ~, caret ^, | |
1253 | # colon :, question-mark ?, asterisk *, space, or open bracket [ | |
1254 | # anywhere. | |
1255 | # | |
1256 | # Additionally, % must be escaped because it is used for escaping | |
1257 | # and we want our escaped refname to be reversible | |
1258 | $refname =~ s{([ \%~\^:\?\*\[\t])}{uc sprintf('%%%02x',ord($1))}eg; | |
1259 | ||
1260 | # no slash-separated component can begin with a dot . | |
1261 | # /.* becomes /%2E* | |
1262 | $refname =~ s{/\.}{/%2E}g; | |
1263 | ||
1264 | # It cannot have two consecutive dots .. anywhere | |
1265 | # .. becomes %2E%2E | |
1266 | $refname =~ s{\.\.}{%2E%2E}g; | |
1267 | ||
1268 | return $refname; | |
1269 | } | |
1270 | ||
1271 | sub desanitize_refname { | |
1272 | my ($refname) = @_; | |
1273 | $refname =~ s{%(?:([0-9A-F]{2}))}{chr hex($1)}eg; | |
1274 | return $refname; | |
1275 | } | |
9b981fc6 | 1276 | |
26a62d57 EW |
1277 | sub svm_uuid { |
1278 | my ($self) = @_; | |
1279 | return $self->{svm}->{uuid} if $self->svm; | |
1280 | $self->ra; | |
1281 | unless ($self->{svm}) { | |
1282 | die "SVM UUID not cached, and reading remotely failed\n"; | |
1283 | } | |
1284 | $self->{svm}->{uuid}; | |
1285 | } | |
8a49ee97 | 1286 | |
26a62d57 EW |
1287 | sub svm { |
1288 | my ($self) = @_; | |
1289 | return $self->{svm} if $self->{svm}; | |
1290 | my $svm; | |
8a49ee97 EW |
1291 | # see if we have it in our config, first: |
1292 | eval { | |
26a62d57 EW |
1293 | my $section = "svn-remote.$self->{repo_id}"; |
1294 | $svm = { | |
93f2689c EW |
1295 | source => tmp_config('--get', "$section.svm-source"), |
1296 | uuid => tmp_config('--get', "$section.svm-uuid"), | |
befc9adc | 1297 | replace => tmp_config('--get', "$section.svm-replace"), |
8a49ee97 EW |
1298 | } |
1299 | }; | |
befc9adc EW |
1300 | if ($svm && $svm->{source} && $svm->{uuid} && $svm->{replace}) { |
1301 | $self->{svm} = $svm; | |
1302 | } | |
26a62d57 EW |
1303 | $self->{svm}; |
1304 | } | |
1305 | ||
1306 | sub _set_svm_vars { | |
1307 | my ($self, $ra) = @_; | |
db03cd24 EW |
1308 | return $ra if $self->svm; |
1309 | ||
1310 | my @err = ( "useSvmProps set, but failed to read SVM properties\n", | |
befc9adc | 1311 | "(svm:source, svm:uuid) ", |
db03cd24 EW |
1312 | "from the following URLs:\n" ); |
1313 | sub read_svm_props { | |
befc9adc EW |
1314 | my ($self, $ra, $path, $r) = @_; |
1315 | my $props = ($ra->get_dir($path, $r))[2]; | |
db03cd24 | 1316 | my $src = $props->{'svm:source'}; |
db03cd24 | 1317 | my $uuid = $props->{'svm:uuid'}; |
befc9adc | 1318 | return undef if (!$src || !$uuid); |
26a62d57 | 1319 | |
befc9adc | 1320 | chomp($src, $uuid); |
26a62d57 | 1321 | |
db03cd24 EW |
1322 | $uuid =~ m{^[0-9a-f\-]{30,}$} |
1323 | or die "doesn't look right - svm:uuid is '$uuid'\n"; | |
befc9adc EW |
1324 | |
1325 | # the '!' is used to mark the repos_root!/relative/path | |
1326 | $src =~ s{/?!/?}{/}; | |
db03cd24 | 1327 | $src =~ s{/+$}{}; # no trailing slashes please |
befc9adc | 1328 | # username is of no interest |
8a49ee97 | 1329 | $src =~ s{(^[a-z\+]*://)[^/@]*@}{$1}; |
8a49ee97 | 1330 | |
befc9adc EW |
1331 | my $replace = $ra->{url}; |
1332 | $replace .= "/$path" if length $path; | |
1333 | ||
db03cd24 | 1334 | my $section = "svn-remote.$self->{repo_id}"; |
befc9adc EW |
1335 | tmp_config("$section.svm-source", $src); |
1336 | tmp_config("$section.svm-replace", $replace); | |
1337 | tmp_config("$section.svm-uuid", $uuid); | |
1338 | $self->{svm} = { | |
1339 | source => $src, | |
1340 | uuid => $uuid, | |
1341 | replace => $replace | |
1342 | }; | |
db03cd24 EW |
1343 | } |
1344 | ||
1345 | my $r = $ra->get_latest_revnum; | |
1346 | my $path = $self->{path}; | |
befc9adc | 1347 | my %tried; |
db03cd24 | 1348 | while (length $path) { |
befc9adc EW |
1349 | unless ($tried{"$self->{url}/$path"}) { |
1350 | return $ra if $self->read_svm_props($ra, $path, $r); | |
1351 | $tried{"$self->{url}/$path"} = 1; | |
db03cd24 | 1352 | } |
befc9adc | 1353 | $path =~ s#/?[^/]+$##; |
8a49ee97 | 1354 | } |
befc9adc EW |
1355 | die "Path: '$path' should be ''\n" if $path ne ''; |
1356 | return $ra if $self->read_svm_props($ra, $path, $r); | |
1357 | $tried{"$self->{url}/$path"} = 1; | |
db03cd24 EW |
1358 | |
1359 | if ($ra->{repos_root} eq $self->{url}) { | |
befc9adc | 1360 | die @err, (map { " $_\n" } keys %tried), "\n"; |
db03cd24 EW |
1361 | } |
1362 | ||
1363 | # nope, make sure we're connected to the repository root: | |
1364 | my $ok; | |
1365 | my @tried_b; | |
1366 | $path = $ra->{svn_path}; | |
db03cd24 EW |
1367 | $ra = Git::SVN::Ra->new($ra->{repos_root}); |
1368 | while (length $path) { | |
befc9adc EW |
1369 | unless ($tried{"$ra->{url}/$path"}) { |
1370 | $ok = $self->read_svm_props($ra, $path, $r); | |
1371 | last if $ok; | |
1372 | $tried{"$ra->{url}/$path"} = 1; | |
1373 | } | |
1374 | $path =~ s#/?[^/]+$##; | |
db03cd24 | 1375 | } |
befc9adc EW |
1376 | die "Path: '$path' should be ''\n" if $path ne ''; |
1377 | $ok ||= $self->read_svm_props($ra, $path, $r); | |
1378 | $tried{"$ra->{url}/$path"} = 1; | |
db03cd24 | 1379 | if (!$ok) { |
befc9adc | 1380 | die @err, (map { " $_\n" } keys %tried), "\n"; |
db03cd24 EW |
1381 | } |
1382 | Git::SVN::Ra->new($self->{url}); | |
8a49ee97 EW |
1383 | } |
1384 | ||
62e349d2 EW |
1385 | sub svnsync { |
1386 | my ($self) = @_; | |
1387 | return $self->{svnsync} if $self->{svnsync}; | |
1388 | ||
1389 | if ($self->no_metadata) { | |
1390 | die "Can't have both 'noMetadata' and ", | |
1391 | "'useSvnsyncProps' options set!\n"; | |
1392 | } | |
1393 | if ($self->rewrite_root) { | |
1394 | die "Can't have both 'useSvnsyncProps' and 'rewriteRoot' ", | |
1395 | "options set!\n"; | |
1396 | } | |
1397 | ||
1398 | my $svnsync; | |
1399 | # see if we have it in our config, first: | |
1400 | eval { | |
1401 | my $section = "svn-remote.$self->{repo_id}"; | |
1402 | $svnsync = { | |
1403 | url => tmp_config('--get', "$section.svnsync-url"), | |
1404 | uuid => tmp_config('--get', "$section.svnsync-uuid"), | |
1405 | } | |
1406 | }; | |
1407 | if ($svnsync && $svnsync->{url} && $svnsync->{uuid}) { | |
1408 | return $self->{svnsync} = $svnsync; | |
1409 | } | |
1410 | ||
1411 | my $err = "useSvnsyncProps set, but failed to read " . | |
1412 | "svnsync property: svn:sync-from-"; | |
1413 | my $rp = $self->ra->rev_proplist(0); | |
1414 | ||
1415 | my $url = $rp->{'svn:sync-from-url'} or die $err . "url\n"; | |
1416 | $url =~ m{^[a-z\+]+://} or | |
1417 | die "doesn't look right - svn:sync-from-url is '$url'\n"; | |
1418 | ||
1419 | my $uuid = $rp->{'svn:sync-from-uuid'} or die $err . "uuid\n"; | |
1420 | $uuid =~ m{^[0-9a-f\-]{30,}$} or | |
1421 | die "doesn't look right - svn:sync-from-uuid is '$uuid'\n"; | |
1422 | ||
1423 | my $section = "svn-remote.$self->{repo_id}"; | |
1424 | tmp_config('--add', "$section.svnsync-uuid", $uuid); | |
1425 | tmp_config('--add', "$section.svnsync-url", $url); | |
1426 | return $self->{svnsync} = { url => $url, uuid => $uuid }; | |
1427 | } | |
1428 | ||
26a62d57 EW |
1429 | # this allows us to memoize our SVN::Ra UUID locally and avoid a |
1430 | # remote lookup (useful for 'git svn log'). | |
1431 | sub ra_uuid { | |
1432 | my ($self) = @_; | |
1433 | unless ($self->{ra_uuid}) { | |
1434 | my $key = "svn-remote.$self->{repo_id}.uuid"; | |
1435 | my $uuid = eval { tmp_config('--get', $key) }; | |
1436 | if (!$@ && $uuid && $uuid =~ /^([a-f\d\-]{30,})$/) { | |
1437 | $self->{ra_uuid} = $uuid; | |
1438 | } else { | |
1439 | die "ra_uuid called without URL\n" unless $self->{url}; | |
1440 | $self->{ra_uuid} = $self->ra->get_uuid; | |
1441 | tmp_config('--add', $key, $self->{ra_uuid}); | |
1442 | } | |
1443 | } | |
1444 | $self->{ra_uuid}; | |
1445 | } | |
1446 | ||
9b981fc6 EW |
1447 | sub ra { |
1448 | my ($self) = shift; | |
8a49ee97 | 1449 | my $ra = Git::SVN::Ra->new($self->{url}); |
91b03282 EW |
1450 | if ($self->use_svm_props && !$self->{svm}) { |
1451 | if ($self->no_metadata) { | |
97ae0911 EW |
1452 | die "Can't have both 'noMetadata' and ", |
1453 | "'useSvmProps' options set!\n"; | |
62e349d2 EW |
1454 | } elsif ($self->use_svnsync_props) { |
1455 | die "Can't have both 'useSvnsyncProps' and ", | |
1456 | "'useSvmProps' options set!\n"; | |
91b03282 | 1457 | } |
26a62d57 | 1458 | $ra = $self->_set_svm_vars($ra); |
8a49ee97 EW |
1459 | $self->{-want_revprops} = 1; |
1460 | } | |
1461 | $ra; | |
9b981fc6 EW |
1462 | } |
1463 | ||
15710b6f EW |
1464 | sub rel_path { |
1465 | my ($self) = @_; | |
1466 | my $repos_root = $self->ra->{repos_root}; | |
1467 | return $self->{path} if ($self->{url} eq $repos_root); | |
0b59451c EW |
1468 | my $url = $self->{url} . |
1469 | (length $self->{path} ? "/$self->{path}" : $self->{path}); | |
1470 | $url =~ s!^\Q$repos_root\E(?:/+|$)!!g; | |
1471 | $url; | |
15710b6f EW |
1472 | } |
1473 | ||
9b981fc6 EW |
1474 | sub traverse_ignore { |
1475 | my ($self, $fh, $path, $r) = @_; | |
1476 | $path =~ s#^/+##g; | |
5d3b7cd5 EW |
1477 | my $ra = $self->ra; |
1478 | my ($dirent, undef, $props) = $ra->get_dir($path, $r); | |
9b981fc6 | 1479 | my $p = $path; |
102a0a2d | 1480 | $p =~ s#^\Q$self->{path}\E(/|$)##; |
9b981fc6 EW |
1481 | print $fh length $p ? "\n# $p\n" : "\n# /\n"; |
1482 | if (my $s = $props->{'svn:ignore'}) { | |
1483 | $s =~ s/[\r\n]+/\n/g; | |
1484 | chomp $s; | |
1485 | if (length $p == 0) { | |
1486 | $s =~ s#\n#\n/$p#g; | |
1487 | print $fh "/$s\n"; | |
1488 | } else { | |
1489 | $s =~ s#\n#\n/$p/#g; | |
1490 | print $fh "/$p/$s\n"; | |
1491 | } | |
1492 | } | |
1493 | foreach (sort keys %$dirent) { | |
0dc03d6a | 1494 | next if $dirent->{$_}->{kind} != $SVN::Node::dir; |
9b981fc6 EW |
1495 | $self->traverse_ignore($fh, "$path/$_", $r); |
1496 | } | |
1497 | } | |
1498 | ||
3ebe8df7 EW |
1499 | sub last_rev { ($_[0]->last_rev_commit)[0] } |
1500 | sub last_commit { ($_[0]->last_rev_commit)[1] } | |
1501 | ||
9b981fc6 EW |
1502 | # returns the newest SVN revision number and newest commit SHA1 |
1503 | sub last_rev_commit { | |
1504 | my ($self) = @_; | |
1505 | if (defined $self->{last_rev} && defined $self->{last_commit}) { | |
1506 | return ($self->{last_rev}, $self->{last_commit}); | |
1507 | } | |
d2866f9e | 1508 | my $c = ::verify_ref($self->refname.'^0'); |
91b03282 | 1509 | if ($c && !$self->use_svm_props && !$self->no_metadata) { |
d2866f9e | 1510 | my $rev = (::cmt_metadata($c))[1]; |
9b981fc6 EW |
1511 | if (defined $rev) { |
1512 | ($self->{last_rev}, $self->{last_commit}) = ($rev, $c); | |
1513 | return ($rev, $c); | |
1514 | } | |
1515 | } | |
26a62d57 EW |
1516 | my $db_path = $self->db_path; |
1517 | unless (-e $db_path) { | |
1518 | ($self->{last_rev}, $self->{last_commit}) = (undef, undef); | |
1519 | return (undef, undef); | |
1520 | } | |
9b981fc6 EW |
1521 | my $offset = -41; # from tail |
1522 | my $rl; | |
26a62d57 | 1523 | open my $fh, '<', $db_path or croak "$db_path not readable: $!\n"; |
ce4b4af7 EW |
1524 | sysseek($fh, $offset, 2); # don't care for errors |
1525 | sysread($fh, $rl, 41) == 41 or return (undef, undef); | |
9b981fc6 | 1526 | chomp $rl; |
ce4b4af7 | 1527 | while (('0' x40) eq $rl && sysseek($fh, 0, 1) != 0) { |
9b981fc6 | 1528 | $offset -= 41; |
ce4b4af7 EW |
1529 | sysseek($fh, $offset, 2); # don't care for errors |
1530 | sysread($fh, $rl, 41) == 41 or return (undef, undef); | |
9b981fc6 EW |
1531 | chomp $rl; |
1532 | } | |
91b03282 | 1533 | if ($c && $c ne $rl) { |
26a62d57 | 1534 | die "$db_path and ", $self->refname, |
9c93fee5 EW |
1535 | " inconsistent!:\n$c != $rl\n"; |
1536 | } | |
ce4b4af7 | 1537 | my $rev = sysseek($fh, 0, 1) or croak $!; |
9b981fc6 EW |
1538 | $rev = ($rev - 41) / 41; |
1539 | close $fh or croak $!; | |
1540 | ($self->{last_rev}, $self->{last_commit}) = ($rev, $c); | |
1541 | return ($rev, $c); | |
1542 | } | |
1543 | ||
3ebe8df7 EW |
1544 | sub get_fetch_range { |
1545 | my ($self, $min, $max) = @_; | |
1546 | $max ||= $self->ra->get_latest_revnum; | |
9c93fee5 | 1547 | $min ||= $self->rev_db_max; |
3ebe8df7 | 1548 | (++$min, $max); |
9b981fc6 EW |
1549 | } |
1550 | ||
8a49ee97 | 1551 | sub tmp_config { |
93f2689c | 1552 | my (@args) = @_; |
b7e5348c EW |
1553 | my $old_def_config = "$ENV{GIT_DIR}/svn/config"; |
1554 | my $config = "$ENV{GIT_DIR}/svn/.metadata"; | |
38570a47 | 1555 | if (! -f $config && -f $old_def_config) { |
b7e5348c EW |
1556 | rename $old_def_config, $config or |
1557 | die "Failed rename $old_def_config => $config: $!\n"; | |
1558 | } | |
8a49ee97 | 1559 | my $old_config = $ENV{GIT_CONFIG}; |
93f2689c | 1560 | $ENV{GIT_CONFIG} = $config; |
8a49ee97 | 1561 | $@ = undef; |
b4d57e5e EW |
1562 | my @ret = eval { |
1563 | unless (-f $config) { | |
1564 | mkfile($config); | |
1565 | open my $fh, '>', $config or | |
1566 | die "Can't open $config: $!\n"; | |
1567 | print $fh "; This file is used internally by ", | |
1568 | "git-svn\n" or die | |
1569 | "Couldn't write to $config: $!\n"; | |
1570 | print $fh "; You should not have to edit it\n" or | |
1571 | die "Couldn't write to $config: $!\n"; | |
1572 | close $fh or die "Couldn't close $config: $!\n"; | |
1573 | } | |
1574 | command('config', @args); | |
1575 | }; | |
8a49ee97 EW |
1576 | my $err = $@; |
1577 | if (defined $old_config) { | |
1578 | $ENV{GIT_CONFIG} = $old_config; | |
1579 | } else { | |
1580 | delete $ENV{GIT_CONFIG}; | |
1581 | } | |
1582 | die $err if $err; | |
1583 | wantarray ? @ret : $ret[0]; | |
1584 | } | |
1585 | ||
9b981fc6 EW |
1586 | sub tmp_index_do { |
1587 | my ($self, $sub) = @_; | |
1588 | my $old_index = $ENV{GIT_INDEX_FILE}; | |
1589 | $ENV{GIT_INDEX_FILE} = $self->{index}; | |
8a49ee97 | 1590 | $@ = undef; |
b4d57e5e EW |
1591 | my @ret = eval { |
1592 | my ($dir, $base) = ($self->{index} =~ m#^(.*?)/?([^/]+)$#); | |
1593 | mkpath([$dir]) unless -d $dir; | |
1594 | &$sub; | |
1595 | }; | |
8a49ee97 EW |
1596 | my $err = $@; |
1597 | if (defined $old_index) { | |
9b981fc6 EW |
1598 | $ENV{GIT_INDEX_FILE} = $old_index; |
1599 | } else { | |
1600 | delete $ENV{GIT_INDEX_FILE}; | |
1601 | } | |
8a49ee97 | 1602 | die $err if $err; |
9b981fc6 EW |
1603 | wantarray ? @ret : $ret[0]; |
1604 | } | |
1605 | ||
1606 | sub assert_index_clean { | |
1607 | my ($self, $treeish) = @_; | |
1608 | ||
1609 | $self->tmp_index_do(sub { | |
1610 | command_noisy('read-tree', $treeish) unless -e $self->{index}; | |
1611 | my $x = command_oneline('write-tree'); | |
1612 | my ($y) = (command(qw/cat-file commit/, $treeish) =~ | |
1613 | /^tree ($::sha1)/mo); | |
e8d120bd EW |
1614 | return if $y eq $x; |
1615 | ||
1616 | warn "Index mismatch: $y != $x\nrereading $treeish\n"; | |
1617 | unlink $self->{index} or die "unlink $self->{index}: $!\n"; | |
1618 | command_noisy('read-tree', $treeish); | |
9b981fc6 EW |
1619 | $x = command_oneline('write-tree'); |
1620 | if ($y ne $x) { | |
1621 | ::fatal "trees ($treeish) $y != $x\n", | |
1622 | "Something is seriously wrong...\n"; | |
1623 | } | |
1624 | }); | |
1625 | } | |
1626 | ||
1627 | sub get_commit_parents { | |
0af9c9f9 | 1628 | my ($self, $log_entry) = @_; |
9b981fc6 | 1629 | my (%seen, @ret, @tmp); |
0af9c9f9 EW |
1630 | # legacy support for 'set-tree'; this is only used by set_tree_cb: |
1631 | if (my $ip = $self->{inject_parents}) { | |
1632 | if (my $commit = delete $ip->{$log_entry->{revision}}) { | |
1633 | push @tmp, $commit; | |
9b981fc6 EW |
1634 | } |
1635 | } | |
d2866f9e | 1636 | if (my $cur = ::verify_ref($self->refname.'^0')) { |
9b981fc6 EW |
1637 | push @tmp, $cur; |
1638 | } | |
733a65aa EW |
1639 | if (my $ipd = $self->{inject_parents_dcommit}) { |
1640 | if (my $commit = delete $ipd->{$log_entry->{revision}}) { | |
1641 | push @tmp, @$commit; | |
1642 | } | |
1643 | } | |
44320b9e | 1644 | push @tmp, $_ foreach (@{$log_entry->{parents}}, @tmp); |
9b981fc6 EW |
1645 | while (my $p = shift @tmp) { |
1646 | next if $seen{$p}; | |
1647 | $seen{$p} = 1; | |
1648 | push @ret, $p; | |
1649 | # MAXPARENT is defined to 16 in commit-tree.c: | |
1650 | last if @ret >= 16; | |
1651 | } | |
1652 | if (@tmp) { | |
44320b9e | 1653 | die "r$log_entry->{revision}: No room for parents:\n\t", |
9b981fc6 EW |
1654 | join("\n\t", @tmp), "\n"; |
1655 | } | |
1656 | @ret; | |
1657 | } | |
1658 | ||
aea736cc EW |
1659 | sub rewrite_root { |
1660 | my ($self) = @_; | |
1661 | return $self->{-rewrite_root} if exists $self->{-rewrite_root}; | |
1662 | my $k = "svn-remote.$self->{repo_id}.rewriteRoot"; | |
1663 | my $rwr = eval { command_oneline(qw/config --get/, $k) }; | |
1664 | if ($rwr) { | |
1665 | $rwr =~ s#/+$##; | |
1666 | if ($rwr !~ m#^[a-z\+]+://#) { | |
1667 | die "$rwr is not a valid URL (key: $k)\n"; | |
1668 | } | |
1669 | } | |
1670 | $self->{-rewrite_root} = $rwr; | |
1671 | } | |
1672 | ||
1673 | sub metadata_url { | |
1674 | my ($self) = @_; | |
1675 | ($self->rewrite_root || $self->{url}) . | |
1676 | (length $self->{path} ? '/' . $self->{path} : ''); | |
1677 | } | |
1678 | ||
706587fc | 1679 | sub full_url { |
9b981fc6 | 1680 | my ($self) = @_; |
5d3b7cd5 | 1681 | $self->{url} . (length $self->{path} ? '/' . $self->{path} : ''); |
9b981fc6 EW |
1682 | } |
1683 | ||
1684 | sub do_git_commit { | |
0af9c9f9 | 1685 | my ($self, $log_entry) = @_; |
8a603774 EW |
1686 | my $lr = $self->last_rev; |
1687 | if (defined $lr && $lr >= $log_entry->{revision}) { | |
1688 | die "Last fetched revision of ", $self->refname, | |
1689 | " was r$lr, but we are about to fetch: ", | |
1690 | "r$log_entry->{revision}!\n"; | |
1691 | } | |
44320b9e EW |
1692 | if (my $c = $self->rev_db_get($log_entry->{revision})) { |
1693 | croak "$log_entry->{revision} = $c already exists! ", | |
9b981fc6 EW |
1694 | "Why are we refetching it?\n"; |
1695 | } | |
db03cd24 EW |
1696 | $ENV{GIT_AUTHOR_NAME} = $ENV{GIT_COMMITTER_NAME} = $log_entry->{name}; |
1697 | $ENV{GIT_AUTHOR_EMAIL} = $ENV{GIT_COMMITTER_EMAIL} = | |
1698 | $log_entry->{email}; | |
44320b9e | 1699 | $ENV{GIT_AUTHOR_DATE} = $ENV{GIT_COMMITTER_DATE} = $log_entry->{date}; |
9b981fc6 | 1700 | |
44320b9e | 1701 | my $tree = $log_entry->{tree}; |
9b981fc6 EW |
1702 | if (!defined $tree) { |
1703 | $tree = $self->tmp_index_do(sub { | |
1704 | command_oneline('write-tree') }); | |
1705 | } | |
1706 | die "Tree is not a valid sha1: $tree\n" if $tree !~ /^$::sha1$/o; | |
1707 | ||
1708 | my @exec = ('git-commit-tree', $tree); | |
0af9c9f9 | 1709 | foreach ($self->get_commit_parents($log_entry)) { |
9b981fc6 EW |
1710 | push @exec, '-p', $_; |
1711 | } | |
1712 | defined(my $pid = open3(my $msg_fh, my $out_fh, '>&STDERR', @exec)) | |
1713 | or croak $!; | |
44320b9e | 1714 | print $msg_fh $log_entry->{log} or croak $!; |
91b03282 | 1715 | unless ($self->no_metadata) { |
8a49ee97 EW |
1716 | print $msg_fh "\ngit-svn-id: $log_entry->{metadata}\n" |
1717 | or croak $!; | |
9760adcc | 1718 | } |
9b981fc6 EW |
1719 | $msg_fh->flush == 0 or croak $!; |
1720 | close $msg_fh or croak $!; | |
1721 | chomp(my $commit = do { local $/; <$out_fh> }); | |
1722 | close $out_fh or croak $!; | |
1723 | waitpid $pid, 0; | |
1724 | croak $? if $?; | |
1725 | if ($commit !~ /^$::sha1$/o) { | |
1726 | die "Failed to commit, invalid sha1: $commit\n"; | |
1727 | } | |
1728 | ||
373274f9 | 1729 | $self->rev_db_set($log_entry->{revision}, $commit, 1); |
9b981fc6 | 1730 | |
44320b9e | 1731 | $self->{last_rev} = $log_entry->{revision}; |
9b981fc6 | 1732 | $self->{last_commit} = $commit; |
8a49ee97 EW |
1733 | print "r$log_entry->{revision}"; |
1734 | if (defined $log_entry->{svm_revision}) { | |
1735 | print " (\@$log_entry->{svm_revision})"; | |
26a62d57 EW |
1736 | $self->rev_db_set($log_entry->{svm_revision}, $commit, |
1737 | 0, $self->svm_uuid); | |
8a49ee97 EW |
1738 | } |
1739 | print " = $commit ($self->{ref_id})\n"; | |
ecc712dd EW |
1740 | if (defined $_repack && (--$_repack_nr == 0)) { |
1741 | $_repack_nr = $_repack; | |
1742 | # repack doesn't use any arguments with spaces in them, does it? | |
1743 | print "Running git repack $_repack_flags ...\n"; | |
1744 | command_noisy('repack', split(/\s+/, $_repack_flags)); | |
1745 | print "Done repacking\n"; | |
1746 | } | |
9b981fc6 EW |
1747 | return $commit; |
1748 | } | |
1749 | ||
fbcc1737 EW |
1750 | sub match_paths { |
1751 | my ($self, $paths, $r) = @_; | |
4e9f6cc7 | 1752 | return 1 if $self->{path} eq ''; |
d542aedb EW |
1753 | if (my $path = $paths->{"/$self->{path}"}) { |
1754 | return ($path->{action} eq 'D') ? 0 : 1; | |
1755 | } | |
4e9f6cc7 | 1756 | $self->{path_regex} ||= qr/^\/\Q$self->{path}\E\//; |
fbcc1737 EW |
1757 | if (grep /$self->{path_regex}/, keys %$paths) { |
1758 | return 1; | |
1759 | } | |
1760 | my $c = ''; | |
1761 | foreach (split m#/#, $self->{path}) { | |
1762 | $c .= "/$_"; | |
74a81227 EW |
1763 | next unless ($paths->{$c} && |
1764 | ($paths->{$c}->{action} =~ /^[AR]$/)); | |
e518192f EW |
1765 | if ($self->ra->check_path($self->{path}, $r) == |
1766 | $SVN::Node::dir) { | |
fbcc1737 EW |
1767 | return 1; |
1768 | } | |
1769 | } | |
1770 | return 0; | |
1771 | } | |
1772 | ||
15710b6f EW |
1773 | sub find_parent_branch { |
1774 | my ($self, $paths, $rev) = @_; | |
91b03282 | 1775 | return undef unless $self->follow_parent; |
e5a0b240 | 1776 | unless (defined $paths) { |
c7eba716 EW |
1777 | my $err_handler = $SVN::Error::handler; |
1778 | $SVN::Error::handler = \&Git::SVN::Ra::skip_unknown_revs; | |
d4eff2bd EW |
1779 | $self->ra->get_log([$self->{path}], $rev, $rev, 0, 1, 1, sub { |
1780 | $paths = | |
1781 | Git::SVN::Ra::dup_changed_paths($_[0]) }); | |
c7eba716 | 1782 | $SVN::Error::handler = $err_handler; |
e5a0b240 EW |
1783 | } |
1784 | return undef unless defined $paths; | |
15710b6f EW |
1785 | |
1786 | # look for a parent from another branch: | |
7f578c55 EW |
1787 | my @b_path_components = split m#/#, $self->rel_path; |
1788 | my @a_path_components; | |
1789 | my $i; | |
1790 | while (@b_path_components) { | |
1791 | $i = $paths->{'/'.join('/', @b_path_components)}; | |
74a81227 | 1792 | last if $i && defined $i->{copyfrom_path}; |
7f578c55 EW |
1793 | unshift(@a_path_components, pop(@b_path_components)); |
1794 | } | |
74a81227 EW |
1795 | return undef unless defined $i && defined $i->{copyfrom_path}; |
1796 | my $branch_from = $i->{copyfrom_path}; | |
7f578c55 EW |
1797 | if (@a_path_components) { |
1798 | print STDERR "branch_from: $branch_from => "; | |
1799 | $branch_from .= '/'.join('/', @a_path_components); | |
1800 | print STDERR $branch_from, "\n"; | |
1801 | } | |
3ebe8df7 | 1802 | my $r = $i->{copyfrom_rev}; |
15710b6f EW |
1803 | my $repos_root = $self->ra->{repos_root}; |
1804 | my $url = $self->ra->{url}; | |
1805 | my $new_url = $repos_root . $branch_from; | |
1806 | print STDERR "Found possible branch point: ", | |
1807 | "$new_url => ", $self->full_url, ", $r\n"; | |
1808 | $branch_from =~ s#^/##; | |
a8ae2623 | 1809 | my $gs = Git::SVN->find_by_url($new_url, $repos_root, $branch_from); |
15710b6f | 1810 | unless ($gs) { |
ce2a0f2f EW |
1811 | my $ref_id = $self->{ref_id}; |
1812 | $ref_id =~ s/\@\d+$//; | |
1813 | $ref_id .= "\@$r"; | |
15710b6f EW |
1814 | # just grow a tail if we're not unique enough :x |
1815 | $ref_id .= '-' while find_ref($ref_id); | |
ce2a0f2f | 1816 | print STDERR "Initializing parent: $ref_id\n"; |
d8115c51 | 1817 | $gs = Git::SVN->init($new_url, '', $ref_id, $ref_id, 1); |
15710b6f EW |
1818 | } |
1819 | my ($r0, $parent) = $gs->find_rev_before($r, 1); | |
91b03282 | 1820 | if (!defined $r0 || !defined $parent) { |
d627de6b EW |
1821 | my ($base, $head) = parse_revision_argument(0, $r); |
1822 | if ($base <= $r) { | |
1823 | $gs->fetch($base, $r); | |
1824 | } | |
15710b6f EW |
1825 | ($r0, $parent) = $gs->last_rev_commit; |
1826 | } | |
ef70de96 | 1827 | if (defined $r0 && defined $parent) { |
15710b6f | 1828 | print STDERR "Found branch parent: ($self->{ref_id}) $parent\n"; |
15710b6f EW |
1829 | my $ed; |
1830 | if ($self->ra->can_do_switch) { | |
2e5e2480 | 1831 | $self->assert_index_clean($parent); |
8b8fc068 | 1832 | print STDERR "Following parent with do_switch\n"; |
15710b6f | 1833 | # do_switch works with svn/trunk >= r22312, but that |
2b27f6c8 | 1834 | # is not included with SVN 1.4.3 (the latest version |
15710b6f EW |
1835 | # at the moment), so we can't rely on it |
1836 | $self->{last_commit} = $parent; | |
1837 | $ed = SVN::Git::Fetcher->new($self); | |
8a603774 | 1838 | $gs->ra->gs_do_switch($r0, $rev, $gs, |
15710b6f EW |
1839 | $self->full_url, $ed) |
1840 | or die "SVN connection failed somewhere...\n"; | |
1841 | } else { | |
8b8fc068 | 1842 | print STDERR "Following parent with do_update\n"; |
15710b6f | 1843 | $ed = SVN::Git::Fetcher->new($self); |
8a603774 | 1844 | $self->ra->gs_do_update($rev, $rev, $self, $ed) |
15710b6f EW |
1845 | or die "SVN connection failed somewhere...\n"; |
1846 | } | |
f7c3fc4a | 1847 | print STDERR "Successfully followed parent\n"; |
15710b6f EW |
1848 | return $self->make_log_entry($rev, [$parent], $ed); |
1849 | } | |
15710b6f EW |
1850 | return undef; |
1851 | } | |
1852 | ||
9b981fc6 | 1853 | sub do_fetch { |
706587fc | 1854 | my ($self, $paths, $rev) = @_; |
15710b6f | 1855 | my $ed; |
9b981fc6 | 1856 | my ($last_rev, @parents); |
b9dffd8c EW |
1857 | if (my $lc = $self->last_commit) { |
1858 | # we can have a branch that was deleted, then re-added | |
1859 | # under the same name but copied from another path, in | |
1860 | # which case we'll have multiple parents (we don't | |
1861 | # want to break the original ref, nor lose copypath info): | |
1862 | if (my $log_entry = $self->find_parent_branch($paths, $rev)) { | |
1863 | push @{$log_entry->{parents}}, $lc; | |
1864 | return $log_entry; | |
1865 | } | |
15710b6f | 1866 | $ed = SVN::Git::Fetcher->new($self); |
9b981fc6 | 1867 | $last_rev = $self->{last_rev}; |
b9dffd8c EW |
1868 | $ed->{c} = $lc; |
1869 | @parents = ($lc); | |
9b981fc6 EW |
1870 | } else { |
1871 | $last_rev = $rev; | |
15710b6f EW |
1872 | if (my $log_entry = $self->find_parent_branch($paths, $rev)) { |
1873 | return $log_entry; | |
1874 | } | |
1875 | $ed = SVN::Git::Fetcher->new($self); | |
9b981fc6 | 1876 | } |
8a603774 | 1877 | unless ($self->ra->gs_do_update($last_rev, $rev, $self, $ed)) { |
9b981fc6 EW |
1878 | die "SVN connection failed somewhere...\n"; |
1879 | } | |
1880 | $self->make_log_entry($rev, \@parents, $ed); | |
1881 | } | |
1882 | ||
97f6987a EW |
1883 | sub get_untracked { |
1884 | my ($self, $ed) = @_; | |
1885 | my @out; | |
1886 | my $h = $ed->{empty}; | |
9b981fc6 EW |
1887 | foreach (sort keys %$h) { |
1888 | my $act = $h->{$_} ? '+empty_dir' : '-empty_dir'; | |
97f6987a | 1889 | push @out, " $act: " . uri_encode($_); |
9b981fc6 EW |
1890 | warn "W: $act: $_\n"; |
1891 | } | |
1892 | foreach my $t (qw/dir_prop file_prop/) { | |
97f6987a | 1893 | $h = $ed->{$t} or next; |
9b981fc6 EW |
1894 | foreach my $path (sort keys %$h) { |
1895 | my $ppath = $path eq '' ? '.' : $path; | |
1896 | foreach my $prop (sort keys %{$h->{$path}}) { | |
1ce255dc | 1897 | next if $SKIP_PROP{$prop}; |
9b981fc6 | 1898 | my $v = $h->{$path}->{$prop}; |
97f6987a EW |
1899 | my $t_ppath_prop = "$t: " . |
1900 | uri_encode($ppath) . ' ' . | |
1901 | uri_encode($prop); | |
9b981fc6 | 1902 | if (defined $v) { |
97f6987a EW |
1903 | push @out, " +$t_ppath_prop " . |
1904 | uri_encode($v); | |
9b981fc6 | 1905 | } else { |
97f6987a | 1906 | push @out, " -$t_ppath_prop"; |
9b981fc6 EW |
1907 | } |
1908 | } | |
1909 | } | |
1910 | } | |
1911 | foreach my $t (qw/absent_file absent_directory/) { | |
97f6987a | 1912 | $h = $ed->{$t} or next; |
9b981fc6 EW |
1913 | foreach my $parent (sort keys %$h) { |
1914 | foreach my $path (sort @{$h->{$parent}}) { | |
97f6987a EW |
1915 | push @out, " $t: " . |
1916 | uri_encode("$parent/$path"); | |
9b981fc6 EW |
1917 | warn "W: $t: $parent/$path ", |
1918 | "Insufficient permissions?\n"; | |
1919 | } | |
1920 | } | |
1921 | } | |
97f6987a | 1922 | \@out; |
9b981fc6 EW |
1923 | } |
1924 | ||
1c8443b0 EW |
1925 | sub parse_svn_date { |
1926 | my $date = shift || return '+0000 1970-01-01 00:00:00'; | |
1927 | my ($Y,$m,$d,$H,$M,$S) = ($date =~ /^(\d{4})\-(\d\d)\-(\d\d)T | |
1928 | (\d\d)\:(\d\d)\:(\d\d).\d+Z$/x) or | |
1929 | croak "Unable to parse date: $date\n"; | |
1930 | "+0000 $Y-$m-$d $H:$M:$S"; | |
1931 | } | |
1932 | ||
1933 | sub check_author { | |
1934 | my ($author) = @_; | |
1935 | if (!defined $author || length $author == 0) { | |
1936 | $author = '(no author)'; | |
1937 | } | |
1938 | if (defined $::_authors && ! defined $::users{$author}) { | |
1939 | die "Author: $author not defined in $::_authors file\n"; | |
1940 | } | |
1941 | $author; | |
1942 | } | |
1943 | ||
9b981fc6 | 1944 | sub make_log_entry { |
97f6987a EW |
1945 | my ($self, $rev, $parents, $ed) = @_; |
1946 | my $untracked = $self->get_untracked($ed); | |
1947 | ||
9b981fc6 | 1948 | open my $un, '>>', "$self->{dir}/unhandled.log" or croak $!; |
97f6987a EW |
1949 | print $un "r$rev\n" or croak $!; |
1950 | print $un $_, "\n" foreach @$untracked; | |
1951 | my %log_entry = ( parents => $parents || [], revision => $rev, | |
1952 | log => ''); | |
fbcc1737 | 1953 | |
8a49ee97 | 1954 | my $headrev; |
fbcc1737 | 1955 | my $logged = delete $self->{logged_rev_props}; |
8a49ee97 | 1956 | if (!$logged || $self->{-want_revprops}) { |
fbcc1737 EW |
1957 | my $rp = $self->ra->rev_proplist($rev); |
1958 | foreach (sort keys %$rp) { | |
1959 | my $v = $rp->{$_}; | |
1960 | if (/^svn:(author|date|log)$/) { | |
1961 | $log_entry{$1} = $v; | |
8a49ee97 EW |
1962 | } elsif ($_ eq 'svm:headrev') { |
1963 | $headrev = $v; | |
fbcc1737 EW |
1964 | } else { |
1965 | print $un " rev_prop: ", uri_encode($_), ' ', | |
1966 | uri_encode($v), "\n"; | |
1967 | } | |
9b981fc6 | 1968 | } |
fbcc1737 EW |
1969 | } else { |
1970 | map { $log_entry{$_} = $logged->{$_} } keys %$logged; | |
9b981fc6 EW |
1971 | } |
1972 | close $un or croak $!; | |
97f6987a | 1973 | |
9b981fc6 | 1974 | $log_entry{date} = parse_svn_date($log_entry{date}); |
9b981fc6 | 1975 | $log_entry{log} .= "\n"; |
db03cd24 EW |
1976 | my $author = $log_entry{author} = check_author($log_entry{author}); |
1977 | my ($name, $email) = defined $::users{$author} ? @{$::users{$author}} | |
1978 | : ($author, undef); | |
91b03282 | 1979 | if (defined $headrev && $self->use_svm_props) { |
aea736cc EW |
1980 | if ($self->rewrite_root) { |
1981 | die "Can't have both 'useSvmProps' and 'rewriteRoot' ", | |
1982 | "options set!\n"; | |
1983 | } | |
8a49ee97 | 1984 | my ($uuid, $r) = $headrev =~ m{^([a-f\d\-]{30,}):(\d+)$}; |
befc9adc EW |
1985 | # we don't want "SVM: initializing mirror for junk" ... |
1986 | return undef if $r == 0; | |
1987 | my $svm = $self->svm; | |
1988 | if ($uuid ne $svm->{uuid}) { | |
8a49ee97 | 1989 | die "UUID mismatch on SVM path:\n", |
befc9adc | 1990 | "expected: $svm->{uuid}\n", |
8a49ee97 EW |
1991 | " got: $uuid\n"; |
1992 | } | |
befc9adc EW |
1993 | my $full_url = $self->full_url; |
1994 | $full_url =~ s#^\Q$svm->{replace}\E(/|$)#$svm->{source}$1# or | |
1995 | die "Failed to replace '$svm->{replace}' with ", | |
1996 | "'$svm->{source}' in $full_url\n"; | |
18ea92bd SV |
1997 | # throw away username for storing in records |
1998 | remove_username($full_url); | |
8a49ee97 EW |
1999 | $log_entry{metadata} = "$full_url\@$r $uuid"; |
2000 | $log_entry{svm_revision} = $r; | |
db03cd24 | 2001 | $email ||= "$author\@$uuid" |
62e349d2 EW |
2002 | } elsif ($self->use_svnsync_props) { |
2003 | my $full_url = $self->svnsync->{url}; | |
2004 | $full_url .= "/$self->{path}" if length $self->{path}; | |
ce118739 | 2005 | remove_username($full_url); |
62e349d2 EW |
2006 | my $uuid = $self->svnsync->{uuid}; |
2007 | $log_entry{metadata} = "$full_url\@$rev $uuid"; | |
2008 | $email ||= "$author\@$uuid" | |
8a49ee97 | 2009 | } else { |
ce118739 AR |
2010 | my $url = $self->metadata_url; |
2011 | remove_username($url); | |
2012 | $log_entry{metadata} = "$url\@$rev " . | |
26a62d57 | 2013 | $self->ra->get_uuid; |
db03cd24 | 2014 | $email ||= "$author\@" . $self->ra->get_uuid; |
8a49ee97 | 2015 | } |
db03cd24 EW |
2016 | $log_entry{name} = $name; |
2017 | $log_entry{email} = $email; | |
9b981fc6 EW |
2018 | \%log_entry; |
2019 | } | |
2020 | ||
2021 | sub fetch { | |
3ebe8df7 | 2022 | my ($self, $min_rev, $max_rev, @parents) = @_; |
9b981fc6 | 2023 | my ($last_rev, $last_commit) = $self->last_rev_commit; |
3ebe8df7 | 2024 | my ($base, $head) = $self->get_fetch_range($min_rev, $max_rev); |
e518192f | 2025 | $self->ra->gs_fetch_loop_common($base, $head, [$self]); |
9b981fc6 EW |
2026 | } |
2027 | ||
2028 | sub set_tree_cb { | |
2029 | my ($self, $log_entry, $tree, $rev, $date, $author) = @_; | |
490f49ea EW |
2030 | $self->{inject_parents} = { $rev => $tree }; |
2031 | $self->fetch(undef, undef); | |
9b981fc6 EW |
2032 | } |
2033 | ||
2034 | sub set_tree { | |
2035 | my ($self, $tree) = (shift, shift); | |
1ce255dc | 2036 | my $log_entry = ::get_commit_entry($tree); |
9b981fc6 EW |
2037 | unless ($self->{last_rev}) { |
2038 | fatal("Must have an existing revision to commit\n"); | |
2039 | } | |
61395354 EW |
2040 | my %ed_opts = ( r => $self->{last_rev}, |
2041 | log => $log_entry->{log}, | |
2042 | ra => $self->ra, | |
2043 | tree_a => $self->{last_commit}, | |
2044 | tree_b => $tree, | |
2045 | editor_cb => sub { | |
2046 | $self->set_tree_cb($log_entry, $tree, @_) }, | |
2047 | svn_path => $self->{path} ); | |
2048 | if (!SVN::Git::Editor->new(\%ed_opts)->apply_diff) { | |
9b981fc6 EW |
2049 | print "No changes\nr$self->{last_rev} = $tree\n"; |
2050 | } | |
9b981fc6 EW |
2051 | } |
2052 | ||
f0ecca10 EW |
2053 | sub rebuild { |
2054 | my ($self) = @_; | |
26a62d57 | 2055 | my $db_path = $self->db_path; |
d6d3346b EW |
2056 | return if (-e $db_path && ! -z $db_path); |
2057 | return unless ::verify_ref($self->refname.'^0'); | |
26a62d57 EW |
2058 | if (-f $self->{db_root}) { |
2059 | rename $self->{db_root}, $db_path or die | |
2060 | "rename $self->{db_root} => $db_path failed: $!\n"; | |
2061 | my ($dir, $base) = ($db_path =~ m#^(.*?)/?([^/]+)$#); | |
2062 | symlink $base, $self->{db_root} or die | |
2063 | "symlink $base => $self->{db_root} failed: $!\n"; | |
2064 | return; | |
2065 | } | |
2066 | print "Rebuilding $db_path ...\n"; | |
3dfab993 | 2067 | my ($log, $ctx) = command_output_pipe("log", $self->refname); |
f0ecca10 EW |
2068 | my $latest; |
2069 | my $full_url = $self->full_url; | |
18ea92bd | 2070 | remove_username($full_url); |
f0ecca10 | 2071 | my $svn_uuid; |
3dfab993 SV |
2072 | my $c; |
2073 | while (<$log>) { | |
2074 | if ( m{^commit ($::sha1)$} ) { | |
2075 | $c = $1; | |
2076 | next; | |
2077 | } | |
2078 | next unless s{^\s*(git-svn-id:)}{$1}; | |
2079 | my ($url, $rev, $uuid) = ::extract_metadata($_); | |
18ea92bd | 2080 | remove_username($url); |
f0ecca10 EW |
2081 | |
2082 | # ignore merges (from set-tree) | |
2083 | next if (!defined $rev || !$uuid); | |
2084 | ||
2085 | # if we merged or otherwise started elsewhere, this is | |
2086 | # how we break out of it | |
2087 | if ((defined $svn_uuid && ($uuid ne $svn_uuid)) || | |
2088 | ($full_url && $url && ($url ne $full_url))) { | |
2089 | next; | |
2090 | } | |
2091 | $latest ||= $rev; | |
2092 | $svn_uuid ||= $uuid; | |
2093 | ||
2094 | $self->rev_db_set($rev, $c); | |
2095 | print "r$rev = $c\n"; | |
2096 | } | |
3dfab993 | 2097 | command_close_pipe($log, $ctx); |
26a62d57 | 2098 | print "Done rebuilding $db_path\n"; |
f0ecca10 EW |
2099 | } |
2100 | ||
9b981fc6 EW |
2101 | # rev_db: |
2102 | # Tie::File seems to be prone to offset errors if revisions get sparse, | |
2103 | # it's not that fast, either. Tie::File is also not in Perl 5.6. So | |
2104 | # one of my favorite modules is out :< Next up would be one of the DBM | |
2105 | # modules, but I'm not sure which is most portable... So I'll just | |
2106 | # go with something that's plain-text, but still capable of | |
2107 | # being randomly accessed. So here's my ultra-simple fixed-width | |
2108 | # database. All records are 40 characters + "\n", so it's easy to seek | |
2109 | # to a revision: (41 * rev) is the byte offset. | |
2110 | # A record of 40 0s denotes an empty revision. | |
2111 | # And yes, it's still pretty fast (faster than Tie::File). | |
97ae0911 | 2112 | # These files are disposable unless noMetadata or useSvmProps is set |
9b981fc6 | 2113 | |
26a62d57 EW |
2114 | sub _rev_db_set { |
2115 | my ($fh, $rev, $commit) = @_; | |
2116 | my $offset = $rev * 41; | |
2117 | # assume that append is the common case: | |
2118 | seek $fh, 0, 2 or croak $!; | |
2119 | my $pos = tell $fh; | |
2120 | if ($pos < $offset) { | |
2121 | for (1 .. (($offset - $pos) / 41)) { | |
2122 | print $fh (('0' x 40),"\n") or croak $!; | |
2123 | } | |
2124 | } | |
2125 | seek $fh, $offset, 0 or croak $!; | |
2126 | print $fh $commit,"\n" or croak $!; | |
2127 | } | |
2128 | ||
2129 | sub mkfile { | |
2130 | my ($path) = @_; | |
2131 | unless (-e $path) { | |
2132 | my ($dir, $base) = ($path =~ m#^(.*?)/?([^/]+)$#); | |
2133 | mkpath([$dir]) unless -d $dir; | |
2134 | open my $fh, '>>', $path or die "Couldn't create $path: $!\n"; | |
2135 | close $fh or die "Couldn't close (create) $path: $!\n"; | |
2136 | } | |
2137 | } | |
2138 | ||
9b981fc6 | 2139 | sub rev_db_set { |
26a62d57 EW |
2140 | my ($self, $rev, $commit, $update_ref, $uuid) = @_; |
2141 | length $commit == 40 or die "arg3 must be a full SHA1 hexsum\n"; | |
2142 | my $db = $self->db_path($uuid); | |
2143 | my $db_lock = "$db.lock"; | |
373274f9 EW |
2144 | my $sig; |
2145 | if ($update_ref) { | |
2146 | $SIG{INT} = $SIG{HUP} = $SIG{TERM} = $SIG{ALRM} = $SIG{PIPE} = | |
2147 | $SIG{USR1} = $SIG{USR2} = sub { $sig = $_[0] }; | |
2148 | } | |
26a62d57 EW |
2149 | mkfile($db); |
2150 | ||
373274f9 | 2151 | $LOCKFILES{$db_lock} = 1; |
97ae0911 | 2152 | my $sync; |
97ae0911 EW |
2153 | # both of these options make our .rev_db file very, very important |
2154 | # and we can't afford to lose it because rebuild() won't work | |
2155 | if ($self->use_svm_props || $self->no_metadata) { | |
2156 | $sync = 1; | |
373274f9 | 2157 | copy($db, $db_lock) or die "rev_db_set(@_): ", |
26a62d57 | 2158 | "Failed to copy: ", |
373274f9 EW |
2159 | "$db => $db_lock ($!)\n"; |
2160 | } else { | |
2161 | rename $db, $db_lock or die "rev_db_set(@_): ", | |
26a62d57 | 2162 | "Failed to rename: ", |
373274f9 EW |
2163 | "$db => $db_lock ($!)\n"; |
2164 | } | |
26a62d57 EW |
2165 | open my $fh, '+<', $db_lock or die "Couldn't open $db_lock: $!\n"; |
2166 | _rev_db_set($fh, $rev, $commit); | |
97ae0911 EW |
2167 | if ($sync) { |
2168 | $fh->flush or die "Couldn't flush $db_lock: $!\n"; | |
2169 | $fh->sync or die "Couldn't sync $db_lock: $!\n"; | |
2170 | } | |
9b981fc6 | 2171 | close $fh or croak $!; |
373274f9 | 2172 | if ($update_ref) { |
1e889ef3 | 2173 | $_head = $self; |
373274f9 EW |
2174 | command_noisy('update-ref', '-m', "r$rev", |
2175 | $self->refname, $commit); | |
2176 | } | |
2177 | rename $db_lock, $db or die "rev_db_set(@_): ", "Failed to rename: ", | |
2178 | "$db_lock => $db ($!)\n"; | |
2179 | delete $LOCKFILES{$db_lock}; | |
2180 | if ($update_ref) { | |
2181 | $SIG{INT} = $SIG{HUP} = $SIG{TERM} = $SIG{ALRM} = $SIG{PIPE} = | |
2182 | $SIG{USR1} = $SIG{USR2} = 'DEFAULT'; | |
2183 | kill $sig, $$ if defined $sig; | |
2184 | } | |
9b981fc6 EW |
2185 | } |
2186 | ||
9c93fee5 EW |
2187 | sub rev_db_max { |
2188 | my ($self) = @_; | |
d6d3346b | 2189 | $self->rebuild; |
26a62d57 EW |
2190 | my $db_path = $self->db_path; |
2191 | my @stat = stat $db_path or return 0; | |
2192 | ($stat[7] % 41) == 0 or die "$db_path inconsistent size: $stat[7]\n"; | |
9c93fee5 EW |
2193 | my $max = $stat[7] / 41; |
2194 | (($max > 0) ? $max - 1 : 0); | |
2195 | } | |
2196 | ||
9b981fc6 | 2197 | sub rev_db_get { |
26a62d57 | 2198 | my ($self, $rev, $uuid) = @_; |
9b981fc6 EW |
2199 | my $ret; |
2200 | my $offset = $rev * 41; | |
26a62d57 EW |
2201 | my $db_path = $self->db_path($uuid); |
2202 | return undef unless -e $db_path; | |
2203 | open my $fh, '<', $db_path or croak $!; | |
ce4b4af7 EW |
2204 | if (sysseek($fh, $offset, 0) == $offset) { |
2205 | my $read = sysread($fh, $ret, 40); | |
2206 | $ret = undef if ($read != 40 || $ret eq ('0'x40)); | |
9b981fc6 EW |
2207 | } |
2208 | close $fh or croak $!; | |
2209 | $ret; | |
2210 | } | |
2211 | ||
15710b6f EW |
2212 | sub find_rev_before { |
2213 | my ($self, $rev, $eq_ok) = @_; | |
2214 | --$rev unless $eq_ok; | |
2215 | while ($rev > 0) { | |
2216 | if (my $c = $self->rev_db_get($rev)) { | |
2217 | return ($rev, $c); | |
2218 | } | |
2219 | --$rev; | |
2220 | } | |
2221 | return (undef, undef); | |
2222 | } | |
2223 | ||
9b981fc6 | 2224 | sub _new { |
706587fc EW |
2225 | my ($class, $repo_id, $ref_id, $path) = @_; |
2226 | unless (defined $repo_id && length $repo_id) { | |
2227 | $repo_id = $Git::SVN::default_repo_id; | |
2228 | } | |
2229 | unless (defined $ref_id && length $ref_id) { | |
8b8fc068 | 2230 | $_[2] = $ref_id = $Git::SVN::default_ref_id; |
706587fc EW |
2231 | } |
2232 | $_[1] = $repo_id = sanitize_remote_name($repo_id); | |
2233 | my $dir = "$ENV{GIT_DIR}/svn/$ref_id"; | |
2234 | $_[3] = $path = '' unless (defined $path); | |
b4d57e5e | 2235 | mkpath(["$ENV{GIT_DIR}/svn"]); |
26a62d57 EW |
2236 | bless { |
2237 | ref_id => $ref_id, dir => $dir, index => "$dir/index", | |
8a49ee97 | 2238 | path => $path, config => "$ENV{GIT_DIR}/svn/config", |
26a62d57 EW |
2239 | db_root => "$dir/.rev_db", repo_id => $repo_id }, $class; |
2240 | } | |
2241 | ||
2242 | sub db_path { | |
2243 | my ($self, $uuid) = @_; | |
2244 | $uuid ||= $self->ra_uuid; | |
2245 | "$self->{db_root}.$uuid"; | |
9b981fc6 EW |
2246 | } |
2247 | ||
1c8443b0 EW |
2248 | sub uri_encode { |
2249 | my ($f) = @_; | |
2250 | $f =~ s#([^a-zA-Z0-9\*!\:_\./\-])#uc sprintf("%%%02x",ord($1))#eg; | |
2251 | $f | |
2252 | } | |
9b981fc6 | 2253 | |
18ea92bd SV |
2254 | sub remove_username { |
2255 | $_[0] =~ s{^([^:]*://)[^@]+@}{$1}; | |
2256 | } | |
2257 | ||
d976acfd EW |
2258 | package Git::SVN::Prompt; |
2259 | use strict; | |
2260 | use warnings; | |
2261 | require SVN::Core; | |
2262 | use vars qw/$_no_auth_cache $_username/; | |
2263 | ||
2264 | sub simple { | |
30d055aa EW |
2265 | my ($cred, $realm, $default_username, $may_save, $pool) = @_; |
2266 | $may_save = undef if $_no_auth_cache; | |
2267 | $default_username = $_username if defined $_username; | |
2268 | if (defined $default_username && length $default_username) { | |
2269 | if (defined $realm && length $realm) { | |
6f729591 EW |
2270 | print STDERR "Authentication realm: $realm\n"; |
2271 | STDERR->flush; | |
30d055aa EW |
2272 | } |
2273 | $cred->username($default_username); | |
2274 | } else { | |
d976acfd | 2275 | username($cred, $realm, $may_save, $pool); |
30d055aa EW |
2276 | } |
2277 | $cred->password(_read_password("Password for '" . | |
2278 | $cred->username . "': ", $realm)); | |
2279 | $cred->may_save($may_save); | |
2280 | $SVN::_Core::SVN_NO_ERROR; | |
2281 | } | |
2282 | ||
d976acfd | 2283 | sub ssl_server_trust { |
30d055aa EW |
2284 | my ($cred, $realm, $failures, $cert_info, $may_save, $pool) = @_; |
2285 | $may_save = undef if $_no_auth_cache; | |
6f729591 | 2286 | print STDERR "Error validating server certificate for '$realm':\n"; |
30d055aa | 2287 | if ($failures & $SVN::Auth::SSL::UNKNOWNCA) { |
6f729591 | 2288 | print STDERR " - The certificate is not issued by a trusted ", |
30d055aa EW |
2289 | "authority. Use the\n", |
2290 | " fingerprint to validate the certificate manually!\n"; | |
2291 | } | |
2292 | if ($failures & $SVN::Auth::SSL::CNMISMATCH) { | |
6f729591 | 2293 | print STDERR " - The certificate hostname does not match.\n"; |
30d055aa EW |
2294 | } |
2295 | if ($failures & $SVN::Auth::SSL::NOTYETVALID) { | |
6f729591 | 2296 | print STDERR " - The certificate is not yet valid.\n"; |
30d055aa EW |
2297 | } |
2298 | if ($failures & $SVN::Auth::SSL::EXPIRED) { | |
6f729591 | 2299 | print STDERR " - The certificate has expired.\n"; |
30d055aa EW |
2300 | } |
2301 | if ($failures & $SVN::Auth::SSL::OTHER) { | |
6f729591 | 2302 | print STDERR " - The certificate has an unknown error.\n"; |
30d055aa | 2303 | } |
6f729591 EW |
2304 | printf STDERR |
2305 | "Certificate information:\n". | |
30d055aa EW |
2306 | " - Hostname: %s\n". |
2307 | " - Valid: from %s until %s\n". | |
2308 | " - Issuer: %s\n". | |
2309 | " - Fingerprint: %s\n", | |
2310 | map $cert_info->$_, qw(hostname valid_from valid_until | |
6f729591 | 2311 | issuer_dname fingerprint); |
30d055aa EW |
2312 | my $choice; |
2313 | prompt: | |
6f729591 | 2314 | print STDERR $may_save ? |
30d055aa EW |
2315 | "(R)eject, accept (t)emporarily or accept (p)ermanently? " : |
2316 | "(R)eject or accept (t)emporarily? "; | |
6f729591 | 2317 | STDERR->flush; |
30d055aa EW |
2318 | $choice = lc(substr(<STDIN> || 'R', 0, 1)); |
2319 | if ($choice =~ /^t$/i) { | |
2320 | $cred->may_save(undef); | |
2321 | } elsif ($choice =~ /^r$/i) { | |
2322 | return -1; | |
2323 | } elsif ($may_save && $choice =~ /^p$/i) { | |
2324 | $cred->may_save($may_save); | |
2325 | } else { | |
2326 | goto prompt; | |
2327 | } | |
2328 | $cred->accepted_failures($failures); | |
2329 | $SVN::_Core::SVN_NO_ERROR; | |
2330 | } | |
2331 | ||
d976acfd | 2332 | sub ssl_client_cert { |
30d055aa EW |
2333 | my ($cred, $realm, $may_save, $pool) = @_; |
2334 | $may_save = undef if $_no_auth_cache; | |
6f729591 EW |
2335 | print STDERR "Client certificate filename: "; |
2336 | STDERR->flush; | |
30d055aa EW |
2337 | chomp(my $filename = <STDIN>); |
2338 | $cred->cert_file($filename); | |
2339 | $cred->may_save($may_save); | |
2340 | $SVN::_Core::SVN_NO_ERROR; | |
2341 | } | |
2342 | ||
d976acfd | 2343 | sub ssl_client_cert_pw { |
30d055aa EW |
2344 | my ($cred, $realm, $may_save, $pool) = @_; |
2345 | $may_save = undef if $_no_auth_cache; | |
2346 | $cred->password(_read_password("Password: ", $realm)); | |
2347 | $cred->may_save($may_save); | |
2348 | $SVN::_Core::SVN_NO_ERROR; | |
2349 | } | |
2350 | ||
d976acfd | 2351 | sub username { |
30d055aa EW |
2352 | my ($cred, $realm, $may_save, $pool) = @_; |
2353 | $may_save = undef if $_no_auth_cache; | |
2354 | if (defined $realm && length $realm) { | |
6f729591 | 2355 | print STDERR "Authentication realm: $realm\n"; |
30d055aa EW |
2356 | } |
2357 | my $username; | |
2358 | if (defined $_username) { | |
2359 | $username = $_username; | |
2360 | } else { | |
6f729591 EW |
2361 | print STDERR "Username: "; |
2362 | STDERR->flush; | |
30d055aa EW |
2363 | chomp($username = <STDIN>); |
2364 | } | |
2365 | $cred->username($username); | |
2366 | $cred->may_save($may_save); | |
2367 | $SVN::_Core::SVN_NO_ERROR; | |
2368 | } | |
2369 | ||
2370 | sub _read_password { | |
2371 | my ($prompt, $realm) = @_; | |
6f729591 EW |
2372 | print STDERR $prompt; |
2373 | STDERR->flush; | |
30d055aa EW |
2374 | require Term::ReadKey; |
2375 | Term::ReadKey::ReadMode('noecho'); | |
2376 | my $password = ''; | |
2377 | while (defined(my $key = Term::ReadKey::ReadKey(0))) { | |
2378 | last if $key =~ /[\012\015]/; # \n\r | |
2379 | $password .= $key; | |
2380 | } | |
2381 | Term::ReadKey::ReadMode('restore'); | |
6f729591 EW |
2382 | print STDERR "\n"; |
2383 | STDERR->flush; | |
30d055aa EW |
2384 | $password; |
2385 | } | |
2386 | ||
d976acfd EW |
2387 | package main; |
2388 | ||
b9c85187 EW |
2389 | { |
2390 | my $kill_stupid_warnings = $SVN::Node::none.$SVN::Node::file. | |
2391 | $SVN::Node::dir.$SVN::Node::unknown. | |
2392 | $SVN::Node::none.$SVN::Node::file. | |
2393 | $SVN::Node::dir.$SVN::Node::unknown. | |
2394 | $SVN::Auth::SSL::CNMISMATCH. | |
2395 | $SVN::Auth::SSL::NOTYETVALID. | |
2396 | $SVN::Auth::SSL::EXPIRED. | |
2397 | $SVN::Auth::SSL::UNKNOWNCA. | |
2398 | $SVN::Auth::SSL::OTHER; | |
2399 | } | |
2400 | ||
27a1a801 EW |
2401 | package SVN::Git::Fetcher; |
2402 | use vars qw/@ISA/; | |
2403 | use strict; | |
2404 | use warnings; | |
2405 | use Carp qw/croak/; | |
2406 | use IO::File qw//; | |
90c1b15d | 2407 | use Digest::MD5; |
27a1a801 EW |
2408 | |
2409 | # file baton members: path, mode_a, mode_b, pool, fh, blob, base | |
2410 | sub new { | |
2411 | my ($class, $git_svn) = @_; | |
2412 | my $self = SVN::Delta::Editor->new; | |
2413 | bless $self, $class; | |
1c8443b0 | 2414 | $self->{c} = $git_svn->{last_commit} if exists $git_svn->{last_commit}; |
d2a9a87b EW |
2415 | $self->{empty} = {}; |
2416 | $self->{dir_prop} = {}; | |
2417 | $self->{file_prop} = {}; | |
2418 | $self->{absent_dir} = {}; | |
2419 | $self->{absent_file} = {}; | |
ef3cfaad | 2420 | $self->{gii} = $git_svn->tmp_index_do(sub { Git::IndexInfo->new }); |
27a1a801 EW |
2421 | $self; |
2422 | } | |
2423 | ||
8b8fc068 EW |
2424 | sub set_path_strip { |
2425 | my ($self, $path) = @_; | |
4e9f6cc7 | 2426 | $self->{path_strip} = qr/^\Q$path\E(\/|$)/ if length $path; |
8b8fc068 EW |
2427 | } |
2428 | ||
d2a9a87b EW |
2429 | sub open_root { |
2430 | { path => '' }; | |
2431 | } | |
2432 | ||
2433 | sub open_directory { | |
2434 | my ($self, $path, $pb, $rev) = @_; | |
2435 | { path => $path }; | |
2436 | } | |
2437 | ||
706587fc EW |
2438 | sub git_path { |
2439 | my ($self, $path) = @_; | |
2b27f6c8 EW |
2440 | if ($self->{path_strip}) { |
2441 | $path =~ s!$self->{path_strip}!! or | |
2442 | die "Failed to strip path '$path' ($self->{path_strip})\n"; | |
2443 | } | |
706587fc EW |
2444 | $path; |
2445 | } | |
2446 | ||
27a1a801 EW |
2447 | sub delete_entry { |
2448 | my ($self, $path, $rev, $pb) = @_; | |
4a87db0e | 2449 | |
706587fc | 2450 | my $gpath = $self->git_path($path); |
8a603774 EW |
2451 | return undef if ($gpath eq ''); |
2452 | ||
4a87db0e | 2453 | # remove entire directories. |
706587fc | 2454 | if (command('ls-tree', $self->{c}, '--', $gpath) =~ /^040000 tree/) { |
4a87db0e EW |
2455 | my ($ls, $ctx) = command_output_pipe(qw/ls-tree |
2456 | -r --name-only -z/, | |
706587fc | 2457 | $self->{c}, '--', $gpath); |
4a87db0e EW |
2458 | local $/ = "\0"; |
2459 | while (<$ls>) { | |
ef3cfaad EW |
2460 | chomp; |
2461 | $self->{gii}->remove($_); | |
9e3cdbd4 | 2462 | print "\tD\t$_\n" unless $::_q; |
4a87db0e | 2463 | } |
9e3cdbd4 | 2464 | print "\tD\t$gpath/\n" unless $::_q; |
4a87db0e EW |
2465 | command_close_pipe($ls, $ctx); |
2466 | $self->{empty}->{$path} = 0 | |
2467 | } else { | |
ef3cfaad | 2468 | $self->{gii}->remove($gpath); |
9e3cdbd4 | 2469 | print "\tD\t$gpath\n" unless $::_q; |
4a87db0e | 2470 | } |
27a1a801 EW |
2471 | undef; |
2472 | } | |
2473 | ||
2474 | sub open_file { | |
2475 | my ($self, $path, $pb, $rev) = @_; | |
706587fc EW |
2476 | my $gpath = $self->git_path($path); |
2477 | my ($mode, $blob) = (command('ls-tree', $self->{c}, '--', $gpath) | |
27a1a801 | 2478 | =~ /^(\d{6}) blob ([a-f\d]{40})\t/); |
006ede5e EW |
2479 | unless (defined $mode && defined $blob) { |
2480 | die "$path was not found in commit $self->{c} (r$rev)\n"; | |
2481 | } | |
27a1a801 | 2482 | { path => $path, mode_a => $mode, mode_b => $mode, blob => $blob, |
0864e3ba | 2483 | pool => SVN::Pool->new, action => 'M' }; |
27a1a801 EW |
2484 | } |
2485 | ||
2486 | sub add_file { | |
2487 | my ($self, $path, $pb, $cp_path, $cp_rev) = @_; | |
d2a9a87b EW |
2488 | my ($dir, $file) = ($path =~ m#^(.*?)/?([^/]+)$#); |
2489 | delete $self->{empty}->{$dir}; | |
27a1a801 | 2490 | { path => $path, mode_a => 100644, mode_b => 100644, |
0864e3ba | 2491 | pool => SVN::Pool->new, action => 'A' }; |
27a1a801 EW |
2492 | } |
2493 | ||
d2a9a87b EW |
2494 | sub add_directory { |
2495 | my ($self, $path, $cp_path, $cp_rev) = @_; | |
2496 | my ($dir, $file) = ($path =~ m#^(.*?)/?([^/]+)$#); | |
2497 | delete $self->{empty}->{$dir}; | |
2498 | $self->{empty}->{$path} = 1; | |
2499 | { path => $path }; | |
2500 | } | |
2501 | ||
2502 | sub change_dir_prop { | |
2503 | my ($self, $db, $prop, $value) = @_; | |
2504 | $self->{dir_prop}->{$db->{path}} ||= {}; | |
2505 | $self->{dir_prop}->{$db->{path}}->{$prop} = $value; | |
2506 | undef; | |
2507 | } | |
2508 | ||
2509 | sub absent_directory { | |
2510 | my ($self, $path, $pb) = @_; | |
2511 | $self->{absent_dir}->{$pb->{path}} ||= []; | |
2512 | push @{$self->{absent_dir}->{$pb->{path}}}, $path; | |
2513 | undef; | |
2514 | } | |
2515 | ||
2516 | sub absent_file { | |
2517 | my ($self, $path, $pb) = @_; | |
2518 | $self->{absent_file}->{$pb->{path}} ||= []; | |
2519 | push @{$self->{absent_file}->{$pb->{path}}}, $path; | |
2520 | undef; | |
2521 | } | |
2522 | ||
27a1a801 EW |
2523 | sub change_file_prop { |
2524 | my ($self, $fb, $prop, $value) = @_; | |
2525 | if ($prop eq 'svn:executable') { | |
2526 | if ($fb->{mode_b} != 120000) { | |
2527 | $fb->{mode_b} = defined $value ? 100755 : 100644; | |
2528 | } | |
2529 | } elsif ($prop eq 'svn:special') { | |
2530 | $fb->{mode_b} = defined $value ? 120000 : 100644; | |
d2a9a87b EW |
2531 | } else { |
2532 | $self->{file_prop}->{$fb->{path}} ||= {}; | |
2533 | $self->{file_prop}->{$fb->{path}}->{$prop} = $value; | |
27a1a801 EW |
2534 | } |
2535 | undef; | |
2536 | } | |
2537 | ||
2538 | sub apply_textdelta { | |
2539 | my ($self, $fb, $exp) = @_; | |
2540 | my $fh = IO::File->new_tmpfile; | |
2541 | $fh->autoflush(1); | |
2542 | # $fh gets auto-closed() by SVN::TxDelta::apply(), | |
2543 | # (but $base does not,) so dup() it for reading in close_file | |
2544 | open my $dup, '<&', $fh or croak $!; | |
2545 | my $base = IO::File->new_tmpfile; | |
2546 | $base->autoflush(1); | |
2547 | if ($fb->{blob}) { | |
2548 | defined (my $pid = fork) or croak $!; | |
2549 | if (!$pid) { | |
2550 | open STDOUT, '>&', $base or croak $!; | |
2551 | print STDOUT 'link ' if ($fb->{mode_a} == 120000); | |
2552 | exec qw/git-cat-file blob/, $fb->{blob} or croak $!; | |
2553 | } | |
2554 | waitpid $pid, 0; | |
2555 | croak $? if $?; | |
2556 | ||
2557 | if (defined $exp) { | |
2558 | seek $base, 0, 0 or croak $!; | |
2559 | my $md5 = Digest::MD5->new; | |
2560 | $md5->addfile($base); | |
2561 | my $got = $md5->hexdigest; | |
2562 | die "Checksum mismatch: $fb->{path} $fb->{blob}\n", | |
2563 | "expected: $exp\n", | |
2564 | " got: $got\n" if ($got ne $exp); | |
2565 | } | |
2566 | } | |
2567 | seek $base, 0, 0 or croak $!; | |
2568 | $fb->{fh} = $dup; | |
2569 | $fb->{base} = $base; | |
2570 | [ SVN::TxDelta::apply($base, $fh, undef, $fb->{path}, $fb->{pool}) ]; | |
2571 | } | |
2572 | ||
2573 | sub close_file { | |
2574 | my ($self, $fb, $exp) = @_; | |
2575 | my $hash; | |
706587fc | 2576 | my $path = $self->git_path($fb->{path}); |
27a1a801 | 2577 | if (my $fh = $fb->{fh}) { |
7faf0686 EW |
2578 | if (defined $exp) { |
2579 | seek($fh, 0, 0) or croak $!; | |
2580 | my $md5 = Digest::MD5->new; | |
2581 | $md5->addfile($fh); | |
2582 | my $got = $md5->hexdigest; | |
2583 | if ($got ne $exp) { | |
2584 | die "Checksum mismatch: $path\n", | |
2585 | "expected: $exp\n got: $got\n"; | |
2586 | } | |
2587 | } | |
bcd8ee5b | 2588 | sysseek($fh, 0, 0) or croak $!; |
27a1a801 | 2589 | if ($fb->{mode_b} == 120000) { |
bcd8ee5b | 2590 | sysread($fh, my $buf, 5) == 5 or croak $!; |
27a1a801 EW |
2591 | $buf eq 'link ' or die "$path has mode 120000", |
2592 | "but is not a link\n"; | |
2593 | } | |
2594 | defined(my $pid = open my $out,'-|') or die "Can't fork: $!\n"; | |
2595 | if (!$pid) { | |
2596 | open STDIN, '<&', $fh or croak $!; | |
2597 | exec qw/git-hash-object -w --stdin/ or croak $!; | |
2598 | } | |
2599 | chomp($hash = do { local $/; <$out> }); | |
2600 | close $out or croak $!; | |
2601 | close $fh or croak $!; | |
2602 | $hash =~ /^[a-f\d]{40}$/ or die "not a sha1: $hash\n"; | |
2603 | close $fb->{base} or croak $!; | |
2604 | } else { | |
2605 | $hash = $fb->{blob} or die "no blob information\n"; | |
2606 | } | |
2607 | $fb->{pool}->clear; | |
ef3cfaad | 2608 | $self->{gii}->update($fb->{mode_b}, $hash, $path) or croak $!; |
9e3cdbd4 | 2609 | print "\t$fb->{action}\t$path\n" if $fb->{action} && ! $::_q; |
27a1a801 EW |
2610 | undef; |
2611 | } | |
2612 | ||
2613 | sub abort_edit { | |
2614 | my $self = shift; | |
ef3cfaad EW |
2615 | $self->{nr} = $self->{gii}->{nr}; |
2616 | delete $self->{gii}; | |
27a1a801 EW |
2617 | $self->SUPER::abort_edit(@_); |
2618 | } | |
2619 | ||
2620 | sub close_edit { | |
2621 | my $self = shift; | |
dad73c0b | 2622 | $self->{git_commit_ok} = 1; |
ef3cfaad EW |
2623 | $self->{nr} = $self->{gii}->{nr}; |
2624 | delete $self->{gii}; | |
27a1a801 EW |
2625 | $self->SUPER::close_edit(@_); |
2626 | } | |
1a82e793 | 2627 | |
a5e0cedc | 2628 | package SVN::Git::Editor; |
24e22aa8 | 2629 | use vars qw/@ISA $_rmdir $_cp_similarity $_find_copies_harder $_rename_limit/; |
a5e0cedc EW |
2630 | use strict; |
2631 | use warnings; | |
2632 | use Carp qw/croak/; | |
2633 | use IO::File; | |
90c1b15d | 2634 | use Digest::MD5; |
a5e0cedc EW |
2635 | |
2636 | sub new { | |
61395354 EW |
2637 | my ($class, $opts) = @_; |
2638 | foreach (qw/svn_path r ra tree_a tree_b log editor_cb/) { | |
2639 | die "$_ required!\n" unless (defined $opts->{$_}); | |
2640 | } | |
2641 | ||
2642 | my $pool = SVN::Pool->new; | |
2643 | my $mods = generate_diff($opts->{tree_a}, $opts->{tree_b}); | |
2644 | my $types = check_diff_paths($opts->{ra}, $opts->{svn_path}, | |
2645 | $opts->{r}, $mods); | |
2646 | ||
2647 | # $opts->{ra} functions should not be used after this: | |
2648 | my @ce = $opts->{ra}->get_commit_editor($opts->{log}, | |
2649 | $opts->{editor_cb}, $pool); | |
2650 | my $self = SVN::Delta::Editor->new(@ce, $pool); | |
a5e0cedc | 2651 | bless $self, $class; |
61395354 EW |
2652 | foreach (qw/svn_path r tree_a tree_b/) { |
2653 | $self->{$_} = $opts->{$_}; | |
a5e0cedc | 2654 | } |
61395354 EW |
2655 | $self->{url} = $opts->{ra}->{url}; |
2656 | $self->{mods} = $mods; | |
2657 | $self->{types} = $types; | |
2658 | $self->{pool} = $pool; | |
a5e0cedc EW |
2659 | $self->{bat} = { '' => $self->open_root($self->{r}, $self->{pool}) }; |
2660 | $self->{rm} = { }; | |
d3a840dc EW |
2661 | $self->{path_prefix} = length $self->{svn_path} ? |
2662 | "$self->{svn_path}/" : ''; | |
a5e0cedc EW |
2663 | return $self; |
2664 | } | |
2665 | ||
61395354 EW |
2666 | sub generate_diff { |
2667 | my ($tree_a, $tree_b) = @_; | |
2668 | my @diff_tree = qw(diff-tree -z -r); | |
24e22aa8 EW |
2669 | if ($_cp_similarity) { |
2670 | push @diff_tree, "-C$_cp_similarity"; | |
61395354 EW |
2671 | } else { |
2672 | push @diff_tree, '-C'; | |
2673 | } | |
24e22aa8 EW |
2674 | push @diff_tree, '--find-copies-harder' if $_find_copies_harder; |
2675 | push @diff_tree, "-l$_rename_limit" if defined $_rename_limit; | |
61395354 EW |
2676 | push @diff_tree, $tree_a, $tree_b; |
2677 | my ($diff_fh, $ctx) = command_output_pipe(@diff_tree); | |
2678 | local $/ = "\0"; | |
2679 | my $state = 'meta'; | |
2680 | my @mods; | |
2681 | while (<$diff_fh>) { | |
2682 | chomp $_; # this gets rid of the trailing "\0" | |
2683 | if ($state eq 'meta' && /^:(\d{6})\s(\d{6})\s | |
2684 | $::sha1\s($::sha1)\s | |
2685 | ([MTCRAD])\d*$/xo) { | |
2686 | push @mods, { mode_a => $1, mode_b => $2, | |
2687 | sha1_b => $3, chg => $4 }; | |
2688 | if ($4 =~ /^(?:C|R)$/) { | |
2689 | $state = 'file_a'; | |
2690 | } else { | |
2691 | $state = 'file_b'; | |
2692 | } | |
2693 | } elsif ($state eq 'file_a') { | |
2694 | my $x = $mods[$#mods] or croak "Empty array\n"; | |
2695 | if ($x->{chg} !~ /^(?:C|R)$/) { | |
2696 | croak "Error parsing $_, $x->{chg}\n"; | |
2697 | } | |
2698 | $x->{file_a} = $_; | |
2699 | $state = 'file_b'; | |
2700 | } elsif ($state eq 'file_b') { | |
2701 | my $x = $mods[$#mods] or croak "Empty array\n"; | |
2702 | if (exists $x->{file_a} && $x->{chg} !~ /^(?:C|R)$/) { | |
2703 | croak "Error parsing $_, $x->{chg}\n"; | |
2704 | } | |
2705 | if (!exists $x->{file_a} && $x->{chg} =~ /^(?:C|R)$/) { | |
2706 | croak "Error parsing $_, $x->{chg}\n"; | |
2707 | } | |
2708 | $x->{file_b} = $_; | |
2709 | $state = 'meta'; | |
2710 | } else { | |
2711 | croak "Error parsing $_\n"; | |
2712 | } | |
2713 | } | |
2714 | command_close_pipe($diff_fh, $ctx); | |
2715 | \@mods; | |
2716 | } | |
2717 | ||
2718 | sub check_diff_paths { | |
2719 | my ($ra, $pfx, $rev, $mods) = @_; | |
2720 | my %types; | |
2721 | $pfx .= '/' if length $pfx; | |
2722 | ||
2723 | sub type_diff_paths { | |
2724 | my ($ra, $types, $path, $rev) = @_; | |
2725 | my @p = split m#/+#, $path; | |
2726 | my $c = shift @p; | |
2727 | unless (defined $types->{$c}) { | |
2728 | $types->{$c} = $ra->check_path($c, $rev); | |
2729 | } | |
2730 | while (@p) { | |
2731 | $c .= '/' . shift @p; | |
2732 | next if defined $types->{$c}; | |
2733 | $types->{$c} = $ra->check_path($c, $rev); | |
2734 | } | |
2735 | } | |
2736 | ||
2737 | foreach my $m (@$mods) { | |
2738 | foreach my $f (qw/file_a file_b/) { | |
2739 | next unless defined $m->{$f}; | |
2740 | my ($dir) = ($m->{$f} =~ m#^(.*?)/?(?:[^/]+)$#); | |
2741 | if (length $pfx.$dir && ! defined $types{$dir}) { | |
2742 | type_diff_paths($ra, \%types, $pfx.$dir, $rev); | |
2743 | } | |
2744 | } | |
2745 | } | |
2746 | \%types; | |
2747 | } | |
2748 | ||
a5e0cedc EW |
2749 | sub split_path { |
2750 | return ($_[0] =~ m#^(.*?)/?([^/]+)$#); | |
2751 | } | |
2752 | ||
2753 | sub repo_path { | |
d3a840dc EW |
2754 | my ($self, $path) = @_; |
2755 | $self->{path_prefix}.(defined $path ? $path : ''); | |
a5e0cedc EW |
2756 | } |
2757 | ||
2758 | sub url_path { | |
2759 | my ($self, $path) = @_; | |
29633bb9 EW |
2760 | if ($self->{url} =~ m#^https?://#) { |
2761 | $path =~ s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg; | |
2762 | } | |
6e8548cc | 2763 | $self->{url} . '/' . $self->repo_path($path); |
a5e0cedc EW |
2764 | } |
2765 | ||
2766 | sub rmdirs { | |
61395354 | 2767 | my ($self) = @_; |
a5e0cedc EW |
2768 | my $rm = $self->{rm}; |
2769 | delete $rm->{''}; # we never delete the url we're tracking | |
2770 | return unless %$rm; | |
2771 | ||
2772 | foreach (keys %$rm) { | |
2773 | my @d = split m#/#, $_; | |
2774 | my $c = shift @d; | |
2775 | $rm->{$c} = 1; | |
2776 | while (@d) { | |
2777 | $c .= '/' . shift @d; | |
2778 | $rm->{$c} = 1; | |
2779 | } | |
2780 | } | |
2781 | delete $rm->{$self->{svn_path}}; | |
2782 | delete $rm->{''}; # we never delete the url we're tracking | |
2783 | return unless %$rm; | |
2784 | ||
61395354 EW |
2785 | my ($fh, $ctx) = command_output_pipe(qw/ls-tree --name-only -r -z/, |
2786 | $self->{tree_b}); | |
a5e0cedc EW |
2787 | local $/ = "\0"; |
2788 | while (<$fh>) { | |
2789 | chomp; | |
747fa12c | 2790 | my @dn = split m#/#, $_; |
c07eee1f EW |
2791 | while (pop @dn) { |
2792 | delete $rm->{join '/', @dn}; | |
2793 | } | |
2794 | unless (%$rm) { | |
22600a25 | 2795 | close $fh; |
c07eee1f EW |
2796 | return; |
2797 | } | |
a5e0cedc | 2798 | } |
aef4e921 | 2799 | command_close_pipe($fh, $ctx); |
c07eee1f | 2800 | |
a5e0cedc EW |
2801 | my ($r, $p, $bat) = ($self->{r}, $self->{pool}, $self->{bat}); |
2802 | foreach my $d (sort { $b =~ tr#/#/# <=> $a =~ tr#/#/# } keys %$rm) { | |
2803 | $self->close_directory($bat->{$d}, $p); | |
2804 | my ($dn) = ($d =~ m#^(.*?)/?(?:[^/]+)$#); | |
44320b9e | 2805 | print "\tD+\t$d/\n" unless $::_q; |
a5e0cedc EW |
2806 | $self->SUPER::delete_entry($d, $r, $bat->{$dn}, $p); |
2807 | delete $bat->{$d}; | |
2808 | } | |
2809 | } | |
2810 | ||
2811 | sub open_or_add_dir { | |
2812 | my ($self, $full_path, $baton) = @_; | |
6e8548cc EW |
2813 | my $t = $self->{types}->{$full_path}; |
2814 | if (!defined $t) { | |
2815 | die "$full_path not known in r$self->{r} or we have a bug!\n"; | |
2816 | } | |
a5e0cedc EW |
2817 | if ($t == $SVN::Node::none) { |
2818 | return $self->add_directory($full_path, $baton, | |
2819 | undef, -1, $self->{pool}); | |
2820 | } elsif ($t == $SVN::Node::dir) { | |
2821 | return $self->open_directory($full_path, $baton, | |
2822 | $self->{r}, $self->{pool}); | |
2823 | } | |
2824 | print STDERR "$full_path already exists in repository at ", | |
2825 | "r$self->{r} and it is not a directory (", | |
2826 | ($t == $SVN::Node::file ? 'file' : 'unknown'),"/$t)\n"; | |
2827 | exit 1; | |
2828 | } | |
2829 | ||
2830 | sub ensure_path { | |
2831 | my ($self, $path) = @_; | |
2832 | my $bat = $self->{bat}; | |
6e8548cc EW |
2833 | my $repo_path = $self->repo_path($path); |
2834 | return $bat->{''} unless (length $repo_path); | |
2835 | my @p = split m#/+#, $repo_path; | |
a5e0cedc EW |
2836 | my $c = shift @p; |
2837 | $bat->{$c} ||= $self->open_or_add_dir($c, $bat->{''}); | |
2838 | while (@p) { | |
2839 | my $c0 = $c; | |
2840 | $c .= '/' . shift @p; | |
2841 | $bat->{$c} ||= $self->open_or_add_dir($c, $bat->{$c0}); | |
2842 | } | |
2843 | return $bat->{$c}; | |
2844 | } | |
2845 | ||
2846 | sub A { | |
44320b9e | 2847 | my ($self, $m) = @_; |
a5e0cedc EW |
2848 | my ($dir, $file) = split_path($m->{file_b}); |
2849 | my $pbat = $self->ensure_path($dir); | |
2850 | my $fbat = $self->add_file($self->repo_path($m->{file_b}), $pbat, | |
2851 | undef, -1); | |
44320b9e | 2852 | print "\tA\t$m->{file_b}\n" unless $::_q; |
a5e0cedc EW |
2853 | $self->chg_file($fbat, $m); |
2854 | $self->close_file($fbat,undef,$self->{pool}); | |
2855 | } | |
2856 | ||
2857 | sub C { | |
44320b9e | 2858 | my ($self, $m) = @_; |
a5e0cedc EW |
2859 | my ($dir, $file) = split_path($m->{file_b}); |
2860 | my $pbat = $self->ensure_path($dir); | |
2861 | my $fbat = $self->add_file($self->repo_path($m->{file_b}), $pbat, | |
2862 | $self->url_path($m->{file_a}), $self->{r}); | |
44320b9e | 2863 | print "\tC\t$m->{file_a} => $m->{file_b}\n" unless $::_q; |
a5e0cedc EW |
2864 | $self->chg_file($fbat, $m); |
2865 | $self->close_file($fbat,undef,$self->{pool}); | |
2866 | } | |
2867 | ||
2868 | sub delete_entry { | |
2869 | my ($self, $path, $pbat) = @_; | |
2870 | my $rpath = $self->repo_path($path); | |
2871 | my ($dir, $file) = split_path($rpath); | |
2872 | $self->{rm}->{$dir} = 1; | |
2873 | $self->SUPER::delete_entry($rpath, $self->{r}, $pbat, $self->{pool}); | |
2874 | } | |
2875 | ||
2876 | sub R { | |
44320b9e | 2877 | my ($self, $m) = @_; |
a5e0cedc EW |
2878 | my ($dir, $file) = split_path($m->{file_b}); |
2879 | my $pbat = $self->ensure_path($dir); | |
2880 | my $fbat = $self->add_file($self->repo_path($m->{file_b}), $pbat, | |
2881 | $self->url_path($m->{file_a}), $self->{r}); | |
44320b9e | 2882 | print "\tR\t$m->{file_a} => $m->{file_b}\n" unless $::_q; |
a5e0cedc EW |
2883 | $self->chg_file($fbat, $m); |
2884 | $self->close_file($fbat,undef,$self->{pool}); | |
2885 | ||
2886 | ($dir, $file) = split_path($m->{file_a}); | |
2887 | $pbat = $self->ensure_path($dir); | |
2888 | $self->delete_entry($m->{file_a}, $pbat); | |
2889 | } | |
2890 | ||
2891 | sub M { | |
44320b9e | 2892 | my ($self, $m) = @_; |
a5e0cedc EW |
2893 | my ($dir, $file) = split_path($m->{file_b}); |
2894 | my $pbat = $self->ensure_path($dir); | |
2895 | my $fbat = $self->open_file($self->repo_path($m->{file_b}), | |
2896 | $pbat,$self->{r},$self->{pool}); | |
44320b9e | 2897 | print "\t$m->{chg}\t$m->{file_b}\n" unless $::_q; |
a5e0cedc EW |
2898 | $self->chg_file($fbat, $m); |
2899 | $self->close_file($fbat,undef,$self->{pool}); | |
2900 | } | |
2901 | ||
2902 | sub T { shift->M(@_) } | |
2903 | ||
2904 | sub change_file_prop { | |
2905 | my ($self, $fbat, $pname, $pval) = @_; | |
2906 | $self->SUPER::change_file_prop($fbat, $pname, $pval, $self->{pool}); | |
2907 | } | |
2908 | ||
2909 | sub chg_file { | |
2910 | my ($self, $fbat, $m) = @_; | |
2911 | if ($m->{mode_b} =~ /755$/ && $m->{mode_a} !~ /755$/) { | |
2912 | $self->change_file_prop($fbat,'svn:executable','*'); | |
2913 | } elsif ($m->{mode_b} !~ /755$/ && $m->{mode_a} =~ /755$/) { | |
2914 | $self->change_file_prop($fbat,'svn:executable',undef); | |
2915 | } | |
2916 | my $fh = IO::File->new_tmpfile or croak $!; | |
2917 | if ($m->{mode_b} =~ /^120/) { | |
2918 | print $fh 'link ' or croak $!; | |
2919 | $self->change_file_prop($fbat,'svn:special','*'); | |
2920 | } elsif ($m->{mode_a} =~ /^120/ && $m->{mode_b} !~ /^120/) { | |
2921 | $self->change_file_prop($fbat,'svn:special',undef); | |
2922 | } | |
2923 | defined(my $pid = fork) or croak $!; | |
2924 | if (!$pid) { | |
2925 | open STDOUT, '>&', $fh or croak $!; | |
2926 | exec qw/git-cat-file blob/, $m->{sha1_b} or croak $!; | |
2927 | } | |
2928 | waitpid $pid, 0; | |
2929 | croak $? if $?; | |
2930 | $fh->flush == 0 or croak $!; | |
2931 | seek $fh, 0, 0 or croak $!; | |
2932 | ||
2933 | my $md5 = Digest::MD5->new; | |
2934 | $md5->addfile($fh) or croak $!; | |
2935 | seek $fh, 0, 0 or croak $!; | |
2936 | ||
2937 | my $exp = $md5->hexdigest; | |
f7197dff EW |
2938 | my $pool = SVN::Pool->new; |
2939 | my $atd = $self->apply_textdelta($fbat, undef, $pool); | |
2940 | my $got = SVN::TxDelta::send_stream($fh, @$atd, $pool); | |
a5e0cedc | 2941 | die "Checksum mismatch\nexpected: $exp\ngot: $got\n" if ($got ne $exp); |
f7197dff | 2942 | $pool->clear; |
a5e0cedc EW |
2943 | |
2944 | close $fh or croak $!; | |
2945 | } | |
2946 | ||
2947 | sub D { | |
44320b9e | 2948 | my ($self, $m) = @_; |
a5e0cedc EW |
2949 | my ($dir, $file) = split_path($m->{file_b}); |
2950 | my $pbat = $self->ensure_path($dir); | |
44320b9e | 2951 | print "\tD\t$m->{file_b}\n" unless $::_q; |
a5e0cedc EW |
2952 | $self->delete_entry($m->{file_b}, $pbat); |
2953 | } | |
2954 | ||
2955 | sub close_edit { | |
2956 | my ($self) = @_; | |
2957 | my ($p,$bat) = ($self->{pool}, $self->{bat}); | |
2958 | foreach (sort { $b =~ tr#/#/# <=> $a =~ tr#/#/# } keys %$bat) { | |
6442754d | 2959 | next if $_ eq ''; |
a5e0cedc EW |
2960 | $self->close_directory($bat->{$_}, $p); |
2961 | } | |
6442754d | 2962 | $self->close_directory($bat->{''}, $p); |
a5e0cedc EW |
2963 | $self->SUPER::close_edit($p); |
2964 | $p->clear; | |
2965 | } | |
2966 | ||
2967 | sub abort_edit { | |
2968 | my ($self) = @_; | |
2969 | $self->SUPER::abort_edit($self->{pool}); | |
61395354 EW |
2970 | } |
2971 | ||
2972 | sub DESTROY { | |
2973 | my $self = shift; | |
2974 | $self->SUPER::DESTROY(@_); | |
a5e0cedc EW |
2975 | $self->{pool}->clear; |
2976 | } | |
2977 | ||
44320b9e EW |
2978 | # this drives the editor |
2979 | sub apply_diff { | |
61395354 EW |
2980 | my ($self) = @_; |
2981 | my $mods = $self->{mods}; | |
44320b9e | 2982 | my %o = ( D => 1, R => 0, C => -1, A => 3, M => 3, T => 3 ); |
6e8548cc | 2983 | foreach my $m (sort { $o{$a->{chg}} <=> $o{$b->{chg}} } @$mods) { |
44320b9e EW |
2984 | my $f = $m->{chg}; |
2985 | if (defined $o{$f}) { | |
2986 | $self->$f($m); | |
2987 | } else { | |
2988 | fatal("Invalid change type: $f\n"); | |
2989 | } | |
2990 | } | |
24e22aa8 | 2991 | $self->rmdirs if $_rmdir; |
6e8548cc | 2992 | if (@$mods == 0) { |
44320b9e EW |
2993 | $self->abort_edit; |
2994 | } else { | |
2995 | $self->close_edit; | |
2996 | } | |
6e8548cc | 2997 | return scalar @$mods; |
44320b9e EW |
2998 | } |
2999 | ||
d81bf827 | 3000 | package Git::SVN::Ra; |
6af1db44 | 3001 | use vars qw/@ISA $config_dir $_log_window_size/; |
d81bf827 EW |
3002 | use strict; |
3003 | use warnings; | |
a6a15a99 | 3004 | my ($can_do_switch, %ignored_err, $RA); |
d81bf827 EW |
3005 | |
3006 | BEGIN { | |
3007 | # enforce temporary pool usage for some simple functions | |
c5f71ad0 SV |
3008 | no strict 'refs'; |
3009 | for my $f (qw/rev_proplist get_latest_revnum get_uuid get_repos_root/) { | |
3010 | my $SUPER = "SUPER::$f"; | |
3011 | *$f = sub { | |
3012 | my $self = shift; | |
3013 | my $pool = SVN::Pool->new; | |
3014 | my @ret = $self->$SUPER(@_,$pool); | |
3015 | $pool->clear; | |
3016 | wantarray ? @ret : $ret[0]; | |
3017 | }; | |
d81bf827 | 3018 | } |
d81bf827 EW |
3019 | } |
3020 | ||
3021 | sub new { | |
3022 | my ($class, $url) = @_; | |
f6f09876 | 3023 | $url =~ s!/+$!!; |
5d3b7cd5 | 3024 | return $RA if ($RA && $RA->{url} eq $url); |
f6f09876 | 3025 | |
d81bf827 EW |
3026 | SVN::_Core::svn_config_ensure($config_dir, undef); |
3027 | my ($baton, $callbacks) = SVN::Core::auth_open_helper([ | |
3028 | SVN::Client::get_simple_provider(), | |
3029 | SVN::Client::get_ssl_server_trust_file_provider(), | |
3030 | SVN::Client::get_simple_prompt_provider( | |
3031 | \&Git::SVN::Prompt::simple, 2), | |
6caf5b18 | 3032 | SVN::Client::get_ssl_client_cert_file_provider(), |
d81bf827 EW |
3033 | SVN::Client::get_ssl_client_cert_prompt_provider( |
3034 | \&Git::SVN::Prompt::ssl_client_cert, 2), | |
3035 | SVN::Client::get_ssl_client_cert_pw_prompt_provider( | |
3036 | \&Git::SVN::Prompt::ssl_client_cert_pw, 2), | |
3037 | SVN::Client::get_username_provider(), | |
3038 | SVN::Client::get_ssl_server_trust_prompt_provider( | |
3039 | \&Git::SVN::Prompt::ssl_server_trust), | |
3040 | SVN::Client::get_username_prompt_provider( | |
3041 | \&Git::SVN::Prompt::username, 2), | |
3042 | ]); | |
3043 | my $config = SVN::Core::config_get_config($config_dir); | |
7730fbe6 | 3044 | $RA = undef; |
d81bf827 EW |
3045 | my $self = SVN::Ra->new(url => $url, auth => $baton, |
3046 | config => $config, | |
3047 | pool => SVN::Pool->new, | |
3048 | auth_provider_callbacks => $callbacks); | |
3049 | $self->{svn_path} = $url; | |
3050 | $self->{repos_root} = $self->get_repos_root; | |
4e9f6cc7 | 3051 | $self->{svn_path} =~ s#^\Q$self->{repos_root}\E(/|$)##; |
0dc03d6a EW |
3052 | $self->{cache} = { check_path => { r => 0, data => {} }, |
3053 | get_dir => { r => 0, data => {} } }; | |
5d3b7cd5 | 3054 | $RA = bless $self, $class; |
d81bf827 EW |
3055 | } |
3056 | ||
0dc03d6a EW |
3057 | sub check_path { |
3058 | my ($self, $path, $r) = @_; | |
3059 | my $cache = $self->{cache}->{check_path}; | |
3060 | if ($r == $cache->{r} && exists $cache->{data}->{$path}) { | |
3061 | return $cache->{data}->{$path}; | |
3062 | } | |
3063 | my $pool = SVN::Pool->new; | |
3064 | my $t = $self->SUPER::check_path($path, $r, $pool); | |
3065 | $pool->clear; | |
3066 | if ($r != $cache->{r}) { | |
3067 | %{$cache->{data}} = (); | |
3068 | $cache->{r} = $r; | |
3069 | } | |
3070 | $cache->{data}->{$path} = $t; | |
3071 | } | |
3072 | ||
3073 | sub get_dir { | |
3074 | my ($self, $dir, $r) = @_; | |
3075 | my $cache = $self->{cache}->{get_dir}; | |
3076 | if ($r == $cache->{r}) { | |
3077 | if (my $x = $cache->{data}->{$dir}) { | |
3078 | return wantarray ? @$x : $x->[0]; | |
3079 | } | |
3080 | } | |
3081 | my $pool = SVN::Pool->new; | |
3082 | my ($d, undef, $props) = $self->SUPER::get_dir($dir, $r, $pool); | |
3083 | my %dirents = map { $_ => { kind => $d->{$_}->kind } } keys %$d; | |
3084 | $pool->clear; | |
3085 | if ($r != $cache->{r}) { | |
3086 | %{$cache->{data}} = (); | |
3087 | $cache->{r} = $r; | |
3088 | } | |
3089 | $cache->{data}->{$dir} = [ \%dirents, $r, $props ]; | |
3090 | wantarray ? (\%dirents, $r, $props) : \%dirents; | |
3091 | } | |
3092 | ||
d81bf827 | 3093 | sub DESTROY { |
5d3b7cd5 | 3094 | # do not call the real DESTROY since we store ourselves in $RA |
d81bf827 EW |
3095 | } |
3096 | ||
d81bf827 EW |
3097 | sub get_log { |
3098 | my ($self, @args) = @_; | |
3099 | my $pool = SVN::Pool->new; | |
d81bf827 EW |
3100 | splice(@args, 3, 1) if ($SVN::Core::VERSION le '1.2.0'); |
3101 | my $ret = $self->SUPER::get_log(@args, $pool); | |
3102 | $pool->clear; | |
3103 | $ret; | |
3104 | } | |
3105 | ||
3106 | sub get_commit_editor { | |
44320b9e | 3107 | my ($self, $log, $cb, $pool) = @_; |
d81bf827 | 3108 | my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef, 0) : (); |
44320b9e | 3109 | $self->SUPER::get_commit_editor($log, $cb, @lock, $pool); |
d81bf827 EW |
3110 | } |
3111 | ||
d81bf827 | 3112 | sub gs_do_update { |
8a603774 EW |
3113 | my ($self, $rev_a, $rev_b, $gs, $editor) = @_; |
3114 | my $new = ($rev_a == $rev_b); | |
3115 | my $path = $gs->{path}; | |
3116 | ||
2e5e2480 EW |
3117 | if ($new && -e $gs->{index}) { |
3118 | unlink $gs->{index} or die | |
3119 | "Couldn't unlink index: $gs->{index}: $!\n"; | |
3120 | } | |
d81bf827 | 3121 | my $pool = SVN::Pool->new; |
8b8fc068 | 3122 | $editor->set_path_strip($path); |
2b27f6c8 EW |
3123 | my (@pc) = split m#/#, $path; |
3124 | my $reporter = $self->do_update($rev_b, (@pc ? shift @pc : ''), | |
8a603774 | 3125 | 1, $editor, $pool); |
d81bf827 | 3126 | my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef) : (); |
2b27f6c8 EW |
3127 | |
3128 | # Since we can't rely on svn_ra_reparent being available, we'll | |
3129 | # just have to do some magic with set_path to make it so | |
3130 | # we only want a partial path. | |
3131 | my $sp = ''; | |
3132 | my $final = join('/', @pc); | |
3133 | while (@pc) { | |
3134 | $reporter->set_path($sp, $rev_b, 0, @lock, $pool); | |
3135 | $sp .= '/' if length $sp; | |
3136 | $sp .= shift @pc; | |
3137 | } | |
3138 | die "BUG: '$sp' != '$final'\n" if ($sp ne $final); | |
3139 | ||
2b27f6c8 EW |
3140 | $reporter->set_path($sp, $rev_a, $new, @lock, $pool); |
3141 | ||
d81bf827 EW |
3142 | $reporter->finish_report($pool); |
3143 | $pool->clear; | |
3144 | $editor->{git_commit_ok}; | |
3145 | } | |
3146 | ||
2b27f6c8 EW |
3147 | # this requires SVN 1.4.3 or later (do_switch didn't work before 1.4.3, and |
3148 | # svn_ra_reparent didn't work before 1.4) | |
d81bf827 | 3149 | sub gs_do_switch { |
8a603774 EW |
3150 | my ($self, $rev_a, $rev_b, $gs, $url_b, $editor) = @_; |
3151 | my $path = $gs->{path}; | |
d81bf827 | 3152 | my $pool = SVN::Pool->new; |
2b27f6c8 EW |
3153 | |
3154 | my $full_url = $self->{url}; | |
3155 | my $old_url = $full_url; | |
3156 | $full_url .= "/$path" if length $path; | |
5d3b7cd5 EW |
3157 | my ($ra, $reparented); |
3158 | if ($old_url ne $full_url) { | |
3159 | if ($old_url !~ m#^svn(\+ssh)?://#) { | |
3160 | SVN::_Ra::svn_ra_reparent($self->{session}, $full_url, | |
3161 | $pool); | |
3162 | $self->{url} = $full_url; | |
3163 | $reparented = 1; | |
3164 | } else { | |
3165 | $ra = Git::SVN::Ra->new($full_url); | |
3166 | } | |
3167 | } | |
3168 | $ra ||= $self; | |
8a603774 | 3169 | my $reporter = $ra->do_switch($rev_b, '', 1, $url_b, $editor, $pool); |
d81bf827 | 3170 | my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef) : (); |
8b8fc068 | 3171 | $reporter->set_path('', $rev_a, 0, @lock, $pool); |
d81bf827 | 3172 | $reporter->finish_report($pool); |
2b27f6c8 | 3173 | |
5d3b7cd5 EW |
3174 | if ($reparented) { |
3175 | SVN::_Ra::svn_ra_reparent($self->{session}, $old_url, $pool); | |
3176 | $self->{url} = $old_url; | |
3177 | } | |
2b27f6c8 | 3178 | |
d81bf827 EW |
3179 | $pool->clear; |
3180 | $editor->{git_commit_ok}; | |
3181 | } | |
3182 | ||
b54a901e EW |
3183 | sub longest_common_path { |
3184 | my ($gsv, $globs) = @_; | |
d2ae1434 | 3185 | my %common; |
e518192f EW |
3186 | my $common_max = scalar @$gsv; |
3187 | ||
3188 | foreach my $gs (@$gsv) { | |
d2ae1434 EW |
3189 | my @tmp = split m#/#, $gs->{path}; |
3190 | my $p = ''; | |
3191 | foreach (@tmp) { | |
3192 | $p .= length($p) ? "/$_" : $_; | |
3193 | $common{$p} ||= 0; | |
3194 | $common{$p}++; | |
3195 | } | |
3196 | } | |
e518192f EW |
3197 | $globs ||= []; |
3198 | $common_max += scalar @$globs; | |
3199 | foreach my $glob (@$globs) { | |
3200 | my @tmp = split m#/#, $glob->{path}->{left}; | |
3201 | my $p = ''; | |
3202 | foreach (@tmp) { | |
3203 | $p .= length($p) ? "/$_" : $_; | |
3204 | $common{$p} ||= 0; | |
3205 | $common{$p}++; | |
3206 | } | |
3207 | } | |
3208 | ||
d2ae1434 EW |
3209 | my $longest_path = ''; |
3210 | foreach (sort {length $b <=> length $a} keys %common) { | |
e518192f | 3211 | if ($common{$_} == $common_max) { |
d2ae1434 EW |
3212 | $longest_path = $_; |
3213 | last; | |
3214 | } | |
0af9c9f9 | 3215 | } |
b54a901e EW |
3216 | $longest_path; |
3217 | } | |
3218 | ||
3219 | sub gs_fetch_loop_common { | |
3220 | my ($self, $base, $head, $gsv, $globs) = @_; | |
3221 | return if ($base > $head); | |
3222 | my $inc = $_log_window_size; | |
3223 | my ($min, $max) = ($base, $head < $base + $inc ? $head : $base + $inc); | |
3224 | my $longest_path = longest_common_path($gsv, $globs); | |
0af9c9f9 | 3225 | while (1) { |
d4eff2bd | 3226 | my %revs; |
d2ae1434 | 3227 | my $err; |
f7c3fc4a | 3228 | my $err_handler = $SVN::Error::handler; |
d2ae1434 EW |
3229 | $SVN::Error::handler = sub { |
3230 | ($err) = @_; | |
3231 | skip_unknown_revs($err); | |
3232 | }; | |
3233 | sub _cb { | |
3234 | my ($paths, $r, $author, $date, $log) = @_; | |
3235 | [ dup_changed_paths($paths), | |
3236 | { author => $author, date => $date, log => $log } ]; | |
3237 | } | |
3238 | $self->get_log([$longest_path], $min, $max, 0, 1, 1, | |
3239 | sub { $revs{$_[1]} = _cb(@_) }); | |
3240 | if ($err && $max >= $head) { | |
3241 | print STDERR "Path '$longest_path' ", | |
3242 | "was probably deleted:\n", | |
3243 | $err->expanded_message, | |
3244 | "\nWill attempt to follow ", | |
3245 | "revisions r$min .. r$max ", | |
3246 | "committed before the deletion\n"; | |
3247 | my $hi = $max; | |
3248 | while (--$hi >= $min) { | |
3249 | my $ok; | |
3250 | $self->get_log([$longest_path], $min, $hi, | |
3251 | 0, 1, 1, sub { | |
3252 | $ok ||= $_[1]; | |
3253 | $revs{$_[1]} = _cb(@_) }); | |
3254 | if ($ok) { | |
3255 | print STDERR "r$min .. r$ok OK\n"; | |
3256 | last; | |
3257 | } | |
3258 | } | |
3259 | } | |
d4eff2bd | 3260 | $SVN::Error::handler = $err_handler; |
fbcc1737 | 3261 | |
e518192f | 3262 | my %exists = map { $_->{path} => $_ } @$gsv; |
d4eff2bd | 3263 | foreach my $r (sort {$a <=> $b} keys %revs) { |
fbcc1737 | 3264 | my ($paths, $logged) = @{$revs{$r}}; |
e518192f EW |
3265 | |
3266 | foreach my $gs ($self->match_globs(\%exists, $paths, | |
3267 | $globs, $r)) { | |
fbcc1737 EW |
3268 | if ($gs->rev_db_max >= $r) { |
3269 | next; | |
3270 | } | |
3271 | next unless $gs->match_paths($paths, $r); | |
3272 | $gs->{logged_rev_props} = $logged; | |
e8d120bd EW |
3273 | if (my $last_commit = $gs->last_commit) { |
3274 | $gs->assert_index_clean($last_commit); | |
3275 | } | |
fbcc1737 EW |
3276 | my $log_entry = $gs->do_fetch($paths, $r); |
3277 | if ($log_entry) { | |
0af9c9f9 EW |
3278 | $gs->do_git_commit($log_entry); |
3279 | } | |
3280 | } | |
e518192f | 3281 | foreach my $g (@$globs) { |
93f2689c EW |
3282 | my $k = "svn-remote.$g->{remote}." . |
3283 | "$g->{t}-maxRev"; | |
3284 | Git::SVN::tmp_config($k, $r); | |
e518192f | 3285 | } |
0af9c9f9 | 3286 | } |
9c93fee5 EW |
3287 | # pre-fill the .rev_db since it'll eventually get filled in |
3288 | # with '0' x40 if something new gets committed | |
e518192f | 3289 | foreach my $gs (@$gsv) { |
9c93fee5 EW |
3290 | next if defined $gs->rev_db_get($max); |
3291 | $gs->rev_db_set($max, 0 x40); | |
3292 | } | |
c3560e53 EW |
3293 | foreach my $g (@$globs) { |
3294 | my $k = "svn-remote.$g->{remote}.$g->{t}-maxRev"; | |
3295 | Git::SVN::tmp_config($k, $max); | |
3296 | } | |
0af9c9f9 EW |
3297 | last if $max >= $head; |
3298 | $min = $max + 1; | |
3299 | $max += $inc; | |
3300 | $max = $head if ($max > $head); | |
3301 | } | |
0af9c9f9 EW |
3302 | } |
3303 | ||
e518192f EW |
3304 | sub match_globs { |
3305 | my ($self, $exists, $paths, $globs, $r) = @_; | |
74a81227 EW |
3306 | |
3307 | sub get_dir_check { | |
3308 | my ($self, $exists, $g, $r) = @_; | |
3309 | my @x = eval { $self->get_dir($g->{path}->{left}, $r) }; | |
3310 | return unless scalar @x == 3; | |
3311 | my $dirents = $x[0]; | |
3312 | foreach my $de (keys %$dirents) { | |
0dc03d6a | 3313 | next if $dirents->{$de}->{kind} != $SVN::Node::dir; |
74a81227 EW |
3314 | my $p = $g->{path}->full_path($de); |
3315 | next if $exists->{$p}; | |
3316 | next if (length $g->{path}->{right} && | |
3317 | ($self->check_path($p, $r) != | |
3318 | $SVN::Node::dir)); | |
3319 | $exists->{$p} = Git::SVN->init($self->{url}, $p, undef, | |
3320 | $g->{ref}->full_path($de), 1); | |
3321 | } | |
3322 | } | |
e518192f | 3323 | foreach my $g (@$globs) { |
74a81227 EW |
3324 | if (my $path = $paths->{"/$g->{path}->{left}"}) { |
3325 | if ($path->{action} =~ /^[AR]$/) { | |
3326 | get_dir_check($self, $exists, $g, $r); | |
3327 | } | |
3328 | } | |
e518192f | 3329 | foreach (keys %$paths) { |
28710f74 EW |
3330 | if (/$g->{path}->{left_regex}/ && |
3331 | !/$g->{path}->{regex}/) { | |
74a81227 EW |
3332 | next if $paths->{$_}->{action} !~ /^[AR]$/; |
3333 | get_dir_check($self, $exists, $g, $r); | |
3334 | } | |
e518192f EW |
3335 | next unless /$g->{path}->{regex}/; |
3336 | my $p = $1; | |
3337 | my $pathname = $g->{path}->full_path($p); | |
3338 | next if $exists->{$pathname}; | |
0c1ec5a1 EW |
3339 | next if ($self->check_path($pathname, $r) != |
3340 | $SVN::Node::dir); | |
e518192f EW |
3341 | $exists->{$pathname} = Git::SVN->init( |
3342 | $self->{url}, $pathname, undef, | |
3343 | $g->{ref}->full_path($p), 1); | |
3344 | } | |
3345 | my $c = ''; | |
3346 | foreach (split m#/#, $g->{path}->{left}) { | |
3347 | $c .= "/$_"; | |
3348 | next unless ($paths->{$c} && | |
74a81227 EW |
3349 | ($paths->{$c}->{action} =~ /^[AR]$/)); |
3350 | get_dir_check($self, $exists, $g, $r); | |
e518192f EW |
3351 | } |
3352 | } | |
3353 | values %$exists; | |
3354 | } | |
3355 | ||
e6434f87 EW |
3356 | sub minimize_url { |
3357 | my ($self) = @_; | |
3358 | return $self->{url} if ($self->{url} eq $self->{repos_root}); | |
3359 | my $url = $self->{repos_root}; | |
3360 | my @components = split(m!/!, $self->{svn_path}); | |
3361 | my $c = ''; | |
3362 | do { | |
3363 | $url .= "/$c" if length $c; | |
3364 | eval { (ref $self)->new($url)->get_latest_revnum }; | |
3365 | } while ($@ && ($c = shift @components)); | |
3366 | $url; | |
3367 | } | |
3368 | ||
d81bf827 EW |
3369 | sub can_do_switch { |
3370 | my $self = shift; | |
3371 | unless (defined $can_do_switch) { | |
3372 | my $pool = SVN::Pool->new; | |
3373 | my $rep = eval { | |
3374 | $self->do_switch(1, '', 0, $self->{url}, | |
3375 | SVN::Delta::Editor->new, $pool); | |
3376 | }; | |
3377 | if ($@) { | |
3378 | $can_do_switch = 0; | |
3379 | } else { | |
3380 | $rep->abort_report($pool); | |
3381 | $can_do_switch = 1; | |
3382 | } | |
3383 | $pool->clear; | |
3384 | } | |
3385 | $can_do_switch; | |
3386 | } | |
3387 | ||
0af9c9f9 EW |
3388 | sub skip_unknown_revs { |
3389 | my ($err) = @_; | |
3390 | my $errno = $err->apr_err(); | |
3391 | # Maybe the branch we're tracking didn't | |
3392 | # exist when the repo started, so it's | |
3393 | # not an error if it doesn't, just continue | |
3394 | # | |
3395 | # Wonderfully consistent library, eh? | |
3396 | # 160013 - svn:// and file:// | |
3397 | # 175002 - http(s):// | |
3398 | # 175007 - http(s):// (this repo required authorization, too...) | |
3399 | # More codes may be discovered later... | |
3400 | if ($errno == 175007 || $errno == 175002 || $errno == 160013) { | |
a6a15a99 EW |
3401 | my $err_key = $err->expanded_message; |
3402 | # revision numbers change every time, filter them out | |
3403 | $err_key =~ s/\d+/\0/g; | |
3404 | $err_key = "$errno\0$err_key"; | |
3405 | unless ($ignored_err{$err_key}) { | |
3406 | warn "W: Ignoring error from SVN, path probably ", | |
3407 | "does not exist: ($errno): ", | |
3408 | $err->expanded_message,"\n"; | |
3409 | $ignored_err{$err_key} = 1; | |
3410 | } | |
0af9c9f9 EW |
3411 | return; |
3412 | } | |
3413 | die "Error from SVN, ($errno): ", $err->expanded_message,"\n"; | |
3414 | } | |
3415 | ||
3416 | # svn_log_changed_path_t objects passed to get_log are likely to be | |
3417 | # overwritten even if only the refs are copied to an external variable, | |
3418 | # so we should dup the structures in their entirety. Using an externally | |
3419 | # passed pool (instead of our temporary and quickly cleared pool in | |
3420 | # Git::SVN::Ra) does not help matters at all... | |
3421 | sub dup_changed_paths { | |
3422 | my ($paths) = @_; | |
3423 | return undef unless $paths; | |
3424 | my %ret; | |
3425 | foreach my $p (keys %$paths) { | |
3426 | my $i = $paths->{$p}; | |
3427 | my %s = map { $_ => $i->$_ } | |
3428 | qw/copyfrom_path copyfrom_rev action/; | |
3429 | $ret{$p} = \%s; | |
3430 | } | |
3431 | \%ret; | |
3432 | } | |
3433 | ||
f8c9d1d2 EW |
3434 | package Git::SVN::Log; |
3435 | use strict; | |
3436 | use warnings; | |
3437 | use POSIX qw/strftime/; | |
3438 | use vars qw/$TZ $limit $color $pager $non_recursive $verbose $oneline | |
3439 | %rusers $show_commit $incremental/; | |
3440 | my $l_fmt; | |
3441 | ||
3442 | sub cmt_showable { | |
3443 | my ($c) = @_; | |
3444 | return 1 if defined $c->{r}; | |
c16d0871 EW |
3445 | |
3446 | # big commit message got truncated by the 16k pretty buffer in rev-list | |
f8c9d1d2 EW |
3447 | if ($c->{l} && $c->{l}->[-1] eq "...\n" && |
3448 | $c->{a_raw} =~ /\@([a-f\d\-]+)>$/) { | |
c16d0871 | 3449 | @{$c->{l}} = (); |
44320b9e | 3450 | my @log = command(qw/cat-file commit/, $c->{c}); |
c16d0871 EW |
3451 | |
3452 | # shift off the headers | |
3453 | shift @log while ($log[0] ne ''); | |
44320b9e | 3454 | shift @log; |
c16d0871 EW |
3455 | |
3456 | # TODO: make $c->{l} not have a trailing newline in the future | |
3457 | @{$c->{l}} = map { "$_\n" } grep !/^git-svn-id: /, @log; | |
f8c9d1d2 EW |
3458 | |
3459 | (undef, $c->{r}, undef) = ::extract_metadata( | |
44320b9e | 3460 | (grep(/^git-svn-id: /, @log))[-1]); |
f8c9d1d2 EW |
3461 | } |
3462 | return defined $c->{r}; | |
3463 | } | |
3464 | ||
3465 | sub log_use_color { | |
3466 | return 1 if $color; | |
3467 | my ($dc, $dcvar); | |
3468 | $dcvar = 'color.diff'; | |
3469 | $dc = `git-config --get $dcvar`; | |
3470 | if ($dc eq '') { | |
3471 | # nothing at all; fallback to "diff.color" | |
3472 | $dcvar = 'diff.color'; | |
3473 | $dc = `git-config --get $dcvar`; | |
3474 | } | |
3475 | chomp($dc); | |
3476 | if ($dc eq 'auto') { | |
3477 | my $pc; | |
3478 | $pc = `git-config --get color.pager`; | |
3479 | if ($pc eq '') { | |
3480 | # does not have it -- fallback to pager.color | |
3481 | $pc = `git-config --bool --get pager.color`; | |
3482 | } | |
3483 | else { | |
3484 | $pc = `git-config --bool --get color.pager`; | |
3485 | if ($?) { | |
3486 | $pc = 'false'; | |
3487 | } | |
3488 | } | |
3489 | chomp($pc); | |
3490 | if (-t *STDOUT || (defined $pager && $pc eq 'true')) { | |
3491 | return ($ENV{TERM} && $ENV{TERM} ne 'dumb'); | |
3492 | } | |
3493 | return 0; | |
3494 | } | |
3495 | return 0 if $dc eq 'never'; | |
3496 | return 1 if $dc eq 'always'; | |
3497 | chomp($dc = `git-config --bool --get $dcvar`); | |
3498 | return ($dc eq 'true'); | |
3499 | } | |
3500 | ||
3501 | sub git_svn_log_cmd { | |
3bc718ba EW |
3502 | my ($r_min, $r_max, @args) = @_; |
3503 | my $head = 'HEAD'; | |
6ed77266 | 3504 | my (@files, @log_opts); |
3bc718ba | 3505 | foreach my $x (@args) { |
6ed77266 EW |
3506 | if ($x eq '--' || @files) { |
3507 | push @files, $x; | |
3508 | } else { | |
3509 | if (::verify_ref("$x^0")) { | |
3510 | $head = $x; | |
3511 | } else { | |
3512 | push @log_opts, $x; | |
3513 | } | |
3514 | } | |
3bc718ba EW |
3515 | } |
3516 | ||
13c823fb EW |
3517 | my ($url, $rev, $uuid, $gs) = ::working_head_info($head); |
3518 | $gs ||= Git::SVN->_new; | |
f8c9d1d2 EW |
3519 | my @cmd = (qw/log --abbrev-commit --pretty=raw --default/, |
3520 | $gs->refname); | |
3521 | push @cmd, '-r' unless $non_recursive; | |
3522 | push @cmd, qw/--raw --name-status/ if $verbose; | |
3523 | push @cmd, '--color' if log_use_color(); | |
6ed77266 EW |
3524 | push @cmd, @log_opts; |
3525 | if (defined $r_max && $r_max == $r_min) { | |
f8c9d1d2 EW |
3526 | push @cmd, '--max-count=1'; |
3527 | if (my $c = $gs->rev_db_get($r_max)) { | |
3528 | push @cmd, $c; | |
3529 | } | |
6ed77266 | 3530 | } elsif (defined $r_max) { |
f8c9d1d2 EW |
3531 | my ($c_min, $c_max); |
3532 | $c_max = $gs->rev_db_get($r_max); | |
3533 | $c_min = $gs->rev_db_get($r_min); | |
3534 | if (defined $c_min && defined $c_max) { | |
3535 | if ($r_max > $r_max) { | |
3536 | push @cmd, "$c_min..$c_max"; | |
3537 | } else { | |
3538 | push @cmd, "$c_max..$c_min"; | |
3539 | } | |
3540 | } elsif ($r_max > $r_min) { | |
3541 | push @cmd, $c_max; | |
3542 | } else { | |
3543 | push @cmd, $c_min; | |
3544 | } | |
3545 | } | |
6ed77266 | 3546 | return (@cmd, @files); |
f8c9d1d2 EW |
3547 | } |
3548 | ||
3549 | # adapted from pager.c | |
3550 | sub config_pager { | |
3551 | $pager ||= $ENV{GIT_PAGER} || $ENV{PAGER}; | |
3552 | if (!defined $pager) { | |
3553 | $pager = 'less'; | |
3554 | } elsif (length $pager == 0 || $pager eq 'cat') { | |
3555 | $pager = undef; | |
3556 | } | |
3557 | } | |
3558 | ||
3559 | sub run_pager { | |
3560 | return unless -t *STDOUT; | |
3561 | pipe my $rfd, my $wfd or return; | |
3562 | defined(my $pid = fork) or ::fatal "Can't fork: $!\n"; | |
3563 | if (!$pid) { | |
3564 | open STDOUT, '>&', $wfd or | |
3565 | ::fatal "Can't redirect to stdout: $!\n"; | |
3566 | return; | |
3567 | } | |
3568 | open STDIN, '<&', $rfd or ::fatal "Can't redirect stdin: $!\n"; | |
3569 | $ENV{LESS} ||= 'FRSX'; | |
3570 | exec $pager or ::fatal "Can't run pager: $! ($pager)\n"; | |
3571 | } | |
3572 | ||
21819a37 EW |
3573 | sub tz_to_s_offset { |
3574 | my ($tz) = @_; | |
3575 | $tz =~ s/(\d\d)$//; | |
3576 | return ($1 * 60) + ($tz * 3600); | |
3577 | } | |
3578 | ||
f8c9d1d2 EW |
3579 | sub get_author_info { |
3580 | my ($dest, $author, $t, $tz) = @_; | |
3581 | $author =~ s/(?:^\s*|\s*$)//g; | |
3582 | $dest->{a_raw} = $author; | |
3583 | my $au; | |
1c8443b0 | 3584 | if ($::_authors) { |
f8c9d1d2 EW |
3585 | $au = $rusers{$author} || undef; |
3586 | } | |
3587 | if (!$au) { | |
3588 | ($au) = ($author =~ /<([^>]+)\@[^>]+>$/); | |
3589 | } | |
3590 | $dest->{t} = $t; | |
3591 | $dest->{tz} = $tz; | |
3592 | $dest->{a} = $au; | |
3593 | # Date::Parse isn't in the standard Perl distro :( | |
3594 | if ($tz =~ s/^\+//) { | |
21819a37 | 3595 | $t += tz_to_s_offset($tz); |
f8c9d1d2 | 3596 | } elsif ($tz =~ s/^\-//) { |
21819a37 | 3597 | $t -= tz_to_s_offset($tz); |
f8c9d1d2 EW |
3598 | } |
3599 | $dest->{t_utc} = $t; | |
3600 | } | |
3601 | ||
3602 | sub process_commit { | |
3603 | my ($c, $r_min, $r_max, $defer) = @_; | |
3604 | if (defined $r_min && defined $r_max) { | |
3605 | if ($r_min == $c->{r} && $r_min == $r_max) { | |
3606 | show_commit($c); | |
3607 | return 0; | |
3608 | } | |
3609 | return 1 if $r_min == $r_max; | |
3610 | if ($r_min < $r_max) { | |
3611 | # we need to reverse the print order | |
3612 | return 0 if (defined $limit && --$limit < 0); | |
3613 | push @$defer, $c; | |
3614 | return 1; | |
3615 | } | |
3616 | if ($r_min != $r_max) { | |
3617 | return 1 if ($r_min < $c->{r}); | |
3618 | return 1 if ($r_max > $c->{r}); | |
3619 | } | |
3620 | } | |
3621 | return 0 if (defined $limit && --$limit < 0); | |
3622 | show_commit($c); | |
3623 | return 1; | |
3624 | } | |
3625 | ||
3626 | sub show_commit { | |
3627 | my $c = shift; | |
3628 | if ($oneline) { | |
3629 | my $x = "\n"; | |
3630 | if (my $l = $c->{l}) { | |
3631 | while ($l->[0] =~ /^\s*$/) { shift @$l } | |
3632 | $x = $l->[0]; | |
3633 | } | |
3634 | $l_fmt ||= 'A' . length($c->{r}); | |
3635 | print 'r',pack($l_fmt, $c->{r}),' | '; | |
3636 | print "$c->{c} | " if $show_commit; | |
3637 | print $x; | |
3638 | } else { | |
3639 | show_commit_normal($c); | |
3640 | } | |
3641 | } | |
3642 | ||
3643 | sub show_commit_changed_paths { | |
3644 | my ($c) = @_; | |
3645 | return unless $c->{changed}; | |
3646 | print "Changed paths:\n", @{$c->{changed}}; | |
3647 | } | |
3648 | ||
3649 | sub show_commit_normal { | |
3650 | my ($c) = @_; | |
3651 | print '-' x72, "\nr$c->{r} | "; | |
3652 | print "$c->{c} | " if $show_commit; | |
3653 | print "$c->{a} | ", strftime("%Y-%m-%d %H:%M:%S %z (%a, %d %b %Y)", | |
3654 | localtime($c->{t_utc})), ' | '; | |
3655 | my $nr_line = 0; | |
3656 | ||
3657 | if (my $l = $c->{l}) { | |
3658 | while ($l->[$#$l] eq "\n" && $#$l > 0 | |
3659 | && $l->[($#$l - 1)] eq "\n") { | |
3660 | pop @$l; | |
3661 | } | |
3662 | $nr_line = scalar @$l; | |
3663 | if (!$nr_line) { | |
3664 | print "1 line\n\n\n"; | |
3665 | } else { | |
3666 | if ($nr_line == 1) { | |
3667 | $nr_line = '1 line'; | |
3668 | } else { | |
3669 | $nr_line .= ' lines'; | |
3670 | } | |
3671 | print $nr_line, "\n"; | |
3672 | show_commit_changed_paths($c); | |
3673 | print "\n"; | |
3674 | print $_ foreach @$l; | |
3675 | } | |
3676 | } else { | |
3677 | print "1 line\n"; | |
3678 | show_commit_changed_paths($c); | |
3679 | print "\n"; | |
3680 | ||
3681 | } | |
488a63ec | 3682 | foreach my $x (qw/raw stat diff/) { |
f8c9d1d2 EW |
3683 | if ($c->{$x}) { |
3684 | print "\n"; | |
3685 | print $_ foreach @{$c->{$x}} | |
3686 | } | |
3687 | } | |
3688 | } | |
3689 | ||
3690 | sub cmd_show_log { | |
3691 | my (@args) = @_; | |
3692 | my ($r_min, $r_max); | |
3693 | my $r_last = -1; # prevent dupes | |
3694 | if (defined $TZ) { | |
3695 | $ENV{TZ} = $TZ; | |
3696 | } else { | |
3697 | delete $ENV{TZ}; | |
3698 | } | |
3699 | if (defined $::_revision) { | |
3700 | if ($::_revision =~ /^(\d+):(\d+)$/) { | |
3701 | ($r_min, $r_max) = ($1, $2); | |
3702 | } elsif ($::_revision =~ /^\d+$/) { | |
3703 | $r_min = $r_max = $::_revision; | |
3704 | } else { | |
3705 | ::fatal "-r$::_revision is not supported, use ", | |
3706 | "standard \'git log\' arguments instead\n"; | |
3707 | } | |
3708 | } | |
3709 | ||
3710 | config_pager(); | |
6ed77266 | 3711 | @args = git_svn_log_cmd($r_min, $r_max, @args); |
f8c9d1d2 EW |
3712 | my $log = command_output_pipe(@args); |
3713 | run_pager(); | |
488a63ec | 3714 | my (@k, $c, $d, $stat); |
f8c9d1d2 EW |
3715 | my $esc_color = qr/(?:\033\[(?:(?:\d+;)*\d*)?m)*/; |
3716 | while (<$log>) { | |
3717 | if (/^${esc_color}commit ($::sha1_short)/o) { | |
3718 | my $cmt = $1; | |
3719 | if ($c && cmt_showable($c) && $c->{r} != $r_last) { | |
3720 | $r_last = $c->{r}; | |
3721 | process_commit($c, $r_min, $r_max, \@k) or | |
3722 | goto out; | |
3723 | } | |
3724 | $d = undef; | |
3725 | $c = { c => $cmt }; | |
3726 | } elsif (/^${esc_color}author (.+) (\d+) ([\-\+]?\d+)$/o) { | |
3727 | get_author_info($c, $1, $2, $3); | |
3728 | } elsif (/^${esc_color}(?:tree|parent|committer) /o) { | |
3729 | # ignore | |
3730 | } elsif (/^${esc_color}:\d{6} \d{6} $::sha1_short/o) { | |
3731 | push @{$c->{raw}}, $_; | |
3732 | } elsif (/^${esc_color}[ACRMDT]\t/) { | |
3733 | # we could add $SVN->{svn_path} here, but that requires | |
3734 | # remote access at the moment (repo_path_split)... | |
3735 | s#^(${esc_color})([ACRMDT])\t#$1 $2 #o; | |
3736 | push @{$c->{changed}}, $_; | |
3737 | } elsif (/^${esc_color}diff /o) { | |
3738 | $d = 1; | |
3739 | push @{$c->{diff}}, $_; | |
3740 | } elsif ($d) { | |
3741 | push @{$c->{diff}}, $_; | |
488a63ec EW |
3742 | } elsif (/^\ .+\ \|\s*\d+\ $esc_color[\+\-]* |
3743 | $esc_color*[\+\-]*$esc_color$/x) { | |
3744 | $stat = 1; | |
3745 | push @{$c->{stat}}, $_; | |
3746 | } elsif ($stat && /^ \d+ files changed, \d+ insertions/) { | |
3747 | push @{$c->{stat}}, $_; | |
3748 | $stat = undef; | |
f8c9d1d2 EW |
3749 | } elsif (/^${esc_color} (git-svn-id:.+)$/o) { |
3750 | ($c->{url}, $c->{r}, undef) = ::extract_metadata($1); | |
3751 | } elsif (s/^${esc_color} //o) { | |
3752 | push @{$c->{l}}, $_; | |
3753 | } | |
3754 | } | |
3755 | if ($c && defined $c->{r} && $c->{r} != $r_last) { | |
3756 | $r_last = $c->{r}; | |
3757 | process_commit($c, $r_min, $r_max, \@k); | |
3758 | } | |
3759 | if (@k) { | |
3760 | my $swap = $r_max; | |
3761 | $r_max = $r_min; | |
3762 | $r_min = $swap; | |
3763 | process_commit($_, $r_min, $r_max) foreach reverse @k; | |
3764 | } | |
3765 | out: | |
c843c464 | 3766 | close $log; |
f8c9d1d2 EW |
3767 | print '-' x72,"\n" unless $incremental || $oneline; |
3768 | } | |
3769 | ||
706587fc EW |
3770 | package Git::SVN::Migration; |
3771 | # these version numbers do NOT correspond to actual version numbers | |
3772 | # of git nor git-svn. They are just relative. | |
3773 | # | |
3774 | # v0 layout: .git/$id/info/url, refs/heads/$id-HEAD | |
3775 | # | |
3776 | # v1 layout: .git/$id/info/url, refs/remotes/$id | |
3777 | # | |
3778 | # v2 layout: .git/svn/$id/info/url, refs/remotes/$id | |
3779 | # | |
3780 | # v3 layout: .git/svn/$id, refs/remotes/$id | |
3781 | # - info/url may remain for backwards compatibility | |
3782 | # - this is what we migrate up to this layout automatically, | |
3783 | # - this will be used by git svn init on single branches | |
26a62d57 EW |
3784 | # v3.1 layout (auto migrated): |
3785 | # - .rev_db => .rev_db.$UUID, .rev_db will remain as a symlink | |
3786 | # for backwards compatibility | |
706587fc EW |
3787 | # |
3788 | # v4 layout: .git/svn/$repo_id/$id, refs/remotes/$repo_id/$id | |
3789 | # - this is only created for newly multi-init-ed | |
3790 | # repositories. Similar in spirit to the | |
3791 | # --use-separate-remotes option in git-clone (now default) | |
3792 | # - we do not automatically migrate to this (following | |
3793 | # the example set by core git) | |
3794 | use strict; | |
3795 | use warnings; | |
3796 | use Carp qw/croak/; | |
3797 | use File::Path qw/mkpath/; | |
47e39c55 EW |
3798 | use File::Basename qw/dirname basename/; |
3799 | use vars qw/$_minimize/; | |
706587fc EW |
3800 | |
3801 | sub migrate_from_v0 { | |
3802 | my $git_dir = $ENV{GIT_DIR}; | |
3803 | return undef unless -d $git_dir; | |
3804 | my ($fh, $ctx) = command_output_pipe(qw/rev-parse --symbolic --all/); | |
3805 | my $migrated = 0; | |
3806 | while (<$fh>) { | |
3807 | chomp; | |
3808 | my ($id, $orig_ref) = ($_, $_); | |
3809 | next unless $id =~ s#^refs/heads/(.+)-HEAD$#$1#; | |
3810 | next unless -f "$git_dir/$id/info/url"; | |
3811 | my $new_ref = "refs/remotes/$id"; | |
3812 | if (::verify_ref("$new_ref^0")) { | |
3813 | print STDERR "W: $orig_ref is probably an old ", | |
3814 | "branch used by an ancient version of ", | |
3815 | "git-svn.\n", | |
3816 | "However, $new_ref also exists.\n", | |
3817 | "We will not be able ", | |
3818 | "to use this branch until this ", | |
3819 | "ambiguity is resolved.\n"; | |
3820 | next; | |
3821 | } | |
3822 | print STDERR "Migrating from v0 layout...\n" if !$migrated; | |
3823 | print STDERR "Renaming ref: $orig_ref => $new_ref\n"; | |
3824 | command_noisy('update-ref', $new_ref, $orig_ref); | |
3825 | command_noisy('update-ref', '-d', $orig_ref, $orig_ref); | |
3826 | $migrated++; | |
3827 | } | |
3828 | command_close_pipe($fh, $ctx); | |
3829 | print STDERR "Done migrating from v0 layout...\n" if $migrated; | |
3830 | $migrated; | |
3831 | } | |
3832 | ||
3833 | sub migrate_from_v1 { | |
3834 | my $git_dir = $ENV{GIT_DIR}; | |
3835 | my $migrated = 0; | |
3836 | return $migrated unless -d $git_dir; | |
3837 | my $svn_dir = "$git_dir/svn"; | |
3838 | ||
3839 | # just in case somebody used 'svn' as their $id at some point... | |
3840 | return $migrated if -d $svn_dir && ! -f "$svn_dir/info/url"; | |
3841 | ||
3842 | print STDERR "Migrating from a git-svn v1 layout...\n"; | |
3843 | mkpath([$svn_dir]); | |
3844 | print STDERR "Data from a previous version of git-svn exists, but\n\t", | |
3845 | "$svn_dir\n\t(required for this version ", | |
3846 | "($::VERSION) of git-svn) does not. exist\n"; | |
3847 | my ($fh, $ctx) = command_output_pipe(qw/rev-parse --symbolic --all/); | |
3848 | while (<$fh>) { | |
3849 | my $x = $_; | |
3850 | next unless $x =~ s#^refs/remotes/##; | |
3851 | chomp $x; | |
3852 | next unless -f "$git_dir/$x/info/url"; | |
3853 | my $u = eval { ::file_to_s("$git_dir/$x/info/url") }; | |
3854 | next unless $u; | |
3855 | my $dn = dirname("$git_dir/svn/$x"); | |
3856 | mkpath([$dn]) unless -d $dn; | |
3857 | if ($x eq 'svn') { # they used 'svn' as GIT_SVN_ID: | |
3858 | mkpath(["$git_dir/svn/svn"]); | |
3859 | print STDERR " - $git_dir/$x/info => ", | |
3860 | "$git_dir/svn/$x/info\n"; | |
3861 | rename "$git_dir/$x/info", "$git_dir/svn/$x/info" or | |
3862 | croak "$!: $x"; | |
3863 | # don't worry too much about these, they probably | |
3864 | # don't exist with repos this old (save for index, | |
3865 | # and we can easily regenerate that) | |
3866 | foreach my $f (qw/unhandled.log index .rev_db/) { | |
3867 | rename "$git_dir/$x/$f", "$git_dir/svn/$x/$f"; | |
3868 | } | |
3869 | } else { | |
3870 | print STDERR " - $git_dir/$x => $git_dir/svn/$x\n"; | |
3871 | rename "$git_dir/$x", "$git_dir/svn/$x" or | |
3872 | croak "$!: $x"; | |
3873 | } | |
3874 | $migrated++; | |
3875 | } | |
3876 | command_close_pipe($fh, $ctx); | |
3877 | print STDERR "Done migrating from a git-svn v1 layout\n"; | |
3878 | $migrated; | |
3879 | } | |
3880 | ||
3881 | sub read_old_urls { | |
3882 | my ($l_map, $pfx, $path) = @_; | |
3883 | my @dir; | |
3884 | foreach (<$path/*>) { | |
3885 | if (-r "$_/info/url") { | |
3886 | $pfx .= '/' if $pfx && $pfx !~ m!/$!; | |
3887 | my $ref_id = $pfx . basename $_; | |
3888 | my $url = ::file_to_s("$_/info/url"); | |
3889 | $l_map->{$ref_id} = $url; | |
3890 | } elsif (-d $_) { | |
3891 | push @dir, $_; | |
3892 | } | |
3893 | } | |
3894 | foreach (@dir) { | |
3895 | my $x = $_; | |
3896 | $x =~ s!^\Q$ENV{GIT_DIR}\E/svn/!!o; | |
3897 | read_old_urls($l_map, $x, $_); | |
3898 | } | |
3899 | } | |
3900 | ||
3901 | sub migrate_from_v2 { | |
3902 | my @cfg = command(qw/config -l/); | |
3903 | return if grep /^svn-remote\..+\.url=/, @cfg; | |
3904 | my %l_map; | |
3905 | read_old_urls(\%l_map, '', "$ENV{GIT_DIR}/svn"); | |
3906 | my $migrated = 0; | |
3907 | ||
3908 | foreach my $ref_id (sort keys %l_map) { | |
471bc000 EW |
3909 | eval { Git::SVN->init($l_map{$ref_id}, '', undef, $ref_id) }; |
3910 | if ($@) { | |
3911 | Git::SVN->init($l_map{$ref_id}, '', $ref_id, $ref_id); | |
3912 | } | |
706587fc EW |
3913 | $migrated++; |
3914 | } | |
3915 | $migrated; | |
3916 | } | |
3917 | ||
47e39c55 EW |
3918 | sub minimize_connections { |
3919 | my $r = Git::SVN::read_all_remotes(); | |
3920 | my $new_urls = {}; | |
3921 | my $root_repos = {}; | |
3922 | foreach my $repo_id (keys %$r) { | |
3923 | my $url = $r->{$repo_id}->{url} or next; | |
3924 | my $fetch = $r->{$repo_id}->{fetch} or next; | |
3925 | my $ra = Git::SVN::Ra->new($url); | |
3926 | ||
3927 | # skip existing cases where we already connect to the root | |
3928 | if (($ra->{url} eq $ra->{repos_root}) || | |
3929 | (Git::SVN::sanitize_remote_name($ra->{repos_root}) eq | |
3930 | $repo_id)) { | |
3931 | $root_repos->{$ra->{url}} = $repo_id; | |
3932 | next; | |
3933 | } | |
3934 | ||
3935 | my $root_ra = Git::SVN::Ra->new($ra->{repos_root}); | |
3936 | my $root_path = $ra->{url}; | |
4e9f6cc7 | 3937 | $root_path =~ s#^\Q$ra->{repos_root}\E(/|$)##; |
47e39c55 EW |
3938 | foreach my $path (keys %$fetch) { |
3939 | my $ref_id = $fetch->{$path}; | |
3940 | my $gs = Git::SVN->new($ref_id, $repo_id, $path); | |
3941 | ||
3942 | # make sure we can read when connecting to | |
3943 | # a higher level of a repository | |
3944 | my ($last_rev, undef) = $gs->last_rev_commit; | |
3945 | if (!defined $last_rev) { | |
3946 | $last_rev = eval { | |
3947 | $root_ra->get_latest_revnum; | |
3948 | }; | |
3949 | next if $@; | |
3950 | } | |
3951 | my $new = $root_path; | |
3952 | $new .= length $path ? "/$path" : ''; | |
3953 | eval { | |
3954 | $root_ra->get_log([$new], $last_rev, $last_rev, | |
3955 | 0, 0, 1, sub { }); | |
3956 | }; | |
3957 | next if $@; | |
3958 | $new_urls->{$ra->{repos_root}}->{$new} = | |
3959 | { ref_id => $ref_id, | |
3960 | old_repo_id => $repo_id, | |
3961 | old_path => $path }; | |
3962 | } | |
3963 | } | |
3964 | ||
3965 | my @emptied; | |
3966 | foreach my $url (keys %$new_urls) { | |
3967 | # see if we can re-use an existing [svn-remote "repo_id"] | |
3968 | # instead of creating a(n ugly) new section: | |
3969 | my $repo_id = $root_repos->{$url} || | |
3970 | Git::SVN::sanitize_remote_name($url); | |
3971 | ||
3972 | my $fetch = $new_urls->{$url}; | |
3973 | foreach my $path (keys %$fetch) { | |
3974 | my $x = $fetch->{$path}; | |
3975 | Git::SVN->init($url, $path, $repo_id, $x->{ref_id}); | |
3976 | my $pfx = "svn-remote.$x->{old_repo_id}"; | |
3977 | ||
3978 | my $old_fetch = quotemeta("$x->{old_path}:". | |
3979 | "refs/remotes/$x->{ref_id}"); | |
8b8fc068 | 3980 | command_noisy(qw/config --unset/, |
47e39c55 EW |
3981 | "$pfx.fetch", '^'. $old_fetch . '$'); |
3982 | delete $r->{$x->{old_repo_id}}-> | |
3983 | {fetch}->{$x->{old_path}}; | |
3984 | if (!keys %{$r->{$x->{old_repo_id}}->{fetch}}) { | |
8b8fc068 | 3985 | command_noisy(qw/config --unset/, |
47e39c55 EW |
3986 | "$pfx.url"); |
3987 | push @emptied, $x->{old_repo_id} | |
3988 | } | |
3989 | } | |
3990 | } | |
3991 | if (@emptied) { | |
3992 | my $file = $ENV{GIT_CONFIG} || $ENV{GIT_CONFIG_LOCAL} || | |
3993 | "$ENV{GIT_DIR}/config"; | |
3994 | print STDERR <<EOF; | |
3995 | The following [svn-remote] sections in your config file ($file) are empty | |
3996 | and can be safely removed: | |
3997 | EOF | |
3998 | print STDERR "[svn-remote \"$_\"]\n" foreach @emptied; | |
3999 | } | |
4000 | } | |
4001 | ||
706587fc EW |
4002 | sub migration_check { |
4003 | migrate_from_v0(); | |
4004 | migrate_from_v1(); | |
4005 | migrate_from_v2(); | |
47e39c55 | 4006 | minimize_connections() if $_minimize; |
706587fc EW |
4007 | } |
4008 | ||
ef3cfaad EW |
4009 | package Git::IndexInfo; |
4010 | use strict; | |
4011 | use warnings; | |
4012 | use Git qw/command_input_pipe command_close_pipe/; | |
4013 | ||
4014 | sub new { | |
4015 | my ($class) = @_; | |
4016 | my ($gui, $ctx) = command_input_pipe(qw/update-index -z --index-info/); | |
4017 | bless { gui => $gui, ctx => $ctx, nr => 0}, $class; | |
4018 | } | |
4019 | ||
4020 | sub remove { | |
4021 | my ($self, $path) = @_; | |
4022 | if (print { $self->{gui} } '0 ', 0 x 40, "\t", $path, "\0") { | |
4023 | return ++$self->{nr}; | |
4024 | } | |
4025 | undef; | |
4026 | } | |
4027 | ||
4028 | sub update { | |
4029 | my ($self, $mode, $hash, $path) = @_; | |
4030 | if (print { $self->{gui} } $mode, ' ', $hash, "\t", $path, "\0") { | |
4031 | return ++$self->{nr}; | |
4032 | } | |
4033 | undef; | |
4034 | } | |
4035 | ||
4036 | sub DESTROY { | |
4037 | my ($self) = @_; | |
4038 | command_close_pipe($self->{gui}, $self->{ctx}); | |
4039 | } | |
4040 | ||
4bb9ed04 EW |
4041 | package Git::SVN::GlobSpec; |
4042 | use strict; | |
4043 | use warnings; | |
4044 | ||
4045 | sub new { | |
4046 | my ($class, $glob) = @_; | |
4bb9ed04 EW |
4047 | my $re = $glob; |
4048 | $re =~ s!/+$!!g; # no need for trailing slashes | |
4e9f6cc7 | 4049 | my $nr = ($re =~ s!^(.*)\*(.*)$!\(\[^/\]+\)!g); |
4bb9ed04 EW |
4050 | my ($left, $right) = ($1, $2); |
4051 | if ($nr > 1) { | |
e518192f EW |
4052 | die "Only one '*' wildcard expansion ", |
4053 | "is supported (got $nr): '$glob'\n"; | |
4bb9ed04 | 4054 | } elsif ($nr == 0) { |
e518192f | 4055 | die "One '*' is needed for glob: '$glob'\n"; |
4bb9ed04 EW |
4056 | } |
4057 | $re = quotemeta($left) . $re . quotemeta($right); | |
4e9f6cc7 EW |
4058 | if (length $left && !($left =~ s!/+$!!g)) { |
4059 | die "Missing trailing '/' on left side of: '$glob' ($left)\n"; | |
4060 | } | |
4061 | if (length $right && !($right =~ s!^/+!!g)) { | |
4062 | die "Missing leading '/' on right side of: '$glob' ($right)\n"; | |
4063 | } | |
74a81227 EW |
4064 | my $left_re = qr/^\/\Q$left\E(\/|$)/; |
4065 | bless { left => $left, right => $right, left_regex => $left_re, | |
4bb9ed04 EW |
4066 | regex => qr/$re/, glob => $glob }, $class; |
4067 | } | |
4068 | ||
4069 | sub full_path { | |
4070 | my ($self, $path) = @_; | |
4071 | return (length $self->{left} ? "$self->{left}/" : '') . | |
4072 | $path . (length $self->{right} ? "/$self->{right}" : ''); | |
4073 | } | |
4074 | ||
3397f9df EW |
4075 | __END__ |
4076 | ||
4077 | Data structures: | |
4078 | ||
4bb9ed04 EW |
4079 | |
4080 | $remotes = { # returned by read_all_remotes() | |
4081 | 'svn' => { | |
4082 | # svn-remote.svn.url=https://svn.musicpd.org | |
4083 | url => 'https://svn.musicpd.org', | |
4084 | # svn-remote.svn.fetch=mpd/trunk:trunk | |
4085 | fetch => { | |
4086 | 'mpd/trunk' => 'trunk', | |
4087 | }, | |
4088 | # svn-remote.svn.tags=mpd/tags/*:tags/* | |
4089 | tags => { | |
4090 | path => { | |
4091 | left => 'mpd/tags', | |
4092 | right => '', | |
4093 | regex => qr!mpd/tags/([^/]+)$!, | |
4094 | glob => 'tags/*', | |
4095 | }, | |
4096 | ref => { | |
4097 | left => 'tags', | |
4098 | right => '', | |
4099 | regex => qr!tags/([^/]+)$!, | |
4100 | glob => 'tags/*', | |
4101 | }, | |
4102 | } | |
4103 | } | |
4104 | }; | |
4105 | ||
44320b9e | 4106 | $log_entry hashref as returned by libsvn_log_entry() |
3397f9df | 4107 | { |
44320b9e | 4108 | log => 'whitespace-formatted log entry |
3397f9df EW |
4109 | ', # trailing newline is preserved |
4110 | revision => '8', # integer | |
4111 | date => '2004-02-24T17:01:44.108345Z', # commit date | |
4112 | author => 'committer name' | |
4113 | }; | |
4114 | ||
6e8548cc EW |
4115 | |
4116 | # this is generated by generate_diff(); | |
3397f9df EW |
4117 | @mods = array of diff-index line hashes, each element represents one line |
4118 | of diff-index output | |
4119 | ||
4120 | diff-index line ($m hash) | |
4121 | { | |
4122 | mode_a => first column of diff-index output, no leading ':', | |
4123 | mode_b => second column of diff-index output, | |
4124 | sha1_b => sha1sum of the final blob, | |
ac8e0b91 | 4125 | chg => change type [MCRADT], |
3397f9df EW |
4126 | file_a => original file name of a file (iff chg is 'C' or 'R') |
4127 | file_b => new/current file name of a file (any chg) | |
4128 | } | |
4129 | ; | |
a5e0cedc | 4130 | |
a00439ac EW |
4131 | # retval of read_url_paths{,_all}(); |
4132 | $l_map = { | |
4133 | # repository root url | |
4134 | 'https://svn.musicpd.org' => { | |
4135 | # repository path # GIT_SVN_ID | |
4136 | 'mpd/trunk' => 'trunk', | |
4137 | 'mpd/tags/0.11.5' => 'tags/0.11.5', | |
4138 | }, | |
4139 | } | |
4140 | ||
a5e0cedc EW |
4141 | Notes: |
4142 | I don't trust the each() function on unless I created %hash myself | |
4143 | because the internal iterator may not have started at base. |