Re: [PATCH] gitweb: return correct HTTP status codes

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Lea Wiemann
Date: Tuesday, June 17, 2008 - 4:47 pm

Jakub Narebski wrote:

It's actually not checking, it's resolving.  Instead of ...

get_commit($symbol)

... (with $symbol = 'HEAD' for instance), you do (pseudocode):

$hash = get_hash($symbol, 'commit'); # 'commit' to resolve tags
check that $hash is defined
get_commit($hash)

(And get_commit won't even accept anything but 40-byte hashes.)  This is 
for two reasons:

1. Caching: Resolving symbols first gives you some (very few) cache 
entries that need to be expired (namely, get_hash results for symbols 
that are not SHA1 hashes already), but most cache entries (like the 
get_commit) are infinitely valid.

2. Besides being a little more straightforward to implement, it ensures 
that you have well-defined failure points.  IOW, first you resolve the 
symbols you're getting from the user and check them for existence (and 
correct type).  From then on, any hashes you pass around are guaranteed 
to be valid, so failures indicate that something serious went wrong. 
Apart from making things easier for the developer by reminding them of 
the points where they *need* to check for errors, it means that you can 
very easily check the error-handling code for completeness (by only 
reading the first few lines that resolve symbols).


Will do in the next 2 days after some cleanup.


It makes things better to read for sure, and it means that you can have 
a plain API without caching, and implement the caching layer as a 
subclass (which overrides the methods with cacheable results).

-- Lea
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] gitweb: return correct HTTP status codes, Lea Wiemann, (Sun Jun 15, 2:15 pm)
Re: [PATCH] gitweb: return correct HTTP status codes, Jakub Narebski, (Sun Jun 15, 3:48 pm)
Re: [PATCH] gitweb: return correct HTTP status codes, Lea Wiemann, (Mon Jun 16, 8:57 am)
Re: [PATCH] gitweb: return correct HTTP status codes, Jakub Narebski, (Mon Jun 16, 9:43 am)
Re: [PATCH] gitweb: return correct HTTP status codes, Lea Wiemann, (Mon Jun 16, 2:49 pm)
Re: [PATCH] gitweb: return correct HTTP status codes, Jakub Narebski, (Mon Jun 16, 3:34 pm)
Re: [PATCH] gitweb: return correct HTTP status codes, Junio C Hamano, (Mon Jun 16, 3:38 pm)
Re: [PATCH] gitweb: return correct HTTP status codes, Jakub Narebski, (Mon Jun 16, 4:37 pm)
Re: [PATCH] gitweb: return correct HTTP status codes, Lea Wiemann, (Tue Jun 17, 6:53 am)
Re: [PATCH] gitweb: return correct HTTP status codes, Lea Wiemann, (Tue Jun 17, 7:04 am)
Re: [PATCH] gitweb: return correct HTTP status codes, Jakub Narebski, (Tue Jun 17, 7:33 am)
Re: [PATCH] gitweb: return correct HTTP status codes, Lea Wiemann, (Tue Jun 17, 3:28 pm)
Re: [PATCH] gitweb: return correct HTTP status codes, Jakub Narebski, (Tue Jun 17, 3:54 pm)
Re: [PATCH] gitweb: return correct HTTP status codes, Lea Wiemann, (Tue Jun 17, 4:47 pm)
Re: [PATCH] gitweb: return correct HTTP status codes, Jakub Narebski, (Tue Jun 17, 5:12 pm)
[PATCH] gitweb: standarize HTTP status codes, Lea Wiemann, (Tue Jun 17, 5:15 pm)
Re: [PATCH] gitweb: return correct HTTP status codes, Lea Wiemann, (Tue Jun 17, 6:25 pm)
Re: [PATCH] gitweb: return correct HTTP status codes, Jakub Narebski, (Wed Jun 18, 12:35 am)
Re: [PATCH v2] gitweb: standarize HTTP status codes, Jakub Narebski, (Wed Jun 18, 5:51 pm)
Re: [PATCH v2] gitweb: standarize HTTP status codes, Lea Wiemann, (Thu Jun 19, 12:08 pm)
[PATCH v3] gitweb: standarize HTTP status codes, Lea Wiemann, (Thu Jun 19, 1:03 pm)
[PATCH v3] gitweb: standarize HTTP status codes, Lea Wiemann, (Thu Jun 19, 1:25 pm)
Re: [PATCH v2] gitweb: standarize HTTP status codes, Jakub Narebski, (Thu Jun 19, 3:22 pm)
Re: [PATCH v3] gitweb: standarize HTTP status codes, Jakub Narebski, (Thu Jun 19, 3:37 pm)
Re: [PATCH v3] gitweb: standarize HTTP status codes, Junio C Hamano, (Thu Jun 19, 5:48 pm)