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 /builtin-cat-file.c | |
parent | df8436622fb553f468180b61032fe34bd6712752 (diff) | |
download | git-21666f1aae4e890d8f50924f9e80763b27e6a45d.tar.gz git-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>
Diffstat (limited to 'builtin-cat-file.c')
-rw-r--r-- | builtin-cat-file.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/builtin-cat-file.c b/builtin-cat-file.c index 6c16bfa1a..d61d3d5b7 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; } |