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

Re: [PATCH 2/4] split-index; stop abusing the `base_oid` to strip the "link" extension

From
JHJeff Hostetler <git@jeffhostetler.com>
Date
Mar 23, 2023, 13:59 UTC
Message-ID
<ba23850b-0fc5-4a82-49df-88550ae8b4ed@jeffhostetler.com>
In-Reply-To
<xmqqjzz8cwdp.fsf@gitster.g>
On 3/22/23 5:24 PM, Junio C Hamano wrote:
Show 29 quoted lines
> "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
> writes:
> 
>> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>>
>> When a split-index is in effect, the `$GIT_DIR/index` file needs to
>> contain a "link" extension that contains all the information about the
>> split-index, including the information about the shared index.
>> ...
>> Let's stop zeroing out the `base_oid` to indicate that the "link"
>> extension should not be written.
> 
> Nicely explained.
> 
>> One might be tempted to simply call `discard_split_index()` instead,
>> under the assumption that Git decided to write a non-split index and
>> therefore the the `split_index` structure might no longer be wanted.
> 
> "the the".
> 
>> +enum strip_extensions {
>> +	WRITE_ALL_EXTENSIONS = 0,
>> +	STRIP_ALL_EXTENSIONS = 1,
>> +	STRIP_LINK_EXTENSION_ONLY = 2
>> +};
> 
> We do not need to spell out the specific values for this enum; the
> users' (i.e. the callers of do_write_index()) sole requirement is
> for these symbols to have different values.

There are several calls to do_write_locked_index() that pass 0 or 1 as the new final arg. If we update them to use these enum values, then we don't need integer values here.

Show 12 quoted lines
> 
> Also do we envision that (1) we would need to keep STRIP_LINK_ONLY
> to be with the largest value among the enum values, or (2) we would
> never add new value to the set?  Otherwise let's end the last one
> with a trailing comma.
> 
> Looking at the way strip_extensions variable is used in
> do_write_index(), an alternative design might be to make it a set of
> bits (e.g. unsigned write_extension) and give one bit to each
> extension.  But such a clean-up is better left outside the topic, I
> would imagine, as we do not have any need to skip an arbitrary set
> of extensions right now.

Agreed, I thought about suggesting a set of bits too, but right now we only need to strip all of them or just this one.

Show 25 quoted lines
> 
>> +/*
>> + * Write the Git index into a `.lock` file
>> + *
>> + * If `strip_link_extension` is non-zero, avoid writing any "link" extension
>> + * (used by the split-index feature).
>> + */
> 
> Not exposing "enum strip_extensions" to the caller of this function,
> like this patch does, is probably a very safe and sensible thing to
> do.  We do not have a reason to allow its callers to (perhaps
> mistakenly) pass STRIP_ALL_EXTENSIONS to it.
> 
>>   static int do_write_locked_index(struct index_state *istate, struct lock_file *lock,
>> -				 unsigned flags)
>> +				 unsigned flags, int strip_link_extension)
>>   {
>>   	int ret;
>>   	int was_full = istate->sparse_index == INDEX_EXPANDED;
>> @@ -3185,7 +3197,7 @@ static int do_write_locked_index(struct index_state *istate, struct lock_file *l
>>   	 */
>>   	trace2_region_enter_printf("index", "do_write_index", the_repository,
>>   				   "%s", get_lock_file_path(lock));
>> -	ret = do_write_index(istate, lock->tempfile, 0, flags);
>> +	ret = do_write_index(istate, lock->tempfile, strip_link_extension ? STRIP_LINK_EXTENSION_ONLY : 0, flags);

In the else of the ?: operator, could we use the WRITE_ALL_EXTENSIONS instead of 0?

Show 7 quoted lines
>>   	trace2_region_leave_printf("index", "do_write_index", the_repository,
>>   				   "%s", get_lock_file_path(lock));
>>   
> 
> OK.
> 
> Very nicely done.
Previous: Junio C HamanoNext: Junio C Hamano
Message 6 of 19 in “Fix a few split-index bugs”
  1. 0/4 Fix a few split-index bugsJohannes Schindelin via GitGitGadget, Mar 22, 2023
  2. 1/4 split-index & fsmonitor: demonstrate a bugJohannes Schindelin via GitGitGadget, Mar 22, 2023
  3. Jeff HostetlerMar 23, 2023
  4. 2/4 split-index; stop abusing the `base_oid` to strip the "link" extensionJohannes Schindelin via GitGitGadget, Mar 22, 2023
  5. Junio C HamanoMar 22, 2023
  6. Jeff HostetlerMar 23, 2023
  7. Junio C HamanoMar 23, 2023
  8. Jeff HostetlerMar 23, 2023
  9. 3/4 fsmonitor: avoid overriding `cache_changed` bitsJohannes Schindelin via GitGitGadget, Mar 22, 2023
  10. 4/4 unpack-trees: take care to propagate the split-index flagJohannes Schindelin via GitGitGadget, Mar 22, 2023
  11. Jeff HostetlerMar 23, 2023
  12. Junio C HamanoMar 22, 2023
  13. 0/4 Fix a few split-index bugsJohannes Schindelin via GitGitGadget, Mar 26, 2023
  14. 3/4 fsmonitor: avoid overriding `cache_changed` bitsJohannes Schindelin via GitGitGadget, Mar 26, 2023
  15. 2/4 split-index; stop abusing the `base_oid` to strip the "link" extensionJohannes Schindelin via GitGitGadget, Mar 26, 2023
  16. 1/4 split-index & fsmonitor: demonstrate a bugJohannes Schindelin via GitGitGadget, Mar 26, 2023
  17. 4/4 unpack-trees: take care to propagate the split-index flagJohannes Schindelin via GitGitGadget, Mar 26, 2023
  18. Jeff HostetlerMar 27, 2023
  19. Junio C HamanoMar 27, 2023

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.