{"thread":{"id":"10772","subject":"[PATCH v2] builtin-commit: Refresh cache after adding files.","startedAt":"2007-11-09T18:50:38Z","lastAt":"2007-11-09T19:37:51Z","messageCount":2,"participants":["Kristian Høgsberg","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"59113","messageId":"1194634238-3308-1-git-send-email-krh@redhat.com","threadId":"10772","inReplyTo":null,"subject":"[PATCH v2] builtin-commit: Refresh cache after adding files.","fromName":"Kristian Høgsberg","fromEmail":"krh@redhat.com","sentAt":"2007-11-09T18:50:38Z","receivedAt":"2007-11-09T18:50:38Z","isPatch":true,"sender":{"key":"krh@redhat.com","avatar":"https://gravatar.com/avatar/763dee6f9594ac474f725b137a39565792928e583ddf59b32befc2907409027e?d=mp&s=160"},"body":"This fixes the race in the last test in t3700-add.sh.\nadd_files_to_cache() should leave the new index stat-clean, but some\ntimes it doesn't.  Calling refresh_cache() in a few places works\naround this for now.\n\nSigned-off-by: Kristian Høgsberg <krh@redhat.com>\n---\n\nShould we add the refresh_cache() call in add_files_to_cache() instead?\n\n builtin-commit.c |    3 +++\n 1 files changed, 3 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-commit.c b/builtin-commit.c\nindex 7dc8977..81539c8 100644\n--- a/builtin-commit.c\n+++ b/builtin-commit.c\n@@ -81,6 +81,7 @@ static char *prepare_index(const char **files, const char *prefix)\n \n \tif (all || also) {\n \t\tadd_files_to_cache(verbose, also ? prefix : NULL, files);\n+\t\trefresh_cache(REFRESH_QUIET);\n \t\tif (write_cache(fd, active_cache, active_nr) || close(fd))\n \t\t\tdie(\"unable to write new_index file\");\n \t\treturn lock_file.filename;\n@@ -94,6 +95,7 @@ static char *prepare_index(const char **files, const char *prefix)\n \n \t/* update the user index file */\n \tadd_files_to_cache(verbose, prefix, files);\n+\trefresh_cache(REFRESH_QUIET);\n \tif (write_cache(fd, active_cache, active_nr) || close(fd))\n \t\tdie(\"unable to write new_index file\");\n \n@@ -110,6 +112,7 @@ static char *prepare_index(const char **files, const char *prefix)\n \tfd = hold_lock_file_for_update(next_index_lock,\n \t\t\t\t       git_path(\"next-index-%d\", getpid()), 1);\n \tadd_files_to_cache(verbose, prefix, files);\n+\trefresh_cache(REFRESH_QUIET);\n \tif (write_cache(fd, active_cache, active_nr) || close(fd))\n \t\tdie(\"unable to write new_index file\");\n \n-- \n1.5.3.4.206.g58ba4\n"},{"id":"59118","messageId":"7vzlxnrz00.fsf@gitster.siamese.dyndns.org","threadId":"10772","inReplyTo":"1194634238-3308-1-git-send-email-krh@redhat.com","subject":"Re: [PATCH v2] builtin-commit: Refresh cache after adding files.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-11-09T19:37:51Z","receivedAt":"2007-11-09T19:37:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Kristian Høgsberg <krh@redhat.com> writes:\n\n> This fixes the race in the last test in t3700-add.sh.\n> add_files_to_cache() should leave the new index stat-clean, but some\n> times it doesn't.  Calling refresh_cache() in a few places works\n> around this for now.\n\nSorry, but this description based on my previous observation is\nnot quite right.\n\nAs we have been promising users that \"git status\" will clear\naway the stat dirtiness, we should call refresh_cache() at the\nend of prepare_index() regardless of the add_files_to_cache()\nissue.  We need to refresh_cache() the whole thing, even if we\nfixed add_files_to_cache() to add entries that are stat clean,\nso this is not a workaround but implementation of the advertised\nbehaviour.  It does hide the problem add_files_to_cache() seems\nto have, which we would need to fix independently.\n\nI think the additional refresh_cache() for the user index you\ndid is also the right thing to do for the same reason.\n\n> Signed-off-by: Kristian Høgsberg <krh@redhat.com>\n> ---\n>\n> Should we add the refresh_cache() call in add_files_to_cache() instead?\n\nI do not think so.  These two functions, add_files_to_cache()\nand add_file_to_cache(), should make the entries they add to the\nindex stat-clean, but they should not spend extra cycles\nscanning the whole index and re-statting the whole tree to\nrefresh entries the user did not mention.\n"}]}