Skip to contentSkip to conversation

gitweb: Add an option for adding more branch refs

PATCH Superseded Krzesimir Nowak 3 participants 5 messages Jun 15, 2016 Documentation

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 gitweb: Add an option for adding more branch refs

Overriding an @additional_branch_refs configuration variable with value ('wip') will make gitweb to show branches that appear in refs/heads and refs/wip (refs/heads is hardcoded). Might be useful for gerrit setups where user branches are not stored under refs/heads/.

---
 Documentation/gitweb.conf.txt | 14 ++++++++
 gitweb/gitweb.perl            | 75 +++++++++++++++++++++++++++++++++----------
 2 files changed, 72 insertions(+), 17 deletions(-)
Documentation/gitweb.conf.txt +14 -0
index e2113d9..74de87a 100644
@@ -549,6 +549,20 @@ This variable matters only when using persistent web environments that
 serve multiple requests using single gitweb instance, like mod_perl,
 FastCGI or Plackup.
 
+@additional_branch_refs::
+	List of additional directories under "refs" which are going to be used
+	as branch refs. You might want to set this variable if you have a gerrit
+	setup where all branches under refs/heads/ are official,
+	push-after-review ones and branches under refs/sandbox/, refs/wip and
+	refs/other are user ones where permissions are much wider, for example
++
+--------------------------------------------------------------------------------
+our @additional_branch_refs = ('sandbox', 'wip', 'other');
+--------------------------------------------------------------------------------
++
+It is an error to specify 'heads' in the list - it is implicitly added. It is an
+error to specify a ref that does not pass "git check-ref-format" scrutiny. It is
+an error to specify a ref twice in the list.
 
 Other variables
 ~~~~~~~~~~~~~~~
gitweb/gitweb.perl +58 -17

153 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 12 lines · Krzesimir Nowak

Overriding an @additional_branch_refs configuration variable with value ('wip') will make gitweb to show branches that appear in refs/heads and refs/wip (refs/heads is hardcoded). Might be useful for gerrit setups where user branches are not stored under refs/heads/.

---

gitweb/gitweb.perl +0 -0
index 68c77f6..499281b 100755

