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

Re: [PATCH 1/4] sha1_name: introduce getn_sha1() to take length

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Apr 4, 2012, 07:35 UTC
Message-ID
<vpqr4w40x1d.fsf@bauges.imag.fr>
In-Reply-To
<20120403220817.GE19858@burratino>
Jonathan Nieder <jrnieder@gmail.com> writes:
> (cc-ing Clément who is one of the last people to change this family of
>  APIs, and Matthieu who knows these codepaths well and may have been a
>  mentor for that project)
I wouldn't say I know them well, but I did touch them in the past.
> Holy cow this function is going crazy.  So let's take a survey of
> the public functions in this family.
>
>  [... nice explanations of different functions ...]

Good job. I think your explanations could actually be added as comments to cache.h to document the corresponding functions.

> My first reaction is that the meaning of the _1 suffix is not going to
> be obvious to newcomers.  Any ideas for addressing that?

It seems I'm the one who introduced get_sha1_with_context_1. I meant "internal variant of the one without _1", which is a convention used in other places of Git's code, but usually as static functions, not in .h files.

> "get_sha1_with_context_1" has no external callers so it could probably
> be made private.

I kept it public as a very small implementation detail: I tried not to introduce performance penalty, hence made get_sha1_with_mode inline (since it is really a trivial wrapper). But we probably wouldn't notice the difference in performance making the _1 version private and losing the "static inline"-ness of the public version.

Another way to say this is: get_sha1_with_context_1() does the real job (perhaps it should be called get_sha1_real()?), and others are convenience wrappers. Since convenience wrappers are convenient, nobody use the actual function directly.

> Or maybe it makes sense to bite the bullet and add the length
> argument to all callers:

I don't think so. Convenience wrappers are meant to be simple to call, and I don't think we want to force everybody to call strlen() before calling them.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: Jonathan NiederNext: Ramkumar Ramachandra
Message 4 of 11 in “Minor sequencer.c cleanups”
  1. 0/4 Minor sequencer.c cleanupsRamkumar Ramachandra, Mar 29, 2012
  2. 1/4 sha1_name: introduce getn_sha1() to take lengthRamkumar Ramachandra, Mar 29, 2012
  3. Jonathan NiederApr 3, 2012
  4. Matthieu MoyApr 4, 2012
  5. Ramkumar RamachandraApr 4, 2012
  6. Jonathan NiederApr 4, 2012
  7. 2/4 revert: use getn_sha1() to simplify insn parsingRamkumar Ramachandra, Mar 29, 2012
  8. 3/4 revert: simplify insn parsing logicRamkumar Ramachandra, Mar 29, 2012
  9. Junio C HamanoApr 2, 2012
  10. Ramkumar RamachandraApr 3, 2012
  11. 4/4 revert: report fine-grained errors from insn parserRamkumar Ramachandra, Mar 29, 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.