commit/revisions: bookkeeping before refactoring

There are a few things that need to move around a little before making a big refactoring in the topo-order logic: 1. We need access to record_author_date() and compare_commits_by_author_date() in revision.c. These are used currently by sort_in_topological_order() in commit.c. 2. Moving these methods to commit.h requires adding an author_date_slab declaration to commit.h. Consumers will need their own implementation. 3. The add_parents_to_list() method in revision.c performs logic around the UNINTERESTING flag and other special cases depending on the struct rev_info. Allow this method to ignore a NULL 'list' parameter, as we will not be populating the list for our walk. Also rename the method to the slightly more generic name process_parents() to make clear that this method does more than add to a list (and no list is required anymore). Helped-by: Jeff King <peff@peff.net> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Nov 1, 2018 at 13:46 UTC 5284fc5cc9791b6526b36909373748bc14daef1a
3 files changed +21 -13
commit.c
+4 -5
@@ -655,11 +655,10 @@ struct commit *pop_commit(struct commit_list **stack)
655 /* count number of children that have not been emitted */
656 define_commit_slab(indegree_slab, int);
657
658 -/* record author-date for each commit object */
658 define_commit_slab(author_date_slab, timestamp_t);
659
661 -static void record_author_date(struct author_date_slab *author_date,
662 - struct commit *commit)
660 +void record_author_date(struct author_date_slab *author_date,
661 + struct commit *commit)
662 {
663 const char *buffer = get_commit_buffer(commit, NULL);
664 struct ident_split ident;
@@ -684,8 +683,8 @@ fail_exit:
683 unuse_commit_buffer(commit, buffer);
684 }
685
687 -static int compare_commits_by_author_date(const void *a_, const void *b_,
688 - void *cb_data)
686 +int compare_commits_by_author_date(const void *a_, const void *b_,
687 + void *cb_data)
688 {
689 const struct commit *a = a_, *b = b_;
690 struct author_date_slab *author_date = cb_data;
commit.h
+7
@@ -8,6 +8,7 @@
8 #include "gpg-interface.h"
9 #include "string-list.h"
10 #include "pretty.h"
11 +#include "commit-slab.h"
12
13 #define COMMIT_NOT_FROM_GRAPH 0xFFFFFFFF
14 #define GENERATION_NUMBER_INFINITY 0xFFFFFFFF
@@ -328,6 +329,12 @@ extern int remove_signature(struct strbuf *buf);
329 */
330 extern int check_commit_signature(const struct commit *commit, struct signature_check *sigc);
331
332 +/* record author-date for each commit object */
333 +struct author_date_slab;
334 +void record_author_date(struct author_date_slab *author_date,
335 + struct commit *commit);
336 +
337 +int compare_commits_by_author_date(const void *a_, const void *b_, void *unused);
338 int compare_commits_by_commit_date(const void *a_, const void *b_, void *unused);
339 int compare_commits_by_gen_then_commit_date(const void *a_, const void *b_, void *unused);
340
revision.c
+10 -8
@@ -768,8 +768,8 @@ static void commit_list_insert_by_date_cached(struct commit *p, struct commit_li
768 *cache = new_entry;
769 }
770
771 -static int add_parents_to_list(struct rev_info *revs, struct commit *commit,
772 - struct commit_list **list, struct commit_list **cache_ptr)
771 +static int process_parents(struct rev_info *revs, struct commit *commit,
772 + struct commit_list **list, struct commit_list **cache_ptr)
773 {
774 struct commit_list *parent = commit->parents;
775 unsigned left_flag;
@@ -808,7 +808,8 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit,
808 if (p->object.flags & SEEN)
809 continue;
810 p->object.flags |= SEEN;
811 - commit_list_insert_by_date_cached(p, list, cached_base, cache_ptr);
811 + if (list)
812 + commit_list_insert_by_date_cached(p, list, cached_base, cache_ptr);
813 }
814 return 0;
815 }
@@ -847,7 +848,8 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit,
848 p->object.flags |= left_flag;
849 if (!(p->object.flags & SEEN)) {
850 p->object.flags |= SEEN;
850 - commit_list_insert_by_date_cached(p, list, cached_base, cache_ptr);
851 + if (list)
852 + commit_list_insert_by_date_cached(p, list, cached_base, cache_ptr);
853 }
854 if (revs->first_parent_only)
855 break;
@@ -1091,7 +1093,7 @@ static int limit_list(struct rev_info *revs)
1093
1094 if (revs->max_age != -1 && (commit->date < revs->max_age))
1095 obj->flags |= UNINTERESTING;
1094 - if (add_parents_to_list(revs, commit, &list, NULL) < 0)
1096 + if (process_parents(revs, commit, &list, NULL) < 0)
1097 return -1;
1098 if (obj->flags & UNINTERESTING) {
1099 mark_parents_uninteresting(commit);
@@ -2913,7 +2915,7 @@ static struct commit *next_topo_commit(struct rev_info *revs)
2915
2916 static void expand_topo_walk(struct rev_info *revs, struct commit *commit)
2917 {
2916 - if (add_parents_to_list(revs, commit, &revs->commits, NULL) < 0) {
2918 + if (process_parents(revs, commit, &revs->commits, NULL) < 0) {
2919 if (!revs->ignore_missing_links)
2920 die("Failed to traverse parents of commit %s",
2921 oid_to_hex(&commit->object.oid));
@@ -2979,7 +2981,7 @@ static enum rewrite_result rewrite_one(struct rev_info *revs, struct commit **pp
2981 for (;;) {
2982 struct commit *p = *pp;
2983 if (!revs->limited)
2982 - if (add_parents_to_list(revs, p, &revs->commits, &cache) < 0)
2984 + if (process_parents(revs, p, &revs->commits, &cache) < 0)
2985 return rewrite_one_error;
2986 if (p->object.flags & UNINTERESTING)
2987 return rewrite_one_ok;
@@ -3312,7 +3314,7 @@ static struct commit *get_revision_1(struct rev_info *revs)
3314 try_to_simplify_commit(revs, commit);
3315 else if (revs->topo_walk_info)
3316 expand_topo_walk(revs, commit);
3315 - else if (add_parents_to_list(revs, commit, &revs->commits, NULL) < 0) {
3317 + else if (process_parents(revs, commit, &revs->commits, NULL) < 0) {
3318 if (!revs->ignore_missing_links)
3319 die("Failed to traverse parents of commit %s",
3320 oid_to_hex(&commit->object.oid));