@noldova/checkpoints.git.linux-arm64 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +11 -2
  3. package/git/bin/git +0 -0
  4. package/git/bin/scalar +0 -0
  5. package/git/etc/gitconfig +13 -0
  6. package/git/libexec/git-core/git +0 -0
  7. package/git/libexec/git-core/git-archimport +1136 -0
  8. package/git/libexec/git-core/git-cvsexportcommit +469 -0
  9. package/git/libexec/git-core/git-cvsimport +1185 -0
  10. package/git/libexec/git-core/git-cvsserver +5109 -0
  11. package/git/libexec/git-core/git-daemon +0 -0
  12. package/git/libexec/git-core/git-difftool--helper +125 -0
  13. package/git/libexec/git-core/git-filter-branch +665 -0
  14. package/git/libexec/git-core/git-http-backend +0 -0
  15. package/git/libexec/git-core/git-http-fetch +0 -0
  16. package/git/libexec/git-core/git-imap-send +0 -0
  17. package/git/libexec/git-core/git-instaweb +786 -0
  18. package/git/libexec/git-core/git-merge-octopus +112 -0
  19. package/git/libexec/git-core/git-merge-one-file +167 -0
  20. package/git/libexec/git-core/git-merge-resolve +64 -0
  21. package/git/libexec/git-core/git-mergetool +579 -0
  22. package/git/libexec/git-core/git-mergetool--lib +549 -0
  23. package/git/libexec/git-core/git-quiltimport +155 -0
  24. package/git/libexec/git-core/git-receive-pack +0 -0
  25. package/git/libexec/git-core/git-remote-ftp +0 -0
  26. package/git/libexec/git-core/git-remote-ftps +0 -0
  27. package/git/libexec/git-core/git-remote-http +0 -0
  28. package/git/libexec/git-core/git-remote-https +0 -0
  29. package/git/libexec/git-core/git-request-pull +178 -0
  30. package/git/libexec/git-core/git-send-email +2474 -0
  31. package/git/libexec/git-core/git-sh-i18n +79 -0
  32. package/git/libexec/git-core/git-sh-i18n--envsubst +0 -0
  33. package/git/libexec/git-core/git-sh-setup +357 -0
  34. package/git/libexec/git-core/git-shell +0 -0
  35. package/git/libexec/git-core/git-submodule +671 -0
  36. package/git/libexec/git-core/git-upload-archive +0 -0
  37. package/git/libexec/git-core/git-upload-pack +0 -0
  38. package/git/libexec/git-core/git-web--browse +196 -0
  39. package/git/libexec/git-core/mergetools/araxis +26 -0
  40. package/git/libexec/git-core/mergetools/bc +37 -0
  41. package/git/libexec/git-core/mergetools/codecompare +31 -0
  42. package/git/libexec/git-core/mergetools/deltawalker +33 -0
  43. package/git/libexec/git-core/mergetools/diffmerge +26 -0
  44. package/git/libexec/git-core/mergetools/diffuse +23 -0
  45. package/git/libexec/git-core/mergetools/ecmerge +22 -0
  46. package/git/libexec/git-core/mergetools/emerge +34 -0
  47. package/git/libexec/git-core/mergetools/examdiff +24 -0
  48. package/git/libexec/git-core/mergetools/guiffy +26 -0
  49. package/git/libexec/git-core/mergetools/gvimdiff +1 -0
  50. package/git/libexec/git-core/mergetools/kdiff3 +44 -0
  51. package/git/libexec/git-core/mergetools/kompare +19 -0
  52. package/git/libexec/git-core/mergetools/meld +97 -0
  53. package/git/libexec/git-core/mergetools/nvimdiff +1 -0
  54. package/git/libexec/git-core/mergetools/opendiff +22 -0
  55. package/git/libexec/git-core/mergetools/p4merge +44 -0
  56. package/git/libexec/git-core/mergetools/smerge +20 -0
  57. package/git/libexec/git-core/mergetools/tkdiff +24 -0
  58. package/git/libexec/git-core/mergetools/tortoisemerge +40 -0
  59. package/git/libexec/git-core/mergetools/vimdiff +657 -0
  60. package/git/libexec/git-core/mergetools/vscode +19 -0
  61. package/git/libexec/git-core/mergetools/winmerge +23 -0
  62. package/git/libexec/git-core/mergetools/xxdiff +38 -0
  63. package/git/libexec/git-core/scalar +0 -0
  64. package/git/share/bash-completion/completions/git +4115 -0
  65. package/git/share/git-core/templates/description +1 -0
  66. package/git/share/git-core/templates/hooks/applypatch-msg.sample +15 -0
  67. package/git/share/git-core/templates/hooks/commit-msg.sample +74 -0
  68. package/git/share/git-core/templates/hooks/fsmonitor-watchman.sample +168 -0
  69. package/git/share/git-core/templates/hooks/post-update.sample +8 -0
  70. package/git/share/git-core/templates/hooks/pre-applypatch.sample +14 -0
  71. package/git/share/git-core/templates/hooks/pre-commit.sample +49 -0
  72. package/git/share/git-core/templates/hooks/pre-merge-commit.sample +13 -0
  73. package/git/share/git-core/templates/hooks/pre-push.sample +53 -0
  74. package/git/share/git-core/templates/hooks/pre-rebase.sample +169 -0
  75. package/git/share/git-core/templates/hooks/pre-receive.sample +24 -0
  76. package/git/share/git-core/templates/hooks/prepare-commit-msg.sample +42 -0
  77. package/git/share/git-core/templates/hooks/push-to-checkout.sample +78 -0
  78. package/git/share/git-core/templates/hooks/sendemail-validate.sample +77 -0
  79. package/git/share/git-core/templates/hooks/update.sample +128 -0
  80. package/git/share/git-core/templates/info/exclude +6 -0
  81. package/git/share/gitweb/gitweb.cgi +8499 -0
  82. package/git/share/gitweb/static/git-favicon.png +0 -0
  83. package/git/share/gitweb/static/git-logo.png +0 -0
  84. package/git/share/gitweb/static/gitweb.css +756 -0
  85. package/git/share/gitweb/static/gitweb.js +1579 -0
  86. package/git/share/locale/af/LC_MESSAGES/git.mo +0 -0
  87. package/git/share/locale/bg/LC_MESSAGES/git.mo +0 -0
  88. package/git/share/locale/ca/LC_MESSAGES/git.mo +0 -0
  89. package/git/share/locale/de/LC_MESSAGES/git.mo +0 -0
  90. package/git/share/locale/el/LC_MESSAGES/git.mo +0 -0
  91. package/git/share/locale/es/LC_MESSAGES/git.mo +0 -0
  92. package/git/share/locale/fr/LC_MESSAGES/git.mo +0 -0
  93. package/git/share/locale/ga/LC_MESSAGES/git.mo +0 -0
  94. package/git/share/locale/id/LC_MESSAGES/git.mo +0 -0
  95. package/git/share/locale/is/LC_MESSAGES/git.mo +0 -0
  96. package/git/share/locale/it/LC_MESSAGES/git.mo +0 -0
  97. package/git/share/locale/ko/LC_MESSAGES/git.mo +0 -0
  98. package/git/share/locale/pl/LC_MESSAGES/git.mo +0 -0
  99. package/git/share/locale/pt_BR/LC_MESSAGES/git.mo +0 -0
  100. package/git/share/locale/pt_PT/LC_MESSAGES/git.mo +0 -0
  101. package/git/share/locale/ru/LC_MESSAGES/git.mo +0 -0
  102. package/git/share/locale/sv/LC_MESSAGES/git.mo +0 -0
  103. package/git/share/locale/tr/LC_MESSAGES/git.mo +0 -0
  104. package/git/share/locale/uk/LC_MESSAGES/git.mo +0 -0
  105. package/git/share/locale/vi/LC_MESSAGES/git.mo +0 -0
  106. package/git/share/locale/zh_CN/LC_MESSAGES/git.mo +0 -0
  107. package/git/share/locale/zh_TW/LC_MESSAGES/git.mo +0 -0
  108. package/git/share/perl5/FromCPAN/Error.pm +1040 -0
  109. package/git/share/perl5/FromCPAN/Mail/Address.pm +280 -0
  110. package/git/share/perl5/Git/I18N.pm +125 -0
  111. package/git/share/perl5/Git/IndexInfo.pm +35 -0
  112. package/git/share/perl5/Git/LoadCPAN/Error.pm +10 -0
  113. package/git/share/perl5/Git/LoadCPAN/Mail/Address.pm +10 -0
  114. package/git/share/perl5/Git/LoadCPAN.pm +104 -0
  115. package/git/share/perl5/Git/Packet.pm +173 -0
  116. package/git/share/perl5/Git/SVN/Editor.pm +605 -0
  117. package/git/share/perl5/Git/SVN/Fetcher.pm +622 -0
  118. package/git/share/perl5/Git/SVN/GlobSpec.pm +65 -0
  119. package/git/share/perl5/Git/SVN/Log.pm +400 -0
  120. package/git/share/perl5/Git/SVN/Memoize/YAML.pm +93 -0
  121. package/git/share/perl5/Git/SVN/Migration.pm +265 -0
  122. package/git/share/perl5/Git/SVN/Prompt.pm +184 -0
  123. package/git/share/perl5/Git/SVN/Ra.pm +708 -0
  124. package/git/share/perl5/Git/SVN/Utils.pm +232 -0
  125. package/git/share/perl5/Git/SVN.pm +2573 -0
  126. package/git/share/perl5/Git.pm +1780 -0
  127. package/licenses/git/COPYING +360 -0
  128. package/licenses/git/LGPL-2.1 +511 -0
  129. package/licenses/perl-modules-from-cpan/Artistic +131 -0
  130. package/licenses/perl-modules-from-cpan/Copying +250 -0
  131. package/package.json +167 -4
