From: Geert Bosch <bosch@gnat.com>
To: git@vger.kernel.org
Subject: [PATCH] create_directories: simplify and avoid repeated copying
Date: Thu, 12 Apr 2007 16:29:10 -0400 [thread overview]
Message-ID: <20070414013003.B0B4C2F1DC3@geert-boschs-computer.local> (raw)
Signed-off-by: Geert Bosch <bosch@gnat.com>
---
I needed to change the logic of this function a bit for
doing some local hacks^Wmodifications and thought it might
be a slight improvement/simplification.
No change in functionality and passed 'make test'.
entry.c | 23 +++++++++--------------
1 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/entry.c b/entry.c
index d72f811..f966c59 100644
--- a/entry.c
+++ b/entry.c
@@ -3,24 +3,19 @@
static void create_directories(const char *path, struct checkout *state)
{
- int len = strlen(path);
- char *buf = xmalloc(len + 1);
- const char *slash = path;
+ char *buf = xstrdup(path);
+ char *slash = buf;
while ((slash = strchr(slash+1, '/')) != NULL) {
- len = slash - path;
- memcpy(buf, path, len);
- buf[len] = 0;
+ *slash = 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 */
- }
- die("cannot create directory at %s", buf);
+ struct stat st;
+ int force = (slash - buf) > state->base_dir_len && state->force;
+ if (errno != EEXIST || ((!force || unlink(buf) || mkdir(buf, 0777)) &&
+ (stat(buf, &st) || !S_ISDIR(st.st_mode))))
+ die("cannot create directory at %s", buf);
}
+ *slash='/';
}
free(buf);
}
--
1.5.1
next reply other threads:[~2007-04-14 1:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-12 20:29 Geert Bosch [this message]
2007-04-14 14:11 ` [PATCH] create_directories: simplify and avoid repeated copying Junio C Hamano
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=20070414013003.B0B4C2F1DC3@geert-boschs-computer.local \
--to=bosch@gnat.com \
--cc=git@vger.kernel.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