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

Re: [PATCH 1/1] sha1-file: split OBJECT_INFO_FOR_PREFETCH

From
Jeff King <peff@peff.net>
Date
May 28, 2019, 20:54 UTC
Message-ID
<20190528205441.GB24650@sigill.intra.peff.net>
In-Reply-To
<2737e62966cae2f00d75a93446bad76e5816d07e.1559056745.git.gitgitgadget@gmail.com>
On Tue, May 28, 2019 at 08:19:07AM -0700, Derrick Stolee via GitGitGadget wrote:
Show 17 quoted lines
> From: Derrick Stolee <dstolee@microsoft.com>
> 
> The OBJECT_INFO_FOR_PREFETCH bitflag was added to sha1-file.c in 0f4a4fb1
> (sha1-file: support OBJECT_INFO_FOR_PREFETCH, 2019-03-29) and is used to
> prevent the fetch_objects() method when enabled.
> 
> However, there is a problem with the current use. The definition of
> OBJECT_INFO_FOR_PREFETCH is given by adding 32 to OBJECT_INFO_QUICK. This is
> clearly stated above the definition (in a comment) that this is so
> OBJECT_INFO_FOR_PREFETCH implies OBJECT_INFO_QUICK. The problem is that using
> "flag & OBJECT_INFO_FOR_PREFETCH" means that OBJECT_INFO_QUICK also implies
> OBJECT_INFO_FOR_PREFETCH.
> 
> Split out the single bit from OBJECT_INFO_FOR_PREFETCH into a new
> OBJECT_INFO_SKIP_FETCH_OBJECT as the single bit and keep
> OBJECT_INFO_FOR_PREFETCH as the union of two flags. This allows a clearer use
> of flag checking while also keeping the implication of OBJECT_INFO_QUICK.

Oof. I actually suggested splitting these up for review, but thought it was only a clarity/flexibility issue, and completely missed the correctness aspect of checking when the bit is set.

I agree with Junio's other response that using "==" would be the right way for a multi-bit check, in general. But I like the split here, because I think the result is more clear to read and harder to get wrong for future checks.

I'd even go so far as to say...
> + * This is meant for bulk prefetching of missing blobs in a partial
> + * clone. Implies OBJECT_INFO_SKIP_FETCH_OBJECT and OBJECT_INFO_QUICK
> + */
> +#define OBJECT_INFO_FOR_PREFETCH (OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK)

we could dump this, and callers should just say what they mean (i.e., specify both flags).

There are only two of them, and I think both would be more readable with a helper more like:

  int should_prefetch_object(struct repository *r,
                             const struct object_id *oid) {
	return !oid_object_info_extended(r, oid, NULL,
	                                 OBJECT_INFO_SKIP_FETCH_OBJECT |
					 OBJECT_INFO_QUICK);
  }

but unless everybody is immediately on-board with "yes, that is much nicer", I don't want bikeshedding to hold up your important and obviously-correct fix.

-Peff
Previous: Junio C HamanoNext: Derrick Stolee
Message 4 of 5 in “sha1-file: split OBJECT_INFO_FOR_PREFETCH”
  1. 0/1 sha1-file: split OBJECT_INFO_FOR_PREFETCHDerrick Stolee via GitGitGadget, May 28, 2019
  2. 1/1 sha1-file: split OBJECT_INFO_FOR_PREFETCHDerrick Stolee via GitGitGadget, May 28, 2019
  3. Junio C HamanoMay 28, 2019
  4. Jeff KingMay 28, 2019
  5. Derrick StoleeMay 29, 2019

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.