revision.c: explain what tree_difference does
[gitweb.git] / tree-diff.c
index 7e2f4f088a359fe138b085730ba1b3465342e9e9..44cde74caf20ded9cd196c4e5d16f4d9ba251a22 100644 (file)
@@ -139,13 +139,13 @@ static void show_entry(struct diff_options *opt, const char *prefix, struct tree
        const unsigned char *sha1 = tree_entry_extract(desc, &path, &mode);
 
        if (opt->recursive && S_ISDIR(mode)) {
-               char type[20];
+               enum object_type type;
                char *newbase = malloc_base(base, path, strlen(path));
                struct tree_desc inner;
                void *tree;
 
-               tree = read_sha1_file(sha1, type, &inner.size);
-               if (!tree || strcmp(type, tree_type))
+               tree = read_sha1_file(sha1, &type, &inner.size);
+               if (!tree || type != OBJ_TREE)
                        die("corrupt tree sha %s", sha1_to_hex(sha1));
 
                inner.buf = tree;
@@ -161,6 +161,8 @@ static void show_entry(struct diff_options *opt, const char *prefix, struct tree
 int diff_tree(struct tree_desc *t1, struct tree_desc *t2, const char *base, struct diff_options *opt)
 {
        while (t1->size | t2->size) {
+               if (opt->quiet && opt->has_changes)
+                       break;
                if (opt->nr_paths && t1->size && !interesting(t1, base, opt)) {
                        update_tree_entry(t1);
                        continue;
@@ -215,6 +217,24 @@ int diff_tree_sha1(const unsigned char *old, const unsigned char *new, const cha
        return retval;
 }
 
+int diff_root_tree_sha1(const unsigned char *new, const char *base, struct diff_options *opt)
+{
+       int retval;
+       void *tree;
+       struct tree_desc empty, real;
+
+       tree = read_object_with_reference(new, tree_type, &real.size, NULL);
+       if (!tree)
+               die("unable to read root tree (%s)", sha1_to_hex(new));
+       real.buf = tree;
+
+       empty.size = 0;
+       empty.buf = "";
+       retval = diff_tree(&empty, &real, base, opt);
+       free(tree);
+       return retval;
+}
+
 static int count_paths(const char **paths)
 {
        int i = 0;