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 <[EMAIL PROTECTED]>
---
Documentation/git-rev-list.txt | 2 +
rev-list.c | 54 +++++++++++++++++++++++++++-------------
2 files changed, 38 insertions(+), 18 deletions(-)
1ecc1f5936fb35d2ea8e7aef2d97643a78fe1069
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;
}
------------
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at http://vger.kernel.org/majordomo-info.html