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

[PATCH 3/3] commit-tree: teach -x <extra>

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 9, 2011, 21:01 UTC
Message-ID
<1320872495-7545-4-git-send-email-gitster@pobox.com>
In-Reply-To
<1320872495-7545-1-git-send-email-gitster@pobox.com>

By feeding the header part of the original commit with this parameter, e.g. -x "$(git cat-file commit $commit | sed -n -e /^$/q -e p)", extra headers of another commit can be transplanted to the resulting commit.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/git-commit-tree.txt |    3 ++-
 builtin/commit-tree.c             |   20 ++++++++++++++++++--
 2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-commit-tree.txt b/Documentation/git-commit-tree.txt
index cfb9906..060e79d 100644
--- a/Documentation/git-commit-tree.txt
+++ b/Documentation/git-commit-tree.txt
@@ -10,7 +10,8 @@ SYNOPSIS
 --------
 [verse]
 'git commit-tree' <tree> [(-p <parent>)...] < changelog
-'git commit-tree' [(-p <parent>)...] [(-m <message>)...] [(-F <file>)...] <tree>
+'git commit-tree' [(-p <parent>)...] [(-m <message>)...] [(-F <file>)...]
+    [(-x <extra>)...]<tree>
 
 DESCRIPTION
 -----------
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index db5b6e5..8b0a223 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -9,7 +9,7 @@
 #include "builtin.h"
 #include "utf8.h"
 
-static const char commit_tree_usage[] = "git commit-tree [(-p <sha1>)...] [-m <message>] <sha1> < changelog";
+static const char commit_tree_usage[] = "git commit-tree [(-p <sha1>)...] [-m <message>] [-x <extra>] <sha1> < changelog";
 
 static void new_parent(struct commit *parent, struct commit_list **parents_p)
 {
@@ -32,6 +32,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
 	unsigned char tree_sha1[20];
 	unsigned char commit_sha1[20];
 	struct strbuf buffer = STRBUF_INIT;
+	struct commit_extra_header *extra = NULL, **extra_tail = &extra;
 
 	git_config(git_default_config, NULL);
 
@@ -86,6 +87,20 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
 			continue;
 		}
 
+		if (!strcmp(arg, "-x")) {
+			struct commit_extra_header *x;
+			if (argc <= ++i)
+				usage(commit_tree_usage);
+			x = read_commit_extra_header_lines(argv[i], strlen(argv[i]));
+			if (x) {
+				*extra_tail = x;
+				while (x->next)
+					x = x->next;
+				extra_tail = &x->next;
+			}
+			continue;
+		}
+
 		if (get_sha1(arg, tree_sha1))
 			die("Not a valid object name %s", arg);
 		if (got_tree)
@@ -98,7 +113,8 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
 			die_errno("git commit-tree: failed to read");
 	}
 
-	if (commit_tree(buffer.buf, tree_sha1, parents, commit_sha1, NULL)) {
+	if (commit_tree_extended(buffer.buf, tree_sha1, parents, commit_sha1,
+				 NULL, extra)) {
 		strbuf_release(&buffer);
 		return 1;
 	}
-- 
1.7.8.rc1.82.gde0f9
Previous: Junio C HamanoNext: Brad King
Message 4 of 5 in “commit-tree updates”
  1. 0/3 commit-tree updatesJunio C Hamano, Nov 9, 2011
  2. 1/3 commit-tree: update the command line parsingJunio C Hamano, Nov 9, 2011
  3. 2/3 commit-tree: teach -m/-F options to read logs from elsewhereJunio C Hamano, Nov 9, 2011
  4. 3/3 commit-tree: teach -x <extra>Junio C Hamano, Nov 9, 2011
  5. Brad KingNov 9, 2011

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.