git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Adam Simpkins <adam@adamsimpkins.net>
To: git@vger.kernel.org
Cc: Teemu Likonen <tlikonen@iki.fi>,
	Junio C Hamano <gitster@pobox.com>,
	Adam Simpkins <adam@adamsimpkins.net>
Subject: [PATCH] graph API: fix "git log --graph --first-parent"
Date: Thu,  5 Jun 2008 01:56:19 -0700	[thread overview]
Message-ID: <1212656179-13637-1-git-send-email-adam@adamsimpkins.net> (raw)
In-Reply-To: <20080604180432.GA31437@adamsimpkins.net>

This change teaches the graph API that only the first parent of each
commit is interesting when "--first-parent" was specified.

This change also consolidates the graph parent walking logic into two
new internal functions, first_interesting_parent() and
next_interesting_parent().  A simpler fix would have been to simply
break at the end of the 2 existing for loops when
graph->revs->first_parent_only is set.  However, this change seems
nicer, especially if we ever need to add any new loops over the parent
list in the future.

Signed-off-by: Adam Simpkins <adam@adamsimpkins.net>
---
 graph.c |   64 ++++++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 53 insertions(+), 11 deletions(-)

diff --git a/graph.c b/graph.c
index edfab2d..283b137 100644
--- a/graph.c
+++ b/graph.c
@@ -237,6 +237,52 @@ static int graph_is_interesting(struct git_graph *graph, struct commit *commit)
 	return (commit->object.flags & (UNINTERESTING | TREESAME)) ? 0 : 1;
 }
 
+static struct commit_list *next_interesting_parent(struct git_graph *graph,
+						   struct commit_list *orig)
+{
+	struct commit_list *list;
+
+	/*
+	 * If revs->first_parent_only is set, only the first
+	 * parent is interesting.  None of the others are.
+	 */
+	if (graph->revs->first_parent_only)
+		return NULL;
+
+	/*
+	 * Return the next interesting commit after orig
+	 */
+	for (list = orig->next; list; list = list->next) {
+		if (graph_is_interesting(graph, list->item))
+			return list;
+	}
+
+	return NULL;
+}
+
+static struct commit_list *first_interesting_parent(struct git_graph *graph)
+{
+	struct commit_list *parents = graph->commit->parents;
+
+	/*
+	 * If this commit has no parents, ignore it
+	 */
+	if (!parents)
+		return NULL;
+
+	/*
+	 * If the first parent is interesting, return it
+	 */
+	if (graph_is_interesting(graph, parents->item))
+		return parents;
+
+	/*
+	 * Otherwise, call next_interesting_parent() to get
+	 * the next interesting parent
+	 */
+	return next_interesting_parent(graph, parents);
+}
+
 static void graph_insert_into_new_columns(struct git_graph *graph,
 					  struct commit *commit,
 					  int *mapping_index)
@@ -244,12 +290,6 @@ static void graph_insert_into_new_columns(struct git_graph *graph,
 	int i;
 
 	/*
-	 * Ignore uinteresting commits
-	 */
-	if (!graph_is_interesting(graph, commit))
-		return;
-
-	/*
 	 * If the commit is already in the new_columns list, we don't need to
 	 * add it.  Just update the mapping correctly.
 	 */
@@ -373,9 +413,9 @@ static void graph_update_columns(struct git_graph *graph)
 			int old_mapping_idx = mapping_idx;
 			seen_this = 1;
 			graph->commit_index = i;
-			for (parent = graph->commit->parents;
+			for (parent = first_interesting_parent(graph);
 			     parent;
-			     parent = parent->next) {
+			     parent = next_interesting_parent(graph, parent)) {
 				graph_insert_into_new_columns(graph,
 							      parent->item,
 							      &mapping_idx);
@@ -420,9 +460,11 @@ void graph_update(struct git_graph *graph, struct commit *commit)
 	 * Count how many interesting parents this commit has
 	 */
 	graph->num_parents = 0;
-	for (parent = commit->parents; parent; parent = parent->next) {
-		if (graph_is_interesting(graph, parent->item))
-			graph->num_parents++;
+	for (parent = first_interesting_parent(graph);
+	     parent;
+	     parent = next_interesting_parent(graph, parent))
+	{
+		graph->num_parents++;
 	}
 
 	/*
-- 
1.5.6.rc1.13.g14be6

  reply	other threads:[~2008-06-05  8:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-04 15:00 log --graph --first-parent weirdness Teemu Likonen
2008-06-04 15:08 ` Teemu Likonen
2008-06-04 17:12 ` Junio C Hamano
2008-06-04 17:38   ` Teemu Likonen
2008-06-04 18:04     ` Adam Simpkins
2008-06-05  8:56       ` Adam Simpkins [this message]
2008-06-04 18:05     ` Junio C Hamano
2008-06-05  1:37       ` Ping Yin
2008-06-05  9:28       ` Adam Simpkins
2008-06-05  9:50       ` Teemu Likonen
2008-06-05 18:31         ` Junio C Hamano

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=1212656179-13637-1-git-send-email-adam@adamsimpkins.net \
    --to=adam@adamsimpkins.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=tlikonen@iki.fi \
    /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).