Skip to content

Commit 5284fc5

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f0d9cc4 commit 5284fc5

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

commit.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -655,11 +655,10 @@ struct commit *pop_commit(struct commit_list **stack)
655655
/* count number of children that have not been emitted */
656656
define_commit_slab(indegree_slab, int);
657657

658-
/* record author-date for each commit object */
659658
define_commit_slab(author_date_slab, timestamp_t);
660659

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)
663662
{
664663
const char *buffer = get_commit_buffer(commit, NULL);
665664
struct ident_split ident;
@@ -684,8 +683,8 @@ static void record_author_date(struct author_date_slab *author_date,
684683
unuse_commit_buffer(commit, buffer);
685684
}
686685

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)
689688
{
690689
const struct commit *a = a_, *b = b_;
691690
struct author_date_slab *author_date = cb_data;

commit.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "gpg-interface.h"
99
#include "string-list.h"
1010
#include "pretty.h"
11+
#include "commit-slab.h"
1112

1213
#define COMMIT_NOT_FROM_GRAPH 0xFFFFFFFF
1314
#define GENERATION_NUMBER_INFINITY 0xFFFFFFFF
@@ -328,6 +329,12 @@ extern int remove_signature(struct strbuf *buf);
328329
*/
329330
extern int check_commit_signature(const struct commit *commit, struct signature_check *sigc);
330331

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);
331338
int compare_commits_by_commit_date(const void *a_, const void *b_, void *unused);
332339
int compare_commits_by_gen_then_commit_date(const void *a_, const void *b_, void *unused);
333340

revision.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,8 @@ static void commit_list_insert_by_date_cached(struct commit *p, struct commit_li
768768
*cache = new_entry;
769769
}
770770

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)
773773
{
774774
struct commit_list *parent = commit->parents;
775775
unsigned left_flag;
@@ -808,7 +808,8 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit,
808808
if (p->object.flags & SEEN)
809809
continue;
810810
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);
812813
}
813814
return 0;
814815
}
@@ -847,7 +848,8 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit,
847848
p->object.flags |= left_flag;
848849
if (!(p->object.flags & SEEN)) {
849850
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);
851853
}
852854
if (revs->first_parent_only)
853855
break;
@@ -1091,7 +1093,7 @@ static int limit_list(struct rev_info *revs)
10911093

10921094
if (revs->max_age != -1 && (commit->date < revs->max_age))
10931095
obj->flags |= UNINTERESTING;
1094-
if (add_parents_to_list(revs, commit, &list, NULL) < 0)
1096+
if (process_parents(revs, commit, &list, NULL) < 0)
10951097
return -1;
10961098
if (obj->flags & UNINTERESTING) {
10971099
mark_parents_uninteresting(commit);
@@ -2913,7 +2915,7 @@ static struct commit *next_topo_commit(struct rev_info *revs)
29132915

29142916
static void expand_topo_walk(struct rev_info *revs, struct commit *commit)
29152917
{
2916-
if (add_parents_to_list(revs, commit, &revs->commits, NULL) < 0) {
2918+
if (process_parents(revs, commit, &revs->commits, NULL) < 0) {
29172919
if (!revs->ignore_missing_links)
29182920
die("Failed to traverse parents of commit %s",
29192921
oid_to_hex(&commit->object.oid));
@@ -2979,7 +2981,7 @@ static enum rewrite_result rewrite_one(struct rev_info *revs, struct commit **pp
29792981
for (;;) {
29802982
struct commit *p = *pp;
29812983
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)
29832985
return rewrite_one_error;
29842986
if (p->object.flags & UNINTERESTING)
29852987
return rewrite_one_ok;
@@ -3312,7 +3314,7 @@ static struct commit *get_revision_1(struct rev_info *revs)
33123314
try_to_simplify_commit(revs, commit);
33133315
else if (revs->topo_walk_info)
33143316
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) {
33163318
if (!revs->ignore_missing_links)
33173319
die("Failed to traverse parents of commit %s",
33183320
oid_to_hex(&commit->object.oid));

0 commit comments

Comments
 (0)