git/ref-filter.c

#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
#include "config.h"
#include "gpg-interface.h"
#include "hex.h"
#include "parse-options.h"
#include "run-command.h"
#include "refs.h"
#include "wildmatch.h"
#include "object-name.h"
#include "object-store-ll.h"
#include "oid-array.h"
#include "repo-settings.h"
#include "repository.h"
#include "commit.h"
#include "mailmap.h"
#include "ident.h"
#include "remote.h"
#include "color.h"
#include "tag.h"
#include "quote.h"
#include "ref-filter.h"
#include "revision.h"
#include "utf8.h"
#include "versioncmp.h"
#include "trailer.h"
#include "wt-status.h"
#include "commit-slab.h"
#include "commit-reach.h"
#include "worktree.h"
#include "hashmap.h"

static struct ref_msg {} msgs =;

void setup_ref_filter_porcelain_msg(void)
{}

cmp_type;
cmp_status;
info_source;

struct align {};

struct if_then_else {};

struct refname_atom {};

struct ref_trailer_buf {};

static struct expand_data {} oi, oi_deref;

struct ref_to_worktree_entry {};

static int ref_to_worktree_map_cmpfnc(const void *lookupdata UNUSED,
				      const struct hashmap_entry *eptr,
				      const struct hashmap_entry *kptr,
				      const void *keydata_aka_refname)
{}

static struct ref_to_worktree_map {} ref_to_worktree_map;

/*
 * The enum atom_type is used as the index of valid_atom array.
 * In the atom parsing stage, it will be passed to used_atom.atom_type
 * as the identifier of the atom type. We can check the type of used_atom
 * entry by `if (used_atom[i].atom_type == ATOM_*)`.
 */
enum atom_type {};

/*
 * An atom is a valid field atom listed below, possibly prefixed with
 * a "*" to denote deref_tag().
 *
 * We parse given format string and sort specifiers, and make a list
 * of properties that we need to extract out of objects.  ref_array_item
 * structure will hold an array of values extracted that can be
 * indexed with the "atom number", which is an index into this
 * array.
 */
static struct used_atom {} *used_atom;
static int used_atom_cnt, need_tagged, need_symref;

/*
 * Expand string, append it to strbuf *sb, then return error code ret.
 * Allow to save few lines of code.
 */
__attribute__((format (printf, 3, 4)))
static int strbuf_addf_ret(struct strbuf *sb, int ret, const char *fmt, ...)
{}

static int err_no_arg(struct strbuf *sb, const char *name)
{}

static int err_bad_arg(struct strbuf *sb, const char *name, const char *arg)
{}

/*
 * Parse option of name "candidate" in the option string "to_parse" of
 * the form
 *
 *	"candidate1[=val1],candidate2[=val2],candidate3[=val3],..."
 *
 * The remaining part of "to_parse" is stored in "end" (if we are
 * parsing the last candidate, then this is NULL) and the value of
 * the candidate is stored in "valuestart" and its length in "valuelen",
 * that is the portion after "=". Since it is possible for a "candidate"
 * to not have a value, in such cases, "valuestart" is set to point to
 * NULL and "valuelen" to 0.
 *
 * The function returns 1 on success. It returns 0 if we don't find
 * "candidate" in "to_parse" or we find "candidate" but it is followed
 * by more chars (for example, "candidatefoo"), that is, we don't find
 * an exact match.
 *
 * This function only does the above for one "candidate" at a time. So
 * it has to be called each time trying to parse a "candidate" in the
 * option string "to_parse".
 */
static int match_atom_arg_value(const char *to_parse, const char *candidate,
				const char **end, const char **valuestart,
				size_t *valuelen)
{}

