From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Christian Couder <chriscool@tuxfamily.org>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
Miklos Vajna <vmiklos@frugalware.org>
Subject: Re: [RFC/PATCH v2] merge-base: teach "git merge-base" to accept more than 2 arguments
Date: Sun, 27 Jul 2008 16:38:05 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.1.00.0807271631470.5526@eeepc-johanness> (raw)
In-Reply-To: <20080727053324.b54fe48e.chriscool@tuxfamily.org>
Hi,
On Sun, 27 Jul 2008, Christian Couder wrote:
> diff --git a/builtin-merge-base.c b/builtin-merge-base.c
> index 1cb2925..f2c9756 100644
> --- a/builtin-merge-base.c
> +++ b/builtin-merge-base.c
> @@ -38,15 +48,22 @@ 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;
Why do you special case rev1? Is it so special? Just handle it together
with all of the other arguments!
IOW have one commit array, and do not call it "prev".
> - return show_merge_base(rev1, rev2, show_all);
> + argc--; argv++;
> +
> + do {
> + struct commit *rev2 = get_commit_reference(argv[1]);
> + if (!rev2)
> + return 1;
> + ALLOC_GROW(prev2, prev2_nr + 1, prev2_alloc);
> + prev2[prev2_nr++] = rev2;
> + argc--; argv++;
> + } while (argc > 1);
Now, this is ugly. You know beforehand the _exact_ number of arguments,
and yet you dynamically grow the array? Also, why do you use a do { }
while(), when a for () would be much, much clearer?
BTW I seem to recall that get_merge_bases_many() was _not_ the same as
get_merge_octopus(). Could you please remind me what _many() does?
Ciao,
Dscho
next prev parent reply other threads:[~2008-07-27 14:38 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-27 3:33 [RFC/PATCH v2] merge-base: teach "git merge-base" to accept more than 2 arguments Christian Couder
2008-07-27 4:47 ` Junio C Hamano
2008-07-28 6:10 ` Christian Couder
2008-07-28 6:18 ` Junio C Hamano
2008-07-27 14:38 ` Johannes Schindelin [this message]
2008-07-27 15:28 ` Miklos Vajna
2008-07-27 18:11 ` Junio C Hamano
2008-07-27 20:44 ` Johannes Schindelin
2008-07-27 20:47 ` Re* " Junio C Hamano
2008-07-28 5:49 ` Christian Couder
2008-07-27 15:02 ` Jakub Narebski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.1.00.0807271631470.5526@eeepc-johanness \
--to=johannes.schindelin@gmx.de \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=vmiklos@frugalware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox