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

[PATCH v3 2/3] rebase-update-refs: extract load_branch_decorations

From
NGNicolas Guichard via GitGitGadget <gitgitgadget@gmail.com>
Date
Oct 9, 2024, 07:58 UTC
Message-ID
<1dad6096eb7f329d8b43390f1a445e28d0e609d9.1728460700.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1784.v3.git.git.1728460700.gitgitgadget@gmail.com>
From: Nicolas Guichard <nicolas@guichard.eu>

Extract load_branch_decorations from todo_list_add_update_ref_commands so it can be re-used in make_script_with_merges.

Since it can now be called multiple times, use non-static lists and place it next to load_ref_decorations to re-use the decoration_loaded guard.

Signed-off-by: Nicolas Guichard <nicolas@guichard.eu>
---
 log-tree.c  | 21 +++++++++++++++++++++
 log-tree.h  |  1 +
 sequencer.c | 11 +----------
 3 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/log-tree.c b/log-tree.c
index c65ebd29202..bf6d2ae40c8 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -248,6 +248,27 @@ void load_ref_decorations(struct decoration_filter *filter, int flags)
 	}
 }
 
+void load_branch_decorations(void)
+{
+	if (!decoration_loaded) {
+		struct string_list decorate_refs_exclude = STRING_LIST_INIT_NODUP;
+		struct string_list decorate_refs_exclude_config = STRING_LIST_INIT_NODUP;
+		struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP;
+		struct decoration_filter decoration_filter = {
+			.include_ref_pattern = &decorate_refs_include,
+			.exclude_ref_pattern = &decorate_refs_exclude,
+			.exclude_ref_config_pattern = &decorate_refs_exclude_config,
+		};
+
+		string_list_append(&decorate_refs_include, "refs/heads/");
+		load_ref_decorations(&decoration_filter, 0);
+
+		string_list_clear(&decorate_refs_exclude, 0);
+		string_list_clear(&decorate_refs_exclude_config, 0);
+		string_list_clear(&decorate_refs_include, 0);
+	}
+}
+
 static void show_parents(struct commit *commit, int abbrev, FILE *file)
 {
 	struct commit_list *p;
diff --git a/log-tree.h b/log-tree.h
index 94978e2c838..ebe491c543c 100644
--- a/log-tree.h
+++ b/log-tree.h
@@ -33,6 +33,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
 			     int *need_8bit_cte_p,
 			     int maybe_multipart);
 void load_ref_decorations(struct decoration_filter *filter, int flags);
+void load_branch_decorations(void);
 
 void fmt_output_commit(struct strbuf *, struct commit *, struct rev_info *);
 void fmt_output_subject(struct strbuf *, const char *subject, struct rev_info *);
diff --git a/sequencer.c b/sequencer.c
index 8d01cd50ac9..97959036b50 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -6403,14 +6403,6 @@ static int add_decorations_to_list(const struct commit *commit,
 static int todo_list_add_update_ref_commands(struct todo_list *todo_list)
 {
 	int i, res;
-	static struct string_list decorate_refs_exclude = STRING_LIST_INIT_NODUP;
-	static struct string_list decorate_refs_exclude_config = STRING_LIST_INIT_NODUP;
-	static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP;
-	struct decoration_filter decoration_filter = {
-		.include_ref_pattern = &decorate_refs_include,
-		.exclude_ref_pattern = &decorate_refs_exclude,
-		.exclude_ref_config_pattern = &decorate_refs_exclude_config,
-	};
 	struct todo_add_branch_context ctx = {
 		.buf = &todo_list->buf,
 		.refs_to_oids = STRING_LIST_INIT_DUP,
@@ -6419,8 +6411,7 @@ static int todo_list_add_update_ref_commands(struct todo_list *todo_list)
 	ctx.items_alloc = 2 * todo_list->nr + 1;
 	ALLOC_ARRAY(ctx.items, ctx.items_alloc);
 
-	string_list_append(&decorate_refs_include, "refs/heads/");
-	load_ref_decorations(&decoration_filter, 0);
+	load_branch_decorations();
 
 	for (i = 0; i < todo_list->nr; ) {
 		struct todo_item *item = &todo_list->items[i];
-- 
gitgitgadget
Previous: Nicolas Guichard via GitGitGadgetNext: Nicolas Guichard via GitGitGadget
Message 14 of 18 in “rebase-merges: try and use branch names for labels”
  1. 0/2 rebase-merges: try and use branch names for labelsNicolas Guichard via GitGitGadget, Sep 21, 2024
  2. 1/2 sequencer.c: extract load_branch_decorationsNicolas Guichard via GitGitGadget, Sep 21, 2024
  3. Junio C HamanoSep 23, 2024
  4. 2/2 rebase-merges: try and use branch names as labelsNicolas Guichard via GitGitGadget, Sep 21, 2024
  5. Junio C HamanoSep 23, 2024
  6. 0/3 rebase-merges: try and use branch names for labelsNicolas Guichard via GitGitGadget, Oct 4, 2024
  7. 1/3 load_branch_decorations: fix memory leak with non-static filtersNicolas Guichard via GitGitGadget, Oct 4, 2024
  8. Eric SunshineOct 5, 2024
  9. 2/3 rebase-update-refs: extract load_branch_decorationsNicolas Guichard via GitGitGadget, Oct 4, 2024
  10. Eric SunshineOct 5, 2024
  11. 3/3 rebase-merges: try and use branch names as labelsNicolas Guichard via GitGitGadget, Oct 4, 2024
  12. 0/3 rebase-merges: try and use branch names for labelsNicolas Guichard via GitGitGadget, Oct 9, 2024
  13. 1/3 load_branch_decorations: fix memory leak with non-static filtersNicolas Guichard via GitGitGadget, Oct 9, 2024
  14. 2/3 rebase-update-refs: extract load_branch_decorationsNicolas Guichard via GitGitGadget, Oct 9, 2024
  15. 3/3 rebase-merges: try and use branch names as labelsNicolas Guichard via GitGitGadget, Oct 9, 2024
  16. Phillip WoodOct 9, 2024
  17. Junio C HamanoOct 9, 2024
  18. Phillip WoodOct 9, 2024

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.