summaryrefslogtreecommitdiff
path: root/tree-walk.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2007-03-21 10:08:25 -0700
committerJunio C Hamano <junkio@cox.net>2007-03-21 10:21:57 -0700
commit6fda5e5180c2e7c130978361aea53b4e66f36823 (patch)
tree89df3a31883fe84ae06d1c05f29fa823614eef87 /tree-walk.c
parenta8c40471ab0851bf9a58f7dc76f121258e0690e2 (diff)
downloadgit-6fda5e5180c2e7c130978361aea53b4e66f36823.tar.gz
Initialize tree descriptors with a helper function rather than by hand.
This removes slightly more lines than it adds, but the real reason for doing this is that future optimizations will require more setup of the tree descriptor, and so we want to do it in one place. Also renamed the "desc.buf" field to "desc.buffer" just to trigger compiler errors for old-style manual initializations, making sure I didn't miss anything. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'tree-walk.c')
-rw-r--r--tree-walk.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/tree-walk.c b/tree-walk.c
index 1869baede5..c65492c02d 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -2,6 +2,12 @@
#include "tree-walk.h"
#include "tree.h"
+void init_tree_desc(struct tree_desc *desc, const void *buffer, unsigned long size)
+{
+ desc->buffer = buffer;
+ desc->size = size;
+}
+
void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1)
{
unsigned long size = 0;
@@ -12,8 +18,7 @@ void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1)
if (!buf)
die("unable to read tree %s", sha1_to_hex(sha1));
}
- desc->size = size;
- desc->buf = buf;
+ init_tree_desc(desc, buf, size);
return buf;
}
@@ -36,13 +41,13 @@ static void entry_extract(struct tree_desc *t, struct name_entry *a)
void update_tree_entry(struct tree_desc *desc)
{
- const void *buf = desc->buf;
+ const void *buf = desc->buffer;
unsigned long size = desc->size;
int len = strlen(buf) + 1 + 20;
if (size < len)
die("corrupt tree file");
- desc->buf = (char *) buf + len;
+ desc->buffer = (char *) buf + len;
desc->size = size - len;
}
@@ -62,7 +67,7 @@ static const char *get_mode(const char *str, unsigned int *modep)
const unsigned char *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned int *modep)
{
- const void *tree = desc->buf;
+ const void *tree = desc->buffer;
unsigned long size = desc->size;
int len = strlen(tree)+1;
const unsigned char *sha1 = (unsigned char *) tree + len;
@@ -79,7 +84,7 @@ const unsigned char *tree_entry_extract(struct tree_desc *desc, const char **pat
int tree_entry(struct tree_desc *desc, struct name_entry *entry)
{
- const void *tree = desc->buf;
+ const void *tree = desc->buffer;
const char *path;
unsigned long len, size = desc->size;
@@ -101,7 +106,7 @@ int tree_entry(struct tree_desc *desc, struct name_entry *entry)
if (len > size)
die("corrupt tree file");
- desc->buf = path;
+ desc->buffer = path;
desc->size = size - len;
return 1;
}
@@ -196,10 +201,11 @@ int get_tree_entry(const unsigned char *tree_sha1, const char *name, unsigned ch
{
int retval;
void *tree;
+ unsigned long size;
struct tree_desc t;
unsigned char root[20];
- tree = read_object_with_reference(tree_sha1, tree_type, &t.size, root);
+ tree = read_object_with_reference(tree_sha1, tree_type, &size, root);
if (!tree)
return -1;
@@ -208,7 +214,7 @@ int get_tree_entry(const unsigned char *tree_sha1, const char *name, unsigned ch
return 0;
}
- t.buf = tree;
+ init_tree_desc(&t, tree, size);
retval = find_tree_entry(&t, name, sha1, mode);
free(tree);
return retval;