From 3a8f32ac9bf47c9f1372e589e5e35124fae06a94 Mon Sep 17 00:00:00 2001 From: Sitaram Chamarty Date: Fri, 20 Aug 2010 22:47:34 +0530 Subject: [PATCH] minor fixups to the "gitweb/daemon from setperms" code... - fork was not printing a newline after the permissions - "add_del_line" to properly handle that damn projects.list file! --- conf/example.gitolite.rc | 2 +- contrib/adc/fork | 2 +- src/gitolite.pm | 23 ++++++++++++++++++++++- src/gl-auth-command | 2 +- t/t60-daemon-gitweb-via-setperms | 9 --------- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/conf/example.gitolite.rc b/conf/example.gitolite.rc index 82a9783..e57f8fc 100644 --- a/conf/example.gitolite.rc +++ b/conf/example.gitolite.rc @@ -231,7 +231,7 @@ $GL_WILDREPOS = 0; # as desired after repository creation; it is only a default. Note that @all can be # used here but is special; no other groups can be used in user-level permissions. -# $GL_WILDREPOS_DEFPERMS = 'R = @all'; +# $GL_WILDREPOS_DEFPERMS = 'R @all'; # -------------------------------------- # HOOK CHAINING diff --git a/contrib/adc/fork b/contrib/adc/fork index b3cac93..70deb4c 100755 --- a/contrib/adc/fork +++ b/contrib/adc/fork @@ -19,7 +19,7 @@ git clone --bare -l $GL_REPO_BASE_ABS/$from.git $GL_REPO_BASE_ABS/$to.git cd $GL_REPO_BASE_ABS/$to.git echo $GL_USER > gl-creater git config gitweb.owner "$GL_USER" -( cd $HOME;perl -e 'do ".gitolite.rc"; print $GL_WILDREPOS_DEFPERMS' ) | +( cd $HOME;perl -le 'do ".gitolite.rc"; print $GL_WILDREPOS_DEFPERMS' ) | SSH_ORIGINAL_COMMAND="setperms $to" $GL_BINDIR/gl-auth-command $GL_USER cp -R $GL_REPO_BASE_ABS/$from.git/hooks/* $GL_REPO_BASE_ABS/$to.git/hooks diff --git a/src/gitolite.pm b/src/gitolite.pm index 13a761d..e0c2af4 100644 --- a/src/gitolite.pm +++ b/src/gitolite.pm @@ -66,6 +66,26 @@ sub wrap_print { close($fh); } +sub add_del_line { + my ($line, $file, $flag) = @_; + my $contents; + + local $/ = undef; + my $fh = wrap_open("<", $file); + $contents = <$fh>; + $contents =~ s/\s+$/\n/; + + if ($flag and $contents !~ /^\Q$line\E$/m) { + # add line if it doesn't exist + $contents .= "$line\n"; + wrap_print($file, $contents); + } + if (not $flag and $contents =~ /^\Q$line\E$/m) { + $contents =~ s/^\Q$line\E(\n|$)//m; + wrap_print($file, $contents); + } +} + sub dbg { for my $i (@_) { print STDERR "DBG: $i\n"; @@ -279,7 +299,8 @@ sub get_set_perms # gitweb and daemon setup_daemon_access($repo); - system("echo $repo.git >> $PROJECTS_LIST") if &setup_gitweb_access($repo, '', ''); + # add or delete line (arg1) from file (arg2) depending on arg3 + &add_del_line ("$repo.git", $PROJECTS_LIST, &setup_gitweb_access($repo, '', '')); } } diff --git a/src/gl-auth-command b/src/gl-auth-command index 9870b2d..45e6ced 100755 --- a/src/gl-auth-command +++ b/src/gl-auth-command @@ -199,7 +199,7 @@ if ($perm =~ /C/) { wrap_print("gl-perms", "$GL_WILDREPOS_DEFPERMS\n") if $GL_WILDREPOS_DEFPERMS; &setup_repo_configs($repo, \%repo_config); &setup_daemon_access($repo); - system("echo $repo.git >> $PROJECTS_LIST") if &setup_gitweb_access($repo, '', ''); + &add_del_line ("$repo.git", $PROJECTS_LIST, &setup_gitweb_access($repo, '', '')); wrap_chdir($ENV{HOME}); } diff --git a/t/t60-daemon-gitweb-via-setperms b/t/t60-daemon-gitweb-via-setperms index 47bc5b7..4d23b10 100644 --- a/t/t60-daemon-gitweb-via-setperms +++ b/t/t60-daemon-gitweb-via-setperms @@ -109,18 +109,9 @@ do runlocal git ls-remote u1:bar/u1/try6 runremote ls -al repositories/bar/u1/try6.git/git-daemon-export-ok expect "ls: cannot access repositories/bar/u1/try6.git/git-daemon-export-ok: No such file or directory" - # projects.list currently does not get cleared until a compile, so you - # will still see the entry for .../try6 - runremote ls -al projects.list - expect "gitolite-test gitolite-test 76 .* projects.list" - runremote cat projects.list - expect "bar/u1/try6.git" - - echo | ugc runremote ls -al projects.list expect "gitolite-test gitolite-test 60 .* projects.list" runremote cat projects.list - # but *now* it should be gone notexpect "bar/u1/try6.git" name "INTERNAL"