diff options
author | Junio C Hamano <gitster@pobox.com> | 2011-03-26 20:13:16 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-03-26 20:13:16 -0700 |
commit | ad7bb2f68c0b7786521173e05ef58d0f3e0db3d7 (patch) | |
tree | 9fc6b2df2743b837f774c0ce925cdad2427c4535 /sha1_file.c | |
parent | 54f6a8dbd65cbe6ad31a8b6b531de81009514eb3 (diff) | |
parent | 90a6464b4ad5887e4d12e660f51dabdbd5c00812 (diff) | |
download | git-ad7bb2f68c0b7786521173e05ef58d0f3e0db3d7.tar.gz |
Merge branch 'jc/maint-rerere-in-workdir'
* jc/maint-rerere-in-workdir:
rerere: make sure it works even in a workdir attached to a young repository
Diffstat (limited to 'sha1_file.c')
-rw-r--r-- | sha1_file.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/sha1_file.c b/sha1_file.c index 7829d615d4..df0edbad1e 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -68,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); |