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

[PATCH 13/16] Update commit_tree() interface to take base tree too

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jul 31, 2010, 16:18 UTC
Message-ID
<1280593105-22015-14-git-send-email-pclouds@gmail.com>
In-Reply-To
<1280593105-22015-1-git-send-email-pclouds@gmail.com>

In subtree mode, you work on a narrowed trees. You make narrowed commits. If you want to push upstream, you would need to put your updated subtree back to the full tree again. Otherwise upstream would complain you delete all trees but your subtree, not good.

In order to do that, commit_tree() now takes the base tree SHA-1. With that, it can create upstream-compatible commits. It does not now, though.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/commit-tree.c |    2 +-
 builtin/commit.c      |    2 +-
 builtin/merge.c       |    4 ++--
 builtin/notes.c       |    2 +-
 commit.c              |    2 +-
 commit.h              |    2 +-
 notes-cache.c         |    2 +-
 7 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index 87f0591..88a6833 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -56,7 +56,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
 	if (strbuf_read(&buffer, 0, 0) < 0)
 		die_errno("git commit-tree: failed to read");
 
-	if (!commit_tree(buffer.buf, tree_sha1, parents, commit_sha1, NULL)) {
+	if (!commit_tree(buffer.buf, tree_sha1, NULL, parents, commit_sha1, NULL)) {
 		printf("%s\n", sha1_to_hex(commit_sha1));
 		return 0;
 	}
diff --git a/builtin/commit.c b/builtin/commit.c
index 2bb30c0..6b4c678 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1350,7 +1350,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		exit(1);
 	}
 
