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

Re: [StGit PATCH] Parse commit object header correctly

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 9, 2012, 03:58 UTC
Message-ID
<7v39akzmgx.fsf@alter.siamese.dyndns.org>
In-Reply-To
<op.v9dl1e0v0aolir@keputer.lokaal>
"Frans Klaver" <fransklaver@gmail.com> writes:
Show 16 quoted lines
>>>>           for line in lines:
>>>>               try:
>>>>                   key, value = line.rstrip('\n').split(' ', 1)
>>>>               except ValueError:
>>>>                   continue
>>>
>>> This is generally considered more pythonic: "It's easier to ask for
>>> forgiveness than to get permission".
>>
>> Given that Junio explicitly wanted to allow lines with no spaces, I
>> assume that lack of a space is not an error but rather a conceivable
>> future extension.  If my assumption is correct, then it is misleading
>> (and inefficient) to handle it via an exception.
>
> I find the documenting more convincing than the efficiency, but from
> the phrasing I think you do too.

A line that consists entirely of non-SP may or may not a conceivable future extension, but the point is to "skip without barfing anything you do not understand".

I wouldn't oppose the rewrite that uses try/except ValueError if "everything in this try block will parse what I understand correctly, and any ValueError exception this try block throws is an indication that I encountered what I do not understand and I must skip" is the more pythonic way to express that principle. Python is not my primary language as I said, and in addition StGit may have its own style I haven't learned.

Previous: Frans KlaverNext: Catalin Marinas
Message 8 of 15 in “STGIT: Deathpatch in linus tree”
  1. Andy Green (林安廸)Feb 7, 2012
  2. Junio C HamanoFeb 7, 2012
  3. Parse commit object header correctlyJunio C Hamano, Feb 8, 2012
  4. Michael HaggertyFeb 8, 2012
  5. Frans KlaverFeb 8, 2012
  6. Michael HaggertyFeb 8, 2012
  7. Frans KlaverFeb 8, 2012
  8. Junio C HamanoFeb 9, 2012
  9. Catalin MarinasFeb 15, 2012
  10. Junio C HamanoFeb 15, 2012
  11. Andy Green (林安廸)Feb 15, 2012
  12. Catalin MarinasFeb 9, 2012
  13. Jonathan NiederFeb 9, 2012
  14. Nguyen Thai Ngoc DuyFeb 10, 2012
  15. Junio C HamanoFeb 9, 2012

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.