diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-03-05 14:21:24 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-03-05 14:21:24 +0000 |
commit | 5624a6a073835e5509d652ad020a28dc67d2360c (patch) | |
tree | e036a232ec4fbccc7e60afbff63746ac1bc036af | |
parent | Update lastcommit when performing a git tree update (diff) | |
download | gentoobrowse-api-5624a6a073835e5509d652ad020a28dc67d2360c.tar.bz2 gentoobrowse-api-5624a6a073835e5509d652ad020a28dc67d2360c.tar.xz gentoobrowse-api-5624a6a073835e5509d652ad020a28dc67d2360c.zip |
libgit2 library helper
-rw-r--r-- | gentoobrowse-api/service/maintenanceGitOperations.cpp | 10 | ||||
-rw-r--r-- | gentoobrowse-api/service/utils/git.cpp | 10 | ||||
-rw-r--r-- | gentoobrowse-api/service/utils/git.h | 6 |
3 files changed, 19 insertions, 7 deletions
diff --git a/gentoobrowse-api/service/maintenanceGitOperations.cpp b/gentoobrowse-api/service/maintenanceGitOperations.cpp index 583968c..e306741 100644 --- a/gentoobrowse-api/service/maintenanceGitOperations.cpp +++ b/gentoobrowse-api/service/maintenanceGitOperations.cpp @@ -5,7 +5,6 @@ #include <selectcommandUtil.impl.h> #include <utils/dbUtils.h> #include <git2.h> -#include <scopeExit.h> #include <sql/maintenance/changeLogRoots.sql.h> #include <sql/maintenance/changeLogInsert.sql.h> #include <sql/maintenance/changeLogRepoCommits.sql.h> @@ -45,8 +44,7 @@ namespace Gentoo { void Maintenance::refreshChangeLogs(const Ice::Current & c) { - git_libgit2_init(); - AdHoc::ScopeExit shutdownlibgit2(&git_libgit2_shutdown); + libgit2 git; auto dbc = db->get(); DB::TransactionScope tx(dbc.get()); @@ -125,8 +123,7 @@ namespace Gentoo { void Maintenance::updateRepositories(const Ice::Current &) { - git_libgit2_init(); - AdHoc::ScopeExit shutdownlibgit2(&git_libgit2_shutdown); + libgit2 git; auto dbc = db->get(); sql::maintenance::reposToUpdate.select(dbc.get())->forEachRow<std::string, std::string, std::string>(&updateRepository); @@ -185,8 +182,7 @@ namespace Gentoo { void Maintenance::refreshPackageTreeGit(const Ice::Current & c) { - git_libgit2_init(); - AdHoc::ScopeExit shutdownlibgit2(&git_libgit2_shutdown); + libgit2 git; auto properties = c.adapter->getCommunicator()->getProperties(); auto repoRoot = boost::filesystem::path(properties->getPropertyWithDefault("GentooBrowseAPI.RepoRoot", "/")); diff --git a/gentoobrowse-api/service/utils/git.cpp b/gentoobrowse-api/service/utils/git.cpp index 095c9c2..7e1ce71 100644 --- a/gentoobrowse-api/service/utils/git.cpp +++ b/gentoobrowse-api/service/utils/git.cpp @@ -15,6 +15,16 @@ namespace Gentoo { throw ::Gentoo::GitError(*fn, err, e->klass, e->message); } + libgit2::libgit2() + { + git_libgit2_init(); + } + + libgit2::~libgit2() + { + git_libgit2_shutdown(); + } + int show(const git_transfer_progress * p, void *) { fprintf(stderr, "%u / %u\n", p->total_objects, p->received_objects); diff --git a/gentoobrowse-api/service/utils/git.h b/gentoobrowse-api/service/utils/git.h index 8e70074..7df0172 100644 --- a/gentoobrowse-api/service/utils/git.h +++ b/gentoobrowse-api/service/utils/git.h @@ -33,6 +33,12 @@ namespace Gentoo { return r; } + class libgit2 { + public: + libgit2(); + ~libgit2(); + }; + std::unique_ptr<git_annotated_commit, void (*)(git_annotated_commit*)> gitFetch(git_repository * repo, git_remote * remote, const char * branch); |