-	if (commit_tree(sb.buf, active_cache_tree->sha1, parents, commit_sha1,
+	if (commit_tree(sb.buf, active_cache_tree->sha1, NULL, parents, commit_sha1,
 			fmt_ident(author_name, author_email, author_date,
 				IDENT_ERROR_ON_NO_NAME))) {
 		rollback_index_files();
diff --git a/builtin/merge.c b/builtin/merge.c
index 37ce4f5..8745b54 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -779,7 +779,7 @@ static int merge_trivial(void)
 	parent->next = xmalloc(sizeof(*parent->next));
 	parent->next->item = remoteheads->item;
 	parent->next->next = NULL;
-	commit_tree(merge_msg.buf, result_tree, parent, result_commit, NULL);
+	commit_tree(merge_msg.buf, result_tree, NULL, parent, result_commit, NULL);
 	finish(result_commit, "In-index merge");
 	drop_save();
 	return 0;
@@ -808,7 +808,7 @@ static int finish_automerge(struct commit_list *common,
 	}
 	free_commit_list(remoteheads);
 	strbuf_addch(&merge_msg, '\n');
-	commit_tree(merge_msg.buf, result_tree, parents, result_commit, NULL);
+	commit_tree(merge_msg.buf, result_tree, NULL, parents, result_commit, NULL);
 	strbuf_addf(&buf, "Merge made by %s.", wt_strategy);
 	finish(result_commit, buf.buf);
 	strbuf_release(&buf);
diff --git a/builtin/notes.c b/builtin/notes.c
index 190005f..8d574eb 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -303,7 +303,7 @@ int commit_notes(struct notes_tree *t, const char *msg)
 		hashclr(prev_commit);
 		parent = NULL;
 	}
-	if (commit_tree(buf.buf + 7, tree_sha1, parent, new_commit, NULL))
+	if (commit_tree(buf.buf + 7, tree_sha1, NULL, parent, new_commit, NULL))
 		die("Failed to commit notes tree to database");
 
 	/* Update notes ref with new commit */
diff --git a/commit.c b/commit.c
index d1e30b2..7121631 100644
--- a/commit.c
+++ b/commit.c
@@ -811,7 +811,7 @@ static const char commit_utf8_warn[] =
 "You may want to amend it after fixing the message, or set the config\n"
 "variable i18n.commitencoding to the encoding your project uses.\n";
 
-int commit_tree(const char *msg, unsigned char *tree,
+int commit_tree(const char *msg, unsigned char *tree, unsigned char *base_tree,
 		struct commit_list *parents, unsigned char *ret,
 		const char *author)
 {
diff --git a/commit.h b/commit.h
index d8c01ea..7c34368 100644
--- a/commit.h
+++ b/commit.h
@@ -166,7 +166,7 @@ static inline int single_parent(struct commit *commit)
 
 struct commit_list *reduce_heads(struct commit_list *heads);
 
-extern int commit_tree(const char *msg, unsigned char *tree,
+extern int commit_tree(const char *msg, unsigned char *tree, unsigned char *base_tree,
 		struct commit_list *parents, unsigned char *ret,
 		const char *author);
 
diff --git a/notes-cache.c b/notes-cache.c
index dee6d62..96afb25 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -56,7 +56,7 @@ int notes_cache_write(struct notes_cache *c)
 
 	if (write_notes_tree(&c->tree, tree_sha1))
 		return -1;
-	if (commit_tree(c->validity, tree_sha1, NULL, commit_sha1, NULL) < 0)
+	if (commit_tree(c->validity, tree_sha1, NULL, NULL, commit_sha1, NULL) < 0)
 		return -1;
 	if (update_ref("update notes cache", c->tree.ref, commit_sha1, NULL,
 		       0, QUIET_ON_ERR) < 0)
-- 
1.7.1.rc1.69.g24c2f7
Previous: Elijah NewrenNext: Nguyễn Thái Ngọc Duy
Message 24 of 33 in “Subtree clone proof of concept”
  1. 00/16 Subtree clone proof of conceptNguyễn Thái Ngọc Duy, Jul 31, 2010
  2. 01/16 Add core.subtreeNguyễn Thái Ngọc Duy, Jul 31, 2010
  3. 02/16 list-objects: limit traversing within the given subtree if core.subtree is setNguyễn Thái Ngọc Duy, Jul 31, 2010
  4. Ævar Arnfjörð BjarmasonAug 1, 2010
  5. Nguyen Thai Ngoc DuyAug 1, 2010
  6. Elijah NewrenAug 2, 2010
  7. Nguyen Thai Ngoc DuyAug 2, 2010
  8. 03/16 parse_object: keep sha1 even when parsing replaced oneNguyễn Thái Ngọc Duy, Jul 31, 2010
  9. 04/16 Allow to invalidate a commit in in-memory object storeNguyễn Thái Ngọc Duy, Jul 31, 2010
  10. 05/16 Hook up replace-object to allow bulk commit replacementNguyễn Thái Ngọc Duy, Jul 31, 2010
  11. Junio C HamanoAug 2, 2010
  12. Nguyen Thai Ngoc DuyAug 2, 2010
  13. 06/16 upload-pack: use a separate variable to control whether internal rev-list is usedNguyễn Thái Ngọc Duy, Jul 31, 2010
  14. Elijah NewrenAug 2, 2010
  15. 07/16 upload-pack: support subtree packNguyễn Thái Ngọc Duy, Jul 31, 2010
  16. Elijah NewrenAug 2, 2010
  17. 08/16 fetch-pack: support --subtreeNguyễn Thái Ngọc Duy, Jul 31, 2010
  18. 09/16 subtree: rewrite incoming commitsNguyễn Thái Ngọc Duy, Jul 31, 2010
  19. Elijah NewrenAug 2, 2010
  20. 10/16 clone: support subtree clone with parameter --subtreeNguyễn Thái Ngọc Duy, Jul 31, 2010
  21. 11/16 pack-objects: add --subtree (for pushing)Nguyễn Thái Ngọc Duy, Jul 31, 2010
  22. 12/16 subtree: rewriting outgoing commitsNguyễn Thái Ngọc Duy, Jul 31, 2010
  23. Elijah NewrenAug 2, 2010
  24. 13/16 Update commit_tree() interface to take base tree tooNguyễn Thái Ngọc Duy, Jul 31, 2010
  25. 14/16 commit_tree(): rewriting/replacing new commitsNguyễn Thái Ngọc Duy, Jul 31, 2010
  26. 15/16 commit: rewrite outgoing commitsNguyễn Thái Ngọc Duy, Jul 31, 2010
  27. 16/16 do not use thin packs and subtree together (just a bad feeling about this)Nguyễn Thái Ngọc Duy, Jul 31, 2010
  28. Sverre RabbelierAug 1, 2010
  29. Nguyen Thai Ngoc DuyAug 1, 2010
  30. Sverre RabbelierAug 1, 2010
  31. Elijah NewrenAug 2, 2010
  32. Nguyen Thai Ngoc DuyAug 2, 2010
  33. Nguyen Thai Ngoc DuyAug 2, 2010

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.