{"thread":{"id":"14683","subject":"[RFC/PATCH] merge-base: teach \"git merge-base\" to accept more than 2 arguments","startedAt":"2008-07-26T03:59:20Z","lastAt":"2008-07-26T04:37:08Z","messageCount":3,"participants":["Christian Couder","Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"84999","messageId":"20080726055920.3a2fc8e7.chriscool@tuxfamily.org","threadId":"14683","inReplyTo":null,"subject":"[RFC/PATCH] merge-base: teach \"git merge-base\" to accept more than 2 arguments","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2008-07-26T03:59:20Z","receivedAt":"2008-07-26T03:59:20Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Before this patch \"git merge-base\" accepted only 2 arguments, so\nonly merge bases between 2 references could be computed.\n\nThe purpose of this patch is to make \"git merge-base\" accept more\nthan 2 arguments so that the merge bases between the first given\nreference and all the other references can be computed.\n\nThis is easily implemented because the \"get_merge_bases_many\"\nfunction in \"commit.c\" already implements the computation.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n builtin-merge-base.c |   51 ++++++++++++++++++++++++++++++++++++-------------\n commit.h             |    2 +\n 2 files changed, 39 insertions(+), 14 deletions(-)\n\n\tI suspect this patch may be usefull to simplify my\n\t\"bisect: add merge bases check\" series and perhaps\n\talso generally usefull.\n\n\tI will add documentation and perhaps tests too if\n\tpeople are ok with something like that.\n\n\tBy the way perhaps such a patch has already been\n\tposted by someone else. In this case sorry for the\n\tnoise and thanks for any pointer to the previous\n\tpatch.\n\ndiff --git a/builtin-merge-base.c b/builtin-merge-base.c\nindex 1cb2925..9c41849 100644\n--- a/builtin-merge-base.c\n+++ b/builtin-merge-base.c\n@@ -2,9 +2,14 @@\n #include \"cache.h\"\n #include \"commit.h\"\n \n-static int show_merge_base(struct commit *rev1, struct commit *rev2, int show_all)\n+static struct commit *rev1, **prev2;\n+static size_t prev2_nr, prev2_alloc;\n+\n+\n+static int show_merge_base(int show_all)\n {\n-\tstruct commit_list *result = get_merge_bases(rev1, rev2, 0);\n+\tstruct commit_list *result = get_merge_bases_many(rev1, prev2_nr,\n+\t\t\t\t\t\t\t  prev2, 0);\n \n \tif (!result)\n \t\treturn 1;\n@@ -20,12 +25,24 @@ static int show_merge_base(struct commit *rev1, struct commit *rev2, int show_al\n }\n \n static const char merge_base_usage[] =\n-\"git merge-base [--all] <commit-id> <commit-id>\";\n+\"git merge-base [--all] <commit-id> <commit-id>...\";\n+\n+static void append_rev2(struct commit *rev)\n+{\n+\tALLOC_GROW(prev2, prev2_nr + 1, prev2_alloc);\n+\tprev2[prev2_nr++] = rev;\n+}\n+\n+static struct commit *get_commit_reference(const char *arg)\n+{\n+\tunsigned char revkey[20];\n+\tif (get_sha1(arg, revkey))\n+\t\tdie(\"Not a valid object name %s\", arg);\n+\treturn lookup_commit_reference(revkey);\n+}\n \n int cmd_merge_base(int argc, const char **argv, const char *prefix)\n {\n-\tstruct commit *rev1, *rev2;\n-\tunsigned char rev1key[20], rev2key[20];\n \tint show_all = 0;\n \n \tgit_config(git_default_config, NULL);\n@@ -38,15 +55,21 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix)\n \t\t\tusage(merge_base_usage);\n \t\targc--; argv++;\n \t}\n-\tif (argc != 3)\n+\tif (argc < 3)\n \t\tusage(merge_base_usage);\n-\tif (get_sha1(argv[1], rev1key))\n-\t\tdie(\"Not a valid object name %s\", argv[1]);\n-\tif (get_sha1(argv[2], rev2key))\n-\t\tdie(\"Not a valid object name %s\", argv[2]);\n-\trev1 = lookup_commit_reference(rev1key);\n-\trev2 = lookup_commit_reference(rev2key);\n-\tif (!rev1 || !rev2)\n+\n+\trev1 = get_commit_reference(argv[1]);\n+\tif (!rev1)\n \t\treturn 1;\n-\treturn show_merge_base(rev1, rev2, show_all);\n+\targc--; argv++;\n+\n+\tdo {\n+\t\tstruct commit *rev2 = get_commit_reference(argv[1]);\n+\t\tif (!rev2)\n+\t\t\treturn 1;\n+\t\tappend_rev2(rev2);\n+\t\targc--; argv++;\n+\t} while (argc > 1);\n+\n+\treturn show_merge_base(show_all);\n }\ndiff --git a/commit.h b/commit.h\nindex 77de962..4829a5c 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -121,6 +121,8 @@ int read_graft_file(const char *graft_file);\n struct commit_graft *lookup_commit_graft(const unsigned char *sha1);\n \n extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2, int cleanup);\n+extern struct commit_list *get_merge_bases_many(struct commit *one,\n+\t\tint n, struct commit **twos, int cleanup);\n extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);\n \n extern int register_shallow(const unsigned char *sha1);\n-- \n1.6.0.rc0.43.g62478.dirty\n"},{"id":"85002","messageId":"alpine.DEB.1.00.0807260624210.26810@eeepc-johanness","threadId":"14683","inReplyTo":"20080726055920.3a2fc8e7.chriscool@tuxfamily.org","subject":"Re: [RFC/PATCH] merge-base: teach \"git merge-base\" to accept more than 2 arguments","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-07-26T04:25:50Z","receivedAt":"2008-07-26T04:25:50Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 26 Jul 2008, Christian Couder wrote:\n\n> \tI suspect this patch may be usefull to simplify my\n> \t\"bisect: add merge bases check\" series and perhaps\n> \talso generally usefull.\n\ns/usefull/useful/\n\n> diff --git a/builtin-merge-base.c b/builtin-merge-base.c\n> index 1cb2925..9c41849 100644\n> --- a/builtin-merge-base.c\n> +++ b/builtin-merge-base.c\n> @@ -2,9 +2,14 @@\n>  #include \"cache.h\"\n>  #include \"commit.h\"\n>  \n> -static int show_merge_base(struct commit *rev1, struct commit *rev2, int show_all)\n> +static struct commit *rev1, **prev2;\n> +static size_t prev2_nr, prev2_alloc;\n> +\n> +\n> +static int show_merge_base(int show_all)\n>  {\n\nChanging the arguments to be static variables?\n\nNACK!\n\nCiao,\nDscho\n"},{"id":"85004","messageId":"7vzlo5mfbf.fsf@gitster.siamese.dyndns.org","threadId":"14683","inReplyTo":"20080726055920.3a2fc8e7.chriscool@tuxfamily.org","subject":"Re: [RFC/PATCH] merge-base: teach \"git merge-base\" to accept more than 2 arguments","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-07-26T04:37:08Z","receivedAt":"2008-07-26T04:37:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <chriscool@tuxfamily.org> writes:\n\n> Before this patch \"git merge-base\" accepted only 2 arguments, so\n> only merge bases between 2 references could be computed.\n>\n> The purpose of this patch is to make \"git merge-base\" accept more\n> than 2 arguments so that the merge bases between the first given\n> reference and all the other references can be computed.\n\nI think this is a logical conclusion of merge_bases_many().  You need\ntests and docs, though.\n"}]}