-defaultrepo=`cat _darcs/prefs/defaultrepo`
-case $defaultrepo in
- http://* | *@*:*)
- defaultrepo_lib=`echo $defaultrepo | sed 's!/ghc$!!'`/packages;;
- /*)
- defaultrepo_lib=$defaultrepo/libraries;;
-esac
-
-quiet=NO
-
-message()
-{
- if [ "$quiet" = "NO" ]; then
- echo $*
- fi
+my $defaultrepo = `cat _darcs/prefs/defaultrepo`;
+chomp $defaultrepo;
+my $defaultrepo_base;
+my $checked_out_tree;
+
+if ($defaultrepo =~ /^...*:/) {
+ # HTTP or SSH
+ # Above regex says "at least two chars before the :", to avoid
+ # catching Win32 drives ("C:\").
+ $defaultrepo_base = $defaultrepo;
+ $defaultrepo_base =~ s#/[^/]+/?$##;
+ $checked_out_tree = 0;
+}
+elsif ($defaultrepo =~ /^\/|\.\.\/|.:(\/|\\)/) {
+ # Local filesystem, either absolute or relative path
+ # (assumes a checked-out tree):
+ $defaultrepo_base = $defaultrepo;
+ $checked_out_tree = 1;
+}
+else {
+ die "Couldn't work out defaultrepo";
+}
+
+my $verbose = 2;
+my $ignore_failure = 0;
+
+my %tags;
+
+sub message {
+ if ($verbose >= 2) {
+ print "@_\n";
+ }
+}
+
+sub warning {
+ if ($verbose >= 1) {
+ print "warning: @_\n";
+ }
+}
+
+sub darcs {
+ message "== running darcs @_";
+ system ("darcs", @_) == 0
+ or $ignore_failure
+ or die "darcs failed: $?";
+}
+
+sub darcsall {
+ my $localpath;
+ my $path;
+ my $tag;
+ my @repos;
+
+ open IN, "< packages" or die "Can't open packages file";
+ @repos = <IN>;
+ close IN;
+
+ foreach (@repos) {
+ 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: $_";
+ }
+ }