{"thread":{"id":"9494","subject":"[PATCH] git-add: Add support for --refresh option.","startedAt":"2007-08-11T21:59:01Z","lastAt":"2007-08-12T01:55:56Z","messageCount":2,"participants":["Alexandre Julliard","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"50508","messageId":"874pj5wx5m.fsf@wine.dyndns.org","threadId":"9494","inReplyTo":null,"subject":"[PATCH] git-add: Add support for --refresh option.","fromName":"Alexandre Julliard","fromEmail":"julliard@winehq.org","sentAt":"2007-08-11T21:59:01Z","receivedAt":"2007-08-11T21:59:01Z","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\nThis time with test and docs...\n\n Documentation/git-add.txt |    6 +++++-\n builtin-add.c             |   28 +++++++++++++++++++++++++++-\n cache.h                   |    4 ++--\n read-cache.c              |    6 +++++-\n t/t3700-add.sh            |   12 ++++++++++++\n 5 files changed, 51 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-add.txt b/Documentation/git-add.txt\nindex 4af3a9b..dee38f8 100644\n--- a/Documentation/git-add.txt\n+++ b/Documentation/git-add.txt\n@@ -7,7 +7,7 @@ git-add - Add file contents to the index\n \n SYNOPSIS\n --------\n-'git-add' [-n] [-v] [-f] [--interactive | -i] [-u] [--] <file>...\n+'git-add' [-n] [-v] [-f] [--interactive | -i] [-u] [--refresh] [--] <file>...\n \n DESCRIPTION\n -----------\n@@ -66,6 +66,10 @@ OPTIONS\n \tcommand line. If no paths are specified, all tracked files are\n \tupdated.\n \n+\\--refresh::\n+\tDon't add the file(s), but only refresh their stat()\n+\tinformation in the index.\n+\n \\--::\n \tThis option can be used to separate command-line options from\n \tthe list of files, (useful when filenames might be mistaken\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;\ndiff --git a/t/t3700-add.sh b/t/t3700-add.sh\nindex 213e924..a328bf5 100755\n--- a/t/t3700-add.sh\n+++ b/t/t3700-add.sh\n@@ -143,4 +143,16 @@ test_expect_success 'git add with filemode=0, symlinks=0 prefers stage 2 over st\n \tgit ls-files --stage | grep \"^120000 .* 0\tsymlink$\"\n '\n \n+test_expect_success 'git add --refresh' '\n+\t>foo && git add foo && git commit -a -m \"commit all\" &&\n+\ttest -z \"`git diff-index HEAD -- foo`\" &&\n+\tgit read-tree HEAD &&\n+\tcase \"`git diff-index HEAD -- foo`\" in\n+\t:100644\" \"*\"M\tfoo\") echo ok;;\n+\t*) echo fail; (exit 1);;\n+\tesac &&\n+\tgit add --refresh -- foo &&\n+\ttest -z \"`git diff-index HEAD -- foo`\"\n+'\n+\n test_done\n-- \n1.5.3.rc4.70.gf909\n\n-- \nAlexandre Julliard\njulliard@winehq.org\n"},{"id":"50531","messageId":"7vr6m9jz2r.fsf@assigned-by-dhcp.cox.net","threadId":"9494","inReplyTo":"874pj5wx5m.fsf@wine.dyndns.org","subject":"Re: [PATCH] git-add: Add support for --refresh option.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-08-12T01:55:56Z","receivedAt":"2007-08-12T01:55:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks.\n"}]}