From: Atharva Raykar Date: Thu, 16 Sep 2021 10:32:34 GMT Subject: [PATCH v2 1/8] submodule--helper: split up ensure_core_worktree() Message-ID: <20210916103241.62376-2-raykar.ath@gmail.com> In-Reply-To: <20210916103241.62376-1-raykar.ath@gmail.com> Let's split up `ensure_core_worktree()` so that we can call it from C code without needing to deal with command line arguments. Mentored-by: Christian Couder Mentored-by: Shourya Shukla Signed-off-by: Atharva Raykar --- builtin/submodule--helper.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 80619361fc..97512ccf0b 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2794,18 +2794,12 @@ static int push_check(int argc, const char **argv, const char *prefix) return 0; } -static int ensure_core_worktree(int argc, const char **argv, const char *prefix) +static void do_ensure_core_worktree(const char *path) { const struct submodule *sub; - const char *path; const char *cw; struct repository subrepo; - if (argc != 2) - BUG("submodule--helper ensure-core-worktree "); - - path = argv[1]; - sub = submodule_from_path(the_repository, null_oid(), path); if (!sub) BUG("We could get the submodule handle before?"); @@ -2829,6 +2823,17 @@ static int ensure_core_worktree(int argc, const char **argv, const char *prefix) free(abs_path); strbuf_release(&sb); } +} + +static int ensure_core_worktree(int argc, const char **argv, const char *prefix) +{ + const char *path; + + if (argc != 2) + BUG("submodule--helper ensure-core-worktree "); + + path = argv[1]; + do_ensure_core_worktree(path); return 0; } -- 2.32.0