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>
Jeff King committed
Feb 16, 2021 at 09:44 UTC
1679d60bfc4c5c38f30fc938cf006b1e8608f733
3 files changed
+13
-11
builtin/sparse-checkout.c
+4
-4
@@ -64,7 +64,7 @@ static int sparse_checkout_list(int argc, const char **argv)
64
pl.use_cone_patterns = core_sparse_checkout_cone;
65
66
sparse_filename = get_sparse_checkout_filename();
67
- res = add_patterns_from_file_to_list(sparse_filename, "", 0, &pl, NULL);
67
+ res = add_patterns_from_file_to_list(sparse_filename, "", 0, &pl, NULL, 0);
68
free(sparse_filename);
69
70
if (res < 0) {
@@ -321,7 +321,7 @@ static int sparse_checkout_init(int argc, const char **argv)
321
memset(&pl, 0, sizeof(pl));
322
323
sparse_filename = get_sparse_checkout_filename();
324
- res = add_patterns_from_file_to_list(sparse_filename, "", 0, &pl, NULL);
324
+ res = add_patterns_from_file_to_list(sparse_filename, "", 0, &pl, NULL, 0);
325
326
/* If we already have a sparse-checkout file, use it. */
327
if (res >= 0) {
@@ -483,7 +483,7 @@ static void add_patterns_cone_mode(int argc, const char **argv,
483
existing.use_cone_patterns = core_sparse_checkout_cone;
484
485
if (add_patterns_from_file_to_list(sparse_filename, "", 0,
486
- &existing, NULL))
486
+ &existing, NULL, 0))
487
die(_("unable to load existing sparse-checkout patterns"));
488
free(sparse_filename);
489
@@ -507,7 +507,7 @@ static void add_patterns_literal(int argc, const char **argv,
507
{
508
char *sparse_filename = get_sparse_checkout_filename();
509
if (add_patterns_from_file_to_list(sparse_filename, "", 0,
510
- pl, NULL))
510
+ pl, NULL, 0))
511
die(_("unable to load existing sparse-checkout patterns"));
512
free(sparse_filename);
513
add_patterns_from_input(pl, argc, argv);
dir.c
+7
-6
@@ -1046,7 +1046,7 @@ static int add_patterns_from_buffer(char *buf, size_t size,
1046
*/
1047
static int add_patterns(const char *fname, const char *base, int baselen,
1048
struct pattern_list *pl, struct index_state *istate,
1049
- struct oid_stat *oid_stat)
1049
+ unsigned flags, struct oid_stat *oid_stat)
1050
{
1051
struct stat st;
1052
int r;
@@ -1143,9 +1143,10 @@ static int add_patterns_from_buffer(char *buf, size_t size,
1143
1144
int add_patterns_from_file_to_list(const char *fname, const char *base,
1145
int baselen, struct pattern_list *pl,
1146
- struct index_state *istate)
1146
+ struct index_state *istate,
1147
+ unsigned flags)
1148
{
1148
- return add_patterns(fname, base, baselen, pl, istate, NULL);
1149
+ return add_patterns(fname, base, baselen, pl, istate, flags, NULL);
1150
}
1151
1152
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,
1195
if (!dir->untracked)
1196
dir->unmanaged_exclude_files++;
1197
pl = add_pattern_list(dir, EXC_FILE, fname);
1197
- if (add_patterns(fname, "", 0, pl, NULL, oid_stat) < 0)
1198
+ if (add_patterns(fname, "", 0, pl, NULL, 0, oid_stat) < 0)
1199
die(_("cannot use %s as an exclude file"), fname);
1200
}
1201
@@ -1557,7 +1558,7 @@ static void prep_exclude(struct dir_struct *dir,
1558
strbuf_addbuf(&sb, &dir->basebuf);
1559
strbuf_addstr(&sb, dir->exclude_per_dir);
1560
pl->src = strbuf_detach(&sb, NULL);
1560
- add_patterns(pl->src, pl->src, stk->baselen, pl, istate,
1561
+ add_patterns(pl->src, pl->src, stk->baselen, pl, istate, 0,
1562
untracked ? &oid_stat : NULL);
1563
}
1564
/*
@@ -3009,7 +3010,7 @@ int get_sparse_checkout_patterns(struct pattern_list *pl)
3010
char *sparse_filename = get_sparse_checkout_filename();
3011
3012
pl->use_cone_patterns = core_sparse_checkout_cone;
3012
- res = add_patterns_from_file_to_list(sparse_filename, "", 0, pl, NULL);
3013
+ res = add_patterns_from_file_to_list(sparse_filename, "", 0, pl, NULL, 0);
3014
3015
free(sparse_filename);
3016
return res;
dir.h
+2
-1
@@ -420,7 +420,8 @@ int hashmap_contains_parent(struct hashmap *map,
420
struct pattern_list *add_pattern_list(struct dir_struct *dir,
421
int group_type, const char *src);
422
int add_patterns_from_file_to_list(const char *fname, const char *base, int baselen,
423
- struct pattern_list *pl, struct index_state *istate);
423
+ struct pattern_list *pl, struct index_state *istate,
424
+ unsigned flags);
425
void add_patterns_from_file(struct dir_struct *, const char *fname);
426
int add_patterns_from_blob_to_list(struct object_id *oid,
427
const char *base, int baselen,