summaryrefslogtreecommitdiff
path: root/convert-gitosis-conf
diff options
context:
space:
mode:
authorSitaram Chamarty <sitaram@atc.tcs.com>2012-04-09 07:31:33 +0530
committerSitaram Chamarty <sitaram@atc.tcs.com>2012-04-10 15:41:32 +0530
commitbbaacfaee72f1f6b58defa0a0f64a56b504222ec (patch)
tree0bbcea85154d04e3e9804fd256cd78d3e07d2bc3 /convert-gitosis-conf
parentc5e0e929a72d5557c75d150ff72f0a2e189c727d (diff)
(mostly) doc changes
- minor typo fixes, clarifications, etc. - keep sts.html url consistent, because many people link to http://sitaramc.github.com/gitolite/sts.html - create a common migration doc, so the old 'migr.html' does not 404 when g3 docs become "main" - progit doc done - add gitosis convert script (FWIW) - a minor comment fix to Sugar.pm
Diffstat (limited to 'convert-gitosis-conf')
-rwxr-xr-xconvert-gitosis-conf124
1 files changed, 124 insertions, 0 deletions
diff --git a/convert-gitosis-conf b/convert-gitosis-conf
new file mode 100755
index 0000000..999f8f7
--- /dev/null
+++ b/convert-gitosis-conf
@@ -0,0 +1,124 @@
+#!/usr/bin/perl -w
+#
+# migrate gitosis.conf to gitolite.conf format
+#
+# Based on gl-conf-convert by: Sitaram Chamarty
+# Rewritten by: Behan Webster <behanw@websterwood.com>
+#
+
+use strict;
+use warnings;
+
+if (not @ARGV and -t or @ARGV and $ARGV[0] eq '-h') {
+ print "Usage:\n gl-conf-convert < gitosis.conf > gitolite.conf\n(please see the documentation for details)\n";
+ exit 1;
+}
+
+my @comments = ();
+my $groupname;
+my %groups;
+my $reponame;
+my %repos;
+
+while (<>)
+{
+ # not supported
+ if (/^repositories *=/ or /^map /) {
+ print STDERR "not supported: $_";
+ s/^/NOT SUPPORTED: /;
+ print;
+ next;
+ }
+
+ # normalise whitespace to help later regexes
+ chomp;
+ s/\s+/ /g;
+ s/ ?= ?/ = /;
+ s/^ //;
+ s/ $//;
+
+ if (/^\s*$/ and @comments > 1) {
+ @{$repos{$reponame}{comments}} = @comments if $reponame;
+ @{$groups{$groupname}{comments}} = @comments if $groupname;
+ @comments = ();
+ } elsif (/^\s*#/) {
+ push @comments, $_;
+ } elsif (/^\[repo\s+(.*?)\]$/) {
+ $groupname = '';
+ $reponame = $1;
+ $reponame =~ s/\.git$//;
+ } elsif (/^gitweb\s*=\s*yes/i) {
+ push @{$repos{$reponame}{R}}, 'gitweb';
+ } elsif (/^daemon\s*=\s*yes/i) {
+ push @{$repos{$reponame}{R}}, 'daemon';
+ } elsif (/^description\s*=\s*(.+?)$/) {
+ $repos{$reponame}{desc} = $1;
+ } elsif (/^owner\s*=\s*(.+?)$/) {
+ $repos{$reponame}{owner} = $1;
+ } elsif (/^\[group\s+(.*)\]$/) {
+ $reponame = '';
+ $groupname = $1;
+ } elsif (/^members\s*=\s*(.*)/) {
+ push @{$groups{$groupname}{users}}, map {s/\@([^.]+)$/_$1/g; $_} split(' ', $1);
+ } elsif (/^write?able\s*=\s*(.*)/) {
+ foreach my $repo (split(' ', $1)) {
+ $repo =~ s/\.git$//;
+ push @{$repos{$repo}{RW}}, "\@$groupname";
+ }
+ } elsif (/^readonly\s*=\s*(.*)/) {
+ foreach my $repo (split(' ', $1)) {
+ $repo =~ s/\.git$//;
+ push @{$repos{$repo}{R}}, "\@$groupname";
+ }
+ }
+}
+
+#use Data::Dumper;
+#print Dumper(\%repos);
+#print Dumper(\%groups);
+
+# Groups
+print "#\n# Groups\n#\n\n";
+foreach my $grp (sort keys %groups) {
+ next unless @{$groups{$grp}{users}};
+ printf join("\n", @{$groups{$grp}{comments}})."\n" if $groups{$grp}{comments};
+ printf "\@%-19s = %s\n", $grp, join(' ', @{$groups{$grp}{users}});
+}
+
+# Gitweb
+print "\n#\n# Gitweb\n#\n\n";
+foreach my $repo (sort keys %repos) {
+ if ($repos{$repo}{desc}) {
+ @{$repos{$repo}{R}} = grep(!/^gitweb$/, @{$repos{$repo}{R}});
+ print $repo;
+ print " \"$repos{$repo}{owner}\"" if $repos{$repo}{owner};
+ print " = \"$repos{$repo}{desc}\"\n";
+ }
+}
+
+# Repos
+print "\n#\n# Repos\n#\n";
+foreach my $repo (sort keys %repos) {
+ print "\n";
+ printf join("\n", @{$repos{$repo}{comments}})."\n" if $repos{$repo}{comments};
+ #if ($repos{$repo}{desc}) {
+ # @{$repos{$repo}{R}} = grep(!/^gitweb$/, @{$repos{$repo}{R}});
+ #}
+ print "repo\t$repo\n";
+ foreach my $access (qw(RW+ RW R)) {
+ next unless $repos{$repo}{$access};
+ my @keys;
+ foreach my $key (@{$repos{$repo}{$access}}) {
+ if ($key =~ /^\@(.*)/) {
+ next unless defined $groups{$1} and @{$groups{$1}{users}};
+ }
+ push @keys, $key;
+ }
+ printf "\t$access\t= %s\n", join(' ', @keys) if @keys;
+ }
+ #if ($repos{$repo}{desc}) {
+ # print $repo;
+ # print " \"$repos{$repo}{owner}\"" if $repos{$repo}{owner};
+ # print " = \"$repos{$repo}{desc}\"\n";
+ #}
+}