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

[PATCH 4/6] WIP: mess only with mark_reachable

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Feb 26, 2016, 16:39 UTC
Message-ID
<b318af9a93f1d49f4480d63b74fa07d4b605f16b.1456504190.git.git@drmicha.warpmail.net>
In-Reply-To
<cover.1456504190.git.git@drmicha.warpmail.net>

This still messes up gc/prune on an empty repo where the worktree code can't parse HEAD properly. Bummer. That code sucks for the non-worktree case.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
 reachable.c          |  2 +-
 refs.h               |  1 +
 refs/files-backend.c | 23 +++++++++++++++++++++++
 3 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/reachable.c b/reachable.c
index ed35201..15a06a7 100644
--- a/reachable.c
+++ b/reachable.c
@@ -177,7 +177,7 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
 	for_each_ref(add_one_ref, revs);
 
 	/* detached HEAD is not included in the list above */
-	head_ref(add_one_ref, revs);
+	head_ref_worktrees(add_one_ref, revs);
 
 	/* Add all reflog info */
 	if (mark_reflog)
diff --git a/refs.h b/refs.h
index 2f3decb..c9621b4 100644
--- a/refs.h
+++ b/refs.h
@@ -183,6 +183,7 @@ typedef int each_ref_fn(const char *refname,
  * stop the iteration.
  */
 extern int head_ref(each_ref_fn fn, void *cb_data);
+extern int head_ref_worktrees(each_ref_fn fn, void *cb_data);
 extern int for_each_ref(each_ref_fn fn, void *cb_data);
 extern int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data);
 extern int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data, unsigned int broken);
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 5bdb568..f020c52 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1749,6 +1749,24 @@ static int do_for_each_ref(struct ref_cache *refs, const char *base,
 static int do_head_ref(const char *submodule, each_ref_fn fn, void *cb_data)
 {
 	struct object_id oid;
+	int flag;
+
+	if (submodule) {
+		if (resolve_gitlink_ref(submodule, "HEAD", oid.hash) == 0)
+			return fn("HEAD", &oid, 0, cb_data);
+
+		return 0;
+	}
+
+	if (!read_ref_full("HEAD", RESOLVE_REF_READING, oid.hash, &flag))
+		return fn("HEAD", &oid, flag, cb_data);
+
+	return 0;
+}
+
+static int do_head_ref_worktrees(const char *submodule, each_ref_fn fn, void *cb_data)
+{
+	struct object_id oid;
 	struct worktree **worktrees;
 	int i, retval;
 
@@ -1775,6 +1793,11 @@ int head_ref(each_ref_fn fn, void *cb_data)
 	return do_head_ref(NULL, fn, cb_data);
 }
 
+int head_ref_worktrees(each_ref_fn fn, void *cb_data)
+{
+	return do_head_ref_worktrees(NULL, fn, cb_data);
+}
+
 int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
 {
 	return do_head_ref(submodule, fn, cb_data);
-- 
2.7.2.618.g7a61b68
Previous: Duy NguyenNext: Michael J Gruber
Message 8 of 11 in “Detached HEADs in new worktrees considered harmful”
  1. 0/6 Detached HEADs in new worktrees considered harmfulMichael J Gruber, Feb 26, 2016
  2. 1/6 Documentation/git-worktree: spell --detach correctlyMichael J Gruber, Feb 26, 2016
  3. Junio C HamanoFeb 26, 2016
  4. 2/6 t6014: test prune with detached HEADs in separate worktreesMichael J Gruber, Feb 26, 2016
  5. Junio C HamanoFeb 26, 2016
  6. 3/6 rev-list: list all heads with --allMichael J Gruber, Feb 26, 2016
  7. Duy NguyenFeb 27, 2016
  8. 4/6 WIP: mess only with mark_reachableMichael J Gruber, Feb 26, 2016
  9. 5/6 WIP: fix unborn branch caseMichael J Gruber, Feb 26, 2016
  10. 6/6 revisions: list all worktree HEADs with --allMichael J Gruber, Feb 26, 2016
  11. Junio C HamanoFeb 26, 2016

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.