* [RFC/PATCH] merge-base: teach "git merge-base" to accept more than 2 arguments
@ 2008-07-26 3:59 Christian Couder
2008-07-26 4:25 ` Johannes Schindelin
2008-07-26 4:37 ` Junio C Hamano
0 siblings, 2 replies; 3+ messages in thread
From: Christian Couder @ 2008-07-26 3:59 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Miklos Vajna
Before this patch "git merge-base" accepted only 2 arguments, so
only merge bases between 2 references could be computed.
The purpose of this patch is to make "git merge-base" accept more
than 2 arguments so that the merge bases between the first given
reference and all the other references can be computed.
This is easily implemented because the "get_merge_bases_many"
function in "commit.c" already implements the computation.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
builtin-merge-base.c | 51 ++++++++++++++++++++++++++++++++++++-------------
commit.h | 2 +
2 files changed, 39 insertions(+), 14 deletions(-)
I suspect this patch may be usefull to simplify my
"bisect: add merge bases check" series and perhaps
also generally usefull.
I will add documentation and perhaps tests too if
people are ok with something like that.
By the way perhaps such a patch has already been
posted by someone else. In this case sorry for the
noise and thanks for any pointer to the previous
patch.
diff --git a/builtin-merge-base.c b/builtin-merge-base.c
index 1cb2925..9c41849 100644
--- a/builtin-merge-base.c
+++ b/builtin-merge-base.c
@@ -2,9 +2,14 @@
#include "cache.h"
#include "commit.h"
-static int show_merge_base(struct commit *rev1, struct commit *rev2, int show_all)
+static struct commit *rev1, **prev2;
+static size_t prev2_nr, prev2_alloc;
+
+
+static int show_merge_base(int show_all)
{
- struct commit_list *result = get_merge_bases(rev1, rev2, 0);
+ struct commit_list *result = get_merge_bases_many(rev1, prev2_nr,
+ prev2, 0);
if (!result)
return 1;
@@ -20,12 +25,24 @@ static int show_merge_base(struct commit *rev1, struct commit *rev2, int show_al
}
static const char merge_base_usage[] =
-"git merge-base [--all] <commit-id> <commit-id>";
+"git merge-base [--all] <commit-id> <commit-id>...";
+
+static void append_rev2(struct commit *rev)
+{
+ ALLOC_GROW(prev2, prev2_nr + 1, prev2_alloc);
+ prev2[prev2_nr++] = rev;
+}
+
+static struct commit *get_commit_reference(const char *arg)
+{
+ unsigned char revkey[20];
+ if (get_sha1(arg, revkey))
+ die("Not a valid object name %s", arg);
+ return lookup_commit_reference(revkey);
+}
int cmd_merge_base(int argc, const char **argv, const char *prefix)
{
- struct commit *rev1, *rev2;
- unsigned char rev1key[20], rev2key[20];
int show_all = 0;
git_config(git_default_config, NULL);
@@ -38,15 +55,21 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix)
usage(merge_base_usage);
argc--; argv++;
}
- if (argc != 3)
+ if (argc < 3)
usage(merge_base_usage);
- if (get_sha1(argv[1], rev1key))
- die("Not a valid object name %s", argv[1]);
- if (get_sha1(argv[2], rev2key))
- die("Not a valid object name %s", argv[2]);
- rev1 = lookup_commit_reference(rev1key);
- rev2 = lookup_commit_reference(rev2key);
- if (!rev1 || !rev2)
+
+ rev1 = get_commit_reference(argv[1]);
+ if (!rev1)
return 1;
- return show_merge_base(rev1, rev2, show_all);
+ argc--; argv++;
+
+ do {
+ struct commit *rev2 = get_commit_reference(argv[1]);
+ if (!rev2)
+ return 1;
+ append_rev2(rev2);
+ argc--; argv++;
+ } while (argc > 1);
+
+ return show_merge_base(show_all);
}
diff --git a/commit.h b/commit.h
index 77de962..4829a5c 100644
--- a/commit.h
+++ b/commit.h
@@ -121,6 +121,8 @@ int read_graft_file(const char *graft_file);
struct commit_graft *lookup_commit_graft(const unsigned char *sha1);
extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2, int cleanup);
+extern struct commit_list *get_merge_bases_many(struct commit *one,
+ int n, struct commit **twos, int cleanup);
extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
extern int register_shallow(const unsigned char *sha1);
--
1.6.0.rc0.43.g62478.dirty
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [RFC/PATCH] merge-base: teach "git merge-base" to accept more than 2 arguments
2008-07-26 3:59 [RFC/PATCH] merge-base: teach "git merge-base" to accept more than 2 arguments Christian Couder
@ 2008-07-26 4:25 ` Johannes Schindelin
2008-07-26 4:37 ` Junio C Hamano
1 sibling, 0 replies; 3+ messages in thread
From: Johannes Schindelin @ 2008-07-26 4:25 UTC (permalink / raw)
To: Christian Couder; +Cc: git, Junio C Hamano, Miklos Vajna
Hi,
On Sat, 26 Jul 2008, Christian Couder wrote:
> I suspect this patch may be usefull to simplify my
> "bisect: add merge bases check" series and perhaps
> also generally usefull.
s/usefull/useful/
> diff --git a/builtin-merge-base.c b/builtin-merge-base.c
> index 1cb2925..9c41849 100644
> --- a/builtin-merge-base.c
> +++ b/builtin-merge-base.c
> @@ -2,9 +2,14 @@
> #include "cache.h"
> #include "commit.h"
>
> -static int show_merge_base(struct commit *rev1, struct commit *rev2, int show_all)
> +static struct commit *rev1, **prev2;
> +static size_t prev2_nr, prev2_alloc;
> +
> +
> +static int show_merge_base(int show_all)
> {
Changing the arguments to be static variables?
NACK!
Ciao,
Dscho
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFC/PATCH] merge-base: teach "git merge-base" to accept more than 2 arguments
2008-07-26 3:59 [RFC/PATCH] merge-base: teach "git merge-base" to accept more than 2 arguments Christian Couder
2008-07-26 4:25 ` Johannes Schindelin
@ 2008-07-26 4:37 ` Junio C Hamano
1 sibling, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2008-07-26 4:37 UTC (permalink / raw)
To: Christian Couder; +Cc: git, Miklos Vajna
Christian Couder <chriscool@tuxfamily.org> writes:
> Before this patch "git merge-base" accepted only 2 arguments, so
> only merge bases between 2 references could be computed.
>
> The purpose of this patch is to make "git merge-base" accept more
> than 2 arguments so that the merge bases between the first given
> reference and all the other references can be computed.
I think this is a logical conclusion of merge_bases_many(). You need
tests and docs, though.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-07-26 4:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-26 3:59 [RFC/PATCH] merge-base: teach "git merge-base" to accept more than 2 arguments Christian Couder
2008-07-26 4:25 ` Johannes Schindelin
2008-07-26 4:37 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).