From: "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: sunshine@sunshineco.com, gitster@pobox.com, newren@gmail.com,
jn.avila@free.fr, Taylor Blau <me@ttaylorr.com>,
Derrick Stolee <derrickstolee@github.com>,
Derrick Stolee <derrickstolee@github.com>
Subject: [PATCH v3 03/11] worktree: extract copy_sparse_checkout()
Date: Wed, 23 Feb 2022 14:29:11 +0000 [thread overview]
Message-ID: <ccc5b1ef9fb4dbeedfbc1ad8f0da36299bf48b56.1645626559.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1154.v3.git.1645626559.gitgitgadget@gmail.com>
From: Derrick Stolee <derrickstolee@github.com>
This logic was introduced by 5325591 (worktree: copy sparse-checkout
patterns and config on add, 2022-02-07), but some feedback came in that
the add_worktree() method was already too complex. It is better to
extract this logic into a helper method to reduce this complexity.
Reported-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Derrick Stolee <derrickstolee@github.com>
---
builtin/worktree.c | 33 ++++++++++++++++++---------------
1 file changed, 18 insertions(+), 15 deletions(-)
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 2771a6dc793..c806aa2b261 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -236,6 +236,22 @@ static void check_candidate_path(const char *path,
die(_("'%s' is a missing but already registered worktree;\nuse '%s -f' to override, or 'prune' or 'remove' to clear"), path, cmd);
}
+static void copy_sparse_checkout(const char *worktree_git_dir)
+{
+ char *from_file = git_pathdup("info/sparse-checkout");
+ char *to_file = xstrfmt("%s/info/sparse-checkout", worktree_git_dir);
+
+ if (file_exists(from_file)) {
+ if (safe_create_leading_directories(to_file) ||
+ copy_file(to_file, from_file, 0666))
+ error(_("failed to copy '%s' to '%s'; sparse-checkout may not work correctly"),
+ from_file, to_file);
+ }
+
+ free(from_file);
+ free(to_file);
+}
+
static void copy_filtered_worktree_config(const char *worktree_git_dir)
{
char *from_file = git_pathdup("config.worktree");
@@ -379,21 +395,8 @@ static int add_worktree(const char *path, const char *refname,
* If the current worktree has sparse-checkout enabled, then copy
* the sparse-checkout patterns from the current worktree.
*/
- if (core_apply_sparse_checkout) {
- char *from_file = git_pathdup("info/sparse-checkout");
- char *to_file = xstrfmt("%s/info/sparse-checkout",
- sb_repo.buf);
-
- if (file_exists(from_file)) {
- if (safe_create_leading_directories(to_file) ||
- copy_file(to_file, from_file, 0666))
- error(_("failed to copy '%s' to '%s'; sparse-checkout may not work correctly"),
- from_file, to_file);
- }
-
- free(from_file);
- free(to_file);
- }
+ if (core_apply_sparse_checkout)
+ copy_sparse_checkout(sb_repo.buf);
/*
* If we are using worktree config, then copy all current config
--
gitgitgadget
next prev parent reply other threads:[~2022-02-23 14:29 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-20 17:54 [PATCH 00/11] Updates to worktree code and docs Derrick Stolee via GitGitGadget
2022-02-20 17:54 ` [PATCH 01/11] worktree: combine two translatable messages Derrick Stolee via GitGitGadget
2022-02-20 20:22 ` Junio C Hamano
2022-02-20 20:29 ` Derrick Stolee
2022-02-20 17:54 ` [PATCH 02/11] worktree: extract copy_filtered_worktree_config() Derrick Stolee via GitGitGadget
2022-02-20 20:26 ` Junio C Hamano
2022-02-20 17:54 ` [PATCH 03/11] worktree: extract copy_sparse_checkout() Derrick Stolee via GitGitGadget
2022-02-20 17:54 ` [PATCH 04/11] worktree: extract checkout_worktree() Derrick Stolee via GitGitGadget
2022-02-20 21:59 ` Taylor Blau
2022-02-20 17:54 ` [PATCH 05/11] worktree: use 'worktree' over 'working tree' Derrick Stolee via GitGitGadget
2022-02-20 20:42 ` Junio C Hamano
2022-02-20 20:48 ` Derrick Stolee
2022-02-24 14:33 ` Philip Oakley
2022-02-24 15:53 ` Derrick Stolee
2022-03-03 15:41 ` Philip Oakley
2022-02-20 17:54 ` [PATCH 06/11] " Derrick Stolee via GitGitGadget
2022-02-20 17:54 ` [PATCH 07/11] " Derrick Stolee via GitGitGadget
2022-02-20 17:54 ` [PATCH 08/11] " Derrick Stolee via GitGitGadget
2022-02-20 22:29 ` Taylor Blau
2022-02-20 17:54 ` [PATCH 09/11] " Derrick Stolee via GitGitGadget
2022-02-20 22:31 ` Taylor Blau
2022-02-21 2:26 ` Derrick Stolee
2022-02-20 17:54 ` [PATCH 10/11] " Derrick Stolee via GitGitGadget
2022-02-20 17:54 ` [PATCH 11/11] " Derrick Stolee via GitGitGadget
2022-02-20 22:37 ` Taylor Blau
2022-02-21 2:11 ` Derrick Stolee
2022-02-20 22:38 ` [PATCH 00/11] Updates to worktree code and docs Taylor Blau
2022-02-20 22:41 ` Taylor Blau
2022-02-22 0:17 ` [PATCH v2 " Derrick Stolee via GitGitGadget
2022-02-22 0:17 ` [PATCH v2 01/11] worktree: combine two translatable messages Derrick Stolee via GitGitGadget
2022-02-22 0:17 ` [PATCH v2 02/11] worktree: extract copy_filtered_worktree_config() Derrick Stolee via GitGitGadget
2022-02-22 0:17 ` [PATCH v2 03/11] worktree: extract copy_sparse_checkout() Derrick Stolee via GitGitGadget
2022-02-22 0:17 ` [PATCH v2 04/11] worktree: extract checkout_worktree() Derrick Stolee via GitGitGadget
2022-02-22 0:17 ` [PATCH v2 05/11] worktree: use 'worktree' over 'working tree' Derrick Stolee via GitGitGadget
2022-02-22 7:22 ` Junio C Hamano
2022-02-23 6:47 ` Elijah Newren
2022-02-22 0:17 ` [PATCH v2 06/11] " Derrick Stolee via GitGitGadget
2022-02-22 7:22 ` Junio C Hamano
2022-02-22 14:06 ` Derrick Stolee
2022-02-22 0:17 ` [PATCH v2 07/11] " Derrick Stolee via GitGitGadget
2022-02-22 0:17 ` [PATCH v2 08/11] " Derrick Stolee via GitGitGadget
2022-02-22 19:49 ` Taylor Blau
2022-02-22 21:24 ` Derrick Stolee
2022-02-23 0:05 ` Taylor Blau
2022-02-22 0:17 ` [PATCH v2 09/11] " Derrick Stolee via GitGitGadget
2022-02-22 0:17 ` [PATCH v2 10/11] " Derrick Stolee via GitGitGadget
2022-02-22 0:18 ` [PATCH v2 11/11] " Derrick Stolee via GitGitGadget
2022-02-22 19:50 ` [PATCH v2 00/11] Updates to worktree code and docs Taylor Blau
2022-02-23 20:24 ` Junio C Hamano
2022-02-23 6:51 ` Elijah Newren
2022-02-23 14:26 ` Derrick Stolee
2022-02-23 14:29 ` [PATCH v3 " Derrick Stolee via GitGitGadget
2022-02-23 14:29 ` [PATCH v3 01/11] worktree: combine two translatable messages Derrick Stolee via GitGitGadget
2022-02-23 14:29 ` [PATCH v3 02/11] worktree: extract copy_filtered_worktree_config() Derrick Stolee via GitGitGadget
2022-02-23 14:29 ` Derrick Stolee via GitGitGadget [this message]
2022-02-23 14:29 ` [PATCH v3 04/11] worktree: extract checkout_worktree() Derrick Stolee via GitGitGadget
2022-02-23 14:29 ` [PATCH v3 05/11] worktree: use 'worktree' over 'working tree' Derrick Stolee via GitGitGadget
2022-02-23 14:29 ` [PATCH v3 06/11] " Derrick Stolee via GitGitGadget
2022-02-23 14:29 ` [PATCH v3 07/11] " Derrick Stolee via GitGitGadget
2022-02-23 14:29 ` [PATCH v3 08/11] " Derrick Stolee via GitGitGadget
2022-02-23 14:29 ` [PATCH v3 09/11] " Derrick Stolee via GitGitGadget
2022-02-23 14:29 ` [PATCH v3 10/11] " Derrick Stolee via GitGitGadget
2022-02-23 14:29 ` [PATCH v3 11/11] " Derrick Stolee via GitGitGadget
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ccc5b1ef9fb4dbeedfbc1ad8f0da36299bf48b56.1645626559.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=derrickstolee@github.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jn.avila@free.fr \
--cc=me@ttaylorr.com \
--cc=newren@gmail.com \
--cc=sunshine@sunshineco.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).