[PATCH 4/9] update-index: refactor mark_valid() in preparation for new options

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Nguyễn Thái Ngọc Duy
Date: Tuesday, September 30, 2008 - 9:04 pm

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin-update-index.c |   24 ++++++++++--------------
 1 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/builtin-update-index.c b/builtin-update-index.c
index 417f972..ae94739 100644
--- a/builtin-update-index.c
+++ b/builtin-update-index.c
@@ -24,8 +24,8 @@ static int info_only;
 static int force_remove;
 static int verbose;
 static int mark_valid_only;
-#define MARK_VALID 1
-#define UNMARK_VALID 2
+#define MARK_FLAG 1
+#define UNMARK_FLAG 2
 
 static void report(const char *fmt, ...)
 {
@@ -40,19 +40,15 @@ static void report(const char *fmt, ...)
 	va_end(vp);
 }
 
-static int mark_valid(const char *path)
+static int mark_ce_flags(const char *path, int flag, int mark)
 {
 	int namelen = strlen(path);
 	int pos = cache_name_pos(path, namelen);
 	if (0 <= pos) {
-		switch (mark_valid_only) {
-		case MARK_VALID:
-			active_cache[pos]->ce_flags |= CE_VALID;
-			break;
-		case UNMARK_VALID:
-			active_cache[pos]->ce_flags &= ~CE_VALID;
-			break;
-		}
+		if (mark)
+			active_cache[pos]->ce_flags |= flag;
+		else
+			active_cache[pos]->ce_flags &= ~flag;
 		cache_tree_invalidate_path(active_cache_tree, path);
 		active_cache_changed = 1;
 		return 0;
@@ -276,7 +272,7 @@ static void update_one(const char *path, const char *prefix, int prefix_length)
 		goto free_return;
 	}
 	if (mark_valid_only) {
-		if (mark_valid(p))
+		if (mark_ce_flags(p, CE_VALID, mark_valid_only == MARK_FLAG))
 			die("Unable to mark file %s", path);
 		goto free_return;
 	}
@@ -649,11 +645,11 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
 				continue;
 			}
 			if (!strcmp(path, "--assume-unchanged")) {
-				mark_valid_only = MARK_VALID;
+				mark_valid_only = MARK_FLAG;
 				continue;
 			}
 			if (!strcmp(path, "--no-assume-unchanged")) {
-				mark_valid_only = UNMARK_VALID;
+				mark_valid_only = UNMARK_FLAG;
 				continue;
 			}
 			if (!strcmp(path, "--info-only")) {
-- 
1.6.0.2.488.gf604a

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH/resent 0/9] Sparse checkout (first half), Nguyễn Thái Ngọc Duy, (Tue Sep 30, 9:04 pm)
[PATCH 1/9] Extend index to save more flags, Nguyễn Thái Ngọc Duy, (Tue Sep 30, 9:04 pm)
[PATCH 2/9] Introduce CE_NO_CHECKOUT bit, Nguyễn Thái Ngọc Duy, (Tue Sep 30, 9:04 pm)
[PATCH 3/9] ls-files: add options to support sparse checkout, Nguyễn Thái Ngọc Duy, (Tue Sep 30, 9:04 pm)
[PATCH 4/9] update-index: refactor mark_valid() in prepara ..., Nguyễn Thái Ngọc Duy, (Tue Sep 30, 9:04 pm)
[PATCH 5/9] update-index: add --checkout/--no-checkout to ..., Nguyễn Thái Ngọc Duy, (Tue Sep 30, 9:04 pm)
[PATCH 6/9] ls-files: Add tests for --sparse and friends, Nguyễn Thái Ngọc Duy, (Tue Sep 30, 9:04 pm)
Re: [PATCH/resent 0/9] Sparse checkout (first half), Santi Béjar, (Wed Oct 1, 3:20 am)
Re: [PATCH/resent 0/9] Sparse checkout (first half), Santi Béjar, (Wed Oct 1, 4:25 am)
Re: [PATCH/resent 0/9] Sparse checkout (first half), Nguyen Thai Ngoc Duy, (Wed Oct 1, 5:09 am)
Re: [PATCH/resent 0/9] Sparse checkout (first half), Santi Béjar, (Wed Oct 1, 7:38 am)
Re: [PATCH 5/9] update-index: add --checkout/--no-checkout ..., Nguyen Thai Ngoc Duy, (Thu Nov 20, 8:26 am)
Re: [PATCH 5/9] update-index: add --checkout/--no-checkout ..., Nguyen Thai Ngoc Duy, (Thu Nov 20, 8:54 am)