Git development
 help / color / mirror / Atom feed
From: Jon Seymour <jon.seymour@gmail.com>
To: git@vger.kernel.org
Cc: torvalds@osdl.org, jon.seymour@gmail.com
Subject: [PATCH 3/13] Introduce struct rev_list_fns to rev-list.c to reduce amount of conditional processing.
Date: Thu, 07 Jul 2005 02:39:34 +1000	[thread overview]
Message-ID: <20050706163934.9851.qmail@blackcubes.dyndns.org> (raw)


Per a suggestion from Linus, I have introduced the rev_list_fns structure into
rev-list.c

The intent of this change is to make use of a strategy pattern to configure 
the behaviour of git-rev-list and so help limit the ever-increasing 
proliferation of boolean switches throughout the body of the code.

This change also makes --show-breaks imply --merge-order rather than require
it as before. There was no advantage to the previous strict argument
checking.

A subsequent change will take advantage of this pattern to introduce a
topological sort switch.

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---

 Documentation/git-rev-list.txt |    2 +
 rev-list.c                     |   54 +++++++++++++++++++++++++++-------------
 2 files changed, 38 insertions(+), 18 deletions(-)

77418fc85cc40e56ef66c5031025399c5e6ed787
diff --git a/Documentation/git-rev-list.txt b/Documentation/git-rev-list.txt
--- a/Documentation/git-rev-list.txt
+++ b/Documentation/git-rev-list.txt
@@ -57,7 +57,7 @@ Commits marked with (^) are not parents 
 These "breaks" represent necessary discontinuities implied by trying to
 represent an arbtirary DAG in a linear form.
 
-*--show-breaks* is only valid if *--merge-order* is also specified.
+*--show-breaks* implies **-merge-order*.
 
 Author
 ------
diff --git a/rev-list.c b/rev-list.c
--- a/rev-list.c
+++ b/rev-list.c
@@ -39,6 +39,12 @@ static int merge_order = 0;
 static int show_breaks = 0;
 static int stop_traversal = 0;
 
+struct rev_list_fns {
+	struct commit_list * (*insert)(struct commit *, struct commit_list **);
+	struct commit_list * (*limit)(struct commit_list *);
+	void (*process)(struct commit_list *);
+};
+
 static void show_commit(struct commit *commit)
 {
 	commit->object.flags |= SHOWN;
@@ -410,9 +416,30 @@ static struct commit *get_commit_referen
 	die("%s is unknown object", name);
 }
 
+static void merge_order_sort(struct commit_list * list)
+{
+	if (sort_list_in_merge_order(list, &process_commit))
+		die("commit graph traversal failed");
+}
+
+struct rev_list_fns default_fns = {
+	&insert_by_date,
+	&limit_list,
+        &show_commit_list
+};
+
+struct rev_list_fns merge_order_fns = {
+	&commit_list_insert,
+	NULL,
+	&merge_order_sort
+};
+
 int main(int argc, char **argv)
 {
 	struct commit_list *list = NULL;
+	struct commit_list *sorted = NULL;
+	struct commit_list **list_tail = &list;
+	struct rev_list_fns * fns = &default_fns;
 	int i, limited = 0;
 
 	for (i = 1 ; i < argc; i++) {
@@ -468,6 +495,7 @@ int main(int argc, char **argv)
 		}
 		if (!strcmp(arg, "--show-breaks")) {
 			show_breaks = 1;
+			merge_order = 1;
 			continue;
 		}
 
@@ -477,26 +505,18 @@ int main(int argc, char **argv)
 			arg++;
 			limited = 1;
 		}
-		if (show_breaks && !merge_order)
-			usage(rev_list_usage);
 		commit = get_commit_reference(arg, flags);
 		if (!commit)
 			continue;
-		if (!merge_order) 
-			insert_by_date(commit, &list);
-		else 
-			commit_list_insert(commit, &list);
+		list_tail = &commit_list_insert(commit, list_tail)->next;
 	}
-
-	if (!merge_order) {		
-	        if (limited)
-			list = limit_list(list);
-		show_commit_list(list);
-	} else {
-		if (sort_list_in_merge_order(list, &process_commit)) {
-			  die("merge order sort failed\n");
-		}
-	}
-
+	if (merge_order)
+		fns=&merge_order_fns;
+	while (list)
+		fns->insert(pop_commit(&list), &sorted);
+	list=sorted;
+	if (limited && fns->limit)
+		list = fns->limit(list);
+	fns->process(list);
 	return 0;
 }
------------

                 reply	other threads:[~2005-07-06 16:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20050706163934.9851.qmail@blackcubes.dyndns.org \
    --to=jon.seymour@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=torvalds@osdl.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