summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a8c4047)
raw | patch | inline | side by side (parent: a8c4047)
author | Linus Torvalds <torvalds@linux-foundation.org> | |
Wed, 21 Mar 2007 17:08:25 +0000 (10:08 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Wed, 21 Mar 2007 17:21:57 +0000 (10:21 -0700) |
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>
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>
15 files changed:
builtin-fsck.c | patch | blob | history | |
builtin-grep.c | patch | blob | history | |
builtin-pack-objects.c | patch | blob | history | |
builtin-read-tree.c | patch | blob | history | |
builtin-reflog.c | patch | blob | history | |
fetch.c | patch | blob | history | |
http-push.c | patch | blob | history | |
list-objects.c | patch | blob | history | |
reachable.c | patch | blob | history | |
revision.c | patch | blob | history | |
tree-diff.c | patch | blob | history | |
tree-walk.c | patch | blob | history | |
tree-walk.h | patch | blob | history | |
tree.c | patch | blob | history | |
unpack-trees.c | patch | blob | history |
diff --git a/builtin-fsck.c b/builtin-fsck.c
index b8e71b640b66ebd95a436a5c1c7f3fce0647be0c..21f1f9e91d5a1ba8e8c3fd968b56d5c860b2aeac 100644 (file)
--- a/builtin-fsck.c
+++ b/builtin-fsck.c
const char *o_name;
const unsigned char *o_sha1;
- desc.buf = item->buffer;
- desc.size = item->size;
+ init_tree_desc(&desc, item->buffer, item->size);
o_mode = 0;
o_name = NULL;
if (strchr(name, '/'))
has_full_path = 1;
- has_zero_pad |= *(char *)desc.buf == '0';
+ has_zero_pad |= *(char *)desc.buffer == '0';
update_tree_entry(&desc);
switch (mode) {
diff --git a/builtin-grep.c b/builtin-grep.c
index 1348cc92efc19b30f3bbda15ef4205ec2ffabb85..981f3d4d8eb079f5985beaaf94014d5745c5aacc 100644 (file)
--- a/builtin-grep.c
+++ b/builtin-grep.c
enum object_type type;
struct tree_desc sub;
void *data;
- data = read_sha1_file(entry.sha1, &type, &sub.size);
+ unsigned long size;
+
+ data = read_sha1_file(entry.sha1, &type, &size);
if (!data)
die("unable to read tree (%s)",
sha1_to_hex(entry.sha1));
- sub.buf = data;
+ init_tree_desc(&sub, data, size);
hit |= grep_tree(opt, paths, &sub, tree_name, down);
free(data);
}
if (obj->type == OBJ_COMMIT || obj->type == OBJ_TREE) {
struct tree_desc tree;
void *data;
+ unsigned long size;
int hit;
data = read_object_with_reference(obj->sha1, tree_type,
- &tree.size, NULL);
+ &size, NULL);
if (!data)
die("unable to read tree (%s)", sha1_to_hex(obj->sha1));
- tree.buf = data;
+ init_tree_desc(&tree, data, size);
hit = grep_tree(opt, paths, &tree, name, "");
free(data);
return hit;
diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index 9231b6564ff08315f205ba630a238d3c56deac4f..b5f9648e809a3ef7f381239470c031208ade4a34 100644 (file)
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
tree = pbase_tree_get(entry.sha1);
if (!tree)
return;
- sub.buf = tree->tree_data;
- sub.size = tree->tree_size;
+ init_tree_desc(&sub, tree->tree_data, tree->tree_size);
add_pbase_object(&sub, down, downlen, fullname);
pbase_tree_put(tree);
}
else {
struct tree_desc tree;
- tree.buf = it->pcache.tree_data;
- tree.size = it->pcache.tree_size;
+ init_tree_desc(&tree, it->pcache.tree_data, it->pcache.tree_size);
add_pbase_object(&tree, name, cmplen, name);
}
}
diff --git a/builtin-read-tree.c b/builtin-read-tree.c
index e47715538bd1ff81d1a91e0a43cd9bdbe1cb0d3f..82df94101a20a9ea9c06cd6d6ce8db56d8a7de18 100644 (file)
--- a/builtin-read-tree.c
+++ b/builtin-read-tree.c
int cnt;
hashcpy(it->sha1, tree->object.sha1);
- desc.buf = tree->buffer;
- desc.size = tree->size;
+ init_tree_desc(&desc, tree->buffer, tree->size);
cnt = 0;
while (tree_entry(&desc, &entry)) {
if (!S_ISDIR(entry.mode))
diff --git a/builtin-reflog.c b/builtin-reflog.c
index 186aabce042a1d6e5d83141495a854db09223bf8..4c39f1da98e5e690f28f5145a1ab5dba790da68d 100644 (file)
--- a/builtin-reflog.c
+++ b/builtin-reflog.c
if (tree->object.flags & INCOMPLETE)
return 0;
- desc.buf = tree->buffer;
- desc.size = tree->size;
- if (!desc.buf) {
+ if (!tree->buffer) {
enum object_type type;
- void *data = read_sha1_file(sha1, &type, &desc.size);
+ unsigned long size;
+ void *data = read_sha1_file(sha1, &type, &size);
if (!data) {
tree->object.flags |= INCOMPLETE;
return 0;
}
- desc.buf = data;
tree->buffer = data;
+ tree->size = size;
}
+ init_tree_desc(&desc, tree->buffer, tree->size);
complete = 1;
while (tree_entry(&desc, &entry)) {
if (!has_sha1_file(entry.sha1) ||
index f69be82f10d287d71f6184c4b9203bdab3ce81fc..8e29d313f817981a29ebb65f2f579c9f1bd8e9b6 100644 (file)
--- a/fetch.c
+++ b/fetch.c
if (parse_tree(tree))
return -1;
- desc.buf = tree->buffer;
- desc.size = tree->size;
+ init_tree_desc(&desc, tree->buffer, tree->size);
while (tree_entry(&desc, &entry)) {
struct object *obj = NULL;
diff --git a/http-push.c b/http-push.c
index cbb02d3bc1eef3d5a088be320a3a8bcb87a4a685..724720c562ab6da2b02e91b69f5365bc7bfee4f4 100644 (file)
--- a/http-push.c
+++ b/http-push.c
me.elem = name;
me.elem_len = strlen(name);
- desc.buf = tree->buffer;
- desc.size = tree->size;
+ init_tree_desc(&desc, tree->buffer, tree->size);
while (tree_entry(&desc, &entry)) {
if (S_ISDIR(entry.mode))
diff --git a/list-objects.c b/list-objects.c
index f1fa21c3978f32882b6aac68c32d33ead6f8f1ff..2ba2c958e0aac63f0d5b092019e71f6905edb052 100644 (file)
--- a/list-objects.c
+++ b/list-objects.c
me.elem = name;
me.elem_len = strlen(name);
- desc.buf = tree->buffer;
- desc.size = tree->size;
+ init_tree_desc(&desc, tree->buffer, tree->size);
while (tree_entry(&desc, &entry)) {
if (S_ISDIR(entry.mode))
diff --git a/reachable.c b/reachable.c
index 01760d70462927ad33c7976a50e31372863a45f9..ff3dd34962ec69320a67a4823b844755ebfe0e7d 100644 (file)
--- a/reachable.c
+++ b/reachable.c
me.elem = name;
me.elem_len = strlen(name);
- desc.buf = tree->buffer;
- desc.size = tree->size;
+ init_tree_desc(&desc, tree->buffer, tree->size);
while (tree_entry(&desc, &entry)) {
if (S_ISDIR(entry.mode))
diff --git a/revision.c b/revision.c
index c680dcb8ba28bb8405cec06846592f5430e8f45b..adc381c268b6f336ab7820c464fafa39629c8e28 100644 (file)
--- a/revision.c
+++ b/revision.c
if (parse_tree(tree) < 0)
die("bad tree %s", sha1_to_hex(obj->sha1));
- desc.buf = tree->buffer;
- desc.size = tree->size;
+ init_tree_desc(&desc, tree->buffer, tree->size);
while (tree_entry(&desc, &entry)) {
if (S_ISDIR(entry.mode))
mark_tree_uninteresting(lookup_tree(entry.sha1));
{
int retval;
void *tree;
+ unsigned long size;
struct tree_desc empty, real;
if (!t1)
return 0;
- tree = read_object_with_reference(t1->object.sha1, tree_type, &real.size, NULL);
+ tree = read_object_with_reference(t1->object.sha1, tree_type, &size, NULL);
if (!tree)
return 0;
- real.buf = tree;
-
- empty.buf = "";
- empty.size = 0;
+ init_tree_desc(&real, tree, size);
+ init_tree_desc(&empty, "", 0);
tree_difference = REV_TREE_SAME;
revs->pruning.has_changes = 0;
diff --git a/tree-diff.c b/tree-diff.c
index b2f35dc3d82a2a2ef4726073ca3f77f10c7c28bb..36788058aefb567eee042ea3e44baca144302835 100644 (file)
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -154,12 +154,13 @@ static void show_entry(struct diff_options *opt, const char *prefix, struct tree
char *newbase = malloc_base(base, baselen, path, pathlen);
struct tree_desc inner;
void *tree;
+ unsigned long size;
- tree = read_sha1_file(sha1, &type, &inner.size);
+ tree = read_sha1_file(sha1, &type, &size);
if (!tree || type != OBJ_TREE)
die("corrupt tree sha %s", sha1_to_hex(sha1));
- inner.buf = tree;
+ init_tree_desc(&inner, tree, size);
show_tree(opt, prefix, &inner, newbase, baselen + 1 + pathlen);
free(tree);
@@ -227,16 +228,17 @@ int diff_tree_sha1(const unsigned char *old, const unsigned char *new, const cha
{
void *tree1, *tree2;
struct tree_desc t1, t2;
+ unsigned long size1, size2;
int retval;
- tree1 = read_object_with_reference(old, tree_type, &t1.size, NULL);
+ tree1 = read_object_with_reference(old, tree_type, &size1, NULL);
if (!tree1)
die("unable to read source tree (%s)", sha1_to_hex(old));
- tree2 = read_object_with_reference(new, tree_type, &t2.size, NULL);
+ tree2 = read_object_with_reference(new, tree_type, &size2, NULL);
if (!tree2)
die("unable to read destination tree (%s)", sha1_to_hex(new));
- t1.buf = tree1;
- t2.buf = tree2;
+ init_tree_desc(&t1, tree1, size1);
+ init_tree_desc(&t2, tree2, size2);
retval = diff_tree(&t1, &t2, base, opt);
free(tree1);
free(tree2);
@@ -247,15 +249,15 @@ int diff_root_tree_sha1(const unsigned char *new, const char *base, struct diff_
{
int retval;
void *tree;
+ unsigned long size;
struct tree_desc empty, real;
- tree = read_object_with_reference(new, tree_type, &real.size, NULL);
+ tree = read_object_with_reference(new, tree_type, &size, NULL);
if (!tree)
die("unable to read root tree (%s)", sha1_to_hex(new));
- real.buf = tree;
+ init_tree_desc(&real, tree, size);
- empty.size = 0;
- empty.buf = "";
+ init_tree_desc(&empty, "", 0);
retval = diff_tree(&empty, &real, base, opt);
free(tree);
return retval;
diff --git a/tree-walk.c b/tree-walk.c
index 1869baede56da54f964e4300d0b4148e66999cab..c65492c02d5e37840bbaed9535b93404482b90a1 100644 (file)
--- a/tree-walk.c
+++ b/tree-walk.c
#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;
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;
}
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;
}
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;
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;
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;
diff --git a/tree-walk.h b/tree-walk.h
index 149393aaa476985d3607f796366b537b6622d50e..ca0c29fb1ac7d6e5c0d364fd27845515de151469 100644 (file)
--- a/tree-walk.h
+++ b/tree-walk.h
#define TREE_WALK_H
struct tree_desc {
- const void *buf;
- unsigned long size;
+ const void *buffer;
+ unsigned int size;
};
struct name_entry {
}
void update_tree_entry(struct tree_desc *);
+void init_tree_desc(struct tree_desc *desc, const void *buf, unsigned long size);
const unsigned char *tree_entry_extract(struct tree_desc *, const char **, unsigned int *);
/* Helper function that does both of the above and returns true for success */
index 705a4812558654a35f03d669431d2d962b3b1bb1..d188c0fbaee110a17ca7a0d16dcc979091f44ded 100644 (file)
--- a/tree.c
+++ b/tree.c
if (parse_tree(tree))
return -1;
- desc.buf = tree->buffer;
- desc.size = tree->size;
+ init_tree_desc(&desc, tree->buffer, tree->size);
while (tree_entry(&desc, &entry)) {
if (!match_tree_entry(base, baselen, entry.path, entry.mode, match))
struct name_entry entry;
/* Count how many entries there are.. */
- desc.buf = item->buffer;
- desc.size = item->size;
+ init_tree_desc(&desc, item->buffer, item->size);
while (tree_entry(&desc, &entry))
n_refs++;
/* Allocate object refs and walk it again.. */
i = 0;
refs = alloc_object_refs(n_refs);
- desc.buf = item->buffer;
- desc.size = item->size;
+ init_tree_desc(&desc, item->buffer, item->size);
while (tree_entry(&desc, &entry)) {
struct object *obj;
diff --git a/unpack-trees.c b/unpack-trees.c
index 2e2232cbb07e61de3be74302fba67142a58a857b..ee10eea24cdd37d308066721c947b2d2449e786e 100644 (file)
--- a/unpack-trees.c
+++ b/unpack-trees.c
if (!tree->object.parsed)
parse_tree(tree);
- desc.buf = tree->buffer;
- desc.size = tree->size;
+ init_tree_desc(&desc, tree->buffer, tree->size);
while (tree_entry(&desc, &one)) {
struct tree_entry_list *entry;