From patchwork Thu May 2 14:48:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matheus Tavares X-Patchwork-Id: 10927031 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BAF2414B6 for ; Thu, 2 May 2019 14:49:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AACEC285B5 for ; Thu, 2 May 2019 14:49:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F435285C3; Thu, 2 May 2019 14:49:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4428C285B5 for ; Thu, 2 May 2019 14:49:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726477AbfEBOtM (ORCPT ); Thu, 2 May 2019 10:49:12 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:46682 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726297AbfEBOtL (ORCPT ); Thu, 2 May 2019 10:49:11 -0400 Received: by mail-qt1-f195.google.com with SMTP id i31so2734330qti.13 for ; Thu, 02 May 2019 07:49:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=usp-br.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bWCV+CWpi3XnwtnI5CIUo+JQ1nhJiKlP+GPCB1eYga4=; b=JFVta34k+qi+my0WI+awnYgdPccTOtCrROhkW+Cop7QGO9HUTQXoVpYQs9sZQjQzsk uQ9Dsle/i24dHqwzwpY5epLfErtqbsLDnOSEzlCbiMjE4ABcZ8g1P08szXZC0pcPt6K1 U7nyHhidbeYywp1neM9klrC9gomvHycqUhMql8WHzBcIzlt850uIjma3GdIUn33Dwryh oLiWvNUGcz+pIsAHdMic73a2m21L3DpUs/mt73LmHeSt0/QtfxJvz+aQ6mldc8zkEWfV F3Qfhhm8bgjWbtXzlMEXU5uN7Cjk2sGLmzUX+NjwKfwi6oQf87f5Eal465tBJ/4Ho3mN LAQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bWCV+CWpi3XnwtnI5CIUo+JQ1nhJiKlP+GPCB1eYga4=; b=pKRanV3dofSB77bd6MZ4NQT9vXks4OUIOBxrpAF6xMgQ0VcPzkrJd8kz6ur/Ck+IbR 0r1w+fAUOGCreRylYoznwFZdWqltpS/cQ7OTLmta7RoI7XmG7bAMSBIdEShPl3SUXvjD AcHjBioSoiQWoIOrcl1/ABynfPTIATjWCR35NPF2+EoVCsscsRvERx7gDRowuPLHMw3d RS845AUo16HVV2ykPSXiSYjMJfwRRBvxHy6DVE+7sX6hybUo+HbUb/3XvLR7IS8l8Ej3 dl67x0m02dF1y+RQXQXsqN/3jgRV46yZRznd2fkj5pmhwXcOTfcLM28Uu3vi1DqRU3Pl gKCg== X-Gm-Message-State: APjAAAUHsqSy/g44293yvj59cKCb4fiMz1Ms3xOVq+goTl6stAZclVwt KLud2YATfF5+P7O+gh21GCILoJV9HgI= X-Google-Smtp-Source: APXvYqyzsVQMYjh+W0yU1Q9d3D8oT+Lbz1yNEJYbuqAPZttqNYJTxkEQmyf9Ul0wHnkVjOyS+u6/oA== X-Received: by 2002:aed:3522:: with SMTP id a31mr3356037qte.269.1556808549347; Thu, 02 May 2019 07:49:09 -0700 (PDT) Received: from mango.spo.virtua.com.br ([2804:14c:81:942d::1]) by smtp.gmail.com with ESMTPSA id s64sm22002880qkc.39.2019.05.02.07.49.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 May 2019 07:49:08 -0700 (PDT) From: Matheus Tavares To: git@vger.kernel.org Cc: Thomas Gummerer , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= , Christian Couder , =?utf-8?b?Tmd1eeG7hW4gVGg=?= =?utf-8?b?w6FpIE5n4buNYyBEdXk=?= , =?utf-8?q?SZEDER_G?= =?utf-8?q?=C3=A1bor?= , kernel-usp@googlegroups.com, Junio C Hamano , Michael Haggerty Subject: [GSoC][PATCH v6 08/10] clone: extract function from copy_or_link_directory Date: Thu, 2 May 2019 11:48:27 -0300 Message-Id: <20190502144829.4394-9-matheus.bernardino@usp.br> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190502144829.4394-1-matheus.bernardino@usp.br> References: <20190330224907.3277-1-matheus.bernardino@usp.br> <20190502144829.4394-1-matheus.bernardino@usp.br> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- builtin/clone.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/builtin/clone.c b/builtin/clone.c index f117a6b206..1ee6d6050e 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -392,6 +392,21 @@ static void copy_alternates(struct strbuf *src, struct strbuf *dst, 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) { @@ -404,14 +419,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;