{"thread":{"id":"9377","subject":"[RFC/PATCH] update-index: Add a --refresh-only option to refresh specified files.","startedAt":"2007-08-04T09:59:32Z","lastAt":"2007-08-04T21:31:02Z","messageCount":3,"participants":["Alexandre Julliard","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"49689","messageId":"87odhnk4cb.fsf@wine.dyndns.org","threadId":"9377","inReplyTo":null,"subject":"[RFC/PATCH] update-index: Add a --refresh-only option to refresh specified files.","fromName":"Alexandre Julliard","fromEmail":"julliard@winehq.org","sentAt":"2007-08-04T09:59:32Z","receivedAt":"2007-08-04T09:59:32Z","isPatch":true,"sender":{"key":"julliard@winehq.org","avatar":null},"body":"This allows to quickly refresh a file that has been touched without\nhaving to stat all the files of the project.\n\nSigned-off-by: Alexandre Julliard <julliard@winehq.org>\n---\n\nDoes this look reasonable?  The refresh_index_path() function is a\ncopy/paste of refresh_index(), I'm not sure all of it is really\nneeded, but I don't claim to understand all the subtleties of the\nindex management...\n\n\n builtin-update-index.c |   17 +++++++++++++--\n cache.h                |    1 +\n read-cache.c           |   49 ++++++++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 64 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin-update-index.c b/builtin-update-index.c\nindex 509369e..ac24ef3 100644\n--- a/builtin-update-index.c\n+++ b/builtin-update-index.c\n@@ -22,6 +22,7 @@ static int allow_add;\n static int allow_remove;\n static int allow_replace;\n static int info_only;\n+static int refresh_only;\n static int force_remove;\n static int verbose;\n static int mark_valid_only;\n@@ -266,8 +267,9 @@ static void chmod_path(int flip, const char *path)\n \tdie(\"git-update-index: cannot chmod %cx '%s'\", flip, path);\n }\n \n-static void update_one(const char *path, const char *prefix, int prefix_length)\n+static int update_one(const char *path, const char *prefix, int prefix_length)\n {\n+\tint has_errors = 0;\n \tconst char *p = prefix_path(prefix, prefix_length, path);\n \tif (!verify_path(p)) {\n \t\tfprintf(stderr, \"Ignoring path %s\\n\", path);\n@@ -278,6 +280,10 @@ static void update_one(const char *path, const char *prefix, int prefix_length)\n \t\t\tdie(\"Unable to mark file %s\", path);\n \t\tgoto free_return;\n \t}\n+\tif (refresh_only) {\n+\t\thas_errors |= refresh_index_path(&the_index, 0, path);\n+\t\tgoto free_return;\n+\t}\n \tcache_tree_invalidate_path(active_cache_tree, path);\n \n \tif (force_remove) {\n@@ -292,6 +298,7 @@ static void update_one(const char *path, const char *prefix, int prefix_length)\n  free_return:\n \tif (p < path || p > path + strlen(path))\n \t\tfree((char*)p);\n+\treturn has_errors;\n }\n \n static void read_index_info(int line_termination)\n@@ -620,6 +627,10 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \t\t\t\thas_errors |= refresh_cache(REFRESH_REALLY | refresh_flags);\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!strcmp(path, \"--refresh-only\")) {\n+\t\t\t\trefresh_only = 1;\n+\t\t\t\tcontinue;\n+\t\t\t}\n \t\t\tif (!strcmp(path, \"--cacheinfo\")) {\n \t\t\t\tunsigned char sha1[20];\n \t\t\t\tunsigned int mode;\n@@ -702,7 +713,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \t\t\tdie(\"unknown option %s\", path);\n \t\t}\n \t\tp = prefix_path(prefix, prefix_length, path);\n-\t\tupdate_one(p, NULL, 0);\n+\t\thas_errors |= update_one(p, NULL, 0);\n \t\tif (set_executable_bit)\n \t\t\tchmod_path(set_executable_bit, p);\n \t\tif (p < path || p > path + strlen(path))\n@@ -722,7 +733,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \t\t\telse\n \t\t\t\tpath_name = buf.buf;\n \t\t\tp = prefix_path(prefix, prefix_length, path_name);\n-\t\t\tupdate_one(p, NULL, 0);\n+\t\t\thas_errors |= update_one(p, NULL, 0);\n \t\t\tif (set_executable_bit)\n \t\t\t\tchmod_path(set_executable_bit, p);\n \t\t\tif (p < path_name || p > path_name + strlen(path_name))\ndiff --git a/cache.h b/cache.h\nindex e97af18..6982ab4 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -278,6 +278,7 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);\n #define REFRESH_QUIET\t\t0x0004\t/* be quiet about it */\n #define REFRESH_IGNORE_MISSING\t0x0008\t/* ignore non-existent */\n extern int refresh_index(struct index_state *, unsigned int flags);\n+extern int refresh_index_path(struct index_state *istate, unsigned int flags, const char *path);\n \n struct lock_file {\n \tstruct lock_file *next;\ndiff --git a/read-cache.c b/read-cache.c\nindex e060392..1c0bfe8 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -836,6 +836,55 @@ int refresh_index(struct index_state *istate, unsigned int flags)\n \treturn has_errors;\n }\n \n+int refresh_index_path(struct index_state *istate, unsigned int flags, const char *path)\n+{\n+\tint really = (flags & REFRESH_REALLY) != 0;\n+\tint allow_unmerged = (flags & REFRESH_UNMERGED) != 0;\n+\tint quiet = (flags & REFRESH_QUIET) != 0;\n+\tint not_new = (flags & REFRESH_IGNORE_MISSING) != 0;\n+\tstruct cache_entry *ce, *new;\n+\tint cache_errno = 0;\n+\tint i = index_name_pos(istate, path, strlen(path));\n+\n+\tif (i < 0) {\n+\t\tprintf(\"%s: not in index\\n\", path);\n+\t\treturn 1;\n+\t}\n+\n+\tce = istate->cache[i];\n+\tif (ce_stage(ce)) {\n+\t\tif (allow_unmerged)\n+\t\t\treturn 0;\n+\t\tprintf(\"%s: needs merge\\n\", ce->name);\n+\t\treturn 1;\n+\t}\n+\n+\tnew = refresh_cache_ent(istate, ce, really, &cache_errno);\n+\tif (new == ce)\n+\t\treturn 0;\n+\tif (!new) {\n+\t\tif (not_new && cache_errno == ENOENT)\n+\t\t\treturn 0;\n+\t\tif (really && cache_errno == EINVAL) {\n+\t\t\t/* If we are doing --really-refresh that\n+\t\t\t * means the index is not valid anymore.\n+\t\t\t */\n+\t\t\tce->ce_flags &= ~htons(CE_VALID);\n+\t\t\tistate->cache_changed = 1;\n+\t\t}\n+\t\tif (quiet)\n+\t\t\treturn 0;\n+\t\tprintf(\"%s: needs update\\n\", ce->name);\n+\t\treturn 1;\n+\t}\n+\tistate->cache_changed = 1;\n+\t/* You can NOT just free istate->cache[i] here, since it\n+\t * might not be necessarily malloc()ed but can also come\n+\t * from mmap(). */\n+\tistate->cache[i] = new;\n+\treturn 0;\n+}\n+\n struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really)\n {\n \treturn refresh_cache_ent(&the_index, ce, really, NULL);\n-- \n1.5.3.rc4\n\n-- \nAlexandre Julliard\njulliard@winehq.org\n"},{"id":"49767","messageId":"7vlkcrgnd1.fsf@assigned-by-dhcp.cox.net","threadId":"9377","inReplyTo":"87odhnk4cb.fsf@wine.dyndns.org","subject":"Re: [RFC/PATCH] update-index: Add a --refresh-only option to refresh specified files.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-08-04T18:34:34Z","receivedAt":"2007-08-04T18:34:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alexandre Julliard <julliard@winehq.org> writes:\n\n> This allows to quickly refresh a file that has been touched without\n> having to stat all the files of the project.\n>\n> Signed-off-by: Alexandre Julliard <julliard@winehq.org>\n> ---\n>\n> Does this look reasonable?  The refresh_index_path() function is a\n> copy/paste of refresh_index(), I'm not sure all of it is really\n> needed, but I don't claim to understand all the subtleties of the\n> index management...\n\nMakes me wonder why it is not like:\n\n\t$ git update-index --refresh Documentation/\n\nThat is:\n\n - why a new option?\n - why not a pathspec or glob, similar to what ls-files gets?\n"},{"id":"49780","messageId":"87hcnfj8bt.fsf@wine.dyndns.org","threadId":"9377","inReplyTo":"7vlkcrgnd1.fsf@assigned-by-dhcp.cox.net","subject":"Re: [RFC/PATCH] update-index: Add a --refresh-only option to refresh specified files.","fromName":"Alexandre Julliard","fromEmail":"julliard@winehq.org","sentAt":"2007-08-04T21:31:02Z","receivedAt":"2007-08-04T21:31:02Z","isPatch":true,"sender":{"key":"julliard@winehq.org","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Makes me wonder why it is not like:\n>\n> \t$ git update-index --refresh Documentation/\n>\n> That is:\n>\n>  - why a new option?\n\nIt was to avoid breaking backwards compatibility, since passing files\nwith --refresh currently has a different meaning. But if you think we\ncan change that, then sure, it would be much nicer.\n\n>  - why not a pathspec or glob, similar to what ls-files gets?\n\nI'm not sure, would this really belong in update-index since it\ncurrently always requires explicit pathnames?  Or should it be in a\nhigher-level command like git-add --refresh?\n\n-- \nAlexandre Julliard\njulliard@winehq.org\n"}]}