Skip to content

Commit 113e641

Browse files
chriscoolgitster
authored andcommitted
update-index: use enum for untracked cache options
Helped-by: Duy Nguyen <[email protected]> Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9624a22 commit 113e641

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

builtin/update-index.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ static int mark_skip_worktree_only;
3535
#define UNMARK_FLAG 2
3636
static struct strbuf mtime_dir = STRBUF_INIT;
3737

38+
/* Untracked cache mode */
39+
enum uc_mode {
40+
UC_UNSPECIFIED = -1,
41+
UC_DISABLE = 0,
42+
UC_ENABLE,
43+
UC_FORCE
44+
};
45+
3846
__attribute__((format (printf, 1, 2)))
3947
static void report(const char *fmt, ...)
4048
{
@@ -902,7 +910,7 @@ static int reupdate_callback(struct parse_opt_ctx_t *ctx,
902910
int cmd_update_index(int argc, const char **argv, const char *prefix)
903911
{
904912
int newfd, entries, has_errors = 0, line_termination = '\n';
905-
int untracked_cache = -1;
913+
enum uc_mode untracked_cache = UC_UNSPECIFIED;
906914
int read_from_stdin = 0;
907915
int prefix_length = prefix ? strlen(prefix) : 0;
908916
int preferred_index_format = 0;
@@ -997,7 +1005,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
9971005
OPT_BOOL(0, "untracked-cache", &untracked_cache,
9981006
N_("enable/disable untracked cache")),
9991007
OPT_SET_INT(0, "force-untracked-cache", &untracked_cache,
1000-
N_("enable untracked cache without testing the filesystem"), 2),
1008+
N_("enable untracked cache without testing the filesystem"), UC_FORCE),
10011009
OPT_END()
10021010
};
10031011

@@ -1104,10 +1112,10 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11041112
the_index.split_index = NULL;
11051113
the_index.cache_changed |= SOMETHING_CHANGED;
11061114
}
1107-
if (untracked_cache > 0) {
1115+
if (untracked_cache > UC_DISABLE) {
11081116
struct untracked_cache *uc;
11091117

1110-
if (untracked_cache < 2) {
1118+
if (untracked_cache < UC_FORCE) {
11111119
setup_work_tree();
11121120
if (!test_if_untracked_cache_is_supported())
11131121
return 1;
@@ -1122,7 +1130,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11221130
}
11231131
add_untracked_ident(the_index.untracked);
11241132
the_index.cache_changed |= UNTRACKED_CHANGED;
1125-
} else if (!untracked_cache && the_index.untracked) {
1133+
} else if (untracked_cache == UC_DISABLE && the_index.untracked) {
11261134
free_untracked_cache(the_index.untracked);
11271135
the_index.untracked = NULL;
11281136
the_index.cache_changed |= UNTRACKED_CHANGED;

0 commit comments

Comments
 (0)