summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
7d65848)
This allows us to avoid allocating information for names etc, because
we can just use the information from the tree buffer directly.
We still keep the old "tree_entry_list" in struct tree as well, so old
users aren't affected, apart from the fact that the allocations are
different (if you free a tree entry, you should no longer free the name
allocation for it, since it's allocated as part of "tree->buffer")
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
typedef int (*merge_fn_t)(struct cache_entry **src);
typedef int (*merge_fn_t)(struct cache_entry **src);
-static int entcmp(char *name1, int dir1, char *name2, int dir2)
+static int entcmp(const char *name1, int dir1, const char *name2, int dir2)
{
int len1 = strlen(name1);
int len2 = strlen(name2);
{
int len1 = strlen(name1);
int len2 = strlen(name2);
int src_size = len + 1;
do {
int i;
int src_size = len + 1;
do {
int i;
int firstdir = 0;
int pathlen;
unsigned ce_size;
int firstdir = 0;
int pathlen;
unsigned ce_size;
p = process_tree(entry->item.tree, p, &me, entry->name);
else
p = process_blob(entry->item.blob, p, &me, entry->name);
p = process_tree(entry->item.tree, p, &me, entry->name);
else
p = process_blob(entry->item.blob, p, &me, entry->name);
free(entry);
entry = next;
}
free(entry);
entry = next;
}
+ free(tree->buffer);
+ tree->buffer = NULL;
free(last);
}
last = entry;
}
free(last);
}
last = entry;
}
- if (last) {
- free(last->name);
+ free(item->buffer);
+ item->buffer = NULL;
retval = 0;
if (has_full_path) {
retval = 0;
if (has_full_path) {
obj = &blob->object;
} else if (!strcmp(type, tree_type)) {
struct tree *tree = lookup_tree(sha1);
obj = &blob->object;
} else if (!strcmp(type, tree_type)) {
struct tree *tree = lookup_tree(sha1);
- parse_tree_buffer(tree, buffer, size);
+ if (!tree->object.parsed) {
+ parse_tree_buffer(tree, buffer, size);
+ buffer = NULL;
+ }
} else if (!strcmp(type, commit_type)) {
struct commit *commit = lookup_commit(sha1);
parse_commit_buffer(commit, buffer, size);
} else if (!strcmp(type, commit_type)) {
struct commit *commit = lookup_commit(sha1);
parse_commit_buffer(commit, buffer, size);
#include "blob.h"
#include "commit.h"
#include "tag.h"
#include "blob.h"
#include "commit.h"
#include "tag.h"
#include <stdlib.h>
const char *tree_type = "tree";
#include <stdlib.h>
const char *tree_type = "tree";
int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
{
int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
{
struct tree_entry_list **list_p;
int n_refs = 0;
if (item->object.parsed)
return 0;
item->object.parsed = 1;
struct tree_entry_list **list_p;
int n_refs = 0;
if (item->object.parsed)
return 0;
item->object.parsed = 1;
+ item->buffer = buffer;
+ item->size = size;
+
+ desc.buf = buffer;
+ desc.size = size;
+
- while (size) {
- struct object *obj;
+ while (desc.size) {
+ unsigned mode;
+ const char *path;
+ const unsigned char *sha1;
struct tree_entry_list *entry;
struct tree_entry_list *entry;
- int len = 1+strlen(bufptr);
- unsigned char *file_sha1 = bufptr + len;
- char *path = strchr(bufptr, ' ');
- unsigned int mode;
- if (size < len + 20 || !path ||
- sscanf(bufptr, "%o", &mode) != 1)
- return -1;
+
+ sha1 = tree_entry_extract(&desc, &path, &mode);
entry = xmalloc(sizeof(struct tree_entry_list));
entry = xmalloc(sizeof(struct tree_entry_list));
- entry->name = strdup(path + 1);
+ entry->name = path;
+ entry->mode = mode;
entry->directory = S_ISDIR(mode) != 0;
entry->executable = (mode & S_IXUSR) != 0;
entry->symlink = S_ISLNK(mode) != 0;
entry->directory = S_ISDIR(mode) != 0;
entry->executable = (mode & S_IXUSR) != 0;
entry->symlink = S_ISLNK(mode) != 0;
- entry->zeropad = *(char *)bufptr == '0';
- entry->mode = mode;
+ entry->zeropad = *(const char *)(desc.buf) == '0';
- bufptr += len + 20;
- size -= len + 20;
+ update_tree_entry(&desc);
- entry->item.tree = lookup_tree(file_sha1);
- obj = &entry->item.tree->object;
+ entry->item.tree = lookup_tree(sha1);
- entry->item.blob = lookup_blob(file_sha1);
- obj = &entry->item.blob->object;
+ entry->item.blob = lookup_blob(sha1);
*list_p = entry;
list_p = &entry->next;
}
*list_p = entry;
list_p = &entry->next;
}
char type[20];
void *buffer;
unsigned long size;
char type[20];
void *buffer;
unsigned long size;
if (item->object.parsed)
return 0;
if (item->object.parsed)
return 0;
return error("Object %s not a tree",
sha1_to_hex(item->object.sha1));
}
return error("Object %s not a tree",
sha1_to_hex(item->object.sha1));
}
- ret = parse_tree_buffer(item, buffer, size);
- free(buffer);
- return ret;
+ return parse_tree_buffer(item, buffer, size);
}
struct tree *parse_tree_indirect(const unsigned char *sha1)
}
struct tree *parse_tree_indirect(const unsigned char *sha1)
unsigned symlink : 1;
unsigned zeropad : 1;
unsigned int mode;
unsigned symlink : 1;
unsigned zeropad : 1;
unsigned int mode;
union {
struct object *any;
struct tree *tree;
union {
struct object *any;
struct tree *tree;
struct tree {
struct object object;
struct tree {
struct object object;
+ void *buffer;
+ unsigned long size;
struct tree_entry_list *entries;
};
struct tree_entry_list *entries;
};