From 75589220289ca8400388813af66c7219811e0334 Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Tue, 11 May 2010 01:17:47 +0800 Subject: merge: update comment ce9d823 (merge: do not add standard message when message is given with -m option) changed the behaviour of the code that the comment addressed, but the comment was not similarly updated. Fix this. Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano --- builtin/merge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin') diff --git a/builtin/merge.c b/builtin/merge.c index c043066845..457bb5e48a 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -981,7 +981,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) /* * All the rest are the commits being merged; * prepare the standard merge summary message to - * be appended to the given message. If remote + * used as the merge message. If remote * is invalid we will die later in the common * codepath so we discard the error in this * loop. -- cgit v1.2.3 From 97d45bcb2f6bdd9cb164d151a6e064ffdcd5e2bc Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Tue, 11 May 2010 01:17:48 +0800 Subject: merge: rename variable It is more accurate to call it 'merge_names' instead of 'msg', as it does not contain the final message. Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano --- builtin/merge.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'builtin') diff --git a/builtin/merge.c b/builtin/merge.c index 457bb5e48a..0ae480987a 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -973,7 +973,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) reset_hard(remote_head->sha1, 0); return 0; } else { - struct strbuf msg = STRBUF_INIT; + struct strbuf merge_names = STRBUF_INIT; /* We are invoked directly as the first-class UI. */ head_arg = "HEAD"; @@ -988,8 +988,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix) */ if (!have_message) { for (i = 0; i < argc; i++) - merge_name(argv[i], &msg); - fmt_merge_msg(option_log, &msg, &merge_msg); + merge_name(argv[i], &merge_names); + fmt_merge_msg(option_log, &merge_names, &merge_msg); if (merge_msg.len) strbuf_setlen(&merge_msg, merge_msg.len-1); } -- cgit v1.2.3 From 2234ec5422201cd58f51b82fb4af146cf896767d Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Tue, 11 May 2010 01:17:49 +0800 Subject: fmt-merge-msg: minor refactor of fmt_merge_msg() Shift implementation into a private function, do_fmt_merge_msg(). This allows for further changes to the implementation, without affecting the interface. Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano --- builtin/fmt-merge-msg.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'builtin') diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index 379a03131f..a2bccd6ea4 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -202,7 +202,8 @@ static void shortlog(const char *name, unsigned char *sha1, string_list_clear(&subjects, 0); } -int fmt_merge_msg(int merge_summary, struct strbuf *in, struct strbuf *out) { +static int do_fmt_merge_msg(int merge_summary, struct strbuf *in, + struct strbuf *out) { int limit = 20, i = 0, pos = 0; char *sep = ""; unsigned char head_sha1[20]; @@ -296,6 +297,10 @@ int fmt_merge_msg(int merge_summary, struct strbuf *in, struct strbuf *out) { return 0; } +int fmt_merge_msg(int merge_summary, struct strbuf *in, struct strbuf *out) { + return do_fmt_merge_msg(merge_summary, in, out); +} + int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix) { const char *inpath = NULL; -- cgit v1.2.3 From 403994e83dd3ad2424f0b3084c8dc4fd1ca6374a Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Tue, 11 May 2010 01:17:50 +0800 Subject: fmt-merge-msg: refactor merge title formatting Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano --- builtin/fmt-merge-msg.c | 65 +++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 29 deletions(-) (limited to 'builtin') diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index a2bccd6ea4..d0160cb822 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -202,36 +202,10 @@ static void shortlog(const char *name, unsigned char *sha1, string_list_clear(&subjects, 0); } -static int do_fmt_merge_msg(int merge_summary, struct strbuf *in, - struct strbuf *out) { - int limit = 20, i = 0, pos = 0; +static void do_fmt_merge_msg_title(struct strbuf *out, + const char *current_branch) { + int i = 0; char *sep = ""; - unsigned char head_sha1[20]; - const char *current_branch; - - /* get current branch */ - current_branch = resolve_ref("HEAD", head_sha1, 1, NULL); - if (!current_branch) - die("No current branch"); - if (!prefixcmp(current_branch, "refs/heads/")) - current_branch += 11; - - /* get a line */ - while (pos < in->len) { - int len; - char *newline, *p = in->buf + pos; - - newline = strchr(p, '\n'); - len = newline ? newline - p : strlen(p); - pos += len + !!newline; - i++; - p[len] = 0; - if (handle_line(p)) - die ("Error in line %d: %.*s", i, len, p); - } - - if (!srcs.nr) - return 0; strbuf_addstr(out, "Merge "); for (i = 0; i < srcs.nr; i++) { @@ -279,6 +253,39 @@ static int do_fmt_merge_msg(int merge_summary, struct strbuf *in, strbuf_addch(out, '\n'); else strbuf_addf(out, " into %s\n", current_branch); +} + +static int do_fmt_merge_msg(int merge_summary, struct strbuf *in, + struct strbuf *out) { + int limit = 20, i = 0, pos = 0; + unsigned char head_sha1[20]; + const char *current_branch; + + /* get current branch */ + current_branch = resolve_ref("HEAD", head_sha1, 1, NULL); + if (!current_branch) + die("No current branch"); + if (!prefixcmp(current_branch, "refs/heads/")) + current_branch += 11; + + /* get a line */ + while (pos < in->len) { + int len; + char *newline, *p = in->buf + pos; + + newline = strchr(p, '\n'); + len = newline ? newline - p : strlen(p); + pos += len + !!newline; + i++; + p[len] = 0; + if (handle_line(p)) + die ("Error in line %d: %.*s", i, len, p); + } + + if (!srcs.nr) + return 0; + + do_fmt_merge_msg_title(out, current_branch); if (merge_summary) { struct commit *head; -- cgit v1.2.3 From 8c6bdfdf8ba9a3d7a03d64b7a98305a460921130 Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Tue, 11 May 2010 01:17:51 +0800 Subject: fmt-merge-msg: add function to append shortlog only Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano --- builtin/fmt-merge-msg.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'builtin') diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index d0160cb822..48548cf11b 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -255,8 +255,8 @@ static void do_fmt_merge_msg_title(struct strbuf *out, strbuf_addf(out, " into %s\n", current_branch); } -static int do_fmt_merge_msg(int merge_summary, struct strbuf *in, - struct strbuf *out) { +static int do_fmt_merge_msg(int merge_title, int merge_summary, + struct strbuf *in, struct strbuf *out) { int limit = 20, i = 0, pos = 0; unsigned char head_sha1[20]; const char *current_branch; @@ -285,7 +285,8 @@ static int do_fmt_merge_msg(int merge_summary, struct strbuf *in, if (!srcs.nr) return 0; - do_fmt_merge_msg_title(out, current_branch); + if (merge_title) + do_fmt_merge_msg_title(out, current_branch); if (merge_summary) { struct commit *head; @@ -305,7 +306,11 @@ static int do_fmt_merge_msg(int merge_summary, struct strbuf *in, } int fmt_merge_msg(int merge_summary, struct strbuf *in, struct strbuf *out) { - return do_fmt_merge_msg(merge_summary, in, out); + return do_fmt_merge_msg(1, merge_summary, in, out); +} + +int fmt_merge_msg_shortlog(struct strbuf *in, struct strbuf *out) { + return do_fmt_merge_msg(0, 1, in, out); } int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix) -- cgit v1.2.3 From f0ecac2b70bf6b44b89dfa493abd2f544010b1eb Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Tue, 11 May 2010 01:17:52 +0800 Subject: merge: --log appends shortlog to message if specified When the user specifies a message, use fmt_merge_msg_shortlog() to append the shortlog. Previously, when a message was specified, we ignored the merge title ("Merge into ") and shortlog from fmt_merge_msg(). Update the documentation for -m to reflect this too. Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano --- builtin/fmt-merge-msg.c | 3 +++ builtin/merge.c | 18 +++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'builtin') diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index 48548cf11b..44204257c7 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -298,6 +298,9 @@ static int do_fmt_merge_msg(int merge_title, int merge_summary, rev.ignore_merges = 1; rev.limited = 1; + if (suffixcmp(out->buf, "\n")) + strbuf_addch(out, '\n'); + for (i = 0; i < origins.nr; i++) shortlog(origins.items[i].string, origins.items[i].util, head, &rev, limit, out); diff --git a/builtin/merge.c b/builtin/merge.c index 0ae480987a..cae1cbee26 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -981,18 +981,22 @@ int cmd_merge(int argc, const char **argv, const char *prefix) /* * All the rest are the commits being merged; * prepare the standard merge summary message to - * used as the merge message. If remote + * be appended to the given message. If remote * is invalid we will die later in the common * codepath so we discard the error in this * loop. */ - if (!have_message) { - for (i = 0; i < argc; i++) - merge_name(argv[i], &merge_names); + for (i = 0; i < argc; i++) + merge_name(argv[i], &merge_names); + + if (have_message && option_log) + fmt_merge_msg_shortlog(&merge_names, &merge_msg); + else if (!have_message) fmt_merge_msg(option_log, &merge_names, &merge_msg); - if (merge_msg.len) - strbuf_setlen(&merge_msg, merge_msg.len-1); - } + + + if (!(have_message && !option_log) && merge_msg.len) + strbuf_setlen(&merge_msg, merge_msg.len-1); } if (head_invalid || !argc) -- cgit v1.2.3