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

Re: [PATCH] gc --auto: release pack files before auto packing

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 6, 2018, 16:39 UTC
Message-ID
<xmqqpo00mi7q.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20180630145849.GA9416@duynguyen.home>
Duy Nguyen <pclouds@gmail.com> writes:
Show 50 quoted lines
> On Sat, Jun 30, 2018 at 03:38:21PM +0200, Kim Gybels wrote:
>> Teach gc --auto to release pack files before auto packing the repository
>> to prevent failures when removing them.
>> 
>> Also teach the test 'fetching with auto-gc does not lock up' to complain
>> when it is no longer triggering an auto packing of the repository.
>> 
>> Fixes https://github.com/git-for-windows/git/issues/500
>> 
>> Signed-off-by: Kim Gybels <kgybels@infogroep.be>
>> ---
>> 
>> Patch based on master, since problem doesn't reproduce on maint,
>> however, the improvement to the test might be valuable on maint.
>> 
>>  builtin/gc.c     | 1 +
>>  t/t5510-fetch.sh | 2 ++
>>  2 files changed, 3 insertions(+)
>> 
>> diff --git a/builtin/gc.c b/builtin/gc.c
>> index ccfb1ceaeb..63b62ab57c 100644
>> --- a/builtin/gc.c
>> +++ b/builtin/gc.c
>> @@ -612,6 +612,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
>>  		return -1;
>>  
>>  	if (!repository_format_precious_objects) {
>> +		close_all_packs(the_repository->objects);
>
> We have repo_clear() which does this and potentially closing file
> descriptors on other things as well. I suggest we use it, and before
> any external command is run. Something like
>
> diff --git a/builtin/gc.c b/builtin/gc.c
> index ccfb1ceaeb..a852c71da6 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -473,6 +473,13 @@ static int report_last_gc_error(void)
>  
>  static int gc_before_repack(void)
>  {
> +	/*
> +	 * Shut down everything, we should have all the info we need
> +	 * at this point. Leaving some file descriptors open may
> +	 * prevent them from being removed on Windows.
> +	 */
> +	repo_clear(the_repository);
> +
>  	if (pack_refs && run_command_v_opt(pack_refs_cmd.argv, RUN_GIT_CMD))
>  		return error(FAILED_RUN, pack_refs_cmd.argv[0]);
With 
  https://public-inbox.org/git/20180509170409.13666-1-pclouds@gmail.com/

the call to repo_clear() on the_repository itself may be safe [*1*], but if command line parsing code etc. has pointers to in-core object etc. obtained before this function was called, the codeflow after this function returns will be quite disturbed. Has anybody in this review thread audited the codeflow _after_ this function is run to make sure that invalidating in-core repository here does not cause us problems? Just checking, because I won't queue this change until I hear that somebody familiar with the codepath actually did so (I may get around to do so myself later).

Thanks.
[Footnote]
*1* ... and of course changing the_index to &the_repo->index would
    make it even safer ;-)
Previous: Duy NguyenNext: SZEDER Gábor
Message 3 of 11 in “gc --auto: release pack files before auto packing”
  1. gc --auto: release pack files before auto packingKim Gybels, Jun 30, 2018
  2. Duy NguyenJun 30, 2018
  3. Junio C HamanoJul 6, 2018
  4. SZEDER GáborJul 7, 2018
  5. Kim GybelsJul 7, 2018
  6. Duy NguyenJul 9, 2018
  7. Junio C HamanoJul 9, 2018
  8. Duy NguyenJul 11, 2018
  9. gc --auto: clear repository before auto packingKim Gybels, Jul 4, 2018
  10. SZEDER GáborJul 7, 2018
  11. gc --auto: release pack files before auto packingKim Gybels, Jul 9, 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.