Merge branch 'ds/ahead-behind'

"git for-each-ref" learns '%(ahead-behind:<base>)' that computes the
distances from a single reference point in the history with bunch
of commits in bulk.

* ds/ahead-behind:
  commit-reach: add tips_reachable_from_bases()
  for-each-ref: add ahead-behind format atom
  commit-reach: implement ahead_behind() logic
  commit-graph: introduce `ensure_generations_valid()`
  commit-graph: return generation from memory
  commit-graph: simplify compute_generation_numbers()
  commit-graph: refactor compute_topological_levels()
  for-each-ref: explicitly test no matches
  for-each-ref: add --stdin option
This commit is contained in:
Junio C Hamano
2023-04-06 13:38:21 -07:00
17 changed files with 866 additions and 91 deletions

View File

@ -4,6 +4,7 @@
#include "oid-array.h"
#include "refs.h"
#include "commit.h"
#include "string-list.h"
/* Quoting styles */
#define QUOTE_NONE 0
@ -23,6 +24,7 @@
struct atom_value;
struct ref_sorting;
struct ahead_behind_count;
struct option;
enum ref_sorting_order {
@ -40,6 +42,8 @@ struct ref_array_item {
const char *symref;
struct commit *commit;
struct atom_value *value;
struct ahead_behind_count **counts;
char refname[FLEX_ARRAY];
};
@ -47,6 +51,9 @@ struct ref_array {
int nr, alloc;
struct ref_array_item **items;
struct rev_info *revs;
struct ahead_behind_count *counts;
size_t counts_nr;
};
struct ref_filter {
@ -80,9 +87,15 @@ struct ref_format {
/* Internal state to ref-filter */
int need_color_reset_at_eol;
/* List of bases for ahead-behind counts. */
struct string_list bases;
};
#define REF_FORMAT_INIT { .use_color = -1 }
#define REF_FORMAT_INIT { \
.use_color = -1, \
.bases = STRING_LIST_INIT_DUP, \
}
/* Macros for checking --merged and --no-merged options */
#define _OPT_MERGED_NO_MERGED(option, filter, h) \
@ -143,4 +156,15 @@ struct ref_array_item *ref_array_push(struct ref_array *array,
const char *refname,
const struct object_id *oid);
/*
* If the provided format includes ahead-behind atoms, then compute the
* ahead-behind values for the array of filtered references. Must be
* called after filter_refs() but before outputting the formatted refs.
*
* If this is not called, then any ahead-behind atoms will be blank.
*/
void filter_ahead_behind(struct repository *r,
struct ref_format *format,
struct ref_array *array);
#endif /* REF_FILTER_H */