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

Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Junio C Hamano 2007-02-28 11:45:56 -08:00
Родитель 597388f6a1
Коммит edaec3fbe8
4 изменённых файлов: 24 добавлений и 23 удалений

28
cache.h
Просмотреть файл

@ -127,6 +127,19 @@ extern unsigned int active_nr, active_alloc, active_cache_changed;
extern struct cache_tree *active_cache_tree;
extern int cache_errno;
enum object_type {
OBJ_BAD = -1,
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_MAX,
};
#define GIT_DIR_ENVIRONMENT "GIT_DIR"
#define DEFAULT_GIT_DIR_ENVIRONMENT ".git"
#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"
@ -177,7 +190,7 @@ extern int ce_same_name(struct cache_entry *a, struct cache_entry *b);
extern int ce_match_stat(struct cache_entry *ce, struct stat *st, int);
extern int ce_modified(struct cache_entry *ce, struct stat *st, int);
extern int ce_path_match(const struct cache_entry *ce, const char **pathspec);
extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, const char *type);
extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type);
extern int read_pipe(int fd, char** return_buf, unsigned long* return_size);
extern int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object);
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);
int safe_create_leading_directories(char *path);
char *enter_repo(char *path, int strict);
enum object_type {
OBJ_BAD = -1,
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_MAX,
};
/* Read and unpack a sha1 file into memory, write memory to a sha1 file */
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);

Просмотреть файл

@ -7,7 +7,7 @@
#include "cache.h"
#include "blob.h"
static void hash_object(const char *path, const char *type, int write_object)
static void hash_object(const char *path, enum object_type type, int write_object)
{
int fd;
struct stat st;
@ -73,7 +73,7 @@ int main(int argc, char **argv)
if (0 <= prefix_length)
arg = prefix_filename(prefix, prefix_length,
arg);
hash_object(arg, type, write_object);
hash_object(arg, type_from_string(type), write_object);
no_more_flags = 1;
}
}

Просмотреть файл

@ -59,7 +59,7 @@ static int ce_compare_data(struct cache_entry *ce, struct stat *st)
if (fd >= 0) {
unsigned char sha1[20];
if (!index_fd(sha1, fd, st, 0, NULL))
if (!index_fd(sha1, fd, st, 0, OBJ_BLOB))
match = hashcmp(sha1, ce->sha1);
/* index_fd() closed the file descriptor already */
}

Просмотреть файл

@ -2053,7 +2053,8 @@ int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object)
return ret;
}
int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, const char *type)
int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object,
enum object_type type)
{
unsigned long size = st->st_size;
void *buf;
@ -2065,12 +2066,12 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, con
close(fd);
if (!type)
type = blob_type;
type = OBJ_BLOB;
/*
* Convert blobs to git internal format
*/
if (!strcmp(type, blob_type)) {
if (type == OBJ_BLOB) {
unsigned long nsize = size;
char *nbuf = buf;
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
}
if (write_object)
ret = write_sha1_file(buf, size, type, sha1);
ret = write_sha1_file(buf, size, typename(type), sha1);
else
ret = hash_sha1_file(buf, size, type, sha1);
ret = hash_sha1_file(buf, size, typename(type), sha1);
if (re_allocated) {
free(buf);
return ret;
@ -2106,7 +2107,7 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, int write
if (fd < 0)
return error("open(\"%s\"): %s", path,
strerror(errno));
if (index_fd(sha1, fd, st, write_object, NULL) < 0)
if (index_fd(sha1, fd, st, write_object, OBJ_BLOB) < 0)
return error("%s: failed to insert into database",
path);
break;