Skip to content

Commit 72e59ba

Browse files
ffyuandagitster
authored andcommitted
mv: rename check_dir_in_index() to empty_dir_has_sparse_contents()
Method check_dir_in_index() introduced in b91a2b6 (mv: add check_dir_in_index() and solve general dir check issue, 2022-06-30) does not describe its intent and behavior well. Change its name to empty_dir_has_sparse_contents(), which more precisely describes its purpose. Reverse the return values, check_dir_in_index() return 0 for success and 1 for failure; reverse the values so empty_dir_has_sparse_contents() return 1 for success and 0 for failure. These values are more intuitive because 1 usually means "has" and 0 means "not found". Also modify the documentation to better align with the method's intent and behavior. Helped-by: Derrick Stolee <[email protected]> Helped-by: Victoria Dye <[email protected]> Signed-off-by: Shaoxuan Yuan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5506683 commit 72e59ba

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

builtin/mv.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,13 @@ static int index_range_of_same_dir(const char *src, int length,
125125
}
126126

127127
/*
128-
* Check if an out-of-cone directory should be in the index. Imagine this case
129-
* that all the files under a directory are marked with 'CE_SKIP_WORKTREE' bit
130-
* and thus the directory is sparsified.
131-
*
132-
* Return 0 if such directory exist (i.e. with any of its contained files not
133-
* marked with CE_SKIP_WORKTREE, the directory would be present in working tree).
134-
* Return 1 otherwise.
128+
* Given the path of a directory that does not exist on-disk, check whether the
129+
* directory contains any entries in the index with the SKIP_WORKTREE flag
130+
* enabled.
131+
* Return 1 if such index entries exist.
132+
* Return 0 otherwise.
135133
*/
136-
static int check_dir_in_index(const char *name)
134+
static int empty_dir_has_sparse_contents(const char *name)
137135
{
138136
const char *with_slash = add_slash(name);
139137
int length = strlen(with_slash);
@@ -144,14 +142,14 @@ static int check_dir_in_index(const char *name)
144142
if (pos < 0) {
145143
pos = -pos - 1;
146144
if (pos >= the_index.cache_nr)
147-
return 1;
145+
return 0;
148146
ce = active_cache[pos];
149147
if (strncmp(with_slash, ce->name, length))
150-
return 1;
151-
if (ce_skip_worktree(ce))
152148
return 0;
149+
if (ce_skip_worktree(ce))
150+
return 1;
153151
}
154-
return 1;
152+
return 0;
155153
}
156154

157155
int cmd_mv(int argc, const char **argv, const char *prefix)
@@ -231,7 +229,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
231229
if (pos < 0) {
232230
const char *src_w_slash = add_slash(src);
233231
if (!path_in_sparse_checkout(src_w_slash, &the_index) &&
234-
!check_dir_in_index(src)) {
232+
empty_dir_has_sparse_contents(src)) {
235233
modes[i] |= SKIP_WORKTREE_DIR;
236234
goto dir_check;
237235
}

0 commit comments

Comments
 (0)