Merge branch 'lt/commit-tree-guess-utf-8'
[gitweb.git] / builtin / commit-tree.c
index b9c331225f0d5c960e9e03f2c92d498f8f01f74c..eac901a0ee15f72eacffea32d1b327c7a336f19c 100644 (file)
@@ -8,8 +8,9 @@
 #include "tree.h"
 #include "builtin.h"
 #include "utf8.h"
+#include "gpg-interface.h"
 
-static const char commit_tree_usage[] = "git commit-tree [(-p <sha1>)...] [-m <message>] [-F <file>] <sha1> <changelog";
+static const char commit_tree_usage[] = "git commit-tree [(-p <sha1>)...] [-S<signer>] [-m <message>] [-F <file>] <sha1> <changelog";
 
 static void new_parent(struct commit *parent, struct commit_list **parents_p)
 {
@@ -25,6 +26,14 @@ static void new_parent(struct commit *parent, struct commit_list **parents_p)
        commit_list_insert(parent, parents_p);
 }
 
+static int commit_tree_config(const char *var, const char *value, void *cb)
+{
+       int status = git_gpg_config(var, value, NULL);
+       if (status)
+               return status;
+       return git_default_config(var, value, cb);
+}
+
 int cmd_commit_tree(int argc, const char **argv, const char *prefix)
 {
        int i, got_tree = 0;
@@ -32,8 +41,9 @@ 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;
+       const char *sign_commit = NULL;
 
-       git_config(git_default_config, NULL);
+       git_config(commit_tree_config, NULL);
 
        if (argc < 2 || !strcmp(argv[1], "-h"))
                usage(commit_tree_usage);
@@ -44,13 +54,18 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
                        unsigned char sha1[20];
                        if (argc <= ++i)
                                usage(commit_tree_usage);
-                       if (get_sha1(argv[i], sha1))
+                       if (get_sha1_commit(argv[i], sha1))
                                die("Not a valid object name %s", argv[i]);
                        assert_sha1_type(sha1, OBJ_COMMIT);
                        new_parent(lookup_commit(sha1), &parents);
                        continue;
                }
 
+               if (!memcmp(arg, "-S", 2)) {
+                       sign_commit = arg + 2;
+                       continue;
+               }
+
                if (!strcmp(arg, "-m")) {
                        if (argc <= ++i)
                                usage(commit_tree_usage);
@@ -86,7 +101,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
                        continue;
                }
 
-               if (get_sha1(arg, tree_sha1))
+               if (get_sha1_tree(arg, tree_sha1))
                        die("Not a valid object name %s", arg);
                if (got_tree)
                        die("Cannot give more than one trees");
@@ -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(&buffer, tree_sha1, parents, commit_sha1,
+                       NULL, sign_commit)) {
                strbuf_release(&buffer);
                return 1;
        }