Merge branch 'sb/submodule-blanket-recursive'
[gitweb.git] / builtin / read-tree.c
index 7fd55140db6423f77237bed70b53a6acd4ef7064..5bfd4c9f76d84c177b72a8ed97d3418d111583e9 100644 (file)
@@ -22,13 +22,13 @@ static int nr_trees;
 static int read_empty;
 static struct tree *trees[MAX_UNPACK_TREES];
 
-static int list_tree(unsigned char *sha1)
+static int list_tree(struct object_id *oid)
 {
        struct tree *tree;
 
        if (nr_trees >= MAX_UNPACK_TREES)
                die("I cannot read more than %d trees", MAX_UNPACK_TREES);
-       tree = parse_tree_indirect(sha1);
+       tree = parse_tree_indirect(oid);
        if (!tree)
                return -1;
        trees[nr_trees++] = tree;
@@ -111,7 +111,7 @@ static struct lock_file lock_file;
 int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
 {
        int i, stage = 0;
-       unsigned char sha1[20];
+       struct object_id oid;
        struct tree_desc t[MAX_UNPACK_TREES];
        struct unpack_trees_options opts;
        int prefix_set = 0;
@@ -190,13 +190,13 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
        for (i = 0; i < argc; i++) {
                const char *arg = argv[i];
 
-               if (get_sha1(arg, sha1))
+               if (get_oid(arg, &oid))
                        die("Not a valid object name %s", arg);
-               if (list_tree(sha1) < 0)
+               if (list_tree(&oid) < 0)
                        die("failed to unpack tree object %s", arg);
                stage++;
        }
-       if (nr_trees == 0 && !read_empty)
+       if (!nr_trees && !read_empty && !opts.merge)
                warning("read-tree: emptying the index with no arguments is deprecated; use --empty");
        else if (nr_trees > 0 && read_empty)
                die("passing trees as arguments contradicts --empty");
@@ -212,9 +212,10 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
                setup_work_tree();
 
        if (opts.merge) {
-               if (stage < 2)
-                       die("just how do you expect me to merge %d trees?", stage-1);
                switch (stage - 1) {
+               case 0:
+                       die("you must specify at least one tree to merge");
+                       break;
                case 1:
                        opts.fn = opts.prefix ? bind_merge : oneway_merge;
                        break;