Follow darcs-all changes in push-all
[ghc-hetmet.git] / push-all
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 my $reporoot;
6
7 my $verbose = 1;
8 my $ignore_failure = 0;
9
10 # --checked-out says we are pushing to a checked out tree
11 my $checked_out = 0;
12 # --push or --pull or --send?
13 my $push_pull_send = "push";
14
15 sub message {
16     if ($verbose) {
17         print "@_\n";
18     }
19 }
20
21 sub warning {
22     print "warning: @_\n";
23 }
24
25 sub darcs {
26     message "== running darcs @_";
27     system ("darcs", @_) == 0
28         or $ignore_failure
29         or die "darcs failed: $?";
30 }
31
32 sub darcs_push {
33     darcs ($push_pull_send, "--no-set-default", @_);
34 }
35
36 sub pushall {
37     my $dir;
38     my $localpath;
39     my $remotepath;
40     my $path;
41     my $tag;
42     my $ghcrepo = $checked_out ? $reporoot : "$reporoot/ghc";
43     darcs_push ($ghcrepo, @_);
44
45     open IN, "< packages" or die "Can't open packages file";
46     while (<IN>) {
47         chomp;
48         if (/^([^ ]+) +(?:([^ ]+) +)?([^ ]+)/) {
49             $localpath = $1;
50             $tag = defined($2) ? $2 : "";
51             $remotepath = $3;
52
53             if ($checked_out) {
54                 $path = "$reporoot/$localpath";
55             }
56             else {
57                 $path = "$reporoot/$remotepath";
58             }
59
60             if (-d "$localpath/_darcs") {
61                 darcs_push ($path, @_, "--repodir", $localpath);
62             }
63             elsif ($tag eq "") {
64                 message "== Required repo $localpath is missing! Skipping";
65             }
66             else {
67                 message "== $localpath repo not present; skipping";
68             }
69         }
70     }
71     close IN;
72 }
73
74 sub main {
75     if (! -d "_darcs" || ! -d "compiler") {
76         die "error: darcs-all must be run from the top level of the ghc tree."
77     }
78
79     if ($#_ ne -1) {
80         while ($#_ ne -1) {
81             my $arg = shift;
82             # We handle -q here as well as lower down as we need to skip
83             # over it if it comes before the darcs command
84             if ($arg eq "-q") {
85                 $verbose = 0;
86             }
87             elsif ($arg eq "--ignore-failure") {
88                 $ignore_failure = 1;
89             }
90             elsif ($arg eq "--checked-out") {
91                 $checked_out = 1;
92             }
93             elsif ($arg eq "--push") {
94                 $push_pull_send = "push";
95             }
96             elsif ($arg eq "--pull") {
97                 $push_pull_send = "pull";
98             }
99             elsif ($arg eq "--send") {
100                 $push_pull_send = "send";
101             }
102             else {
103                 $reporoot = $arg;
104                 if (grep /^-q$/, @_) {
105                     $verbose = 0;
106                 }
107                 last;
108             }
109         }
110     }
111     else {
112         die "Where do you want to push to?";
113     }
114
115     pushall (@_);
116 }
117
118 main(@ARGV);
119