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

Re: [PATCH v2 4/4] gc: remove broken symrefs

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 28, 2015, 18:49 UTC
Message-ID
<xmqqh9mecrap.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<xmqqpp12croq.fsf@gitster.mtv.corp.google.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 20 quoted lines
> Johannes Schindelin <johannes.schindelin@gmx.de> writes:
>
>> When encountering broken symrefs, such as a stale remote HEAD (which can
>> happen if the active branch was renamed in the remote), it is more
>> helpful to remove those symrefs than to exit with an error.
>
> I think this depends on the perspective.  One side of me says that a
> remote HEAD that points at refs/remotes/origin/topic that no longer
> exists is still giving me a valuable information and it should take
> a conscious action by the user to remove it, or evne better to
> repoint it to a more useful place.  And from that point of view,
> removing is not all that helpful.  Keeping them and not allowing
> them to exit with an error would be a real improvement.
>
> On the other hand, I can certainly understand a view that considers
> that such a dangling symbolic ref is merely a cruft like any other
> cruft, and "gc" is all about removing cruft.
>
> It just feels to me that this is a bit more valuable than other
> kinds of cruft, but maybe it is just me.

Sorry, it is a bad habit of me to send out without concluding remark, leaving the recipient hanging without knowing what the next step should be.

I meant to say that I plan to, and I indeed did, queue these 4 without changes. I am not opposed to the removal so strongly to reject [4/4].

The above comment was that I just do not know if this is the right thing to do, or it will be hurting users.

Thanks.
Show 67 quoted lines
>
>>
>> This fixes https://github.com/git-for-windows/git/issues/423
>>
>> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
>> ---
>>  builtin/prune.c | 12 +++++++++++-
>>  t/t6500-gc.sh   |  2 +-
>>  2 files changed, 12 insertions(+), 2 deletions(-)
>>
>> diff --git a/builtin/prune.c b/builtin/prune.c
>> index d6f664f..337b12a 100644
>> --- a/builtin/prune.c
>> +++ b/builtin/prune.c
>> @@ -6,6 +6,7 @@
>>  #include "reachable.h"
>>  #include "parse-options.h"
>>  #include "progress.h"
>> +#include "refs.h"
>>  
>>  static const char * const prune_usage[] = {
>>  	N_("git prune [-n] [-v] [--expire <time>] [--] [<head>...]"),
>> @@ -100,6 +101,7 @@ static void remove_temporary_files(const char *path)
>>  int cmd_prune(int argc, const char **argv, const char *prefix)
>>  {
>>  	struct rev_info revs;
>> +	struct string_list broken_symrefs = STRING_LIST_INIT_DUP;
>>  	struct progress *progress = NULL;
>>  	const struct option options[] = {
>>  		OPT__DRY_RUN(&show_only, N_("do not remove, show only")),
>> @@ -110,6 +112,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
>>  		OPT_END()
>>  	};
>>  	char *s;
>> +	int i;
>>  
>>  	expire = ULONG_MAX;
>>  	save_commit_buffer = 0;
>> @@ -136,7 +139,14 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
>>  	if (show_progress)
>>  		progress = start_progress_delay(_("Checking connectivity"), 0, 0, 2);
>>  
>> -	mark_reachable_objects(&revs, 1, expire, progress, NULL);
>> +	revs.ignore_missing = 1;
>> +	mark_reachable_objects(&revs, 1, expire, progress, &broken_symrefs);
>> +	for (i = 0; i < broken_symrefs.nr; i++) {
>> +		char *path = broken_symrefs.items[i].string;
>> +		printf("Removing stale ref %s\n", path);
>> +		if (!show_only && delete_ref(path, NULL, REF_NODEREF))
>> +			die("Could not remove stale ref %s", path);
>> +	}
>>  	stop_progress(&progress);
>>  	for_each_loose_file_in_objdir(get_object_directory(), prune_object,
>>  				      prune_cruft, prune_subdir, NULL);
>> diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh
>> index b736774..0ae4271 100755
>> --- a/t/t6500-gc.sh
>> +++ b/t/t6500-gc.sh
>> @@ -30,7 +30,7 @@ test_expect_success 'gc -h with invalid configuration' '
>>  	test_i18ngrep "[Uu]sage" broken/usage
>>  '
>>  
>> -test_expect_failure 'gc removes broken refs/remotes/<name>/HEAD' '
>> +test_expect_success 'gc removes broken refs/remotes/<name>/HEAD' '
>>  	git init remote &&
>>  	(
>>  		cd remote &&
Previous: Junio C HamanoNext: Johannes Schindelin
Message 17 of 28 in “Fix gc failure when a remote HEAD goes stale”
  1. 0/4 Fix gc failure when a remote HEAD goes staleJohannes Schindelin, Sep 24, 2015
  2. 1/4 gc: demonstrate failure with stale remote HEADJohannes Schindelin, Sep 24, 2015
  3. 2/4 pack-objects: do not get distracted by stale refsJohannes Schindelin, Sep 24, 2015
  4. Jeff KingSep 24, 2015
  5. 3/4 mark_reachable_objects(): optionally collect broken refsJohannes Schindelin, Sep 24, 2015
  6. Jeff KingSep 24, 2015
  7. 4/4 gc: remove broken refsJohannes Schindelin, Sep 24, 2015
  8. Jeff KingSep 24, 2015
  9. Junio C HamanoSep 25, 2015
  10. Jeff KingSep 25, 2015
  11. 0/4 Fix gc failure when a remote HEAD goes staleJohannes Schindelin, Sep 28, 2015
  12. 1/4 gc: demonstrate failure with stale remote HEADJohannes Schindelin, Sep 28, 2015
  13. 2/4 pack-objects: do not get distracted by broken symrefsJohannes Schindelin, Sep 28, 2015
  14. 3/4 mark_reachable_objects(): optionally collect broken symrefsJohannes Schindelin, Sep 28, 2015
  15. 4/4 gc: remove broken symrefsJohannes Schindelin, Sep 28, 2015
  16. Junio C HamanoSep 28, 2015
  17. Junio C HamanoSep 28, 2015
  18. Johannes SchindelinSep 28, 2015
  19. Junio C HamanoOct 5, 2015
  20. Jeff KingSep 28, 2015
  21. Johannes SchindelinSep 28, 2015
  22. 0/2 Fix gc failure when a remote HEAD goes staleJohannes Schindelin, Oct 6, 2015
  23. 1/2 gc: demonstrate failure with stale remote HEADJohannes Schindelin, Oct 6, 2015
  24. 2/2 pack-objects: do not get distracted by broken symrefsJohannes Schindelin, Oct 6, 2015
  25. Junio C HamanoOct 7, 2015
  26. Johannes SchindelinOct 8, 2015
  27. Junio C HamanoOct 8, 2015
  28. Johannes SchindelinOct 8, 2015

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.