Skip to content

Commit 4c0ea82

Browse files
committed
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 <[email protected]>
1 parent dd621df commit 4c0ea82

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

builtin/fmt-merge-msg.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static int fmt_merge_msg_config(const char *key, const char *value, void *cb)
2626
return 0;
2727
}
2828

29+
/* merge data per repository where the merged tips came from */
2930
struct src_data {
3031
struct string_list branch, tag, r_branch, generic;
3132
int head_status;
@@ -71,6 +72,11 @@ static int handle_line(char *line)
7172
line[len - 1] = 0;
7273
line += 42;
7374

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+
*/
7480
src = strstr(line, " of ");
7581
if (src) {
7682
*src = 0;
@@ -283,10 +289,7 @@ static int do_fmt_merge_msg(int merge_title, struct strbuf *in,
283289
die ("Error in line %d: %.*s", i, len, p);
284290
}
285291

286-
if (!srcs.nr)
287-
return 0;
288-
289-
if (merge_title)
292+
if (merge_title && srcs.nr)
290293
do_fmt_merge_msg_title(out, current_branch);
291294

292295
if (shortlog_len) {
@@ -306,6 +309,8 @@ static int do_fmt_merge_msg(int merge_title, struct strbuf *in,
306309
shortlog(origins.items[i].string, origins.items[i].util,
307310
head, &rev, shortlog_len, out);
308311
}
312+
if (out->len && out->buf[out->len-1] != '\n')
313+
strbuf_addch(out, '\n');
309314
return 0;
310315
}
311316

@@ -341,12 +346,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
341346
0);
342347
if (argc > 0)
343348
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+
350350
if (shortlog_len < 0)
351351
die("Negative --log=%d", shortlog_len);
352352

0 commit comments

Comments
 (0)