summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 597388f)
raw | patch | inline | side by side (parent: 597388f)
author | Junio C Hamano <junkio@cox.net> | |
Wed, 28 Feb 2007 19:45:56 +0000 (11:45 -0800) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Wed, 28 Feb 2007 20:00:00 +0000 (12:00 -0800) |
Signed-off-by: Junio C Hamano <junkio@cox.net>
cache.h | patch | blob | history | |
hash-object.c | patch | blob | history | |
read-cache.c | patch | blob | history | |
sha1_file.c | patch | blob | history |
index ec72c0c438e9a4cd9532bd0cd3cc0c161299bc54..9f30ad672b746b31d2d3719cf6c354df403621bd 100644 (file)
--- a/cache.h
+++ b/cache.h
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"
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);
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);
diff --git a/hash-object.c b/hash-object.c
index 5f89e64c13d6f13fd832309041a6a9fa9d0bca5c..1e6f6bf7061d57bcfa194b3b7b3e45f6a3f7b54c 100644 (file)
--- a/hash-object.c
+++ b/hash-object.c
#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;
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;
}
}
diff --git a/read-cache.c b/read-cache.c
index d63746476e8922ab0105347cbfdaea1823156563..6bfd4116508d0c885ab6c60931cd01cec58afbaf 100644 (file)
--- a/read-cache.c
+++ b/read-cache.c
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 */
}
diff --git a/sha1_file.c b/sha1_file.c
index 38316147345ad98faa5bce94db55f67f47498d7a..38ccf1b80911facf8e28968306d4cafcc4464229 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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;