summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 210a0be)
raw | patch | inline | side by side (parent: 210a0be)
author | Linus Torvalds <torvalds@osdl.org> | |
Wed, 14 Jun 2006 23:45:13 +0000 (16:45 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Sun, 18 Jun 2006 01:49:18 +0000 (18:49 -0700) |
This shrinks "struct object" by a small amount, by getting rid of the
"struct type *" pointer and replacing it with a 3-bit bitfield instead.
In addition, we merge the bitfields and the "flags" field, which
incidentally should also remove a useless 4-byte padding from the object
when in 64-bit mode.
Now, our "struct object" is still too damn large, but it's now less
obviously bloated, and of the remaining fields, only the "util" (which is
not used by most things) is clearly something that should be eventually
discarded.
This shrinks the "git-rev-list --all" memory use by about 2.5% on the
kernel archive (and, perhaps more importantly, on the larger mozilla
archive). That may not sound like much, but I suspect it's more on a
64-bit platform.
There are other remaining inefficiencies (the parent lists, for example,
probably have horrible malloc overhead), but this was pretty obvious.
Most of the patch is just changing the comparison of the "type" pointer
from one of the constant string pointers to the appropriate new TYPE_xxx
small integer constant.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
"struct type *" pointer and replacing it with a 3-bit bitfield instead.
In addition, we merge the bitfields and the "flags" field, which
incidentally should also remove a useless 4-byte padding from the object
when in 64-bit mode.
Now, our "struct object" is still too damn large, but it's now less
obviously bloated, and of the remaining fields, only the "util" (which is
not used by most things) is clearly something that should be eventually
discarded.
This shrinks the "git-rev-list --all" memory use by about 2.5% on the
kernel archive (and, perhaps more importantly, on the larger mozilla
archive). That may not sound like much, but I suspect it's more on a
64-bit platform.
There are other remaining inefficiencies (the parent lists, for example,
probably have horrible malloc overhead), but this was pretty obvious.
Most of the patch is just changing the comparison of the "type" pointer
from one of the constant string pointers to the appropriate new TYPE_xxx
small integer constant.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
21 files changed:
blob.c | patch | blob | history | |
builtin-diff.c | patch | blob | history | |
builtin-grep.c | patch | blob | history | |
builtin-rev-list.c | patch | blob | history | |
builtin-show-branch.c | patch | blob | history | |
commit.c | patch | blob | history | |
describe.c | patch | blob | history | |
fetch-pack.c | patch | blob | history | |
fetch.c | patch | blob | history | |
fsck-objects.c | patch | blob | history | |
http-push.c | patch | blob | history | |
name-rev.c | patch | blob | history | |
object.c | patch | blob | history | |
object.h | patch | blob | history | |
revision.c | patch | blob | history | |
send-pack.c | patch | blob | history | |
server-info.c | patch | blob | history | |
sha1_name.c | patch | blob | history | |
tag.c | patch | blob | history | |
tree.c | patch | blob | history | |
upload-pack.c | patch | blob | history |
index c1fdd861c3dedbbd670fcf07989501fd0f9b5fda..7377008744430cea453010fe93e6c1f51c37fdde 100644 (file)
--- a/blob.c
+++ b/blob.c
if (!obj) {
struct blob *ret = xcalloc(1, sizeof(struct blob));
created_object(sha1, &ret->object);
- ret->object.type = blob_type;
+ ret->object.type = TYPE_BLOB;
return ret;
}
if (!obj->type)
- obj->type = blob_type;
- if (obj->type != blob_type) {
- error("Object %s is a %s, not a blob",
- sha1_to_hex(sha1), obj->type);
+ obj->type = TYPE_BLOB;
+ if (obj->type != TYPE_BLOB) {
+ error("Object %s is a %s, not a blob",
+ sha1_to_hex(sha1), typename(obj->type));
return NULL;
}
return (struct blob *) obj;
diff --git a/builtin-diff.c b/builtin-diff.c
index 27451d56134e08364c33c26d5074693dd4437d31..6ac3d4b8ca23e7c4d724b22fd3222005d8fe3df8 100644 (file)
--- a/builtin-diff.c
+++ b/builtin-diff.c
obj = deref_tag(obj, NULL, 0);
if (!obj)
die("invalid object '%s' given.", name);
- if (!strcmp(obj->type, commit_type))
+ if (obj->type == TYPE_COMMIT)
obj = &((struct commit *)obj)->tree->object;
- if (!strcmp(obj->type, tree_type)) {
+ if (obj->type == TYPE_TREE) {
if (ARRAY_SIZE(ent) <= ents)
die("more than %d trees given: '%s'",
(int) ARRAY_SIZE(ent), name);
ents++;
continue;
}
- if (!strcmp(obj->type, blob_type)) {
+ if (obj->type == TYPE_BLOB) {
if (2 <= blobs)
die("more than two blobs given: '%s'", name);
memcpy(blob[blobs].sha1, obj->sha1, 20);
diff --git a/builtin-grep.c b/builtin-grep.c
index 5fac5701e6ccebdbe83b00d2e2df19343d3aea0e..9806499263dcb92c7a6903ead36646baf676b178 100644 (file)
--- a/builtin-grep.c
+++ b/builtin-grep.c
static int grep_object(struct grep_opt *opt, const char **paths,
struct object *obj, const char *name)
{
- if (!strcmp(obj->type, blob_type))
+ if (obj->type == TYPE_BLOB)
return grep_sha1(opt, obj->sha1, name);
- if (!strcmp(obj->type, commit_type) ||
- !strcmp(obj->type, tree_type)) {
+ if (obj->type == TYPE_COMMIT || obj->type == TYPE_TREE) {
struct tree_desc tree;
void *data;
int hit;
free(data);
return hit;
}
- die("unable to grep from object of type %s", obj->type);
+ die("unable to grep from object of type %s", typename(obj->type));
}
static const char builtin_grep_usage[] =
diff --git a/builtin-rev-list.c b/builtin-rev-list.c
index e885624255ac8e1007df797d339e3e81020f95a2..2b298c4e412c4fca24ea5068f17a557f89a6a449 100644 (file)
--- a/builtin-rev-list.c
+++ b/builtin-rev-list.c
const char *name = pending->name;
if (obj->flags & (UNINTERESTING | SEEN))
continue;
- if (obj->type == tag_type) {
+ if (obj->type == TYPE_TAG) {
obj->flags |= SEEN;
p = add_object(obj, p, NULL, name);
continue;
}
- if (obj->type == tree_type) {
+ if (obj->type == TYPE_TREE) {
p = process_tree((struct tree *)obj, p, NULL, name);
continue;
}
- if (obj->type == blob_type) {
+ if (obj->type == TYPE_BLOB) {
p = process_blob((struct blob *)obj, p, NULL, name);
continue;
}
diff --git a/builtin-show-branch.c b/builtin-show-branch.c
index 2895140915cb603e2c5f971d0356f2e48106bc0e..cf9c071a53c09476acaecb6bcbf95d4ff76dca79 100644 (file)
--- a/builtin-show-branch.c
+++ b/builtin-show-branch.c
#define UNINTERESTING 01
#define REV_SHIFT 2
-#define MAX_REVS 29 /* should not exceed bits_per_int - REV_SHIFT */
+#define MAX_REVS (FLAG_BITS - REV_SHIFT) /* should not exceed bits_per_int - REV_SHIFT */
static struct commit *interesting(struct commit_list *list)
{
diff --git a/commit.c b/commit.c
index 94f470b75cfc68bfd8e14d1e421e19c5ad6004d6..11fca559d8a4bcb6b6dc67f41ec54991acaba11a 100644 (file)
--- a/commit.c
+++ b/commit.c
const unsigned char *sha1,
int quiet)
{
- if (obj->type != commit_type) {
+ if (obj->type != TYPE_COMMIT) {
if (!quiet)
error("Object %s is a %s, not a commit",
- sha1_to_hex(sha1), obj->type);
+ sha1_to_hex(sha1), typename(obj->type));
return NULL;
}
return (struct commit *) obj;
if (!obj) {
struct commit *ret = xcalloc(1, sizeof(struct commit));
created_object(sha1, &ret->object);
- ret->object.type = commit_type;
+ ret->object.type = TYPE_COMMIT;
return ret;
}
if (!obj->type)
- obj->type = commit_type;
+ obj->type = TYPE_COMMIT;
return check_commit(obj, sha1, 0);
}
diff --git a/describe.c b/describe.c
index 8a9cd5d52c555330c512b977179ab030ccd28861..aa3434a4cbfe62563b7621ddd7e72be3adbea1cc 100644 (file)
--- a/describe.c
+++ b/describe.c
* Otherwise only annotated tags are used.
*/
if (!strncmp(path, "refs/tags/", 10)) {
- if (object->type == tag_type)
+ if (object->type == TYPE_TAG)
prio = 2;
else
prio = 1;
diff --git a/fetch-pack.c b/fetch-pack.c
index 83713485562fd340a67e5073b443679d0b2a4c24..7d23a8071a9c2923b1f9bcf1d897e590e04f432b 100644 (file)
--- a/fetch-pack.c
+++ b/fetch-pack.c
{
struct object *o = deref_tag(parse_object(sha1), path, 0);
- if (o && o->type == commit_type)
+ if (o && o->type == TYPE_COMMIT)
rev_list_push((struct commit *)o, SEEN);
return 0;
{
struct object *o = parse_object(sha1);
- while (o && o->type == tag_type) {
+ while (o && o->type == TYPE_TAG) {
struct tag *t = (struct tag *) o;
if (!t->tagged)
break; /* broken repository */
o->flags |= COMPLETE;
o = parse_object(t->tagged->sha1);
}
- if (o && o->type == commit_type) {
+ if (o && o->type == TYPE_COMMIT) {
struct commit *commit = (struct commit *)o;
commit->object.flags |= COMPLETE;
insert_by_date(commit, &complete);
* in sync with the other side at some time after
* that (it is OK if we guess wrong here).
*/
- if (o->type == commit_type) {
+ if (o->type == TYPE_COMMIT) {
struct commit *commit = (struct commit *)o;
if (!cutoff || cutoff < commit->date)
cutoff = commit->date;
struct object *o = deref_tag(lookup_object(ref->old_sha1),
NULL, 0);
- if (!o || o->type != commit_type || !(o->flags & COMPLETE))
+ if (!o || o->type != TYPE_COMMIT || !(o->flags & COMPLETE))
continue;
if (!(o->flags & SEEN)) {
index cf6c99490c234c5854146f8f6e72d8c615517eea..238032b798008cd1f96d5083b63dc582f8191a1d 100644 (file)
--- a/fetch.c
+++ b/fetch.c
static int process_object(struct object *obj)
{
- if (obj->type == commit_type) {
+ if (obj->type == TYPE_COMMIT) {
if (process_commit((struct commit *)obj))
return -1;
return 0;
}
- if (obj->type == tree_type) {
+ if (obj->type == TYPE_TREE) {
if (process_tree((struct tree *)obj))
return -1;
return 0;
}
- if (obj->type == blob_type) {
+ if (obj->type == TYPE_BLOB) {
return 0;
}
- if (obj->type == tag_type) {
+ if (obj->type == TYPE_TAG) {
if (process_tag((struct tag *)obj))
return -1;
return 0;
}
return error("Unable to determine requirements "
"of type %s for %s",
- obj->type, sha1_to_hex(obj->sha1));
+ typename(obj->type), sha1_to_hex(obj->sha1));
}
static int process(struct object *obj)
*/
if (! (obj->flags & TO_SCAN)) {
if (fetch(obj->sha1)) {
- report_missing(obj->type
- ? obj->type
- : "object", obj->sha1);
+ report_missing(typename(obj->type), obj->sha1);
return -1;
}
}
diff --git a/fsck-objects.c b/fsck-objects.c
index 33ce366e99376619c96ad3b1a1d883a98d55193b..2b1aab488f2b8d64fa799adf427b6eeca35ac757 100644 (file)
--- a/fsck-objects.c
+++ b/fsck-objects.c
const char *err, va_list params)
{
fprintf(stderr, "%s in %s %s: ",
- severity, obj->type, sha1_to_hex(obj->sha1));
+ severity, typename(obj->type), sha1_to_hex(obj->sha1));
vfprintf(stderr, err, params);
fputs("\n", stderr);
}
; /* it is in pack */
else
printf("missing %s %s\n",
- obj->type, sha1_to_hex(obj->sha1));
+ typename(obj->type), sha1_to_hex(obj->sha1));
continue;
}
(has_sha1_file(ref->sha1)))
continue;
printf("broken link from %7s %s\n",
- obj->type, sha1_to_hex(obj->sha1));
+ typename(obj->type), sha1_to_hex(obj->sha1));
printf(" to %7s %s\n",
- ref->type, sha1_to_hex(ref->sha1));
+ typename(ref->type), sha1_to_hex(ref->sha1));
}
}
if (show_unreachable && !(obj->flags & REACHABLE)) {
printf("unreachable %s %s\n",
- obj->type, sha1_to_hex(obj->sha1));
+ typename(obj->type), sha1_to_hex(obj->sha1));
continue;
}
if (!obj->used) {
- printf("dangling %s %s\n", obj->type,
+ printf("dangling %s %s\n", typename(obj->type),
sha1_to_hex(obj->sha1));
}
}
if (!show_tags)
return 0;
- printf("tagged %s %s", tagged->type, sha1_to_hex(tagged->sha1));
+ printf("tagged %s %s", typename(tagged->type), sha1_to_hex(tagged->sha1));
printf(" (%s) in %s\n", tag->tag, sha1_to_hex(tag->object.sha1));
return 0;
}
if (obj->flags & SEEN)
return 0;
obj->flags |= SEEN;
- if (obj->type == blob_type)
+ if (obj->type == TYPE_BLOB)
return 0;
- if (obj->type == tree_type)
+ if (obj->type == TYPE_TREE)
return fsck_tree((struct tree *) obj);
- if (obj->type == commit_type)
+ if (obj->type == TYPE_COMMIT)
return fsck_commit((struct commit *) obj);
- if (obj->type == tag_type)
+ if (obj->type == TYPE_TAG)
return fsck_tag((struct tag *) obj);
/* By now, parse_object() would've returned NULL instead. */
- return objerror(obj, "unknown type '%s' (internal fsck error)", obj->type);
+ return objerror(obj, "unknown type '%d' (internal fsck error)", obj->type);
}
/*
}
mark_reachable(obj, REACHABLE);
obj->used = 1;
- if (obj->type != tree_type)
+ if (obj->type != TYPE_TREE)
err |= objerror(obj, "non-tree in cache-tree");
}
for (i = 0; i < it->subtree_nr; i++)
diff --git a/http-push.c b/http-push.c
index 2d9441ec60222be6806eddbd5e515b2233a4f06d..ba64f8fff58936ab59074b835b9df06eecf3031e 100644 (file)
--- a/http-push.c
+++ b/http-push.c
if (obj->flags & (UNINTERESTING | SEEN))
continue;
- if (obj->type == tag_type) {
+ if (obj->type == TYPE_TAG) {
obj->flags |= SEEN;
p = add_object(obj, p, NULL, name);
continue;
}
- if (obj->type == tree_type) {
+ if (obj->type == TYPE_TREE) {
p = process_tree((struct tree *)obj, p, NULL, name);
continue;
}
- if (obj->type == blob_type) {
+ if (obj->type == TYPE_BLOB) {
p = process_blob((struct blob *)obj, p, NULL, name);
continue;
}
* old. Otherwise we require --force.
*/
o = deref_tag(parse_object(old_sha1), NULL, 0);
- if (!o || o->type != commit_type)
+ if (!o || o->type != TYPE_COMMIT)
return 0;
old = (struct commit *) o;
o = deref_tag(parse_object(new_sha1), NULL, 0);
- if (!o || o->type != commit_type)
+ if (!o || o->type != TYPE_COMMIT)
return 0;
new = (struct commit *) o;
fwrite_buffer(ref_info, 1, len, buf);
free(ref_info);
- if (o->type == tag_type) {
+ if (o->type == TYPE_TAG) {
o = deref_tag(o, ls->dentry_name, 0);
if (o) {
len = strlen(ls->dentry_name) + 45;
diff --git a/name-rev.c b/name-rev.c
index bad8a5377771e678624d01895ca0603070d6bede..1f0135f5ab92a3eaadfb05b62a5ccea62cb43826 100644 (file)
--- a/name-rev.c
+++ b/name-rev.c
if (tags_only && strncmp(path, "refs/tags/", 10))
return 0;
- while (o && o->type == tag_type) {
+ while (o && o->type == TYPE_TAG) {
struct tag *t = (struct tag *) o;
if (!t->tagged)
break; /* broken repository */
o = parse_object(t->tagged->sha1);
deref = 1;
}
- if (o && o->type == commit_type) {
+ if (o && o->type == TYPE_COMMIT) {
struct commit *commit = (struct commit *)o;
if (!strncmp(path, "refs/heads/", 11))
}
o = deref_tag(parse_object(sha1), *argv, 0);
- if (!o || o->type != commit_type) {
+ if (!o || o->type != TYPE_COMMIT) {
fprintf(stderr, "Could not get commit for %s. Skipping.\n",
*argv);
continue;
diff --git a/object.c b/object.c
index 9adc87479bde2a0b2a0a0335aed12a9f485facff..0f70890a4582fec845fb9399b3dc9f388c6538fc 100644 (file)
--- a/object.c
+++ b/object.c
static int nr_objs;
int obj_allocs;
+const char *type_names[] = {
+ "none", "blob", "tree", "commit", "bad"
+};
+
int track_object_refs = 0;
static int hashtable_index(const unsigned char *sha1)
obj->parsed = 0;
memcpy(obj->sha1, sha1, 20);
- obj->type = NULL;
+ obj->type = TYPE_NONE;
obj->refs = NULL;
obj->used = 0;
if (!obj) {
union any_object *ret = xcalloc(1, sizeof(*ret));
created_object(sha1, &ret->object);
- ret->object.type = NULL;
+ ret->object.type = TYPE_NONE;
return &ret->object;
}
return obj;
diff --git a/object.h b/object.h
index e08afbd29ff04cf463a4aacdc4fe141a2ab54ce6..a0762b66725a1f8af45ea65147178b9130e2e056 100644 (file)
--- a/object.h
+++ b/object.h
struct object *ref[FLEX_ARRAY]; /* more */
};
+#define TYPE_BITS 3
+#define FLAG_BITS 27
+
+#define TYPE_NONE 0
+#define TYPE_BLOB 1
+#define TYPE_TREE 2
+#define TYPE_COMMIT 3
+#define TYPE_TAG 4
+#define TYPE_BAD 5
+
struct object {
unsigned parsed : 1;
unsigned used : 1;
- unsigned int flags;
+ unsigned type : TYPE_BITS;
+ unsigned flags : FLAG_BITS;
unsigned char sha1[20];
- const char *type;
struct object_refs *refs;
void *util;
};
extern int track_object_refs;
extern int obj_allocs;
extern struct object **objs;
+extern const char *type_names[];
+
+static inline const char *typename(unsigned int type)
+{
+ return type_names[type > TYPE_TAG ? TYPE_BAD : type];
+}
/** Internal only **/
struct object *lookup_object(const unsigned char *sha1);
diff --git a/revision.c b/revision.c
index 75c648c13c6c50335ffc3e79f5d6303bea20104e..82214eb71a96e75089dbe583eb4e2d06eb608550 100644 (file)
--- a/revision.c
+++ b/revision.c
@@ -140,7 +140,7 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object
/*
* Tag object? Look what it points to..
*/
- while (object->type == tag_type) {
+ while (object->type == TYPE_TAG) {
struct tag *tag = (struct tag *) object;
if (revs->tag_objects && !(flags & UNINTERESTING))
add_pending_object(revs, object, tag->tag);
@@ -153,7 +153,7 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object
* Commit object? Just return it, we'll do all the complex
* reachability crud.
*/
- if (object->type == commit_type) {
+ if (object->type == TYPE_COMMIT) {
struct commit *commit = (struct commit *)object;
if (parse_commit(commit) < 0)
die("unable to parse commit %s", name);
@@ -169,7 +169,7 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object
* Tree object? Either mark it uniniteresting, or add it
* to the list of objects to look at later..
*/
- if (object->type == tree_type) {
+ if (object->type == TYPE_TREE) {
struct tree *tree = (struct tree *)object;
if (!revs->tree_objects)
return NULL;
@@ -184,7 +184,7 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object
/*
* Blob object? You know the drill by now..
*/
- if (object->type == blob_type) {
+ if (object->type == TYPE_BLOB) {
struct blob *blob = (struct blob *)object;
if (!revs->blob_objects)
return NULL;
@@ -498,11 +498,11 @@ static int add_parents_only(struct rev_info *revs, const char *arg, int flags)
return 0;
while (1) {
it = get_reference(revs, arg, sha1, 0);
- if (strcmp(it->type, tag_type))
+ if (it->type != TYPE_TAG)
break;
memcpy(sha1, ((struct tag*)it)->tagged->sha1, 20);
}
- if (strcmp(it->type, commit_type))
+ if (it->type != TYPE_COMMIT)
return 0;
commit = (struct commit *)it;
for (parents = commit->parents; parents; parents = parents->next) {
diff --git a/send-pack.c b/send-pack.c
index 409f18850357567748f63f73ec84c066f9e3fe94..af93b11f238e4583f6e7fb9dab5a2224acf4ee1f 100644 (file)
--- a/send-pack.c
+++ b/send-pack.c
* old. Otherwise we require --force.
*/
o = deref_tag(parse_object(old_sha1), NULL, 0);
- if (!o || o->type != commit_type)
+ if (!o || o->type != TYPE_COMMIT)
return 0;
old = (struct commit *) o;
o = deref_tag(parse_object(new_sha1), NULL, 0);
- if (!o || o->type != commit_type)
+ if (!o || o->type != TYPE_COMMIT)
return 0;
new = (struct commit *) o;
diff --git a/server-info.c b/server-info.c
index 05bce7da3b4935675465f993c24bb1188439d6d9..0eb5132cc1cf09ea7dacdf659d3c03adae761acf 100644 (file)
--- a/server-info.c
+++ b/server-info.c
struct object *o = parse_object(sha1);
fprintf(info_ref_fp, "%s %s\n", sha1_to_hex(sha1), path);
- if (o->type == tag_type) {
+ if (o->type == TYPE_TAG) {
o = deref_tag(o, path, 0);
if (o)
fprintf(info_ref_fp, "%s %s^{}\n",
diff --git a/sha1_name.c b/sha1_name.c
index 8fe9b7a75f0f8c43744ce6c031d953f51481ecab..cd85d1fa0f9f2afb4e159cb635db435e75ef3e58 100644 (file)
--- a/sha1_name.c
+++ b/sha1_name.c
{
unsigned char outer[20];
const char *sp;
- const char *type_string = NULL;
+ unsigned int expected_type = 0;
struct object *o;
/*
sp++; /* beginning of type name, or closing brace for empty */
if (!strncmp(commit_type, sp, 6) && sp[6] == '}')
- type_string = commit_type;
+ expected_type = TYPE_COMMIT;
else if (!strncmp(tree_type, sp, 4) && sp[4] == '}')
- type_string = tree_type;
+ expected_type = TYPE_TREE;
else if (!strncmp(blob_type, sp, 4) && sp[4] == '}')
- type_string = blob_type;
+ expected_type = TYPE_BLOB;
else if (sp[0] == '}')
- type_string = NULL;
+ expected_type = TYPE_NONE;
else
return -1;
o = parse_object(outer);
if (!o)
return -1;
- if (!type_string) {
+ if (!expected_type) {
o = deref_tag(o, name, sp - name - 2);
if (!o || (!o->parsed && !parse_object(o->sha1)))
return -1;
while (1) {
if (!o || (!o->parsed && !parse_object(o->sha1)))
return -1;
- if (o->type == type_string) {
+ if (o->type == expected_type) {
memcpy(sha1, o->sha1, 20);
return 0;
}
- if (o->type == tag_type)
+ if (o->type == TYPE_TAG)
o = ((struct tag*) o)->tagged;
- else if (o->type == commit_type)
+ else if (o->type == TYPE_COMMIT)
o = &(((struct commit *) o)->tree->object);
else
return error("%.*s: expected %s type, but the object dereferences to %s type",
- len, name, type_string,
- o->type);
+ len, name, typename(expected_type),
+ typename(o->type));
if (!o->parsed)
parse_object(o->sha1);
}
index f390ee703036bc74d6447d7e96c828310a948c2b..91913332709eb67252a776ddd1995e183a1a5bf5 100644 (file)
--- a/tag.c
+++ b/tag.c
struct object *deref_tag(struct object *o, const char *warn, int warnlen)
{
- while (o && o->type == tag_type)
+ while (o && o->type == TYPE_TAG)
o = parse_object(((struct tag *)o)->tagged->sha1);
if (!o && warn) {
if (!warnlen)
if (!obj) {
struct tag *ret = xcalloc(1, sizeof(struct tag));
created_object(sha1, &ret->object);
- ret->object.type = tag_type;
+ ret->object.type = TYPE_TAG;
return ret;
}
if (!obj->type)
- obj->type = tag_type;
- if (obj->type != tag_type) {
- error("Object %s is a %s, not a tree",
- sha1_to_hex(sha1), obj->type);
+ obj->type = TYPE_TAG;
+ if (obj->type != TYPE_TAG) {
+ error("Object %s is a %s, not a tree",
+ sha1_to_hex(sha1), typename(obj->type));
return NULL;
}
return (struct tag *) obj;
index 9bbe2da37b24007b6409d5e1e5c61a20d0903628..64422fd27e3f855b7989bc8cb9a6a0ada7a30472 100644 (file)
--- a/tree.c
+++ b/tree.c
if (!obj) {
struct tree *ret = xcalloc(1, sizeof(struct tree));
created_object(sha1, &ret->object);
- ret->object.type = tree_type;
+ ret->object.type = TYPE_TREE;
return ret;
}
if (!obj->type)
- obj->type = tree_type;
- if (obj->type != tree_type) {
- error("Object %s is a %s, not a tree",
- sha1_to_hex(sha1), obj->type);
+ obj->type = TYPE_TREE;
+ if (obj->type != TYPE_TREE) {
+ error("Object %s is a %s, not a tree",
+ sha1_to_hex(sha1), typename(obj->type));
return NULL;
}
return (struct tree *) obj;
do {
if (!obj)
return NULL;
- if (obj->type == tree_type)
+ if (obj->type == TYPE_TREE)
return (struct tree *) obj;
- else if (obj->type == commit_type)
+ else if (obj->type == TYPE_COMMIT)
obj = &(((struct commit *) obj)->tree->object);
- else if (obj->type == tag_type)
+ else if (obj->type == TYPE_TAG)
obj = ((struct tag *) obj)->tagged;
else
return NULL;
diff --git a/upload-pack.c b/upload-pack.c
index 47560c9527b9c17db34f10e78d7c1f0d99b746e1..979e58306e46e5fdc005feb9d5a1bf44490fb5c1 100644 (file)
--- a/upload-pack.c
+++ b/upload-pack.c
o = parse_object(sha1);
if (!o)
die("oops (%s)", sha1_to_hex(sha1));
- if (o->type == commit_type) {
+ if (o->type == TYPE_COMMIT) {
struct commit_list *parents;
if (o->flags & THEY_HAVE)
return 0;
o->flags |= OUR_REF;
nr_our_refs++;
}
- if (o->type == tag_type) {
+ if (o->type == TYPE_TAG) {
o = deref_tag(o, refname, 0);
packet_write(1, "%s %s^{}\n", sha1_to_hex(o->sha1), refname);
}