From 760bf91df2a052c0f4473cb45a5ffce01d856a1f Mon Sep 17 00:00:00 2001
From: Spiridon Eliopoulos <seliopou@gmail.com>
Date: Wed, 15 Jul 2009 22:23:20 -0400
Subject: [PATCH] Add -r repo option to darcs-all

Use the -r option to specify the repository darcs-all should use to fetch
GHC's dependencies.
---
 darcs-all |   70 +++++++++++++++++++++++++++++++++++-------------------------
 1 files changed, 41 insertions(+), 29 deletions(-)

diff --git a/darcs-all b/darcs-all
index e8a1139..75cfeaf 100755
--- a/darcs-all
+++ b/darcs-all
@@ -4,14 +4,15 @@ use strict;
 
 # Usage:
 #
-# ./darcs-all [-q] [-s] [--nofib] [--testsuite] get [darcs get flags]
+# ./darcs-all [-q] [-s] [-r repo] [--nofib] [--testsuite] get [darcs get flags]
 #   This gets the GHC core repos, if they do not already exist.
 #   -q says to be quite, and -s to be silent.
+#   -r repo says to use repo as the location of package repositories
 #   --nofib, --testsuite also get the nofib and testsuite repos respectively
 #   The darcs get flag you are most likely to want is --complete. By
 #   default we pass darcs the --partial flag.
 #
-# ./darcs-all [-q] [-s] cmd [darcs cmd flags]
+# ./darcs-all [-q] [-s] [-r repo] cmd [darcs cmd flags]
 #   This runs the darcs "cmd" command, with any flags you give, in all
 #   of the repos you have checked out. e.g.
 #       ./darcs-all pull
@@ -20,36 +21,42 @@ use strict;
 
 $| = 1; # autoflush stdout after each print, to avoid output after die
 
-# Figure out where to get the other repositories from,
-# based on where this GHC repo came from.
-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 $defaultrepo;
 
 my $verbose = 2;
 my $ignore_failure = 0;
 
 my %tags;
 
+# Figure out where to get the other repositories from.
+sub getrepo {
+    my $repo = $defaultrepo || `cat _darcs/prefs/defaultrepo`;
+    chomp $repo;
+
+    my $repo_base;
+    my $checked_out_tree;
+
+    if ($repo =~ /^...*:/) {
+        # HTTP or SSH
+        # Above regex says "at least two chars before the :", to avoid
+        # catching Win32 drives ("C:\").
+        $repo_base = $repo;
+        $repo_base =~ s#/[^/]+/?$##;
+        $checked_out_tree = 0;
+    }
+    elsif ($repo =~ /^\/|\.\.\/|.:(\/|\\)/) {
+        # Local filesystem, either absolute or relative path
+        # (assumes a checked-out tree):
+        $repo_base = $repo;
+        $checked_out_tree = 1;
+    }
+    else {
+        die "Couldn't work out repo";
+    }
+
+    return $repo_base, $checked_out_tree;
+}
+
 sub message {
     if ($verbose >= 2) {
         print "@_\n";
@@ -109,6 +116,8 @@ sub darcsget {
     my $tag;
     my @repos;
 
+    my ($repo_base, $checked_out_tree) = getrepo();
+
     if (! grep /(?:--complete|--partial)/, @_) {
         warning("adding --partial, to override use --complete");
         $r_flags = [@_, "--partial"];
@@ -129,14 +138,14 @@ sub darcsget {
             $remotepath = $3;
 
             if ($checked_out_tree) {
-                $path = "$defaultrepo_base/$localpath";
+                $path = "$repo_base/$localpath";
             }
             else {
                 if ($remotepath =~ /^http:/) {
                     $path = $remotepath;
                 }
                 else {
-                    $path = "$defaultrepo_base/$remotepath";
+                    $path = "$repo_base/$remotepath";
                 }
             }
 
@@ -156,7 +165,7 @@ sub darcsget {
 }
 
 sub main {
-    if (! -d "_darcs" || ! -d "compiler") {
+    if (! -d "compiler") {
         die "error: darcs-all must be run from the top level of the ghc tree."
     }
 
@@ -170,6 +179,9 @@ sub main {
         elsif ($arg eq "-s") {
             $verbose = 0;
         }
+        elsif ($arg eq "-r") {
+            $defaultrepo = shift;
+        }
         # --nofib tells get to also grab the nofib repo.
         # It has no effect on the other commands.
         elsif ($arg eq "--nofib") {
-- 
1.6.1