/*
 * Parse boolean option of name "candidate" in the option list "to_parse"
 * of the form
 *
 *	"candidate1[=bool1],candidate2[=bool2],candidate3[=bool3],..."
 *
 * The remaining part of "to_parse" is stored in "end" (if we are parsing
 * the last candidate, then this is NULL) and the value (if given) is
 * parsed and stored in "val", so "val" always points to either 0 or 1.
 * If the value is not given, then "val" is set to point to 1.
 *
 * The boolean value is parsed using "git_parse_maybe_bool()", so the
 * accepted values are
 *
 *	to set true  - "1", "yes", "true"
 *	to set false - "0", "no", "false"
 *
 * This function returns 1 on success. It returns 0 when we don't find
 * an exact match for "candidate" or when the boolean value given is
 * not valid.
 */
static int match_atom_bool_arg(const char *to_parse, const char *candidate,
				const char **end, int *val)
{}

static int color_atom_parser(struct ref_format *format, struct used_atom *atom,
			     const char *color_value, struct strbuf *err)
{}

static int refname_atom_parser_internal(struct refname_atom *atom, const char *arg,
					 const char *name, struct strbuf *err)
{}

static int remote_ref_atom_parser(struct ref_format *format UNUSED,
				  struct used_atom *atom,
				  const char *arg, struct strbuf *err)
{}

static int objecttype_atom_parser(struct ref_format *format UNUSED,
				  struct used_atom *atom,
				  const char *arg, struct strbuf *err)
{}

static int objectsize_atom_parser(struct ref_format *format UNUSED,
				  struct used_atom *atom,
				  const char *arg, struct strbuf *err)
{}

static int deltabase_atom_parser(struct ref_format *format UNUSED,
				 struct used_atom *atom,
				 const char *arg, struct strbuf *err)
{}

static int body_atom_parser(struct ref_format *format UNUSED,
			    struct used_atom *atom,
			    const char *arg, struct strbuf *err)
{}

static int subject_atom_parser(struct ref_format *format UNUSED,
			       struct used_atom *atom,
			       const char *arg, struct strbuf *err)
{}

static int parse_signature_option(const char *arg)
{}

static int signature_atom_parser(struct ref_format *format UNUSED,
				 struct used_atom *atom,
				 const char *arg, struct strbuf *err)
{}

static int trailers_atom_parser(struct ref_format *format UNUSED,
				struct used_atom *atom,
				const char *arg, struct strbuf *err)
{}

static int contents_atom_parser(struct ref_format *format, struct used_atom *atom,
				const char *arg, struct strbuf *err)
{}

static int describe_atom_option_parser(struct strvec *args, const char **arg,
				       struct strbuf *err)
{}

static int describe_atom_parser(struct ref_format *format UNUSED,
				struct used_atom *atom,
				const char *arg, struct strbuf *err)
{}

static int raw_atom_parser(struct ref_format *format UNUSED,
			   struct used_atom *atom,
			   const char *arg, struct strbuf *err)
{}

static int oid_atom_parser(struct ref_format *format UNUSED,
			   struct used_atom *atom,
			   const char *arg, struct strbuf *err)
{}

static int person_name_atom_parser(struct ref_format *format UNUSED,
				   struct used_atom *atom,
				   const char *arg, struct strbuf *err)
{}

static int email_atom_option_parser(const char **arg)
{}

static int person_email_atom_parser(struct ref_format *format UNUSED,
				    struct used_atom *atom,
				    const char *arg, struct strbuf *err)
{}

static int refname_atom_parser(struct ref_format *format UNUSED,
			       struct used_atom *atom,
			       const char *arg, struct strbuf *err)
{}

static align_type parse_align_position(const char *s)
{}

static int align_atom_parser(struct ref_format *format UNUSED,
			     struct used_atom *atom,
			     const char *arg, struct strbuf *err)
{}

static int if_atom_parser(struct ref_format *format UNUSED,
			  struct used_atom *atom,
			  const char *arg, struct strbuf *err)
{}

static int rest_atom_parser(struct ref_format *format UNUSED,
			    struct used_atom *atom UNUSED,
			    const char *arg, struct strbuf *err)
{}

static int ahead_behind_atom_parser(struct ref_format *format,
				    struct used_atom *atom UNUSED,
				    const char *arg, struct strbuf *err)
{}

