Skip to content

Commit 473e393

Browse files
bmwillgitster
authored andcommitted
dir: convert add_excludes to take an index
Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent fba92be commit 473e393

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

dir.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -730,15 +730,16 @@ static void invalidate_directory(struct untracked_cache *uc,
730730

731731
/*
732732
* Given a file with name "fname", read it (either from disk, or from
733-
* the index if "check_index" is non-zero), parse it and store the
733+
* an index if 'istate' is non-null), parse it and store the
734734
* exclude rules in "el".
735735
*
736736
* If "ss" is not NULL, compute SHA-1 of the exclude file and fill
737737
* stat data from disk (only valid if add_excludes returns zero). If
738738
* ss_valid is non-zero, "ss" must contain good value as input.
739739
*/
740740
static int add_excludes(const char *fname, const char *base, int baselen,
741-
struct exclude_list *el, int check_index,
741+
struct exclude_list *el,
742+
struct index_state *istate,
742743
struct sha1_stat *sha1_stat)
743744
{
744745
struct stat st;
@@ -752,8 +753,8 @@ static int add_excludes(const char *fname, const char *base, int baselen,
752753
warn_on_inaccessible(fname);
753754
if (0 <= fd)
754755
close(fd);
755-
if (!check_index ||
756-
(buf = read_skip_worktree_file_from_index(&the_index, fname, &size, sha1_stat)) == NULL)
756+
if (!istate ||
757+
(buf = read_skip_worktree_file_from_index(istate, fname, &size, sha1_stat)) == NULL)
757758
return -1;
758759
if (size == 0) {
759760
free(buf);
@@ -785,15 +786,15 @@ static int add_excludes(const char *fname, const char *base, int baselen,
785786
if (sha1_stat) {
786787
int pos;
787788
if (sha1_stat->valid &&
788-
!match_stat_data_racy(&the_index, &sha1_stat->stat, &st))
789+
!match_stat_data_racy(istate, &sha1_stat->stat, &st))
789790
; /* no content change, ss->sha1 still good */
790-
else if (check_index &&
791-
(pos = index_name_pos(&the_index, fname, strlen(fname))) >= 0 &&
792-
!ce_stage(the_index.cache[pos]) &&
793-
ce_uptodate(the_index.cache[pos]) &&
791+
else if (istate &&
792+
(pos = index_name_pos(istate, fname, strlen(fname))) >= 0 &&
793+
!ce_stage(istate->cache[pos]) &&
794+
ce_uptodate(istate->cache[pos]) &&
794795
!would_convert_to_git(fname))
795796
hashcpy(sha1_stat->sha1,
796-
the_index.cache[pos]->oid.hash);
797+
istate->cache[pos]->oid.hash);
797798
else
798799
hash_sha1_file(buf, size, "blob", sha1_stat->sha1);
799800
fill_stat_data(&sha1_stat->stat, &st);
@@ -824,9 +825,9 @@ static int add_excludes(const char *fname, const char *base, int baselen,
824825

825826
int add_excludes_from_file_to_list(const char *fname, const char *base,
826827
int baselen, struct exclude_list *el,
827-
int check_index)
828+
struct index_state *istate)
828829
{
829-
return add_excludes(fname, base, baselen, el, check_index, NULL);
830+
return add_excludes(fname, base, baselen, el, istate, NULL);
830831
}
831832

832833
struct exclude_list *add_exclude_list(struct dir_struct *dir,
@@ -858,7 +859,7 @@ static void add_excludes_from_file_1(struct dir_struct *dir, const char *fname,
858859
if (!dir->untracked)
859860
dir->unmanaged_exclude_files++;
860861
el = add_exclude_list(dir, EXC_FILE, fname);
861-
if (add_excludes(fname, "", 0, el, 0, sha1_stat) < 0)
862+
if (add_excludes(fname, "", 0, el, NULL, sha1_stat) < 0)
862863
die("cannot use %s as an exclude file", fname);
863864
}
864865

@@ -1166,7 +1167,7 @@ static void prep_exclude(struct dir_struct *dir, const char *base, int baselen)
11661167
strbuf_addbuf(&sb, &dir->basebuf);
11671168
strbuf_addstr(&sb, dir->exclude_per_dir);
11681169
el->src = strbuf_detach(&sb, NULL);
1169-
add_excludes(el->src, el->src, stk->baselen, el, 1,
1170+
add_excludes(el->src, el->src, stk->baselen, el, &the_index,
11701171
untracked ? &sha1_stat : NULL);
11711172
}
11721173
/*

dir.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ extern int is_excluded(struct dir_struct *dir, const char *name, int *dtype);
243243
extern struct exclude_list *add_exclude_list(struct dir_struct *dir,
244244
int group_type, const char *src);
245245
extern int add_excludes_from_file_to_list(const char *fname, const char *base, int baselen,
246-
struct exclude_list *el, int check_index);
246+
struct exclude_list *el, struct index_state *istate);
247247
extern void add_excludes_from_file(struct dir_struct *, const char *fname);
248248
extern void parse_exclude_pattern(const char **string, int *patternlen, unsigned *flags, int *nowildcardlen);
249249
extern void add_exclude(const char *string, const char *base,

unpack-trees.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
12511251
o->skip_sparse_checkout = 1;
12521252
if (!o->skip_sparse_checkout) {
12531253
char *sparse = git_pathdup("info/sparse-checkout");
1254-
if (add_excludes_from_file_to_list(sparse, "", 0, &el, 0) < 0)
1254+
if (add_excludes_from_file_to_list(sparse, "", 0, &el, NULL) < 0)
12551255
o->skip_sparse_checkout = 1;
12561256
else
12571257
o->el = &el;

0 commit comments

Comments
 (0)