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>

Johannes Schindelin committed May 4, 2018 at 01:01 UTC ba97aea1659e249a3a58ecc5f583ee2056a90ad8
1 file changed +18 -9
sequencer.c
+18 -9
@@ -562,9 +562,23 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
562 return !clean;
563 }
564
565 +static struct object_id *get_cache_tree_oid(void)
566 +{
567 + if (!active_cache_tree)
568 + active_cache_tree = cache_tree();
569 +
570 + if (!cache_tree_fully_valid(active_cache_tree))
571 + if (cache_tree_update(&the_index, 0)) {
572 + error(_("unable to update cache tree"));
573 + return NULL;
574 + }
575 +
576 + return &active_cache_tree->oid;
577 +}
578 +
579 static int is_index_unchanged(void)
580 {
567 - struct object_id head_oid;
581 + struct object_id head_oid, *cache_tree_oid;
582 struct commit *head_commit;
583
584 if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
@@ -583,15 +597,10 @@ static int is_index_unchanged(void)
597 if (parse_commit(head_commit))
598 return -1;
599
586 - if (!active_cache_tree)
587 - active_cache_tree = cache_tree();
588 -
589 - if (!cache_tree_fully_valid(active_cache_tree))
590 - if (cache_tree_update(&the_index, 0))
591 - return error(_("unable to update cache tree"));
600 + if (!(cache_tree_oid = get_cache_tree_oid()))
601 + return -1;
602
593 - return !oidcmp(&active_cache_tree->oid,
594 - &head_commit->tree->object.oid);
603 + return !oidcmp(cache_tree_oid, &head_commit->tree->object.oid);
604 }
605
606 static int write_author_script(const char *message)