static int is_base_atom_parser(struct ref_format *format,
			       struct used_atom *atom UNUSED,
			       const char *arg, struct strbuf *err)
{}

static int head_atom_parser(struct ref_format *format UNUSED,
			    struct used_atom *atom,
			    const char *arg, struct strbuf *err)
{}

static struct {} valid_atom[] =;

#define REF_FORMATTING_STATE_INIT

struct ref_formatting_stack {};

struct ref_formatting_state {};

struct atom_value {};

#define ATOM_SIZE_UNSPECIFIED

#define ATOM_VALUE_INIT

/*
 * Used to parse format string and sort specifiers
 */
static int parse_ref_filter_atom(struct ref_format *format,
				 const char *atom, const char *ep,
				 struct strbuf *err)
{}

static void quote_formatting(struct strbuf *s, const char *str, ssize_t len, int quote_style)
{}

static int append_atom(struct atom_value *v, struct ref_formatting_state *state,
		       struct strbuf *err UNUSED)
{}

static void push_stack_element(struct ref_formatting_stack **stack)
{}

static void pop_stack_element(struct ref_formatting_stack **stack)
{}

static void end_align_handler(struct ref_formatting_stack **stack)
{}

static int align_atom_handler(struct atom_value *atomv, struct ref_formatting_state *state,
			      struct strbuf *err UNUSED)
{}

static void if_then_else_handler(struct ref_formatting_stack **stack)
{}

static int if_atom_handler(struct atom_value *atomv, struct ref_formatting_state *state,
			   struct strbuf *err UNUSED)
{}

static int is_empty(struct strbuf *buf)
{}

static int then_atom_handler(struct atom_value *atomv UNUSED,
			     struct ref_formatting_state *state,
			     struct strbuf *err)
{}

static int else_atom_handler(struct atom_value *atomv UNUSED,
			     struct ref_formatting_state *state,
			     struct strbuf *err)
{}

static int end_atom_handler(struct atom_value *atomv UNUSED,
			    struct ref_formatting_state *state,
			    struct strbuf *err)
{}

/*
 * In a format string, find the next occurrence of %(atom).
 */
static const char *find_next(const char *cp)
{}

static int reject_atom(enum atom_type atom_type)
{}

/*
 * Make sure the format string is well formed, and parse out
 * the used atoms.
 */
int verify_ref_format(struct ref_format *format)
{}

static const char *do_grab_oid(const char *field, const struct object_id *oid,
			       struct used_atom *atom)
{}

static int grab_oid(const char *name, const char *field, const struct object_id *oid,
		    struct atom_value *v, struct used_atom *atom)
{}

/* See grab_values */
static void grab_common_values(struct atom_value *val, int deref, struct expand_data *oi)
{}

/* See grab_values */
static void grab_tag_values(struct atom_value *val, int deref, struct object *obj)
{}

/* See grab_values */
static void grab_commit_values(struct atom_value *val, int deref, struct object *obj)
{}

static const char *find_wholine(const char *who, int wholen, const char *buf)
{}

static const char *copy_line(const char *buf)
{}

static const char *copy_name(const char *buf)
{}

static const char *find_end_of_email(const char *email, int opt)
{}

static const char *copy_email(const char *buf, struct used_atom *atom)
{}

static char *copy_subject(const char *buf, unsigned long len)
{}

static void grab_date(const char *buf, struct atom_value *v, const char *atomname)
{}

static struct string_list mailmap =;

/* See grab_values */
static void grab_person(const char *who, struct atom_value *val, int deref, void *buf)
{}

static void grab_signature(struct atom_value *val, int deref, struct object *obj)
{}

static void find_subpos(const char *buf,
			const char **sub, size_t *sublen,
			const char **body, size_t *bodylen,
			size_t *nonsiglen,
			const char **sig, size_t *siglen)
{}

/*
 * If 'lines' is greater than 0, append that many lines from the given
 * 'buf' of length 'size' to the given strbuf.
 */
static void append_lines(struct strbuf *out, const char *buf, unsigned long size, int lines)
{}

