git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 1/4] "log" and friends: --children option
Date: Thu, 03 Apr 2008 02:12:06 -0700	[thread overview]
Message-ID: <7vlk3v2tg9.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <7v4paj486a.fsf@gitster.siamese.dyndns.org> (Junio C. Hamano's message of "Thu, 03 Apr 2008 02:08:45 -0700")

This adds a new --children option to the revision machinery.  In addition
to the list of parents, child commits of each commit are computed and
shown in the output from "git log" and friends.

Note that this does _not_ show all children of a commit.  It only shows
children on the commit ancestry you made the revision machinery traverse.
For example, "git log --children master..next" will not show side branches
forked from any commits shown in the range that have not been merged to
"next" (i.e. what are queued in 'pu' but not yet merged to 'next').

This patch was primarily done for adding the infrastructure to allow users
of revision machinery to find out children of commits; please consider the
current output not much more than debugging aid.  If you want to use it
from "git log" and friends, the output format needs a bit more serious
thought.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 log-tree.c |   20 ++++++++++++++++++++
 revision.c |   28 ++++++++++++++++++++++++++++
 revision.h |    1 +
 3 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/log-tree.c b/log-tree.c
index 5b29639..75851d1 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -32,6 +32,24 @@ void show_decorations(struct commit *commit)
 	putchar(')');
 }
 
+static void show_children(struct rev_info *revs, struct commit *commit, int abbrev)
+{
+	struct commit_list *p;
+
+	if (!revs->children.name)
+		return;
+	p = lookup_decoration(&revs->children, &commit->object);
+	if (!p)
+		return;
+	printf("child");
+	while (p) {
+		struct commit *child = p->item;
+		printf(" %s", diff_unique_abbrev(child->object.sha1, abbrev));
+		p = p->next;
+	}
+	putchar(revs->diffopt.line_termination);
+}
+
 /*
  * Search for "^[-A-Za-z]+: [^@]+@" pattern. It usually matches
  * Signed-off-by: and Acked-by: lines.
@@ -236,6 +254,7 @@ void show_log(struct rev_info *opt, const char *sep)
 			show_parents(commit, abbrev_commit);
 		show_decorations(commit);
 		putchar(opt->diffopt.line_termination);
+		show_children(opt, commit, abbrev_commit);
 		return;
 	}
 
@@ -297,6 +316,7 @@ void show_log(struct rev_info *opt, const char *sep)
 				return;
 			}
 		}
+		show_children(opt, commit, abbrev_commit);
 	}
 
 	if (!commit->buffer)
diff --git a/revision.c b/revision.c
index 196fedc..e5138b7 100644
--- a/revision.c
+++ b/revision.c
@@ -9,6 +9,7 @@
 #include "grep.h"
 #include "reflog-walk.h"
 #include "patch-ids.h"
+#include "decorate.h"
 
 volatile show_early_output_fn_t show_early_output;
 
@@ -1309,6 +1310,11 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
 				revs->no_walk = 0;
 				continue;
 			}
+			if (!strcmp(arg, "--children")) {
+				revs->children.name = "children";
+				revs->limited = 1;
+				continue;
+			}
 
 			opts = diff_opt_parse(&revs->diffopt, argv+i, argc-i);
 			if (opts > 0) {
@@ -1398,6 +1404,26 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
 	return left;
 }
 
+static void add_child(struct rev_info *revs, struct commit *parent, struct commit *child)
+{
+	struct commit_list *l = xcalloc(1, sizeof(*l));
+
+	l->item = child;
+	l->next = add_decoration(&revs->children, &parent->object, l);
+}
+
+static void set_children(struct rev_info *revs)
+{
+	struct commit_list *l;
+	for (l = revs->commits; l; l = l->next) {
+		struct commit *commit = l->item;
+		struct commit_list *p;
+
+		for (p = commit->parents; p; p = p->next)
+			add_child(revs, p->item, commit);
+	}
+}
+
 int prepare_revision_walk(struct rev_info *revs)
 {
 	int nr = revs->pending.nr;
@@ -1426,6 +1452,8 @@ int prepare_revision_walk(struct rev_info *revs)
 			return -1;
 	if (revs->topo_order)
 		sort_in_topological_order(&revs->commits, revs->lifo);
+	if (revs->children.name)
+		set_children(revs);
 	return 0;
 }
 
diff --git a/revision.h b/revision.h
index c8b3b94..966116c 100644
--- a/revision.h
+++ b/revision.h
@@ -98,6 +98,7 @@ struct rev_info {
 	struct diff_options pruning;
 
 	struct reflog_walk_info *reflog_info;
+	struct decoration children;
 };
 
 #define REV_TREE_SAME		0
-- 
1.5.5.rc3.139.g8b2cf

  reply	other threads:[~2008-04-03  9:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-03  9:08 [PATCH 0/4] Blame in reverse Junio C Hamano
2008-04-03  9:12 ` Junio C Hamano [this message]
2008-04-03 19:58   ` [PATCH 1/4] "log" and friends: --children option Johannes Schindelin
2008-04-03  9:13 ` [PATCH 2/4] builtin-blame.c: move prepare_final() into a separate function Junio C Hamano
2008-04-03  9:14 ` [PATCH 3/4] builtin-blame.c: allow more than 16 parents Junio C Hamano
2008-04-03  9:19 ` [PATCH 4/4] git-blame --reverse Junio C Hamano
2008-04-03 11:25 ` [PATCH 0/4] Blame in reverse Johannes Sixt
2008-04-03 19:47   ` 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

  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=7vlk3v2tg9.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --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).