{"thread":{"id":"37538","subject":"How to update index stat info without reading file content?","startedAt":"2014-09-11T19:04:08Z","lastAt":"2014-09-11T20:51:53Z","messageCount":2,"participants":["Steffen Prohaska","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"249245","messageId":"99C877A8-8145-4D8E-BE83-0F8A1FC16214@zib.de","threadId":"37538","inReplyTo":null,"subject":"How to update index stat info without reading file content?","fromName":"Steffen Prohaska","fromEmail":"prohaska@zib.de","sentAt":"2014-09-11T19:04:08Z","receivedAt":"2014-09-11T19:04:08Z","isPatch":false,"sender":{"key":"prohaska@zib.de","avatar":"https://avatars.githubusercontent.com/u/217580?v=4"},"body":"Hi,\n\nIs there a way to update the stat information recorded in the index without reading the file content from disk?\n\nStarting from a clean working copy with a committed `file`, I'd like \n\n    touch file\n    git <magic-command> file\n\nto bring the index into essentially the same state as\n\n    touch file\n    git status\n\nbut without reading the content of `file`.  (I'd be willing to wait a bit between touch and the magic command, to avoid any racy-git-related code paths.)\n\n`git-update-index --assume-unchanged` is related.  But it requires completely manual handling of changes, because git will not look at marked files until told otherwise with `--no-assume-unchanged`.  I'd like to tell git only that the current file content is known to be up-to-date.  Any future changes should be handled as usual.\n\nIn the documentation, `git add --refresh file` sounds a bit like what I'm looking for.  The documentation of `--refresh` states: \"Don’t add the file(s), but only refresh their stat() information in the index.\"  But it doesn't do what I want.\n\nI looked a bit into `read-cache.c`.  The comment above `refresh_cache_ent()` sounds promising:\n\n     \"refresh\" does not calculate a new sha1 file or bring the\n     cache up-to-date for mode/content changes. But what it\n     _does_ do is to \"re-match\" the stat information of a file\n     with the cache, so that you can refresh the cache for a\n     file that hasn't been changed but where the stat entry is\n     out of date.\n\nBut it isn't obvious to me whether what I'm looking for is available.  All code paths that eventually reach `fill_stat_cache_info()` seem to go through `ce_compare_data()` and therefore `index_fd()`, which reads the data from disk.\n\n\tSteffen"},{"id":"249258","messageId":"xmqqtx4ddgnq.fsf@gitster.dls.corp.google.com","threadId":"37538","inReplyTo":"99C877A8-8145-4D8E-BE83-0F8A1FC16214@zib.de","subject":"Re: How to update index stat info without reading file content?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-09-11T20:51:53Z","receivedAt":"2014-09-11T20:51:53Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Steffen Prohaska <prohaska@zib.de> writes:\n\n> Hi,\n>\n> Is there a way to update the stat information recorded in the index without reading the file content from disk?\n>\n> Starting from a clean working copy with a committed `file`, I'd like \n>\n>     touch file\n>     git <magic-command> file\n>\n> to bring the index into essentially the same state as\n>\n>     touch file\n>     git status\n>\n> but without reading the content of `file`.  (I'd be willing to wait a bit between touch and the magic command, to avoid any racy-git-related code paths.)\n>\n> `git-update-index --assume-unchanged` is related.  But it requires completely manual handling of changes, because git will not look at marked files until told otherwise with `--no-assume-unchanged`.  I'd like to tell git only that the current file content is known to be up-to-date.  Any future changes should be handled as usual.\n\nYes, \"assume-unchanged\" is related and it is often abused by\nclueless.  The only thing it does is by setting the bit, you promise\nGit that the one on the filesystem will be kept the same as the\nobject recorded in the index forever, one of the implications of\nwhich is that Git is free to use either the version on the\nfilesystem or data read with read_sha1_file() from the object store,\nwhichever it finds more convenient, when it needs to read the data\nfor the object recorded in the index for the path.  You are not\npromising the \"forever\" part, so it is not a good match for what you\nare trying to do.\n\n> In the documentation, `git add --refresh file` sounds a bit like\n> what I'm looking for.  The documentation of `--refresh` states:\n> \"Don’t add the file(s), but only refresh their stat() information\n> in the index.\"  But it doesn't do what I want.\n\nNo.  It is the same as \"update-index --refresh\".  You tell it \"I've\nmade this file, which may have had contents different from the\nobject name recorded in the index before, back to match what is\nrecorded in the index.\", it makes sure that you are not lying, and\nthen updates the cached stat information so that the next time it\ndoes not have to read the contents.\n"}]}