summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-03-05 14:21:24 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2017-03-05 14:21:24 +0000
commit062798915d3af60beb1b9d30c10c750d089d6119 (patch)
treee036a232ec4fbccc7e60afbff63746ac1bc036af
parentUpdate lastcommit when performing a git tree update (diff)
downloadgentoobrowse-api-062798915d3af60beb1b9d30c10c750d089d6119.tar.bz2
gentoobrowse-api-062798915d3af60beb1b9d30c10c750d089d6119.tar.xz
gentoobrowse-api-062798915d3af60beb1b9d30c10c750d089d6119.zip
libgit2 library helper
-rw-r--r--gentoobrowse-api/service/maintenanceGitOperations.cpp10
-rw-r--r--gentoobrowse-api/service/utils/git.cpp10
-rw-r--r--gentoobrowse-api/service/utils/git.h6
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);