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

Re: [PATCHv2 2/2] git-patch-id: do not trip over "no newline" markers

From
Jeff King <peff@peff.net>
Date
Feb 18, 2011, 10:40 UTC
Message-ID
<20110218104035.GA7262@sigill.intra.peff.net>
In-Reply-To
<4D5E278F.2010509@drmicha.warpmail.net>
On Fri, Feb 18, 2011 at 09:02:23AM +0100, Michael J Gruber wrote:
Show 9 quoted lines
> > Wow, that's pretty obscure. I wonder if the test should be factored out
> > into line_is_no_newline_at_end_of_file() (or surely there is some more
> > sensible name), and used by both apply and patch-id. Along with a nice
> > comment (which I see apply already has) describing what in the world the
> > magic number 12 means.
> 
> So, where do you suggest it should go? As far as I can see, we have two
> places reading these markers (the above builtins) and two places writing
> them (diff.c, xdiff/xutils.c), at least for git-core.

I think you could ignore the writers, as they are much more straightforward. But...

> (git-gui's diff.tcl has its own strict check etc.)
Ugh. Factoring that out with the C code would not be easy. :)
> I would opt for putting a more detailed explanation in the commit
> message (reasoning + ref. to apply.c) rather then trying to factor this.

I think that's OK. It's not a lot of code, it's just very non-obvious. So a comment is probably as good as a refactor.

> After all, our code is largely undocumented as far as inline
> documentation goes (it has frustrated me a few times), and the more
> comprehensive documentation are the commit messages which git blame
> points you to.

Yeah, it is sometimes annoying. On the other hand, you know that a comment in the commit log cannot be stale, because you are viewing it in context (well, it can be, but theoretically you have the tools to determine that).

I'm not sure what the right balance is. I tend to write inline comments for small non-obvious things (e.g., why a variable is being strdup'd), and describe the bigger picture in the commit message (e.g., why a particular algorithm was chosen).

But it has only been a few years that we've had version control systems where history browsing wasn't absolutely horrendous. Maybe in another decade or so there will be best practices for this sort of thing. :)

-Peff
Previous: Jakub Narebski
Message 18 of 18 in “Why does git-patch-id(1) sometimes print two lines, one of which has commit = 0000000000000000000000000000000000000000”
  1. Ævar Arnfjörð BjarmasonFeb 16, 2011
  2. Michael J GruberFeb 16, 2011
  3. 1/2 git-patch-id: test for "no newline" markersMichael J Gruber, Feb 16, 2011
  4. 2/2 git-patch-id: do not trip over "no newline" markersMichael J Gruber, Feb 16, 2011
  5. Junio C HamanoFeb 16, 2011
  6. 1/2 git-patch-id: test for "no newline" markersMichael J Gruber, Feb 17, 2011
  7. Jakub NarebskiFeb 17, 2011
  8. Michael J GruberFeb 17, 2011
  9. 2/2 git-patch-id: do not trip over "no newline" markersMichael J Gruber, Feb 17, 2011
  10. Jeff KingFeb 18, 2011
  11. Michael J GruberFeb 18, 2011
  12. 1/2 git-patch-id: test for "no newline" markersMichael J Gruber, Feb 18, 2011
  13. 2/2 git-patch-id: do not trip over "no newline" markersMichael J Gruber, Feb 18, 2011
  14. Jeff KingFeb 18, 2011
  15. Michael J GruberFeb 18, 2011
  16. Jeff KingFeb 18, 2011
  17. Jakub NarebskiFeb 18, 2011
  18. Jeff KingFeb 18, 2011

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.