From b81f925f709a10b37fb4fcd03629b55bc890a478 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 17 Aug 2010 01:52:48 -0500 Subject: merge: do not mistake (ancestor of) tag for branch If no branch 'foo' exists but a tag 'foo' does, then git merge foo^ results in Merge branch 'foo' (early part) as a commit message, because the relevant code path checks that refs/heads/foo is a valid refname for writing rather than for reading. Signed-off-by: Jonathan Nieder 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 37ce4f589f..2207f79969 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -437,7 +437,7 @@ static void merge_name(const char *remote, struct strbuf *msg) strbuf_addstr(&truname, "refs/heads/"); strbuf_addstr(&truname, remote); strbuf_setlen(&truname, truname.len - len); - if (resolve_ref(truname.buf, buf_sha, 0, NULL)) { + if (resolve_ref(truname.buf, buf_sha, 1, NULL)) { strbuf_addf(msg, "%s\t\tbranch '%s'%s of .\n", sha1_to_hex(remote_head->sha1), -- cgit v1.2.1 From aa8f98c1bfcf162e0bd23d20c34857940f2c2256 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 17 Aug 2010 02:01:15 -0500 Subject: merge-base --octopus to mimic show-branch --merge-base While show-branch --merge-base does not support more than MAX_REVS revs, git supports more with a different algorithm (v1.6.0-rc0~51^2~13, Introduce get_octopus_merge_bases() in commit.c, 2008-06-27). Expose that functionality. This should help scripts to catch up with builtin merge in supporting dodecapus. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin/merge-base.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'builtin') diff --git a/builtin/merge-base.c b/builtin/merge-base.c index 54e7ec2237..c30128659f 100644 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@ -23,7 +23,7 @@ static int show_merge_base(struct commit **rev, int rev_nr, int show_all) } static const char * const merge_base_usage[] = { - "git merge-base [-a|--all] ...", + "git merge-base [-a|--all] [--octopus] ...", NULL }; @@ -41,21 +41,50 @@ static struct commit *get_commit_reference(const char *arg) return r; } +static int show_octopus_merge_bases(int count, const char **args, int show_all) +{ + struct commit_list *revs = NULL; + struct commit_list *result; + int i; + + for (i = count - 1; i >= 0; i++) + commit_list_insert(get_commit_reference(args[i]), &revs); + result = get_octopus_merge_bases(revs); + + if (!result) + return 1; + + while (result) { + printf("%s\n", sha1_to_hex(result->item->object.sha1)); + if (!show_all) + return 0; + result = result->next; + } + + return 0; +} + int cmd_merge_base(int argc, const char **argv, const char *prefix) { struct commit **rev; int rev_nr = 0; int show_all = 0; + int octopus = 0; struct option options[] = { - OPT_BOOLEAN('a', "all", &show_all, "outputs all common ancestors"), + OPT_BOOLEAN('a', "all", &show_all, "output all common ancestors"), + OPT_BOOLEAN(0, "octopus", &octopus, "find ancestors for a single n-way merge"), OPT_END() }; git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, options, merge_base_usage, 0); - if (argc < 2) + if (!octopus && argc < 2) usage_with_options(merge_base_usage, options); + + if (octopus) + return show_octopus_merge_bases(argc, argv, show_all); + rev = xmalloc(argc * sizeof(*rev)); while (argc-- > 0) rev[rev_nr++] = get_commit_reference(*argv++); -- cgit v1.2.1 From a1e0ad78b784fd7c47c7bc2847f4813aca4cebaf Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 17 Aug 2010 02:01:54 -0500 Subject: merge-base --independent to print reduced parent list in a merge While show-branch --independent does not support more than MAX_REVS revs, git internally supports more with a different algorithm. Expose that functionality as "git merge-base --independent". This should help scripts to catch up with builtin merge in supporting dodecapus. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin/merge-base.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'builtin') diff --git a/builtin/merge-base.c b/builtin/merge-base.c index c30128659f..96dd160731 100644 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@ -24,6 +24,7 @@ static int show_merge_base(struct commit **rev, int rev_nr, int show_all) static const char * const merge_base_usage[] = { "git merge-base [-a|--all] [--octopus] ...", + "git merge-base --independent ...", NULL }; @@ -41,15 +42,19 @@ static struct commit *get_commit_reference(const char *arg) return r; } -static int show_octopus_merge_bases(int count, const char **args, int show_all) +static int handle_octopus(int count, const char **args, int reduce, int show_all) { struct commit_list *revs = NULL; struct commit_list *result; int i; - for (i = count - 1; i >= 0; i++) + if (reduce) + show_all = 1; + + for (i = count - 1; i >= 0; i--) commit_list_insert(get_commit_reference(args[i]), &revs); - result = get_octopus_merge_bases(revs); + + result = reduce ? reduce_heads(revs) : get_octopus_merge_bases(revs); if (!result) return 1; @@ -70,20 +75,24 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix) int rev_nr = 0; int show_all = 0; int octopus = 0; + int reduce = 0; struct option options[] = { OPT_BOOLEAN('a', "all", &show_all, "output all common ancestors"), OPT_BOOLEAN(0, "octopus", &octopus, "find ancestors for a single n-way merge"), + OPT_BOOLEAN(0, "independent", &reduce, "list revs not reachable from others"), OPT_END() }; git_config(git_default_config, NULL); argc = parse_options(argc, argv, prefix, options, merge_base_usage, 0); - if (!octopus && argc < 2) + if (!octopus && !reduce && argc < 2) usage_with_options(merge_base_usage, options); + if (reduce && (show_all || octopus)) + die("--independent cannot be used with other options"); - if (octopus) - return show_octopus_merge_bases(argc, argv, show_all); + if (octopus || reduce) + return handle_octopus(argc, argv, reduce, show_all); rev = xmalloc(argc * sizeof(*rev)); while (argc-- > 0) -- cgit v1.2.1 From 2102440c17f990fcb5c9269459c39c6312e80d1c Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 17 Aug 2010 18:00:34 -0500 Subject: fmt-merge-msg -m to override merge title Since v1.7.1.1~23^2 (merge: --log appends shortlog to message if specified, 2010-05-11), the fmt-merge-msg backend supports custom text to override the merge title "Merge into ". Expose this functionality for scripted callers. Example: git fmt-merge-msg --log -m \ "$(printf '%s\n' \ "Merge branch 'api-cleanup' into feature" \ '' \ 'This is to use a few functions refactored for this purpose.' )" <.git/FETCH_HEAD Cc: Tay Ray Chuan Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin/fmt-merge-msg.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'builtin') diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index bc3c5e6d3e..937d5a717b 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -7,7 +7,7 @@ #include "string-list.h" static const char * const fmt_merge_msg_usage[] = { - "git fmt-merge-msg [--log|--no-log] [--file ]", + "git fmt-merge-msg [-m ] [--log|--no-log] [--file ]", NULL }; @@ -319,11 +319,14 @@ int fmt_merge_msg_shortlog(struct strbuf *in, struct strbuf *out) { int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix) { const char *inpath = NULL; + const char *message = NULL; struct option options[] = { OPT_BOOLEAN(0, "log", &merge_summary, "populate log with the shortlog"), { OPTION_BOOLEAN, 0, "summary", &merge_summary, NULL, "alias for --log (deprecated)", PARSE_OPT_NOARG | PARSE_OPT_HIDDEN }, + OPT_STRING('m', "message", &message, "text", + "use as start of message"), OPT_FILENAME('F', "file", &inpath, "file to read from"), OPT_END() }; @@ -337,6 +340,12 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix) 0); if (argc > 0) usage_with_options(fmt_merge_msg_usage, options); + if (message && !merge_summary) { + char nl = '\n'; + write_in_full(STDOUT_FILENO, message, strlen(message)); + write_in_full(STDOUT_FILENO, &nl, 1); + return 0; + } if (inpath && strcmp(inpath, "-")) { in = fopen(inpath, "r"); @@ -346,7 +355,12 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix) if (strbuf_read(&input, fileno(in), 0) < 0) die_errno("could not read input file"); - ret = fmt_merge_msg(merge_summary, &input, &output); + if (message) { + strbuf_addstr(&output, message); + ret = fmt_merge_msg_shortlog(&input, &output); + } else { + ret = fmt_merge_msg(merge_summary, &input, &output); + } if (ret) return ret; write_in_full(STDOUT_FILENO, output.buf, output.len); -- cgit v1.2.1