Git development
 help / color / mirror / Atom feed
* [PATCH] unpack-trees.c: simplify check_updates() code path when o->update is false
@ 2009-08-16  5:05 Nguyễn Thái Ngọc Duy
  0 siblings, 0 replies; only message in thread
From: Nguyễn Thái Ngọc Duy @ 2009-08-16  5:05 UTC (permalink / raw)
  To: Junio C Hamano, git; +Cc: Nguyễn Thái Ngọc Duy

check_updates() is heavily branched by o->update, which makes it quite
difficult to follow. This patch rips "o->update == 0" code path out and
put it on top.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 unpack-trees.c |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/unpack-trees.c b/unpack-trees.c
index 720f7a1..3ee9919 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -75,7 +75,15 @@ static int check_updates(struct unpack_trees_options *o)
 	int i;
 	int errs = 0;
 
-	if (o->update && o->verbose_update) {
+	if (!o->update) {
+		remove_marked_cache_entries(&o->result);
+		remove_scheduled_dirs();
+		for (i = 0; i < index->cache_nr; i++)
+			index->cache[i]->ce_flags &= ~CE_UPDATE;
+		return 0;
+	}
+
+	if (o->verbose_update) {
 		for (total = cnt = 0; cnt < index->cache_nr; cnt++) {
 			struct cache_entry *ce = index->cache[cnt];
 			if (ce->ce_flags & (CE_UPDATE | CE_REMOVE))
@@ -87,15 +95,13 @@ static int check_updates(struct unpack_trees_options *o)
 		cnt = 0;
 	}
 
-	if (o->update)
-		git_attr_set_direction(GIT_ATTR_CHECKOUT, &o->result);
+	git_attr_set_direction(GIT_ATTR_CHECKOUT, &o->result);
 	for (i = 0; i < index->cache_nr; i++) {
 		struct cache_entry *ce = index->cache[i];
 
 		if (ce->ce_flags & CE_REMOVE) {
 			display_progress(progress, ++cnt);
-			if (o->update)
-				unlink_entry(ce);
+			unlink_entry(ce);
 		}
 	}
 	remove_marked_cache_entries(&o->result);
@@ -107,14 +113,11 @@ static int check_updates(struct unpack_trees_options *o)
 		if (ce->ce_flags & CE_UPDATE) {
 			display_progress(progress, ++cnt);
 			ce->ce_flags &= ~CE_UPDATE;
-			if (o->update) {
-				errs |= checkout_entry(ce, &state, NULL);
-			}
+			errs |= checkout_entry(ce, &state, NULL);
 		}
 	}
 	stop_progress(&progress);
-	if (o->update)
-		git_attr_set_direction(GIT_ATTR_CHECKIN, NULL);
+	git_attr_set_direction(GIT_ATTR_CHECKIN, NULL);
 	return errs != 0;
 }
 
-- 
1.6.3.GIT

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2009-08-16  5:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-16  5:05 [PATCH] unpack-trees.c: simplify check_updates() code path when o->update is false Nguyễn Thái Ngọc Duy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox