From: Junio C Hamano <junkio@cox.net>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH 2/2] Teach "git-read-tree -u" to check out submodules as a directory
Date: Thu, 12 Apr 2007 21:32:48 -0700 [thread overview]
Message-ID: <7v7isghp1r.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <Pine.LNX.4.64.0704122104030.4061@woody.linux-foundation.org> (Linus Torvalds's message of "Thu, 12 Apr 2007 21:08:52 -0700 (PDT)")
Linus Torvalds <torvalds@linux-foundation.org> writes:
> @@ -136,8 +147,13 @@ static int write_entry(struct cache_entry *ce, char *path, struct checkout *stat
> "symlink %s (%s)", path, strerror(errno));
> }
> break;
> + case S_IFDIRLNK:
> + if (to_tempfile)
> + return error("git-checkout-index: cannot create temporary subproject %s", path);
> + if (mkdir(path, 0777) < 0)
> + return error("git-checkout-index: cannot create subproject directory %s", path);
> + break;
> default:
> return error("git-checkout-index: unknown file mode for %s", path);
> }
>
Hmm. Perhaps something like this on top?
diff --git a/entry.c b/entry.c
index 9545e89..0874d61 100644
--- a/entry.c
+++ b/entry.c
@@ -1,6 +1,23 @@
#include "cache.h"
#include "blob.h"
+static int make_directory(const char *path, int unlink_as_needed)
+{
+ if (mkdir(path, 0777) < 0) {
+ if (errno == EEXIST) {
+ struct stat st;
+ if (unlink_as_needed &&
+ !unlink(path) &&
+ !mkdir(path, 0777))
+ return 0; /* ok */
+ if (!stat(path, &st) && S_ISDIR(st.st_mode))
+ return 0; /* ok */
+ }
+ return -1;
+ }
+ return 0;
+}
+
static void create_directories(const char *path, struct checkout *state)
{
int len = strlen(path);
@@ -8,19 +25,14 @@ static void create_directories(const char *path, struct checkout *state)
const char *slash = path;
while ((slash = strchr(slash+1, '/')) != NULL) {
+ int unlink_as_needed;
+
len = slash - path;
memcpy(buf, path, len);
buf[len] = 0;
- if (mkdir(buf, 0777)) {
- if (errno == EEXIST) {
- struct stat st;
- if (len > state->base_dir_len && state->force && !unlink(buf) && !mkdir(buf, 0777))
- continue;
- if (!stat(buf, &st) && S_ISDIR(st.st_mode))
- continue; /* ok */
- }
+ unlink_as_needed = (state->base_dir_len < len && state->force);
+ if (make_directory(buf, unlink_as_needed) < 0)
die("cannot create directory at %s", buf);
- }
}
free(buf);
}
@@ -150,7 +162,7 @@ static int write_entry(struct cache_entry *ce, char *path, struct checkout *stat
case S_IFDIRLNK:
if (to_tempfile)
return error("git-checkout-index: cannot create temporary subproject %s", path);
- if (mkdir(path, 0777) < 0)
+ if (make_directory(path, 0))
return error("git-checkout-index: cannot create subproject directory %s", path);
break;
default:
next prev parent reply other threads:[~2007-04-13 4:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-13 4:03 [PATCH 1/2] Teach git list-objects logic not to follow gitlinks Linus Torvalds
2007-04-13 4:08 ` [PATCH 2/2] Teach "git-read-tree -u" to check out submodules as a directory Linus Torvalds
2007-04-13 4:15 ` Linus Torvalds
2007-04-13 4:32 ` Junio C Hamano [this message]
2007-04-13 4:54 ` Linus Torvalds
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7v7isghp1r.fsf@assigned-by-dhcp.cox.net \
--to=junkio@cox.net \
--cc=git@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox