fmt-merge-msg: avoid early returns

In various places in the codepath, the program tries to return early assuming there is no more work needed. That is generally untrue when over time new features are added. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Nov 4, 2011 at 17:00 UTC 4c0ea82da3cd35eff50377cab78208c8ef57933b
1 file changed +10 -10
builtin/fmt-merge-msg.c
+10 -10
@@ -26,6 +26,7 @@ static int fmt_merge_msg_config(const char *key, const char *value, void *cb)
26 return 0;
27 }
28
29 +/* merge data per repository where the merged tips came from */
30 struct src_data {
31 struct string_list branch, tag, r_branch, generic;
32 int head_status;
@@ -71,6 +72,11 @@ static int handle_line(char *line)
72 line[len - 1] = 0;
73 line += 42;
74
75 + /*
76 + * At this point, line points at the beginning of comment e.g.
77 + * "branch 'frotz' of git://that/repository.git".
78 + * Find the repository name and point it with src.
79 + */
80 src = strstr(line, " of ");
81 if (src) {
82 *src = 0;
@@ -283,10 +289,7 @@ static int do_fmt_merge_msg(int merge_title, struct strbuf *in,
289 die ("Error in line %d: %.*s", i, len, p);
290 }
291
286 - if (!srcs.nr)
287 - return 0;
288 -
289 - if (merge_title)
292 + if (merge_title && srcs.nr)
293 do_fmt_merge_msg_title(out, current_branch);
294
295 if (shortlog_len) {
@@ -306,6 +309,8 @@ static int do_fmt_merge_msg(int merge_title, struct strbuf *in,
309 shortlog(origins.items[i].string, origins.items[i].util,
310 head, &rev, shortlog_len, out);
311 }
312 + if (out->len && out->buf[out->len-1] != '\n')
313 + strbuf_addch(out, '\n');
314 return 0;
315 }
316
@@ -341,12 +346,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
346 0);
347 if (argc > 0)
348 usage_with_options(fmt_merge_msg_usage, options);
344 - if (message && !shortlog_len) {
345 - char nl = '\n';
346 - write_in_full(STDOUT_FILENO, message, strlen(message));
347 - write_in_full(STDOUT_FILENO, &nl, 1);
348 - return 0;
349 - }
349 +
350 if (shortlog_len < 0)
351 die("Negative --log=%d", shortlog_len);
352