update-index: Add a --refresh-only option to refresh specified files.
This allows to quickly refresh a file that has been touched without having to stat all the files of the project.
---
Does this look reasonable? The refresh_index_path() function is a copy/paste of refresh_index(), I'm not sure all of it is really needed, but I don't claim to understand all the subtleties of the index management...
builtin-update-index.c | 17 +++++++++++++-- cache.h | 1 + read-cache.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 3 deletions(-)
builtin-update-index.c +14 -3
@@ -22,6 +22,7 @@ static int allow_add;static int allow_remove;static int allow_replace;static int info_only; +static int refresh_only;static int force_remove;static int verbose;static int mark_valid_only;
@@ -266,8 +267,9 @@ static void chmod_path(int flip, const char *path)die ("git-update-index: cannot chmod %cx '%s'" , flip, path); } -static void update_one (const char *path,const char *prefix,int prefix_length) +static int update_one (const char *path,const char *prefix,int prefix_length) { +int has_errors =0 ;const char *p =prefix_path (prefix, prefix_length, path);if (!verify_path (p)) {fprintf (stderr,"Ignoring path %s\n" , path);
@@ -278,6 +280,10 @@ static void update_one(const char *path, const char *prefix, int prefix_length)die ("Unable to mark file %s" , path); goto free_return; } +if (refresh_only) { + has_errors |=refresh_index_path (&the_index,0 , path); + goto free_return; + }cache_tree_invalidate_path (active_cache_tree, path);if (force_remove) {
@@ -292,6 +298,7 @@ static void update_one(const char *path, const char *prefix, int prefix_length) free_return:if (p < path || p > path +strlen (path))free ((char *)p); +return has_errors; }static void read_index_info (int line_termination)
@@ -620,6 +627,10 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) has_errors |=refresh_cache (REFRESH_REALLY | refresh_flags);continue ; } +if (!strcmp (path,"--refresh-only" )) { + refresh_only =1 ; +continue ; + }if (!strcmp (path,"--cacheinfo" )) {unsigned char sha1[20 ];unsigned int mode;
@@ -702,7 +713,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)die ("unknown option %s" , path); } p =prefix_path (prefix, prefix_length, path); -update_one (p,NULL ,0 ); + has_errors |=update_one (p,NULL ,0 );if (set_executable_bit)chmod_path (set_executable_bit, p);if (p < path || p > path +strlen (path))
@@ -722,7 +733,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)else path_name = buf.buf; p =prefix_path (prefix, prefix_length, path_name); -update_one (p,NULL ,0 ); + has_errors |=update_one (p,NULL ,0 );if (set_executable_bit)chmod_path (set_executable_bit, p);if (p < path_name || p > path_name +strlen (path_name))
cache.h +1 -0
@@ -278,6 +278,7 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);#define REFRESH_QUIET 0x0004/* be quiet about it */ #define REFRESH_IGNORE_MISSING 0x0008/* ignore non-existent */ extern int refresh_index (struct index_state *,unsigned int flags); +extern int refresh_index_path (struct index_state *istate,unsigned int flags,const char *path);struct lock_file {struct lock_file *next;
read-cache.c +49 -0
55 lines not on this page · raw message
Signature · 5 lines
1.5.3.rc4 -- Alexandre Julliard [email protected]
Quoted 10 lines · Alexandre Julliard
This allows to quickly refresh a file that has been touched without having to stat all the files of the project.
Signed-off-by Alexandre Julliard <[email protected]>---
Does this look reasonable? The
refresh_index_path()function is a copy/paste ofrefresh_index(), I'm not sure all of it is really needed, but I don't claim to understand all the subtleties of the index management...
Makes me wonder why it is not like:
$ git update-index --refresh Documentation/
That is:
- why a new option?
- why not a pathspec or glob, similar to what ls-files gets?
Quoted 7 lines · Junio C Hamano
Makes me wonder why it is not like:
$ git update-index --refresh Documentation/That is:
- why a new option?
It was to avoid breaking backwards compatibility, since passing files with --refresh currently has a different meaning. But if you think we can change that, then sure, it would be much nicer.
Quoted 1 line
- why not a pathspec or glob, similar to what ls-files gets?
I'm not sure, would this really belong in update-index since it currently always requires explicit pathnames? Or should it be in a higher-level command like git-add --refresh?
Signature · 2 lines
Alexandre Julliard [email protected]