Skip to content

Commit

Permalink
index_fd(): use enum object_type instead of type name string.
Browse files Browse the repository at this point in the history
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Junio C Hamano committed Feb 28, 2007
1 parent 597388f commit edaec3f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
28 changes: 14 additions & 14 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions hash-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
}
Expand Down
13 changes: 7 additions & 6 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)) {
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit edaec3f

Please sign in to comment.