{"thread":{"id":"20614","subject":"[PATCH] unpack-trees.c: simplify check_updates() code path when o->update is false","startedAt":"2009-08-16T05:05:30Z","lastAt":"2009-08-16T05:05:30Z","messageCount":1,"participants":["Nguyễn Thái Ngọc Duy"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"120757","messageId":"1250399130-31793-1-git-send-email-pclouds@gmail.com","threadId":"20614","inReplyTo":null,"subject":"[PATCH] unpack-trees.c: simplify check_updates() code path when o->update is false","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2009-08-16T05:05:30Z","receivedAt":"2009-08-16T05:05:30Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"check_updates() is heavily branched by o->update, which makes it quite\ndifficult to follow. This patch rips \"o->update == 0\" code path out and\nput it on top.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n unpack-trees.c |   23 +++++++++++++----------\n 1 files changed, 13 insertions(+), 10 deletions(-)\n\ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex 720f7a1..3ee9919 100644\n--- a/unpack-trees.c\n+++ b/unpack-trees.c\n@@ -75,7 +75,15 @@ static int check_updates(struct unpack_trees_options *o)\n \tint i;\n \tint errs = 0;\n \n-\tif (o->update && o->verbose_update) {\n+\tif (!o->update) {\n+\t\tremove_marked_cache_entries(&o->result);\n+\t\tremove_scheduled_dirs();\n+\t\tfor (i = 0; i < index->cache_nr; i++)\n+\t\t\tindex->cache[i]->ce_flags &= ~CE_UPDATE;\n+\t\treturn 0;\n+\t}\n+\n+\tif (o->verbose_update) {\n \t\tfor (total = cnt = 0; cnt < index->cache_nr; cnt++) {\n \t\t\tstruct cache_entry *ce = index->cache[cnt];\n \t\t\tif (ce->ce_flags & (CE_UPDATE | CE_REMOVE))\n@@ -87,15 +95,13 @@ static int check_updates(struct unpack_trees_options *o)\n \t\tcnt = 0;\n \t}\n \n-\tif (o->update)\n-\t\tgit_attr_set_direction(GIT_ATTR_CHECKOUT, &o->result);\n+\tgit_attr_set_direction(GIT_ATTR_CHECKOUT, &o->result);\n \tfor (i = 0; i < index->cache_nr; i++) {\n \t\tstruct cache_entry *ce = index->cache[i];\n \n \t\tif (ce->ce_flags & CE_REMOVE) {\n \t\t\tdisplay_progress(progress, ++cnt);\n-\t\t\tif (o->update)\n-\t\t\t\tunlink_entry(ce);\n+\t\t\tunlink_entry(ce);\n \t\t}\n \t}\n \tremove_marked_cache_entries(&o->result);\n@@ -107,14 +113,11 @@ static int check_updates(struct unpack_trees_options *o)\n \t\tif (ce->ce_flags & CE_UPDATE) {\n \t\t\tdisplay_progress(progress, ++cnt);\n \t\t\tce->ce_flags &= ~CE_UPDATE;\n-\t\t\tif (o->update) {\n-\t\t\t\terrs |= checkout_entry(ce, &state, NULL);\n-\t\t\t}\n+\t\t\terrs |= checkout_entry(ce, &state, NULL);\n \t\t}\n \t}\n \tstop_progress(&progress);\n-\tif (o->update)\n-\t\tgit_attr_set_direction(GIT_ATTR_CHECKIN, NULL);\n+\tgit_attr_set_direction(GIT_ATTR_CHECKIN, NULL);\n \treturn errs != 0;\n }\n \n-- \n1.6.3.GIT\n"}]}