{"thread":{"id":"3774","subject":"[PATCH] Use _type constants instead of litteral constants","startedAt":"2006-04-02T13:00:52Z","lastAt":"2006-04-02T13:41:20Z","messageCount":2,"participants":["Peter Eriksen","Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"18218","messageId":"20060402130051.GA2933@ebar091.ebar.dtu.dk","threadId":"3774","inReplyTo":null,"subject":"[PATCH] Use _type constants instead of litteral constants","fromName":"Peter Eriksen","fromEmail":"s022018@student.dtu.dk","sentAt":"2006-04-02T13:00:52Z","receivedAt":"2006-04-02T13:00:52Z","isPatch":true,"sender":{"key":"s022018@student.dtu.dk","avatar":null},"body":"From: Peter Eriksen <s022018@student.dtu.dk>\nDate: Sun Apr 2 14:44:09 2006 +0200\nSubject: [PATCH] Use blob_, commit_, tag_, and tree_type throughout.\n\nThis replaces occurences of \"blob\", \"commit\", \"tag\", and \"tree\",\nwhere they're really used as type specifiers, which we already\nhave defined global constants for.\n\nSigned-off-by: Peter Eriksen <s022018@student.dtu.dk>\n\n\n---\n\nI have no idea if something like this is wanted. It does touch\na lot of core files, and probably will give merge conflicts \nall over the place. It was good fun and practice for me, though. \n\nRegards,\n\nPeter\n\n apply.c           |    5 +++--\n blame.c           |    2 +-\n cat-file.c        |    6 ++++--\n combine-diff.c    |    3 ++-\n commit-tree.c     |    8 +++++---\n convert-objects.c |   15 +++++++++------\n diff-tree.c       |    2 +-\n entry.c           |    3 ++-\n hash-object.c     |    3 ++-\n index-pack.c      |   14 +++++++++-----\n ls-tree.c         |    4 ++--\n mktag.c           |    3 ++-\n mktree.c          |    3 ++-\n object.c          |    8 ++++----\n pack-objects.c    |   16 ++++++++++------\n revision.c        |    2 +-\n sha1_file.c       |   42 +++++++++++++++++++++++-------------------\n tar-tree.c        |    2 +-\n tree-diff.c       |    7 ++++---\n tree-walk.c       |    3 ++-\n unpack-file.c     |    3 ++-\n unpack-objects.c  |   14 +++++++++-----\n write-tree.c      |    3 ++-\n 23 files changed, 102 insertions(+), 69 deletions(-)\n\nfad7c58e5e1bc105b7a39ff9ceb19eb7c4927c28\ndiff --git a/apply.c b/apply.c\nindex c50b3a6..cc3f12e 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -9,6 +9,7 @@\n #include <fnmatch.h>\n #include \"cache.h\"\n #include \"quote.h\"\n+#include \"blob.h\"\n \n //  --check turns on checking that the working tree matches the\n //    files that are being modified, but doesn't apply the patch\n@@ -1296,7 +1297,7 @@ static int apply_fragments(struct buffer\n \t\t\t * applies to.\n \t\t\t */\n \t\t\twrite_sha1_file_prepare(desc->buffer, desc->size,\n-\t\t\t\t\t\t\"blob\", sha1, hdr, &hdrlen);\n+\t\t\t\t\t\tblob_type, sha1, hdr, &hdrlen);\n \t\t\tif (strcmp(sha1_to_hex(sha1), patch->old_sha1_prefix))\n \t\t\t\treturn error(\"the patch applies to '%s' (%s), \"\n \t\t\t\t\t     \"which does not match the \"\n@@ -1659,7 +1660,7 @@ static void add_index_file(const char *p\n \tif (lstat(path, &st) < 0)\n \t\tdie(\"unable to stat newly created file %s\", path);\n \tfill_stat_cache_info(ce, &st);\n-\tif (write_sha1_file(buf, size, \"blob\", ce->sha1) < 0)\n+\tif (write_sha1_file(buf, size, blob_type, ce->sha1) < 0)\n \t\tdie(\"unable to create backing store for newly created file %s\", path);\n \tif (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0)\n \t\tdie(\"unable to add cache entry for %s\", path);\ndiff --git a/blame.c b/blame.c\nindex 396defc..98f9992 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -229,7 +229,7 @@ static void get_blob(struct commit *comm\n \n \tinfo->buf = read_sha1_file(info->sha1, type, &info->size);\n \n-\tassert(!strcmp(type, \"blob\"));\n+\tassert(!strcmp(type, blob_type));\n }\n \n /* For debugging only */\ndiff --git a/cat-file.c b/cat-file.c\nindex 761111e..628f6ca 100644\n--- a/cat-file.c\n+++ b/cat-file.c\n@@ -5,6 +5,8 @@\n  */\n #include \"cache.h\"\n #include \"exec_cmd.h\"\n+#include \"tag.h\"\n+#include \"tree.h\"\n \n static void flush_buffer(const char *buf, unsigned long size)\n {\n@@ -136,13 +138,13 @@ int main(int argc, char **argv)\n \t\t\tdie(\"Not a valid object name %s\", argv[2]);\n \n \t\t/* custom pretty-print here */\n-\t\tif (!strcmp(type, \"tree\"))\n+\t\tif (!strcmp(type, tree_type))\n \t\t\treturn execl_git_cmd(\"ls-tree\", argv[2], NULL);\n \n \t\tbuf = read_sha1_file(sha1, type, &size);\n \t\tif (!buf)\n \t\t\tdie(\"Cannot read object %s\", argv[2]);\n-\t\tif (!strcmp(type, \"tag\"))\n+\t\tif (!strcmp(type, tag_type))\n \t\t\treturn pprint_tag(sha1, buf, size);\n \n \t\t/* otherwise just spit out the data */\ndiff --git a/combine-diff.c b/combine-diff.c\nindex f17aab3..7693884 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"commit.h\"\n+#include \"blob.h\"\n #include \"diff.h\"\n #include \"diffcore.h\"\n #include \"quote.h\"\n@@ -104,7 +105,7 @@ static char *grab_blob(const unsigned ch\n \t\treturn xcalloc(1, 1);\n \t}\n \tblob = read_sha1_file(sha1, type, size);\n-\tif (strcmp(type, \"blob\"))\n+\tif (strcmp(type, blob_type))\n \t\tdie(\"object '%s' is not a blob!\", sha1_to_hex(sha1));\n \treturn blob;\n }\ndiff --git a/commit-tree.c b/commit-tree.c\nindex 16c1787..2d86518 100644\n--- a/commit-tree.c\n+++ b/commit-tree.c\n@@ -4,6 +4,8 @@\n  * Copyright (C) Linus Torvalds, 2005\n  */\n #include \"cache.h\"\n+#include \"commit.h\"\n+#include \"tree.h\"\n \n #define BLOCKING (1ul << 14)\n \n@@ -93,13 +95,13 @@ int main(int argc, char **argv)\n \tif (argc < 2 || get_sha1_hex(argv[1], tree_sha1) < 0)\n \t\tusage(commit_tree_usage);\n \n-\tcheck_valid(tree_sha1, \"tree\");\n+\tcheck_valid(tree_sha1, tree_type);\n \tfor (i = 2; i < argc; i += 2) {\n \t\tchar *a, *b;\n \t\ta = argv[i]; b = argv[i+1];\n \t\tif (!b || strcmp(a, \"-p\") || get_sha1(b, parent_sha1[parents]))\n \t\t\tusage(commit_tree_usage);\n-\t\tcheck_valid(parent_sha1[parents], \"commit\");\n+\t\tcheck_valid(parent_sha1[parents], commit_type);\n \t\tif (new_parent(parents))\n \t\t\tparents++;\n \t}\n@@ -125,7 +127,7 @@ int main(int argc, char **argv)\n \twhile (fgets(comment, sizeof(comment), stdin) != NULL)\n \t\tadd_buffer(&buffer, &size, \"%s\", comment);\n \n-\tif (!write_sha1_file(buffer, size, \"commit\", commit_sha1)) {\n+\tif (!write_sha1_file(buffer, size, commit_type, commit_sha1)) {\n \t\tprintf(\"%s\\n\", sha1_to_hex(commit_sha1));\n \t\treturn 0;\n \t}\ndiff --git a/convert-objects.c b/convert-objects.c\nindex b49bce2..2476577 100644\n--- a/convert-objects.c\n+++ b/convert-objects.c\n@@ -2,6 +2,9 @@ #define _XOPEN_SOURCE 500 /* glibc2 and \n #define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */\n #include <time.h>\n #include \"cache.h\"\n+#include \"blob.h\"\n+#include \"commit.h\"\n+#include \"tree.h\"\n \n struct entry {\n \tunsigned char old_sha1[20];\n@@ -122,7 +125,7 @@ static int write_subdirectory(void *buff\n \t\tbuffer += len;\n \t}\n \n-\twrite_sha1_file(new, newlen, \"tree\", result_sha1);\n+\twrite_sha1_file(new, newlen, tree_type, result_sha1);\n \tfree(new);\n \treturn used;\n }\n@@ -262,7 +265,7 @@ static void convert_date(void *buffer, u\n \tmemcpy(new + newlen, buffer, size);\n \tnewlen += size;\n \n-\twrite_sha1_file(new, newlen, \"commit\", result_sha1);\n+\twrite_sha1_file(new, newlen, commit_type, result_sha1);\n \tfree(new);\t\n }\n \n@@ -298,11 +301,11 @@ static struct entry * convert_entry(unsi\n \tbuffer = xmalloc(size);\n \tmemcpy(buffer, data, size);\n \t\n-\tif (!strcmp(type, \"blob\")) {\n-\t\twrite_sha1_file(buffer, size, \"blob\", entry->new_sha1);\n-\t} else if (!strcmp(type, \"tree\"))\n+\tif (!strcmp(type, blob_type)) {\n+\t\twrite_sha1_file(buffer, size, blob_type, entry->new_sha1);\n+\t} else if (!strcmp(type, tree_type))\n \t\tconvert_tree(buffer, size, entry->new_sha1);\n-\telse if (!strcmp(type, \"commit\"))\n+\telse if (!strcmp(type, commit_type))\n \t\tconvert_commit(buffer, size, entry->new_sha1);\n \telse\n \t\tdie(\"unknown object type '%s' in %s\", type, sha1_to_hex(sha1));\ndiff --git a/diff-tree.c b/diff-tree.c\nindex f55a35a..d1265d7 100644\n--- a/diff-tree.c\n+++ b/diff-tree.c\n@@ -52,7 +52,7 @@ static int diff_root_tree(const unsigned\n \tvoid *tree;\n \tstruct tree_desc empty, real;\n \n-\ttree = read_object_with_reference(new, \"tree\", &real.size, NULL);\n+\ttree = read_object_with_reference(new, tree_type, &real.size, NULL);\n \tif (!tree)\n \t\tdie(\"unable to read root tree (%s)\", sha1_to_hex(new));\n \treal.buf = tree;\ndiff --git a/entry.c b/entry.c\nindex 5d9aefd..793724f 100644\n--- a/entry.c\n+++ b/entry.c\n@@ -1,6 +1,7 @@\n #include <sys/types.h>\n #include <dirent.h>\n #include \"cache.h\"\n+#include \"blob.h\"\n \n static void create_directories(const char *path, struct checkout *state)\n {\n@@ -72,7 +73,7 @@ static int write_entry(struct cache_entr\n \tchar type[20];\n \n \tnew = read_sha1_file(ce->sha1, type, &size);\n-\tif (!new || strcmp(type, \"blob\")) {\n+\tif (!new || strcmp(type, blob_type)) {\n \t\tif (new)\n \t\t\tfree(new);\n \t\treturn error(\"git-checkout-index: unable to read sha1 file of %s (%s)\",\ndiff --git a/hash-object.c b/hash-object.c\nindex 6502b5b..87e1277 100644\n--- a/hash-object.c\n+++ b/hash-object.c\n@@ -5,6 +5,7 @@\n  * Copyright (C) Junio C Hamano, 2005 \n  */\n #include \"cache.h\"\n+#include \"blob.h\"\n \n static void hash_object(const char *path, const char *type, int write_object)\n {\n@@ -35,7 +36,7 @@ static const char hash_object_usage[] =\n int main(int argc, char **argv)\n {\n \tint i;\n-\tconst char *type = \"blob\";\n+\tconst char *type = blob_type;\n \tint write_object = 0;\n \tconst char *prefix = NULL;\n \tint prefix_length = -1;\ndiff --git a/index-pack.c b/index-pack.c\nindex babe34b..b39953d 100644\n--- a/index-pack.c\n+++ b/index-pack.c\n@@ -2,7 +2,11 @@ #include \"cache.h\"\n #include \"delta.h\"\n #include \"pack.h\"\n #include \"csum-file.h\"\n-\n+#include \"blob.h\"\n+#include \"commit.h\"\n+#include \"tag.h\"\n+#include \"tree.h\"\n+\n static const char index_pack_usage[] =\n \"git-index-pack [-o index-file] pack-file\";\n \n@@ -224,10 +228,10 @@ static void sha1_object(const void *data\n \tconst char *type_str;\n \n \tswitch (type) {\n-\tcase OBJ_COMMIT: type_str = \"commit\"; break;\n-\tcase OBJ_TREE:   type_str = \"tree\"; break;\n-\tcase OBJ_BLOB:   type_str = \"blob\"; break;\n-\tcase OBJ_TAG:    type_str = \"tag\"; break;\n+\tcase OBJ_COMMIT: type_str = commit_type; break;\n+\tcase OBJ_TREE:   type_str = tree_type; break;\n+\tcase OBJ_BLOB:   type_str = blob_type; break;\n+\tcase OBJ_TAG:    type_str = tag_type; break;\n \tdefault:\n \t\tdie(\"bad type %d\", type);\n \t}\ndiff --git a/ls-tree.c b/ls-tree.c\nindex 26258c3..e4ef200 100644\n--- a/ls-tree.c\n+++ b/ls-tree.c\n@@ -56,7 +56,7 @@ static int show_tree(unsigned char *sha1\n \t\t     const char *pathname, unsigned mode, int stage)\n {\n \tint retval = 0;\n-\tconst char *type = \"blob\";\n+\tconst char *type = blob_type;\n \n \tif (S_ISDIR(mode)) {\n \t\tif (show_recursive(base, baselen, pathname)) {\n@@ -64,7 +64,7 @@ static int show_tree(unsigned char *sha1\n \t\t\tif (!(ls_options & LS_SHOW_TREES))\n \t\t\t\treturn retval;\n \t\t}\n-\t\ttype = \"tree\";\n+\t\ttype = tree_type;\n \t}\n \telse if (ls_options & LS_TREE_ONLY)\n \t\treturn 0;\ndiff --git a/mktag.c b/mktag.c\nindex fc6a9bf..2328878 100644\n--- a/mktag.c\n+++ b/mktag.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"tag.h\"\n \n /*\n  * A signature file has a very simple fixed format: three lines\n@@ -126,7 +127,7 @@ int main(int argc, char **argv)\n \tif (verify_tag(buffer, size) < 0)\n \t\tdie(\"invalid tag signature file\");\n \n-\tif (write_sha1_file(buffer, size, \"tag\", result_sha1) < 0)\n+\tif (write_sha1_file(buffer, size, tag_type, result_sha1) < 0)\n \t\tdie(\"unable to write tag file\");\n \tprintf(\"%s\\n\", sha1_to_hex(result_sha1));\n \treturn 0;\ndiff --git a/mktree.c b/mktree.c\nindex f853585..ab63cd9 100644\n--- a/mktree.c\n+++ b/mktree.c\n@@ -6,6 +6,7 @@\n #include \"cache.h\"\n #include \"strbuf.h\"\n #include \"quote.h\"\n+#include \"tree.h\"\n \n static struct treeent {\n \tunsigned mode;\n@@ -67,7 +68,7 @@ static void write_tree(unsigned char *sh\n \t\tmemcpy(buffer + offset, ent->sha1, 20);\n \t\toffset += 20;\n \t}\n-\twrite_sha1_file(buffer, offset, \"tree\", sha1);\n+\twrite_sha1_file(buffer, offset, tree_type, sha1);\n }\n \n static const char mktree_usage[] = \"mktree [-z]\";\ndiff --git a/object.c b/object.c\nindex c9ca481..b5c0ecf 100644\n--- a/object.c\n+++ b/object.c\n@@ -196,15 +196,15 @@ struct object *parse_object(const unsign\n \t\tstruct object *obj;\n \t\tif (check_sha1_signature(sha1, buffer, size, type) < 0)\n \t\t\tprintf(\"sha1 mismatch %s\\n\", sha1_to_hex(sha1));\n-\t\tif (!strcmp(type, \"blob\")) {\n+\t\tif (!strcmp(type, blob_type)) {\n \t\t\tstruct blob *blob = lookup_blob(sha1);\n \t\t\tparse_blob_buffer(blob, buffer, size);\n \t\t\tobj = &blob->object;\n-\t\t} else if (!strcmp(type, \"tree\")) {\n+\t\t} else if (!strcmp(type, tree_type)) {\n \t\t\tstruct tree *tree = lookup_tree(sha1);\n \t\t\tparse_tree_buffer(tree, buffer, size);\n \t\t\tobj = &tree->object;\n-\t\t} else if (!strcmp(type, \"commit\")) {\n+\t\t} else if (!strcmp(type, commit_type)) {\n \t\t\tstruct commit *commit = lookup_commit(sha1);\n \t\t\tparse_commit_buffer(commit, buffer, size);\n \t\t\tif (!commit->buffer) {\n@@ -212,7 +212,7 @@ struct object *parse_object(const unsign\n \t\t\t\tbuffer = NULL;\n \t\t\t}\n \t\t\tobj = &commit->object;\n-\t\t} else if (!strcmp(type, \"tag\")) {\n+\t\t} else if (!strcmp(type, tag_type)) {\n \t\t\tstruct tag *tag = lookup_tag(sha1);\n \t\t\tparse_tag_buffer(tag, buffer, size);\n \t\t\tobj = &tag->object;\ndiff --git a/pack-objects.c b/pack-objects.c\nindex ccfaa5f..4145f25 100644\n--- a/pack-objects.c\n+++ b/pack-objects.c\n@@ -1,5 +1,9 @@\n #include \"cache.h\"\n #include \"object.h\"\n+#include \"blob.h\"\n+#include \"commit.h\"\n+#include \"tag.h\"\n+#include \"tree.h\"\n #include \"delta.h\"\n #include \"pack.h\"\n #include \"csum-file.h\"\n@@ -603,7 +607,7 @@ static void add_pbase_tree(struct tree_d\n \t\tif (!add_object_entry(sha1, hash, 1))\n \t\t\tcontinue;\n \n-\t\tif (!strcmp(type, \"tree\")) {\n+\t\tif (!strcmp(type, tree_type)) {\n \t\t\tstruct tree_desc sub;\n \t\t\tvoid *elem;\n \t\t\tstruct name_path me;\n@@ -626,7 +630,7 @@ static void add_preferred_base(unsigned \n \tstruct tree_desc tree;\n \tvoid *elem;\n \n-\telem = read_object_with_reference(sha1, \"tree\", &tree.size, NULL);\n+\telem = read_object_with_reference(sha1, tree_type, &tree.size, NULL);\n \ttree.buf = elem;\n \tif (!tree.buf)\n \t\treturn;\n@@ -684,13 +688,13 @@ static void check_object(struct object_e\n \t\tdie(\"unable to get type of object %s\",\n \t\t    sha1_to_hex(entry->sha1));\n \n-\tif (!strcmp(type, \"commit\")) {\n+\tif (!strcmp(type, commit_type)) {\n \t\tentry->type = OBJ_COMMIT;\n-\t} else if (!strcmp(type, \"tree\")) {\n+\t} else if (!strcmp(type, tree_type)) {\n \t\tentry->type = OBJ_TREE;\n-\t} else if (!strcmp(type, \"blob\")) {\n+\t} else if (!strcmp(type, blob_type)) {\n \t\tentry->type = OBJ_BLOB;\n-\t} else if (!strcmp(type, \"tag\")) {\n+\t} else if (!strcmp(type, tag_type)) {\n \t\tentry->type = OBJ_TAG;\n \t} else\n \t\tdie(\"unable to pack object %s of type %s\",\ndiff --git a/revision.c b/revision.c\nindex c2a95aa..902a99f 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -260,7 +260,7 @@ int rev_same_tree_as_empty(struct tree *\n \tif (!t1)\n \t\treturn 0;\n \n-\ttree = read_object_with_reference(t1->object.sha1, \"tree\", &real.size, NULL);\n+\ttree = read_object_with_reference(t1->object.sha1, tree_type, &real.size, NULL);\n \tif (!tree)\n \t\treturn 0;\n \treal.buf = tree;\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 58edec0..ba8c4f7 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -9,7 +9,11 @@\n #include \"cache.h\"\n #include \"delta.h\"\n #include \"pack.h\"\n-\n+#include \"blob.h\"\n+#include \"commit.h\"\n+#include \"tag.h\"\n+#include \"tree.h\"\n+\n #ifndef O_NOATIME\n #if defined(__linux__) && (defined(__i386__) || defined(__PPC__))\n #define O_NOATIME 01000000\n@@ -894,16 +898,16 @@ void packed_object_info_detail(struct pa\n \t}\n \tswitch (kind) {\n \tcase OBJ_COMMIT:\n-\t\tstrcpy(type, \"commit\");\n+\t\tstrcpy(type, commit_type);\n \t\tbreak;\n \tcase OBJ_TREE:\n-\t\tstrcpy(type, \"tree\");\n+\t\tstrcpy(type, tree_type);\n \t\tbreak;\n \tcase OBJ_BLOB:\n-\t\tstrcpy(type, \"blob\");\n+\t\tstrcpy(type, blob_type);\n \t\tbreak;\n \tcase OBJ_TAG:\n-\t\tstrcpy(type, \"tag\");\n+\t\tstrcpy(type, tag_type);\n \t\tbreak;\n \tdefault:\n \t\tdie(\"corrupted pack file %s containing object of kind %d\",\n@@ -934,16 +938,16 @@ static int packed_object_info(struct pac\n \t\tunuse_packed_git(p);\n \t\treturn retval;\n \tcase OBJ_COMMIT:\n-\t\tstrcpy(type, \"commit\");\n+\t\tstrcpy(type, commit_type);\n \t\tbreak;\n \tcase OBJ_TREE:\n-\t\tstrcpy(type, \"tree\");\n+\t\tstrcpy(type, tree_type);\n \t\tbreak;\n \tcase OBJ_BLOB:\n-\t\tstrcpy(type, \"blob\");\n+\t\tstrcpy(type, blob_type);\n \t\tbreak;\n \tcase OBJ_TAG:\n-\t\tstrcpy(type, \"tag\");\n+\t\tstrcpy(type, tag_type);\n \t\tbreak;\n \tdefault:\n \t\tdie(\"corrupted pack file %s containing object of kind %d\",\n@@ -1071,16 +1075,16 @@ void *unpack_entry_gently(struct pack_en\n \t\tretval = unpack_delta_entry(pack, size, left, type, sizep, p);\n \t\treturn retval;\n \tcase OBJ_COMMIT:\n-\t\tstrcpy(type, \"commit\");\n+\t\tstrcpy(type, commit_type);\n \t\tbreak;\n \tcase OBJ_TREE:\n-\t\tstrcpy(type, \"tree\");\n+\t\tstrcpy(type, tree_type);\n \t\tbreak;\n \tcase OBJ_BLOB:\n-\t\tstrcpy(type, \"blob\");\n+\t\tstrcpy(type, blob_type);\n \t\tbreak;\n \tcase OBJ_TAG:\n-\t\tstrcpy(type, \"tag\");\n+\t\tstrcpy(type, tag_type);\n \t\tbreak;\n \tdefault:\n \t\treturn NULL;\n@@ -1241,9 +1245,9 @@ void *read_object_with_reference(const u\n \t\t\treturn buffer;\n \t\t}\n \t\t/* Handle references */\n-\t\telse if (!strcmp(type, \"commit\"))\n+\t\telse if (!strcmp(type, commit_type))\n \t\t\tref_type = \"tree \";\n-\t\telse if (!strcmp(type, \"tag\"))\n+\t\telse if (!strcmp(type, tag_type))\n \t\t\tref_type = \"object \";\n \t\telse {\n \t\t\tfree(buffer);\n@@ -1625,7 +1629,7 @@ int index_pipe(unsigned char *sha1, int \n \t\treturn -1;\n \t}\n \tif (!type)\n-\t\ttype = \"blob\";\n+\t\ttype = blob_type;\n \tif (write_object)\n \t\tret = write_sha1_file(buf, off, type, sha1);\n \telse {\n@@ -1652,7 +1656,7 @@ int index_fd(unsigned char *sha1, int fd\n \t\treturn -1;\n \n \tif (!type)\n-\t\ttype = \"blob\";\n+\t\ttype = blob_type;\n \tif (write_object)\n \t\tret = write_sha1_file(buf, size, type, sha1);\n \telse {\n@@ -1690,9 +1694,9 @@ int index_path(unsigned char *sha1, cons\n \t\tif (!write_object) {\n \t\t\tunsigned char hdr[50];\n \t\t\tint hdrlen;\n-\t\t\twrite_sha1_file_prepare(target, st->st_size, \"blob\",\n+\t\t\twrite_sha1_file_prepare(target, st->st_size, blob_type,\n \t\t\t\t\t\tsha1, hdr, &hdrlen);\n-\t\t} else if (write_sha1_file(target, st->st_size, \"blob\", sha1))\n+\t\t} else if (write_sha1_file(target, st->st_size, blob_type, sha1))\n \t\t\treturn error(\"%s: failed to insert into database\",\n \t\t\t\t     path);\n \t\tfree(target);\ndiff --git a/tar-tree.c b/tar-tree.c\nindex 705b8fa..87870b6 100644\n--- a/tar-tree.c\n+++ b/tar-tree.c\n@@ -336,7 +336,7 @@ int main(int argc, char **argv)\n \t} else\n \t\tarchive_time = time(NULL);\n \n-\ttree.buf = read_object_with_reference(sha1, \"tree\", &tree.size,\n+\ttree.buf = read_object_with_reference(sha1, tree_type, &tree.size,\n \t                                      tree_sha1);\n \tif (!tree.buf)\n \t\tdie(\"not a reference to a tag, commit or tree object: %s\",\ndiff --git a/tree-diff.c b/tree-diff.c\nindex 7bb6109..701fbba 100644\n--- a/tree-diff.c\n+++ b/tree-diff.c\n@@ -3,6 +3,7 @@\n  */\n #include \"cache.h\"\n #include \"diff.h\"\n+#include \"tree.h\"\n \n // What paths are we interested in?\n static int nr_paths = 0;\n@@ -148,7 +149,7 @@ static int show_entry(struct diff_option\n \t\tvoid *tree;\n \n \t\ttree = read_sha1_file(sha1, type, &inner.size);\n-\t\tif (!tree || strcmp(type, \"tree\"))\n+\t\tif (!tree || strcmp(type, tree_type))\n \t\t\tdie(\"corrupt tree sha %s\", sha1_to_hex(sha1));\n \n \t\tinner.buf = tree;\n@@ -206,10 +207,10 @@ int diff_tree_sha1(const unsigned char *\n \tstruct tree_desc t1, t2;\n \tint retval;\n \n-\ttree1 = read_object_with_reference(old, \"tree\", &t1.size, NULL);\n+\ttree1 = read_object_with_reference(old, tree_type, &t1.size, NULL);\n \tif (!tree1)\n \t\tdie(\"unable to read source tree (%s)\", sha1_to_hex(old));\n-\ttree2 = read_object_with_reference(new, \"tree\", &t2.size, NULL);\n+\ttree2 = read_object_with_reference(new, tree_type, &t2.size, NULL);\n \tif (!tree2)\n \t\tdie(\"unable to read destination tree (%s)\", sha1_to_hex(new));\n \tt1.buf = tree1;\ndiff --git a/tree-walk.c b/tree-walk.c\nindex 0735f40..bf8bfdf 100644\n--- a/tree-walk.c\n+++ b/tree-walk.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"tree-walk.h\"\n+#include \"tree.h\"\n \n void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1)\n {\n@@ -7,7 +8,7 @@ void *fill_tree_descriptor(struct tree_d\n \tvoid *buf = NULL;\n \n \tif (sha1) {\n-\t\tbuf = read_object_with_reference(sha1, \"tree\", &size, NULL);\n+\t\tbuf = read_object_with_reference(sha1, tree_type, &size, NULL);\n \t\tif (!buf)\n \t\t\tdie(\"unable to read tree %s\", sha1_to_hex(sha1));\n \t}\ndiff --git a/unpack-file.c b/unpack-file.c\nindex 3accb97..23a8562 100644\n--- a/unpack-file.c\n+++ b/unpack-file.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"blob.h\"\n \n static char *create_temp_file(unsigned char *sha1)\n {\n@@ -9,7 +10,7 @@ static char *create_temp_file(unsigned c\n \tint fd;\n \n \tbuf = read_sha1_file(sha1, type, &size);\n-\tif (!buf || strcmp(type, \"blob\"))\n+\tif (!buf || strcmp(type, blob_type))\n \t\tdie(\"unable to read blob object %s\", sha1_to_hex(sha1));\n \n \tstrcpy(path, \".merge_file_XXXXXX\");\ndiff --git a/unpack-objects.c b/unpack-objects.c\nindex 815a1b3..3b824b0 100644\n--- a/unpack-objects.c\n+++ b/unpack-objects.c\n@@ -2,7 +2,11 @@ #include \"cache.h\"\n #include \"object.h\"\n #include \"delta.h\"\n #include \"pack.h\"\n-\n+#include \"blob.h\"\n+#include \"commit.h\"\n+#include \"tag.h\"\n+#include \"tree.h\"\n+\n #include <sys/time.h>\n \n static int dry_run, quiet;\n@@ -148,10 +152,10 @@ static int unpack_non_delta_entry(enum o\n \tconst char *type;\n \n \tswitch (kind) {\n-\tcase OBJ_COMMIT: type = \"commit\"; break;\n-\tcase OBJ_TREE:   type = \"tree\"; break;\n-\tcase OBJ_BLOB:   type = \"blob\"; break;\n-\tcase OBJ_TAG:    type = \"tag\"; break;\n+\tcase OBJ_COMMIT: type = commit_type; break;\n+\tcase OBJ_TREE:   type = tree_type; break;\n+\tcase OBJ_BLOB:   type = blob_type; break;\n+\tcase OBJ_TAG:    type = tag_type; break;\n \tdefault: die(\"bad type %d\", kind);\n \t}\n \tif (!dry_run)\ndiff --git a/write-tree.c b/write-tree.c\nindex addb5de..dcad6e6 100644\n--- a/write-tree.c\n+++ b/write-tree.c\n@@ -4,6 +4,7 @@\n  * Copyright (C) Linus Torvalds, 2005\n  */\n #include \"cache.h\"\n+#include \"tree.h\"\n \n static int missing_ok = 0;\n \n@@ -78,7 +79,7 @@ static int write_tree(struct cache_entry\n \t\tnr++;\n \t}\n \n-\twrite_sha1_file(buffer, offset, \"tree\", returnsha1);\n+\twrite_sha1_file(buffer, offset, tree_type, returnsha1);\n \tfree(buffer);\n \treturn nr;\n }\n-- \n1.3.0.rc1.g8eef8e\n"},{"id":"18219","messageId":"e0ok9m$oua$1@sea.gmane.org","threadId":"3774","inReplyTo":"20060402130051.GA2933@ebar091.ebar.dtu.dk","subject":"Re: [PATCH] Use _type constants instead of literal constants","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-04-02T13:41:20Z","receivedAt":"2006-04-02T13:41:20Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Peter Eriksen wrote:\n\n> From: Peter Eriksen <s022018@student.dtu.dk>\n> Date: Sun Apr 2 14:44:09 2006 +0200\n> Subject: [PATCH] Use blob_, commit_, tag_, and tree_type throughout.\n> \n> This replaces occurences of \"blob\", \"commit\", \"tag\", and \"tree\",\n> where they're really used as type specifiers, which we already\n> have defined global constants for.\n\nShouldn't the name of constant rather be e.g. instead of blob_type be\ntype_blob, and similarly for the rest of type constants?\n\n-- \nJakub Narebski\nWarsaw, Poland\n"}]}