Re: [PATCH] cherry-pick/revert: transparently refresh index
From: Nguyen Thai Ngoc Duy <hidden>
Date: 2016-06-15 22:49:57
Subsystem:
the rest · Maintainer:
Linus Torvalds
+static void read_and_refresh_cache(const char *me)
+{
+ static struct lock_file index_lock;
+ int index_fd = hold_locked_index(&index_lock, 0);
+ if (read_index_preload(&the_index, NULL) < 0)
+ die("git %s: failed to read the index", me);
+ refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL);Can we refresh only index entries that are cherry-picked/reverted? Full refresh can be expensive on large repos while these operations don't usually touch the whole repo. I'm thinking of adding ce_really_uptodate() and converting most of ce_uptodate() call sites to the new one.
diff --git a/cache.h b/cache.h
index 123dd4b..81dc5cf 100644
--- a/cache.h
+++ b/cache.h@@ -240,6 +240,7 @@ static inline size_t ce_namelen(const structcache_entry *ce) ondisk_cache_entry_size(ce_namelen(ce))) #define ce_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT) #define ce_uptodate(ce) ((ce)->ce_flags & CE_UPTODATE) +#define ce_really_uptodate(ce) (ce_uptodate(ce) || (refresh_cache_entry(ce), ce_uptodate(ce))) #define ce_skip_worktree(ce) ((ce)->ce_flags & CE_SKIP_WORKTREE) #define ce_mark_uptodate(ce) ((ce)->ce_flags |= CE_UPTODATE)
@@ -512,6 +513,7 @@ extern void fill_stat_cache_info(structcache_entry *ce, struct stat *st);
#define REFRESH_IGNORE_SUBMODULES 0x0010 /* ignore submodules */
#define REFRESH_IN_PORCELAIN 0x0020 /* user friendly output, not
"needs update" */
extern int refresh_index(struct index_state *, unsigned int flags,
const char **pathspec, char *seen, char *header_msg);
+extern struct cache_entry *refresh_cache_entry(struct cache_entry
*ce, int really);
struct lock_file {
struct lock_file *next;diff --git a/read-cache.c b/read-cache.c
index 1f42473..76525a9 100644
--- a/read-cache.c
+++ b/read-cache.c@@ -1156,7 +1156,7 @@ int refresh_index(struct index_state *istate,unsigned int flags, const char **p
return has_errors;
}
-static struct cache_entry *refresh_cache_entry(struct cache_entry
*ce, int really)
+struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really)
{
return refresh_cache_ent(&the_index, ce, really, NULL);
}
--
Duy