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 [off-list ref]
Mentored-by: Shourya Shukla [off-list ref]
Signed-off-by: Atharva Raykar <redacted>
---
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>");
-
- 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>");
+
+ path = argv[1];
+ do_ensure_core_worktree(path);
return 0;
}--
2.32.0