commit-reach.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #ifndef COMMIT_REACH_H
  2. #define COMMIT_REACH_H
  3. #include "commit.h"
  4. #include "commit-slab.h"
  5. struct commit_list;
  6. struct ref_filter;
  7. struct object_id;
  8. struct object_array;
  9. struct commit_list *repo_get_merge_bases(struct repository *r,
  10. struct commit *rev1,
  11. struct commit *rev2);
  12. struct commit_list *repo_get_merge_bases_many(struct repository *r,
  13. struct commit *one, int n,
  14. struct commit **twos);
  15. /* To be used only when object flags after this call no longer matter */
  16. struct commit_list *repo_get_merge_bases_many_dirty(struct repository *r,
  17. struct commit *one, int n,
  18. struct commit **twos);
  19. #ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
  20. #define get_merge_bases(r1, r2) repo_get_merge_bases(the_repository, r1, r2)
  21. #define get_merge_bases_many(one, n, two) repo_get_merge_bases_many(the_repository, one, n, two)
  22. #define get_merge_bases_many_dirty(one, n, twos) repo_get_merge_bases_many_dirty(the_repository, one, n, twos)
  23. #endif
  24. struct commit_list *get_octopus_merge_bases(struct commit_list *in);
  25. int repo_is_descendant_of(struct repository *r,
  26. struct commit *commit,
  27. struct commit_list *with_commit);
  28. int repo_in_merge_bases(struct repository *r,
  29. struct commit *commit,
  30. struct commit *reference);
  31. int repo_in_merge_bases_many(struct repository *r,
  32. struct commit *commit,
  33. int nr_reference, struct commit **reference);
  34. #ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
  35. #define in_merge_bases(c1, c2) repo_in_merge_bases(the_repository, c1, c2)
  36. #define in_merge_bases_many(c1, n, cs) repo_in_merge_bases_many(the_repository, c1, n, cs)
  37. #endif
  38. /*
  39. * Takes a list of commits and returns a new list where those
  40. * have been removed that can be reached from other commits in
  41. * the list. It is useful for, e.g., reducing the commits
  42. * randomly thrown at the git-merge command and removing
  43. * redundant commits that the user shouldn't have given to it.
  44. *
  45. * This function destroys the STALE bit of the commit objects'
  46. * flags.
  47. */
  48. struct commit_list *reduce_heads(struct commit_list *heads);
  49. /*
  50. * Like `reduce_heads()`, except it replaces the list. Use this
  51. * instead of `foo = reduce_heads(foo);` to avoid memory leaks.
  52. */
  53. void reduce_heads_replace(struct commit_list **heads);
  54. int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid);
  55. /*
  56. * Unknown has to be "0" here, because that's the default value for
  57. * contains_cache slab entries that have not yet been assigned.
  58. */
  59. enum contains_result {
  60. CONTAINS_UNKNOWN = 0,
  61. CONTAINS_NO,
  62. CONTAINS_YES
  63. };
  64. define_commit_slab(contains_cache, enum contains_result);
  65. int commit_contains(struct ref_filter *filter, struct commit *commit,
  66. struct commit_list *list, struct contains_cache *cache);
  67. /*
  68. * Determine if every commit in 'from' can reach at least one commit
  69. * that is marked with 'with_flag'. As we traverse, use 'assign_flag'
  70. * as a marker for commits that are already visited. Do not walk
  71. * commits with date below 'min_commit_date' or generation below
  72. * 'min_generation'.
  73. */
  74. int can_all_from_reach_with_flag(struct object_array *from,
  75. unsigned int with_flag,
  76. unsigned int assign_flag,
  77. time_t min_commit_date,
  78. uint32_t min_generation);
  79. int can_all_from_reach(struct commit_list *from, struct commit_list *to,
  80. int commit_date_cutoff);
  81. /*
  82. * Return a list of commits containing the commits in the 'to' array
  83. * that are reachable from at least one commit in the 'from' array.
  84. * Also add the given 'flag' to each of the commits in the returned list.
  85. *
  86. * This method uses the PARENT1 and PARENT2 flags during its operation,
  87. * so be sure these flags are not set before calling the method.
  88. */
  89. struct commit_list *get_reachable_subset(struct commit **from, int nr_from,
  90. struct commit **to, int nr_to,
  91. unsigned int reachable_flag);
  92. #endif