X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=sha1_file.c;h=0a3a721e97c89f1dd494831a9321de4668f214c8;hb=a49dd05fd047f504a74fb053bb8ddbb9e4bd152b;hp=8bebbb255f762fc36f165b87023d8cc37732968a;hpb=59617ebb746b67921856c00a63f943d43b0abeea;p=git.git diff --git a/sha1_file.c b/sha1_file.c index 8bebbb255..0a3a721e9 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -6,8 +6,6 @@ * This handles basic git sha1 object files - packing, unpacking, * creation etc. */ -#include -#include #include "cache.h" #include "delta.h" #include "pack.h" @@ -74,6 +72,8 @@ int adjust_shared_perm(const char *path) int safe_create_leading_directories(char *path) { char *pos = path; + struct stat st; + if (*pos == '/') pos++; @@ -82,12 +82,17 @@ int safe_create_leading_directories(char *path) if (!pos) break; *pos = 0; - if (mkdir(path, 0777) < 0) { - if (errno != EEXIST) { + if (!stat(path, &st)) { + /* path exists */ + if (!S_ISDIR(st.st_mode)) { *pos = '/'; - return -1; + return -3; } } + else if (mkdir(path, 0777)) { + *pos = '/'; + return -1; + } else if (adjust_shared_perm(path)) { *pos = '/'; return -2; @@ -349,16 +354,12 @@ struct packed_git *packed_git; static int check_packed_git_idx(const char *path, unsigned long *idx_size_, void **idx_map_) { - SHA_CTX ctx; - unsigned char sha1[20]; void *idx_map; unsigned int *index; unsigned long idx_size; int nr, i; - int fd; + int fd = open(path, O_RDONLY); struct stat st; - - fd = open(path, O_RDONLY); if (fd < 0) return -1; if (fstat(fd, &st)) { @@ -396,16 +397,6 @@ static int check_packed_git_idx(const char *path, unsigned long *idx_size_, if (idx_size != 4*256 + nr * 24 + 20 + 20) return error("wrong index file size"); - /* - * File checksum. - */ - SHA1_Init(&ctx); - SHA1_Update(&ctx, idx_map, idx_size-20); - SHA1_Final(sha1, &ctx); - - if (memcmp(sha1, idx_map + idx_size - 20, 20)) - return error("index checksum mismatch"); - return 0; } @@ -835,11 +826,30 @@ static unsigned long unpack_object_header(struct packed_git *p, unsigned long of return offset; } +int check_reuse_pack_delta(struct packed_git *p, unsigned long offset, + unsigned char *base, unsigned long *sizep, + enum object_type *kindp) +{ + unsigned long ptr; + int status = -1; + + use_packed_git(p); + ptr = offset; + ptr = unpack_object_header(p, ptr, kindp, sizep); + if (*kindp != OBJ_DELTA) + goto done; + memcpy(base, p->pack_base + ptr, 20); + status = 0; + done: + unuse_packed_git(p); + return status; +} + void packed_object_info_detail(struct pack_entry *e, char *type, unsigned long *size, unsigned long *store_size, - int *delta_chain_length, + unsigned int *delta_chain_length, unsigned char *base_sha1) { struct packed_git *p = e->p; @@ -853,7 +863,7 @@ void packed_object_info_detail(struct pack_entry *e, if (kind != OBJ_DELTA) *delta_chain_length = 0; else { - int chain_length = 0; + unsigned int chain_length = 0; memcpy(base_sha1, pack, 20); do { struct pack_entry base_ent;