static void grab_describe_values(struct atom_value *val, int deref,
				 struct object *obj)
{}

/* See grab_values */
static void grab_sub_body_contents(struct atom_value *val, int deref, struct expand_data *data)
{}

/*
 * We want to have empty print-string for field requests
 * that do not apply (e.g. "authordate" for a tag object)
 */
static void fill_missing_values(struct atom_value *val)
{}

/*
 * val is a list of atom_value to hold returned values.  Extract
 * the values for atoms in used_atom array out of (obj, buf, sz).
 * when deref is false, (obj, buf, sz) is the object that is
 * pointed at by the ref itself; otherwise it is the object the
 * ref (which is a tag) refers to.
 */
static void grab_values(struct atom_value *val, int deref, struct object *obj, struct expand_data *data)
{}

static inline char *copy_advance(char *dst, const char *src)
{}

static const char *lstrip_ref_components(const char *refname, int len)
{}

static const char *rstrip_ref_components(const char *refname, int len)
{}

static const char *show_ref(struct refname_atom *atom, const char *refname)
{}

static void fill_remote_ref_details(struct used_atom *atom, const char *refname,
				    struct branch *branch, const char **s)
{}

char *get_head_description(void)
{}

static const char *get_symref(struct used_atom *atom, struct ref_array_item *ref)
{}

static const char *get_refname(struct used_atom *atom, struct ref_array_item *ref)
{}

static int get_object(struct ref_array_item *ref, int deref, struct object **obj,
		      struct expand_data *oi, struct strbuf *err)
{}

static void populate_worktree_map(struct hashmap *map, struct worktree **worktrees)
{}

static void lazy_init_worktree_map(void)
{}

static char *get_worktree_path(const struct ref_array_item *ref)
{}

/*
 * Parse the object referred by ref, and grab needed value.
 */
static int populate_value(struct ref_array_item *ref, struct strbuf *err)
{}

/*
 * Given a ref, return the value for the atom.  This lazily gets value
 * out of the object by calling populate value.
 */
static int get_ref_atom_value(struct ref_array_item *ref, int atom,
			      struct atom_value **v, struct strbuf *err)
{}

/*
 * Return 1 if the refname matches one of the patterns, otherwise 0.
 * A pattern can be a literal prefix (e.g. a refname "refs/heads/master"
 * matches a pattern "refs/heads/mas") or a wildcard (e.g. the same ref
 * matches "refs/heads/mas*", too).
 */
static int match_pattern(const char **patterns, const char *refname,
			 int ignore_case)
{}

/*
 * Return 1 if the refname matches one of the patterns, otherwise 0.
 * A pattern can be path prefix (e.g. a refname "refs/heads/master"
 * matches a pattern "refs/heads/" but not "refs/heads/m") or a
 * wildcard (e.g. the same ref matches "refs/heads/m*", too).
 */
static int match_name_as_path(const char **pattern, const char *refname,
			      int ignore_case)
{}

/* Return 1 if the refname matches one of the patterns, otherwise 0. */
static int filter_pattern_match(struct ref_filter *filter, const char *refname)
{}

static int filter_exclude_match(struct ref_filter *filter, const char *refname)
{}

/*
 * This is the same as for_each_fullref_in(), but it tries to iterate
 * only over the patterns we'll care about. Note that it _doesn't_ do a full
 * pattern match, so the callback still has to match each ref individually.
 */
static int for_each_fullref_in_pattern(struct ref_filter *filter,
				       each_ref_fn cb,
				       void *cb_data)
{}

/*
 * Given a ref (oid, refname), check if the ref belongs to the array
 * of oids. If the given ref is a tag, check if the given tag points
 * at one of the oids in the given oid array. Returns non-zero if a
 * match is found.
 *
 * NEEDSWORK:
 * As the refs are cached we might know what refname peels to without
 * the need to parse the object via parse_object(). peel_ref() might be a
 * more efficient alternative to obtain the pointee.
 */
