tests: fix negated test_i18ngrep calls
[gitweb.git] / tree.c
diff --git a/tree.c b/tree.c
index 62fed632d8a1ade389dd645b5887155c21ae25ba..bb02c1caa4ff6a8af40b89498de3af3381272999 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -47,7 +47,7 @@ static int read_one_entry_quick(const unsigned char *sha1, const char *base, int
 }
 
 static int read_tree_1(struct tree *tree, struct strbuf *base,
-                      int stage, struct pathspec *pathspec,
+                      int stage, const struct pathspec *pathspec,
                       read_tree_fn_t fn, void *context)
 {
        struct tree_desc desc;
@@ -116,7 +116,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
 
 int read_tree_recursive(struct tree *tree,
                        const char *base, int baselen,
-                       int stage, struct pathspec *pathspec,
+                       int stage, const struct pathspec *pathspec,
                        read_tree_fn_t fn, void *context)
 {
        struct strbuf sb = STRBUF_INIT;
@@ -159,7 +159,7 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match)
         * sort at the end.
         */
        for (i = 0; !fn && i < active_nr; i++) {
-               struct cache_entry *ce = active_cache[i];
+               const struct cache_entry *ce = active_cache[i];
                if (ce_stage(ce) == stage)
                        fn = read_one_entry;
        }
@@ -183,15 +183,8 @@ struct tree *lookup_tree(const unsigned char *sha1)
 {
        struct object *obj = lookup_object(sha1);
        if (!obj)
-               return create_object(sha1, OBJ_TREE, alloc_tree_node());
-       if (!obj->type)
-               obj->type = OBJ_TREE;
-       if (obj->type != OBJ_TREE) {
-               error("Object %s is a %s, not a tree",
-                     sha1_to_hex(sha1), typename(obj->type));
-               return NULL;
-       }
-       return (struct tree *) obj;
+               return create_object(sha1, alloc_tree_node());
+       return object_as_type(obj, OBJ_TREE, 0);
 }
 
 int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
@@ -225,6 +218,14 @@ int parse_tree(struct tree *item)
        return parse_tree_buffer(item, buffer, size);
 }
 
+void free_tree_buffer(struct tree *tree)
+{
+       free(tree->buffer);
+       tree->buffer = NULL;
+       tree->size = 0;
+       tree->object.parsed = 0;
+}
+
 struct tree *parse_tree_indirect(const unsigned char *sha1)
 {
        struct object *obj = parse_object(sha1);