From: Mark Lodato <lodatom@gmail.com>
To: git@vger.kernel.org
Cc: Mark Lodato <lodatom@gmail.com>
Subject: [PATCH/RFC 01/12] commit-tree: allow indirect tree references
Date: Fri, 12 Mar 2010 23:52:53 -0500 [thread overview]
Message-ID: <1268455984-19061-2-git-send-email-lodatom@gmail.com> (raw)
In-Reply-To: <1268455984-19061-1-git-send-email-lodatom@gmail.com>
'git commit-tree' was the last remaining built-in to accept a <tree> but
not a <tree-ish> (an indirect tree reference through a commit or tag
object.)
Signed-off-by: Mark Lodato <lodatom@gmail.com>
---
A similar thing should be done for the parent commits. As far as I can
tell, this is the only command that requires a commit object, not a tag.
Documentation/git-commit-tree.txt | 4 +-
builtin/commit-tree.c | 13 ++++++----
t/t1101-commit-tree-indirect.sh | 49 +++++++++++++++++++++++++++++++++++++
3 files changed, 59 insertions(+), 7 deletions(-)
create mode 100755 t/t1101-commit-tree-indirect.sh
diff --git a/Documentation/git-commit-tree.txt b/Documentation/git-commit-tree.txt
index 6188854..67b6bc0 100644
--- a/Documentation/git-commit-tree.txt
+++ b/Documentation/git-commit-tree.txt
@@ -8,7 +8,7 @@ git-commit-tree - Create a new commit object
SYNOPSIS
--------
-'git commit-tree' <tree> [-p <parent commit>]\* < changelog
+'git commit-tree' <tree-ish> [-p <parent commit>]\* < changelog
DESCRIPTION
-----------
@@ -35,7 +35,7 @@ state was.
OPTIONS
-------
-<tree>::
+<tree-ish>::
An existing tree object
-p <parent commit>::
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index 90dac34..96a421e 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -97,16 +97,19 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
{
int i;
struct commit_list *parents = NULL;
- unsigned char tree_sha1[20];
- unsigned char commit_sha1[20];
+ unsigned char sha1[20];
struct strbuf buffer = STRBUF_INIT;
+ struct tree *tree;
git_config(git_default_config, NULL);
if (argc < 2 || !strcmp(argv[1], "-h"))
usage(commit_tree_usage);
- if (get_sha1(argv[1], tree_sha1))
+ if (get_sha1(argv[1], sha1))
die("Not a valid object name %s", argv[1]);
+ tree = parse_tree_indirect(sha1);
+ if (!tree)
+ die("%s is not a valid 'tree' object", argv[1]);
for (i = 2; i < argc; i += 2) {
unsigned char sha1[20];
@@ -124,8 +127,8 @@ 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)) {
- printf("%s\n", sha1_to_hex(commit_sha1));
+ if (!commit_tree(buffer.buf, tree->object.sha1, parents, sha1, NULL)) {
+ printf("%s\n", sha1_to_hex(sha1));
return 0;
}
else
diff --git a/t/t1101-commit-tree-indirect.sh b/t/t1101-commit-tree-indirect.sh
new file mode 100755
index 0000000..905bad7
--- /dev/null
+++ b/t/t1101-commit-tree-indirect.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+#
+# Copyright (c) 2010 Mark Lodato
+#
+
+test_description='git commit-tree works with indirect references'
+
+. ./test-lib.sh
+
+get_tree() {
+ git cat-file commit $1 | sed -n -e 's/^tree //p'
+}
+
+test_expect_success 'prepare the repository' '
+ touch a &&
+ git add a &&
+ git commit -m x &&
+ git tag -a -m x tag-commit &&
+ git tag -a -m x tag-tree HEAD^{tree} &&
+ git tag -a -m x tag-blob HEAD:a &&
+ git tag -a -m x tag-tag-commit tag-commit
+'
+
+expected_tree="$(get_tree HEAD)"
+
+test_success() {
+ test_expect_success "commit-tree succeeds with $2" '
+ id="$(echo x | git commit-tree '"$1"')" &&
+ tree="$(get_tree $id)" &&
+ test "x$tree" = "x$expected_tree"
+ '
+}
+test_failure() {
+ test_expect_code 128 "commit-tree fails with $2" '
+ echo x | git commit-tree '"$1"' 2>/dev/null
+ '
+}
+
+test_failure HEAD:a "a blob"
+test_success HEAD^{tree} "a tree"
+test_success HEAD "HEAD"
+test_success master "a branch"
+test_failure foo "an invalid object name"
+test_failure tag-blob "a tag pointing to a blob"
+test_success tag-tree "a tag pointing to a tree"
+test_success tag-commit "a tag pointing to a commit"
+test_success tag-tag-commit "a tag pointing to a tag (to a commit)"
+
+test_done
--
1.7.0.2
next prev parent reply other threads:[~2010-03-13 4:53 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-13 4:52 [PATCH/RFC 00/12] docs: use metavariables consistently Mark Lodato
2010-03-13 4:52 ` Mark Lodato [this message]
2010-03-13 21:58 ` [PATCH/RFC 01/12] commit-tree: allow indirect tree references Junio C Hamano
2010-03-16 0:44 ` Mark Lodato
2010-03-13 4:52 ` [PATCH/RFC 02/12] grep docs: grep accepts a <tree-ish>, not a <tree> Mark Lodato
2010-03-13 21:59 ` Junio C Hamano
2010-03-16 0:47 ` Mark Lodato
2010-03-13 4:52 ` [PATCH/RFC 03/12] fsck docs: remove outdated and useless diagnostic Mark Lodato
2010-03-13 4:52 ` [PATCH/RFC 04/12] docs: use <sha1> to mean unabbreviated ID Mark Lodato
2010-03-13 4:52 ` [PATCH/RFC 05/12] docs: differentiate between <tag> and <tagname> Mark Lodato
2010-03-13 21:53 ` Junio C Hamano
2010-03-13 4:52 ` [PATCH/RFC 06/12] docs: clarify <object>, <commit>, <tree-ish>, etc Mark Lodato
2010-03-13 4:52 ` [PATCH/RFC 07/12] docs: use <tree> instead of <tree-ish> Mark Lodato
2010-03-13 4:53 ` [PATCH/RFC 08/12] http-fetch docs: use <commit-id> consistently Mark Lodato
2010-03-13 4:53 ` [PATCH/RFC 09/12] docs: use <commit> instead of <commit-ish> Mark Lodato
2010-03-13 22:05 ` Junio C Hamano
2010-03-16 1:12 ` Mark Lodato
2010-03-13 4:53 ` [PATCH/RFC 10/12] diff: use brackets for optional args in usage Mark Lodato
2010-03-13 4:53 ` [PATCH/RFC 11/12] docs: use ... instead of * for multiplicity Mark Lodato
2010-03-13 4:53 ` [PATCH/RFC 12/12] diff docs: remove <rev>{0,2} notation Mark Lodato
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1268455984-19061-2-git-send-email-lodatom@gmail.com \
--to=lodatom@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).