From 412a691810f6fcd68d2ccbd04b2352fc00badcf7 Mon Sep 17 00:00:00 2001 From: Sitaram Chamarty Date: Wed, 17 Mar 2010 17:45:49 +0530 Subject: [PATCH] compile: remove the sortsub for data dumper Data dumper was failing (returning an empty string!) on an input config file of about 350 lines or so (output 2400 lines or so). Removing the sort sub fixed the problem. To recap why that sub was put in (see deleted lines in this commit for details), what we really want is that $creater must appear *last* in the resulting dump. So we trick it. "man ascii" tells you that ~ is the highest valued ASCII character (yes, I know, not utf-8 safe etc... I'll deal with that if and when needed or punt!). So we just put that in front of $creater and remove it later... You *don't* want to do this for $readers and $writers -- then they will once again sort *after* $creater, which would be a bad thing. Also, it's probably better this way, because now the order of the hash keys will be: $readers, $writers, any actual users listed, and then $creater. This means the effective access rights will be: 1. if you are the creater you get CREATER's rights 2. else if your userid is listed *explicitly* in the config, you get those rights 3. else if you've been setperm'd as a writer, you get WRITERS rights 4. else if you've been setperm'd as a reader, you get READERS rights This is different from what used to happen till now; READERS and WRITERS used to trump explicitly given rights. I'd been meaning to fix that somehow, but never got around to it, until this DDD (damn Data Dumper!) forced my hand :) --- src/gitolite.pm | 5 ----- src/gl-compile-conf | 13 ++----------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/src/gitolite.pm b/src/gitolite.pm index 65709fa..061e57c 100644 --- a/src/gitolite.pm +++ b/src/gitolite.pm @@ -234,11 +234,6 @@ sub parse_acl my ($GL_CONF_COMPILED, $repo, $c, $r, $w) = @_; $c = $r = $w = "NOBODY" unless $GL_WILDREPOS; - # void $r if same as $w (otherwise "readers" overrides "writers"; this is - # the same problem that needed a sort sub for the Dumper in the compile - # script, but in this case it's limited to just $readers and $writers) - $r = "NOBODY" if $r eq $w; - # set up the variables for a parse to interpolate stuff from the dumped # hash (remember the selective conversion of single to double quotes?). diff --git a/src/gl-compile-conf b/src/gl-compile-conf index 1693dcc..b308529 100755 --- a/src/gl-compile-conf +++ b/src/gl-compile-conf @@ -5,15 +5,6 @@ use warnings; use Data::Dumper; $Data::Dumper::Indent = 1; $Data::Dumper::Sortkeys = 1; -$Data::Dumper::Sortkeys = sub { return [ reverse sort keys %{$_[0]} ]; }; - # this is to make sure that $creater etc go to the end of the dumped hash. - # Without this, a setup that has something like - # @team = u1 u2 u3 - # repo priv/CREATER/.+ - # RW+ = CREATER - # RW = @team - # has a problem. The RW overrides the RW+ when the dumped hash is read in - # (simply going by sequence), so creater's special privs are lost # === add-auth-keys === @@ -224,7 +215,7 @@ sub parse_conf_file unless (@users == 1 and $users[0] eq '@all'); do { die "$ABRT bad username $_\n" unless $_ =~ $USERNAME_PATT } for @users; - s/\bCREAT[EO]R\b/\$creater/g for @users; + s/\bCREAT[EO]R\b/~\$creater/g for @users; s/\bREADERS\b/\$readers/g for @users; s/\bWRITERS\b/\$writers/g for @users; @@ -368,7 +359,7 @@ my $dumped_data = Data::Dumper->Dump([\%repos], [qw(*repos)]); # the dump uses single quotes, but we convert any strings containing $creater, # $readers, $writers, to double quoted strings. A wee bit sneaky, but not too # much... -$dumped_data =~ s/'(?=[^']*\$(?:creater|readers|writers|gl_user))(.*?)'/"$1"/g; +$dumped_data =~ s/'(?=[^']*\$(?:creater|readers|writers|gl_user))~?(.*?)'/"$1"/g; print $compiled_fh $dumped_data; close $compiled_fh or die "$ABRT close compiled-conf failed: $!\n";