@matheusbsbs / matheus-bagliano / commits / edaec3fbe8
Fork 0

index_fd(): use enum object_type instead of type name string.

Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Feb 28, 2007 at 11:45 UTC edaec3fbe8821a5761e35e9b01937eea9b2544c1
4 files changed +24 -23
cache.h
+14 -14
@@ -127,6 +127,19 @@ extern unsigned int active_nr, active_alloc, active_cache_changed;
127 extern struct cache_tree *active_cache_tree;
128 extern int cache_errno;
129
130 +enum object_type {
131 + OBJ_BAD = -1,
132 + OBJ_NONE = 0,
133 + OBJ_COMMIT = 1,
134 + OBJ_TREE = 2,
135 + OBJ_BLOB = 3,
136 + OBJ_TAG = 4,
137 + /* 5 for future expansion */
138 + OBJ_OFS_DELTA = 6,
139 + OBJ_REF_DELTA = 7,
140 + OBJ_MAX,
141 +};
142 +
143 #define GIT_DIR_ENVIRONMENT "GIT_DIR"
144 #define DEFAULT_GIT_DIR_ENVIRONMENT ".git"
145 #define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"
@@ -177,7 +190,7 @@ extern int ce_same_name(struct cache_entry *a, struct cache_entry *b);
190 extern int ce_match_stat(struct cache_entry *ce, struct stat *st, int);
191 extern int ce_modified(struct cache_entry *ce, struct stat *st, int);
192 extern int ce_path_match(const struct cache_entry *ce, const char **pathspec);
180 -extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, const char *type);
193 +extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type);
194 extern int read_pipe(int fd, char** return_buf, unsigned long* return_size);
195 extern int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object);
196 extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object);
@@ -262,19 +275,6 @@ int adjust_shared_perm(const char *path);
275 int safe_create_leading_directories(char *path);
276 char *enter_repo(char *path, int strict);
277
265 -enum object_type {
266 - OBJ_BAD = -1,
267 - OBJ_NONE = 0,
268 - OBJ_COMMIT = 1,
269 - OBJ_TREE = 2,
270 - OBJ_BLOB = 3,
271 - OBJ_TAG = 4,
272 - /* 5 for future expansion */
273 - OBJ_OFS_DELTA = 6,
274 - OBJ_REF_DELTA = 7,
275 - OBJ_MAX,
276 -};
277 -
278 /* Read and unpack a sha1 file into memory, write memory to a sha1 file */
279 extern int sha1_object_info(const unsigned char *, unsigned long *);
280 extern void * unpack_sha1_file(void *map, unsigned long mapsize, enum object_type *type, unsigned long *size);
hash-object.c
+2 -2
@@ -7,7 +7,7 @@
7 #include "cache.h"
8 #include "blob.h"
9
10 -static void hash_object(const char *path, const char *type, int write_object)
10 +static void hash_object(const char *path, enum object_type type, int write_object)
11 {
12 int fd;
13 struct stat st;
@@ -73,7 +73,7 @@ int main(int argc, char **argv)
73 if (0 <= prefix_length)
74 arg = prefix_filename(prefix, prefix_length,
75 arg);
76 - hash_object(arg, type, write_object);
76 + hash_object(arg, type_from_string(type), write_object);
77 no_more_flags = 1;
78 }
79 }
read-cache.c
+1 -1
@@ -59,7 +59,7 @@ static int ce_compare_data(struct cache_entry *ce, struct stat *st)
59
60 if (fd >= 0) {
61 unsigned char sha1[20];
62 - if (!index_fd(sha1, fd, st, 0, NULL))
62 + if (!index_fd(sha1, fd, st, 0, OBJ_BLOB))
63 match = hashcmp(sha1, ce->sha1);
64 /* index_fd() closed the file descriptor already */
65 }
sha1_file.c
+7 -6
@@ -2053,7 +2053,8 @@ int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object)
2053 return ret;
2054 }
2055
2056 -int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, const char *type)
2056 +int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object,
2057 + enum object_type type)
2058 {
2059 unsigned long size = st->st_size;
2060 void *buf;
@@ -2065,12 +2066,12 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, con
2066 close(fd);
2067
2068 if (!type)
2068 - type = blob_type;
2069 + type = OBJ_BLOB;
2070
2071 /*
2072 * Convert blobs to git internal format
2073 */
2073 - if (!strcmp(type, blob_type)) {
2074 + if (type == OBJ_BLOB) {
2075 unsigned long nsize = size;
2076 char *nbuf = buf;
2077 if (convert_to_git(NULL, &nbuf, &nsize)) {
@@ -2083,9 +2084,9 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, con
2084 }
2085
2086 if (write_object)
2086 - ret = write_sha1_file(buf, size, type, sha1);
2087 + ret = write_sha1_file(buf, size, typename(type), sha1);
2088 else
2088 - ret = hash_sha1_file(buf, size, type, sha1);
2089 + ret = hash_sha1_file(buf, size, typename(type), sha1);
2090 if (re_allocated) {
2091 free(buf);
2092 return ret;
@@ -2106,7 +2107,7 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, int write
2107 if (fd < 0)
2108 return error("open(\"%s\"): %s", path,
2109 strerror(errno));
2109 - if (index_fd(sha1, fd, st, write_object, NULL) < 0)
2110 + if (index_fd(sha1, fd, st, write_object, OBJ_BLOB) < 0)
2111 return error("%s: failed to insert into database",
2112 path);
2113 break;