git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miklos Vajna <vmiklos@frugalware.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH] Introduce filter_independent() in commit.c
Date: Sat, 21 Jun 2008 02:23:04 +0200	[thread overview]
Message-ID: <1214007784-4801-1-git-send-email-vmiklos@frugalware.org> (raw)
In-Reply-To: <7vabhgq02p.fsf@gitster.siamese.dyndns.org>

This is similar to git-show-branch --independent: It filters out commits
which are reachable from any other item from the input list.

Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
---

On Thu, Jun 19, 2008 at 08:03:58PM -0700, Junio C Hamano <gitster@pobox.com> wrote:
> > +   for (i = heads; i; i = i->next)
> > +           if (!(i->item->object.flags & RESULT))
> > +                   pptr = &commit_list_insert(i->item, pptr)->next;
>
> Hmm.  How well was this function tested?

As Dscho pointed out in an other mail there was no testcase for it, I
wrote one and it pointed out what you said: it was buggy.

> Because RESULT is an implementation detail of merge_bases(), I do not
> think we would want to expose it outside of it.

The new version does not have this problem, either.

> More worryingly, the flag is supposed to be cleaned from the objects
> after get_merge_bases() returns.  I am not sure what you'll learn by
> looking at the flag here.

Yes, you are right. In fact the idea to use get_octopus_merge_bases()
was wrong, since it does not do what we need.

Here is an example:

	A - B
	  \ C
	  \ D
	  \ E - F

In this case get_octopus_merge_bases() will return only A, which is what
it should do, but we need E in filter_indepenent() as well.

Below is what I pushed to my working branch.

This version now passes the test that was failed for the previous one.

 commit.c |   32 ++++++++++++++++++++++++++++++++
 commit.h |    1 +
 2 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/commit.c b/commit.c
index 6052ca3..17e18d7 100644
--- a/commit.c
+++ b/commit.c
@@ -705,3 +705,35 @@ int in_merge_bases(struct commit *commit, struct commit **reference, int num)
 	free_commit_list(bases);
 	return ret;
 }
+
+struct commit_list *filter_independent(unsigned char *head,
+	struct commit_list *heads)
+{
+	struct commit_list *b, *i, *j, *k, *bases = NULL, *ret = NULL;
+	struct commit_list **pptr = &ret;
+
+	commit_list_insert(lookup_commit(head), &heads);
+
+	for (i = heads; i; i = i->next) {
+		for (j = heads; j; j = j->next) {
+			if (i == j)
+				continue;
+			b = get_merge_bases(i->item, j->item, 1);
+			for (k = b; k; k = k->next)
+				commit_list_insert(k->item, &bases);
+		}
+	}
+
+	for (i = heads; i; i = i->next) {
+		int found = 0;
+		for (b = bases; b; b = b->next) {
+			if (!hashcmp(i->item->object.sha1, b->item->object.sha1)) {
+				found = 1;
+				break;
+			}
+		}
+		if (!found)
+			pptr = &commit_list_insert(i->item, pptr)->next;
+	}
+	return ret;
+}
diff --git a/commit.h b/commit.h
index dcec7fb..0aef7e4 100644
--- a/commit.h
+++ b/commit.h
@@ -131,6 +131,7 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
 		int depth, int shallow_flag, int not_shallow_flag);
 
 int in_merge_bases(struct commit *, struct commit **, int);
+struct commit_list *filter_independent(unsigned char *head, struct commit_list *heads);
 
 extern int interactive_add(int argc, const char **argv, const char *prefix);
 extern int rerere(void);
-- 
1.5.6

  parent reply	other threads:[~2008-06-21  0:24 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-19 23:22 [PATCH 00/11] Build in merge Miklos Vajna
2008-06-19 23:22 ` [PATCH 01/11] Move split_cmdline() to alias.c Miklos Vajna
2008-06-19 23:22   ` [PATCH 02/11] Move commit_list_count() to commit.c Miklos Vajna
2008-06-19 23:22     ` [PATCH 03/11] Move parse-options's skip_prefix() to git-compat-util.h Miklos Vajna
2008-06-19 23:22       ` [PATCH 04/11] Add new test to ensure git-merge handles pull.twohead and pull.octopus Miklos Vajna
2008-06-19 23:22         ` [PATCH 05/11] parseopt: add a new PARSE_OPT_ARGV0_IS_AN_OPTION option Miklos Vajna
2008-06-19 23:22           ` [PATCH 06/11] Move read_cache_unmerged() to read-cache.c Miklos Vajna
2008-06-19 23:22             ` [PATCH 07/11] git-fmt-merge-msg: make it usable from other builtins Miklos Vajna
2008-06-19 23:22               ` [PATCH 08/11] Introduce get_octopus_merge_bases() in commit.c Miklos Vajna
2008-06-19 23:22                 ` [PATCH 09/11] Introduce filter_independent() " Miklos Vajna
2008-06-19 23:22                   ` [PATCH 10/11] Build in merge Miklos Vajna
2008-06-19 23:22                     ` [PATCH 11/11] Add new test to ensure git-merge handles more than 25 refs Miklos Vajna
2008-06-20  3:03                   ` [PATCH 09/11] Introduce filter_independent() in commit.c Junio C Hamano
2008-06-20 11:53                     ` Johannes Schindelin
2008-06-20 12:06                       ` Miklos Vajna
2008-06-20 12:37                         ` Johannes Schindelin
2008-06-20 13:25                       ` Miklos Vajna
2008-06-21  0:23                     ` Miklos Vajna [this message]
2008-06-21  9:45                       ` [PATCH] " Junio C Hamano
2008-06-21 17:00                         ` [PATCH 00/13] Build in merge Miklos Vajna
2008-06-21 17:00                           ` [PATCH 09/13] Add new test to ensure git-merge handles more than 25 refs Miklos Vajna
2008-06-21 17:00                             ` [PATCH 10/13] Introduce get_merge_bases_many() Miklos Vajna
2008-06-21 17:00                               ` [PATCH 11/13] Introduce reduce_heads() Miklos Vajna
2008-06-21 17:00                                 ` [PATCH 12/13] Build in merge Miklos Vajna
2008-06-21 17:00                                   ` [PATCH 13/13] Add new test case to ensure git-merge filters for independent parents Miklos Vajna
2008-06-21 17:15                                     ` [PATCH 13/13] Add new test case to ensure git-merge reduces octopus parents when possible Miklos Vajna
2008-06-25 16:22                                   ` [PATCH 12/13] Build in merge Olivier Marin
2008-06-27  1:06                                     ` Miklos Vajna
2008-06-27 11:03                                       ` Olivier Marin
2008-06-27 12:54                                         ` Miklos Vajna
2008-06-27 13:04                                           ` Olivier Marin
2008-06-27 13:17                                             ` Miklos Vajna
2008-06-27 11:56                                       ` Johannes Schindelin
2008-06-27 13:01                                         ` Miklos Vajna
2008-06-21  9:45                       ` [PATCH 1/2] Introduce get_merge_bases_many() Junio C Hamano
2008-06-21  9:45                       ` [PATCH 2/2] Introduce reduce_heads() Junio C Hamano
2008-06-20  3:04 ` [PATCH 00/11] Build in merge Junio C Hamano
2008-06-21  0:32   ` Miklos Vajna

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=1214007784-4801-1-git-send-email-vmiklos@frugalware.org \
    --to=vmiklos@frugalware.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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;
as well as URLs for NNTP newsgroup(s).