git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Schindelin <johannes.schindelin@gmx.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: Jeff King <peff@peff.net>, git@vger.kernel.org
Subject: [PATCH v2 3/4] mark_reachable_objects(): optionally collect broken symrefs
Date: Mon, 28 Sep 2015 16:01:35 +0200	[thread overview]
Message-ID: <b0403395b261a70b7e0d31e02420930adc8d97ea.1443448748.git.johannes.schindelin@gmx.de> (raw)
In-Reply-To: <cover.1443448748.git.johannes.schindelin@gmx.de>

The behavior of `mark_reachable_objects()` without this patch is that
it warns if it encounters a broken symref. Sometimes the caller wants
to act upon broken symrefs, e.g. when garbage collecting in a repository
with a broken remote HEAD.

So let's introduce an optional parameter to collect broken symrefs. The
behavior of the function is unchanged if that parameter is `NULL`.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin/prune.c  |  2 +-
 builtin/reflog.c |  2 +-
 reachable.c      | 25 +++++++++++++++++++------
 reachable.h      |  3 ++-
 4 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/builtin/prune.c b/builtin/prune.c
index 10b03d3..d6f664f 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -136,7 +136,7 @@ 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);
+	mark_reachable_objects(&revs, 1, expire, progress, NULL);
 	stop_progress(&progress);
 	for_each_loose_file_in_objdir(get_object_directory(), prune_object,
 				      prune_cruft, prune_subdir, NULL);
diff --git a/builtin/reflog.c b/builtin/reflog.c
index f96ca2a..cb8758a 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -583,7 +583,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
 		init_revisions(&cb.cmd.revs, prefix);
 		if (flags & EXPIRE_REFLOGS_VERBOSE)
 			printf("Marking reachable objects...");
-		mark_reachable_objects(&cb.cmd.revs, 0, 0, NULL);
+		mark_reachable_objects(&cb.cmd.revs, 0, 0, NULL, NULL);
 		if (flags & EXPIRE_REFLOGS_VERBOSE)
 			putchar('\n');
 	}
diff --git a/reachable.c b/reachable.c
index 64289f3..25c4932 100644
--- a/reachable.c
+++ b/reachable.c
@@ -15,6 +15,11 @@ struct connectivity_progress {
 	unsigned long count;
 };
 
+struct add_one_data {
+	struct rev_info *revs;
+	struct string_list *broken_symrefs;
+};
+
 static void update_progress(struct connectivity_progress *cp)
 {
 	cp->count++;
@@ -25,16 +30,19 @@ static void update_progress(struct connectivity_progress *cp)
 static int add_one_ref(const char *path, const struct object_id *oid,
 		       int flag, void *cb_data)
 {
-	struct rev_info *revs = (struct rev_info *)cb_data;
+	struct add_one_data *data = (struct add_one_data *)cb_data;
 	struct object *object;
 
 	if ((flag & REF_ISSYMREF) && (flag & REF_ISBROKEN)) {
-		warning("ref is broken: %s", path);
+		if (data->broken_symrefs)
+			string_list_append(data->broken_symrefs, path);
+		else
+			warning("ref is broken: %s", path);
 		return 0;
 	}
 
 	object = parse_object_or_die(oid->hash, path);
-	add_pending_object(revs, object, "");
+	add_pending_object(data->revs, object, "");
 
 	return 0;
 }
@@ -159,9 +167,11 @@ int add_unseen_recent_objects_to_traversal(struct rev_info *revs,
 
 void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
 			    unsigned long mark_recent,
-			    struct progress *progress)
+			    struct progress *progress,
+			    struct string_list *broken_symrefs)
 {
 	struct connectivity_progress cp;
+	struct add_one_data data;
 
 	/*
 	 * Set up revision parsing, and mark us as being interested
@@ -174,11 +184,14 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
 	/* Add all refs from the index file */
 	add_index_objects_to_pending(revs, 0);
 
+	data.revs = revs;
+	data.broken_symrefs = broken_symrefs;
+
 	/* Add all external refs */
-	for_each_ref(add_one_ref, revs);
+	for_each_ref(add_one_ref, &data);
 
 	/* detached HEAD is not included in the list above */
-	head_ref(add_one_ref, revs);
+	head_ref(add_one_ref, &data);
 
 	/* Add all reflog info */
 	if (mark_reflog)
diff --git a/reachable.h b/reachable.h
index d23efc3..06f1400 100644
--- a/reachable.h
+++ b/reachable.h
@@ -5,6 +5,7 @@ struct progress;
 extern int add_unseen_recent_objects_to_traversal(struct rev_info *revs,
 						  unsigned long timestamp);
 extern void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
-				   unsigned long mark_recent, struct progress *);
+				   unsigned long mark_recent, struct progress *,
+				   struct string_list *broken_symrefs);
 
 #endif
-- 
2.5.3.windows.1.3.gc322723

  parent reply	other threads:[~2015-09-28 14:01 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 ` [PATCH 4/4] gc: remove " Johannes Schindelin
2015-09-24 17:57   ` 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         ` Johannes Schindelin [this message]
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=b0403395b261a70b7e0d31e02420930adc8d97ea.1443448748.git.johannes.schindelin@gmx.de \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /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).