Permalink
Browse files

make REPO_BASE absolute early

$ENV{GL_REPO_BASE_ABS} is meant to point to the same directory as
$REPO_BASE, except it is meant to be passed to hooks, ADCs and other
child programs.  And since you can't be sure where the child program
starts in, this became an absolute path.

Gradually, however, I started using it wherever I needed an absolute
path (mostly in code that jumps around various directories to do stuff).
Which is silly, because there's no reason $REPO_BASE cannot also be made
an absolute, even if the rc file has a relative path.

So that's what I did now: made $REPO_BASE absolute very early on, and
then systematically changed all uses of the longer form to the shorter
form when appropriate.  And so the only thing we now use the longer one
for is to pass to child programs.

(Implementation note: The actual change is not very big, but while I was
about it I decided to make the test suite able to test with an absolute
REPO_BASE also, which is why the commit seems so large.)

----

This all started with a complaint from Damien Regad.  He had an
extremely odd setup where his bashrc changed PWD to something other than
$HOME before anything else ran.  This caused those two variables to
beceom inconsistent, and he had a 1-line fix he wanted me to apply.

I generally don't like making special fixes for for non-standard setups,
and anyway all he had to do was set the full path to REPO_BASE in the rc
file to get around this.  Which is what I told him and he very politely
left it at that.

However, this did get me thinking, and I soon realised I was needlessly
conflating "relative versus absolute" with "able to be passed to child
programs".  Fixing that solved his problem also, as a side-effect.

So I guess this is all thanks to Damien!
  • Loading branch information...
