fmt-merge-msg: package options into a structure
This way new features can be added more easily Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Nov 4, 2011 at 17:35 UTC
cbda121c993bf14d3743c7fdf0f8c476c9f7c636
3 files changed
+27
-18
builtin.h
+7
-1
@@ -14,8 +14,14 @@ extern const char git_usage_string[];
14
extern const char git_more_info_string[];
15
16
extern void prune_packed_objects(int);
17
+
18
+struct fmt_merge_msg_opts {
19
+ unsigned add_title:1;
20
+ int shortlog_len;
21
+};
22
+
23
extern int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
18
- int merge_title, int shortlog_len);
24
+ struct fmt_merge_msg_opts *);
25
extern void commit_notes(struct notes_tree *t, const char *msg);
26
27
struct notes_rewrite_cfg {
builtin/fmt-merge-msg.c
+14
-15
@@ -209,7 +209,7 @@ static void shortlog(const char *name, unsigned char *sha1,
209
string_list_clear(&subjects, 0);
210
}
211
212
-static void do_fmt_merge_msg_title(struct strbuf *out,
212
+static void fmt_merge_msg_title(struct strbuf *out,
213
const char *current_branch) {
214
int i = 0;
215
char *sep = "";
@@ -262,8 +262,9 @@ static void do_fmt_merge_msg_title(struct strbuf *out,
262
strbuf_addf(out, " into %s\n", current_branch);
263
}
264
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
+{
268
int i = 0, pos = 0;
269
unsigned char head_sha1[20];
270
const char *current_branch;
@@ -289,10 +290,10 @@ static int do_fmt_merge_msg(int merge_title, struct strbuf *in,
290
die ("Error in line %d: %.*s", i, len, p);
291
}
292
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);
295
295
- if (shortlog_len) {
296
+ if (opts->shortlog_len) {
297
struct commit *head;
298
struct rev_info rev;
299
@@ -307,18 +308,13 @@ static int do_fmt_merge_msg(int merge_title, struct strbuf *in,
308
309
for (i = 0; i < origins.nr; i++)
310
shortlog(origins.items[i].string, origins.items[i].util,
310
- head, &rev, shortlog_len, out);
311
+ head, &rev, opts->shortlog_len, out);
312
}
313
if (out->len && out->buf[out->len-1] != '\n')
314
strbuf_addch(out, '\n');
315
return 0;
316
}
317
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
-
318
int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
319
{
320
const char *inpath = NULL;
@@ -340,6 +336,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
336
FILE *in = stdin;
337
struct strbuf input = STRBUF_INIT, output = STRBUF_INIT;
338
int ret;
339
+ struct fmt_merge_msg_opts opts;
340
341
git_config(fmt_merge_msg_config, NULL);
342
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)
358
359
if (message)
360
strbuf_addstr(&output, message);
364
- ret = fmt_merge_msg(&input, &output,
365
- message ? 0 : 1,
366
- shortlog_len);
361
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);
367
if (ret)
368
return ret;
369
write_in_full(STDOUT_FILENO, output.buf, output.len);
builtin/merge.c
+6
-2
@@ -1229,8 +1229,12 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1229
merge_name(argv[i], &merge_names);
1230
1231
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);
1238
if (merge_msg.len)
1239
strbuf_setlen(&merge_msg, merge_msg.len - 1);
1240
}