提交 4c8725f1 编写于 作者: J Junio C Hamano

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: NJunio C Hamano <junkio@cox.net>
上级 be97bd1b
...@@ -571,7 +571,7 @@ int count_parents(struct commit * commit) ...@@ -571,7 +571,7 @@ int count_parents(struct commit * commit)
/* /*
* Performs an in-place topological sort on the list supplied. * Performs an in-place topological sort on the list supplied.
*/ */
void sort_in_topological_order(struct commit_list ** list) void sort_in_topological_order(struct commit_list ** list, int lifo)
{ {
struct commit_list * next = *list; struct commit_list * next = *list;
struct commit_list * work = NULL, **insert; struct commit_list * work = NULL, **insert;
...@@ -630,7 +630,10 @@ void sort_in_topological_order(struct commit_list ** list) ...@@ -630,7 +630,10 @@ void sort_in_topological_order(struct commit_list ** list)
} }
next=next->next; next=next->next;
} }
/* process the list in topological order */ /* process the list in topological order */
if (!lifo)
sort_by_date(&work);
while (work) { while (work) {
struct commit * work_item = pop_commit(&work); struct commit * work_item = pop_commit(&work);
struct sort_node * work_node = (struct sort_node *)work_item->object.util; 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) ...@@ -647,8 +650,12 @@ void sort_in_topological_order(struct commit_list ** list)
* guaranteeing topological order. * guaranteeing topological order.
*/ */
pn->indegree--; pn->indegree--;
if (!pn->indegree) if (!pn->indegree) {
commit_list_insert(parent, &work); if (!lifo)
insert_by_date(parent, &work);
else
commit_list_insert(parent, &work);
}
} }
parents=parents->next; parents=parents->next;
} }
......
...@@ -72,6 +72,8 @@ int count_parents(struct commit * commit); ...@@ -72,6 +72,8 @@ int count_parents(struct commit * commit);
* Post-conditions: * Post-conditions:
* invariant of resulting list is: * invariant of resulting list is:
* a reachable from b => ord(b) < ord(a) * a reachable from b => ord(b) < ord(a)
* in addition, when lifo == 0, commits on parallel tracks are
* sorted in the dates order.
*/ */
void sort_in_topological_order(struct commit_list ** list); void sort_in_topological_order(struct commit_list ** list, int lifo);
#endif /* COMMIT_H */ #endif /* COMMIT_H */
...@@ -27,6 +27,7 @@ static const char rev_list_usage[] = ...@@ -27,6 +27,7 @@ static const char rev_list_usage[] =
" ordering output:\n" " ordering output:\n"
" --merge-order [ --show-breaks ]\n" " --merge-order [ --show-breaks ]\n"
" --topo-order\n" " --topo-order\n"
" --date-order\n"
" formatting output:\n" " formatting output:\n"
" --parents\n" " --parents\n"
" --objects\n" " --objects\n"
...@@ -56,6 +57,7 @@ static int merge_order = 0; ...@@ -56,6 +57,7 @@ static int merge_order = 0;
static int show_breaks = 0; static int show_breaks = 0;
static int stop_traversal = 0; static int stop_traversal = 0;
static int topo_order = 0; static int topo_order = 0;
static int lifo = 1;
static int no_merges = 0; static int no_merges = 0;
static const char **paths = NULL; static const char **paths = NULL;
static int remove_empty_trees = 0; static int remove_empty_trees = 0;
...@@ -856,6 +858,13 @@ int main(int argc, const char **argv) ...@@ -856,6 +858,13 @@ int main(int argc, const char **argv)
} }
if (!strcmp(arg, "--topo-order")) { if (!strcmp(arg, "--topo-order")) {
topo_order = 1; topo_order = 1;
lifo = 1;
limited = 1;
continue;
}
if (!strcmp(arg, "--date-order")) {
topo_order = 1;
lifo = 0;
limited = 1; limited = 1;
continue; continue;
} }
...@@ -940,7 +949,7 @@ int main(int argc, const char **argv) ...@@ -940,7 +949,7 @@ int main(int argc, const char **argv)
if (limited) if (limited)
list = limit_list(list); list = limit_list(list);
if (topo_order) if (topo_order)
sort_in_topological_order(&list); sort_in_topological_order(&list, lifo);
show_commit_list(list); show_commit_list(list);
} else { } else {
#ifndef NO_OPENSSL #ifndef NO_OPENSSL
......
...@@ -48,6 +48,7 @@ static int is_rev_argument(const char *arg) ...@@ -48,6 +48,7 @@ static int is_rev_argument(const char *arg)
"--show-breaks", "--show-breaks",
"--sparse", "--sparse",
"--topo-order", "--topo-order",
"--date-order",
"--unpacked", "--unpacked",
NULL NULL
}; };
......
...@@ -535,6 +535,7 @@ int main(int ac, char **av) ...@@ -535,6 +535,7 @@ int main(int ac, char **av)
int num_rev, i, extra = 0; int num_rev, i, extra = 0;
int all_heads = 0, all_tags = 0; int all_heads = 0, all_tags = 0;
int all_mask, all_revs; int all_mask, all_revs;
int lifo = 1;
char head_path[128]; char head_path[128];
const char *head_path_p; const char *head_path_p;
int head_path_len; int head_path_len;
...@@ -544,7 +545,6 @@ int main(int ac, char **av) ...@@ -544,7 +545,6 @@ int main(int ac, char **av)
int no_name = 0; int no_name = 0;
int sha1_name = 0; int sha1_name = 0;
int shown_merge_point = 0; int shown_merge_point = 0;
int topo_order = 0;
int with_current_branch = 0; int with_current_branch = 0;
int head_at = -1; int head_at = -1;
...@@ -586,7 +586,9 @@ int main(int ac, char **av) ...@@ -586,7 +586,9 @@ int main(int ac, char **av)
else if (!strcmp(arg, "--independent")) else if (!strcmp(arg, "--independent"))
independent = 1; independent = 1;
else if (!strcmp(arg, "--topo-order")) else if (!strcmp(arg, "--topo-order"))
topo_order = 1; lifo = 1;
else if (!strcmp(arg, "--date-order"))
lifo = 0;
else else
usage(show_branch_usage); usage(show_branch_usage);
ac--; av++; ac--; av++;
...@@ -710,8 +712,7 @@ int main(int ac, char **av) ...@@ -710,8 +712,7 @@ int main(int ac, char **av)
exit(0); exit(0);
/* Sort topologically */ /* Sort topologically */
if (topo_order) sort_in_topological_order(&seen, lifo);
sort_in_topological_order(&seen);
/* Give names to commits */ /* Give names to commits */
if (!sha1_name && !no_name) if (!sha1_name && !no_name)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册