push-all 2.67 KB
Newer Older
Ian Lynagh's avatar
Ian Lynagh committed
1 2 3 4 5 6 7 8 9 10 11
#!/usr/bin/perl -w

use strict;

my $reporoot;

my $verbose = 1;
my $ignore_failure = 0;

# --checked-out says we are pushing to a checked out tree
my $checked_out = 0;
12 13
# --push or --pull or --send?
my $push_pull_send = "push";
Ian Lynagh's avatar
Ian Lynagh committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

sub message {
    if ($verbose) {
        print "@_\n";
    }
}

sub warning {
    print "warning: @_\n";
}

sub darcs {
    message "== running darcs @_";
    system ("darcs", @_) == 0
        or $ignore_failure
        or die "darcs failed: $?";
}

sub darcs_push {
33
    darcs ($push_pull_send, "--no-set-default", @_);
Ian Lynagh's avatar
Ian Lynagh committed
34 35 36 37
}

sub pushall {
    my $dir;
38 39 40 41
    my $localpath;
    my $remotepath;
    my $path;
    my $tag;
42
    
43 44 45
    open IN, "< packages" or die "Can't open packages file";
    while (<IN>) {
        chomp;
46
        if (/^([^# ]+) +(?:([^ ]+) +)?([^ ]+) +([^ ]+)$/) {
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
            $localpath = $1;
            $tag = defined($2) ? $2 : "";
            $remotepath = $3;

            if ($checked_out) {
                $path = "$reporoot/$localpath";
            }
            else {
                $path = "$reporoot/$remotepath";
            }

            if (-d "$localpath/_darcs") {
                darcs_push ($path, @_, "--repodir", $localpath);
            }
            elsif ($tag eq "") {
                message "== Required repo $localpath is missing! Skipping";
            }
            else {
                message "== $localpath repo not present; skipping";
            }
Ian Lynagh's avatar
Ian Lynagh committed
67
        }
68 69 70
        elsif (! /^(#.*)?$/) {
            die "Bad line: $_";
        }
Ian Lynagh's avatar
Ian Lynagh committed
71
    }
72
    close IN;
Ian Lynagh's avatar
Ian Lynagh committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
}

sub main {
    if (! -d "_darcs" || ! -d "compiler") {
        die "error: darcs-all must be run from the top level of the ghc tree."
    }

    if ($#_ ne -1) {
        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 = 0;
            }
88 89 90
            elsif ($arg eq "--ignore-failure") {
                $ignore_failure = 1;
            }
Ian Lynagh's avatar
Ian Lynagh committed
91 92 93
            elsif ($arg eq "--checked-out") {
                $checked_out = 1;
            }
94
            elsif ($arg eq "--push") {
95
                $push_pull_send = "push";
96 97
            }
            elsif ($arg eq "--pull") {
98 99 100 101
                $push_pull_send = "pull";
            }
            elsif ($arg eq "--send") {
                $push_pull_send = "send";
102
            }
Ian Lynagh's avatar
Ian Lynagh committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
            else {
                $reporoot = $arg;
                if (grep /^-q$/, @_) {
                    $verbose = 0;
                }
                last;
            }
        }
    }
    else {
        die "Where do you want to push to?";
    }

    pushall (@_);
}

main(@ARGV);