From: Petr Baudis <pasky@ucw.cz>
To: Daniel Barkalow <barkalow@iabervon.org>
Cc: git@vger.kernel.org
Subject: Re: Add merge-base
Date: Sun, 17 Apr 2005 18:01:06 +0200 [thread overview]
Message-ID: <20050417160106.GI1487@pasky.ji.cz> (raw)
In-Reply-To: <Pine.LNX.4.21.0504171124340.30848-100000@iabervon.org>
Dear diary, on Sun, Apr 17, 2005 at 05:27:13PM CEST, I got a letter
where Daniel Barkalow <barkalow@iabervon.org> told me that...
> merge-base finds one of the best common ancestors of a pair of commits. In
> particular, it finds one of the ones which is fewest commits away from the
> further of the heads.
What does it return when I have
A -- C
\/ \
/\ /
B -- D
? >:)
I assume just either A or B, randomly?
I think it would be best if it could list all the "first-class" matches
(both A and B in this case), each on a separate line; this way the
overlay tools could choose an algorithm to evaluate those further as
they see fit - e.g. sort them by time (you might aid that by listing the
commit time in front of them), then take the first n and try to diff
them all and take the one with least changes (as suggested by Linus).
And if someone doesn't care, he just does | head -n 1 | cut -f 2.
> Index: merge-base.c
> ===================================================================
> --- /dev/null (tree:37a0b01b85c2999243674d48bfc71cdba0e5518e)
> +++ d662b707e11391f6cfe597fd4d0bf9c41d34d01a/merge-base.c (mode:100644 sha1:0f85e7d9e9a896d1142a54170ddf1159f11f9cdd)
> @@ -0,0 +1,108 @@
> +#include <stdlib.h>
> +#include "cache.h"
> +#include "revision.h"
> +
> +struct revision *common_ancestor(struct revision *rev1, struct revision *rev2)
> +{
> + struct parent *parent;
> +
> + struct parent *rev1list = malloc(sizeof(struct parent));
> + struct parent *rev2list = malloc(sizeof(struct parent));
Did I overlook anything or you could have just a single revlist?
> +
I smell trailing whitespaces!
> + struct parent *posn, *temp;
> +
> + rev1list->parent = rev1;
> + rev1list->next = NULL;
> +
> + rev2list->parent = rev2;
> + rev2list->next = NULL;
> +
> + while (rev1list || rev2list) {
> + posn = rev1list;
> + rev1list = NULL;
> + while (posn) {
> + parse_commit_object(posn->parent);
> + if (posn->parent->flags & 0x0001) {
> + /*
> + printf("1 already seen %s %x\n",
> + sha1_to_hex(posn->parent->sha1),
> + posn->parent->flags);
> + */
> + // do nothing
Mostly for consistency, I'd prefer you to use /* */ comments in general.
I think a terrified squeak at stderr in this situation (possibly
suggesting fsck-cache) might be appropriate.
> + } else if (posn->parent->flags & 0x0002) {
> + // XXXX free lists
Hmm, so, why not free the lists?
> + return posn->parent;
> + } else {
> + /*
> + printf("1 based on %s\n",
> + sha1_to_hex(posn->parent->sha1));
> + */
> + posn->parent->flags |= 0x0001;
> +
> + parent = posn->parent->parent;
> + while (parent) {
> + temp = malloc(sizeof(struct parent));
> + temp->next = rev1list;
> + temp->parent = parent->parent;
> + rev1list = temp;
> + parent = parent->next;
> + }
> + }
> + posn = posn->next;
> + }
> + posn = rev2list;
> + rev2list = NULL;
> + while (posn) {
> + parse_commit_object(posn->parent);
> + if (posn->parent->flags & 0x0002) {
> + /*
> + printf("2 already seen %s\n",
> + sha1_to_hex(posn->parent->sha1));
> + */
> + // do nothing
> + } else if (posn->parent->flags & 0x0001) {
> + // XXXX free lists
> + return posn->parent;
> + } else {
> + /*
> + printf("2 based on %s\n",
> + sha1_to_hex(posn->parent->sha1));
> + */
> + posn->parent->flags |= 0x0002;
> +
> + parent = posn->parent->parent;
> + while (parent) {
> + temp = malloc(sizeof(struct parent));
> + temp->next = rev2list;
> + temp->parent = parent->parent;
> + rev2list = temp;
> + parent = parent->next;
> + }
> + }
> + posn = posn->next;
> + }
Symmetrical notes apply to this half. Actually, they are too similar.
What about factoring them to a common function?
> + }
> + return NULL;
> +}
> +
> +int main(int argc, char **argv)
> +{
> + struct revision *rev1, *rev2, *ret;
> + unsigned char rev1key[20], rev2key[20];
A newline here please.
> + if (argc != 3 ||
> + get_sha1_hex(argv[1], rev1key) ||
> + get_sha1_hex(argv[2], rev2key)) {
> + usage("mergebase <commit-id> <commit-id>");
> + }
> + rev1 = lookup_rev(rev1key);
> + rev2 = lookup_rev(rev2key);
> + ret = common_ancestor(rev1, rev2);
> + if (ret) {
> + printf("%s\n", sha1_to_hex(ret->sha1));
> + return 0;
> + } else {
> + printf("Sorry.\n");
> + return 1;
Please stay silent if you don't have anything useful to say.
> + }
> +
> +}
--
Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor
next prev parent reply other threads:[~2005-04-17 15:57 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20050417144947.GG1487@pasky.ji.cz>
2005-04-17 15:20 ` [0/5] Patch set for various things Daniel Barkalow
2005-04-17 15:24 ` [1/5] Parsing code in revision.h Daniel Barkalow
2005-04-17 16:09 ` Petr Baudis
2005-04-17 16:44 ` Daniel Barkalow
2005-04-17 18:18 ` [1/5] " Linus Torvalds
2005-04-17 18:30 ` Petr Baudis
2005-04-17 19:25 ` Linus Torvalds
2005-04-17 19:45 ` Daniel Barkalow
2005-04-17 19:54 ` Linus Torvalds
2005-04-17 20:06 ` Linus Torvalds
2005-04-17 20:22 ` Daniel Barkalow
2005-04-17 19:09 ` Daniel Barkalow
2005-04-17 15:27 ` [2/5] Add merge-base Daniel Barkalow
2005-04-17 16:01 ` Petr Baudis [this message]
2005-04-17 16:36 ` Daniel Barkalow
2005-04-17 16:51 ` [2.1/5] " Daniel Barkalow
2005-04-17 21:21 ` Petr Baudis
2005-04-17 21:25 ` Daniel Barkalow
2005-04-17 15:31 ` [3/5] Add http-pull Daniel Barkalow
2005-04-17 18:10 ` Petr Baudis
2005-04-17 18:49 ` Daniel Barkalow
2005-04-17 19:08 ` Petr Baudis
2005-04-17 19:24 ` Daniel Barkalow
2005-04-17 19:59 ` Petr Baudis
2005-04-21 3:27 ` Brad Roberts
2005-04-21 4:28 ` Daniel Barkalow
2005-04-21 22:05 ` tony.luck
2005-04-22 19:46 ` Daniel Barkalow
2005-04-22 22:40 ` Petr Baudis
2005-04-22 23:00 ` Daniel Barkalow
2005-04-22 23:08 ` Petr Baudis
2005-04-22 23:12 ` Daniel Barkalow
2005-04-22 23:24 ` Martin Schlemmer
2005-04-17 18:58 ` [3.1/5] " Daniel Barkalow
2005-04-17 15:35 ` [4/5] Add option for hardlinkable cache of extracted blobs Daniel Barkalow
2005-04-17 17:47 ` Petr Baudis
2005-04-17 18:54 ` Daniel Barkalow
2005-04-17 19:25 ` Paul Jackson
2005-04-17 19:59 ` Petr Baudis
2005-04-17 20:03 ` Daniel Barkalow
2005-04-17 20:18 ` Petr Baudis
2005-04-18 1:35 ` Paul Jackson
2005-04-18 1:48 ` Petr Baudis
2005-04-18 4:49 ` Paul Jackson
2005-04-17 20:58 ` Russell King
2005-04-17 22:10 ` First ever real kernel git merge! Linus Torvalds
2005-04-18 1:24 ` [4/5] Add option for hardlinkable cache of extracted blobs Paul Jackson
2005-04-18 1:20 ` Paul Jackson
2005-04-17 15:37 ` [5/5] Add commit-id to version Daniel Barkalow
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050417160106.GI1487@pasky.ji.cz \
--to=pasky@ucw.cz \
--cc=barkalow@iabervon.org \
--cc=git@vger.kernel.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).