
The existing reachability algorithms in commit-reach.c focus on finding merge-bases or determining if all commits in a set X can reach at least one commit in a set Y. However, for two commits sets X and Y, we may also care about which commits in Y are reachable from at least one commit in X. Implement get_reachable_subset() which answers this question. Given two arrays of commits, 'from' and 'to', return a commit_list with every commit from the 'to' array that is reachable from at least one commit in the 'from' array. The algorithm is a simple walk starting at the 'from' commits, using the PARENT2 flag to indicate "this commit has already been added to the walk queue". By marking the 'to' commits with the PARENT1 flag, we can determine when we see a commit from the 'to' array. We remove the PARENT1 flag as we add that commit to the result list to avoid duplicates. The order of the resulting list is a reverse of the order that the commits are discovered in the walk. There are a couple shortcuts to avoid walking more than we need: 1. We determine the minimum generation number of commits in the 'to' array. We do not walk commits with generation number below this minimum. 2. We count how many distinct commits are in the 'to' array, and decrement this count when we discover a 'to' commit during the walk. If this number reaches zero, then we can terminate the walk. Tests will be added using the 'test-tool reach' helper in a subsequent commit. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
91 lines
3.1 KiB
C
91 lines
3.1 KiB
C
#ifndef COMMIT_REACH_H
|
|
#define COMMIT_REACH_H
|
|
|
|
#include "commit-slab.h"
|
|
|
|
struct commit;
|
|
struct commit_list;
|
|
struct contains_cache;
|
|
struct ref_filter;
|
|
|
|
struct commit_list *get_merge_bases_many(struct commit *one,
|
|
int n,
|
|
struct commit **twos);
|
|
struct commit_list *get_merge_bases_many_dirty(struct commit *one,
|
|
int n,
|
|
struct commit **twos);
|
|
struct commit_list *get_merge_bases(struct commit *one, struct commit *two);
|
|
struct commit_list *get_octopus_merge_bases(struct commit_list *in);
|
|
|
|
/* To be used only when object flags after this call no longer matter */
|
|
struct commit_list *get_merge_bases_many_dirty(struct commit *one, int n, struct commit **twos);
|
|
|
|
int is_descendant_of(struct commit *commit, struct commit_list *with_commit);
|
|
int in_merge_bases_many(struct commit *commit, int nr_reference, struct commit **reference);
|
|
int in_merge_bases(struct commit *commit, struct commit *reference);
|
|
|
|
/*
|
|
* Takes a list of commits and returns a new list where those
|
|
* have been removed that can be reached from other commits in
|
|
* the list. It is useful for, e.g., reducing the commits
|
|
* randomly thrown at the git-merge command and removing
|
|
* redundant commits that the user shouldn't have given to it.
|
|
*
|
|
* This function destroys the STALE bit of the commit objects'
|
|
* flags.
|
|
*/
|
|
struct commit_list *reduce_heads(struct commit_list *heads);
|
|
|
|
/*
|
|
* Like `reduce_heads()`, except it replaces the list. Use this
|
|
* instead of `foo = reduce_heads(foo);` to avoid memory leaks.
|
|
*/
|
|
void reduce_heads_replace(struct commit_list **heads);
|
|
|
|
int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid);
|
|
|
|
/*
|
|
* Unknown has to be "0" here, because that's the default value for
|
|
* contains_cache slab entries that have not yet been assigned.
|
|
*/
|
|
enum contains_result {
|
|
CONTAINS_UNKNOWN = 0,
|
|
CONTAINS_NO,
|
|
CONTAINS_YES
|
|
};
|
|
|
|
define_commit_slab(contains_cache, enum contains_result);
|
|
|
|
int commit_contains(struct ref_filter *filter, struct commit *commit,
|
|
struct commit_list *list, struct contains_cache *cache);
|
|
|
|
/*
|
|
* Determine if every commit in 'from' can reach at least one commit
|
|
* that is marked with 'with_flag'. As we traverse, use 'assign_flag'
|
|
* as a marker for commits that are already visited. Do not walk
|
|
* commits with date below 'min_commit_date' or generation below
|
|
* 'min_generation'.
|
|
*/
|
|
int can_all_from_reach_with_flag(struct object_array *from,
|
|
unsigned int with_flag,
|
|
unsigned int assign_flag,
|
|
time_t min_commit_date,
|
|
uint32_t min_generation);
|
|
int can_all_from_reach(struct commit_list *from, struct commit_list *to,
|
|
int commit_date_cutoff);
|
|
|
|
|
|
/*
|
|
* Return a list of commits containing the commits in the 'to' array
|
|
* that are reachable from at least one commit in the 'from' array.
|
|
* Also add the given 'flag' to each of the commits in the returned list.
|
|
*
|
|
* This method uses the PARENT1 and PARENT2 flags during its operation,
|
|
* so be sure these flags are not set before calling the method.
|
|
*/
|
|
struct commit_list *get_reachable_subset(struct commit **from, int nr_from,
|
|
struct commit **to, int nr_to,
|
|
unsigned int reachable_flag);
|
|
|
|
#endif
|