1 parent 85fe9c1 commit 6539009cb5eb9295452a2588c8aad1171055b431 @sitaramc committed Mar 18, 2011
View
@@ -171,7 +171,7 @@ sub list_phy_repos
{
my @phy_repos;
- wrap_chdir("$ENV{GL_REPO_BASE_ABS}");
+ wrap_chdir($REPO_BASE);
for my $repo (`find . -type d -name "*.git" -prune`) {
chomp ($repo);
$repo =~ s(\./(.*)\.git$)($1);
@@ -250,7 +250,7 @@ sub new_repo
sub new_wild_repo {
my ($repo, $user) = @_;
- wrap_chdir("$ENV{GL_REPO_BASE_ABS}");
+ wrap_chdir($REPO_BASE);
new_repo($repo, "$GL_ADMINDIR/hooks/common", $user);
# note pwd is now the bare "repo.git"; new_repo does that...
wrap_print("gl-perms", "$GL_WILDREPOS_DEFPERMS\n") if $GL_WILDREPOS_DEFPERMS;
@@ -294,8 +294,8 @@ sub new_wild_repo {
# creator
my $c = '';
- if ( -f "$ENV{GL_REPO_BASE_ABS}/$repo.git/gl-creater") {
- my $fh = wrap_open("<", "$ENV{GL_REPO_BASE_ABS}/$repo.git/gl-creater");
+ if ( -f "$REPO_BASE/$repo.git/gl-creater") {
+ my $fh = wrap_open("<", "$REPO_BASE/$repo.git/gl-creater");
chomp($c = <$fh>);
}
@@ -308,8 +308,8 @@ sub new_wild_repo {
# "WRITERS=>foo" and "TESTERS=>@all"
my %perm_cats;
- if ($user and -f "$ENV{GL_REPO_BASE_ABS}/$repo.git/gl-perms") {
- my $fh = wrap_open("<", "$ENV{GL_REPO_BASE_ABS}/$repo.git/gl-perms");
+ if ($user and -f "$REPO_BASE/$repo.git/gl-perms") {
+ my $fh = wrap_open("<", "$REPO_BASE/$repo.git/gl-perms");
my $perms = join ("", <$fh>);
# discard comments
$perms =~ s/#.*//g;
@@ -353,7 +353,7 @@ sub get_set_perms
$GL_WILDREPOS_PERM_CATS ||= "READERS WRITERS";
my ($creator, $dummy, $dummy2) = wild_repo_rights($repo, "");
die "$repo doesnt exist or is not yours\n" unless $user eq $creator;
- wrap_chdir("$ENV{GL_REPO_BASE_ABS}");
+ wrap_chdir($REPO_BASE);
wrap_chdir("$repo.git");
if ($verb eq 'getperms') {
return unless -f "gl-perms";
@@ -390,7 +390,7 @@ sub get_set_desc
my($repo, $verb, $user) = @_;
my ($creator, $dummy, $dummy2) = wild_repo_rights($repo, "");
die "$repo doesnt exist or is not yours\n" unless $user eq $creator;
- wrap_chdir("$ENV{GL_REPO_BASE_ABS}");
+ wrap_chdir($REPO_BASE);
wrap_chdir("$repo.git");
if ($verb eq 'getdesc') {
print slurp("description") if -f "description";
@@ -562,7 +562,7 @@ sub expand_wild
# display matching repos (from *all* the repos in the system) that $user
# has at least "R" access to
- chdir("$ENV{GL_REPO_BASE_ABS}") or die "chdir $ENV{GL_REPO_BASE_ABS} failed: $!\n";
+ chdir($REPO_BASE) or die "chdir $REPO_BASE failed: $!\n";
my $count = 0;
for my $actual_repo (`find . -type d -name "*.git" -prune|sort`) {
chomp ($actual_repo);
@@ -665,7 +665,7 @@ sub add_repo_conf
{
my ($repo) = shift;
return unless $split_conf{$repo};
- do "$ENV{GL_REPO_BASE_ABS}/$repo.git/gl-conf" or return;
+ do "$REPO_BASE/$repo.git/gl-conf" or return;
$repos{$repo} = $one_repo{$repo};
$git_configs{$repo} = $one_git_config{$repo};
}
@@ -694,14 +694,16 @@ sub add_repo_conf
# means we've been called from outside; see doc/admin-defined-commands.mkd
where_is_rc();
die "parse $ENV{GL_RC} failed: " . ($! or $@) unless do $ENV{GL_RC};
+ # fix up REPO_BASE
+ $REPO_BASE = "$ENV{HOME}/$REPO_BASE" unless $REPO_BASE =~ m(^/);
}
my $perm = ' ';
my $creator;
# get basic info about the repo and fill %repos
my $wild = '';
- my $exists = -d "$ENV{GL_REPO_BASE_ABS}/$repo.git";
+ my $exists = -d "$REPO_BASE/$repo.git";
if ($exists) {
# the list of permission categories within gl-perms that this user is a member
# of, or that specify @all as a member. See comments in
@@ -768,7 +770,7 @@ sub can_read {
# helper to manage "disabling" a repo or the whole site for "W" access
sub check_repo_write_enabled {
my ($repo) = shift;
- for my $d ("$ENV{HOME}/.gitolite.down", "$ENV{GL_REPO_BASE_ABS}/$repo.git/.gitolite.down") {
+ for my $d ("$ENV{HOME}/.gitolite.down", "$REPO_BASE/$repo.git/.gitolite.down") {
next unless -f $d;
die $ABRT . slurp($d) if -s $d;
die $ABRT . "writes are currently disabled\n";
View
@@ -65,6 +65,9 @@ for ("$ENV{HOME}/.gitolite.rc", "/etc/gitolite/gitolite.rc") {
die "no rc file found\n" unless $ENV{GL_RC};
do $ENV{GL_RC} or die "error parsing $ENV{GL_RC}\n";
+# fix up REPO_BASE
+$REPO_BASE = "$ENV{HOME}/$REPO_BASE" unless $REPO_BASE =~ m(^/);
+
# ------------------------------------------------------------------------------
# per perl rules, this should be the last line in such a file:
1;
View
@@ -142,7 +142,7 @@ $ENV{GL_REPO}=$repo;
# first level permissions check
my ($perm, $creator, $wild);
-if ( $GL_ALL_READ_ALL and $verb =~ $R_COMMANDS and -d "$ENV{GL_REPO_BASE_ABS}/$repo.git") {
+if ( $GL_ALL_READ_ALL and $verb =~ $R_COMMANDS and -d "$REPO_BASE/$repo.git") {
$perm = 'R';
} else {
($perm, $creator, $wild) = repo_rights($repo);
@@ -164,8 +164,8 @@ check_repo_write_enabled($repo) if $aa eq 'W';
# get confused, in case the code in the pre-git hook forgot. To make it
# simple for the script, send in $aa (which will be 'R' or 'W') so now they
# have all three: GL_USER and GL_REPO in the env, and $aa as arg-1.
-if (-x "$ENV{GL_REPO_BASE_ABS}/$repo.git/hooks/gl-pre-git") {
- system("cd $ENV{GL_REPO_BASE_ABS}/$repo.git; hooks/gl-pre-git $aa >&2");
+if (-x "$REPO_BASE/$repo.git/hooks/gl-pre-git") {
+ system("cd $REPO_BASE/$repo.git; hooks/gl-pre-git $aa >&2");
die "gl-pre-git hook failed ($?)\n" if $?;
}
View
@@ -383,10 +383,6 @@ die "\n\t\t***** AAARGH! *****\n" .
# doc/big-config.mkd for details.
# ----------------------------------------------------------------------------
-# repo-base needs to be an absolute path due to all the jumping around we do,
-# so if it was not already absolute, prefix $HOME.
-$ENV{GL_REPO_BASE_ABS} = ( $REPO_BASE =~ m(^/) ? $REPO_BASE : "$ENV{HOME}/$REPO_BASE" );
-
# process the normal repos in %repos. This includes creating them if needed
# (and GL_NO_CREATE_REPOS is not set), checking hooks, and finally, if
# GL_BIG_CONFIG is set, writing out the one-repo config file for directly
@@ -400,7 +396,7 @@ write_compiled_conf(); # write out the final compiled config
sub do_normal_repos
{
- wrap_chdir("$ENV{GL_REPO_BASE_ABS}");
+ wrap_chdir($REPO_BASE);
# start with the ones that are normal repos in %repos
my @repos = grep { $_ =~ $REPONAME_PATT and not /^@/ } sort keys %repos;
@@ -419,7 +415,7 @@ sub do_normal_repos
print STDERR "creating $repo...\n";
new_repo($repo, "$GL_ADMINDIR/hooks/common");
# new_repo would have chdir'd us away; come back
- wrap_chdir("$ENV{GL_REPO_BASE_ABS}");
+ wrap_chdir($REPO_BASE);
}
# when repos are copied over from elsewhere, one had to run easy install
@@ -520,13 +516,13 @@ my %projlist = ();
# sub parse_acl (look for variable $saved_crwu)
for my $repo (@phy_repos) {
- wrap_chdir("$ENV{GL_REPO_BASE_ABS}/$repo.git");
+ wrap_chdir("$REPO_BASE/$repo.git");
# daemon is easy
setup_daemon_access($repo);
}
for my $repo (@phy_repos) {
- wrap_chdir("$ENV{GL_REPO_BASE_ABS}/$repo.git");
+ wrap_chdir("$REPO_BASE/$repo.git");
# gitweb is a little more complicated. Here're some notes:
# - "setup_gitweb_access" also sets "owner", despite the name
# - specifying a description also counts as enabling gitweb
View
@@ -53,18 +53,14 @@ unless ($ENV{GL_RC}) {
exit;
}
-# ok now the rc file exists; read it to get the other paths
-die "parse $ENV{GL_RC} failed: " . ($! or $@) unless do $ENV{GL_RC};
-
# add a custom path for git binaries, if specified
$ENV{PATH} .= ":$GIT_PATH" if $GIT_PATH;
# set the umask before creating any files/directories
umask($REPO_UMASK);
# mkdir $REPO_BASE, $GL_ADMINDIR if they don't already exist
-$ENV{GL_REPO_BASE_ABS} = ( $REPO_BASE =~ m(^/) ? $REPO_BASE : "$ENV{HOME}/$REPO_BASE" );
-wrap_mkdir($ENV{GL_REPO_BASE_ABS});
+wrap_mkdir($REPO_BASE);
wrap_mkdir($GL_ADMINDIR, 0700);
# mkdir $GL_ADMINDIR's subdirs
for my $dir qw(conf doc keydir logs src hooks hooks/common hooks/gitolite-admin) {
@@ -93,7 +89,7 @@ EOF
}
# finally, hooks must be propagated to all the repos in case they changed
-chdir("$ENV{GL_REPO_BASE_ABS}") or die "chdir $ENV{GL_REPO_BASE_ABS} failed: $!\n";
+chdir($REPO_BASE) or die "chdir $REPO_BASE failed: $!\n";
for my $repo (`find . -type d -name "*.git" -prune`) {
chomp ($repo);
# propagate our own, plus any local admin-defined, hooks
View
@@ -16,7 +16,7 @@ chmod 600 ~/.ssh/u?
# blank out the server side
echo the next command MAY ask for a password
-ssh gitolite-test@localhost rm -rf .ssh .gitolite .gitolite.rc repositories gitolite-install
+ssh gitolite-test@localhost rm -rf .ssh .gitolite .gitolite.rc repositories gitolite-install /tmp/glrb
echo the next command SHOULD ask for a password
ssh-copy-id -i ~/.ssh/id_rsa gitolite-test@localhost
echo the next command should NOT ask for a password
@@ -33,4 +33,6 @@ git push
# make the rollback.tar files on both sides
cd
tar cf rollback.tar gitolite-admin
+ssh gitolite-test@localhost mkdir -p repositories /tmp/glrb
ssh gitolite-test@localhost tar cf rollback.tar .ssh .gitolite .gitolite.rc repositories gitolite-install
+ssh gitolite-test@localhost tar -C /tmp -cf \$HOME/rollback2.tar glrb
@@ -6,10 +6,10 @@ $data_version = '1.7';
'gitolite-admin' => 1,
'testing' => 1
);
-repositories/aa.git/gl-conf
-repositories/bb.git/gl-conf
-repositories/gitolite-admin.git/gl-conf
-repositories/testing.git/gl-conf
+./aa.git/gl-conf
+./bb.git/gl-conf
+./gitolite-admin.git/gl-conf
+./testing.git/gl-conf
%one_repo = (
'aa' => {
'R' => {
@@ -35,8 +35,8 @@ $data_version = '1.7';
'gitolite-admin' => 1,
'testing' => 1
);
-repositories/gitolite-admin.git/gl-conf
-repositories/testing.git/gl-conf
+./gitolite-admin.git/gl-conf
+./testing.git/gl-conf
%one_repo = (
'gitolite-admin' => {
'R' => {
@@ -5,9 +5,9 @@ $data_version = '1.7';
'gitolite-admin' => 1,
'testing' => 1
);
-repositories/aa.git/gl-conf
-repositories/gitolite-admin.git/gl-conf
-repositories/testing.git/gl-conf
+./aa.git/gl-conf
+./gitolite-admin.git/gl-conf
+./testing.git/gl-conf
%one_repo = (
'aa' => {
'R' => {
@@ -19,9 +19,9 @@ $data_version = '1.7';
'gitolite-admin' => 1,
'testing' => 1
);
-repositories/aa.git/gl-conf
-repositories/gitolite-admin.git/gl-conf
-repositories/testing.git/gl-conf
+./aa.git/gl-conf
+./gitolite-admin.git/gl-conf
+./testing.git/gl-conf
%one_repo = (
'aa' => {
'@g1' => [
View
@@ -1,8 +1,9 @@
#!/bin/bash
cd
-rm -rf .ssh .gitolite .gitolite.rc repositories gitolite-install
+rm -rf .ssh .gitolite .gitolite.rc repositories gitolite-install /tmp/glrb
tar xf rollback.tar
+( cd /tmp; tar xf ~/rollback2.tar )
# if arg1 is a directory, we have to overwrite sources from there (see commit
# message for details)
View
@@ -13,7 +13,7 @@ expect "To gitolite:gitolite-admin"
expect "master -> master"
name "basic create repo"
-expect "remote: Initialized empty Git repository in /home/gitolite-test/repositories/aa.git/"
+expect "remote: Initialized empty Git repository in $TEST_BASE_FULL/aa.git/"
# ----------
name "basic clone"
View
@@ -22,12 +22,12 @@ cd ~/td
name "u1 create success"
runlocal git clone u1:foo/u1/a01
-expect "Initialized empty Git repository in /home/gitolite-test/repositories/foo/u1/a01.git/"
+expect "Initialized empty Git repository in $TEST_BASE_FULL/foo/u1/a01.git/"
# expect "R access for foo/u1/a01 DENIED to u1"
name "u2 create success"
runlocal git clone u2:foo/u2/a02
-expect "Initialized empty Git repository in /home/gitolite-test/repositories/foo/u2/a02.git/"
+expect "Initialized empty Git repository in $TEST_BASE_FULL/foo/u2/a02.git/"
# expect "R access for foo/u2/a02 DENIED to u2"
name "u4 tries to create u2 repo"
@@ -40,7 +40,7 @@ expect "R access for foo/u4/a1234 DENIED to u4"
name "u4 tries to create his own repo"
runlocal git clone u4:foo/u4/a12
-expect "Initialized empty Git repository in /home/gitolite-test/repositories/foo/u4/a12.git/"
+expect "Initialized empty Git repository in $TEST_BASE_FULL/foo/u4/a12.git/"
expect "warning: You appear to have cloned an empty repository."
name "u4 push success"
@@ -38,7 +38,7 @@ expect "R access for foo/u4/a1234 DENIED to u4"
name "u4 tries to create his own repo"
runlocal git clone u4:foo/u4/a12
-expect "Initialized empty Git repository in /home/gitolite-test/repositories/foo/u4/a12.git/"
+expect "Initialized empty Git repository in $TEST_BASE_FULL/foo/u4/a12.git/"
expect "warning: You appear to have cloned an empty repository."
name "u4 push success"
View
@@ -30,7 +30,7 @@ echo "
" > conf/fragments/u1r.conf
ugc < /dev/null
expect "create mode 100644 conf/fragments/u1r.conf"
-expect "remote: Initialized empty Git repository in /home/gitolite-test/repositories/r1a.git/"
+expect "remote: Initialized empty Git repository in $TEST_BASE_FULL/r1a.git/"
expect "To gitolite:gitolite-admin"
expect "master -> master"
View
@@ -21,7 +21,7 @@ do
cd ~/td
runlocal git clone u1:foo/u1/bar
- expect "Initialized empty Git repository in /home/gitolite-test/repositories/foo/u1/bar.git/"
+ expect "Initialized empty Git repository in $TEST_BASE_FULL/foo/u1/bar.git/"
cd bar
mdc u1file1
@@ -26,7 +26,7 @@ do
runlocal git clone u1:foo/u1/bar
[ "$wr" = "0" ] && expect "R access for foo/u1/bar DENIED to u1"
[ "$wr" = "0" ] && expect "fatal: The remote end hung up unexpectedly"
- [ "$wr" = "1" ] && expect "Initialized empty Git repository in /home/gitolite-test/repositories/foo/u1/bar.git/"
+ [ "$wr" = "1" ] && expect "Initialized empty Git repository in $TEST_BASE_FULL/foo/u1/bar.git/"
name "u3 fails to make a wildrepo"
runlocal git clone u3:foo/u3/baz
View
@@ -45,10 +45,10 @@ do
RW = @devs
config foo.bar = baz
" | ugc -r
- expect "remote: Initialized empty Git repository in /home/gitolite-test/repositories/bar.git/"
+ expect "remote: Initialized empty Git repository in $TEST_BASE_FULL/bar.git/"
notexpect "git config.*not allowed"
expect_push_ok "master -> master"
- runremote cat repositories/bar.git/config
+ runremote cat $TEST_BASE/bar.git/config
expect '^.foo'
expect 'bar = baz'
@@ -65,7 +65,7 @@ do
config foobar.baz = ooka
" | ugc -r
expect "remote: git config foobar.baz not allowed"
- runremote cat repositories/bar.git/config
+ runremote cat $TEST_BASE/bar.git/config
expect '^.foo'
expect 'bar = baz'
notexpect '^.foobar'
@@ -82,7 +82,7 @@ do
RW = @devs
config foo.bar =
" | ugc -r
- runremote cat repositories/bar.git/config
+ runremote cat $TEST_BASE/bar.git/config
expect '^.foo'
notexpect 'bar = baz'
Oops, something went wrong. Retry.

0 comments on commit 6539009

Please sign in to comment.