From e895cb5135d7fbff8037ce83302aff12ee83667c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 5 Mar 2013 11:42:20 -0800 Subject: commit.c: add clear_commit_marks_many() clear_commit_marks(struct commit *, unsigned) only can clear flag bits starting from a single commit; introduce an API to allow feeding an array of commits, so that flag bits can be cleared from commits reachable from any of them with a single traversal. Signed-off-by: Junio C Hamano --- commit.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'commit.c') diff --git a/commit.c b/commit.c index e8eb0aec55..4757e5058f 100644 --- a/commit.c +++ b/commit.c @@ -463,14 +463,23 @@ static void clear_commit_marks_1(struct commit_list **plist, } } -void clear_commit_marks(struct commit *commit, unsigned int mark) +void clear_commit_marks_many(int nr, struct commit **commit, unsigned int mark) { struct commit_list *list = NULL; - commit_list_insert(commit, &list); + + while (nr--) { + commit_list_insert(*commit, &list); + commit++; + } while (list) clear_commit_marks_1(&list, pop_commit(&list), mark); } +void clear_commit_marks(struct commit *commit, unsigned int mark) +{ + clear_commit_marks_many(1, &commit, mark); +} + void clear_commit_marks_for_object_array(struct object_array *a, unsigned mark) { struct object *object; @@ -797,8 +806,7 @@ struct commit_list *get_merge_bases_many(struct commit *one, if (!result || !result->next) { if (cleanup) { clear_commit_marks(one, all_flags); - for (i = 0; i < n; i++) - clear_commit_marks(twos[i], all_flags); + clear_commit_marks_many(n, twos, all_flags); } return result; } @@ -816,8 +824,7 @@ struct commit_list *get_merge_bases_many(struct commit *one, free_commit_list(result); clear_commit_marks(one, all_flags); - for (i = 0; i < n; i++) - clear_commit_marks(twos[i], all_flags); + clear_commit_marks_many(n, twos, all_flags); cnt = remove_redundant(rslt, cnt); result = NULL; -- cgit v1.2.3 From 4c4b27e8cefdd88d76590c5fd786d1d43fb6f898 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 4 Mar 2013 10:16:42 -0800 Subject: commit.c: add in_merge_bases_many() Similar to in_merge_bases(commit, other) that returns true when commit is an ancestor (i.e. in the merge bases between the two) of the other commit, in_merge_bases_many(commit, n_other, other[]) checks if commit is an ancestor of any of the other[] commits. Signed-off-by: Junio C Hamano --- commit.c | 24 ++++++++++++++++++------ commit.h | 1 + 2 files changed, 19 insertions(+), 6 deletions(-) (limited to 'commit.c') diff --git a/commit.c b/commit.c index 4757e5058f..d12e7995cc 100644 --- a/commit.c +++ b/commit.c @@ -859,25 +859,37 @@ int is_descendant_of(struct commit *commit, struct commit_list *with_commit) } /* - * Is "commit" an ancestor of (i.e. reachable from) the "reference"? + * Is "commit" an ancestor of one of the "references"? */ -int in_merge_bases(struct commit *commit, struct commit *reference) +int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit **reference) { struct commit_list *bases; - int ret = 0; + int ret = 0, i; - if (parse_commit(commit) || parse_commit(reference)) + if (parse_commit(commit)) return ret; + for (i = 0; i < nr_reference; i++) + if (parse_commit(reference[i])) + return ret; - bases = paint_down_to_common(commit, 1, &reference); + bases = paint_down_to_common(commit, nr_reference, reference); if (commit->object.flags & PARENT2) ret = 1; clear_commit_marks(commit, all_flags); - clear_commit_marks(reference, all_flags); + for (i = 0; i < nr_reference; i++) + clear_commit_marks(reference[i], all_flags); free_commit_list(bases); return ret; } +/* + * Is "commit" an ancestor of (i.e. reachable from) the "reference"? + */ +int in_merge_bases(struct commit *commit, struct commit *reference) +{ + return in_merge_bases_many(commit, 1, &reference); +} + struct commit_list *reduce_heads(struct commit_list *heads) { struct commit_list *p; diff --git a/commit.h b/commit.h index b997eeaabd..5057f141f0 100644 --- a/commit.h +++ b/commit.h @@ -171,6 +171,7 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads, int is_descendant_of(struct commit *, struct commit_list *); int in_merge_bases(struct commit *, struct commit *); +int in_merge_bases_many(struct commit *, int, struct commit **); extern int interactive_add(int argc, const char **argv, const char *prefix, int patch); extern int run_add_interactive(const char *revision, const char *patch_mode, -- cgit v1.2.3 From 557899ff6b4093ebffba71e916f7241b36b59068 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 5 Mar 2013 11:56:03 -0800 Subject: commit.c: use clear_commit_marks_many() in in_merge_bases_many() Signed-off-by: Junio C Hamano --- commit.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'commit.c') diff --git a/commit.c b/commit.c index d12e7995cc..b4512ab0b2 100644 --- a/commit.c +++ b/commit.c @@ -876,8 +876,7 @@ int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit * if (commit->object.flags & PARENT2) ret = 1; clear_commit_marks(commit, all_flags); - for (i = 0; i < nr_reference; i++) - clear_commit_marks(reference[i], all_flags); + clear_commit_marks_many(nr_reference, reference, all_flags); free_commit_list(bases); return ret; } -- cgit v1.2.3