Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
sync-all 21.01 KiB
#!/usr/bin/perl -w

use strict;
use Cwd;

$| = 1; # autoflush stdout after each print, to avoid output after die

my $defaultrepo;
my @packages;
my $verbose = 2;
my $try_to_resume = 0;
my $ignore_failure = 0;
my $checked_out_flag = 0; # NOT the opposite of bare_flag (describes remote repo state)
my $get_mode;
my $bare_flag = ""; # NOT the opposite of checked_out_flag (describes local repo state)

my %tags;

# Figure out where to get the other repositories from.
sub getrepo {
    my $repo;

    if (defined($defaultrepo)) {
        $repo = $defaultrepo;
        chomp $repo;
    } else {
        # Figure out where to get the other repositories from,
        # based on where this GHC repo came from.
        my $git_dir = $bare_flag ? "--git-dir=ghc.git" : "";
        my $branch  = `git $git_dir branch | grep "\* " | sed "s/^\* //"`; chomp $branch;
        my $remote  = `git $git_dir config branch.$branch.remote`;         chomp $remote;
        if ($remote eq "") {
            # remotes are not mandatory for branches (e.g. not recorded by default for bare repos)
            $remote = "origin";
        }
        $repo       = `git $git_dir config remote.$remote.url`;            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;

        # --checked-out is needed if you want to use a checked-out repo
        # over SSH or HTTP
        if ($checked_out_flag) {
            $checked_out_tree = 1;
        } else {
            $checked_out_tree = 0;
        }

        # Don't drop the last part of the path if specified with -r, as
        # it expects repos of the form:
        #
        #   http://darcs.haskell.org
        #
        # rather than
        #   
        #   http://darcs.haskell.org/ghc
        #
        if (!$defaultrepo) {
            $repo_base =~ s#/[^/]+/?$##;
        }
    }
    elsif ($repo =~ /^\/|\.\.\/|.:(\/|\\)/) {
        # Local filesystem, either absolute (C:/ or /) or relative (../) path