diff options
author | Johannes Schindelin <johannes.schindelin@gmx.de> | 2018-05-03 23:01:15 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-05-06 04:21:57 (GMT) |
commit | ba97aea1659e249a3a58ecc5f583ee2056a90ad8 (patch) | |
tree | a80826ae4f3bb204caef2bbff08a0f29e471e628 /sequencer.c | |
parent | 25cff9f109afbd6d21b199a38d15911b1f0c5069 (diff) | |
download | git-ba97aea1659e249a3a58ecc5f583ee2056a90ad8.zip git-ba97aea1659e249a3a58ecc5f583ee2056a90ad8.tar.gz git-ba97aea1659e249a3a58ecc5f583ee2056a90ad8.tar.bz2 |
sequencer: extract helper to update active_cache_tree
This patch extracts the code from is_index_unchanged() to initialize or
update the index' cache tree (i.e. a tree object reflecting the current
index' top-level tree).
The new helper will be used in the upcoming code to support `git rebase
-i --root` via the sequencer.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sequencer.c')
-rw-r--r-- | sequencer.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/sequencer.c b/sequencer.c index e2f8394..90c8218 100644 --- a/sequencer.c +++ b/sequencer.c @@ -562,9 +562,23 @@ static int do_recursive_merge(struct commit *base, struct commit *next, return !clean; } +static struct object_id *get_cache_tree_oid(void) +{ + if (!active_cache_tree) + active_cache_tree = cache_tree(); + + if (!cache_tree_fully_valid(active_cache_tree)) + if (cache_tree_update(&the_index, 0)) { + error(_("unable to update cache tree")); + return NULL; + } + + return &active_cache_tree->oid; +} + static int is_index_unchanged(void) { - struct object_id head_oid; + struct object_id head_oid, *cache_tree_oid; struct commit *head_commit; if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL)) @@ -583,15 +597,10 @@ static int is_index_unchanged(void) if (parse_commit(head_commit)) return -1; - if (!active_cache_tree) - active_cache_tree = cache_tree(); - - if (!cache_tree_fully_valid(active_cache_tree)) - if (cache_tree_update(&the_index, 0)) - return error(_("unable to update cache tree")); + if (!(cache_tree_oid = get_cache_tree_oid())) + return -1; - return !oidcmp(&active_cache_tree->oid, - &head_commit->tree->object.oid); + return !oidcmp(cache_tree_oid, &head_commit->tree->object.oid); } static int write_author_script(const char *message) |