Skip to content

Commit

Permalink
Merge branch 'jk/free-tree-buffer'
Browse files Browse the repository at this point in the history
* jk/free-tree-buffer:
  clear parsed flag when we free tree buffers
  • Loading branch information
Junio C Hamano committed Sep 17, 2013
2 parents 5e3a3a1 + 6e454b9 commit b8f2311
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 23 deletions.
17 changes: 8 additions & 9 deletions builtin/fsck.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#define REACHABLE 0x0001
#define SEEN 0x0002
#define HAS_OBJ 0x0004

static int show_root;
static int show_tags;
Expand Down Expand Up @@ -101,7 +102,7 @@ static int mark_object(struct object *obj, int type, void *data)
if (obj->flags & REACHABLE)
return 0;
obj->flags |= REACHABLE;
if (!obj->parsed) {
if (!(obj->flags & HAS_OBJ)) {
if (parent && !has_sha1_file(obj->sha1)) {
printf("broken link from %7s %s\n",
typename(parent->type), sha1_to_hex(parent->sha1));
Expand All @@ -127,16 +128,13 @@ static int traverse_one_object(struct object *obj)
struct tree *tree = NULL;

if (obj->type == OBJ_TREE) {
obj->parsed = 0;
tree = (struct tree *)obj;
if (parse_tree(tree) < 0)
return 1; /* error already displayed */
}
result = fsck_walk(obj, mark_object, obj);
if (tree) {
free(tree->buffer);
tree->buffer = NULL;
}
if (tree)
free_tree_buffer(tree);
return result;
}

Expand Down Expand Up @@ -178,7 +176,7 @@ static void check_reachable_object(struct object *obj)
* except if it was in a pack-file and we didn't
* do a full fsck
*/
if (!obj->parsed) {
if (!(obj->flags & HAS_OBJ)) {
if (has_sha1_pack(obj->sha1))
return; /* it is in pack - forget about it */
printf("missing %s %s\n", typename(obj->type), sha1_to_hex(obj->sha1));
Expand Down Expand Up @@ -306,8 +304,7 @@ static int fsck_obj(struct object *obj)
if (obj->type == OBJ_TREE) {
struct tree *item = (struct tree *) obj;

free(item->buffer);
item->buffer = NULL;
free_tree_buffer(item);
}

if (obj->type == OBJ_COMMIT) {
Expand Down Expand Up @@ -340,6 +337,7 @@ static int fsck_sha1(const unsigned char *sha1)
return error("%s: object corrupt or missing",
sha1_to_hex(sha1));
}
obj->flags |= HAS_OBJ;
return fsck_obj(obj);
}

Expand All @@ -352,6 +350,7 @@ static int fsck_obj_buffer(const unsigned char *sha1, enum object_type type,
errors_found |= ERROR_OBJECT;
return error("%s: object corrupt or missing", sha1_to_hex(sha1));
}
obj->flags = HAS_OBJ;
return fsck_obj(obj);
}

Expand Down
1 change: 1 addition & 0 deletions builtin/index-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
if (obj->type == OBJ_TREE) {
struct tree *item = (struct tree *) obj;
item->buffer = NULL;
obj->parsed = 0;
}
if (obj->type == OBJ_COMMIT) {
struct commit *commit = (struct commit *) obj;
Expand Down
3 changes: 1 addition & 2 deletions builtin/reflog.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ static int tree_is_complete(const unsigned char *sha1)
complete = 0;
}
}
free(tree->buffer);
tree->buffer = NULL;
free_tree_buffer(tree);

if (complete)
tree->object.flags |= SEEN;
Expand Down
3 changes: 1 addition & 2 deletions http-push.c
Original file line number Diff line number Diff line change
Expand Up @@ -1330,8 +1330,7 @@ static struct object_list **process_tree(struct tree *tree,
break;
}

free(tree->buffer);
tree->buffer = NULL;
free_tree_buffer(tree);
return p;
}

Expand Down
3 changes: 1 addition & 2 deletions list-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ static void process_tree(struct rev_info *revs,
cb_data);
}
strbuf_setlen(base, baselen);
free(tree->buffer);
tree->buffer = NULL;
free_tree_buffer(tree);
}

static void mark_edge_parents_uninteresting(struct commit *commit,
Expand Down
3 changes: 1 addition & 2 deletions reachable.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ static void process_tree(struct tree *tree,
else
process_blob(lookup_blob(entry.sha1), p, &me, entry.path, cp);
}
free(tree->buffer);
tree->buffer = NULL;
free_tree_buffer(tree);
}

static void process_tag(struct tag *tag, struct object_array *p,
Expand Down
3 changes: 1 addition & 2 deletions revision.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ void mark_tree_uninteresting(struct tree *tree)
* We don't care about the tree any more
* after it has been marked uninteresting.
*/
free(tree->buffer);
tree->buffer = NULL;
free_tree_buffer(tree);
}

void mark_parents_uninteresting(struct commit *commit)
Expand Down
8 changes: 8 additions & 0 deletions tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,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);
Expand Down
1 change: 1 addition & 0 deletions tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct tree *lookup_tree(const unsigned char *sha1);
int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);

int parse_tree(struct tree *tree);
void free_tree_buffer(struct tree *tree);

/* Parses and returns the tree in the given ent, chasing tags and commits. */
struct tree *parse_tree_indirect(const unsigned char *sha1);
Expand Down
5 changes: 1 addition & 4 deletions walker.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ static int process_tree(struct walker *walker, struct tree *tree)
if (!obj || process(walker, obj))
return -1;
}
free(tree->buffer);
tree->buffer = NULL;
tree->size = 0;
tree->object.parsed = 0;
free_tree_buffer(tree);
return 0;
}

Expand Down

0 comments on commit b8f2311

Please sign in to comment.