diff --git a/libr/main/ravc2.c b/libr/main/ravc2.c index 4d13d1c28a..6a84c3e26c 100644 --- a/libr/main/ravc2.c +++ b/libr/main/ravc2.c @@ -4,6 +4,7 @@ #include #include +#include static void usage(void) { printf ("Usage: ravc2 [-qvh] [action] [args ...]\n"); diff --git a/libr/util/rvc.c b/libr/util/rvc.c index febcf8fb01..1b30486f29 100644 --- a/libr/util/rvc.c +++ b/libr/util/rvc.c @@ -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); } } diff --git a/libr/util/rvc_git.c b/libr/util/rvc_git.c index bd727135cb..df1e1aae5a 100644 --- a/libr/util/rvc_git.c +++ b/libr/util/rvc_git.c @@ -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"); } diff --git a/libr/util/rvc_rvc.c b/libr/util/rvc_rvc.c index 15816fa750..0ad46af526 100644 --- a/libr/util/rvc_rvc.c +++ b/libr/util/rvc_rvc.c @@ -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; }