Fix some problems with the rvc-refactor pr

* Surpress the output of git init
 rationale: rvc init does not output anything so why should git?
* Include r_main.h in ravc2.c
* Fix rvc open and init
* Fix the linter issues
* Remove the no_inline attribute from rvc_repo_type
This commit is contained in:
RHL120 2022-11-16 11:09:43 +01:00 committed by pancake
parent b2ff7de0f0
commit e8b41fa5d5
4 changed files with 30 additions and 50 deletions

View File

@ -4,6 +4,7 @@
#include <rvc.h>
#include <r_list.h>
#include <r_main.h>
static void usage(void) {
printf ("Usage: ravc2 [-qvh] [action] [args ...]\n");

View File

@ -32,14 +32,25 @@ R_API bool rvc_use(Rvc *vc, RvcType type) {
return true;
}
R_API int rvc_repo_type(const char *path) {
return -1;
R_API RvcType rvc_repo_type(const char *path) {
const char *paths[] = {".git", ".rvc"};
const RvcType types[] = {RVC_TYPE_GIT, RVC_TYPE_RVC};
size_t i = 0;
for (; i < sizeof (paths) / sizeof (char *)
&& i < sizeof (types) / sizeof (RvcType); i++) {
char *p = r_file_new (path, paths[i], NULL);
if (r_file_is_directory(p)) {
return types[i];
}
free (p);
}
return RVC_TYPE_INV;
}
R_API Rvc *rvc_open(const char *path, RvcType type) {
r_return_val_if_fail (path, NULL);
Rvc *rvc = NULL;
int repotype = (type == -1)? rvc_repo_type (path): type;
int repotype = (type == RVC_TYPE_ANY)? rvc_repo_type (path): type;
switch (repotype) {
case RVC_TYPE_GIT:
rvc = r_vc_plugin_git.open (path);
@ -89,7 +100,7 @@ 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);
klose (vc, save);
}
}

View File

@ -8,8 +8,7 @@ static Rvc *open_git(const char *path) {
char *git_path = r_file_new (path, ".git", NULL);
if (!git_path || !r_file_is_directory (git_path)) {
char *escpath = r_str_escape (path);
int ret = r_sys_cmdf ("git init \"%s\"", escpath);
free (escpath);
int ret = r_sys_cmdf ("git init \"%s\" > /dev/null", escpath);
if (ret != 0) {
R_LOG_WARN ("git init failed");
}

View File

@ -1023,55 +1023,24 @@ static Sdb *vcdb_open(const char *rp) {
}
static Rvc *open_rvc(const char *rp) {
int type = RVC_TYPE_RVC;
// XXX this is conceptually wrong
Rvc *repo = R_NEW (Rvc);
if (repo) {
repo->path = r_str_new (rp);
if (repo->path) {
repo->db = vcdb_open (rp) ;
switch (type) {
case RVC_TYPE_RVC:
sdb_free (repo->db);
free (repo);
return rvc_rvc_new (rp);
case RVC_TYPE_GIT:
if (rvc_use (repo, type)) {
if (rvc_repo_exists(rp)) {
Rvc *repo = R_NEW (Rvc);
if (repo) {
repo->db = vcdb_open (rp);
if (repo->db) {
repo->path = strdup(rp);
if (repo->path) {
return repo;
}
break;
case RVC_TYPE_ANY:
{
char *rvcdir = r_str_newf ("%s/.rvc/" DBNAME, rp);
// check if .git exists and then .rvc or the other way
if (r_file_exists (rvcdir)) {
free (rvcdir);
type = RVC_TYPE_RVC;
if (rvc_use (repo, type)) {
return repo;
}
}
free (rvcdir);
char *gitdir = r_str_newf ("%s/.git/config", rp);
if (r_file_exists (gitdir)) {
free (gitdir);
type = RVC_TYPE_GIT;
if (rvc_use (repo, type)) {
return repo;
}
}
free (gitdir);
}
break;
default:
// unknown vc type
break;
}
sdb_free (repo->db);
free (repo->path);
}
free (repo);
} else {
Rvc *repo = rvc_rvc_new(rp);
if (repo) {
return repo;
}
}
R_LOG_ERROR("Can't open rvc repo in: %s", rp);
return NULL;
}