Browse Source

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

Signed-off-by: Junio C Hamano <junkio@cox.net>
maint
Junio C Hamano 18 years ago
parent
commit
edaec3fbe8
  1. 28
      cache.h
  2. 4
      hash-object.c
  3. 2
      read-cache.c
  4. 13
      sha1_file.c

28
cache.h

@ -127,6 +127,19 @@ extern unsigned int active_nr, active_alloc, active_cache_changed; @@ -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); @@ -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); @@ -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);

4
hash-object.c

@ -7,7 +7,7 @@ @@ -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) @@ -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;
}
}

2
read-cache.c

@ -59,7 +59,7 @@ static int ce_compare_data(struct cache_entry *ce, struct stat *st) @@ -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 */
}

13
sha1_file.c

@ -2053,7 +2053,8 @@ int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object) @@ -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 @@ -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 @@ -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 @@ -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;

Loading…
Cancel
Save