Skip to content

Commit 0383dc5

Browse files
Linus Arvergitster
authored andcommitted
trailer: reorder format_trailers_from_commit() parameters
Currently there are two functions for formatting trailers in <trailer.h>: void format_trailers(const struct process_trailer_options *, struct list_head *trailers, FILE *outfile); void format_trailers_from_commit(struct strbuf *out, const char *msg, const struct process_trailer_options *opts); and although they are similar enough (even taking the same process_trailer_options struct pointer) they are used quite differently. One might intuitively think that format_trailers_from_commit() builds on top of format_trailers(), but this is not the case. Instead format_trailers_from_commit() calls format_trailer_info() and format_trailers() is never called in that codepath. This is a preparatory refactor to help us deprecate format_trailers() in favor of format_trailer_info() (at which point we can rename the latter to the former). When the deprecation is complete, both format_trailers_from_commit(), and the interpret-trailers builtin will be able to call into the same helper function (instead of format_trailers() and format_trailer_info(), respectively). Unifying the formatters is desirable because it simplifies the API. Reorder parameters for format_trailers_from_commit() to prefer const struct process_trailer_options *opts as the first parameter, because these options are intimately tied to formatting trailers. And take struct strbuf *out last, because it's an "out parameter" (something that the caller wants to use as the output of this function). Similarly, reorder parameters for format_trailer_info(), because later on we will unify the two together. Signed-off-by: Linus Arver <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7b1c6aa commit 0383dc5

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

pretty.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1759,7 +1759,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
17591759
goto trailer_out;
17601760
}
17611761
if (*arg == ')') {
1762-
format_trailers_from_commit(sb, msg + c->subject_off, &opts);
1762+
format_trailers_from_commit(&opts, msg + c->subject_off, sb);
17631763
ret = arg - placeholder + 1;
17641764
}
17651765
trailer_out:

ref-filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1985,7 +1985,7 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, struct exp
19851985
struct strbuf s = STRBUF_INIT;
19861986

19871987
/* Format the trailer info according to the trailer_opts given */
1988-
format_trailers_from_commit(&s, subpos, &atom->u.contents.trailer_opts);
1988+
format_trailers_from_commit(&atom->u.contents.trailer_opts, subpos, &s);
19891989

19901990
v->s = strbuf_detach(&s, NULL);
19911991
} else if (atom->u.contents.option == C_BARE)

trailer.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,10 +1176,10 @@ void trailer_info_release(struct trailer_info *info)
11761176
free(info->trailers);
11771177
}
11781178

1179-
static void format_trailer_info(struct strbuf *out,
1179+
static void format_trailer_info(const struct process_trailer_options *opts,
11801180
const struct trailer_info *info,
11811181
const char *msg,
1182-
const struct process_trailer_options *opts)
1182+
struct strbuf *out)
11831183
{
11841184
size_t origlen = out->len;
11851185
size_t i;
@@ -1237,13 +1237,14 @@ static void format_trailer_info(struct strbuf *out,
12371237

12381238
}
12391239

1240-
void format_trailers_from_commit(struct strbuf *out, const char *msg,
1241-
const struct process_trailer_options *opts)
1240+
void format_trailers_from_commit(const struct process_trailer_options *opts,
1241+
const char *msg,
1242+
struct strbuf *out)
12421243
{
12431244
struct trailer_info info;
12441245

12451246
trailer_info_get(&info, msg, opts);
1246-
format_trailer_info(out, &info, msg, opts);
1247+
format_trailer_info(opts, &info, msg, out);
12471248
trailer_info_release(&info);
12481249
}
12491250

trailer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ void trailer_info_release(struct trailer_info *info);
101101
* only the trailer block itself, even if the "only_trailers" option is not
102102
* set.
103103
*/
104-
void format_trailers_from_commit(struct strbuf *out, const char *msg,
105-
const struct process_trailer_options *opts);
104+
void format_trailers_from_commit(const struct process_trailer_options *opts,
105+
const char *msg,
106+
struct strbuf *out);
106107

107108
/*
108109
* An interface for iterating over the trailers found in a particular commit

0 commit comments

Comments
 (0)