aboutsummaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-03-26 20:13:16 -0700
committerJunio C Hamano <gitster@pobox.com>2011-03-26 20:13:16 -0700
commitad7bb2f68c0b7786521173e05ef58d0f3e0db3d7 (patch)
tree9fc6b2df2743b837f774c0ce925cdad2427c4535 /sha1_file.c
parent54f6a8dbd65cbe6ad31a8b6b531de81009514eb3 (diff)
parent90a6464b4ad5887e4d12e660f51dabdbd5c00812 (diff)
downloadgit-ad7bb2f68c0b7786521173e05ef58d0f3e0db3d7.tar.gz
git-ad7bb2f68c0b7786521173e05ef58d0f3e0db3d7.tar.xz
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.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 7829d615d..df0edbad1 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);