summaryrefslogtreecommitdiffstats
path: root/tests/hawd/state.cpp
diff options
context:
space:
mode:
authorAaron Seigo <aseigo@kde.org>2014-12-10 10:08:42 +0100
committerAaron Seigo <aseigo@kde.org>2014-12-11 01:02:32 +0100
commit997637b3b466e1f1c95405a3d43a78d78d4ba259 (patch)
tree65f383e7001106e4bf1a8e9dcaca79859dba2fae /tests/hawd/state.cpp
parent558ca7f17ae4f6df48b999e98c4004a49549cd79 (diff)
downloadsink-997637b3b466e1f1c95405a3d43a78d78d4ba259.tar.gz
sink-997637b3b466e1f1c95405a3d43a78d78d4ba259.zip
commit hashes!
Diffstat (limited to 'tests/hawd/state.cpp')
-rw-r--r--tests/hawd/state.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/hawd/state.cpp b/tests/hawd/state.cpp
index 3ee7775..4ea741d 100644
--- a/tests/hawd/state.cpp
+++ b/tests/hawd/state.cpp
@@ -26,6 +26,10 @@
26 26
27#include <iostream> 27#include <iostream>
28 28
29#ifdef HAVE_LIBGIT2
30#include <git2.h>
31#endif
32
29static const QString configFileName("hawd.conf"); 33static const QString configFileName("hawd.conf");
30 34
31namespace HAWD 35namespace HAWD
@@ -34,6 +38,7 @@ namespace HAWD
34State::State(const QString &_configPath) 38State::State(const QString &_configPath)
35 : m_valid(true) 39 : m_valid(true)
36{ 40{
41 m_commitHash[0] = '\0';
37 QString configPath = _configPath; 42 QString configPath = _configPath;
38 if (configPath.isEmpty()) { 43 if (configPath.isEmpty()) {
39 QDir dir; 44 QDir dir;
@@ -98,4 +103,36 @@ QVariant State::configValue(const QString &key) const
98 return m_configData.value(key).toVariant(); 103 return m_configData.value(key).toVariant();
99} 104}
100 105
106const char *State::commitHash() const
107{
108 if (isValid() && m_commitHash[0] == '\0') {
109 const_cast<State *>(this)->findGitHash();
110 }
111
112 return m_commitHash;
113}
114
115void State::findGitHash()
116{
117#ifdef HAVE_LIBGIT2
118 git_buf root = {0};
119 int error = git_repository_discover(&root, projectPath().toStdString().data(), 0, NULL);
120 if (!error) {
121 git_repository *repo = NULL;
122 int error = git_repository_open(&repo, root.ptr);
123
124 if (!error) {
125 git_oid oid;
126 error = git_reference_name_to_id(&oid, repo, "HEAD" );
127 if (!error) {
128 git_oid_tostr(m_commitHash, sizeof(m_commitHash), &oid);
129 }
130 }
131
132 git_repository_free(repo);
133 }
134 git_buf_free(&root);
135#endif
136}
137
101} // namespace HAWD 138} // namespace HAWD