summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e0c97ca)
raw | patch | inline | side by side (parent: e0c97ca)
author | Linus Torvalds <torvalds@osdl.org> | |
Mon, 29 May 2006 19:16:12 +0000 (12:16 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Tue, 30 May 2006 02:05:02 +0000 (19:05 -0700) |
This allows us to avoid allocating information for names etc, because
we can just use the information from the tree buffer directly.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
we can just use the information from the tree buffer directly.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
builtin-read-tree.c | patch | blob | history | |
builtin-rev-list.c | patch | blob | history | |
fsck-objects.c | patch | blob | history | |
object.c | patch | blob | history | |
tree.c | patch | blob | history | |
tree.h | patch | blob | history |
diff --git a/builtin-read-tree.c b/builtin-read-tree.c
index 716f7925142bca11cf7ab5438ce5908e55285463..6876f3d79391ce1d73a830336769be4f49644e0f 100644 (file)
--- a/builtin-read-tree.c
+++ b/builtin-read-tree.c
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 src_size = len + 1;
do {
int i;
- char *first;
+ const char *first;
int firstdir = 0;
int pathlen;
unsigned ce_size;
diff --git a/builtin-rev-list.c b/builtin-rev-list.c
index 5277d3cf12da2f029499342eea32441ae4b983d9..72c1549c701f24dc46eaf920fdcb73f822cf5cda 100644 (file)
--- a/builtin-rev-list.c
+++ b/builtin-rev-list.c
p = process_tree(entry->item.tree, p, &me, entry->name);
else
p = process_blob(entry->item.blob, p, &me, entry->name);
- free(entry->name);
free(entry);
entry = next;
}
+ free(tree->buffer);
+ tree->buffer = NULL;
return p;
}
diff --git a/fsck-objects.c b/fsck-objects.c
index 1922b6d84c51588b22553141f608c9a07182560b..5e65df436ba8e4191530ec6f9351d5e069928412 100644 (file)
--- a/fsck-objects.c
+++ b/fsck-objects.c
default:
break;
}
- free(last->name);
free(last);
}
last = entry;
}
- if (last) {
- free(last->name);
+ if (last)
free(last);
- }
item->entries = NULL;
+ free(item->buffer);
+ item->buffer = NULL;
retval = 0;
if (has_full_path) {
diff --git a/object.c b/object.c
index 4d46e0d5e4285251e60d2a6d938f38355ac5d2c0..1a7823c234406a418d360bf5ea322fe2321aec06 100644 (file)
--- a/object.c
+++ b/object.c
obj = &blob->object;
} else if (!strcmp(type, tree_type)) {
struct tree *tree = lookup_tree(sha1);
- parse_tree_buffer(tree, buffer, size);
obj = &tree->object;
+ 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);
index d599fb5e1a8b689460c1e53b319f88aeda9a4c89..1e76d9cc11dcbda655e40f19fbd82d34212383b2 100644 (file)
--- a/tree.c
+++ b/tree.c
#include "blob.h"
#include "commit.h"
#include "tag.h"
+#include "tree-walk.h"
#include <stdlib.h>
const char *tree_type = "tree";
int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)
{
- void *bufptr = buffer;
+ struct tree_desc desc;
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;
+
list_p = &item->entries;
- while (size) {
- struct object *obj;
+ while (desc.size) {
+ unsigned mode;
+ const char *path;
+ const unsigned char *sha1;
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->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->zeropad = *(char *)bufptr == '0';
- entry->mode = mode;
+ entry->zeropad = *(const char *)(desc.buf) == '0';
entry->next = NULL;
- bufptr += len + 20;
- size -= len + 20;
+ update_tree_entry(&desc);
if (entry->directory) {
- entry->item.tree = lookup_tree(file_sha1);
- obj = &entry->item.tree->object;
+ entry->item.tree = lookup_tree(sha1);
} else {
- entry->item.blob = lookup_blob(file_sha1);
- obj = &entry->item.blob->object;
+ entry->item.blob = lookup_blob(sha1);
}
- if (obj)
- n_refs++;
+ n_refs++;
*list_p = entry;
list_p = &entry->next;
}
char type[20];
void *buffer;
unsigned long size;
- int ret;
if (item->object.parsed)
return 0;
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)
index 330ab64bbd40bd9202a7474cbda0818b98640cde..066ac5d5bfa38ec8b61e4a8c9b1d75c1959eaa03 100644 (file)
--- a/tree.h
+++ b/tree.h
unsigned symlink : 1;
unsigned zeropad : 1;
unsigned int mode;
- char *name;
+ const char *name;
union {
struct object *any;
struct tree *tree;
struct tree {
struct object object;
+ void *buffer;
+ unsigned long size;
struct tree_entry_list *entries;
};