{"thread":{"id":"12372","subject":"[PATCH v2] Write index file on any checkout of files","startedAt":"2008-02-28T21:52:44Z","lastAt":"2008-02-28T21:52:44Z","messageCount":1,"participants":["Daniel Barkalow"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"70322","messageId":"alpine.LNX.1.00.0802281652160.19665@iabervon.org","threadId":"12372","inReplyTo":null,"subject":"[PATCH v2] Write index file on any checkout of files","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2008-02-28T21:52:44Z","receivedAt":"2008-02-28T21:52:44Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"We need to rewrite the index file when we check out files, even if we\nhaven't modified the blob info by reading from another tree, so that\nwe get the stat cache to include the fact that we just modified the\nfile so it doesn't need to be refreshed.\n\nWhile we're at it, move everything that needs to be done to check out\nsome paths from a tree (or the current index) into checkout_paths().\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\n---\n builtin-checkout.c |   30 +++++++++++++++---------------\n 1 files changed, 15 insertions(+), 15 deletions(-)\n\ndiff --git a/builtin-checkout.c b/builtin-checkout.c\nindex 4a4bb8b..007572e 100644\n--- a/builtin-checkout.c\n+++ b/builtin-checkout.c\n@@ -67,17 +67,8 @@ static int update_some(const unsigned char *sha1, const char *base, int baselen,\n \n static int read_tree_some(struct tree *tree, const char **pathspec)\n {\n-\tint newfd;\n-\tstruct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));\n-\tnewfd = hold_locked_index(lock_file, 1);\n-\tread_cache();\n-\n \tread_tree_recursive(tree, \"\", 0, 0, pathspec, update_some);\n \n-\tif (write_cache(newfd, active_cache, active_nr) ||\n-\t    commit_locked_index(lock_file))\n-\t\tdie(\"unable to write new index file\");\n-\n \t/* update the index with the given tree's info\n \t * for all args, expanding wildcards, and exit\n \t * with any non-zero return code.\n@@ -85,7 +76,7 @@ static int read_tree_some(struct tree *tree, const char **pathspec)\n \treturn 0;\n }\n \n-static int checkout_paths(const char **pathspec)\n+static int checkout_paths(struct tree *source_tree, const char **pathspec)\n {\n \tint pos;\n \tstruct checkout state;\n@@ -94,6 +85,15 @@ static int checkout_paths(const char **pathspec)\n \tint flag;\n \tstruct commit *head;\n \n+\tint newfd;\n+\tstruct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));\n+\n+\tnewfd = hold_locked_index(lock_file, 1);\n+\tread_cache();\n+\n+\tif (source_tree)\n+\t\tread_tree_some(source_tree, pathspec);\n+\n \tfor (pos = 0; pathspec[pos]; pos++)\n \t\t;\n \tps_matched = xcalloc(1, pos);\n@@ -116,6 +116,10 @@ static int checkout_paths(const char **pathspec)\n \t\t}\n \t}\n \n+\tif (write_cache(newfd, active_cache, active_nr) ||\n+\t    commit_locked_index(lock_file))\n+\t\tdie(\"unable to write new index file\");\n+\n \tresolve_ref(\"HEAD\", rev, 0, &flag);\n \thead = lookup_commit_reference_gently(rev, 1);\n \n@@ -554,11 +558,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)\n \t\t\t}\n \t\t}\n \n-\t\tif (source_tree)\n-\t\t\tread_tree_some(source_tree, pathspec);\n-\t\telse\n-\t\t\tread_cache();\n-\t\treturn checkout_paths(pathspec);\n+\t\treturn checkout_paths(source_tree, pathspec);\n \t}\n \n \tif (new.name && !new.commit) {\n-- \n1.5.4.3.327.g614d7.dirty\n"}]}