Merge pull request #7274 from libgit2/ethomson/ci

examples: don't system() anything
This commit is contained in:
Edward Thomson
2026-05-22 14:43:21 +01:00
committed by GitHub

View File

@@ -14,7 +14,6 @@
#include "common.h" #include "common.h"
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h>
#define REPO_PATH "test-repo" #define REPO_PATH "test-repo"
#define CLONE_PATH "test-repo-clone" #define CLONE_PATH "test-repo-clone"
@@ -154,14 +153,9 @@ static void display_history(git_repository *repo, const char *title, int max_com
static void create_initial_repository(const char *path) static void create_initial_repository(const char *path)
{ {
git_repository *repo = NULL; git_repository *repo = NULL;
char cmd[256];
printf("Creating repository at %s...\n", path); printf("Creating repository at %s...\n", path);
/* Remove existing repository if present */
snprintf(cmd, sizeof(cmd), "rm -rf %s", path);
system(cmd);
/* Initialize repository */ /* Initialize repository */
check_error(git_repository_init(&repo, path, 0), "Failed to initialize repository"); check_error(git_repository_init(&repo, path, 0), "Failed to initialize repository");
@@ -181,14 +175,9 @@ static void clone_repository(const char *source_path, const char *dest_path)
{ {
git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT; git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
git_repository *cloned_repo = NULL; git_repository *cloned_repo = NULL;
char cmd[256];
printf("Cloning repository from %s to %s...\n", source_path, dest_path); printf("Cloning repository from %s to %s...\n", source_path, dest_path);
/* Remove existing clone if present */
snprintf(cmd, sizeof(cmd), "rm -rf %s", dest_path);
system(cmd);
/* Clone the repository */ /* Clone the repository */
check_error(git_clone(&cloned_repo, source_path, dest_path, &clone_opts), "Failed to clone repository"); check_error(git_clone(&cloned_repo, source_path, dest_path, &clone_opts), "Failed to clone repository");
@@ -265,7 +254,7 @@ static char* read_blob_content(git_repository *repo, const git_oid *oid)
return strdup("(unable to read content)"); return strdup("(unable to read content)");
} }
size = git_blob_rawsize(blob); size = (size_t)git_blob_rawsize(blob);
content = malloc(size + 1); content = malloc(size + 1);
if (content) { if (content) {
memcpy(content, git_blob_rawcontent(blob), size); memcpy(content, git_blob_rawcontent(blob), size);
@@ -284,7 +273,7 @@ static char** split_lines(const char *content, int *line_count)
char **lines = malloc(capacity * sizeof(char*)); char **lines = malloc(capacity * sizeof(char*));
const char *start = content; const char *start = content;
const char *end; const char *end;
int len; size_t len;
while (*start) { while (*start) {
end = strchr(start, '\n'); end = strchr(start, '\n');