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";
85 my $wd_before = getcwd;
89 open IN, "< packages" or die "Can't open packages file";
92 if (/^([^# ]+) +(?:([^ ]+) +)?([^ ]+) +([^ ]+)$/) {
94 $tag = defined($2) ? $2 : "";
98 # Check the SCM is OK as early as possible
99 die "Unknown SCM: $scm" if (($scm ne "darcs") and ($scm ne "git"));
101 # Work out the path for this package in the repo we pulled from
102 if ($checked_out_tree) {
103 $path = "$defaultrepo_base/$localpath";
106 $path = "$defaultrepo_base/$remotepath";
109 # Work out the arguments we should give to the SCM
110 if ($command =~ /^(?:w|wh|wha|what|whats|whatsn|whatsne|whatsnew)$/) {
111 @scm_args = (($scm eq "darcs" and "whatsnew")
112 or ($scm eq "git" and "status"));
114 # Hack around 'darcs whatsnew' failing if there are no changes
117 elsif ($command =~ /^(?:pus|push)$/) {
120 elsif ($command =~ /^(?:pul|pull)$/) {
122 # Q: should we append the -a argument for darcs repos?
124 elsif ($command =~ /^(?:g|ge|get)$/) {
125 # Skip any repositories we have not included the tag for
126 if (not defined($tags{$tag})) {
131 warning("$localpath already present; omitting") if $localpath ne ".";
135 # The first time round the loop, default the get-mode
136 if (not defined($get_mode)) {
137 warning("adding --partial, to override use --complete");
138 $get_mode = "--partial";
141 # The only command that doesn't need a repo
142 $local_repo_unnecessary = 1;
144 if ($scm eq "darcs") {
145 # Note: we can only use the get-mode with darcs for now
146 @scm_args = ("get", $get_mode, $path, $localpath);
149 @scm_args = ("clone", $path, $localpath);
152 elsif ($command =~ /^(?:s|se|sen|send)$/) {
153 @scm_args = (($scm eq "darcs" and "send")
154 or ($scm eq "git" and "send-email"));
157 die "Unknown command: $command";
160 # Actually execute the command
161 chdir $wd_before or die "Could not change to $wd_before";
162 if (repoexists ($scm, $localpath)) {
163 chdir $localpath or die "Could not change to $localpath";
164 scm ($scm, @scm_args, @_);
166 elsif ($local_repo_unnecessary) {
167 # Don't bother to change directory in this case
168 scm ($scm, @scm_args, @_);
171 message "== Required repo $localpath is missing! Skipping";
174 message "== $localpath repo not present; skipping";
177 elsif (! /^(#.*)?$/) {
185 if (! -d ".git" || ! -d "compiler") {
186 die "error: sync-all must be run from the top level of the ghc tree."
191 # We handle -q here as well as lower down as we need to skip over it
192 # if it comes before the source-control command
196 elsif ($arg eq "-s") {
199 elsif ($arg eq "--ignore-failure") {
202 elsif ($arg eq "--complete" || $arg eq "--partial") {
205 # --<tag> says we grab the libs tagged 'tag' with
206 # 'get'. It has no effect on the other commands.
207 elsif ($arg =~ m/^--/) {
213 if (grep /^-q$/, @_) {
221 # Get the built in help
223 What do you want to do?
235 Available package-tags are:
238 # Collect all the tags in the packages file
240 open IN, "< packages" or die "Can't open packages file";
243 if (/^([^# ]+) +(?:([^ ]+) +)?([^ ]+) +([^ ]+)/) {
245 $available_tags{$2} = 1;
248 elsif (! /^(#.*)?$/) {
254 # Show those tags and the help text
255 my @available_tags = keys %available_tags;
256 print "$help@available_tags";
260 # Give the command and rest of the arguments to the main loop