From d88cdbefd644185a332f5854f027780cb8ceca30 Mon Sep 17 00:00:00 2001 From: Sitaram Chamarty Date: Thu, 8 Mar 2012 15:06:05 +0530 Subject: [PATCH] 'gitolite list-users' added (but see warnings) this is pretty slow if you have thousands of repos, since it has to read and parse a 'gl-conf' file for every repo. (For example, on a Lenovo X201 thinkpad with 11170 repos and a cold cache, it took 288 seconds). (With a hot cache -- like if you run the command again -- it took 2.1 seconds! So if you have a fast disk this may not be an issue for you even if you have 10,000+ repos). --- Gitolite/Conf/Load.pm | 38 ++++++++++++++++++++++++++++++++++++++ gitolite | 9 +++++++++ 2 files changed, 47 insertions(+) diff --git a/Gitolite/Conf/Load.pm b/Gitolite/Conf/Load.pm index 34b6a1e..c9b09b5 100644 --- a/Gitolite/Conf/Load.pm +++ b/Gitolite/Conf/Load.pm @@ -8,6 +8,7 @@ package Gitolite::Conf::Load; access list_groups + list_users ); use Exporter 'import'; @@ -188,5 +189,42 @@ sub list_groups { return (sort_u(\@g)); } +sub list_users { + my $count = 0; + my $total = 0; + + die "\nUsage: gitolite list-users\n\n - no options, no flags\n - may be slow if you have thousands of repos\n\n" if @ARGV; + + load_common(); + + my @u = map { keys %{ $_ } } values %repos; + $total = scalar(keys %split_conf); + warn "WARNING: you have $total repos to check; this could take some time!\n" if $total > 100; + for my $one ( keys %split_conf ) { + load_1($one); + $count++; print STDERR "$count / $total\r" if not ( $count % 100 ) and timer(5); + push @u, map { keys %{ $_ } } values %one_repo; + } + print STDERR "\n"; + return (sort_u(\@u)); +} + +# ---------------------------------------------------------------------- + +{ + my $start_time = 0; + + sub timer { + unless ($start_time) { + $start_time = time(); + return 0; + } + my $elapsed = shift; + return 0 if time() - $start_time < $elapsed; + $start_time = time(); + return 1; + } +} + 1; diff --git a/gitolite b/gitolite index 43868a5..fb835e2 100755 --- a/gitolite +++ b/gitolite @@ -12,6 +12,10 @@ The following subcommands are available; they should all respond to '-h': compile compile gitolite.conf query-rc get values of rc variables list-groups list all group names in conf + list-users list all user names in conf + +Warnings: + - list-users is disk bound and could take a while on sites with thousands of repos =cut # ---------------------------------------------------------------------- @@ -56,5 +60,10 @@ sub args { require Gitolite::Conf::Load; Gitolite::Conf::Load->import; print "$_\n" for ( @{ list_groups() } ); + } elsif ( $command eq 'list-users' ) { + shift @ARGV; + require Gitolite::Conf::Load; + Gitolite::Conf::Load->import; + print "$_\n" for ( @{ list_users() } ); } }