Skip to content

Commit ba97aea

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 25cff9f commit ba97aea

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

sequencer.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,23 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
562562
return !clean;
563563
}
564564

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+
565579
static int is_index_unchanged(void)
566580
{
567-
struct object_id head_oid;
581+
struct object_id head_oid, *cache_tree_oid;
568582
struct commit *head_commit;
569583

570584
if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, &head_oid, NULL))
@@ -583,15 +597,10 @@ static int is_index_unchanged(void)
583597
if (parse_commit(head_commit))
584598
return -1;
585599

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;
592602

593-
return !oidcmp(&active_cache_tree->oid,
594-
&head_commit->tree->object.oid);
603+
return !oidcmp(cache_tree_oid, &head_commit->tree->object.oid);
595604
}
596605

597606
static int write_author_script(const char *message)

0 commit comments

Comments
 (0)