From aa0d78815004ae6b0c4a42b0e024f5c4ef555ae2 Mon Sep 17 00:00:00 2001 From: dacctal Date: Sun, 24 May 2026 10:23:38 +0000 Subject: c rewrite --- src/fetch_git.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/fetch_git.c (limited to 'src/fetch_git.c') diff --git a/src/fetch_git.c b/src/fetch_git.c new file mode 100644 index 0000000..04f6428 --- /dev/null +++ b/src/fetch_git.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include + +#include "fetch_git.h" +#include "vars.h" + +int fetch_git(Pkg pkg) { + pid_t pid = fork(); + if (pid == 0) { + const char *argv[8]; + int i = 0; + argv[i++] = "git"; + argv[i++] = "-c"; + argv[i++] = "advice.detachedHead=false"; + argv[i++] = "clone"; + if (strcmp(pkg.ver, "HEAD") != 0) { + argv[i++] = "--branch"; + argv[i++] = pkg.ver; + } + argv[i++] = pkg.url; + argv[i++] = pkg.src; + argv[i] = NULL; + + execvp("git", (char *const *)argv); + _exit(127); + } + + int status; + waitpid(pid, &status, 0); + int result = WIFEXITED(status) ? WEXITSTATUS(status) : -1; + + if (result != 0) { + printf("clone failed\n"); + } + + return result; +} \ No newline at end of file -- cgit v1.2.3