Skip to contentSkip to conversation

gitweb: make suspenders more useful

PATCH In review Mark Rada 2 participants 5 messages Jun 15, 2016

lore
Share & tools
lore

Mark Rada

author
#0 lore raw

PATCH 1/3 gitweb: make suspenders more useful

In the first block of checks to validate a snapshot request, the last check is never executed because the second last check is a superset of the last check.

This change will switch the order of the last two checks, it has the advantage of giving clients a more specific reason why they cannot get a specific snapshot format instead of giving them the more generic response.

---
 gitweb/gitweb.perl |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
gitweb/gitweb.perl +2 -2
index 4a42f61..7068db2 100755
@@ -5174,10 +5174,10 @@ sub git_snapshot {
 		die_error(400, "Invalid snapshot format parameter");
 	} elsif (!exists($known_snapshot_formats{$format})) {
 		die_error(400, "Unknown snapshot format");
-	} elsif (!grep($_ eq $format, @snapshot_fmts)) {
-		die_error(403, "Unsupported snapshot format");
 	} elsif ($known_snapshot_formats{$format}{'disabled'}) {
 		die_error(403, "Snapshot format not allowed");
+	} elsif (!grep($_ eq $format, @snapshot_fmts)) {
+		die_error(403, "Unsupported snapshot format");
 	}
 
 	if (!defined $hash) {
Signature · 2 lines
Mark A Rada (ferrous26)
[email protected]
#1 lore raw
Quoted 1 line · Mark Rada

Subject: [RFC/PATCH 1/3] gitweb: make suspenders more useful

Suspenders? Really?

Sam

author
#2 lore raw
Quoted 10 lines · Sam Vilain
Quoted 1 line · Mark Rada

Subject: [RFC/PATCH 1/3] gitweb: make suspenders more useful

Suspenders? Really?

Sam
--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Context:

Quoted 15 lines · Junio C Hamano
Quoted 5 lines · Mark A Rada

Unless I missed a case, the tests show that the extra condition check that was added in the &git_snapshot routine is never actually executed, because a disabled snapshot format is not added to @snapshot_fmts, which is checked first.

Quoted 7 lines

snippet:
5178 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5179 die_error(403, "Unsupported snapshot format");
5180 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
5181 die_error(403, "Snapshot format not allowed");
5182 }
5183

Quoted 4 lines

True; filter_snapshot_fmts looks at 'disabled' first.

I do not mind keeping these two lines as belt-and-suspender, though.

Yup...I couldn't think of an appropriate title and I expect this patch to be edited (for another reason) or thrown out anyways.

Signature · 2 lines
Mark A Rada (ferrous26)
[email protected]
#3 lore raw
Quoted 4 lines · Mark Rada
Quoted 4 lines
Quoted 2 lines

Subject: [RFC/PATCH 1/3] gitweb: make suspenders more useful

Suspenders? Really?

Quoted 9 lines

Context:

Quoted 2 lines · Junio C Hamano

I do not mind keeping these two lines as belt-and-suspender, though.

Yup...I couldn't think of an appropriate title and I expect this patch to be edited (for another reason) or thrown out anyways.

Please don't do that. Use of metaphors makes the code harder to follow, especially for non-native speakers. In this case you confused me, a British/NZ native speaker because you only used half of the idiom; so all I was left with was a word which in the English where I speak refers to a piece of clothing worn most often by prostitutes and people at the Rocky Horror Picture Show.

Can I suggest "snapshot error handling" as a more neutral term... Sam

author
#4 lore raw

PATCH 1/3 gitweb: improve snapshot error handling

Ok, this is just a resend of the first patch in my set from earlier, but with some of the commit message reworded, namely the subject (as suggested by Sam Vilain).

--
Mark Rada (ferrous26)
[email protected]

--->8---
In the second block of checks to validate a snapshot request, the last check is never executed because the second last check is a superset of the last check.

This change will switch the order of the last two checks, it has the advantage of giving clients a more specific reason why they cannot get a snapshot format if the format they have chosen is disabled.

---
 gitweb/gitweb.perl |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
gitweb/gitweb.perl +2 -2
index 4a42f61..7068db2 100755
@@ -5174,10 +5174,10 @@ sub git_snapshot {
 		die_error(400, "Invalid snapshot format parameter");
 	} elsif (!exists($known_snapshot_formats{$format})) {
 		die_error(400, "Unknown snapshot format");
-	} elsif (!grep($_ eq $format, @snapshot_fmts)) {
-		die_error(403, "Unsupported snapshot format");
 	} elsif ($known_snapshot_formats{$format}{'disabled'}) {
 		die_error(403, "Snapshot format not allowed");
+	} elsif (!grep($_ eq $format, @snapshot_fmts)) {
+		die_error(403, "Unsupported snapshot format");
 	}
 
 	if (!defined $hash) {
Signature · 1 line
1.6.4