diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-11-29 17:52:34 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-11-29 17:52:34 -0800 |
commit | 5eee142c89ee4964c9ea4ae1b2fa8344036a7efb (patch) | |
tree | 2d114ae692ac53034a4353e80f44e62598ed1d9a /builtin | |
parent | d7f4809bc5ceaef14420be57aecbdf8280fac81c (diff) | |
parent | f6ce1f25885f3db71935b201c5e3c858eb993f5c (diff) | |
download | git-5eee142c89ee4964c9ea4ae1b2fa8344036a7efb.tar.gz git-5eee142c89ee4964c9ea4ae1b2fa8344036a7efb.tar.xz |
Merge branch 'jn/cherry-pick-refresh-index'
* jn/cherry-pick-refresh-index:
cherry-pick/revert: transparently refresh index
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/revert.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/builtin/revert.c b/builtin/revert.c index 57b51e4a0..bb6e9e83b 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -547,6 +547,21 @@ static void prepare_revs(struct rev_info *revs) die("empty commit set passed"); } +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); + if (the_index.cache_changed) { + if (write_index(&the_index, index_fd) || + commit_locked_index(&index_lock)) + die("git %s: failed to refresh the index", me); + } + rollback_lock_file(&index_lock); +} + static int revert_or_cherry_pick(int argc, const char **argv) { struct rev_info revs; @@ -567,8 +582,7 @@ static int revert_or_cherry_pick(int argc, const char **argv) die("cherry-pick --ff cannot be used with --edit"); } - if (read_cache() < 0) - die("git %s: failed to read the index", me); + read_and_refresh_cache(me); prepare_revs(&revs); |