ATBTariffCalculator/CalculatorCInterface/calculator_c_interface_lib.cpp

51 lines
1.1 KiB
C++
Raw Normal View History

2024-03-04 16:31:14 +01:00
#include "calculator_c_interface_lib.h"
2024-03-11 14:27:33 +01:00
#include <git2.h>
#include <stdio.h>
2024-03-04 16:31:14 +01:00
#ifdef __cplusplus
extern "C" {
#endif
2024-03-11 14:27:33 +01:00
TariffCalculatorHandle NewTariffCalculator(void) {
2024-03-11 12:14:28 +01:00
return new TariffCalculator();
}
2024-03-04 16:31:14 +01:00
2024-03-11 14:27:33 +01:00
void DeleteTariffCalculator(TariffCalculatorHandle handle) {
2024-03-11 12:14:28 +01:00
delete handle;
2024-03-04 16:31:14 +01:00
}
2024-03-11 14:27:33 +01:00
int InitGitLibrary(void) {
return git_libgit2_init();
}
int ShutdownGitLibrary(void) {
return git_libgit2_shutdown();
}
int CloneRepository(char const *url, char const *local_path) {
git_repository *out;
git_clone_options opts;
int res = 0;
if ((res = git_clone_options_init(&opts, GIT_CLONE_OPTIONS_VERSION)) == 0) {
opts.checkout_branch = "master";
fprintf(stderr, "%s:%d %s %s\n", __func__, __LINE__, url, local_path);
if ((res = git_clone(&out, url, local_path, &opts)) < 0) {
git_error const *error = git_error_last();
fprintf(stderr, "%s:%d error: %s\n", __func__, __LINE__, error->message);
}
} else {
git_error const *error = git_error_last();
fprintf(stderr, "%s:%d error: %s\n", __func__, __LINE__, error->message);
}
return res;
}
2024-03-11 12:14:28 +01:00
2024-03-04 16:31:14 +01:00
#ifdef __cplusplus
}
#endif