git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
LWLea Wiemann <lewiemann@gmail.com>
Date
Jun 17, 2008, 23:47 UTC
Message-ID
<48584D1F.5070000@gmail.com>
In-Reply-To
<200806180054.33490.jnareb@gmail.com>
Jakub Narebski wrote:
> But what are arguments for "check params; run command" vs "run command;
> check params if error" proposed by Junio?  Why do you want to check
> parameters upfront?
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).
> By the way, would you be sending your current WIP for review?
Will do in the next 2 days after some cleanup.
> [is] adding object oriented interface (wrapper) to git repositories
> really  needed for implementing gitweb caching?

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
Previous: Jakub NarebskiNext: Jakub Narebski
Message 13 of 25 in “gitweb: return correct HTTP status codes”
  1. gitweb: return correct HTTP status codesLea Wiemann, Jun 15, 2008
  2. Jakub NarebskiJun 15, 2008
  3. Lea WiemannJun 16, 2008
  4. Jakub NarebskiJun 16, 2008
  5. Lea WiemannJun 16, 2008
  6. Jakub NarebskiJun 16, 2008
  7. Lea WiemannJun 17, 2008
  8. Junio C HamanoJun 16, 2008
  9. Lea WiemannJun 17, 2008
  10. Jakub NarebskiJun 17, 2008
  11. Lea WiemannJun 17, 2008
  12. Jakub NarebskiJun 17, 2008
  13. Lea WiemannJun 17, 2008
  14. Jakub NarebskiJun 18, 2008
  15. Lea WiemannJun 18, 2008
  16. Jakub NarebskiJun 18, 2008
  17. Jakub NarebskiJun 16, 2008
  18. gitweb: standarize HTTP status codesLea Wiemann, Jun 18, 2008
  19. Jakub NarebskiJun 19, 2008
  20. Lea WiemannJun 19, 2008
  21. gitweb: standarize HTTP status codesLea Wiemann, Jun 19, 2008
  22. gitweb: standarize HTTP status codesLea Wiemann, Jun 19, 2008
  23. Jakub NarebskiJun 19, 2008
  24. Junio C HamanoJun 20, 2008
  25. Jakub NarebskiJun 19, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.