git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Schindelin <johannes.schindelin@gmx.de>
To: gitster@pobox.com
Cc: git@vger.kernel.org
Subject: [PATCH 4/4] gc: remove broken refs
Date: Thu, 24 Sep 2015 11:14:02 +0200	[thread overview]
Message-ID: <8855bae256311446dffd221ab33c1163eb104c4a.1443085919.git.johannes.schindelin@gmx.de> (raw)
In-Reply-To: <cover.1443085919.git.johannes.schindelin@gmx.de>

When encountering broken refs, 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 refs than to exit with an error.

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..1a30f65 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_refs = 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_refs);
+	for (i = 0; i < broken_refs.nr; i++) {
+		char *path = broken_refs.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 &&
-- 
2.5.2.windows.2

  parent reply	other threads:[~2015-09-24  9:14 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-24  9:13 [PATCH 0/4] Fix gc failure when a remote HEAD goes stale Johannes Schindelin
2015-09-24  9:13 ` [PATCH 1/4] gc: demonstrate failure with stale remote HEAD Johannes Schindelin
2015-09-24  9:13 ` [PATCH 2/4] pack-objects: do not get distracted by stale refs Johannes Schindelin
2015-09-24 17:03   ` Jeff King
2015-09-24  9:13 ` [PATCH 3/4] mark_reachable_objects(): optionally collect broken refs Johannes Schindelin
2015-09-24 17:56   ` Jeff King
2015-09-24  9:14 ` Johannes Schindelin [this message]
2015-09-24 17:57   ` [PATCH 4/4] gc: remove " Jeff King
2015-09-25  0:08     ` Junio C Hamano
2015-09-25  1:35       ` Jeff King
2015-09-28 14:01       ` [PATCH v2 0/4] Fix gc failure when a remote HEAD goes stale Johannes Schindelin
2015-09-28 14:01         ` [PATCH v2 1/4] gc: demonstrate failure with stale remote HEAD Johannes Schindelin
2015-09-28 14:01         ` [PATCH v2 2/4] pack-objects: do not get distracted by broken symrefs Johannes Schindelin
2015-09-28 14:01         ` [PATCH v2 3/4] mark_reachable_objects(): optionally collect " Johannes Schindelin
2015-09-28 14:02         ` [PATCH v2 4/4] gc: remove " Johannes Schindelin
2015-09-28 18:41           ` Junio C Hamano
2015-09-28 18:49             ` Junio C Hamano
2015-09-28 19:58               ` Johannes Schindelin
2015-10-05 22:06                 ` Junio C Hamano
2015-09-28 19:03           ` Jeff King
2015-09-28 20:05             ` Johannes Schindelin
2015-10-06 13:57       ` [PATCH v3 0/2] Fix gc failure when a remote HEAD goes stale Johannes Schindelin
2015-10-06 13:58         ` [PATCH v3 1/2] gc: demonstrate failure with stale remote HEAD Johannes Schindelin
2015-10-06 13:59         ` [PATCH v3 2/2] pack-objects: do not get distracted by broken symrefs Johannes Schindelin
2015-10-07 17:45           ` Junio C Hamano
2015-10-08 19:15             ` Johannes Schindelin
2015-10-08 19:42               ` Junio C Hamano
2015-10-08 20:10                 ` Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8855bae256311446dffd221ab33c1163eb104c4a.1443085919.git.johannes.schindelin@gmx.de \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).