-if test ! -d _darcs -o ! -d compiler; then
- echo "error: darcs-all must be run from the top level of the ghc tree."
- exit 1;
-fi
-
-case $* in
- *-q*) quiet=YES;;
-esac
-
-# --extra says we grab the extra libs with 'get'. It has no effect on
-# the other commands.
-extra=NO
-# --nofib/--testsuite tell get to also grab the respective repos.
-# They have no effect on the other commands.
-nofib=NO
-testsuite=NO
-
-args_done=NO
-
-while [ "$args_done" == NO ]
-do
- case $1 in
- --extra) shift; extra=YES;;
- --nofib) shift; nofib=YES;;
- --testsuite) shift; testsuite=YES;;
- *) args_done=YES;;
- esac
-done
-
-case $1 in
- get) shift; darcsget $*;;
- # Hack around whatsnew failing if there are no changes
- w|wh|wha|what|whats|whatsn|whatsne|whatsnew) set +e; darcsall $*;;
- *) darcsall $*;;
-esac
+sub darcsall {
+ my $localpath;
+ my $path;
+ my $tag;
+
+ open IN, "< packages" or die "Can't open packages file";
+ while (<IN>) {
+ chomp;
+ if (/^([^# ]+) +(?:([^ ]+) +)?([^ ]+) +([^ ]+)$/) {
+ $localpath = $1;
+ $tag = defined($2) ? $2 : "";
+
+ if (-d "$localpath/_darcs") {
+ darcs (@_, "--repodir", $localpath);
+ }
+ elsif ($tag eq "") {
+ message "== Required repo $localpath is missing! Skipping";
+ }
+ else {
+ message "== $localpath repo not present; skipping";
+ }
+ }
+ elsif (! /^(#.*)?$/) {
+ die "Bad line: $_";
+ }
+ }
+ close IN;
+}
+
+sub darcsget {
+ my $r_flags;
+ my $localpath;
+ my $remotepath;
+ my $path;
+ my $tag;
+
+ if (! grep /(?:--complete|--partial)/, @_) {
+ warning("adding --partial, to override use --complete");
+ $r_flags = [@_, "--partial"];
+ }
+ else {
+ $r_flags = \@_;
+ }
+
+ open IN, "< packages" or die "Can't open packages file";
+ while (<IN>) {
+ chomp;
+ if (/^([^ ]+) +(?:([^ ]+) +)?([^ ]+)/) {
+ $localpath = $1;
+ $tag = defined($2) ? $2 : "";
+ $remotepath = $3;
+
+ if ($checked_out_tree) {
+ $path = "$defaultrepo_base/$localpath";
+ }
+ else {
+ $path = "$defaultrepo_base/$remotepath";
+ }
+
+ if (($tag eq "") || defined($tags{$tag})) {
+ if (-d $localpath) {
+ warning("$localpath already present; omitting");
+ }
+ else {
+ darcs (@$r_flags, $path, $localpath);
+ }
+ }
+ }
+ elsif (! /^$/) {
+ die "Bad line: $_";
+ }
+ }
+ close IN;
+}
+
+sub main {
+ if (! -d "_darcs" || ! -d "compiler") {
+ die "error: darcs-all must be run from the top level of the ghc tree."
+ }
+
+ while ($#_ ne -1) {
+ my $arg = shift;
+ # We handle -q here as well as lower down as we need to skip over it
+ # if it comes before the darcs command
+ if ($arg eq "-q") {
+ $verbose = 1;
+ }
+ elsif ($arg eq "-s") {
+ $verbose = 0;
+ }
+ # --dph says we grab the dph libs with 'get'.
+ # It has no effect on the other commands.
+ elsif ($arg eq "--dph") {
+ $tags{"dph"} = 1;
+ }
+ # --extra says we grab the extra libs with 'get'.
+ # It has no effect on the other commands.
+ elsif ($arg eq "--extra") {
+ $tags{"extralibs"} = 1;
+ }
+ # --nofib tells get to also grab the nofib repo.
+ # It has no effect on the other commands.
+ elsif ($arg eq "--nofib") {
+ $tags{"nofib"} = 1;
+ }
+ # --testsuite tells get to also grab the testsuite repo.
+ # It has no effect on the other commands.
+ elsif ($arg eq "--testsuite") {
+ $tags{"testsuite"} = 1;
+ }
+ else {
+ unshift @_, $arg;
+ if (grep /^-q$/, @_) {
+ $verbose = 1;
+ }
+ last;
+ }
+ }
+
+ if ($#_ eq -1) {
+ die "What do you want to do?";
+ }
+ my $command = $_[0];
+ if ($command eq "get") {
+ darcsget @_;
+ }
+ else {
+ if ($command =~ /^(?:w|wh|wha|what|whats|whatsn|whatsne|whatsnew)$/) {
+ # Hack around whatsnew failing if there are no changes
+ $ignore_failure = 1;
+ }
+ darcsall @_;
+ }
+}
+
+main(@ARGV);
+