git/attr.c

/*
 * Handle git attributes.  See gitattributes(5) for a description of
 * the file syntax, and attr.h for a description of the API.
 *
 * One basic design decision here is that we are not going to support
 * an insanely large number of attributes.
 */

#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "config.h"
#include "environment.h"
#include "exec-cmd.h"
#include "attr.h"
#include "dir.h"
#include "gettext.h"
#include "path.h"
#include "utf8.h"
#include "quote.h"
#include "read-cache-ll.h"
#include "refs.h"
#include "revision.h"
#include "object-store-ll.h"
#include "setup.h"
#include "thread-utils.h"
#include "tree-walk.h"
#include "object-name.h"

char *git_attr_tree;

const char git_attr__true[] =;
const char git_attr__false[] =;
static const char git_attr__unknown[] =;
#define ATTR__TRUE
#define ATTR__FALSE
#define ATTR__UNSET
#define ATTR__UNKNOWN

struct git_attr {};

const char *git_attr_name(const struct git_attr *attr)
{}

struct attr_hashmap {};

static inline void hashmap_lock(struct attr_hashmap *map)
{}

static inline void hashmap_unlock(struct attr_hashmap *map)
{}

/* The container for objects stored in "struct attr_hashmap" */
struct attr_hash_entry {};

/* attr_hashmap comparison function */
static int attr_hash_entry_cmp(const void *cmp_data UNUSED,
			       const struct hashmap_entry *eptr,
			       const struct hashmap_entry *entry_or_key,
			       const void *keydata UNUSED)
{}

/*
 * The global dictionary of all interned attributes.  This
 * is a singleton object which is shared between threads.
 * Access to this dictionary must be surrounded with a mutex.
 */
static struct attr_hashmap g_attr_hashmap =;

/*
 * Retrieve the 'value' stored in a hashmap given the provided 'key'.
 * If there is no matching entry, return NULL.
 */
static void *attr_hashmap_get(struct attr_hashmap *map,
			      const char *key, size_t keylen)
{}

/* Add 'value' to a hashmap based on the provided 'key'. */
static void attr_hashmap_add(struct attr_hashmap *map,
			     const char *key, size_t keylen,
			     void *value)
{}

struct all_attrs_item {};

/*
 * Reallocate and reinitialize the array of all attributes (which is used in
 * the attribute collection process) in 'check' based on the global dictionary
 * of attributes.
 */
static void all_attrs_init(struct attr_hashmap *map, struct attr_check *check)
{}

/*
 * Attribute name cannot begin with "builtin_" which
 * is a reserved namespace for built in attributes values.
 */
static int attr_name_reserved(const char *name)
{}

static int attr_name_valid(const char *name, size_t namelen)
{}

static void report_invalid_attr(const char *name, size_t len,
				const char *src, int lineno)
{}

/*
 * Given a 'name', lookup and return the corresponding attribute in the global
 * dictionary.  If no entry is found, create a new attribute and store it in
 * the dictionary.
 */
static const struct git_attr *git_attr_internal(const char *name, size_t namelen)
{}

const struct git_attr *git_attr(const char *name)
{}

/* What does a matched pattern decide? */
struct attr_state {};

struct pattern {};

/*
 * One rule, as from a .gitattributes file.
 *
 * If is_macro is true, then u.attr is a pointer to the git_attr being
 * defined.
 *
 * If is_macro is false, then u.pat is the filename pattern to which the
 * rule applies.
 *
 * In either case, num_attr is the number of attributes affected by
 * this rule, and state is an array listing them.  The attributes are
 * listed as they appear in the file (macros unexpanded).
 */
struct match_attr {};

static const char blank[] =;

/* Flags usable in read_attr() and parse_attr_line() family of functions. */
#define READ_ATTR_MACRO_OK
#define READ_ATTR_NOFOLLOW

/*
 * Parse a whitespace-delimited attribute state (i.e., "attr",
 * "-attr", "!attr", or "attr=value") from the string starting at src.
 * If e is not NULL, write the results to *e.  Return a pointer to the
 * remainder of the string (with leading whitespace removed), or NULL
 * if there was an error.
 */
static const char *parse_attr(const char *src, int lineno, const char *cp,
			      struct attr_state *e)
{}

static struct match_attr *parse_attr_line(const char *line, const char *src,
					  int lineno, unsigned flags)
{}

/*
 * Like info/exclude and .gitignore, the attribute information can
 * come from many places.
 *
 * (1) .gitattributes file of the same directory;
 * (2) .gitattributes file of the parent directory if (1) does not have
 *      any match; this goes recursively upwards, just like .gitignore.
 * (3) $GIT_DIR/info/attributes, which overrides both of the above.
 *
 * In the same file, later entries override the earlier match, so in the
 * global list, we would have entries from info/attributes the earliest
 * (reading the file from top to bottom), .gitattributes of the root
 * directory (again, reading the file from top to bottom) down to the
 * current directory, and then scan the list backwards to find the first match.
 * This is exactly the same as what is_excluded() does in dir.c to deal with
 * .gitignore file and info/excludes file as a fallback.
 */

