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

[PATCH v4 08/16] revision.c: use refs_for_each*() instead of for_each_*_submodule()

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Aug 23, 2017, 12:36 UTC
Message-ID
<20170823123704.16518-9-pclouds@gmail.com>
In-Reply-To
<20170823123704.16518-1-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 refs.c     |  9 ++++-----
 refs.h     |  6 +++---
 revision.c | 48 ++++++++++++++++++++++++++++++++----------------
 3 files changed, 39 insertions(+), 24 deletions(-)
diff --git a/refs.c b/refs.c
index b3a0a24469..cd61509bc8 100644
--- a/refs.c
+++ b/refs.c
@@ -1362,16 +1362,15 @@ int for_each_ref_in_submodule(const char *submodule, const char *prefix,
 				    prefix, fn, cb_data);
 }
 
-int for_each_fullref_in_submodule(const char *submodule, const char *prefix,
-				  each_ref_fn fn, void *cb_data,
-				  unsigned int broken)
+int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,
+			     each_ref_fn fn, void *cb_data,
+			     unsigned int broken)
 {
 	unsigned int flag = 0;
 
 	if (broken)
 		flag = DO_FOR_EACH_INCLUDE_BROKEN;
-	return do_for_each_ref(get_submodule_ref_store(submodule),
-			       prefix, fn, 0, flag, cb_data);
+	return do_for_each_ref(refs, prefix, fn, 0, flag, cb_data);
 }
 
 int for_each_replace_ref(each_ref_fn fn, void *cb_data)
diff --git a/refs.h b/refs.h
index 8073f8ab56..a8d6f33703 100644
--- a/refs.h
+++ b/refs.h
@@ -291,6 +291,9 @@ int refs_for_each_remote_ref(struct ref_store *refs,
 int head_ref(each_ref_fn fn, void *cb_data);
 int for_each_ref(each_ref_fn fn, void *cb_data);
 int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data);
+int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,
+			     each_ref_fn fn, void *cb_data,
+			     unsigned int broken);
 int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data,
 			unsigned int broken);
 int for_each_tag_ref(each_ref_fn fn, void *cb_data);
@@ -306,9 +309,6 @@ int for_each_ref_submodule(const char *submodule,
 			   each_ref_fn fn, void *cb_data);
 int for_each_ref_in_submodule(const char *submodule, const char *prefix,
 			      each_ref_fn fn, void *cb_data);
-int for_each_fullref_in_submodule(const char *submodule, const char *prefix,
-				  each_ref_fn fn, void *cb_data,
-				  unsigned int broken);
 int for_each_tag_ref_submodule(const char *submodule,
 			       each_ref_fn fn, void *cb_data);
 int for_each_branch_ref_submodule(const char *submodule,
diff --git a/revision.c b/revision.c
index f35cb49af5..8d04516266 100644
--- a/revision.c
+++ b/revision.c
@@ -1188,12 +1188,19 @@ void add_ref_exclusion(struct string_list **ref_excludes_p, const char *exclude)
 	string_list_append(*ref_excludes_p, exclude);
 }
 
-static void handle_refs(const char *submodule, struct rev_info *revs, unsigned flags,
-		int (*for_each)(const char *, each_ref_fn, void *))
+static void handle_refs(struct ref_store *refs,
+			struct rev_info *revs, unsigned flags,
+			int (*for_each)(struct ref_store *, each_ref_fn, void *))
 {
 	struct all_refs_cb cb;
+
+	if (!refs) {
+		/* this could happen with uninitialized submodules */
+		return;
+	}
+
 	init_all_refs_cb(&cb, revs, flags);
-	for_each(submodule, handle_one_ref, &cb);
+	for_each(refs, handle_one_ref, &cb);
 }
 
 static void handle_one_reflog_commit(struct object_id *oid, void *cb_data)
@@ -2095,23 +2102,25 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
 	ctx->argc -= n;
 }
 
-static int for_each_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_data, const char *term) {
+static int for_each_bisect_ref(struct ref_store *refs, each_ref_fn fn,
+			       void *cb_data, const char *term)
+{
 	struct strbuf bisect_refs = STRBUF_INIT;
 	int status;
 	strbuf_addf(&bisect_refs, "refs/bisect/%s", term);
-	status = for_each_fullref_in_submodule(submodule, bisect_refs.buf, fn, cb_data, 0);
+	status = refs_for_each_fullref_in(refs, bisect_refs.buf, fn, cb_data, 0);
 	strbuf_release(&bisect_refs);
 	return status;
 }
 
-static int for_each_bad_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_data)
+static int for_each_bad_bisect_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
 {
-	return for_each_bisect_ref(submodule, fn, cb_data, term_bad);
+	return for_each_bisect_ref(refs, fn, cb_data, term_bad);
 }
 
