update submodules for GHC.HetMet.GArrow -> Control.GArrow renaming
[ghc-hetmet.git] / sync-all
index 728c725..ac06af1 100755 (executable)
--- a/sync-all
+++ b/sync-all
@@ -65,13 +65,9 @@ my $defaultrepo;
 my @packages;
 my $verbose = 2;
 my $ignore_failure = 0;
 my @packages;
 my $verbose = 2;
 my $ignore_failure = 0;
-my $want_remote_repo = 0;
 my $checked_out_flag = 0;
 my $get_mode;
 
 my $checked_out_flag = 0;
 my $get_mode;
 
-# Flags specific to a particular command
-my $local_repo_unnecessary = 0;
-
 my %tags;
 
 # Figure out where to get the other repositories from.
 my %tags;
 
 # Figure out where to get the other repositories from.
@@ -146,13 +142,12 @@ sub parsePackages {
     foreach (@repos) {
         chomp;
         $lineNum++;
     foreach (@repos) {
         chomp;
         $lineNum++;
-        if (/^([^# ]+) +([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+)$/) {
+        if (/^([^# ]+) +([^ ]+) +([^ ]+) +([^ ]+)$/) {
             my %line;
             $line{"localpath"}  = $1;
             $line{"tag"}        = $2;
             $line{"remotepath"} = $3;
             $line{"vcs"}        = $4;
             my %line;
             $line{"localpath"}  = $1;
             $line{"tag"}        = $2;
             $line{"remotepath"} = $3;
             $line{"vcs"}        = $4;
-            $line{"upstream"}   = $5;
             push @packages, \%line;
         }
         elsif (! /^(#.*)?$/) {
             push @packages, \%line;
         }
         elsif (! /^(#.*)?$/) {
@@ -195,17 +190,6 @@ sub scm {
     }
 }
 
     }
 }
 
-sub repoexists {
-    my ($scm, $localpath) = @_;
-    
-    if ($scm eq "darcs") {
-        -d "$localpath/_darcs";
-    }
-    else {
-        -d "$localpath/.git";
-    }
-}
-
 sub scmall {
     my $command = shift;
     
 sub scmall {
     my $command = shift;
     
@@ -213,7 +197,6 @@ sub scmall {
     my $tag;
     my $remotepath;
     my $scm;
     my $tag;
     my $remotepath;
     my $scm;
-    my $upstream;
     my $line;
     my $branch_name;
     my $subcommand;
     my $line;
     my $branch_name;
     my $subcommand;
@@ -221,8 +204,6 @@ sub scmall {
     my $path;
     my $wd_before = getcwd;
 
     my $path;
     my $wd_before = getcwd;
 
-    my @scm_args;
-
     my $pwd;
     my @args;
 
     my $pwd;
     my @args;
 
@@ -253,7 +234,7 @@ sub scmall {
         } else {
             $branch_name = shift;
         }
         } else {
             $branch_name = shift;
         }
-    } elsif ($command eq 'new' || $command eq 'fetch') {
+    } elsif ($command eq 'new') {
         if (@_ < 1) {
             $branch_name = 'origin';
         } else {
         if (@_ < 1) {
             $branch_name = 'origin';
         } else {
@@ -265,132 +246,164 @@ sub scmall {
 
     for $line (@packages) {
 
 
     for $line (@packages) {
 
-            $localpath  = $$line{"localpath"};
-            $tag        = $$line{"tag"};
-            $remotepath = $$line{"remotepath"};
-            $scm        = $$line{"vcs"};
-            $upstream   = $$line{"upstream"};
+        $localpath  = $$line{"localpath"};
+        $tag        = $$line{"tag"};
+        $remotepath = $$line{"remotepath"};
+        $scm        = $$line{"vcs"};
 
 
-            # We can't create directories on GitHub, so we translate
-            # "package/foo" into "package-foo".
-            if ($is_github_repo) {
-                $remotepath =~ s/\//-/;
-            }
+        # Check the SCM is OK as early as possible
+        die "Unknown SCM: $scm" if (($scm ne "darcs") and ($scm ne "git"));
 
 
-            # Check the SCM is OK as early as possible
-            die "Unknown SCM: $scm" if (($scm ne "darcs") and ($scm ne "git"));
+        # We can't create directories on GitHub, so we translate
+        # "package/foo" into "package-foo".
+        if ($is_github_repo) {
+            $remotepath =~ s/\//-/;
+        }
 
 
-            # Work out the path for this package in the repo we pulled from
-            if ($checked_out_tree) {
-                $path = "$repo_base/$localpath";
-            }
-            else {
-                $path = "$repo_base/$remotepath";
-            }
+        # Work out the path for this package in the repo we pulled from
+        if ($checked_out_tree) {
+            $path = "$repo_base/$localpath";
+        }
+        else {
+            $path = "$repo_base/$remotepath";
+        }
 
 
-            # Work out the arguments we should give to the SCM
-            if ($command =~ /^(?:w|wh|wha|what|whats|whatsn|whatsne|whatsnew|status)$/) {
-                @scm_args = (($scm eq "darcs" and "whatsnew")
-                          or ($scm eq "git" and "status"));
-                
-                # Hack around 'darcs whatsnew' failing if there are no changes
-                $ignore_failure = 1;
-            }
-            elsif ($command =~ /^commit$/) {
-                @scm_args = ("commit");
-                # git fails if there is nothing to commit, so ignore failures
-                $ignore_failure = 1;
+        if ($command =~ /^(?:g|ge|get)$/) {
+            # Skip any repositories we have not included the tag for
+            if (not defined($tags{$tag})) {
+                $tags{$tag} = 0;
             }
             }
-            elsif ($command =~ /^(?:pus|push)$/) {
-                @scm_args = "push";
-                $want_remote_repo = 1;
+            if ($tags{$tag} == 0) {
+                next;
             }
             }
-            elsif ($command =~ /^(?:pul|pull)$/) {
-                @scm_args = "pull";
-                # Q: should we append the -a argument for darcs repos?
-            }
-            elsif ($command =~ /^(?:g|ge|get)$/) {
-                # Skip any repositories we have not included the tag for
-                if (not defined($tags{$tag})) {
-                    next;
-                }
-                
-                if (-d $localpath) {
-                    warning("$localpath already present; omitting") if $localpath ne ".";
-                    next;
+            
+            if (-d $localpath) {
+                warning("$localpath already present; omitting")
+                    if $localpath ne ".";
+                if ($scm eq "git") {
+                    scm ($localpath, $scm, "config", "core.ignorecase", "true");
                 }
                 }
-                
+                next;
+            }
+
+            # Note that we use "." as the path, as $localpath
+            # doesn't exist yet.
+            if ($scm eq "darcs") {
                 # The first time round the loop, default the get-mode
                 # The first time round the loop, default the get-mode
-                if ($scm eq "darcs" && not defined($get_mode)) {
+                if (not defined($get_mode)) {
                     warning("adding --partial, to override use --complete");
                     $get_mode = "--partial";
                 }
                     warning("adding --partial, to override use --complete");
                     $get_mode = "--partial";
                 }
-                
-                # The only command that doesn't need a repo
-                $local_repo_unnecessary = 1;
-                
-                if ($scm eq "darcs") {
-                    # Note: we can only use the get-mode with darcs for now
-                    @scm_args = ("get", $get_mode, $path, $localpath);
-                }
-                else {
-                    @scm_args = ("clone", $path, $localpath);
-                }
+                scm (".", $scm, "get", $get_mode, $path, $localpath, @args);
             }
             }
-            elsif ($command =~ /^(?:s|se|sen|send)$/) {
-                @scm_args = (($scm eq "darcs" and "send")
-                          or ($scm eq "git" and "send-email"));
-                $want_remote_repo = 1;
-            }
-            elsif ($command =~ /^fetch$/) {
-                @scm_args = ("fetch", "$branch_name");
+            else {
+                scm (".", $scm, "clone", $path, $localpath, @args);
+                scm ($localpath, $scm, "config", "core.ignorecase", "true");
             }
             }
-            elsif ($command =~ /^new$/) {
-                @scm_args = ("log", "$branch_name..");
+            next;
+        }
+
+        if (-d "$localpath/_darcs") {
+            if (-d "$localpath/.git") {
+                die "Found both _darcs and .git in $localpath";
             }
             }
-            elsif ($command =~ /^remote$/) {
-                if ($subcommand eq 'add') {
-                    @scm_args = ("remote", "add", $branch_name, $path);
-                } elsif ($subcommand eq 'rm') {
-                    @scm_args = ("remote", "rm", $branch_name);
-                } elsif ($subcommand eq 'set-url') {
-                    @scm_args = ("remote", "set-url", $branch_name, $path);
-                }
+            $scm = "darcs";
+        } elsif (-d "$localpath/.git") {
+            $scm = "git";
+        } elsif ($tag eq "") {
+            die "Required repo $localpath is missing";
+        } else {
+             message "== $localpath repo not present; skipping";
+             next;
+        }
+
+        # Work out the arguments we should give to the SCM
+        if ($command =~ /^(?:w|wh|wha|what|whats|whatsn|whatsne|whatsnew|status)$/) {
+            if ($scm eq "darcs") {
+                $command = "whatsnew";
             }
             }
-            elsif ($command =~ /^grep$/) {
-              @scm_args = ("grep");
-              # Hack around 'git grep' failing if there are no matches
-              $ignore_failure = 1;
+            elsif ($scm eq "git") {
+                $command = "status";
             }
             else {
             }
             else {
-                die "Unknown command: $command";
-            }
-            
-            # Actually execute the command
-            if (repoexists ($scm, $localpath)) {
-                if ($want_remote_repo) {
-                    if ($scm eq "darcs") {
-                        scm (".", $scm, @scm_args, @args, "--repodir=$localpath", $path);
-                    } else {
-                        # git pull doesn't like to be used with --work-dir
-                        # I couldn't find an alternative to chdir() here
-                        scm ($localpath, $scm, @scm_args, @args, $path, "master");
-                    }
-                } else {
-                    # git status *must* be used with --work-dir, if we don't chdir() to the dir
-                    scm ($localpath, $scm, @scm_args, @args);
-                }
+                die "Unknown scm";
             }
             }
-            elsif ($local_repo_unnecessary) {
-                # Don't bother to change directory in this case
-                scm (".", $scm, @scm_args, @args);
+
+            # Hack around 'darcs whatsnew' failing if there are no changes
+            $ignore_failure = 1;
+            scm ($localpath, $scm, $command, @args);
+        }
+        elsif ($command =~ /^commit$/) {
+            # git fails if there is nothing to commit, so ignore failures
+            $ignore_failure = 1;
+            scm ($localpath, $scm, "commit", @args);
+        }
+        elsif ($command =~ /^(?:pus|push)$/) {
+            scm ($localpath, $scm, "push", @args);
+        }
+        elsif ($command =~ /^(?:pul|pull)$/) {
+            scm ($localpath, $scm, "pull", @args);
+        }
+        elsif ($command =~ /^(?:s|se|sen|send)$/) {
+            if ($scm eq "darcs") {
+                $command = "send";
             }
             }
-            elsif ($tag eq "") {
-                message "== Required repo $localpath is missing! Skipping";
+            elsif ($scm eq "git") {
+                $command = "send-email";
             }
             else {
             }
             else {
-                message "== $localpath repo not present; skipping";
+                die "Unknown scm";
             }
             }
+            scm ($localpath, $scm, $command, @args);
+        }
+        elsif ($command =~ /^fetch$/) {
+            scm ($localpath, $scm, "fetch", @args);
+        }
+        elsif ($command =~ /^new$/) {
+            my @scm_args = ("log", "$branch_name..");
+            scm ($localpath, $scm, @scm_args, @args);
+        }
+        elsif ($command =~ /^log$/) {
+            scm ($localpath, $scm, "log", @args);
+        }
+        elsif ($command =~ /^remote$/) {
+            my @scm_args;
+            if ($subcommand eq 'add') {
+                @scm_args = ("remote", "add", $branch_name, $path);
+            } elsif ($subcommand eq 'rm') {
+                @scm_args = ("remote", "rm", $branch_name);
+            } elsif ($subcommand eq 'set-url') {
+                @scm_args = ("remote", "set-url", $branch_name, $path);
+            }
+            scm ($localpath, $scm, @scm_args, @args);
+        }
+        elsif ($command =~ /^checkout$/) {
+            # Not all repos are necessarily branched, so ignore failure
+            $ignore_failure = 1;
+            scm ($localpath, $scm, "checkout", @args)
+                unless $scm eq "darcs";
+        }
+        elsif ($command =~ /^grep$/) {
+            # Hack around 'git grep' failing if there are no matches
+            $ignore_failure = 1;
+            scm ($localpath, $scm, "grep", @args)
+                unless $scm eq "darcs";
+        }
+        elsif ($command =~ /^clean$/) {
+            scm ($localpath, $scm, "clean", @args)
+                unless $scm eq "darcs";
+        }
+        elsif ($command =~ /^reset$/) {
+            scm ($localpath, $scm, "reset", @args)
+                unless $scm eq "darcs";
+        }
+        elsif ($command =~ /^config$/) {
+            scm ($localpath, $scm, "config", @args)
+                unless $scm eq "darcs";
+        }
+        else {
+            die "Unknown command: $command";
+        }
     }
 }
 
     }
 }
 
@@ -416,7 +429,12 @@ Supported commands:
  * remote add <branch-name>
  * remote rm <branch-name>
  * remote set-url [--push] <branch-name>
  * remote add <branch-name>
  * remote rm <branch-name>
  * remote set-url [--push] <branch-name>
+ * checkout
  * grep
  * grep
+ * clean
+ * reset
+ * config
+ * log
 
 Available package-tags are:
 END
 
 Available package-tags are:
 END
@@ -477,9 +495,11 @@ sub main {
         }
         # --<tag> says we grab the libs tagged 'tag' with
         # 'get'. It has no effect on the other commands.
         }
         # --<tag> says we grab the libs tagged 'tag' with
         # 'get'. It has no effect on the other commands.
-        elsif ($arg =~ m/^--/) {
-            $arg =~ s/^--//;
-            $tags{$arg} = 1;
+        elsif ($arg =~ m/^--no-(.*)$/) {
+            $tags{$1} = 0;
+        }
+        elsif ($arg =~ m/^--(.*)$/) {
+            $tags{$1} = 1;
         }
         else {
             unshift @_, $arg;
         }
         else {
             unshift @_, $arg;