struct attr_stack {};

static void attr_stack_free(struct attr_stack *e)
{}

static void drop_attr_stack(struct attr_stack **stack)
{}

/* List of all attr_check structs; access should be surrounded by mutex */
static struct check_vector {} check_vector;

static inline void vector_lock(void)
{}

static inline void vector_unlock(void)
{}

static void check_vector_add(struct attr_check *c)
{}

static void check_vector_remove(struct attr_check *check)
{}

/* Iterate through all attr_check instances and drop their stacks */
static void drop_all_attr_stacks(void)
{}

struct attr_check *attr_check_alloc(void)
{}

struct attr_check *attr_check_initl(const char *one, ...)
{}

struct attr_check *attr_check_dup(const struct attr_check *check)
{}

struct attr_check_item *attr_check_append(struct attr_check *check,
					  const struct git_attr *attr)
{}

void attr_check_reset(struct attr_check *check)
{}

void attr_check_clear(struct attr_check *check)
{}

void attr_check_free(struct attr_check *check)
{}

static const char *builtin_attr[] =;

static void handle_attr_line(struct attr_stack *res,
			     const char *line,
			     const char *src,
			     int lineno,
			     unsigned flags)
{}

static struct attr_stack *read_attr_from_array(const char **list)
{}

/*
 * Callers into the attribute system assume there is a single, system-wide
 * global state where attributes are read from and when the state is flipped by
 * calling git_attr_set_direction(), the stack frames that have been
 * constructed need to be discarded so that subsequent calls into the
 * attribute system will lazily read from the right place.  Since changing
 * direction causes a global paradigm shift, it should not ever be called while
 * another thread could potentially be calling into the attribute system.
 */
static enum git_attr_direction direction;

void git_attr_set_direction(enum git_attr_direction new_direction)
{}

static struct attr_stack *read_attr_from_file(const char *path, unsigned flags)
{}

static struct attr_stack *read_attr_from_buf(char *buf, size_t length,
					     const char *path, unsigned flags)
{}

static struct attr_stack *read_attr_from_blob(struct index_state *istate,
					      const struct object_id *tree_oid,
					      const char *path, unsigned flags)
{}

static struct attr_stack *read_attr_from_index(struct index_state *istate,
					       const char *path, unsigned flags)
{}

static struct attr_stack *read_attr(struct index_state *istate,
				    const struct object_id *tree_oid,
				    const char *path, unsigned flags)
{}

const char *git_attr_system_file(void)
{}

const char *git_attr_global_file(void)
{}

int git_attr_system_is_enabled(void)
{}

static GIT_PATH_FUNC(git_path_info_attributes, INFOATTRIBUTES_FILE)

static void push_stack(struct attr_stack **attr_stack_p,
		       struct attr_stack *elem, char *origin, size_t originlen)
{}

static void bootstrap_attr_stack(struct index_state *istate,
				 const struct object_id *tree_oid,
				 struct attr_stack **stack)
{}

static void prepare_attr_stack(struct index_state *istate,
			       const struct object_id *tree_oid,
			       const char *path, int dirlen,
			       struct attr_stack **stack)
{}

static int path_matches(const char *pathname, int pathlen,
			int basename_offset,
			const struct pattern *pat,
			const char *base, int baselen)
{}

static int macroexpand_one(struct all_attrs_item *all_attrs, int nr, int rem);

static int fill_one(struct all_attrs_item *all_attrs,
		    const struct match_attr *a, int rem)
{}

static int fill(const char *path, int pathlen, int basename_offset,
		const struct attr_stack *stack,
		struct all_attrs_item *all_attrs, int rem)
{}

static int macroexpand_one(struct all_attrs_item *all_attrs, int nr, int rem)
{}

/*
 * Marks the attributes which are macros based on the attribute stack.
 * This prevents having to search through the attribute stack each time
 * a macro needs to be expanded during the fill stage.
 */
static void determine_macros(struct all_attrs_item *all_attrs,
			     const struct attr_stack *stack)
{}

/*
 * Collect attributes for path into the array pointed to by check->all_attrs.
 * If check->check_nr is non-zero, only attributes in check[] are collected.
 * Otherwise all attributes are collected.
 */
static void collect_some_attrs(struct index_state *istate,
			       const struct object_id *tree_oid,
			       const char *path, struct attr_check *check)
{}

static const char *default_attr_source_tree_object_name;

void set_git_attr_source(const char *tree_object_name)
{}

static int compute_default_attr_source(struct object_id *attr_source)
{}

static struct object_id *default_attr_source(void)
{}

static const char *interned_mode_string(unsigned int mode)
{}

static const char *builtin_object_mode_attr(struct index_state *istate, const char *path)
{}


static const char *compute_builtin_attr(struct index_state *istate,
					  const char *path,
					  const struct git_attr *attr) {}

void git_check_attr(struct index_state *istate,
		    const char *path,
		    struct attr_check *check)
{}

void git_all_attrs(struct index_state *istate,
		   const char *path, struct attr_check *check)
{}

void attr_start(void)
{}