-static int for_each_good_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_data)
+static int for_each_good_bisect_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
 {
-	return for_each_bisect_ref(submodule, fn, cb_data, term_good);
+	return for_each_bisect_ref(refs, fn, cb_data, term_good);
 }
 
 static int handle_revision_pseudo_opt(const char *submodule,
@@ -2120,8 +2129,14 @@ static int handle_revision_pseudo_opt(const char *submodule,
 {
 	const char *arg = argv[0];
 	const char *optarg;
+	struct ref_store *refs;
 	int argcount;
 
+	if (submodule) {
+		refs = get_submodule_ref_store(submodule);
+	} else
+		refs = get_main_ref_store();
+
 	/*
 	 * NOTE!
 	 *
@@ -2133,22 +2148,23 @@ static int handle_revision_pseudo_opt(const char *submodule,
 	 * register it in the list at the top of handle_revision_opt.
 	 */
 	if (!strcmp(arg, "--all")) {
-		handle_refs(submodule, revs, *flags, for_each_ref_submodule);
-		handle_refs(submodule, revs, *flags, head_ref_submodule);
+		handle_refs(refs, revs, *flags, refs_for_each_ref);
+		handle_refs(refs, revs, *flags, refs_head_ref);
 		clear_ref_exclusion(&revs->ref_excludes);
 	} else if (!strcmp(arg, "--branches")) {
-		handle_refs(submodule, revs, *flags, for_each_branch_ref_submodule);
+		handle_refs(refs, revs, *flags, refs_for_each_branch_ref);
 		clear_ref_exclusion(&revs->ref_excludes);
 	} else if (!strcmp(arg, "--bisect")) {
 		read_bisect_terms(&term_bad, &term_good);
-		handle_refs(submodule, revs, *flags, for_each_bad_bisect_ref);
-		handle_refs(submodule, revs, *flags ^ (UNINTERESTING | BOTTOM), for_each_good_bisect_ref);
+		handle_refs(refs, revs, *flags, for_each_bad_bisect_ref);
+		handle_refs(refs, revs, *flags ^ (UNINTERESTING | BOTTOM),
+			    for_each_good_bisect_ref);
 		revs->bisect = 1;
 	} else if (!strcmp(arg, "--tags")) {
-		handle_refs(submodule, revs, *flags, for_each_tag_ref_submodule);
+		handle_refs(refs, revs, *flags, refs_for_each_tag_ref);
 		clear_ref_exclusion(&revs->ref_excludes);
 	} else if (!strcmp(arg, "--remotes")) {
-		handle_refs(submodule, revs, *flags, for_each_remote_ref_submodule);
+		handle_refs(refs, revs, *flags, refs_for_each_remote_ref);
 		clear_ref_exclusion(&revs->ref_excludes);
 	} else if ((argcount = parse_long_opt("glob", argv, &optarg))) {
 		struct all_refs_cb cb;
-- 
2.11.0.157.gd943d85
Previous: Duy NguyenNext: Junio C Hamano
Message 17 of 40 in “Fix git-gc losing objects in multi worktree”
  1. 00/16 Fix git-gc losing objects in multi worktreeNguyễn Thái Ngọc Duy, Aug 23, 2017
  2. 01/16 revision.h: new flag in struct rev_info wrt. worktree-related refsNguyễn Thái Ngọc Duy, Aug 23, 2017
  3. 02/16 refs.c: use is_dir_sep() in resolve_gitlink_ref()Nguyễn Thái Ngọc Duy, Aug 23, 2017
  4. Stefan BellerAug 23, 2017
  5. Duy NguyenSep 6, 2017
  6. Stefan BellerSep 6, 2017
  7. 03/16 revision.c: refactor add_index_objects_to_pending()Nguyễn Thái Ngọc Duy, Aug 23, 2017
  8. 04/16 revision.c: --indexed-objects add objects from all worktreesNguyễn Thái Ngọc Duy, Aug 23, 2017
  9. Stefan BellerAug 23, 2017
  10. 05/16 refs.c: refactor get_submodule_ref_store(), share common free blockNguyễn Thái Ngọc Duy, Aug 23, 2017
  11. Stefan BellerAug 23, 2017
  12. 06/16 refs: move submodule slash stripping code to get_submodule_ref_storeNguyễn Thái Ngọc Duy, Aug 23, 2017
  13. Michael HaggertySep 9, 2017
  14. 07/16 refs: add refs_head_ref()Nguyễn Thái Ngọc Duy, Aug 23, 2017
  15. Junio C HamanoAug 24, 2017
  16. Duy NguyenSep 6, 2017
  17. 08/16 revision.c: use refs_for_each*() instead of for_each_*_submodule()Nguyễn Thái Ngọc Duy, Aug 23, 2017
  18. Junio C HamanoAug 24, 2017
  19. 09/16 refs.c: move for_each_remote_ref_submodule() to submodule.cNguyễn Thái Ngọc Duy, Aug 23, 2017
  20. 10/16 refs: remove dead for_each_*_submodule()Nguyễn Thái Ngọc Duy, Aug 23, 2017
  21. Stefan BellerAug 23, 2017
  22. Michael HaggertySep 9, 2017
  23. 11/16 revision.c: --all adds HEAD from all worktreesNguyễn Thái Ngọc Duy, Aug 23, 2017
  24. Stefan BellerAug 23, 2017
  25. Duy NguyenSep 6, 2017
  26. Stefan BellerSep 6, 2017
  27. Michael HaggertySep 9, 2017
  28. 12/16 files-backend: make reflog iterator go through per-worktree reflogNguyễn Thái Ngọc Duy, Aug 23, 2017
  29. Richard MawAug 24, 2017
  30. Michael HaggertySep 9, 2017
  31. 13/16 revision.c: --reflog add HEAD reflog from all worktreesNguyễn Thái Ngọc Duy, Aug 23, 2017
  32. 14/16 rev-list: expose and document --single-worktreeNguyễn Thái Ngọc Duy, Aug 23, 2017
  33. Stefan BellerAug 23, 2017
  34. 15/16 refs.c: remove fallback-to-main-store code get_submodule_ref_store()Nguyễn Thái Ngọc Duy, Aug 23, 2017
  35. Michael HaggertySep 9, 2017
  36. 16/16 refs.c: reindent get_submodule_ref_store()Nguyễn Thái Ngọc Duy, Aug 23, 2017
  37. Michael HaggertySep 9, 2017
  38. Michael J GruberAug 25, 2017
  39. Duy NguyenSep 6, 2017
  40. Michael HaggertySep 9, 2017

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.