topo-order: make --date-order optional.
This adds --date-order to rev-list; it is similar to topo order in the sense that no parent comes before all of its children, but otherwise things are still ordered in the commit timestamp order. The same flag is also added to show-branch. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Feb 15, 2006 at 22:05 UTC
4c8725f16abff4be4812d0d07a663250bef3ef0e
5 files changed
+29
-9
commit.c
+10
-3
@@ -571,7 +571,7 @@ int count_parents(struct commit * commit)
571
/*
572
* Performs an in-place topological sort on the list supplied.
573
*/
574
-void sort_in_topological_order(struct commit_list ** list)
574
+void sort_in_topological_order(struct commit_list ** list, int lifo)
575
{
576
struct commit_list * next = *list;
577
struct commit_list * work = NULL, **insert;
@@ -630,7 +630,10 @@ void sort_in_topological_order(struct commit_list ** list)
630
}
631
next=next->next;
632
}
633
+
634
/* process the list in topological order */
635
+ if (!lifo)
636
+ sort_by_date(&work);
637
while (work) {
638
struct commit * work_item = pop_commit(&work);
639
struct sort_node * work_node = (struct sort_node *)work_item->object.util;
@@ -647,8 +650,12 @@ void sort_in_topological_order(struct commit_list ** list)
650
* guaranteeing topological order.
651
*/
652
pn->indegree--;
650
- if (!pn->indegree)
651
- commit_list_insert(parent, &work);
653
+ if (!pn->indegree) {
654
+ if (!lifo)
655
+ insert_by_date(parent, &work);
656
+ else
657
+ commit_list_insert(parent, &work);
658
+ }
659
}
660
parents=parents->next;
661
}
commit.h
+3
-1
@@ -72,6 +72,8 @@ int count_parents(struct commit * commit);
72
* Post-conditions:
73
* invariant of resulting list is:
74
* a reachable from b => ord(b) < ord(a)
75
+ * in addition, when lifo == 0, commits on parallel tracks are
76
+ * sorted in the dates order.
77
*/
76
-void sort_in_topological_order(struct commit_list ** list);
78
+void sort_in_topological_order(struct commit_list ** list, int lifo);
79
#endif /* COMMIT_H */
rev-list.c
+10
-1
@@ -27,6 +27,7 @@ static const char rev_list_usage[] =
27
" ordering output:\n"
28
" --merge-order [ --show-breaks ]\n"
29
" --topo-order\n"
30
+" --date-order\n"
31
" formatting output:\n"
32
" --parents\n"
33
" --objects\n"
@@ -56,6 +57,7 @@ static int merge_order = 0;
57
static int show_breaks = 0;
58
static int stop_traversal = 0;
59
static int topo_order = 0;
60
+static int lifo = 1;
61
static int no_merges = 0;
62
static const char **paths = NULL;
63
static int remove_empty_trees = 0;
@@ -856,6 +858,13 @@ int main(int argc, const char **argv)
858
}
859
if (!strcmp(arg, "--topo-order")) {
860
topo_order = 1;
861
+ lifo = 1;
862
+ limited = 1;
863
+ continue;
864
+ }
865
+ if (!strcmp(arg, "--date-order")) {
866
+ topo_order = 1;
867
+ lifo = 0;
868
limited = 1;
869
continue;
870
}
@@ -940,7 +949,7 @@ int main(int argc, const char **argv)
949
if (limited)
950
list = limit_list(list);
951
if (topo_order)
943
- sort_in_topological_order(&list);
952
+ sort_in_topological_order(&list, lifo);
953
show_commit_list(list);
954
} else {
955
#ifndef NO_OPENSSL
rev-parse.c
+1
@@ -48,6 +48,7 @@ static int is_rev_argument(const char *arg)
48
"--show-breaks",
49
"--sparse",
50
"--topo-order",
51
+ "--date-order",
52
"--unpacked",
53
NULL
54
};
show-branch.c
+5
-4
@@ -535,6 +535,7 @@ int main(int ac, char **av)
535
int num_rev, i, extra = 0;
536
int all_heads = 0, all_tags = 0;
537
int all_mask, all_revs;
538
+ int lifo = 1;
539
char head_path[128];
540
const char *head_path_p;
541
int head_path_len;
@@ -544,7 +545,6 @@ int main(int ac, char **av)
545
int no_name = 0;
546
int sha1_name = 0;
547
int shown_merge_point = 0;
547
- int topo_order = 0;
548
int with_current_branch = 0;
549
int head_at = -1;
550
@@ -586,7 +586,9 @@ int main(int ac, char **av)
586
else if (!strcmp(arg, "--independent"))
587
independent = 1;
588
else if (!strcmp(arg, "--topo-order"))
589
- topo_order = 1;
589
+ lifo = 1;
590
+ else if (!strcmp(arg, "--date-order"))
591
+ lifo = 0;
592
else
593
usage(show_branch_usage);
594
ac--; av++;
@@ -710,8 +712,7 @@ int main(int ac, char **av)
712
exit(0);
713
714
/* Sort topologically */
713
- if (topo_order)
714
- sort_in_topological_order(&seen);
715
+ sort_in_topological_order(&seen, lifo);
716
717
/* Give names to commits */
718
if (!sha1_name && !no_name)