{"thread":{"id":"14751","subject":"[RFC/PATCH v4 1/2] merge-base: teach \"git merge-base\" to accept more than 2 arguments","startedAt":"2008-07-30T05:04:14Z","lastAt":"2008-07-30T06:00:34Z","messageCount":2,"participants":["Christian Couder","Junio C Hamano"],"isPatch":true,"patchVersion":4,"patchTotal":2},"messages":[{"id":"85571","messageId":"20080730070414.f7b36eec.chriscool@tuxfamily.org","threadId":"14751","inReplyTo":null,"subject":"[RFC/PATCH v4 1/2] merge-base: teach \"git merge-base\" to accept more than 2 arguments","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2008-07-30T05:04:14Z","receivedAt":"2008-07-30T05:04:14Z","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 needed computation.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n builtin-merge-base.c |   24 ++++++++++++++++--------\n 1 files changed, 16 insertions(+), 8 deletions(-)\n\n\tChanges since previous version are:\n\n\t- the patch is simpler because it now goes on top of\n\ta fix that added the \"get_commit_reference\" function,\n\n\t- documentation has been removed from the first patch\n\tand Junio's documentation has been added in a new 2/2\n\tpatch.\n\n\tThere are still no tests. I need to find time to work\n\ton them before friday otherwise it will probably have\n\tto wait until I come back from vacation.\n\ndiff --git a/builtin-merge-base.c b/builtin-merge-base.c\nindex 3382b13..b08da51 100644\n--- a/builtin-merge-base.c\n+++ b/builtin-merge-base.c\n@@ -2,9 +2,11 @@\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 int show_merge_base(struct commit **rev, int rev_nr, int show_all)\n {\n-\tstruct commit_list *result = get_merge_bases(rev1, rev2, 0);\n+\tstruct commit_list *result;\n+\n+\tresult = get_merge_bases_many(rev[0], rev_nr - 1, rev + 1, 0);\n \n \tif (!result)\n \t\treturn 1;\n@@ -20,7 +22,7 @@ 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 struct commit *get_commit_reference(const char *arg)\n {\n@@ -38,7 +40,8 @@ static struct commit *get_commit_reference(const char *arg)\n \n int cmd_merge_base(int argc, const char **argv, const char *prefix)\n {\n-\tstruct commit *rev1, *rev2;\n+\tstruct commit **rev;\n+\tint rev_nr = 0;\n \tint show_all = 0;\n \n \tgit_config(git_default_config, NULL);\n@@ -51,10 +54,15 @@ 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-\trev1 = get_commit_reference(argv[1]);\n-\trev2 = get_commit_reference(argv[2]);\n \n-\treturn show_merge_base(rev1, rev2, show_all);\n+\trev = xmalloc((argc - 1) * sizeof(*rev));\n+\n+\tdo {\n+\t\trev[rev_nr++] = get_commit_reference(argv[1]);\n+\t\targc--; argv++;\n+\t} while (argc > 1);\n+\n+\treturn show_merge_base(rev, rev_nr, show_all);\n }\n-- \n1.6.0.rc0.42.g186458.dirty\n"},{"id":"85582","messageId":"7vy73j9ail.fsf@gitster.siamese.dyndns.org","threadId":"14751","inReplyTo":"20080730070414.f7b36eec.chriscool@tuxfamily.org","subject":"Re: [RFC/PATCH v4 1/2] merge-base: teach \"git merge-base\" to accept more than 2 arguments","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-07-30T06:00:34Z","receivedAt":"2008-07-30T06:00:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks; queued.  Perhaps I'll add the test scirpt to demonstrate the\ntopology in the new documentation myself, and the merge-octupos update I\nsent earlier to the list can come on top of this series.\n"}]}