Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatheus Tavares <matheus.bernardino@usp.br>2019-07-11 02:59:02 +0300
committerJunio C Hamano <gitster@pobox.com>2019-07-11 23:52:15 +0300
commit14954b799f0bac76e500593c95d1f274cf0636e5 (patch)
tree80917c12efa7de0977796d38380f7780fcf99732 /builtin
parent68c7c59cf202a4d90d96f19076a33d12278c5864 (diff)
clone: extract function from copy_or_link_directory
Extract dir creation code snippet from copy_or_link_directory to its own function named mkdir_if_missing. This change will help to remove copy_or_link_directory's explicit recursion, which will be done in a following patch. Also makes the code more readable. Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/clone.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/builtin/clone.c b/builtin/clone.c
index 541f0e1be3..297af3f40e 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -391,6 +391,21 @@ static void copy_alternates(struct strbuf *src, const char *src_repo)
fclose(in);
}
+static void mkdir_if_missing(const char *pathname, mode_t mode)
+{
+ struct stat st;
+
+ if (!mkdir(pathname, mode))
+ return;
+
+ if (errno != EEXIST)
+ die_errno(_("failed to create directory '%s'"), pathname);
+ else if (stat(pathname, &st))
+ die_errno(_("failed to stat '%s'"), pathname);
+ else if (!S_ISDIR(st.st_mode))
+ die(_("%s exists and is not a directory"), pathname);
+}
+
static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest,
const char *src_repo, int src_baselen)
{
@@ -403,14 +418,7 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest,
if (!dir)
die_errno(_("failed to open '%s'"), src->buf);
- if (mkdir(dest->buf, 0777)) {
- if (errno != EEXIST)
- die_errno(_("failed to create directory '%s'"), dest->buf);
- else if (stat(dest->buf, &buf))
- die_errno(_("failed to stat '%s'"), dest->buf);
- else if (!S_ISDIR(buf.st_mode))
- die(_("%s exists and is not a directory"), dest->buf);
- }
+ mkdir_if_missing(dest->buf, 0777);
strbuf_addch(src, '/');
src_len = src->len;