@matheusbsbs / matheus-bagliano / commits / 83b327ba4e
Fork 0

update-index: refactor mark_valid() in preparation for new options

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Aug 20, 2009 at 20:46 UTC 83b327ba4ec6d29fd59e343b734f642d266aeafc
1 file changed +10 -14
builtin-update-index.c
+10 -14
@@ -24,8 +24,8 @@ static int info_only;
24 static int force_remove;
25 static int verbose;
26 static int mark_valid_only;
27 -#define MARK_VALID 1
28 -#define UNMARK_VALID 2
27 +#define MARK_FLAG 1
28 +#define UNMARK_FLAG 2
29
30 static void report(const char *fmt, ...)
31 {
@@ -40,19 +40,15 @@ static void report(const char *fmt, ...)
40 va_end(vp);
41 }
42
43 -static int mark_valid(const char *path)
43 +static int mark_ce_flags(const char *path, int flag, int mark)
44 {
45 int namelen = strlen(path);
46 int pos = cache_name_pos(path, namelen);
47 if (0 <= pos) {
48 - switch (mark_valid_only) {
49 - case MARK_VALID:
50 - active_cache[pos]->ce_flags |= CE_VALID;
51 - break;
52 - case UNMARK_VALID:
53 - active_cache[pos]->ce_flags &= ~CE_VALID;
54 - break;
55 - }
48 + if (mark)
49 + active_cache[pos]->ce_flags |= flag;
50 + else
51 + active_cache[pos]->ce_flags &= ~flag;
52 cache_tree_invalidate_path(active_cache_tree, path);
53 active_cache_changed = 1;
54 return 0;
@@ -276,7 +272,7 @@ static void update_one(const char *path, const char *prefix, int prefix_length)
272 goto free_return;
273 }
274 if (mark_valid_only) {
279 - if (mark_valid(p))
275 + if (mark_ce_flags(p, CE_VALID, mark_valid_only == MARK_FLAG))
276 die("Unable to mark file %s", path);
277 goto free_return;
278 }
@@ -647,11 +643,11 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
643 continue;
644 }
645 if (!strcmp(path, "--assume-unchanged")) {
650 - mark_valid_only = MARK_VALID;
646 + mark_valid_only = MARK_FLAG;
647 continue;
648 }
649 if (!strcmp(path, "--no-assume-unchanged")) {
654 - mark_valid_only = UNMARK_VALID;
650 + mark_valid_only = UNMARK_FLAG;
651 continue;
652 }
653 if (!strcmp(path, "--info-only")) {