Merge branch 'lt/unitype'

* lt/unitype:
  builtin-prune.c: forgot TYPE => OBJ changes.
  Remove TYPE_* constant macros and use object_type enums consistently.
This commit is contained in:
Junio C Hamano 2006-07-14 15:39:19 -07:00
commit 5cd060b56c
23 changed files with 90 additions and 95 deletions

6
blob.c
View File

@ -10,12 +10,12 @@ struct blob *lookup_blob(const unsigned char *sha1)
if (!obj) { if (!obj) {
struct blob *ret = alloc_blob_node(); struct blob *ret = alloc_blob_node();
created_object(sha1, &ret->object); created_object(sha1, &ret->object);
ret->object.type = TYPE_BLOB; ret->object.type = OBJ_BLOB;
return ret; return ret;
} }
if (!obj->type) if (!obj->type)
obj->type = TYPE_BLOB; obj->type = OBJ_BLOB;
if (obj->type != TYPE_BLOB) { if (obj->type != OBJ_BLOB) {
error("Object %s is a %s, not a blob", error("Object %s is a %s, not a blob",
sha1_to_hex(sha1), typename(obj->type)); sha1_to_hex(sha1), typename(obj->type));
return NULL; return NULL;

View File

@ -285,9 +285,9 @@ int cmd_diff(int argc, const char **argv, char **envp)
obj = deref_tag(obj, NULL, 0); obj = deref_tag(obj, NULL, 0);
if (!obj) if (!obj)
die("invalid object '%s' given.", name); die("invalid object '%s' given.", name);
if (obj->type == TYPE_COMMIT) if (obj->type == OBJ_COMMIT)
obj = &((struct commit *)obj)->tree->object; obj = &((struct commit *)obj)->tree->object;
if (obj->type == TYPE_TREE) { if (obj->type == OBJ_TREE) {
if (ARRAY_SIZE(ent) <= ents) if (ARRAY_SIZE(ent) <= ents)
die("more than %d trees given: '%s'", die("more than %d trees given: '%s'",
(int) ARRAY_SIZE(ent), name); (int) ARRAY_SIZE(ent), name);
@ -297,7 +297,7 @@ int cmd_diff(int argc, const char **argv, char **envp)
ents++; ents++;
continue; continue;
} }
if (obj->type == TYPE_BLOB) { if (obj->type == OBJ_BLOB) {
if (2 <= blobs) if (2 <= blobs)
die("more than two blobs given: '%s'", name); die("more than two blobs given: '%s'", name);
memcpy(blob[blobs].sha1, obj->sha1, 20); memcpy(blob[blobs].sha1, obj->sha1, 20);

View File

@ -181,7 +181,7 @@ static void shortlog(const char *name, unsigned char *sha1,
int flags = UNINTERESTING | TREECHANGE | SEEN | SHOWN | ADDED; int flags = UNINTERESTING | TREECHANGE | SEEN | SHOWN | ADDED;
branch = deref_tag(parse_object(sha1), sha1_to_hex(sha1), 40); branch = deref_tag(parse_object(sha1), sha1_to_hex(sha1), 40);
if (!branch || branch->type != TYPE_COMMIT) if (!branch || branch->type != OBJ_COMMIT)
return; return;
setup_revisions(0, NULL, rev, NULL); setup_revisions(0, NULL, rev, NULL);

View File

@ -891,9 +891,9 @@ static int grep_tree(struct grep_opt *opt, const char **paths,
static int grep_object(struct grep_opt *opt, const char **paths, static int grep_object(struct grep_opt *opt, const char **paths,
struct object *obj, const char *name) struct object *obj, const char *name)
{ {
if (obj->type == TYPE_BLOB) if (obj->type == OBJ_BLOB)
return grep_sha1(opt, obj->sha1, name); return grep_sha1(opt, obj->sha1, name);
if (obj->type == TYPE_COMMIT || obj->type == TYPE_TREE) { if (obj->type == OBJ_COMMIT || obj->type == OBJ_TREE) {
struct tree_desc tree; struct tree_desc tree;
void *data; void *data;
int hit; int hit;

View File

@ -158,15 +158,15 @@ static void walk_commit_list(struct rev_info *revs)
struct object_array_entry *pending = revs->pending.objects + i; struct object_array_entry *pending = revs->pending.objects + i;
struct object *obj = pending->item; struct object *obj = pending->item;
const char *name = pending->name; const char *name = pending->name;
if (obj->type == TYPE_TAG) { if (obj->type == OBJ_TAG) {
process_tag((struct tag *) obj, &objects, name); process_tag((struct tag *) obj, &objects, name);
continue; continue;
} }
if (obj->type == TYPE_TREE) { if (obj->type == OBJ_TREE) {
process_tree((struct tree *)obj, &objects, NULL, name); process_tree((struct tree *)obj, &objects, NULL, name);
continue; continue;
} }
if (obj->type == TYPE_BLOB) { if (obj->type == OBJ_BLOB) {
process_blob((struct blob *)obj, &objects, NULL, name); process_blob((struct blob *)obj, &objects, NULL, name);
continue; continue;
} }

View File

@ -167,16 +167,16 @@ static void show_commit_list(struct rev_info *revs)
const char *name = pending->name; const char *name = pending->name;
if (obj->flags & (UNINTERESTING | SEEN)) if (obj->flags & (UNINTERESTING | SEEN))
continue; continue;
if (obj->type == TYPE_TAG) { if (obj->type == OBJ_TAG) {
obj->flags |= SEEN; obj->flags |= SEEN;
add_object_array(obj, name, &objects); add_object_array(obj, name, &objects);
continue; continue;
} }
if (obj->type == TYPE_TREE) { if (obj->type == OBJ_TREE) {
process_tree((struct tree *)obj, &objects, NULL, name); process_tree((struct tree *)obj, &objects, NULL, name);
continue; continue;
} }
if (obj->type == TYPE_BLOB) { if (obj->type == OBJ_BLOB) {
process_blob((struct blob *)obj, &objects, NULL, name); process_blob((struct blob *)obj, &objects, NULL, name);
continue; continue;
} }

View File

@ -56,7 +56,7 @@ static struct commit *check_commit(struct object *obj,
const unsigned char *sha1, const unsigned char *sha1,
int quiet) int quiet)
{ {
if (obj->type != TYPE_COMMIT) { if (obj->type != OBJ_COMMIT) {
if (!quiet) if (!quiet)
error("Object %s is a %s, not a commit", error("Object %s is a %s, not a commit",
sha1_to_hex(sha1), typename(obj->type)); sha1_to_hex(sha1), typename(obj->type));
@ -86,11 +86,11 @@ struct commit *lookup_commit(const unsigned char *sha1)
if (!obj) { if (!obj) {
struct commit *ret = alloc_commit_node(); struct commit *ret = alloc_commit_node();
created_object(sha1, &ret->object); created_object(sha1, &ret->object);
ret->object.type = TYPE_COMMIT; ret->object.type = OBJ_COMMIT;
return ret; return ret;
} }
if (!obj->type) if (!obj->type)
obj->type = TYPE_COMMIT; obj->type = OBJ_COMMIT;
return check_commit(obj, sha1, 0); return check_commit(obj, sha1, 0);
} }

View File

@ -67,7 +67,7 @@ static int get_name(const char *path, const unsigned char *sha1)
* Otherwise only annotated tags are used. * Otherwise only annotated tags are used.
*/ */
if (!strncmp(path, "refs/tags/", 10)) { if (!strncmp(path, "refs/tags/", 10)) {
if (object->type == TYPE_TAG) if (object->type == OBJ_TAG)
prio = 2; prio = 2;
else else
prio = 1; prio = 1;

View File

@ -46,7 +46,7 @@ static int rev_list_insert_ref(const char *path, const unsigned char *sha1)
{ {
struct object *o = deref_tag(parse_object(sha1), path, 0); struct object *o = deref_tag(parse_object(sha1), path, 0);
if (o && o->type == TYPE_COMMIT) if (o && o->type == OBJ_COMMIT)
rev_list_push((struct commit *)o, SEEN); rev_list_push((struct commit *)o, SEEN);
return 0; return 0;
@ -256,14 +256,14 @@ static int mark_complete(const char *path, const unsigned char *sha1)
{ {
struct object *o = parse_object(sha1); struct object *o = parse_object(sha1);
while (o && o->type == TYPE_TAG) { while (o && o->type == OBJ_TAG) {
struct tag *t = (struct tag *) o; struct tag *t = (struct tag *) o;
if (!t->tagged) if (!t->tagged)
break; /* broken repository */ break; /* broken repository */
o->flags |= COMPLETE; o->flags |= COMPLETE;
o = parse_object(t->tagged->sha1); o = parse_object(t->tagged->sha1);
} }
if (o && o->type == TYPE_COMMIT) { if (o && o->type == OBJ_COMMIT) {
struct commit *commit = (struct commit *)o; struct commit *commit = (struct commit *)o;
commit->object.flags |= COMPLETE; commit->object.flags |= COMPLETE;
insert_by_date(commit, &complete); insert_by_date(commit, &complete);
@ -357,7 +357,7 @@ static int everything_local(struct ref **refs, int nr_match, char **match)
* in sync with the other side at some time after * in sync with the other side at some time after
* that (it is OK if we guess wrong here). * that (it is OK if we guess wrong here).
*/ */
if (o->type == TYPE_COMMIT) { if (o->type == OBJ_COMMIT) {
struct commit *commit = (struct commit *)o; struct commit *commit = (struct commit *)o;
if (!cutoff || cutoff < commit->date) if (!cutoff || cutoff < commit->date)
cutoff = commit->date; cutoff = commit->date;
@ -376,7 +376,7 @@ static int everything_local(struct ref **refs, int nr_match, char **match)
struct object *o = deref_tag(lookup_object(ref->old_sha1), struct object *o = deref_tag(lookup_object(ref->old_sha1),
NULL, 0); NULL, 0);
if (!o || o->type != TYPE_COMMIT || !(o->flags & COMPLETE)) if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE))
continue; continue;
if (!(o->flags & SEEN)) { if (!(o->flags & SEEN)) {

View File

@ -118,20 +118,20 @@ static struct object_list **process_queue_end = &process_queue;
static int process_object(struct object *obj) static int process_object(struct object *obj)
{ {
if (obj->type == TYPE_COMMIT) { if (obj->type == OBJ_COMMIT) {
if (process_commit((struct commit *)obj)) if (process_commit((struct commit *)obj))
return -1; return -1;
return 0; return 0;
} }
if (obj->type == TYPE_TREE) { if (obj->type == OBJ_TREE) {
if (process_tree((struct tree *)obj)) if (process_tree((struct tree *)obj))
return -1; return -1;
return 0; return 0;
} }
if (obj->type == TYPE_BLOB) { if (obj->type == OBJ_BLOB) {
return 0; return 0;
} }
if (obj->type == TYPE_TAG) { if (obj->type == OBJ_TAG) {
if (process_tag((struct tag *)obj)) if (process_tag((struct tag *)obj))
return -1; return -1;
return 0; return 0;

View File

@ -297,13 +297,13 @@ static int fsck_sha1(unsigned char *sha1)
if (obj->flags & SEEN) if (obj->flags & SEEN)
return 0; return 0;
obj->flags |= SEEN; obj->flags |= SEEN;
if (obj->type == TYPE_BLOB) if (obj->type == OBJ_BLOB)
return 0; return 0;
if (obj->type == TYPE_TREE) if (obj->type == OBJ_TREE)
return fsck_tree((struct tree *) obj); return fsck_tree((struct tree *) obj);
if (obj->type == TYPE_COMMIT) if (obj->type == OBJ_COMMIT)
return fsck_commit((struct commit *) obj); return fsck_commit((struct commit *) obj);
if (obj->type == TYPE_TAG) if (obj->type == OBJ_TAG)
return fsck_tag((struct tag *) obj); return fsck_tag((struct tag *) obj);
/* By now, parse_object() would've returned NULL instead. */ /* By now, parse_object() would've returned NULL instead. */
return objerror(obj, "unknown type '%d' (internal fsck error)", obj->type); return objerror(obj, "unknown type '%d' (internal fsck error)", obj->type);
@ -472,7 +472,7 @@ static int fsck_cache_tree(struct cache_tree *it)
} }
mark_reachable(obj, REACHABLE); mark_reachable(obj, REACHABLE);
obj->used = 1; obj->used = 1;
if (obj->type != TYPE_TREE) if (obj->type != OBJ_TREE)
err |= objerror(obj, "non-tree in cache-tree"); err |= objerror(obj, "non-tree in cache-tree");
} }
for (i = 0; i < it->subtree_nr; i++) for (i = 0; i < it->subtree_nr; i++)

View File

@ -1784,16 +1784,16 @@ static int get_delta(struct rev_info *revs, struct remote_lock *lock)
if (obj->flags & (UNINTERESTING | SEEN)) if (obj->flags & (UNINTERESTING | SEEN))
continue; continue;
if (obj->type == TYPE_TAG) { if (obj->type == OBJ_TAG) {
obj->flags |= SEEN; obj->flags |= SEEN;
p = add_one_object(obj, p); p = add_one_object(obj, p);
continue; continue;
} }
if (obj->type == TYPE_TREE) { if (obj->type == OBJ_TREE) {
p = process_tree((struct tree *)obj, p, NULL, name); p = process_tree((struct tree *)obj, p, NULL, name);
continue; continue;
} }
if (obj->type == TYPE_BLOB) { if (obj->type == OBJ_BLOB) {
p = process_blob((struct blob *)obj, p, NULL, name); p = process_blob((struct blob *)obj, p, NULL, name);
continue; continue;
} }
@ -1960,12 +1960,12 @@ static int ref_newer(const unsigned char *new_sha1,
* old. Otherwise we require --force. * old. Otherwise we require --force.
*/ */
o = deref_tag(parse_object(old_sha1), NULL, 0); o = deref_tag(parse_object(old_sha1), NULL, 0);
if (!o || o->type != TYPE_COMMIT) if (!o || o->type != OBJ_COMMIT)
return 0; return 0;
old = (struct commit *) o; old = (struct commit *) o;
o = deref_tag(parse_object(new_sha1), NULL, 0); o = deref_tag(parse_object(new_sha1), NULL, 0);
if (!o || o->type != TYPE_COMMIT) if (!o || o->type != OBJ_COMMIT)
return 0; return 0;
new = (struct commit *) o; new = (struct commit *) o;
@ -2044,7 +2044,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
fwrite_buffer(ref_info, 1, len, buf); fwrite_buffer(ref_info, 1, len, buf);
free(ref_info); free(ref_info);
if (o->type == TYPE_TAG) { if (o->type == OBJ_TAG) {
o = deref_tag(o, ls->dentry_name, 0); o = deref_tag(o, ls->dentry_name, 0);
if (o) { if (o) {
len = strlen(ls->dentry_name) + 45; len = strlen(ls->dentry_name) + 45;

View File

@ -84,14 +84,14 @@ static int name_ref(const char *path, const unsigned char *sha1)
if (tags_only && strncmp(path, "refs/tags/", 10)) if (tags_only && strncmp(path, "refs/tags/", 10))
return 0; return 0;
while (o && o->type == TYPE_TAG) { while (o && o->type == OBJ_TAG) {
struct tag *t = (struct tag *) o; struct tag *t = (struct tag *) o;
if (!t->tagged) if (!t->tagged)
break; /* broken repository */ break; /* broken repository */
o = parse_object(t->tagged->sha1); o = parse_object(t->tagged->sha1);
deref = 1; deref = 1;
} }
if (o && o->type == TYPE_COMMIT) { if (o && o->type == OBJ_COMMIT) {
struct commit *commit = (struct commit *)o; struct commit *commit = (struct commit *)o;
if (!strncmp(path, "refs/heads/", 11)) if (!strncmp(path, "refs/heads/", 11))
@ -111,7 +111,7 @@ static const char* get_rev_name(struct object *o)
struct rev_name *n; struct rev_name *n;
struct commit *c; struct commit *c;
if (o->type != TYPE_COMMIT) if (o->type != OBJ_COMMIT)
return "undefined"; return "undefined";
c = (struct commit *) o; c = (struct commit *) o;
n = c->util; n = c->util;
@ -172,7 +172,7 @@ int main(int argc, char **argv)
} }
o = deref_tag(parse_object(sha1), *argv, 0); o = deref_tag(parse_object(sha1), *argv, 0);
if (!o || o->type != TYPE_COMMIT) { if (!o || o->type != OBJ_COMMIT) {
fprintf(stderr, "Could not get commit for %s. Skipping.\n", fprintf(stderr, "Could not get commit for %s. Skipping.\n",
*argv); *argv);
continue; continue;

View File

@ -19,7 +19,8 @@ struct object *get_indexed_object(unsigned int idx)
} }
const char *type_names[] = { const char *type_names[] = {
"none", "blob", "tree", "commit", "bad" "none", "commit", "tree", "blob", "tag",
"bad type 5", "bad type 6", "delta", "bad",
}; };
static unsigned int hash_obj(struct object *obj, unsigned int n) static unsigned int hash_obj(struct object *obj, unsigned int n)
@ -88,7 +89,7 @@ void created_object(const unsigned char *sha1, struct object *obj)
{ {
obj->parsed = 0; obj->parsed = 0;
obj->used = 0; obj->used = 0;
obj->type = TYPE_NONE; obj->type = OBJ_NONE;
obj->flags = 0; obj->flags = 0;
memcpy(obj->sha1, sha1, 20); memcpy(obj->sha1, sha1, 20);
@ -131,7 +132,7 @@ struct object *lookup_unknown_object(const unsigned char *sha1)
if (!obj) { if (!obj) {
union any_object *ret = xcalloc(1, sizeof(*ret)); union any_object *ret = xcalloc(1, sizeof(*ret));
created_object(sha1, &ret->object); created_object(sha1, &ret->object);
ret->object.type = TYPE_NONE; ret->object.type = OBJ_NONE;
return &ret->object; return &ret->object;
} }
return obj; return obj;

View File

@ -24,12 +24,19 @@ struct object_array {
#define TYPE_BITS 3 #define TYPE_BITS 3
#define FLAG_BITS 27 #define FLAG_BITS 27
#define TYPE_NONE 0 /*
#define TYPE_BLOB 1 * The object type is stored in 3 bits.
#define TYPE_TREE 2 */
#define TYPE_COMMIT 3 enum object_type {
#define TYPE_TAG 4 OBJ_NONE = 0,
#define TYPE_BAD 5 OBJ_COMMIT = 1,
OBJ_TREE = 2,
OBJ_BLOB = 3,
OBJ_TAG = 4,
/* 5/6 for future expansion */
OBJ_DELTA = 7,
OBJ_BAD,
};
struct object { struct object {
unsigned parsed : 1; unsigned parsed : 1;
@ -40,14 +47,14 @@ struct object {
}; };
extern int track_object_refs; extern int track_object_refs;
extern const char *type_names[]; extern const char *type_names[9];
extern unsigned int get_max_object_index(void); extern unsigned int get_max_object_index(void);
extern struct object *get_indexed_object(unsigned int); extern struct object *get_indexed_object(unsigned int);
static inline const char *typename(unsigned int type) static inline const char *typename(unsigned int type)
{ {
return type_names[type > TYPE_TAG ? TYPE_BAD : type]; return type_names[type > OBJ_BAD ? OBJ_BAD : type];
} }
extern struct object_refs *lookup_object_refs(struct object *); extern struct object_refs *lookup_object_refs(struct object *);

15
pack.h
View File

@ -1,20 +1,7 @@
#ifndef PACK_H #ifndef PACK_H
#define PACK_H #define PACK_H
/* #include "object.h"
* The packed object type is stored in 3 bits.
* The type value 0 is a reserved prefix if ever there is more than 7
* object types, or any future format extensions.
*/
enum object_type {
OBJ_EXT = 0,
OBJ_COMMIT = 1,
OBJ_TREE = 2,
OBJ_BLOB = 3,
OBJ_TAG = 4,
/* 5/6 for future expansion */
OBJ_DELTA = 7,
};
/* /*
* Packed object header * Packed object header

View File

@ -135,7 +135,7 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object
/* /*
* Tag object? Look what it points to.. * Tag object? Look what it points to..
*/ */
while (object->type == TYPE_TAG) { while (object->type == OBJ_TAG) {
struct tag *tag = (struct tag *) object; struct tag *tag = (struct tag *) object;
if (revs->tag_objects && !(flags & UNINTERESTING)) if (revs->tag_objects && !(flags & UNINTERESTING))
add_pending_object(revs, object, tag->tag); add_pending_object(revs, object, tag->tag);
@ -148,7 +148,7 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object
* Commit object? Just return it, we'll do all the complex * Commit object? Just return it, we'll do all the complex
* reachability crud. * reachability crud.
*/ */
if (object->type == TYPE_COMMIT) { if (object->type == OBJ_COMMIT) {
struct commit *commit = (struct commit *)object; struct commit *commit = (struct commit *)object;
if (parse_commit(commit) < 0) if (parse_commit(commit) < 0)
die("unable to parse commit %s", name); die("unable to parse commit %s", name);
@ -164,7 +164,7 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object
* Tree object? Either mark it uniniteresting, or add it * Tree object? Either mark it uniniteresting, or add it
* to the list of objects to look at later.. * to the list of objects to look at later..
*/ */
if (object->type == TYPE_TREE) { if (object->type == OBJ_TREE) {
struct tree *tree = (struct tree *)object; struct tree *tree = (struct tree *)object;
if (!revs->tree_objects) if (!revs->tree_objects)
return NULL; return NULL;
@ -179,7 +179,7 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object
/* /*
* Blob object? You know the drill by now.. * Blob object? You know the drill by now..
*/ */
if (object->type == TYPE_BLOB) { if (object->type == OBJ_BLOB) {
struct blob *blob = (struct blob *)object; struct blob *blob = (struct blob *)object;
if (!revs->blob_objects) if (!revs->blob_objects)
return NULL; return NULL;
@ -494,11 +494,11 @@ static int add_parents_only(struct rev_info *revs, const char *arg, int flags)
return 0; return 0;
while (1) { while (1) {
it = get_reference(revs, arg, sha1, 0); it = get_reference(revs, arg, sha1, 0);
if (it->type != TYPE_TAG) if (it->type != OBJ_TAG)
break; break;
memcpy(sha1, ((struct tag*)it)->tagged->sha1, 20); memcpy(sha1, ((struct tag*)it)->tagged->sha1, 20);
} }
if (it->type != TYPE_COMMIT) if (it->type != OBJ_COMMIT)
return 0; return 0;
commit = (struct commit *)it; commit = (struct commit *)it;
for (parents = commit->parents; parents; parents = parents->next) { for (parents = commit->parents; parents; parents = parents->next) {

View File

@ -151,12 +151,12 @@ static int ref_newer(const unsigned char *new_sha1,
* old. Otherwise we require --force. * old. Otherwise we require --force.
*/ */
o = deref_tag(parse_object(old_sha1), NULL, 0); o = deref_tag(parse_object(old_sha1), NULL, 0);
if (!o || o->type != TYPE_COMMIT) if (!o || o->type != OBJ_COMMIT)
return 0; return 0;
old = (struct commit *) o; old = (struct commit *) o;
o = deref_tag(parse_object(new_sha1), NULL, 0); o = deref_tag(parse_object(new_sha1), NULL, 0);
if (!o || o->type != TYPE_COMMIT) if (!o || o->type != OBJ_COMMIT)
return 0; return 0;
new = (struct commit *) o; new = (struct commit *) o;

View File

@ -12,7 +12,7 @@ static int add_info_ref(const char *path, const unsigned char *sha1)
struct object *o = parse_object(sha1); struct object *o = parse_object(sha1);
fprintf(info_ref_fp, "%s %s\n", sha1_to_hex(sha1), path); fprintf(info_ref_fp, "%s %s\n", sha1_to_hex(sha1), path);
if (o->type == TYPE_TAG) { if (o->type == OBJ_TAG) {
o = deref_tag(o, path, 0); o = deref_tag(o, path, 0);
if (o) if (o)
fprintf(info_ref_fp, "%s %s^{}\n", fprintf(info_ref_fp, "%s %s^{}\n",

View File

@ -381,13 +381,13 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
sp++; /* beginning of type name, or closing brace for empty */ sp++; /* beginning of type name, or closing brace for empty */
if (!strncmp(commit_type, sp, 6) && sp[6] == '}') if (!strncmp(commit_type, sp, 6) && sp[6] == '}')
expected_type = TYPE_COMMIT; expected_type = OBJ_COMMIT;
else if (!strncmp(tree_type, sp, 4) && sp[4] == '}') else if (!strncmp(tree_type, sp, 4) && sp[4] == '}')
expected_type = TYPE_TREE; expected_type = OBJ_TREE;
else if (!strncmp(blob_type, sp, 4) && sp[4] == '}') else if (!strncmp(blob_type, sp, 4) && sp[4] == '}')
expected_type = TYPE_BLOB; expected_type = OBJ_BLOB;
else if (sp[0] == '}') else if (sp[0] == '}')
expected_type = TYPE_NONE; expected_type = OBJ_NONE;
else else
return -1; return -1;
@ -416,9 +416,9 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
memcpy(sha1, o->sha1, 20); memcpy(sha1, o->sha1, 20);
return 0; return 0;
} }
if (o->type == TYPE_TAG) if (o->type == OBJ_TAG)
o = ((struct tag*) o)->tagged; o = ((struct tag*) o)->tagged;
else if (o->type == TYPE_COMMIT) else if (o->type == OBJ_COMMIT)
o = &(((struct commit *) o)->tree->object); o = &(((struct commit *) o)->tree->object);
else else
return error("%.*s: expected %s type, but the object dereferences to %s type", return error("%.*s: expected %s type, but the object dereferences to %s type",

8
tag.c
View File

@ -5,7 +5,7 @@ const char *tag_type = "tag";
struct object *deref_tag(struct object *o, const char *warn, int warnlen) struct object *deref_tag(struct object *o, const char *warn, int warnlen)
{ {
while (o && o->type == TYPE_TAG) while (o && o->type == OBJ_TAG)
o = parse_object(((struct tag *)o)->tagged->sha1); o = parse_object(((struct tag *)o)->tagged->sha1);
if (!o && warn) { if (!o && warn) {
if (!warnlen) if (!warnlen)
@ -21,12 +21,12 @@ struct tag *lookup_tag(const unsigned char *sha1)
if (!obj) { if (!obj) {
struct tag *ret = alloc_tag_node(); struct tag *ret = alloc_tag_node();
created_object(sha1, &ret->object); created_object(sha1, &ret->object);
ret->object.type = TYPE_TAG; ret->object.type = OBJ_TAG;
return ret; return ret;
} }
if (!obj->type) if (!obj->type)
obj->type = TYPE_TAG; obj->type = OBJ_TAG;
if (obj->type != TYPE_TAG) { if (obj->type != OBJ_TAG) {
error("Object %s is a %s, not a tree", error("Object %s is a %s, not a tree",
sha1_to_hex(sha1), typename(obj->type)); sha1_to_hex(sha1), typename(obj->type));
return NULL; return NULL;

12
tree.c
View File

@ -131,12 +131,12 @@ struct tree *lookup_tree(const unsigned char *sha1)
if (!obj) { if (!obj) {
struct tree *ret = alloc_tree_node(); struct tree *ret = alloc_tree_node();
created_object(sha1, &ret->object); created_object(sha1, &ret->object);
ret->object.type = TYPE_TREE; ret->object.type = OBJ_TREE;
return ret; return ret;
} }
if (!obj->type) if (!obj->type)
obj->type = TYPE_TREE; obj->type = OBJ_TREE;
if (obj->type != TYPE_TREE) { if (obj->type != OBJ_TREE) {
error("Object %s is a %s, not a tree", error("Object %s is a %s, not a tree",
sha1_to_hex(sha1), typename(obj->type)); sha1_to_hex(sha1), typename(obj->type));
return NULL; return NULL;
@ -216,11 +216,11 @@ struct tree *parse_tree_indirect(const unsigned char *sha1)
do { do {
if (!obj) if (!obj)
return NULL; return NULL;
if (obj->type == TYPE_TREE) if (obj->type == OBJ_TREE)
return (struct tree *) obj; return (struct tree *) obj;
else if (obj->type == TYPE_COMMIT) else if (obj->type == OBJ_COMMIT)
obj = &(((struct commit *) obj)->tree->object); obj = &(((struct commit *) obj)->tree->object);
else if (obj->type == TYPE_TAG) else if (obj->type == OBJ_TAG)
obj = ((struct tag *) obj)->tagged; obj = ((struct tag *) obj)->tagged;
else else
return NULL; return NULL;

View File

@ -330,7 +330,7 @@ static int got_sha1(char *hex, unsigned char *sha1)
o = parse_object(sha1); o = parse_object(sha1);
if (!o) if (!o)
die("oops (%s)", sha1_to_hex(sha1)); die("oops (%s)", sha1_to_hex(sha1));
if (o->type == TYPE_COMMIT) { if (o->type == OBJ_COMMIT) {
struct commit_list *parents; struct commit_list *parents;
if (o->flags & THEY_HAVE) if (o->flags & THEY_HAVE)
return 0; return 0;
@ -461,7 +461,7 @@ static int send_ref(const char *refname, const unsigned char *sha1)
o->flags |= OUR_REF; o->flags |= OUR_REF;
nr_our_refs++; nr_our_refs++;
} }
if (o->type == TYPE_TAG) { if (o->type == OBJ_TAG) {
o = deref_tag(o, refname, 0); o = deref_tag(o, refname, 0);
packet_write(1, "%s %s^{}\n", sha1_to_hex(o->sha1), refname); packet_write(1, "%s %s^{}\n", sha1_to_hex(o->sha1), refname);
} }