6 # Figure out where to get the other repositories from,
7 # based on where this GHC repo came from.
8 my $branch = `git branch | grep "\* " | sed "s/^\* //"`; chomp $branch;
9 my $remote = `git config branch.$branch.remote`; chomp $remote;
10 my $defaultrepo = `git config remote.$remote.url`; chomp $defaultrepo;
15 if ($defaultrepo =~ /^...*:/) {
17 # Above regex says "at least two chars before the :", to avoid
18 # catching Win32 drives ("C:\").
19 $defaultrepo_base = $defaultrepo;
20 $defaultrepo_base =~ s#/[^/]+/?$##;
21 $checked_out_tree = 0;
23 elsif ($defaultrepo =~ /^\/|\.\.\/|.:(\/|\\)/) {
24 # Local filesystem, either absolute or relative path
25 # (assumes a checked-out tree):
26 $defaultrepo_base = $defaultrepo;
27 $checked_out_tree = 1;
30 die "Couldn't work out defaultrepo";
36 # Flags specific to a particular command
37 my $ignore_failure = 0;
38 my $local_repo_unnecessary = 0;
40 # Always define the empty tag so that we fetch the /required/ packages
52 print "warning: @_\n";
59 message "== running $scm @_";
60 system ($scm, @_) == 0
62 or die "$scm failed: $?";
66 my ($scm, $localpath) = @_;
68 if ($scm eq "darcs") {
69 -d "$localpath/_darcs";
86 my $wd_before = getcwd;
90 open IN, "< packages" or die "Can't open packages file";
93 if (/^([^# ]+) +(?:([^ ]+) +)?([^ ]+) +([^ ]+) +([^ ]+)$/) {
95 $tag = defined($2) ? $2 : "";
100 # Check the SCM is OK as early as possible
101 die "Unknown SCM: $scm" if (($scm ne "darcs") and ($scm ne "git"));
103 # Work out the path for this package in the repo we pulled from
104 if ($checked_out_tree) {
105 $path = "$defaultrepo_base/$localpath";
108 $path = "$defaultrepo_base/$remotepath";
111 # Work out the arguments we should give to the SCM
112 if ($command =~ /^(?:w|wh|wha|what|whats|whatsn|whatsne|whatsnew)$/) {
113 @scm_args = (($scm eq "darcs" and "whatsnew")
114 or ($scm eq "git" and "status"));
116 # Hack around 'darcs whatsnew' failing if there are no changes
119 elsif ($command =~ /^(?:pus|push)$/) {
122 elsif ($command =~ /^(?:pul|pull)$/) {
124 # Q: should we append the -a argument for darcs repos?
126 elsif ($command =~ /^(?:g|ge|get)$/) {
127 # Skip any repositories we have not included the tag for
128 if (not defined($tags{$tag})) {
133 warning("$localpath already present; omitting") if $localpath ne ".";
137 # The first time round the loop, default the get-mode
138 if (not defined($get_mode)) {
139 warning("adding --partial, to override use --complete");
140 $get_mode = "--partial";
143 # The only command that doesn't need a repo
144 $local_repo_unnecessary = 1;
146 if ($scm eq "darcs") {
147 # Note: we can only use the get-mode with darcs for now
148 @scm_args = ("get", $get_mode, $path, $localpath);
151 @scm_args = ("clone", $path, $localpath);
154 elsif ($command =~ /^(?:s|se|sen|send)$/) {
155 @scm_args = (($scm eq "darcs" and "send")
156 or ($scm eq "git" and "send-email"));
159 die "Unknown command: $command";
162 # Actually execute the command
163 chdir $wd_before or die "Could not change to $wd_before";
164 if (repoexists ($scm, $localpath)) {
165 chdir $localpath or die "Could not change to $localpath";
166 scm ($scm, @scm_args, @_);
168 elsif ($local_repo_unnecessary) {
169 # Don't bother to change directory in this case
170 scm ($scm, @scm_args, @_);
173 message "== Required repo $localpath is missing! Skipping";
176 message "== $localpath repo not present; skipping";
179 elsif (! /^(#.*)?$/) {
187 if (! -d ".git" || ! -d "compiler") {
188 die "error: sync-all must be run from the top level of the ghc tree."
193 # We handle -q here as well as lower down as we need to skip over it
194 # if it comes before the source-control command
198 elsif ($arg eq "-s") {
201 elsif ($arg eq "--ignore-failure") {
204 elsif ($arg eq "--complete" || $arg eq "--partial") {
207 # --<tag> says we grab the libs tagged 'tag' with
208 # 'get'. It has no effect on the other commands.
209 elsif ($arg =~ m/^--/) {
215 if (grep /^-q$/, @_) {
223 # Get the built in help
225 What do you want to do?
237 Available package-tags are:
240 # Collect all the tags in the packages file
242 open IN, "< packages" or die "Can't open packages file";
245 if (/^([^# ]+) +(?:([^ ]+) +)?([^ ]+) +([^ ]+)/) {
247 $available_tags{$2} = 1;
250 elsif (! /^(#.*)?$/) {
256 # Show those tags and the help text
257 my @available_tags = keys %available_tags;
258 print "$help@available_tags";
262 # Give the command and rest of the arguments to the main loop