8 # ./sync-all [-q] [-s] [--ignore-failure] [-r repo]
9 # [--nofib] [--testsuite] [--checked-out] cmd [git flags]
11 # Applies the command "cmd" to each repository in the tree.
12 # sync-all will try to do the right thing for both git and darcs repositories.
15 # ./sync-all -r http://darcs.haskell.org/ghc get
16 # To get any repos which do not exist in the local tree
19 # To pull everything from the default repos
21 # -------------- Flags -------------------
22 # -q says to be quite, and -s to be silent.
24 # --ignore-failure says to ignore errors and move on to the next repository
26 # -r repo says to use repo as the location of package repositories
28 # --checked-out says that the remote repo is in checked-out layout, as
29 # opposed to the layout used for the main repo. By default a repo on
30 # the local filesystem is assumed to be checked-out, and repos accessed
31 # via HTTP or SSH are assumed to be in the main repo layout; use
32 # --checked-out to override the latter.
34 # --nofib, --testsuite also get the nofib and testsuite repos respectively
36 # ------------ Which repos to use -------------
37 # sync-all uses the following algorithm to decide which remote repos to use
39 # It always computes the remote repos from a single base, $repo_base
40 # How is $repo_base set?
41 # If you say "-r repo", then that's $repo_base
42 # otherwise $repo_base is set by asking git where the ghc repo came
43 # from, and removing the last component (e.g. /ghc.git/ of /ghc/).
45 # Then sync-all iterates over the package found in the file
46 # ./packages; see that file for a description of the contents.
48 # If $repo_base looks like a local filesystem path, or if you give
49 # the --checked-out flag, sync-all works on repos of form
50 # $repo_base/<local-path>
51 # otherwise sync-all works on repos of form
52 # $repo_base/<remote-path>
53 # This logic lets you say
54 # both sync-all -r http://darcs.haskell.org/ghc-6.12 pull
55 # and sync-all -r ../HEAD pull
56 # The latter is called a "checked-out tree".
58 # NB: sync-all *ignores* the defaultrepo of all repos other than the
59 # root one. So the remote repos must be laid out in one of the two
60 # formats given by <local-path> and <remote-path> in the file 'packages'.
65 my $ignore_failure = 0;
66 my $want_remote_repo = 0;
67 my $checked_out_flag = 0;
70 # Flags specific to a particular command
71 my $local_repo_unnecessary = 0;
75 # Figure out where to get the other repositories from.
80 if (defined($defaultrepo)) {
84 # Figure out where to get the other repositories from,
85 # based on where this GHC repo came from.
86 my $branch = `git branch | grep "\* " | sed "s/^\* //"`; chomp $branch;
87 my $remote = `git config branch.$branch.remote`; chomp $remote;
88 $repo = `git config remote.$remote.url`; chomp $repo;
94 if ($repo =~ /^...*:/) {
96 # Above regex says "at least two chars before the :", to avoid
97 # catching Win32 drives ("C:\").
100 # --checked-out is needed if you want to use a checked-out repo
102 if ($checked_out_flag) {
103 $checked_out_tree = 1;
105 $checked_out_tree = 0;
108 # Don't drop the last part of the path if specified with -r, as
109 # it expects repos of the form:
111 # http://darcs.haskell.org
115 # http://darcs.haskell.org/ghc
118 $repo_base =~ s#/[^/]+/?$##;
121 elsif ($repo =~ /^\/|\.\.\/|.:(\/|\\)/) {
122 # Local filesystem, either absolute or relative path
123 # (assumes a checked-out tree):
125 $checked_out_tree = 1;
128 die "Couldn't work out repo";
131 return $repo_base, $checked_out_tree;
138 open IN, "< packages" or die "Can't open packages file";
147 if (/^([^# ]+) +([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+)$/) {
149 $line{"localpath"} = $1;
151 $line{"remotepath"} = $3;
153 $line{"upstream"} = $5;
154 push @packages, \%line;
156 elsif (! /^(#.*)?$/) {
157 die "Bad content on line $lineNum of packages file: $_";
170 print "warning: @_\n";
180 message "== running $scm @_";
182 message "== $dir: running $scm @_";
187 system ($scm, @_) == 0
189 or die "$scm failed: $?";
197 my ($scm, $localpath) = @_;
199 if ($scm eq "darcs") {
200 -d "$localpath/_darcs";
203 -d "$localpath/.git";
218 my $wd_before = getcwd;
224 my ($repo_base, $checked_out_tree) = getrepo();
228 for $line (@packages) {
230 $localpath = $$line{"localpath"};
231 $tag = $$line{"tag"};
232 $remotepath = $$line{"remotepath"};
233 $scm = $$line{"vcs"};
234 $upstream = $$line{"upstream"};
236 # Check the SCM is OK as early as possible
237 die "Unknown SCM: $scm" if (($scm ne "darcs") and ($scm ne "git"));
239 # Work out the path for this package in the repo we pulled from
240 if ($checked_out_tree) {
241 $path = "$repo_base/$localpath";
244 $path = "$repo_base/$remotepath";
247 # Work out the arguments we should give to the SCM
248 if ($command =~ /^(?:w|wh|wha|what|whats|whatsn|whatsne|whatsnew)$/) {
249 @scm_args = (($scm eq "darcs" and "whatsnew")
250 or ($scm eq "git" and "status"));
252 # Hack around 'darcs whatsnew' failing if there are no changes
255 elsif ($command =~ /^(?:pus|push)$/) {
257 $want_remote_repo = 1;
259 elsif ($command =~ /^(?:pul|pull)$/) {
261 $want_remote_repo = 1;
262 # Q: should we append the -a argument for darcs repos?
264 elsif ($command =~ /^(?:g|ge|get)$/) {
265 # Skip any repositories we have not included the tag for
266 if (not defined($tags{$tag})) {
271 warning("$localpath already present; omitting") if $localpath ne ".";
275 # The first time round the loop, default the get-mode
276 if (not defined($get_mode)) {
277 warning("adding --partial, to override use --complete");
278 $get_mode = "--partial";
281 # The only command that doesn't need a repo
282 $local_repo_unnecessary = 1;
284 if ($scm eq "darcs") {
285 # Note: we can only use the get-mode with darcs for now
286 @scm_args = ("get", $get_mode, $path, $localpath);
289 @scm_args = ("clone", $path, $localpath);
292 elsif ($command =~ /^(?:s|se|sen|send)$/) {
293 @scm_args = (($scm eq "darcs" and "send")
294 or ($scm eq "git" and "send-email"));
295 $want_remote_repo = 1;
297 elsif ($command =~ /^set-origin$/) {
298 @scm_args = ("remote", "set-url", "origin", $path);
300 elsif ($command =~ /^fetch$/) {
301 @scm_args = ("fetch", "origin");
303 elsif ($command =~ /^new$/) {
304 @scm_args = ("log", "origin..");
307 die "Unknown command: $command";
310 # Actually execute the command
311 if (repoexists ($scm, $localpath)) {
312 if ($want_remote_repo) {
313 if ($scm eq "darcs") {
314 scm (".", $scm, @scm_args, @_, "--repodir=$localpath", $path);
316 # git pull doesn't like to be used with --work-dir
317 # I couldn't find an alternative to chdir() here
318 scm ($localpath, $scm, @scm_args, @_, $path, "master");
321 # git status *must* be used with --work-dir, if we don't chdir() to the dir
322 scm ($localpath, $scm, @scm_args, @_);
325 elsif ($local_repo_unnecessary) {
326 # Don't bother to change directory in this case
327 scm (".", $scm, @scm_args, @_);
330 message "== Required repo $localpath is missing! Skipping";
333 message "== $localpath repo not present; skipping";
339 if (! -d ".git" || ! -d "compiler") {
340 die "error: sync-all must be run from the top level of the ghc tree."
348 # We handle -q here as well as lower down as we need to skip over it
349 # if it comes before the source-control command
353 elsif ($arg eq "-s") {
356 elsif ($arg eq "-r") {
357 $defaultrepo = shift;
359 elsif ($arg eq "--ignore-failure") {
362 elsif ($arg eq "--complete" || $arg eq "--partial") {
365 # Use --checked-out if the remote repos are a checked-out tree,
366 # rather than the master trees.
367 elsif ($arg eq "--checked-out") {
368 $checked_out_flag = 1;
370 # --<tag> says we grab the libs tagged 'tag' with
371 # 'get'. It has no effect on the other commands.
372 elsif ($arg =~ m/^--/) {
378 if (grep /^-q$/, @_) {
386 # Get the built in help
388 What do you want to do?
403 Available package-tags are:
406 # Collect all the tags in the packages file
408 open IN, "< packages" or die "Can't open packages file";
411 if (/^([^# ]+) +(?:([^ ]+) +)?([^ ]+) +([^ ]+)/) {
412 if (defined($2) && $2 ne "-") {
413 $available_tags{$2} = 1;
416 elsif (! /^(#.*)?$/) {
422 # Show those tags and the help text
423 my @available_tags = keys %available_tags;
424 print "$help@available_tags\n";
428 # Give the command and rest of the arguments to the main loop