diff options
author | Nicolas Pitre <nico@cam.org> | 2007-02-26 14:55:59 -0500 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2007-02-27 01:34:21 -0800 |
commit | 21666f1aae4e890d8f50924f9e80763b27e6a45d (patch) | |
tree | 462de5be3e949924f58858e08e24355f613191ab | |
parent | formalize typename(), and add its reverse type_from_string() (diff) | |
download | tgif-21666f1aae4e890d8f50924f9e80763b27e6a45d.tar.xz |
convert object type handling from a string to a number
We currently have two parallel notation for dealing with object types
in the code: a string and a numerical value. One of them is obviously
redundent, and the most used one requires more stack space and a bunch
of strcmp() all over the place.
This is an initial step for the removal of the version using a char array
found in object reading code paths. The patch is unfortunately large but
there is no sane way to split it in smaller parts without breaking the
system.
Signed-off-by: Nicolas Pitre <nico@cam.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
-rw-r--r-- | archive-tar.c | 4 | ||||
-rw-r--r-- | archive-zip.c | 4 | ||||
-rw-r--r-- | blob.c | 6 | ||||
-rw-r--r-- | builtin-apply.c | 8 | ||||
-rw-r--r-- | builtin-blame.c | 18 | ||||
-rw-r--r-- | builtin-cat-file.c | 19 | ||||
-rw-r--r-- | builtin-commit-tree.c | 7 | ||||
-rw-r--r-- | builtin-for-each-ref.c | 4 | ||||
-rw-r--r-- | builtin-grep.c | 8 | ||||
-rw-r--r-- | builtin-log.c | 4 | ||||
-rw-r--r-- | builtin-pack-objects.c | 32 | ||||
-rw-r--r-- | builtin-prune.c | 11 | ||||
-rw-r--r-- | builtin-reflog.c | 4 | ||||
-rw-r--r-- | builtin-unpack-objects.c | 39 | ||||
-rw-r--r-- | cache.h | 36 | ||||
-rw-r--r-- | combine-diff.c | 6 | ||||
-rw-r--r-- | commit.c | 6 | ||||
-rw-r--r-- | convert-objects.c | 12 | ||||
-rw-r--r-- | diff.c | 7 | ||||
-rw-r--r-- | entry.c | 6 | ||||
-rw-r--r-- | fast-import.c | 18 | ||||
-rw-r--r-- | http-push.c | 6 | ||||
-rw-r--r-- | index-pack.c | 10 | ||||
-rw-r--r-- | merge-file.c | 10 | ||||
-rw-r--r-- | merge-recursive.c | 14 | ||||
-rw-r--r-- | merge-tree.c | 8 | ||||
-rw-r--r-- | mktag.c | 8 | ||||
-rw-r--r-- | mktree.c | 9 | ||||
-rw-r--r-- | object.c | 16 | ||||
-rw-r--r-- | object.h | 2 | ||||
-rw-r--r-- | pack-check.c | 14 | ||||
-rw-r--r-- | read-cache.c | 4 | ||||
-rw-r--r-- | sha1_file.c | 172 | ||||
-rw-r--r-- | tag.c | 6 | ||||
-rw-r--r-- | tree-diff.c | 6 | ||||
-rw-r--r-- | tree.c | 6 | ||||
-rw-r--r-- | unpack-file.c | 6 |
37 files changed, 266 insertions, 290 deletions
diff --git a/archive-tar.c b/archive-tar.c index 7d52a061f4..d9c30d33dc 100644 --- a/archive-tar.c +++ b/archive-tar.c @@ -262,7 +262,7 @@ static int write_tar_entry(const unsigned char *sha1, static struct strbuf path; int filenamelen = strlen(filename); void *buffer; - char type[20]; + enum object_type type; unsigned long size; if (!path.alloc) { @@ -283,7 +283,7 @@ static int write_tar_entry(const unsigned char *sha1, buffer = NULL; size = 0; } else { - buffer = read_sha1_file(sha1, type, &size); + buffer = read_sha1_file(sha1, &type, &size); if (!buffer) die("cannot read %s", sha1_to_hex(sha1)); } diff --git a/archive-zip.c b/archive-zip.c index f31b8ed823..7c4984886f 100644 --- a/archive-zip.c +++ b/archive-zip.c @@ -167,7 +167,7 @@ static int write_zip_entry(const unsigned char *sha1, int pathlen; unsigned char *out; char *path; - char type[20]; + enum object_type type; void *buffer = NULL; void *deflated = NULL; @@ -195,7 +195,7 @@ static int write_zip_entry(const unsigned char *sha1, if (S_ISREG(mode) && zlib_compression_level != 0) method = 8; result = 0; - buffer = read_sha1_file(sha1, type, &size); + buffer = read_sha1_file(sha1, &type, &size); if (!buffer) die("cannot read %s", sha1_to_hex(sha1)); crc = crc32(crc, buffer, size); @@ -30,18 +30,18 @@ int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size) int parse_blob(struct blob *item) { - char type[20]; + enum object_type type; void *buffer; unsigned long size; int ret; if (item->object.parsed) return 0; - buffer = read_sha1_file(item->object.sha1, type, &size); + buffer = read_sha1_file(item->object.sha1, &type, &size); if (!buffer) return error("Could not read %s", sha1_to_hex(item->object.sha1)); - if (strcmp(type, blob_type)) + if (type != OBJ_BLOB) return error("Object %s not a blob", sha1_to_hex(item->object.sha1)); ret = parse_blob_buffer(item, buffer, size); diff --git a/builtin-apply.c b/builtin-apply.c index b84d747e3f..38f647510a 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -1912,11 +1912,11 @@ static int apply_binary(struct buffer_desc *desc, struct patch *patch) if (has_sha1_file(sha1)) { /* We already have the postimage */ - char type[10]; + enum object_type type; unsigned long size; free(desc->buffer); - desc->buffer = read_sha1_file(sha1, type, &size); + desc->buffer = read_sha1_file(sha1, &type, &size); if (!desc->buffer) return error("the necessary postimage %s for " "'%s' cannot be read", @@ -1972,8 +1972,8 @@ static int apply_data(struct patch *patch, struct stat *st, struct cache_entry * buf = NULL; if (cached) { if (ce) { - char type[20]; - buf = read_sha1_file(ce->sha1, type, &size); + enum object_type type; + buf = read_sha1_file(ce->sha1, &type, &size); if (!buf) return error("read of %s failed", patch->old_name); diff --git a/builtin-blame.c b/builtin-blame.c index 530b97f97d..9f7dd4e19f 100644 --- a/builtin-blame.c +++ b/builtin-blame.c @@ -87,9 +87,9 @@ struct origin { static char *fill_origin_blob(struct origin *o, mmfile_t *file) { if (!o->file.ptr) { - char type[10]; + enum object_type type; num_read_blob++; - file->ptr = read_sha1_file(o->blob_sha1, type, + file->ptr = read_sha1_file(o->blob_sha1, &type, (unsigned long *)(&(file->size))); o->file = *file; } @@ -263,7 +263,6 @@ static struct origin *get_origin(struct scoreboard *sb, static int fill_blob_sha1(struct origin *origin) { unsigned mode; - char type[10]; if (!is_null_sha1(origin->blob_sha1)) return 0; @@ -271,8 +270,7 @@ static int fill_blob_sha1(struct origin *origin) origin->path, origin->blob_sha1, &mode)) goto error_out; - if (sha1_object_info(origin->blob_sha1, type, NULL) || - strcmp(type, blob_type)) + if (sha1_object_info(origin->blob_sha1, NULL) != OBJ_BLOB) goto error_out; return 0; error_out: @@ -1322,10 +1320,10 @@ static void get_commit_info(struct commit *commit, * we now need to populate them for output. */ if (!commit->buffer) { - char type[20]; + enum object_type type; unsigned long size; commit->buffer = - read_sha1_file(commit->object.sha1, type, &size); + read_sha1_file(commit->object.sha1, &type, &size); } ret->author = author_buf; get_ac_line(commit->buffer, "\nauthor ", @@ -2006,7 +2004,7 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con buf[fin_size] = 0; origin->file.ptr = buf; origin->file.size = fin_size; - pretend_sha1_file(buf, fin_size, blob_type, origin->blob_sha1); + pretend_sha1_file(buf, fin_size, OBJ_BLOB, origin->blob_sha1); commit->util = origin; /* @@ -2068,7 +2066,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix) int show_stats = 0; const char *revs_file = NULL; const char *final_commit_name = NULL; - char type[10]; + enum object_type type; const char *bottomtop = NULL; const char *contents_from = NULL; @@ -2302,7 +2300,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix) if (fill_blob_sha1(o)) die("no such path %s in %s", path, final_commit_name); - sb.final_buf = read_sha1_file(o->blob_sha1, type, + sb.final_buf = read_sha1_file(o->blob_sha1, &type, &sb.final_buf_size); } num_read_blob++; diff --git a/builtin-cat-file.c b/builtin-cat-file.c index 6c16bfa1ae..d61d3d5b74 100644 --- a/builtin-cat-file.c +++ b/builtin-cat-file.c @@ -79,7 +79,7 @@ static void pprint_tag(const unsigned char *sha1, const char *buf, unsigned long int cmd_cat_file(int argc, const char **argv, const char *prefix) { unsigned char sha1[20]; - char type[20]; + enum object_type type; void *buf; unsigned long size; int opt; @@ -100,14 +100,16 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix) buf = NULL; switch (opt) { case 't': - if (!sha1_object_info(sha1, type, NULL)) { - printf("%s\n", type); + type = sha1_object_info(sha1, NULL); + if (type > 0) { + printf("%s\n", typename(type)); return 0; } break; case 's': - if (!sha1_object_info(sha1, type, &size)) { + type = sha1_object_info(sha1, &size); + if (type > 0) { printf("%lu\n", size); return 0; } @@ -117,17 +119,18 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix) return !has_sha1_file(sha1); case 'p': - if (sha1_object_info(sha1, type, NULL)) + type = sha1_object_info(sha1, NULL); + if (type < 0) die("Not a valid object name %s", argv[2]); /* custom pretty-print here */ - if (!strcmp(type, tree_type)) + if (type == OBJ_TREE) return cmd_ls_tree(2, argv + 1, NULL); - buf = read_sha1_file(sha1, type, &size); + buf = read_sha1_file(sha1, &type, &size); if (!buf) die("Cannot read object %s", argv[2]); - if (!strcmp(type, tag_type)) { + if (type == OBJ_TAG) { pprint_tag(sha1, buf, size); return 0; } diff --git a/builtin-commit-tree.c b/builtin-commit-tree.c index 2a818a0a2c..04f61d5101 100644 --- a/builtin-commit-tree.c +++ b/builtin-commit-tree.c @@ -47,11 +47,10 @@ static void add_buffer(char **bufp, unsigned int *sizep, const char *fmt, ...) static void check_valid(unsigned char *sha1, const char *expect) { - char type[20]; - - if (sha1_object_info(sha1, type, NULL)) + enum object_type type = sha1_object_info(sha1, NULL); + if (type < 0) die("%s is not a valid object", sha1_to_hex(sha1)); - if (expect && strcmp(type, expect)) + if (expect && type != type_from_string(expect)) die("%s is not a valid '%s' object", sha1_to_hex(sha1), expect); } diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c index 14fff2b1c5..b11ca928d6 100644 --- a/builtin-for-each-ref.c +++ b/builtin-for-each-ref.c @@ -173,8 +173,8 @@ static void verify_format(const char *format) */ static void *get_obj(const unsigned char *sha1, struct object **obj, unsigned long *sz, int *eaten) { - char type[20]; - void *buf = read_sha1_file(sha1, type, sz); + enum object_type type; + void *buf = read_sha1_file(sha1, &type, sz); if (buf) *obj = parse_object_buffer(sha1, type, *sz, buf, eaten); diff --git a/builtin-grep.c b/builtin-grep.c index f35f2d023c..96b70227cf 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -84,11 +84,11 @@ static int grep_sha1(struct grep_opt *opt, const unsigned char *sha1, const char { unsigned long size; char *data; - char type[20]; + enum object_type type; char *to_free = NULL; int hit; - data = read_sha1_file(sha1, type, &size); + data = read_sha1_file(sha1, &type, &size); if (!data) { error("'%s': unable to read %s", name, sha1_to_hex(sha1)); return 0; @@ -380,10 +380,10 @@ static int grep_tree(struct grep_opt *opt, const char **paths, else if (S_ISREG(entry.mode)) hit |= grep_sha1(opt, entry.sha1, path_buf, tn_len); else if (S_ISDIR(entry.mode)) { - char type[20]; + enum object_type type; struct tree_desc sub; void *data; - data = read_sha1_file(entry.sha1, type, &sub.size); + data = read_sha1_file(entry.sha1, &type, &sub.size); if (!data) die("unable to read tree (%s)", sha1_to_hex(entry.sha1)); diff --git a/builtin-log.c b/builtin-log.c index f43790cbce..1c9f7d02a8 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -89,8 +89,8 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix) static int show_object(const unsigned char *sha1, int suppress_header) { unsigned long size; - char type[20]; - char *buf = read_sha1_file(sha1, type, &size); + enum object_type type; + char *buf = read_sha1_file(sha1, &type, &size); int offset = 0; if (!buf) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index 1c04618915..8cf24f4079 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -230,8 +230,8 @@ static unsigned char *find_packed_object_name(struct packed_git *p, static void *delta_against(void *buf, unsigned long size, struct object_entry *entry) { unsigned long othersize, delta_size; - char type[10]; - void *otherbuf = read_sha1_file(entry->delta->sha1, type, &othersize); + enum object_type type; + void *otherbuf = read_sha1_file(entry->delta->sha1, &type, &othersize); void *delta_buf; if (!otherbuf) @@ -375,7 +375,7 @@ static unsigned long write_object(struct sha1file *f, struct object_entry *entry) { unsigned long size; - char type[10]; + enum object_type type; void *buf; unsigned char header[10]; unsigned hdrlen, datalen; @@ -416,7 +416,7 @@ static unsigned long write_object(struct sha1file *f, } if (!to_reuse) { - buf = read_sha1_file(entry->sha1, type, &size); + buf = read_sha1_file(entry->sha1, &type, &size); if (!buf) die("unable to read %s", sha1_to_hex(entry->sha1)); if (size != entry->size) @@ -765,7 +765,7 @@ static struct pbase_tree_cache *pbase_tree_get(const unsigned char *sha1) struct pbase_tree_cache *ent, *nent; void *data; unsigned long size; - char type[20]; + enum object_type type; int neigh; int my_ix = pbase_tree_cache_ix(sha1); int available_ix = -1; @@ -792,10 +792,10 @@ static struct pbase_tree_cache *pbase_tree_get(const unsigned char *sha1) /* Did not find one. Either we got a bogus request or * we need to read and perhaps cache. */ - data = read_sha1_file(sha1, type, &size); + data = read_sha1_file(sha1, &type, &size); if (!data) return NULL; - if (strcmp(type, tree_type)) { + if (type != OBJ_TREE) { free(data); return NULL; } @@ -854,19 +854,19 @@ static void add_pbase_object(struct tree_desc *tree, while (tree_entry(tree,&entry)) { unsigned long size; - char type[20]; + enum object_type type; if (entry.pathlen != cmplen || memcmp(entry.path, name, cmplen) || !has_sha1_file(entry.sha1) || - sha1_object_info(entry.sha1, type, &size)) + (type = sha1_object_info(entry.sha1, &size)) < 0) continue; if (name[cmplen] != '/') { unsigned hash = name_hash(fullname); add_object_entry(entry.sha1, hash, 1); return; } - if (!strcmp(type, tree_type)) { + if (type == OBJ_TREE) { struct tree_desc sub; struct pbase_tree_cache *tree; const char *down = name+cmplen+1; @@ -978,8 +978,6 @@ static void add_preferred_base(unsigned char *sha1) static void check_object(struct object_entry *entry) { - char type[20]; - if (entry->in_pack && !entry->preferred_base) { struct packed_git *p = entry->in_pack; struct pack_window *w_curs = NULL; @@ -1062,10 +1060,10 @@ static void check_object(struct object_entry *entry) /* Otherwise we would do the usual */ } - if (sha1_object_info(entry->sha1, type, &entry->size)) + entry->type = sha1_object_info(entry->sha1, &entry->size); + if (entry->type < 0) die("unable to get type of object %s", sha1_to_hex(entry->sha1)); - entry->type = type_from_string(type); } static unsigned int check_delta_limit(struct object_entry *me, unsigned int n) @@ -1195,7 +1193,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src, struct object_entry *trg_entry = trg->entry; struct object_entry *src_entry = src->entry; unsigned long trg_size, src_size, delta_size, sizediff, max_size, sz; - char type[10]; + enum object_type type; void *delta_buf; /* Don't bother doing diffs between different types */ @@ -1246,13 +1244,13 @@ static int try_delta(struct unpacked *trg, struct unpacked *src, /* Load data if not already done */ if (!trg->data) { - trg->data = read_sha1_file(trg_entry->sha1, type, &sz); + trg->data = read_sha1_file(trg_entry->sha1, &type, &sz); if (sz != trg_size) die("object %s inconsistent object length (%lu vs %lu)", sha1_to_hex(trg_entry->sha1), sz, trg_size); } if (!src->data) { - src->data = read_sha1_file(src_entry->sha1, type, &sz); + src->data = read_sha1_file(src_entry->sha1, &type, &sz); if (sz != src_size) die("object %s inconsistent object length (%lu vs %lu)", sha1_to_hex(src_entry->sha1), sz, src_size); diff --git a/builtin-prune.c b/builtin-prune.c index 6f0ba0d04d..09864b7a6d 100644 --- a/builtin-prune.c +++ b/builtin-prune.c @@ -10,15 +10,10 @@ static int show_only; static int prune_object(char *path, const char *filename, const unsigned char *sha1) { - char buf[20]; - const char *type; - if (show_only) { - if (sha1_object_info(sha1, buf, NULL)) - type = "unknown"; - else - type = buf; - printf("%s %s\n", sha1_to_hex(sha1), type); + enum object_type type = sha1_object_info(sha1, NULL); + printf("%s %s\n", sha1_to_hex(sha1), + (type > 0) ? typename(type) : "unknown"); return 0; } unlink(mkpath("%s/%s", path, filename)); diff --git a/builtin-reflog.c b/builtin-reflog.c index cefb40da81..186aabce04 100644 --- a/builtin-reflog.c +++ b/builtin-reflog.c @@ -55,8 +55,8 @@ static int tree_is_complete(const unsigned char *sha1) desc.buf = tree->buffer; desc.size = tree->size; if (!desc.buf) { - char type[20]; - void *data = read_sha1_file(sha1, type, &desc.size); + enum object_type type; + void *data = read_sha1_file(sha1, &type, &desc.size); if (!data) { tree->object.flags |= INCOMPLETE; return 0; diff --git a/builtin-unpack-objects.c b/builtin-unpack-objects.c index 8f8e898516..3956c56334 100644 --- a/builtin-unpack-objects.c +++ b/builtin-unpack-objects.c @@ -119,18 +119,18 @@ struct obj_info { static struct obj_info *obj_list; -static void added_object(unsigned nr, const char *type, void *data, - unsigned long size); +static void added_object(unsigned nr, enum object_type type, + void *data, unsigned long size); -static void write_object(unsigned nr, void *buf, unsigned long size, - const char *type) +static void write_object(unsigned nr, enum object_type type, + void *buf, unsigned long size) { - if (write_sha1_file(buf, size, type, obj_list[nr].sha1) < 0) + if (write_sha1_file(buf, size, typename(type), obj_list[nr].sha1) < 0) die("failed to write object"); added_object(nr, type, buf, size); } -static void resolve_delta(unsigned nr, const char *type, +static void resolve_delta(unsigned nr, enum object_type type, void *base, unsigned long base_size, void *delta, unsigned long delta_size) { @@ -143,12 +143,12 @@ static void resolve_delta(unsigned nr, const char *type, if (!result) die("failed to apply delta"); free(delta); - write_object(nr, result, result_size, type); + write_object(nr, type, result, result_size); free(result); } -static void added_object(unsigned nr, const char *type, void *data, - unsigned long size) +static void added_object(unsigned nr, enum object_type type, + void *data, unsigned long size) { struct delta_info **p = &delta_list; struct delta_info *info; @@ -167,33 +167,24 @@ static void added_object(unsigned nr, const char *type, void *data, } } -static void unpack_non_delta_entry(enum object_type kind, unsigned long size, +static void unpack_non_delta_entry(enum object_type type, unsigned long size, unsigned nr) { void *buf = get_data(size); - const char *type; - - switch (kind) { - case OBJ_COMMIT: type = commit_type; break; - case OBJ_TREE: type = tree_type; break; - case OBJ_BLOB: type = blob_type; break; - case OBJ_TAG: type = tag_type; break; - default: die("bad type %d", kind); - } + if (!dry_run && buf) - write_object(nr, buf, size, type); + write_object(nr, type, buf, size); free(buf); } -static void unpack_delta_entry(enum object_type kind, unsigned long delta_size, +static void unpack_delta_entry(enum object_type type, unsigned long delta_size, unsigned nr) { void *delta_data, *base; unsigned long base_size; - char type[20]; unsigned char base_sha1[20]; - if (kind == OBJ_REF_DELTA) { + if (type == OBJ_REF_DELTA) { hashcpy(base_sha1, fill(20)); use(20); delta_data = get_data(delta_size); @@ -255,7 +246,7 @@ static void unpack_delta_entry(enum object_type kind, unsigned long delta_size, } } - base = read_sha1_file(base_sha1, type, &base_size); + base = read_sha1_file(base_sha1, &type, &base_size); if (!base) { error("failed to read delta-pack base object %s", sha1_to_hex(base_sha1)); @@ -262,13 +262,25 @@ int adjust_shared_perm(const char *path); int safe_create_leading_directories(char *path); char *enter_repo(char *path, int strict); +enum object_type { + OBJ_NONE = 0, + OBJ_COMMIT = 1, + OBJ_TREE = 2, + OBJ_BLOB = 3, + OBJ_TAG = 4, + /* 5 for future expansion */ + OBJ_OFS_DELTA = 6, + OBJ_REF_DELTA = 7, + OBJ_BAD, +}; + /* Read and unpack a sha1 file into memory, write memory to a sha1 file */ -extern int sha1_object_info(const unsigned char *, char *, unsigned long *); -extern void * unpack_sha1_file(void *map, unsigned long mapsize, char *type, unsigned long *size); -extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size); +extern int sha1_object_info(const unsigned char *, unsigned long *); +extern void * unpack_sha1_file(void *map, unsigned long mapsize, enum object_type *type, unsigned long *size); +extern void * read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size); extern int hash_sha1_file(void *buf, unsigned long len, const char *type, unsigned char *sha1); extern int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned char *return_sha1); -extern int pretend_sha1_file(void *, unsigned long, const char *, unsigned char *); +extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *); extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type); @@ -285,18 +297,6 @@ extern int legacy_loose_object(unsigned char *); extern int has_pack_file(const unsigned char *sha1); extern int has_pack_index(const unsigned char *sha1); -enum object_type { - OBJ_NONE = 0, - OBJ_COMMIT = 1, - OBJ_TREE = 2, - OBJ_BLOB = 3, - OBJ_TAG = 4, - /* 5 for future expansion */ - OBJ_OFS_DELTA = 6, - OBJ_REF_DELTA = 7, - OBJ_BAD, -}; - extern signed char hexval_table[256]; static inline unsigned int hexval(unsigned int c) { @@ -422,9 +422,9 @@ extern struct packed_git *add_packed_git(char *, int, int); extern int num_packed_objects(const struct packed_git *p); extern int nth_packed_object_sha1(const struct packed_git *, int, unsigned char*); extern unsigned long find_pack_entry_one(const unsigned char *, struct packed_git *); -extern void *unpack_entry(struct packed_git *, unsigned long, char *, unsigned long *); +extern void *unpack_entry(struct packed_git *, unsigned long, enum object_type *, unsigned long *); extern unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep); -extern void packed_object_info_detail(struct packed_git *, unsigned long, char *, unsigned long *, unsigned long *, unsigned int *, unsigned char *); +extern const char *packed_object_info_detail(struct packed_git *, unsigned long, unsigned long *, unsigned long *, unsigned int *, unsigned char *); /* Dumb servers support */ extern int update_server_info(int); diff --git a/combine-diff.c b/combine-diff.c index 044633d164..9daa0cb9a9 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -92,14 +92,14 @@ struct sline { static char *grab_blob(const unsigned char *sha1, unsigned long *size) { char *blob; - char type[20]; + enum object_type type; if (is_null_sha1(sha1)) { /* deleted blob */ *size = 0; return xcalloc(1, 1); } - blob = read_sha1_file(sha1, type, size); - if (strcmp(type, blob_type)) + blob = read_sha1_file(sha1, &type, size); + if (type != OBJ_BLOB) die("object '%s' is not a blob!", sha1_to_hex(sha1)); return blob; } @@ -342,18 +342,18 @@ int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size) int parse_commit(struct commit *item) { - char type[20]; + enum object_type type; void *buffer; unsigned long size; int ret; if (item->object.parsed) return 0; - buffer = read_sha1_file(item->object.sha1, type, &size); + buffer = read_sha1_file(item->object.sha1, &type, &size); if (!buffer) return error("Could not read %s", sha1_to_hex(item->object.sha1)); - if (strcmp(type, commit_type)) { + if (type != OBJ_COMMIT) { free(buffer); return error("Object %s not a commit", sha1_to_hex(item->object.sha1)); diff --git a/convert-objects.c b/convert-objects.c index a630132985..b5f41ae2e3 100644 --- a/convert-objects.c +++ b/convert-objects.c @@ -284,27 +284,27 @@ static void convert_commit(void *buffer, unsigned long size, unsigned char *resu static struct entry * convert_entry(unsigned char *sha1) { struct entry *entry = lookup_entry(sha1); - char type[20]; + enum object_type type; void *buffer, *data; unsigned long size; if (entry->converted) return entry; - data = read_sha1_file(sha1, type, &size); + data = read_sha1_file(sha1, &type, &size); if (!data) die("unable to read object %s", sha1_to_hex(sha1)); buffer = xmalloc(size); memcpy(buffer, data, size); - if (!strcmp(type, blob_type)) { + if (type == OBJ_BLOB) { write_sha1_file(buffer, size, blob_type, entry->new_sha1); - } else if (!strcmp(type, tree_type)) + } else if (type == OBJ_TREE) convert_tree(buffer, size, entry->new_sha1); - else if (!strcmp(type, commit_type)) + else if (type == OBJ_COMMIT) convert_commit(buffer, size, entry->new_sha1); else - die("unknown object type '%s' in %s", type, sha1_to_hex(sha1)); + die("unknown object type %d in %s", type, sha1_to_hex(sha1)); entry->converted = 1; free(buffer); free(data); @@ -1430,7 +1430,7 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only) } } else { - char type[20]; + enum object_type type; struct sha1_size_cache *e; if (size_only) { @@ -1439,11 +1439,12 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only) s->size = e->size; return 0; } - if (!sha1_object_info(s->sha1, type, &s->size)) + type = sha1_object_info(s->sha1, &s->size); + if (type < 0) locate_size_cache(s->sha1, 0, s->size); |