{"thread":{"id":"9486","subject":"[PATCH] git-add: Add a --refresh option.","startedAt":"2007-08-11T10:32:15Z","lastAt":"2007-08-11T20:05:17Z","messageCount":2,"participants":["Alexandre Julliard","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"50475","messageId":"87bqdeweds.fsf@wine.dyndns.org","threadId":"9486","inReplyTo":null,"subject":"[PATCH] git-add: Add a --refresh option.","fromName":"Alexandre Julliard","fromEmail":"julliard@winehq.org","sentAt":"2007-08-11T10:32:15Z","receivedAt":"2007-08-11T10:32:15Z","isPatch":true,"sender":{"key":"julliard@winehq.org","avatar":null},"body":"This allows to refresh only a subset of the project files, based on\nthe specified pathspecs.\n\nSigned-off-by: Alexandre Julliard <julliard@winehq.org>\n---\n builtin-add.c |   28 +++++++++++++++++++++++++++-\n cache.h       |    4 ++--\n read-cache.c  |    6 +++++-\n 3 files changed, 34 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin-add.c b/builtin-add.c\nindex de5c108..82c806a 100644\n--- a/builtin-add.c\n+++ b/builtin-add.c\n@@ -123,6 +123,23 @@ static void update(int verbose, const char **files)\n \trun_diff_files(&rev, 0);\n }\n \n+static void refresh(int verbose, const char **pathspec)\n+{\n+\tchar *seen;\n+\tint i, specs;\n+\n+\tfor (specs = 0; pathspec[specs];  specs++)\n+\t\t/* nothing */;\n+\tseen = xcalloc(specs, 1);\n+\tif (read_cache() < 0)\n+\t\tdie(\"index file corrupt\");\n+\trefresh_index(&the_index, verbose ? 0 : REFRESH_QUIET, pathspec, seen);\n+\tfor (i = 0; i < specs; i++) {\n+\t\tif (!seen[i])\n+\t\t\tdie(\"pathspec '%s' did not match any files\", pathspec[i]);\n+\t}\n+}\n+\n static int git_add_config(const char *var, const char *value)\n {\n \tif (!strcmp(var, \"core.excludesfile\")) {\n@@ -143,7 +160,7 @@ static const char ignore_warning[] =\n int cmd_add(int argc, const char **argv, const char *prefix)\n {\n \tint i, newfd;\n-\tint verbose = 0, show_only = 0, ignored_too = 0;\n+\tint verbose = 0, show_only = 0, ignored_too = 0, refresh_only = 0;\n \tconst char **pathspec;\n \tstruct dir_struct dir;\n \tint add_interactive = 0;\n@@ -191,6 +208,10 @@ int cmd_add(int argc, const char **argv, const char *prefix)\n \t\t\ttake_worktree_changes = 1;\n \t\t\tcontinue;\n \t\t}\n+\t\tif (!strcmp(arg, \"--refresh\")) {\n+\t\t\trefresh_only = 1;\n+\t\t\tcontinue;\n+\t\t}\n \t\tusage(builtin_add_usage);\n \t}\n \n@@ -206,6 +227,11 @@ int cmd_add(int argc, const char **argv, const char *prefix)\n \t}\n \tpathspec = get_pathspec(prefix, argv + i);\n \n+\tif (refresh_only) {\n+\t\trefresh(verbose, pathspec);\n+\t\tgoto finish;\n+\t}\n+\n \tfill_directory(&dir, pathspec, ignored_too);\n \n \tif (show_only) {\ndiff --git a/cache.h b/cache.h\nindex 4507404..c7e00e7 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -173,7 +173,7 @@ extern struct index_state the_index;\n #define remove_cache_entry_at(pos) remove_index_entry_at(&the_index, (pos))\n #define remove_file_from_cache(path) remove_file_from_index(&the_index, (path))\n #define add_file_to_cache(path, verbose) add_file_to_index(&the_index, (path), (verbose))\n-#define refresh_cache(flags) refresh_index(&the_index, flags)\n+#define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL)\n #define ce_match_stat(ce, st, really) ie_match_stat(&the_index, (ce), (st), (really))\n #define ce_modified(ce, st, really) ie_modified(&the_index, (ce), (st), (really))\n #endif\n@@ -278,7 +278,7 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);\n #define REFRESH_UNMERGED\t0x0002\t/* allow unmerged */\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(struct index_state *, unsigned int flags, const char **pathspec, char *seen);\n \n struct lock_file {\n \tstruct lock_file *next;\ndiff --git a/read-cache.c b/read-cache.c\nindex 865369d..8b1c94e 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -7,6 +7,7 @@\n #include \"cache.h\"\n #include \"cache-tree.h\"\n #include \"refs.h\"\n+#include \"dir.h\"\n \n /* Index extensions.\n  *\n@@ -798,7 +799,7 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,\n \treturn updated;\n }\n \n-int refresh_index(struct index_state *istate, unsigned int flags)\n+int refresh_index(struct index_state *istate, unsigned int flags, const char **pathspec, char *seen)\n {\n \tint i;\n \tint has_errors = 0;\n@@ -824,6 +825,9 @@ int refresh_index(struct index_state *istate, unsigned int flags)\n \t\t\tcontinue;\n \t\t}\n \n+\t\tif (pathspec && !match_pathspec(pathspec, ce->name, strlen(ce->name), 0, seen))\n+\t\t\tcontinue;\n+\n \t\tnew = refresh_cache_ent(istate, ce, really, &cache_errno);\n \t\tif (new == ce)\n \t\t\tcontinue;\n-- \n1.5.3.rc4.70.gf909\n\n-- \nAlexandre Julliard\njulliard@winehq.org\n"},{"id":"50496","messageId":"7v7io1n8g2.fsf@assigned-by-dhcp.cox.net","threadId":"9486","inReplyTo":"87bqdeweds.fsf@wine.dyndns.org","subject":"Re: [PATCH] git-add: Add a --refresh option.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-08-11T20:05:17Z","receivedAt":"2007-08-11T20:05:17Z","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 refresh only a subset of the project files, based on\n> the specified pathspecs.\n\nMakes sense.  Tests and docs?\n"}]}