static int match_points_at(struct oid_array *points_at,
			   const struct object_id *oid,
			   const char *refname)
{}

/*
 * Allocate space for a new ref_array_item and copy the name and oid to it.
 *
 * Callers can then fill in other struct members at their leisure.
 */
static struct ref_array_item *new_ref_array_item(const char *refname,
						 const struct object_id *oid)
{}

static void ref_array_append(struct ref_array *array, struct ref_array_item *ref)
{}

struct ref_array_item *ref_array_push(struct ref_array *array,
				      const char *refname,
				      const struct object_id *oid)
{}

static int ref_kind_from_refname(const char *refname)
{}

static int filter_ref_kind(struct ref_filter *filter, const char *refname)
{}

static struct ref_array_item *apply_ref_filter(const char *refname, const char *referent, const struct object_id *oid,
			    int flag, struct ref_filter *filter)
{}

struct ref_filter_cbdata {};

/*
 * A call-back given to for_each_ref().  Filter refs and keep them for
 * later object processing.
 */
static int filter_one(const char *refname, const char *referent, const struct object_id *oid, int flag, void *cb_data)
{}

/*  Free memory allocated for a ref_array_item */
static void free_array_item(struct ref_array_item *item)
{}

struct ref_filter_and_format_cbdata {};

static int filter_and_format_one(const char *refname, const char *referent, const struct object_id *oid, int flag, void *cb_data)
{}

/* Free all memory allocated for ref_array */
void ref_array_clear(struct ref_array *array)
{}

#define EXCLUDE_REACHED
#define INCLUDE_REACHED
static void reach_filter(struct ref_array *array,
			 struct commit_list **check_reachable,
			 int include_reached)
{}

void filter_ahead_behind(struct repository *r,
			 struct ref_format *format,
			 struct ref_array *array)
{}

void filter_is_base(struct repository *r,
		    struct ref_format *format,
		    struct ref_array *array)
{}

static int do_filter_refs(struct ref_filter *filter, unsigned int type, each_ref_fn fn, void *cb_data)
{}

/*
 * API for filtering a set of refs. Based on the type of refs the user
 * has requested, we iterate through those refs and apply filters
 * as per the given ref_filter structure and finally store the
 * filtered refs in the ref_array structure.
 */
int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int type)
{}

struct ref_sorting {};

static inline int can_do_iterative_format(struct ref_filter *filter,
					  struct ref_sorting *sorting,
					  struct ref_format *format)
{}

void filter_and_format_refs(struct ref_filter *filter, unsigned int type,
			    struct ref_sorting *sorting,
			    struct ref_format *format)
{}

static int compare_detached_head(struct ref_array_item *a, struct ref_array_item *b)
{}

static int memcasecmp(const void *vs1, const void *vs2, size_t n)
{}

static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, struct ref_array_item *b)
{}

static int compare_refs(const void *a_, const void *b_, void *ref_sorting)
{}

void ref_sorting_set_sort_flags_all(struct ref_sorting *sorting,
				    unsigned int mask, int on)
{}

void ref_array_sort(struct ref_sorting *sorting, struct ref_array *array)
{}

static void append_literal(const char *cp, const char *ep, struct ref_formatting_state *state)
{}

int format_ref_array_item(struct ref_array_item *info,
			  struct ref_format *format,
			  struct strbuf *final_buf,
			  struct strbuf *error_buf)
{}

void print_formatted_ref_array(struct ref_array *array, struct ref_format *format)
{}

void pretty_print_ref(const char *name, const struct object_id *oid,
		      struct ref_format *format)
{}

static int parse_sorting_atom(const char *atom)
{}

static void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *arg)
{}

struct ref_sorting *ref_sorting_options(struct string_list *options)
{}

void ref_sorting_release(struct ref_sorting *sorting)
{}

int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset)
{}

void ref_filter_init(struct ref_filter *filter)
{}

void ref_filter_clear(struct ref_filter *filter)
{}

void ref_format_init(struct ref_format *format)
{}

void ref_format_clear(struct ref_format *format)
{}