From 2b066fc9f07e4aab228082d3420f718991a63f77 Mon Sep 17 00:00:00 2001 From: Sitaram Chamarty Date: Tue, 24 Aug 2010 13:34:27 +0530 Subject: [PATCH] info/expand print better(?) permission codes see doc/report-output.mkd for details --- src/gitolite.pm | 21 +++++++++++++++++---- t/t50-sequence-test | 4 ++-- t/t53-check-info-expand-output | 12 ++++++------ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/gitolite.pm b/src/gitolite.pm index e78c882..d1f915c 100644 --- a/src/gitolite.pm +++ b/src/gitolite.pm @@ -518,6 +518,19 @@ sub report_version { system("cat", ($GL_PACKAGE_CONF || "$GL_ADMINDIR/conf") . "/VERSION"); } +sub perm_code { + # print the permission code + my($all, $super, $user, $x) = @_; + return " " unless $all or $super or $user; + return " $x " unless $all or $super; # only $user (explicit access) was given + my $ret; + $ret = " \@$x" if $all; # prefix @ if repo allows access for @all users + $ret = " \#$x" if $super; # prefix # if user has access to @all repos (sort of like a super user) + $ret = " \&$x" if $all and $super; # prefix & if both the above + $ret .= ($user ? " " : "_" ); # suffix _ if no explicit access else + return $ret; +} + # basic means wildcards will be shown as wildcards; this is pretty much what # got parsed by the compile script sub report_basic @@ -551,8 +564,8 @@ sub report_basic # #R => you're a super user and can see @all repos # R => normal access my $perm .= ( $repos{$r}{C}{'@all'} ? ' @C' : ( $repos{$r}{C}{$user} ? ' C' : ' ' ) ); - $perm .= ( $repos{$r}{R}{'@all'} ? ' @R' : ( $repos{'@all'}{R}{$user} ? ' #R' : ( $repos{$r}{R}{$user} ? ' R' : ' ' ))); - $perm .= ( $repos{$r}{W}{'@all'} ? ' @W' : ( $repos{'@all'}{W}{$user} ? ' #W' : ( $repos{$r}{W}{$user} ? ' W' : ' ' ))); + $perm .= &perm_code( $repos{$r}{R}{'@all'}, $repos{'@all'}{R}{$user}, $repos{$r}{R}{$user}, 'R'); + $perm .= &perm_code( $repos{$r}{W}{'@all'}, $repos{'@all'}{W}{$user}, $repos{$r}{W}{$user}, 'W'); print "$perm\t$r\r\n" if $perm =~ /\S/; } print "only 20 out of $count candidate repos examined\r\nplease use a partial reponame or regex pattern to limit output\r\n" if $GL_BIG_CONFIG and $count > 20; @@ -648,8 +661,8 @@ sub expand_wild delete $repos{$repo} if $perm !~ /C/ and $wild; $creator = ""; } - $perm .= ( $repos{$repo}{R}{'@all'} ? ' @R' : ( $repos{'@all'}{R}{$ENV{GL_USER}} ? ' #R' : ( $repos{$repo}{R}{$ENV{GL_USER}} ? ' R' : ' ' ))); - $perm .= ( $repos{$repo}{W}{'@all'} ? ' @W' : ( $repos{'@all'}{W}{$ENV{GL_USER}} ? ' #W' : ( $repos{$repo}{W}{$ENV{GL_USER}} ? ' W' : ' ' ))); + $perm .= &perm_code( $repos{$repo}{R}{'@all'}, $repos{'@all'}{R}{$ENV{GL_USER}}, $repos{$repo}{R}{$ENV{GL_USER}}, 'R' ); + $perm .= &perm_code( $repos{$repo}{W}{'@all'}, $repos{'@all'}{W}{$ENV{GL_USER}}, $repos{$repo}{W}{$ENV{GL_USER}}, 'W' ); # set up for caching %repos $last_repo = $repo; diff --git a/t/t50-sequence-test b/t/t50-sequence-test index f90518d..8326c3c 100644 --- a/t/t50-sequence-test +++ b/t/t50-sequence-test @@ -33,7 +33,7 @@ do expect "RW u2" name "expand" runlocal ssh u2 expand - expect "R W.(u1).foo/u1/bar" + expect "R W .(u1).foo/u1/bar" name "push" cd ~/td @@ -80,7 +80,7 @@ do expect "RW u2" name "expand" runlocal ssh u2 expand - expect "R W.(u1).foo/u1/bar" + expect " R W .(u1).foo/u1/bar" name "push" cd ~/td diff --git a/t/t53-check-info-expand-output b/t/t53-check-info-expand-output index 563d4bd..1d3bc28 100644 --- a/t/t53-check-info-expand-output +++ b/t/t53-check-info-expand-output @@ -36,17 +36,17 @@ do name "u1 info" runlocal ssh u1 info expect "hello u1, the gitolite version here is" - expect "@R.*@W.*testing" - [ "$wr" = "1" ] && [ "$bc" = "0" ] && expect "C.*R.*W.*foo/u1/\\.\\+" - [ "$wr" = "1" ] && [ "$bc" = "1" ] && notexpect "C.*R.*W.*foo/u1/\\.\\+" - [ "$wr" = "1" ] && [ "$bc" = "1" ] && expect "C.*@gfoo" + expect " @R_ @W_.testing" + [ "$wr" = "1" ] && [ "$bc" = "0" ] && expect " C R W .foo/u1/\\.\\+" + [ "$wr" = "1" ] && [ "$bc" = "1" ] && notexpect " C R W .foo/u1/\\.\\+" + [ "$wr" = "1" ] && [ "$bc" = "1" ] && expect " C .@gfoo" name "u1 expand" runlocal ssh u1 expand [ "$wr" = "0" ] && expect "wildrepos disabled, sorry" [ "$wr" = "1" ] && expect "hello u1, the gitolite version here is" - [ "$wr" = "1" ] && expect "R.*W.*(u1).*foo/u1/bar" - [ "$wr" = "1" ] && expect "@R.*@W.*testing" + [ "$wr" = "1" ] && expect " R W .(u1).foo/u1/bar" + [ "$wr" = "1" ] && expect "@R_ @W_..gitolite..testing" name INTERNAL done