2022-08-20 00:02:00 +02:00
|
|
|
/* radare - LGPL - Copyright 2021-2022 - RHL120, pancake */
|
|
|
|
|
2022-10-24 23:32:04 +02:00
|
|
|
#define R_LOG_ORIGIN "rvc"
|
2021-04-26 11:27:46 +02:00
|
|
|
|
2022-10-24 23:32:04 +02:00
|
|
|
#include <rvc.h>
|
2021-06-21 08:44:06 +02:00
|
|
|
#define DBNAME "branches.sdb"
|
2021-04-26 11:27:46 +02:00
|
|
|
|
2022-11-14 14:10:57 +01:00
|
|
|
extern RvcPlugin r_vc_plugin_git;
|
|
|
|
extern RvcPlugin r_vc_plugin_rvc;
|
2021-04-26 11:27:46 +02:00
|
|
|
|
|
|
|
|
2022-11-14 14:10:57 +01:00
|
|
|
R_API void rvc_free(Rvc *vc) {
|
2022-05-26 19:52:01 +02:00
|
|
|
if (vc) {
|
2022-09-27 12:10:26 +02:00
|
|
|
// sdb_sync ()
|
2022-05-26 19:52:01 +02:00
|
|
|
sdb_close (vc->db);
|
|
|
|
free (vc->path);
|
|
|
|
free (vc);
|
|
|
|
}
|
|
|
|
}
|
2022-09-26 11:17:04 +02:00
|
|
|
|
2022-11-14 14:10:57 +01:00
|
|
|
R_API bool rvc_use(Rvc *vc, RvcType type) {
|
2022-09-26 11:17:04 +02:00
|
|
|
switch (type) {
|
2022-09-27 12:10:26 +02:00
|
|
|
case RVC_TYPE_GIT:
|
2022-11-14 14:10:57 +01:00
|
|
|
vc->p = &r_vc_plugin_git;
|
2022-09-26 11:17:04 +02:00
|
|
|
break;
|
2022-09-27 12:10:26 +02:00
|
|
|
case RVC_TYPE_RVC:
|
2022-11-14 14:10:57 +01:00
|
|
|
vc->p = &r_vc_plugin_rvc;
|
2022-09-26 11:17:04 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
r_return_val_if_reached (false);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-11-14 14:10:57 +01:00
|
|
|
R_API int rvc_repo_type(const char *path) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API Rvc *rvc_open(const char *path, RvcType type) {
|
2022-09-27 12:10:26 +02:00
|
|
|
r_return_val_if_fail (path, NULL);
|
2022-11-14 14:10:57 +01:00
|
|
|
Rvc *rvc = NULL;
|
|
|
|
int repotype = (type == -1)? rvc_repo_type (path): type;
|
|
|
|
switch (repotype) {
|
|
|
|
case RVC_TYPE_GIT:
|
|
|
|
rvc = r_vc_plugin_git.open (path);
|
|
|
|
rvc->p = &r_vc_plugin_git;
|
|
|
|
break;
|
|
|
|
case RVC_TYPE_RVC:
|
|
|
|
rvc = r_vc_plugin_rvc.open (path);
|
|
|
|
rvc->p = &r_vc_plugin_rvc;
|
|
|
|
break;
|
2022-09-26 11:17:04 +02:00
|
|
|
}
|
2022-11-14 14:10:57 +01:00
|
|
|
return rvc;
|
2022-09-26 11:17:04 +02:00
|
|
|
}
|
|
|
|
|
2022-11-14 14:10:57 +01:00
|
|
|
#if 0
|
|
|
|
// XXX this is conceptually wrong
|
2022-09-27 12:10:26 +02:00
|
|
|
R_API Rvc *rvc_init(const char *path, RvcType type) {
|
|
|
|
r_return_val_if_fail (path, NULL);
|
2022-11-14 14:10:57 +01:00
|
|
|
#if 0
|
|
|
|
RvcPluginBranch open = R_UNWRAP3 (vc, p, open);
|
|
|
|
return open? open (vc, path, type): NULL;
|
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
r_return_val_if_fail (path, NULL);
|
2022-09-27 12:10:26 +02:00
|
|
|
switch (type) {
|
|
|
|
case RVC_TYPE_GIT:
|
2022-09-26 11:17:04 +02:00
|
|
|
return r_vc_git_init (path);
|
2022-09-27 12:10:26 +02:00
|
|
|
break;
|
|
|
|
case RVC_TYPE_RVC:
|
|
|
|
{
|
|
|
|
Rvc *rvc = r_vc_new (path);
|
2022-11-14 14:10:57 +01:00
|
|
|
if (!rvc || !rvc_save (rvc)) {
|
2022-09-27 12:10:26 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return rvc;
|
2022-09-26 11:17:04 +02:00
|
|
|
}
|
2022-09-27 12:10:26 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2022-09-26 11:17:04 +02:00
|
|
|
}
|
2022-09-27 12:10:26 +02:00
|
|
|
R_LOG_ERROR ("Unknown version control");
|
2022-11-14 14:10:57 +01:00
|
|
|
#endif
|
2022-09-26 11:17:04 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2022-11-14 14:10:57 +01:00
|
|
|
#endif
|
2022-09-26 11:17:04 +02:00
|
|
|
|
2022-11-14 14:10:57 +01:00
|
|
|
R_API void rvc_close(Rvc *vc, bool save) {
|
|
|
|
r_return_if_fail (vc);
|
|
|
|
RvcPluginClose klose = R_UNWRAP3 (vc, p, close);
|
|
|
|
if (klose) {
|
|
|
|
klose (vc, save);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API bool rvc_branch(Rvc *vc, const char *branch_name) {
|
|
|
|
r_return_val_if_fail (vc && branch_name, false);
|
|
|
|
RvcPluginBranch branch = R_UNWRAP3 (vc, p, branch);
|
|
|
|
return branch? branch (vc, branch_name): false;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API RList *rvc_branches(Rvc *vc) {
|
|
|
|
r_return_val_if_fail (vc, NULL);
|
|
|
|
RvcPluginBranches branches = R_UNWRAP3 (vc, p, branches);
|
|
|
|
return branches? branches (vc): NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API bool rvc_checkout(Rvc *vc, const char *bname) {
|
|
|
|
r_return_val_if_fail (vc && bname, false);
|
|
|
|
RvcPluginCheckout co = R_UNWRAP3 (vc, p, checkout);
|
|
|
|
return co? co (vc, bname): false;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API bool rvc_save(Rvc *vc) {
|
|
|
|
r_return_val_if_fail (vc, NULL);
|
|
|
|
RvcPluginSave s = R_UNWRAP3 (vc, p, save);
|
|
|
|
return s? s (vc): false;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API bool rvc_commit(Rvc *vc, const char *message, const char *author, const RList *files) {
|
|
|
|
r_return_val_if_fail (vc, false);
|
|
|
|
RvcPluginCommit ci = R_UNWRAP3 (vc, p, commit);
|
|
|
|
return ci? ci (vc, message, author, files): false;
|
2022-09-26 11:17:04 +02:00
|
|
|
}
|