X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=sha1_file.c;h=889fe7183065ae8bc12821aadebb69a17bc7635c;hb=e2895de4d8efef52e835731aaaaa9467e2110e62;hp=b4fcca8ffdbfe48b11478709c61eb90cd64de20d;hpb=af4c62ae88d403a417ba7c2b879eca10e7bff8f4;p=git.git diff --git a/sha1_file.c b/sha1_file.c index b4fcca8ff..889fe7183 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -26,13 +26,8 @@ #endif #endif -#ifdef NO_C99_FORMAT -#define SZ_FMT "lu" -static unsigned long sz_fmt(size_t s) { return (unsigned long)s; } -#else -#define SZ_FMT "zu" -static size_t sz_fmt(size_t s) { return s; } -#endif +#define SZ_FMT PRIuMAX +static inline uintmax_t sz_fmt(size_t s) { return s; } const unsigned char null_sha1[20]; @@ -73,6 +68,35 @@ static struct cached_object *find_cached_object(const unsigned char *sha1) return NULL; } +int mkdir_in_gitdir(const char *path) +{ + if (mkdir(path, 0777)) { + int saved_errno = errno; + struct stat st; + struct strbuf sb = STRBUF_INIT; + + if (errno != EEXIST) + return -1; + /* + * Are we looking at a path in a symlinked worktree + * whose original repository does not yet have it? + * e.g. .git/rr-cache pointing at its original + * repository in which the user hasn't performed any + * conflict resolution yet? + */ + if (lstat(path, &st) || !S_ISLNK(st.st_mode) || + strbuf_readlink(&sb, path, st.st_size) || + !is_absolute_path(sb.buf) || + mkdir(sb.buf, 0777)) { + strbuf_release(&sb); + errno = saved_errno; + return -1; + } + strbuf_release(&sb); + } + return adjust_shared_perm(path); +} + int safe_create_leading_directories(char *path) { char *pos = path + offset_1st_component(path); @@ -1510,7 +1534,7 @@ static int unpack_object_header(struct packed_git *p, enum object_type type; /* use_pack() assures us we have [base, base + 20) available - * as a range that we can look at at. (Its actually the hash + * as a range that we can look at. (Its actually the hash * size that is assured.) With our object header encoding * the maximum deflated object size is 2^137, which is just * insane, so we know won't exceed what we have been given.