rebase-update-refs: extract load_branch_decorations
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> Acked-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nicolas Guichard committed
Oct 9, 2024 at 07:58 UTC
68c9fcb027b4bd2e5d10618829937ee50503c281
3 files changed
+23
-10
log-tree.c
+21
@@ -248,6 +248,27 @@ void load_ref_decorations(struct decoration_filter *filter, int flags)
248
}
249
}
250
251
+void load_branch_decorations(void)
252
+{
253
+ if (!decoration_loaded) {
254
+ struct string_list decorate_refs_exclude = STRING_LIST_INIT_NODUP;
255
+ struct string_list decorate_refs_exclude_config = STRING_LIST_INIT_NODUP;
256
+ struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP;
257
+ struct decoration_filter decoration_filter = {
258
+ .include_ref_pattern = &decorate_refs_include,
259
+ .exclude_ref_pattern = &decorate_refs_exclude,
260
+ .exclude_ref_config_pattern = &decorate_refs_exclude_config,
261
+ };
262
+
263
+ string_list_append(&decorate_refs_include, "refs/heads/");
264
+ load_ref_decorations(&decoration_filter, 0);
265
+
266
+ string_list_clear(&decorate_refs_exclude, 0);
267
+ string_list_clear(&decorate_refs_exclude_config, 0);
268
+ string_list_clear(&decorate_refs_include, 0);
269
+ }
270
+}
271
+
272
static void show_parents(struct commit *commit, int abbrev, FILE *file)
273
{
274
struct commit_list *p;
log-tree.h
+1
@@ -33,6 +33,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
33
int *need_8bit_cte_p,
34
int maybe_multipart);
35
void load_ref_decorations(struct decoration_filter *filter, int flags);
36
+void load_branch_decorations(void);
37
38
void fmt_output_commit(struct strbuf *, struct commit *, struct rev_info *);
39
void fmt_output_subject(struct strbuf *, const char *subject, struct rev_info *);
sequencer.c
+1
-10
@@ -6403,14 +6403,6 @@ static int add_decorations_to_list(const struct commit *commit,
6403
static int todo_list_add_update_ref_commands(struct todo_list *todo_list)
6404
{
6405
int i, res;
6406
- static struct string_list decorate_refs_exclude = STRING_LIST_INIT_NODUP;
6407
- static struct string_list decorate_refs_exclude_config = STRING_LIST_INIT_NODUP;
6408
- static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP;
6409
- struct decoration_filter decoration_filter = {
6410
- .include_ref_pattern = &decorate_refs_include,
6411
- .exclude_ref_pattern = &decorate_refs_exclude,
6412
- .exclude_ref_config_pattern = &decorate_refs_exclude_config,
6413
- };
6406
struct todo_add_branch_context ctx = {
6407
.buf = &todo_list->buf,
6408
.refs_to_oids = STRING_LIST_INIT_DUP,
@@ -6419,8 +6411,7 @@ static int todo_list_add_update_ref_commands(struct todo_list *todo_list)
6411
ctx.items_alloc = 2 * todo_list->nr + 1;
6412
ALLOC_ARRAY(ctx.items, ctx.items_alloc);
6413
6422
- string_list_append(&decorate_refs_include, "refs/heads/");
6423
- load_ref_decorations(&decoration_filter, 0);
6414
+ load_branch_decorations();
6415
6416
for (i = 0; i < todo_list->nr; ) {
6417
struct todo_item *item = &todo_list->items[i];