Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 102 lines (86 sloc) 2.325 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
#!/usr/bin/perl -w

use strict;
use warnings;

# migrate gitosis.conf to gitolite.conf format

# not very smart, but there shouldn't be any errors for simple configurations.
# the biggest thing you'll find is probably some comments rearranged or
# something, due to the "flush" thing below

# for stuff it can't handle, it'll ignore the trivial ones (like gitweb and
# daemon), and put in an obviously syntax error-ed line for "repositories" and
# "map" statements.

my @repos;
my @RO_repos;
my @comments;
my @users;
my $groupname;

# a gitosis.conf stanza ends when a new "[group name]" line shows up, so you
# can't write as you go; you have to accumulate and flush
sub flush {
    die "repos but no users?\n" if (not @users and (@repos or @RO_repos));
    # just a groupname
    if (@users and not (@repos or @RO_repos)) {
        print "\@$groupname = ", join(" ", @users), "\n";
    }
    # RW repos
    if (@repos)
    {
        print "repo ", join(" ", @repos), "\n";
        print " RW = ", join(" ", @users), "\n";
    }
    # RO repos
    if (@RO_repos)
    {
        print "repo ", join(" ", @RO_repos), "\n";
        print " R = ", join(" ", @users), "\n";
    }
    # comments; yes there'll be some reordering, sorry!
    print @comments if @comments;

    # empty out for next round
    @users = ();
    @repos = ();
    @RO_repos = ();
    @comments = ();
}

while (<>)
{
    # pure comment lines or blank lines
    if (/^\s*#/ or /^\s*$/) {
        push @comments, $_;
        next;
    }

    # not supported
    if (/^repositories *=/ or /^map /) {
        print STDERR "not supported: $_";
        s/^/NOT SUPPORTED: /;
        print;
        next;
    }

    chomp;

    # normalise whitespace to help later regexes
    s/\s+/ /g;
    s/ ?= ?/ = /;
    s/^ //;
    s/ $//;

    # the chaff...
    next if /^\[(gitosis|repo)\]$/
            or /^(gitweb|daemon|loglevel|description|owner) =/;

    # the wheat...
    if (/^members = (.*)/) {
        push @users, split(' ', $1);
        next;
    }
    if (/^write?able = (.*)/) {
        push @repos, split(' ', $1);
        next;
    }
    if (/^readonly = (.*)/) {
        push @RO_repos, split(' ', $1);
        next;
    }

    # new group starts
    if (/^\[group (.*?) ?\]/) {
        flush();
        $groupname = $1;
    }
}

flush();
Something went wrong with that request. Please try again.