gitweb/gitweb.perl sub read_config_file { · line 696

Quoted 9 lines
gitweb/gitweb.perl +6 -0
@@ -680,6 +688,19 @@ sub read_config_file {
        return;
 }
 
+# performs sanity checks on parts of configuration.
+sub config_sanity_check {
+       # check additional refs validity
+       my %unique_branch_refs = ();
+       for my $ref (@additional_branch_refs) {
+               die_error(500, 'Invalid ref in @additional_branch_refs') unless (validate_ref($ref));

Mentioning $ref in the error message would help the user resolve the problem more quickly.

gitweb/gitweb.perl sub read_config_file { · line 697

Quoted 1 line
gitweb/gitweb.perl +1 -0
+               die_error(500, '"heads" specified in @additional_branch_refs') if ($ref eq 'heads');

Rephrasing this as

"heads" disallowed in @additional_branch_refs

would better explain the problem to a user who has only made a cursory read of the documentation.

Quoted 9 lines
gitweb/gitweb.perl +6 -0
+               die_error(500, "Ref '$ref' repeated in \@additional_branch_refs") if (exists $unique_branch_refs{$ref});
+               $unique_branch_refs{$ref} = 1;
+       }
+       %unique_branch_refs = undef;
+}
+
 our ($GITWEB_CONFIG, $GITWEB_CONFIG_SYSTEM, $GITWEB_CONFIG_COMMON);
 sub evaluate_gitweb_config {
        our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
#2 lore raw
Quoted 27 lines · Eric Sunshine
Quoted 12 lines · Krzesimir Nowak

Overriding an @additional_branch_refs configuration variable with value ('wip') will make gitweb to show branches that appear in refs/heads and refs/wip (refs/heads is hardcoded). Might be useful for gerrit setups where user branches are not stored under refs/heads/.

---

gitweb/gitweb.perl +0 -0
index 68c77f6..499281b 100755

gitweb/gitweb.perl sub read_config_file { · line 696

Quoted 9 lines
gitweb/gitweb.perl +6 -0
@@ -680,6 +688,19 @@ sub read_config_file {
        return;
 }
 
+# performs sanity checks on parts of configuration.
+sub config_sanity_check {
+       # check additional refs validity
+       my %unique_branch_refs = ();
+       for my $ref (@additional_branch_refs) {
+               die_error(500, 'Invalid ref in @additional_branch_refs') unless (validate_ref($ref));

Mentioning $ref in the error message would help the user resolve the problem more quickly.

Quoted 8 lines

gitweb/gitweb.perl sub read_config_file { · line 697

Quoted 1 line
gitweb/gitweb.perl +1 -0
+               die_error(500, '"heads" specified in @additional_branch_refs') if ($ref eq 'heads');

Rephrasing this as

"heads" disallowed in @additional_branch_refs

would better explain the problem to a user who has only made a cursory read of the documentation.

The program could easily filter out the redundant 'heads', so does this really deserve a diagnostic?

#3 lore raw
Quoted 6 lines · Eric Sunshine
Quoted 5 lines · Eric Sunshine
Quoted 3 lines · Krzesimir Nowak

Overriding an @additional_branch_refs configuration variable with value ('wip') will make gitweb to show branches that appear in refs/heads and refs/wip (refs/heads is hardcoded).

"branches" are by definition what are in refs/heads/ hierarchy, so

Allow @additional_branch_refs configuration variable to tell gitweb to show refs from additional hierarchies in addition to branches in the list-of-branches view.

would be more appropriate and sufficient.

Quoted 7 lines
Quoted 7 lines

Mentioning $ref in the error message would help the user resolve the problem more quickly.

Quoted 1 line

+ die_error(500, '"heads" specified in @additional_branch_refs') if ($ref eq 'heads');

Rephrasing this as

Quoted 7 lines
Quoted 4 lines

"heads" disallowed in @additional_branch_refs

would better explain the problem to a user who has only made a cursory read of the documentation.

The program could easily filter out the redundant 'heads', so does this really deserve a diagnostic?

True.

I was primarily worried about metacharacters in the specified strings getting in the way of regexp matches the new code allows on them, but that has been resolved with the use of \Q..\E; if that automatic deduping is done, I do not immediately see any remaining issues in the latest round of the patch.

Thanks.

#4 lore raw
Quoted 9 lines · Junio C Hamano
Quoted 6 lines · Eric Sunshine
Quoted 5 lines · Eric Sunshine
Quoted 3 lines · Krzesimir Nowak

Overriding an @additional_branch_refs configuration variable with value ('wip') will make gitweb to show branches that appear in refs/heads and refs/wip (refs/heads is hardcoded).

Quoted 7 lines

"branches" are by definition what are in refs/heads/ hierarchy, so

Allow @additional_branch_refs configuration variable to tell gitweb to show refs from additional hierarchies in addition to branches in the list-of-branches view.

would be more appropriate and sufficient.

Thanks.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Mentioning $ref in the error message would help the user resolve the problem more quickly.

Quoted 1 line

+ die_error(500, '"heads" specified in @additional_branch_refs') if ($ref eq 'heads');

Rephrasing this as

"heads" disallowed in @additional_branch_refs

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

would better explain the problem to a user who has only made a cursory read of the documentation.

The program could easily filter out the redundant 'heads', so does this really deserve a diagnostic?

True.

Ok, I'm deduping both heads and other refs as well. Now we send 500 only if the ref is simply invalid.

Quoted 7 lines

I was primarily worried about metacharacters in the specified strings getting in the way of regexp matches the new code allows on them, but that has been resolved with the use of \Q..\E; if that automatic deduping is done, I do not immediately see any remaining issues in the latest round of the patch.

New patch in "[PATCH v3] gitweb: Add an option for adding more branch refs". Thanks for reviews!

Quoted 1 line

Thanks.

Signature · 15 lines
Krzesimir Nowak
Software Developer
Endocode AG

[email protected]

------
Endocode AG, Johannisstraße 20, 10117 Berlin
[email protected] | www.endocode.com

Vorstandsvorsitzender: Mirko Boehm
Vorstände: Dr. Karl Beecher, Chris Kühl, Sebastian Sucker
Aufsichtsratsvorsitzende: Jennifer Beecher

Registergericht: Amtsgericht Charlottenburg - HRB 150748 B