@@ -0,0 +1,1136 @@
1
+ #!/usr/bin/perl
2
+
3
+ use lib (split(/:/, $ENV{GITPERLLIB} || '//share/perl5'));
4
+ #
5
+ # This tool is copyright (c) 2005, Martin Langhoff.
6
+ # It is released under the Gnu Public License, version 2.
7
+ #
8
+ # The basic idea is to walk the output of tla abrowse,
9
+ # fetch the changesets and apply them.
10
+ #
11
+
12
+ =head1 Invocation
13
+
14
+ git archimport [ -h ] [ -v ] [ -o ] [ -a ] [ -f ] [ -T ]
15
+ [ -D depth] [ -t tempdir ] <archive>/<branch> [ <archive>/<branch> ]
16
+
17
+ Imports a project from one or more Arch repositories. It will follow branches
18
+ and repositories within the namespaces defined by the <archive/branch>
19
+ parameters supplied. If it cannot find the remote branch a merge comes from
20
+ it will just import it as a regular commit. If it can find it, it will mark it
21
+ as a merge whenever possible.
22
+
23
+ See man (1) git-archimport for more details.
24
+
25
+ =head1 TODO
26
+
27
+ - create tag objects instead of ref tags
28
+ - audit shell-escaping of filenames
29
+ - hide our private tags somewhere smarter
30
+ - find a way to make "cat *patches | patch" safe even when patchfiles are missing newlines
31
+ - sort and apply patches by graphing ancestry relations instead of just
32
+ relying in dates supplied in the changeset itself.
33
+ tla ancestry-graph -m could be helpful here...
34
+
35
+ =head1 Devel tricks
36
+
37
+ Add print in front of the shell commands invoked via backticks.
38
+
39
+ =head1 Devel Notes
40
+
41
+ There are several places where Arch and git terminology are intermixed
42
+ and potentially confused.
43
+
44
+ The notion of a "branch" in git is approximately equivalent to
45
+ a "archive/category--branch--version" in Arch. Also, it should be noted
46
+ that the "--branch" portion of "archive/category--branch--version" is really
47
+ optional in Arch although not many people (nor tools!) seem to know this.
48
+ This means that "archive/category--version" is also a valid "branch"
49
+ in git terms.
50
+
51
+ We always refer to Arch names by their fully qualified variant (which
52
+ means the "archive" name is prefixed.
53
+
54
+ For people unfamiliar with Arch, an "archive" is the term for "repository",
55
+ and can contain multiple, unrelated branches.
56
+
57
+ =cut
58
+
59
+ require v5.26;
60
+ use strict;
61
+ use warnings;
62
+ use Getopt::Std;
63
+ use File::Temp qw(tempdir);
64
+ use File::Path qw(mkpath rmtree);
65
+ use File::Basename qw(basename dirname);
66
+ use Data::Dumper qw/ Dumper /;
67
+ use IPC::Open2;
68
+
69
+ $SIG{'PIPE'}="IGNORE";
70
+ $ENV{'TZ'}="UTC";
71
+
72
+ my $git_dir = $ENV{"GIT_DIR"} || ".git";
73
+ $ENV{"GIT_DIR"} = $git_dir;
74
+ my $ptag_dir = "$git_dir/archimport/tags";
75
+
76
+ our($opt_h,$opt_f,$opt_v,$opt_T,$opt_t,$opt_D,$opt_a,$opt_o);
77
+
78
+ sub usage() {
79
+ print STDERR <<END;
80
+ usage: git archimport # fetch/update GIT from Arch
81
+ [ -h ] [ -v ] [ -o ] [ -a ] [ -f ] [ -T ] [ -D depth ] [ -t tempdir ]
82
+ repository/arch-branch [ repository/arch-branch] ...
83
+ END
84
+ exit(1);
85
+ }
86
+
87
+ getopts("fThvat:D:") or usage();
88
+ usage if $opt_h;
89
+
90
+ @ARGV >= 1 or usage();
91
+ # $arch_branches:
92
+ # values associated with keys:
93
+ # =1 - Arch version / git 'branch' detected via abrowse on a limit
94
+ # >1 - Arch version / git 'branch' of an auxiliary branch we've merged
95
+ my %arch_branches = map { my $branch = $_; $branch =~ s/:[^:]*$//; $branch => 1 } @ARGV;
96
+
97
+ # $branch_name_map:
98
+ # maps arch branches to git branch names
99
+ my %branch_name_map = map { m/^(.*):([^:]*)$/; $1 => $2 } grep { m/:/ } @ARGV;
100
+
101
+ $ENV{'TMPDIR'} = $opt_t if $opt_t; # $ENV{TMPDIR} will affect tempdir() calls:
102
+ my $tmp = tempdir('git-archimport-XXXXXX', TMPDIR => 1, CLEANUP => 1);
103
+ $opt_v && print "+ Using $tmp as temporary directory\n";
104
+
105
+ unless (-d $git_dir) { # initial import needs empty directory
106
+ opendir DIR, '.' or die "Unable to open current directory: $!\n";
107
+ while (my $entry = readdir DIR) {
108
+ $entry =~ /^\.\.?$/ or
109
+ die "Initial import needs an empty current working directory.\n"
110
+ }
111
+ closedir DIR
112
+ }
113
+
114
+ my $default_archive; # default Arch archive
115
+ my %reachable = (); # Arch repositories we can access
116
+ my %unreachable = (); # Arch repositories we can't access :<
117
+ my @psets = (); # the collection
118
+ my %psets = (); # the collection, by name
119
+ my %stats = ( # Track which strategy we used to import:
120
+ get_tag => 0, replay => 0, get_new => 0, get_delta => 0,
121
+ simple_changeset => 0, import_or_tag => 0
122
+ );
123
+
124
+ my %rptags = (); # my reverse private tags
125
+ # to map a SHA1 to a commitid
126
+ my $TLA = $ENV{'ARCH_CLIENT'} || 'tla';
127
+
128
+ sub do_abrowse {
129
+ my $stage = shift;
130
+ while (my ($limit, $level) = each %arch_branches) {
131
+ next unless $level == $stage;
132
+
133
+ open ABROWSE, "$TLA abrowse -fkD --merges $limit |"
134
+ or die "Problems with tla abrowse: $!";
135
+
136
+ my %ps = (); # the current one
137
+ my $lastseen = '';
138
+
139
+ while (<ABROWSE>) {
140
+ chomp;
141
+
142
+ # first record padded w 8 spaces
143
+ if (s/^\s{8}\b//) {
144
+ my ($id, $type) = split(m/\s+/, $_, 2);
145
+
146
+ my %last_ps;
147
+ # store the record we just captured
148
+ if (%ps && !exists $psets{ $ps{id} }) {
149
+ %last_ps = %ps; # break references
150
+ push (@psets, \%last_ps);
151
+ $psets{ $last_ps{id} } = \%last_ps;
152
+ }
153
+
154
+ my $branch = extract_versionname($id);
155
+ %ps = ( id => $id, branch => $branch );
156
+ if (%last_ps && ($last_ps{branch} eq $branch)) {
157
+ $ps{parent_id} = $last_ps{id};
158
+ }
159
+
160
+ $arch_branches{$branch} = 1;
161
+ $lastseen = 'id';
162
+
163
+ # deal with types (should work with baz or tla):
164
+ if ($type =~ m/\(.*changeset\)/) {
165
+ $ps{type} = 's';
166
+ } elsif ($type =~ /\(.*import\)/) {
167
+ $ps{type} = 'i';
168
+ } elsif ($type =~ m/\(tag.*?(\S+\@\S+).*?\)/) {
169
+ $ps{type} = 't';
170
+ # read which revision we've tagged when we parse the log
171
+ $ps{tag} = $1;
172
+ } else {
173
+ warn "Unknown type $type";
174
+ }
175
+
176
+ $arch_branches{$branch} = 1;
177
+ $lastseen = 'id';
178
+ } elsif (s/^\s{10}//) {
179
+ # 10 leading spaces or more
180
+ # indicate commit metadata
181
+
182
+ # date
183
+ if ($lastseen eq 'id' && m/^(\d{4}-\d\d-\d\d \d\d:\d\d:\d\d)/){
184
+ $ps{date} = $1;
185
+ $lastseen = 'date';
186
+ } elsif ($_ eq 'merges in:') {
187
+ $ps{merges} = [];
188
+ $lastseen = 'merges';
189
+ } elsif ($lastseen eq 'merges' && s/^\s{2}//) {
190
+ my $id = $_;
191
+ push (@{$ps{merges}}, $id);
192
+
193
+ # aggressive branch finding:
194
+ if ($opt_D) {
195
+ my $branch = extract_versionname($id);
196
+ my $repo = extract_reponame($branch);
197
+
198
+ if (archive_reachable($repo) &&
199
+ !defined $arch_branches{$branch}) {
200
+ $arch_branches{$branch} = $stage + 1;
201
+ }
202
+ }
203
+ } else {
204
+ warn "more metadata after merges!?: $_\n" unless /^\s*$/;
205
+ }
206
+ }
207
+ }
208
+
209
+ if (%ps && !exists $psets{ $ps{id} }) {
210
+ my %temp = %ps; # break references
211
+ if (@psets && $psets[$#psets]{branch} eq $ps{branch}) {
212
+ $temp{parent_id} = $psets[$#psets]{id};
213
+ }
214
+ push (@psets, \%temp);
215
+ $psets{ $temp{id} } = \%temp;
216
+ }
217
+
218
+ close ABROWSE or die "$TLA abrowse failed on $limit\n";
219
+ }
220
+ } # end foreach $root
221
+
222
+ do_abrowse(1);
223
+ my $depth = 2;
224
+ $opt_D ||= 0;
225
+ while ($depth <= $opt_D) {
226
+ do_abrowse($depth);
227
+ $depth++;
228
+ }
229
+
230
+ ## Order patches by time
231
+ # FIXME see if we can find a more optimal way to do this by graphing
232
+ # the ancestry data and walking it, that way we won't have to rely on
233
+ # client-supplied dates
234
+ @psets = sort {$a->{date}.$b->{id} cmp $b->{date}.$b->{id}} @psets;
235
+
236
+ #print Dumper \@psets;
237
+
238
+ ##
239
+ ## TODO cleanup irrelevant patches
240
+ ## and put an initial import
241
+ ## or a full tag
242
+ my $import = 0;
243
+ unless (-d $git_dir) { # initial import
244
+ if ($psets[0]{type} eq 'i' || $psets[0]{type} eq 't') {
245
+ print "Starting import from $psets[0]{id}\n";
246
+ `git-init`;
247
+ die $! if $?;
248
+ $import = 1;
249
+ } else {
250
+ die "Need to start from an import or a tag -- cannot use $psets[0]{id}";
251
+ }
252
+ } else { # progressing an import
253
+ # load the rptags
254
+ opendir(DIR, $ptag_dir)
255
+ || die "can't opendir: $!";
256
+ while (my $file = readdir(DIR)) {
257
+ # skip non-interesting-files
258
+ next unless -f "$ptag_dir/$file";
259
+
260
+ # convert first '--' to '/' from old git-archimport to use
261
+ # as an archivename/c--b--v private tag
262
+ if ($file !~ m!,!) {
263
+ my $oldfile = $file;
264
+ $file =~ s!--!,!;
265
+ print STDERR "converting old tag $oldfile to $file\n";
266
+ rename("$ptag_dir/$oldfile", "$ptag_dir/$file") or die $!;
267
+ }
268
+ my $sha = ptag($file);
269
+ chomp $sha;
270
+ $rptags{$sha} = $file;
271
+ }
272
+ closedir DIR;
273
+ }
274
+
275
+ # process patchsets
276
+ # extract the Arch repository name (Arch "archive" in Arch-speak)
277
+ sub extract_reponame {
278
+ my $fq_cvbr = shift; # archivename/[[[[category]branch]version]revision]
279
+ return (split(/\//, $fq_cvbr))[0];
280
+ }
281
+
282
+ sub extract_versionname {
283
+ my $name = shift;
284
+ $name =~ s/--(?:patch|version(?:fix)?|base)-\d+$//;
285
+ return $name;
286
+ }
287
+
288
+ # convert a fully-qualified revision or version to a unique dirname:
289
+ # normalperson@yhbt.net-05/mpd--uclinux--1--patch-2
290
+ # becomes: normalperson@yhbt.net-05,mpd--uclinux--1
291
+ #
292
+ # the git notion of a branch is closer to
293
+ # archive/category--branch--version than archive/category--branch, so we
294
+ # use this to convert to git branch names.
295
+ # Also, keep archive names but replace '/' with ',' since it won't require
296
+ # subdirectories, and is safer than swapping '--' which could confuse
297
+ # reverse-mapping when dealing with bastard branches that
298
+ # are just archive/category--version (no --branch)
299
+ sub tree_dirname {
300
+ my $revision = shift;
301
+ my $name = extract_versionname($revision);
302
+ $name =~ s#/#,#;
303
+ return $name;
304
+ }
305
+
306
+ # old versions of git-archimport just use the <category--branch> part:
307
+ sub old_style_branchname {
308
+ my $id = shift;
309
+ my $ret = safe_pipe_capture($TLA,'parse-package-name','-p',$id);
310
+ chomp $ret;
311
+ return $ret;
312
+ }
313
+
314
+ *git_default_branchname = $opt_o ? *old_style_branchname : *tree_dirname;
315
+
316
+ # retrieve default archive, since $branch_name_map keys might not include it
317
+ sub get_default_archive {
318
+ if (!defined $default_archive) {
319
+ $default_archive = safe_pipe_capture($TLA,'my-default-archive');
320
+ chomp $default_archive;
321
+ }
322
+ return $default_archive;
323
+ }
324
+
325
+ sub git_branchname {
326
+ my $revision = shift;
327
+ my $name = extract_versionname($revision);
328
+
329
+ if (exists $branch_name_map{$name}) {
330
+ return $branch_name_map{$name};
331
+
332
+ } elsif ($name =~ m#^([^/]*)/(.*)$#
333
+ && $1 eq get_default_archive()
334
+ && exists $branch_name_map{$2}) {
335
+ # the names given in the command-line lacked the archive.
336
+ return $branch_name_map{$2};
337
+
338
+ } else {
339
+ return git_default_branchname($revision);
340
+ }
341
+ }
342
+
343
+ sub process_patchset_accurate {
344
+ my $ps = shift;
345
+
346
+ # switch to that branch if we're not already in that branch:
347
+ if (-e "$git_dir/refs/heads/$ps->{branch}") {
348
+ system('git-checkout','-f',$ps->{branch}) == 0 or die "$! $?\n";
349
+
350
+ # remove any old stuff that got leftover:
351
+ my $rm = safe_pipe_capture('git-ls-files','--others','-z');
352
+ rmtree(split(/\0/,$rm)) if $rm;
353
+ }
354
+
355
+ # Apply the import/changeset/merge into the working tree
356
+ my $dir = sync_to_ps($ps);
357
+ # read the new log entry:
358
+ my @commitlog = safe_pipe_capture($TLA,'cat-log','-d',$dir,$ps->{id});
359
+ die "Error in cat-log: $!" if $?;
360
+ chomp @commitlog;
361
+
362
+ # grab variables we want from the log, new fields get added to $ps:
363
+ # (author, date, email, summary, message body ...)
364
+ parselog($ps, \@commitlog);
365
+
366
+ if ($ps->{id} =~ /--base-0$/ && $ps->{id} ne $psets[0]{id}) {
367
+ # this should work when importing continuations
368
+ if ($ps->{tag} && (my $branchpoint = eval { ptag($ps->{tag}) })) {
369
+
370
+ # find where we are supposed to branch from
371
+ if (! -e "$git_dir/refs/heads/$ps->{branch}") {
372
+ system('git-branch',$ps->{branch},$branchpoint) == 0 or die "$! $?\n";
373
+
374
+ # We trust Arch with the fact that this is just a tag,
375
+ # and it does not affect the state of the tree, so
376
+ # we just tag and move on. If the user really wants us
377
+ # to consolidate more branches into one, don't tag because
378
+ # the tag name would be already taken.
379
+ tag($ps->{id}, $branchpoint);
380
+ ptag($ps->{id}, $branchpoint);
381
+ print " * Tagged $ps->{id} at $branchpoint\n";
382
+ }
383
+ system('git-checkout','-f',$ps->{branch}) == 0 or die "$! $?\n";
384
+
385
+ # remove any old stuff that got leftover:
386
+ my $rm = safe_pipe_capture('git-ls-files','--others','-z');
387
+ rmtree(split(/\0/,$rm)) if $rm;
388
+ return 0;
389
+ } else {
390
+ warn "Tagging from unknown id unsupported\n" if $ps->{tag};
391
+ }
392
+ # allow multiple bases/imports here since Arch supports cherry-picks
393
+ # from unrelated trees
394
+ }
395
+
396
+ # update the index with all the changes we got
397
+ system('git-diff-files --name-only -z | '.
398
+ 'git-update-index --remove -z --stdin') == 0 or die "$! $?\n";
399
+ system('git-ls-files --others -z | '.
400
+ 'git-update-index --add -z --stdin') == 0 or die "$! $?\n";
401
+ return 1;
402
+ }
403
+
404
+ # the native changeset processing strategy. This is very fast, but
405
+ # does not handle permissions or any renames involving directories
406
+ sub process_patchset_fast {
407
+ my $ps = shift;
408
+ #
409
+ # create the branch if needed
410
+ #
411
+ if ($ps->{type} eq 'i' && !$import) {
412
+ die "Should not have more than one 'Initial import' per GIT import: $ps->{id}";
413
+ }
414
+
415
+ unless ($import) { # skip for import
416
+ if ( -e "$git_dir/refs/heads/$ps->{branch}") {
417
+ # we know about this branch
418
+ system('git-checkout',$ps->{branch});
419
+ } else {
420
+ # new branch! we need to verify a few things
421
+ die "Branch on a non-tag!" unless $ps->{type} eq 't';
422
+ my $branchpoint = ptag($ps->{tag});
423
+ die "Tagging from unknown id unsupported: $ps->{tag}"
424
+ unless $branchpoint;
425
+
426
+ # find where we are supposed to branch from
427
+ if (! -e "$git_dir/refs/heads/$ps->{branch}") {
428
+ system('git-branch',$ps->{branch},$branchpoint) == 0 or die "$! $?\n";
429
+
430
+ # We trust Arch with the fact that this is just a tag,
431
+ # and it does not affect the state of the tree, so
432
+ # we just tag and move on. If the user really wants us
433
+ # to consolidate more branches into one, don't tag because
434
+ # the tag name would be already taken.
435
+ tag($ps->{id}, $branchpoint);
436
+ ptag($ps->{id}, $branchpoint);
437
+ print " * Tagged $ps->{id} at $branchpoint\n";
438
+ }
439
+ system('git-checkout',$ps->{branch}) == 0 or die "$! $?\n";
440
+ return 0;
441
+ }
442
+ die $! if $?;
443
+ }
444
+
445
+ #
446
+ # Apply the import/changeset/merge into the working tree
447
+ #
448
+ if ($ps->{type} eq 'i' || $ps->{type} eq 't') {
449
+ apply_import($ps) or die $!;
450
+ $stats{import_or_tag}++;
451
+ $import=0;
452
+ } elsif ($ps->{type} eq 's') {
453
+ apply_cset($ps);
454
+ $stats{simple_changeset}++;
455
+ }
456
+
457
+ #
458
+ # prepare update git's index, based on what arch knows
459
+ # about the pset, resolve parents, etc
460
+ #
461
+
462
+ my @commitlog = safe_pipe_capture($TLA,'cat-archive-log',$ps->{id});
463
+ die "Error in cat-archive-log: $!" if $?;
464
+
465
+ parselog($ps,\@commitlog);
466
+
467
+ # imports don't give us good info
468
+ # on added files. Shame on them
469
+ if ($ps->{type} eq 'i' || $ps->{type} eq 't') {
470
+ system('git-ls-files --deleted -z | '.
471
+ 'git-update-index --remove -z --stdin') == 0 or die "$! $?\n";
472
+ system('git-ls-files --others -z | '.
473
+ 'git-update-index --add -z --stdin') == 0 or die "$! $?\n";
474
+ }
475
+
476
+ # TODO: handle removed_directories and renamed_directories:
477
+
478
+ if (my $del = $ps->{removed_files}) {
479
+ unlink @$del;
480
+ while (@$del) {
481
+ my @slice = splice(@$del, 0, 100);
482
+ system('git-update-index','--remove','--',@slice) == 0 or
483
+ die "Error in git-update-index --remove: $! $?\n";
484
+ }
485
+ }
486
+
487
+ if (my $ren = $ps->{renamed_files}) { # renamed
488
+ if (@$ren % 2) {
489
+ die "Odd number of entries in rename!?";
490
+ }
491
+
492
+ while (@$ren) {
493
+ my $from = shift @$ren;
494
+ my $to = shift @$ren;
495
+
496
+ unless (-d dirname($to)) {
497
+ mkpath(dirname($to)); # will die on err
498
+ }
499
+ # print "moving $from $to";
500
+ rename($from, $to) or die "Error renaming '$from' '$to': $!\n";
501
+ system('git-update-index','--remove','--',$from) == 0 or
502
+ die "Error in git-update-index --remove: $! $?\n";
503
+ system('git-update-index','--add','--',$to) == 0 or
504
+ die "Error in git-update-index --add: $! $?\n";
505
+ }
506
+ }
507
+
508
+ if (my $add = $ps->{new_files}) {
509
+ while (@$add) {
510
+ my @slice = splice(@$add, 0, 100);
511
+ system('git-update-index','--add','--',@slice) == 0 or
512
+ die "Error in git-update-index --add: $! $?\n";
513
+ }
514
+ }
515
+
516
+ if (my $mod = $ps->{modified_files}) {
517
+ while (@$mod) {
518
+ my @slice = splice(@$mod, 0, 100);
519
+ system('git-update-index','--',@slice) == 0 or
520
+ die "Error in git-update-index: $! $?\n";
521
+ }
522
+ }
523
+ return 1; # we successfully applied the changeset
524
+ }
525
+
526
+ if ($opt_f) {
527
+ print "Will import patchsets using the fast strategy\n",
528
+ "Renamed directories and permission changes will be missed\n";
529
+ *process_patchset = *process_patchset_fast;
530
+ } else {
531
+ print "Using the default (accurate) import strategy.\n",
532
+ "Things may be a bit slow\n";
533
+ *process_patchset = *process_patchset_accurate;
534
+ }
535
+
536
+ foreach my $ps (@psets) {
537
+ # process patchsets
538
+ $ps->{branch} = git_branchname($ps->{id});
539
+
540
+ #
541
+ # ensure we have a clean state
542
+ #
543
+ if (my $dirty = `git-diff-files`) {
544
+ die "Unclean tree when about to process $ps->{id} " .
545
+ " - did we fail to commit cleanly before?\n$dirty";
546
+ }
547
+ die $! if $?;
548
+
549
+ #
550
+ # skip commits already in repo
551
+ #
552
+ if (ptag($ps->{id})) {
553
+ $opt_v && print " * Skipping already imported: $ps->{id}\n";
554
+ next;
555
+ }
556
+
557
+ print " * Starting to work on $ps->{id}\n";
558
+
559
+ process_patchset($ps) or next;
560
+
561
+ # warn "errors when running git-update-index! $!";
562
+ my $tree = `git-write-tree`;
563
+ die "cannot write tree $!" if $?;
564
+ chomp $tree;
565
+
566
+ #
567
+ # Who's your daddy?
568
+ #
569
+ my @par;
570
+ if ( -e "$git_dir/refs/heads/$ps->{branch}") {
571
+ if (open HEAD, "<","$git_dir/refs/heads/$ps->{branch}") {
572
+ my $p = <HEAD>;
573
+ close HEAD;
574
+ chomp $p;
575
+ push @par, '-p', $p;
576
+ } else {
577
+ if ($ps->{type} eq 's') {
578
+ warn "Could not find the right head for the branch $ps->{branch}";
579
+ }
580
+ }
581
+ }
582
+
583
+ if ($ps->{merges}) {
584
+ push @par, find_parents($ps);
585
+ }
586
+
587
+ #
588
+ # Commit, tag and clean state
589
+ #
590
+ $ENV{TZ} = 'GMT';
591
+ $ENV{GIT_AUTHOR_NAME} = $ps->{author};
592
+ $ENV{GIT_AUTHOR_EMAIL} = $ps->{email};
593
+ $ENV{GIT_AUTHOR_DATE} = $ps->{date};
594
+ $ENV{GIT_COMMITTER_NAME} = $ps->{author};
595
+ $ENV{GIT_COMMITTER_EMAIL} = $ps->{email};
596
+ $ENV{GIT_COMMITTER_DATE} = $ps->{date};
597
+
598
+ my $pid = open2(*READER, *WRITER,'git-commit-tree',$tree,@par)
599
+ or die $!;
600
+ print WRITER $ps->{summary},"\n\n";
601
+
602
+ # only print message if it's not empty, to avoid a spurious blank line;
603
+ # also append an extra newline, so there's a blank line before the
604
+ # following "git-archimport-id:" line.
605
+ print WRITER $ps->{message},"\n\n" if ($ps->{message} ne "");
606
+
607
+ # make it easy to backtrack and figure out which Arch revision this was:
608
+ print WRITER 'git-archimport-id: ',$ps->{id},"\n";
609
+
610
+ close WRITER;
611
+ my $commitid = <READER>; # read
612
+ chomp $commitid;
613
+ close READER;
614
+ waitpid $pid,0; # close;
615
+
616
+ if (length $commitid != 40) {
617
+ die "Something went wrong with the commit! $! $commitid";
618
+ }
619
+ #
620
+ # Update the branch
621
+ #
622
+ open HEAD, ">","$git_dir/refs/heads/$ps->{branch}";
623
+ print HEAD $commitid;
624
+ close HEAD;
625
+ system('git-update-ref', 'HEAD', "$ps->{branch}");
626
+
627
+ # tag accordingly
628
+ ptag($ps->{id}, $commitid); # private tag
629
+ if ($opt_T || $ps->{type} eq 't' || $ps->{type} eq 'i') {
630
+ tag($ps->{id}, $commitid);
631
+ }
632
+ print " * Committed $ps->{id}\n";
633
+ print " + tree $tree\n";
634
+ print " + commit $commitid\n";
635
+ $opt_v && print " + commit date is $ps->{date} \n";
636
+ $opt_v && print " + parents: ",join(' ',@par),"\n";
637
+ }
638
+
639
+ if ($opt_v) {
640
+ foreach (sort keys %stats) {
641
+ print" $_: $stats{$_}\n";
642
+ }
643
+ }
644
+ exit 0;
645
+
646
+ # used by the accurate strategy:
647
+ sub sync_to_ps {
648
+ my $ps = shift;
649
+ my $tree_dir = $tmp.'/'.tree_dirname($ps->{id});
650
+
651
+ $opt_v && print "sync_to_ps($ps->{id}) method: ";
652
+
653
+ if (-d $tree_dir) {
654
+ if ($ps->{type} eq 't') {
655
+ $opt_v && print "get (tag)\n";
656
+ # looks like a tag-only or (worse,) a mixed tags/changeset branch,
657
+ # can't rely on replay to work correctly on these
658
+ rmtree($tree_dir);
659
+ safe_pipe_capture($TLA,'get','--no-pristine',$ps->{id},$tree_dir);
660
+ $stats{get_tag}++;
661
+ } else {
662
+ my $tree_id = arch_tree_id($tree_dir);
663
+ if ($ps->{parent_id} && ($ps->{parent_id} eq $tree_id)) {
664
+ # the common case (hopefully)
665
+ $opt_v && print "replay\n";
666
+ safe_pipe_capture($TLA,'replay','-d',$tree_dir,$ps->{id});
667
+ $stats{replay}++;
668
+ } else {
669
+ # getting one tree is usually faster than getting two trees
670
+ # and applying the delta ...
671
+ rmtree($tree_dir);
672
+ $opt_v && print "apply-delta\n";
673
+ safe_pipe_capture($TLA,'get','--no-pristine',
674
+ $ps->{id},$tree_dir);
675
+ $stats{get_delta}++;
676
+ }
677
+ }
678
+ } else {
679
+ # new branch work
680
+ $opt_v && print "get (new tree)\n";
681
+ safe_pipe_capture($TLA,'get','--no-pristine',$ps->{id},$tree_dir);
682
+ $stats{get_new}++;
683
+ }
684
+
685
+ # added -I flag to rsync since we're going to fast! AIEEEEE!!!!
686
+ system('rsync','-aI','--delete','--exclude',$git_dir,
687
+ # '--exclude','.arch-inventory',
688
+ '--exclude','.arch-ids','--exclude','{arch}',
689
+ '--exclude','+*','--exclude',',*',
690
+ "$tree_dir/",'./') == 0 or die "Cannot rsync $tree_dir: $! $?";
691
+ return $tree_dir;
692
+ }
693
+
694
+ sub apply_import {
695
+ my $ps = shift;
696
+ my $bname = git_branchname($ps->{id});
697
+
698
+ mkpath($tmp);
699
+
700
+ safe_pipe_capture($TLA,'get','-s','--no-pristine',$ps->{id},"$tmp/import");
701
+ die "Cannot get import: $!" if $?;
702
+ system('rsync','-aI','--delete', '--exclude',$git_dir,
703
+ '--exclude','.arch-ids','--exclude','{arch}',
704
+ "$tmp/import/", './');
705
+ die "Cannot rsync import:$!" if $?;
706
+
707
+ rmtree("$tmp/import");
708
+ die "Cannot remove tempdir: $!" if $?;
709
+
710
+
711
+ return 1;
712
+ }
713
+
714
+ sub apply_cset {
715
+ my $ps = shift;
716
+
717
+ mkpath($tmp);
718
+
719
+ # get the changeset
720
+ safe_pipe_capture($TLA,'get-changeset',$ps->{id},"$tmp/changeset");
721
+ die "Cannot get changeset: $!" if $?;
722
+
723
+ # apply patches
724
+ if (`find $tmp/changeset/patches -type f -name '*.patch'`) {
725
+ # this can be sped up considerably by doing
726
+ # (find | xargs cat) | patch
727
+ # but that can get mucked up by patches
728
+ # with missing trailing newlines or the standard
729
+ # 'missing newline' flag in the patch - possibly
730
+ # produced with an old/buggy diff.
731
+ # slow and safe, we invoke patch once per patchfile
732
+ `find $tmp/changeset/patches -type f -name '*.patch' -print0 | grep -zv '{arch}' | xargs -iFILE -0 --no-run-if-empty patch -p1 --forward -iFILE`;
733
+ die "Problem applying patches! $!" if $?;
734
+ }
735
+
736
+ # apply changed binary files
737
+ if (my @modified = `find $tmp/changeset/patches -type f -name '*.modified'`) {
738
+ foreach my $mod (@modified) {
739
+ chomp $mod;
740
+ my $orig = $mod;
741
+ $orig =~ s/\.modified$//; # lazy
742
+ $orig =~ s!^\Q$tmp\E/changeset/patches/!!;
743
+ #print "rsync -p '$mod' '$orig'";
744
+ system('rsync','-p',$mod,"./$orig");
745
+ die "Problem applying binary changes! $!" if $?;
746
+ }
747
+ }
748
+
749
+ # bring in new files
750
+ system('rsync','-aI','--exclude',$git_dir,
751
+ '--exclude','.arch-ids',
752
+ '--exclude', '{arch}',
753
+ "$tmp/changeset/new-files-archive/",'./');
754
+
755
+ # deleted files are hinted from the commitlog processing
756
+
757
+ rmtree("$tmp/changeset");
758
+ }
759
+
760
+
761
+ # =for reference
762
+ # notes: *-files/-directories keys cannot have spaces, they're always
763
+ # pika-escaped. Everything after the first newline
764
+ # A log entry looks like:
765
+ # Revision: moodle-org--moodle--1.3.3--patch-15
766
+ # Archive: arch-eduforge@catalyst.net.nz--2004
767
+ # Creator: Penny Leach <penny@catalyst.net.nz>
768
+ # Date: Wed May 25 14:15:34 NZST 2005
769
+ # Standard-date: 2005-05-25 02:15:34 GMT
770
+ # New-files: lang/de/.arch-ids/block_glossary_random.php.id
771
+ # lang/de/.arch-ids/block_html.php.id
772
+ # New-directories: lang/de/help/questionnaire
773
+ # lang/de/help/questionnaire/.arch-ids
774
+ # Renamed-files: .arch-ids/db_sears.sql.id db/.arch-ids/db_sears.sql.id
775
+ # db_sears.sql db/db_sears.sql
776
+ # Removed-files: lang/be/docs/.arch-ids/release.html.id
777
+ # lang/be/docs/.arch-ids/releaseold.html.id
778
+ # Modified-files: admin/cron.php admin/delete.php
779
+ # admin/editor.html backup/lib.php backup/restore.php
780
+ # New-patches: arch-eduforge@catalyst.net.nz--2004/moodle-org--moodle--1.3.3--patch-15
781
+ # Summary: Updating to latest from MOODLE_14_STABLE (1.4.5+)
782
+ # summary can be multiline with a leading space just like the above fields
783
+ # Keywords:
784
+ #
785
+ # Updating yadda tadda tadda madda
786
+ sub parselog {
787
+ my ($ps, $log) = @_;
788
+ my $key = undef;
789
+
790
+ # headers we want that contain filenames:
791
+ my %want_headers = (
792
+ new_files => 1,
793
+ modified_files => 1,
794
+ renamed_files => 1,
795
+ renamed_directories => 1,
796
+ removed_files => 1,
797
+ removed_directories => 1,
798
+ );
799
+
800
+ chomp (@$log);
801
+ while ($_ = shift @$log) {
802
+ if (/^Continuation-of:\s*(.*)/) {
803
+ $ps->{tag} = $1;
804
+ $key = undef;
805
+ } elsif (/^Summary:\s*(.*)$/ ) {
806
+ # summary can be multiline as long as it has a leading space.
807
+ # we squeeze it onto a single line, though.
808
+ $ps->{summary} = [ $1 ];
809
+ $key = 'summary';
810
+ } elsif (/^Creator: (.*)\s*<([^\>]+)>/) {
811
+ $ps->{author} = $1;
812
+ $ps->{email} = $2;
813
+ $key = undef;
814
+ # any *-files or *-directories can be read here:
815
+ } elsif (/^([A-Z][a-z\-]+):\s*(.*)$/) {
816
+ my $val = $2;
817
+ $key = lc $1;
818
+ $key =~ tr/-/_/; # too lazy to quote :P
819
+ if ($want_headers{$key}) {
820
+ push @{$ps->{$key}}, split(/\s+/, $val);
821
+ } else {
822
+ $key = undef;
823
+ }
824
+ } elsif (/^$/) {
825
+ last; # remainder of @$log that didn't get shifted off is message
826
+ } elsif ($key) {
827
+ if (/^\s+(.*)$/) {
828
+ if ($key eq 'summary') {
829
+ push @{$ps->{$key}}, $1;
830
+ } else { # files/directories:
831
+ push @{$ps->{$key}}, split(/\s+/, $1);
832
+ }
833
+ } else {
834
+ $key = undef;
835
+ }
836
+ }
837
+ }
838
+
839
+ # drop leading empty lines from the log message
840
+ while (@$log && $log->[0] eq '') {
841
+ shift @$log;
842
+ }
843
+ if (exists $ps->{summary} && @{$ps->{summary}}) {
844
+ $ps->{summary} = join(' ', @{$ps->{summary}});
845
+ }
846
+ elsif (@$log == 0) {
847
+ $ps->{summary} = 'empty commit message';
848
+ } else {
849
+ $ps->{summary} = $log->[0] . '...';
850
+ }
851
+ $ps->{message} = join("\n",@$log);
852
+
853
+ # skip Arch control files, unescape pika-escaped files
854
+ foreach my $k (keys %want_headers) {
855
+ next unless (defined $ps->{$k});
856
+ my @tmp = ();
857
+ foreach my $t (@{$ps->{$k}}) {
858
+ next unless length ($t);
859
+ next if $t =~ m!\{arch\}/!;
860
+ next if $t =~ m!\.arch-ids/!;
861
+ # should we skip this?
862
+ next if $t =~ m!\.arch-inventory$!;
863
+ # tla cat-archive-log will give us filenames with spaces as file\(sp)name - why?
864
+ # we can assume that any filename with \ indicates some pika escaping that we want to get rid of.
865
+ if ($t =~ /\\/ ){
866
+ $t = (safe_pipe_capture($TLA,'escape','--unescaped',$t))[0];
867
+ }
868
+ push @tmp, $t;
869
+ }
870
+ $ps->{$k} = \@tmp;
871
+ }
872
+ }
873
+
874
+ # write/read a tag
875
+ sub tag {
876
+ my ($tag, $commit) = @_;
877
+
878
+ if ($opt_o) {
879
+ $tag =~ s|/|--|g;
880
+ } else {
881
+ my $patchname = $tag;
882
+ $patchname =~ s/.*--//;
883
+ $tag = git_branchname ($tag) . '--' . $patchname;
884
+ }
885
+
886
+ if ($commit) {
887
+ open(C,">","$git_dir/refs/tags/$tag")
888
+ or die "Cannot create tag $tag: $!\n";
889
+ print C "$commit\n"
890
+ or die "Cannot write tag $tag: $!\n";
891
+ close(C)
892
+ or die "Cannot write tag $tag: $!\n";
893
+ print " * Created tag '$tag' on '$commit'\n" if $opt_v;
894
+ } else { # read
895
+ open(C,"<","$git_dir/refs/tags/$tag")
896
+ or die "Cannot read tag $tag: $!\n";
897
+ $commit = <C>;
898
+ chomp $commit;
899
+ die "Error reading tag $tag: $!\n" unless length $commit == 40;
900
+ close(C)
901
+ or die "Cannot read tag $tag: $!\n";
902
+ return $commit;
903
+ }
904
+ }
905
+
906
+ # write/read a private tag
907
+ # reads fail softly if the tag isn't there
908
+ sub ptag {
909
+ my ($tag, $commit) = @_;
910
+
911
+ # don't use subdirs for tags yet, it could screw up other porcelains
912
+ $tag =~ s|/|,|g;
913
+
914
+ my $tag_file = "$ptag_dir/$tag";
915
+ my $tag_branch_dir = dirname($tag_file);
916
+ mkpath($tag_branch_dir) unless (-d $tag_branch_dir);
917
+
918
+ if ($commit) { # write
919
+ open(C,">",$tag_file)
920
+ or die "Cannot create tag $tag: $!\n";
921
+ print C "$commit\n"
922
+ or die "Cannot write tag $tag: $!\n";
923
+ close(C)
924
+ or die "Cannot write tag $tag: $!\n";
925
+ $rptags{$commit} = $tag
926
+ unless $tag =~ m/--base-0$/;
927
+ } else { # read
928
+ # if the tag isn't there, return 0
929
+ unless ( -s $tag_file) {
930
+ return 0;
931
+ }
932
+ open(C,"<",$tag_file)
933
+ or die "Cannot read tag $tag: $!\n";
934
+ $commit = <C>;
935
+ chomp $commit;
936
+ die "Error reading tag $tag: $!\n" unless length $commit == 40;
937
+ close(C)
938
+ or die "Cannot read tag $tag: $!\n";
939
+ unless (defined $rptags{$commit}) {
940
+ $rptags{$commit} = $tag;
941
+ }
942
+ return $commit;
943
+ }
944
+ }
945
+
946
+ sub find_parents {
947
+ #
948
+ # Identify what branches are merging into me
949
+ # and whether we are fully merged
950
+ # git-merge-base <headsha> <headsha> should tell
951
+ # me what the base of the merge should be
952
+ #
953
+ my $ps = shift;
954
+
955
+ my %branches; # holds an arrayref per branch
956
+ # the arrayref contains a list of
957
+ # merged patches between the base
958
+ # of the merge and the current head
959
+
960
+ my @parents; # parents found for this commit
961
+
962
+ # simple loop to split the merges
963
+ # per branch
964
+ foreach my $merge (@{$ps->{merges}}) {
965
+ my $branch = git_branchname($merge);
966
+ unless (defined $branches{$branch} ){
967
+ $branches{$branch} = [];
968
+ }
969
+ push @{$branches{$branch}}, $merge;
970
+ }
971
+
972
+ #
973
+ # foreach branch find a merge base and walk it to the
974
+ # head where we are, collecting the merged patchsets that
975
+ # Arch has recorded. Keep that in @have
976
+ # Compare that with the commits on the other branch
977
+ # between merge-base and the tip of the branch (@need)
978
+ # and see if we have a series of consecutive patches
979
+ # starting from the merge base. The tip of the series
980
+ # of consecutive patches merged is our new parent for
981
+ # that branch.
982
+ #
983
+ foreach my $branch (keys %branches) {
984
+
985
+ # check that we actually know about the branch
986
+ next unless -e "$git_dir/refs/heads/$branch";
987
+
988
+ my $mergebase = safe_pipe_capture(qw(git-merge-base), $branch, $ps->{branch});
989
+ if ($?) {
990
+ # Don't die here, Arch supports one-way cherry-picking
991
+ # between branches with no common base (or any relationship
992
+ # at all beforehand)
993
+ warn "Cannot find merge base for $branch and $ps->{branch}";
994
+ next;
995
+ }
996
+ chomp $mergebase;
997
+
998
+ # now walk up to the mergepoint collecting what patches we have
999
+ my $branchtip = git_rev_parse($ps->{branch});
1000
+ my @ancestors = `git-rev-list --topo-order $branchtip ^$mergebase`;
1001
+ my %have; # collected merges this branch has
1002
+ foreach my $merge (@{$ps->{merges}}) {
1003
+ $have{$merge} = 1;
1004
+ }
1005
+ my %ancestorshave;
1006
+ foreach my $par (@ancestors) {
1007
+ $par = commitid2pset($par);
1008
+ if (defined $par->{merges}) {
1009
+ foreach my $merge (@{$par->{merges}}) {
1010
+ $ancestorshave{$merge}=1;
1011
+ }
1012
+ }
1013
+ }
1014
+ # print "++++ Merges in $ps->{id} are....\n";
1015
+ # my @have = sort keys %have; print Dumper(\@have);
1016
+
1017
+ # merge what we have with what ancestors have
1018
+ %have = (%have, %ancestorshave);
1019
+
1020
+ # see what the remote branch has - these are the merges we
1021
+ # will want to have in a consecutive series from the mergebase
1022
+ my $otherbranchtip = git_rev_parse($branch);
1023
+ my @needraw = `git-rev-list --topo-order $otherbranchtip ^$mergebase`;
1024
+ my @need;
1025
+ foreach my $needps (@needraw) { # get the psets
1026
+ $needps = commitid2pset($needps);
1027
+ # git-rev-list will also
1028
+ # list commits merged in via earlier
1029
+ # merges. we are only interested in commits
1030
+ # from the branch we're looking at
1031
+ if ($branch eq $needps->{branch}) {
1032
+ push @need, $needps->{id};
1033
+ }
1034
+ }
1035
+
1036
+ # print "++++ Merges from $branch we want are....\n";
1037
+ # print Dumper(\@need);
1038
+
1039
+ my $newparent;
1040
+ while (my $needed_commit = pop @need) {
1041
+ if ($have{$needed_commit}) {
1042
+ $newparent = $needed_commit;
1043
+ } else {
1044
+ last; # break out of the while
1045
+ }
1046
+ }
1047
+ if ($newparent) {
1048
+ push @parents, $newparent;
1049
+ }
1050
+
1051
+
1052
+ } # end foreach branch
1053
+
1054
+ # prune redundant parents
1055
+ my %parents;
1056
+ foreach my $p (@parents) {
1057
+ $parents{$p} = 1;
1058
+ }
1059
+ foreach my $p (@parents) {
1060
+ next unless exists $psets{$p}{merges};
1061
+ next unless ref $psets{$p}{merges};
1062
+ my @merges = @{$psets{$p}{merges}};
1063
+ foreach my $merge (@merges) {
1064
+ if ($parents{$merge}) {
1065
+ delete $parents{$merge};
1066
+ }
1067
+ }
1068
+ }
1069
+
1070
+ @parents = ();
1071
+ foreach (keys %parents) {
1072
+ push @parents, '-p', ptag($_);
1073
+ }
1074
+ return @parents;
1075
+ }
1076
+
1077
+ sub git_rev_parse {
1078
+ my $name = shift;
1079
+ my $val = safe_pipe_capture(qw(git-rev-parse), $name);
1080
+ die "Error: git-rev-parse $name" if $?;
1081
+ chomp $val;
1082
+ return $val;
1083
+ }
1084
+
1085
+ # resolve a SHA1 to a known patchset
1086
+ sub commitid2pset {
1087
+ my $commitid = shift;
1088
+ chomp $commitid;
1089
+ my $name = $rptags{$commitid}
1090
+ || die "Cannot find reverse tag mapping for $commitid";
1091
+ $name =~ s|,|/|;
1092
+ my $ps = $psets{$name}
1093
+ || (print Dumper(sort keys %psets)) && die "Cannot find patchset for $name";
1094
+ return $ps;
1095
+ }
1096
+
1097
+
1098
+ # an alternative to `command` that allows input to be passed as an array
1099
+ # to work around shell problems with weird characters in arguments
1100
+ sub safe_pipe_capture {
1101
+ my @output;
1102
+ if (my $pid = open my $child, '-|') {
1103
+ @output = (<$child>);
1104
+ close $child or die join(' ',@_).": $! $?";
1105
+ } else {
1106
+ exec(@_) or die "$! $?"; # exec() can fail the executable can't be found
1107
+ }
1108
+ return wantarray ? @output : join('',@output);
1109
+ }
1110
+
1111
+ # `tla logs -rf -d <dir> | head -n1` or `baz tree-id <dir>`
1112
+ sub arch_tree_id {
1113
+ my $dir = shift;
1114
+ chomp( my $ret = (safe_pipe_capture($TLA,'logs','-rf','-d',$dir))[0] );
1115
+ return $ret;
1116
+ }
1117
+
1118
+ sub archive_reachable {
1119
+ my $archive = shift;
1120
+ return 1 if $reachable{$archive};
1121
+ return 0 if $unreachable{$archive};
1122
+
1123
+ if (system "$TLA whereis-archive $archive >/dev/null") {
1124
+ if ($opt_a && (system($TLA,'register-archive',
1125
+ "http://mirrors.sourcecontrol.net/$archive") == 0)) {
1126
+ $reachable{$archive} = 1;
1127
+ return 1;
1128
+ }
1129
+ print STDERR "Archive is unreachable: $archive\n";
1130
+ $unreachable{$archive} = 1;
1131
+ return 0;
1132
+ } else {
1133
+ $reachable{$archive} = 1;
1134
+ return 1;
1135
+ }
1136
+ }