exclude: add flags parameter to add_patterns()

There are a number of callers of add_patterns() and its sibling
functions. Let's give them a "flags" parameter for adding new options
without having to touch each caller. We'll use this in a future patch to
add O_NOFOLLOW support. But for now each caller just passes 0.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King 2021-02-16 09:44:28 -05:00 committed by Junio C Hamano
parent dbf387d550
commit 1679d60bfc
3 changed files with 13 additions and 11 deletions

View File

@ -64,7 +64,7 @@ static int sparse_checkout_list(int argc, const char **argv)
pl.use_cone_patterns = core_sparse_checkout_cone; pl.use_cone_patterns = core_sparse_checkout_cone;
sparse_filename = get_sparse_checkout_filename(); sparse_filename = get_sparse_checkout_filename();
res = add_patterns_from_file_to_list(sparse_filename, "", 0, &pl, NULL); res = add_patterns_from_file_to_list(sparse_filename, "", 0, &pl, NULL, 0);
free(sparse_filename); free(sparse_filename);
if (res < 0) { if (res < 0) {
@ -321,7 +321,7 @@ static int sparse_checkout_init(int argc, const char **argv)
memset(&pl, 0, sizeof(pl)); memset(&pl, 0, sizeof(pl));
sparse_filename = get_sparse_checkout_filename(); sparse_filename = get_sparse_checkout_filename();
res = add_patterns_from_file_to_list(sparse_filename, "", 0, &pl, NULL); res = add_patterns_from_file_to_list(sparse_filename, "", 0, &pl, NULL, 0);
/* If we already have a sparse-checkout file, use it. */ /* If we already have a sparse-checkout file, use it. */
if (res >= 0) { if (res >= 0) {
@ -483,7 +483,7 @@ static void add_patterns_cone_mode(int argc, const char **argv,
existing.use_cone_patterns = core_sparse_checkout_cone; existing.use_cone_patterns = core_sparse_checkout_cone;
if (add_patterns_from_file_to_list(sparse_filename, "", 0, if (add_patterns_from_file_to_list(sparse_filename, "", 0,
&existing, NULL)) &existing, NULL, 0))
die(_("unable to load existing sparse-checkout patterns")); die(_("unable to load existing sparse-checkout patterns"));
free(sparse_filename); free(sparse_filename);
@ -507,7 +507,7 @@ static void add_patterns_literal(int argc, const char **argv,
{ {
char *sparse_filename = get_sparse_checkout_filename(); char *sparse_filename = get_sparse_checkout_filename();
if (add_patterns_from_file_to_list(sparse_filename, "", 0, if (add_patterns_from_file_to_list(sparse_filename, "", 0,
pl, NULL)) pl, NULL, 0))
die(_("unable to load existing sparse-checkout patterns")); die(_("unable to load existing sparse-checkout patterns"));
free(sparse_filename); free(sparse_filename);
add_patterns_from_input(pl, argc, argv); add_patterns_from_input(pl, argc, argv);

13
dir.c
View File

@ -1046,7 +1046,7 @@ static int add_patterns_from_buffer(char *buf, size_t size,
*/ */
static int add_patterns(const char *fname, const char *base, int baselen, static int add_patterns(const char *fname, const char *base, int baselen,
struct pattern_list *pl, struct index_state *istate, struct pattern_list *pl, struct index_state *istate,
struct oid_stat *oid_stat) unsigned flags, struct oid_stat *oid_stat)
{ {
struct stat st; struct stat st;
int r; int r;
@ -1143,9 +1143,10 @@ static int add_patterns_from_buffer(char *buf, size_t size,
int add_patterns_from_file_to_list(const char *fname, const char *base, int add_patterns_from_file_to_list(const char *fname, const char *base,
int baselen, struct pattern_list *pl, int baselen, struct pattern_list *pl,
struct index_state *istate) struct index_state *istate,
unsigned flags)
{ {
return add_patterns(fname, base, baselen, pl, istate, NULL); return add_patterns(fname, base, baselen, pl, istate, flags, NULL);
} }
int add_patterns_from_blob_to_list( int add_patterns_from_blob_to_list(
@ -1194,7 +1195,7 @@ static void add_patterns_from_file_1(struct dir_struct *dir, const char *fname,
if (!dir->untracked) if (!dir->untracked)
dir->unmanaged_exclude_files++; dir->unmanaged_exclude_files++;
pl = add_pattern_list(dir, EXC_FILE, fname); pl = add_pattern_list(dir, EXC_FILE, fname);
if (add_patterns(fname, "", 0, pl, NULL, oid_stat) < 0) if (add_patterns(fname, "", 0, pl, NULL, 0, oid_stat) < 0)
die(_("cannot use %s as an exclude file"), fname); die(_("cannot use %s as an exclude file"), fname);
} }
@ -1557,7 +1558,7 @@ static void prep_exclude(struct dir_struct *dir,
strbuf_addbuf(&sb, &dir->basebuf); strbuf_addbuf(&sb, &dir->basebuf);
strbuf_addstr(&sb, dir->exclude_per_dir); strbuf_addstr(&sb, dir->exclude_per_dir);
pl->src = strbuf_detach(&sb, NULL); pl->src = strbuf_detach(&sb, NULL);
add_patterns(pl->src, pl->src, stk->baselen, pl, istate, add_patterns(pl->src, pl->src, stk->baselen, pl, istate, 0,
untracked ? &oid_stat : NULL); untracked ? &oid_stat : NULL);
} }
/* /*
@ -3009,7 +3010,7 @@ int get_sparse_checkout_patterns(struct pattern_list *pl)
char *sparse_filename = get_sparse_checkout_filename(); char *sparse_filename = get_sparse_checkout_filename();
pl->use_cone_patterns = core_sparse_checkout_cone; pl->use_cone_patterns = core_sparse_checkout_cone;
res = add_patterns_from_file_to_list(sparse_filename, "", 0, pl, NULL); res = add_patterns_from_file_to_list(sparse_filename, "", 0, pl, NULL, 0);
free(sparse_filename); free(sparse_filename);
return res; return res;

3
dir.h
View File

@ -420,7 +420,8 @@ int hashmap_contains_parent(struct hashmap *map,
struct pattern_list *add_pattern_list(struct dir_struct *dir, struct pattern_list *add_pattern_list(struct dir_struct *dir,
int group_type, const char *src); int group_type, const char *src);
int add_patterns_from_file_to_list(const char *fname, const char *base, int baselen, int add_patterns_from_file_to_list(const char *fname, const char *base, int baselen,
struct pattern_list *pl, struct index_state *istate); struct pattern_list *pl, struct index_state *istate,
unsigned flags);
void add_patterns_from_file(struct dir_struct *, const char *fname); void add_patterns_from_file(struct dir_struct *, const char *fname);
int add_patterns_from_blob_to_list(struct object_id *oid, int add_patterns_from_blob_to_list(struct object_id *oid,
const char *base, int baselen, const char *base, int baselen,