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

Re: Recommendation for consistent update on invoke of "sha1_to_hex()"

From
Jeff King <peff@peff.net>
Date
Jan 5, 2018, 07:08 UTC
Message-ID
<20180105070821.GB14251@sigill.intra.peff.net>
In-Reply-To
<fb56cfe.6744.160c45a9e5a.Coremail.niuxu16@nudt.edu.cn>
On Fri, Jan 05, 2018 at 11:26:01AM +0800, 牛旭 wrote:
> By mining historical patches, we suggest that invokes of sha1_to_hex()
> should be replaced with that of oid_to_hex(). One example for
> recommendation and corresponding patch are listed as follows. 

Note that these two functions take different types. If you only have a "const unsigned char *", then you must use sha1_to_hex(). If you have a "struct object_id", then you should be using oid_to_hex(). If there are sites which do:

  sha1_to_hex(oid.hash)

those should be converted to use oid_to_hex(). I think there's a coccinelle rule for this, though, so there shouldn't be any lingering calls like that.

Of course the ultimate goal is for every function to use oid_to_hex(). But that's much bigger than a single-line change, since groups of dependent functions need to be converted (try "git log --author=carlson" to see example patches).

Show 11 quoted lines
> One example of missed spot:
> 1  void assert_sha1_type(const unsigned char *sha1, enum 
>   object_type expect)
> 2 {
> 3  enum object_type type = sha1_object_info(sha1, NULL);
> 4  if (type < 0)
> 5   die("%s is not a valid object",sha1_to_hex(sha1));
> 6  if (type != expect)
> 7   die("%s is not a valid '%s' object", sha1_to_hex(sha1),
> 8  typename(expect));
> 9 }

So this is an example that doesn't convert easily. The function has only the bare pointer, so you'd have to change its parameter list (and therefore all of its callers).

-Peff
Previous: 牛旭
Message 2 of 2 in “Recommendation for consistent update on invoke of "sha1_to_hex()"”
  1. 牛旭Jan 5, 2018
  2. Jeff KingJan 5, 2018

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.