git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 1/6] sequencer: extract helper to update active_cache_tree

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
May 3, 2018, 23:01 UTC
Message-ID
<ad31aab8e735f7de813860cacb32abbc406f43d1.1525388472.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1525388472.git.johannes.schindelin@gmx.de>

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>
---
 sequencer.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/sequencer.c b/sequencer.c
index e2f83942843..90c8218aa9a 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)
-- 
2.17.0.windows.1.38.g05ca542f78d
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 15 of 22 in “Let the sequencer handle `git rebase -i --root`”
  1. 0/6 Let the sequencer handle `git rebase -i --root`Johannes Schindelin, Apr 27, 2018
  2. 1/6 sequencer: extract helper to update active_cache_treeJohannes Schindelin, Apr 27, 2018
  3. Stefan BellerApr 28, 2018
  4. 2/6 sequencer: learn about the special "fake root commit" handlingJohannes Schindelin, Apr 27, 2018
  5. Stefan BellerApr 28, 2018
  6. Johannes SchindelinApr 29, 2018
  7. Stefan BellerApr 29, 2018
  8. 3/6 rebase -i --root: let the sequencer handle even the initial partJohannes Schindelin, Apr 27, 2018
  9. Stefan BellerApr 28, 2018
  10. Johannes SchindelinApr 29, 2018
  11. 4/6 sequencer: allow introducing new root commitsJohannes Schindelin, Apr 27, 2018
  12. 5/6 rebase --rebase-merges: a "merge" into a new root is a fast-forwardJohannes Schindelin, Apr 27, 2018
  13. 6/6 rebase --rebase-merges: root commits can be cousins, tooJohannes Schindelin, Apr 27, 2018
  14. 0/6 Let the sequencer handle `git rebase -i --root`Johannes Schindelin, May 3, 2018
  15. 1/6 sequencer: extract helper to update active_cache_treeJohannes Schindelin, May 3, 2018
  16. 3/6 rebase -i --root: let the sequencer handle even the initial partJohannes Schindelin, May 3, 2018
  17. 2/6 sequencer: learn about the special "fake root commit" handlingJohannes Schindelin, May 3, 2018
  18. 5/6 rebase --rebase-merges: a "merge" into a new root is a fast-forwardJohannes Schindelin, May 3, 2018
  19. 6/6 rebase --rebase-merges: root commits can be cousins, tooJohannes Schindelin, May 3, 2018
  20. 4/6 sequencer: allow introducing new root commitsJohannes Schindelin, May 3, 2018
  21. Stefan BellerMay 4, 2018
  22. Johannes SchindelinMay 5, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.