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

Re: [PATCH 1/4] add mode parameter to get_sha1

From
Junio C Hamano <junkio@cox.net>
Date
Apr 21, 2007, 18:42 UTC
Message-ID
<7vps5xtvqw.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<1177158380197-git-send-email-mkoegler@auto.tuwien.ac.at>
Martin Koegler <mkoegler@auto.tuwien.ac.at> writes:
> If the mode parameter is not NULL, get_sha1 will store
> the mode of the object in it.

Most existing callers pass NULL to this. Wouldn't it be cleaner to have a new get_sha1_with_mode() function, and convert the callers that care about mode to use it, like this?

int get_sha1(const char *str, unsigned char sha1[20]) {
	unsigned discard;
        return get_sha1_with_mode(str, sha1, &discard);
}

That way, your patch would be much easier to review and would have less chance of getting it wrong. I wonder if [2/4] can be made less impact using a similar trick. Most of the existing callers that place objects in object_array do not know the mode. Only some do.

+/* unknown mode */ +#define S_IFINVALID 0320000 +

This hunk does not belong to [1/4]; it is part of [2/4].

Typically S_IF$TYPE macros are masked with S_IFMT (0170000) before being used, so the above value is *obviously* invalid, but it also risks our code would treat it as a symlink, we do the masking before comparison. I wonder if defining it to S_IFMT mask itself might be a safer option.

Previous: Martin KoeglerNext: Alex Riesen
Message 5 of 6 in “add mode parameter to get_sha1”
  1. 1/4 add mode parameter to get_sha1Martin Koegler, Apr 21, 2007
  2. 2/4 add support for storing the mode in object_arrayMartin Koegler, Apr 21, 2007
  3. 3/4 add mode to add_pending_objectMartin Koegler, Apr 21, 2007
  4. 4/4 use the mode information of the tree, if <SHA1>:file name syntax is usedMartin Koegler, Apr 21, 2007
  5. Junio C HamanoApr 21, 2007
  6. Alex RiesenApr 21, 2007

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.