Skip to content

Commit cbda121

Browse files
committed
fmt-merge-msg: package options into a structure
This way new features can be added more easily Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4c0ea82 commit cbda121

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

builtin.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ extern const char git_usage_string[];
1414
extern const char git_more_info_string[];
1515

1616
extern void prune_packed_objects(int);
17+
18+
struct fmt_merge_msg_opts {
19+
unsigned add_title:1;
20+
int shortlog_len;
21+
};
22+
1723
extern int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
18-
int merge_title, int shortlog_len);
24+
struct fmt_merge_msg_opts *);
1925
extern void commit_notes(struct notes_tree *t, const char *msg);
2026

2127
struct notes_rewrite_cfg {

builtin/fmt-merge-msg.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ static void shortlog(const char *name, unsigned char *sha1,
209209
string_list_clear(&subjects, 0);
210210
}
211211

212-
static void do_fmt_merge_msg_title(struct strbuf *out,
212+
static void fmt_merge_msg_title(struct strbuf *out,
213213
const char *current_branch) {
214214
int i = 0;
215215
char *sep = "";
@@ -262,8 +262,9 @@ static void do_fmt_merge_msg_title(struct strbuf *out,
262262
strbuf_addf(out, " into %s\n", current_branch);
263263
}
264264

265-
static int do_fmt_merge_msg(int merge_title, struct strbuf *in,
266-
struct strbuf *out, int shortlog_len) {
265+
int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
266+
struct fmt_merge_msg_opts *opts)
267+
{
267268
int i = 0, pos = 0;
268269
unsigned char head_sha1[20];
269270
const char *current_branch;
@@ -289,10 +290,10 @@ static int do_fmt_merge_msg(int merge_title, struct strbuf *in,
289290
die ("Error in line %d: %.*s", i, len, p);
290291
}
291292

292-
if (merge_title && srcs.nr)
293-
do_fmt_merge_msg_title(out, current_branch);
293+
if (opts->add_title && srcs.nr)
294+
fmt_merge_msg_title(out, current_branch);
294295

295-
if (shortlog_len) {
296+
if (opts->shortlog_len) {
296297
struct commit *head;
297298
struct rev_info rev;
298299

@@ -307,18 +308,13 @@ static int do_fmt_merge_msg(int merge_title, struct strbuf *in,
307308

308309
for (i = 0; i < origins.nr; i++)
309310
shortlog(origins.items[i].string, origins.items[i].util,
310-
head, &rev, shortlog_len, out);
311+
head, &rev, opts->shortlog_len, out);
311312
}
312313
if (out->len && out->buf[out->len-1] != '\n')
313314
strbuf_addch(out, '\n');
314315
return 0;
315316
}
316317

317-
int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
318-
int merge_title, int shortlog_len) {
319-
return do_fmt_merge_msg(merge_title, in, out, shortlog_len);
320-
}
321-
322318
int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
323319
{
324320
const char *inpath = NULL;
@@ -340,6 +336,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
340336
FILE *in = stdin;
341337
struct strbuf input = STRBUF_INIT, output = STRBUF_INIT;
342338
int ret;
339+
struct fmt_merge_msg_opts opts;
343340

344341
git_config(fmt_merge_msg_config, NULL);
345342
argc = parse_options(argc, argv, prefix, options, fmt_merge_msg_usage,
@@ -361,10 +358,12 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
361358

362359
if (message)
363360
strbuf_addstr(&output, message);
364-
ret = fmt_merge_msg(&input, &output,
365-
message ? 0 : 1,
366-
shortlog_len);
367361

362+
memset(&opts, 0, sizeof(opts));
363+
opts.add_title = !message;
364+
opts.shortlog_len = shortlog_len;
365+
366+
ret = fmt_merge_msg(&input, &output, &opts);
368367
if (ret)
369368
return ret;
370369
write_in_full(STDOUT_FILENO, output.buf, output.len);

builtin/merge.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,8 +1229,12 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
12291229
merge_name(argv[i], &merge_names);
12301230

12311231
if (!have_message || shortlog_len) {
1232-
fmt_merge_msg(&merge_names, &merge_msg, !have_message,
1233-
shortlog_len);
1232+
struct fmt_merge_msg_opts opts;
1233+
memset(&opts, 0, sizeof(opts));
1234+
opts.add_title = !have_message;
1235+
opts.shortlog_len = shortlog_len;
1236+
1237+
fmt_merge_msg(&merge_names, &merge_msg, &opts);
12341238
if (merge_msg.len)
12351239
strbuf_setlen(&merge_msg, merge_msg.len - 1);
12361240
}

0 commit comments

Comments
 (0)