aboutsummaryrefslogtreecommitdiff
path: root/src/fetch_git.c
diff options
context:
space:
mode:
authordacctal <donotcontactmevia@email.invalid>2026-06-25 21:19:44 +0000
committerdacctal <donotcontactmevia@email.invalid>2026-06-25 21:19:44 +0000
commitd64dc64740b7705c64c0ddbff3f989669c016955 (patch)
treecc76e02e9daf9127251f9794cc36de2f38288d48 /src/fetch_git.c
parent724c40efd999597c0e3262181b73e5ff3bbf705f (diff)
FCC: improve fetch_git w/ null checks & error handling1.2.0
Diffstat (limited to 'src/fetch_git.c')
-rw-r--r--src/fetch_git.c92
1 files changed, 45 insertions, 47 deletions
diff --git a/src/fetch_git.c b/src/fetch_git.c
index 570cb1d..8784a03 100644
--- a/src/fetch_git.c
+++ b/src/fetch_git.c
@@ -1,4 +1,3 @@
-
/*
pkgit - package it!
@@ -18,7 +17,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
@@ -29,56 +27,56 @@
#include "vars.h"
int fetch_git(Pkg pkg) {
- if (pkg.url == NULL || pkg.src == NULL) {
- fprintf(stderr, "%s invalid pkg: url or src is NULL\n", print_warning);
- return -1;
+ if (pkg.url == NULL || pkg.src == NULL) {
+ fprintf(stderr, "%s invalid pkg: url or src is NULL\n", print_warning);
+ return -1;
+ }
+
+ pid_t pid = fork();
+ if (pid < 0) {
+ perror("fork failed");
+ return -1;
+ }
+
+ if (pid == 0) {
+ if (!is_verbose) {
+ int nullfd = open("/dev/null", O_WRONLY);
+ if (nullfd >= 0) {
+ dup2(nullfd, STDOUT_FILENO);
+ dup2(nullfd, STDERR_FILENO);
+ close(nullfd);
+ }
}
- pid_t pid = fork();
- if (pid < 0) {
- perror("fork failed");
- return -1;
- }
+ const char *argv[12];
+ int i = 0;
+
+ argv[i++] = "git";
+ argv[i++] = "-c";
+ argv[i++] = "advice.detachedHead=false";
+ argv[i++] = "clone";
- if (pid == 0) {
- if (!is_verbose) {
- int nullfd = open("/dev/null", O_WRONLY);
- if (nullfd >= 0) {
- dup2(nullfd, STDOUT_FILENO);
- dup2(nullfd, STDERR_FILENO);
- close(nullfd);
- }
- }
-
- const char *argv[12];
- int i = 0;
-
- argv[i++] = "git";
- argv[i++] = "-c";
- argv[i++] = "advice.detachedHead=false";
- argv[i++] = "clone";
-
- if (pkg.ver != NULL && strcmp(pkg.ver, "HEAD") != 0) {
- argv[i++] = "--branch";
- argv[i++] = pkg.ver;
- }
-
- argv[i++] = "--recursive";
- argv[i++] = pkg.url;
- argv[i++] = pkg.src;
- argv[i] = NULL;
-
- execvp("git", (char *const *)argv);
- _exit(127);
+ if (pkg.ver != NULL && strcmp(pkg.ver, "HEAD") != 0) {
+ argv[i++] = "--branch";
+ argv[i++] = pkg.ver;
}
- int status;
- waitpid(pid, &status, 0);
+ argv[i++] = "--recursive";
+ argv[i++] = pkg.url;
+ argv[i++] = pkg.src;
+ argv[i] = NULL;
- int result = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
- if (result != 0) {
- printf("%s git clone failed: %d\n", print_warning, result);
- }
+ execvp("git", (char *const *)argv);
+ _exit(127);
+ }
+
+ int status;
+ waitpid(pid, &status, 0);
+
+ int result = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
+ if (result != 0) {
+ printf("%s git clone failed: %d\n", print_warning, result);
+ }
- return result;
+ return result;
}