diff options
author | Aaron Seigo <aseigo@kde.org> | 2014-12-10 10:08:42 +0100 |
---|---|---|
committer | Aaron Seigo <aseigo@kde.org> | 2014-12-11 01:02:32 +0100 |
commit | 997637b3b466e1f1c95405a3d43a78d78d4ba259 (patch) | |
tree | 65f383e7001106e4bf1a8e9dcaca79859dba2fae | |
parent | 558ca7f17ae4f6df48b999e98c4004a49549cd79 (diff) | |
download | sink-997637b3b466e1f1c95405a3d43a78d78d4ba259.tar.gz sink-997637b3b466e1f1c95405a3d43a78d78d4ba259.zip |
commit hashes!
-rw-r--r-- | cmake/modules/FindLibgit2.cmake | 33 | ||||
-rw-r--r-- | tests/hawd/CMakeLists.txt | 12 | ||||
-rw-r--r-- | tests/hawd/dataset.cpp | 40 | ||||
-rw-r--r-- | tests/hawd/dataset.h | 5 | ||||
-rw-r--r-- | tests/hawd/state.cpp | 37 | ||||
-rw-r--r-- | tests/hawd/state.h | 4 | ||||
-rw-r--r-- | tests/storagebenchmark.cpp | 2 |
7 files changed, 118 insertions, 15 deletions
diff --git a/cmake/modules/FindLibgit2.cmake b/cmake/modules/FindLibgit2.cmake new file mode 100644 index 0000000..410eab0 --- /dev/null +++ b/cmake/modules/FindLibgit2.cmake | |||
@@ -0,0 +1,33 @@ | |||
1 | # - Try to find the libgit2 library | ||
2 | # Once done this will define | ||
3 | # | ||
4 | # LIBGIT2_FOUND - System has libgit2 | ||
5 | # LIBGIT2_INCLUDE_DIR - The libgit2 include directory | ||
6 | # LIBGIT2_LIBRARIES - The libraries needed to use libgit2 | ||
7 | # LIBGIT2_DEFINITIONS - Compiler switches required for using libgit2 | ||
8 | |||
9 | |||
10 | # use pkg-config to get the directories and then use these values | ||
11 | # in the FIND_PATH() and FIND_LIBRARY() calls | ||
12 | #FIND_PACKAGE(PkgConfig) | ||
13 | #PKG_SEARCH_MODULE(PC_LIBGIT2 libgit2) | ||
14 | |||
15 | SET(LIBGIT2_DEFINITIONS ${PC_LIBGIT2_CFLAGS_OTHER}) | ||
16 | |||
17 | FIND_PATH(LIBGIT2_INCLUDE_DIR NAMES git2.h | ||
18 | HINTS | ||
19 | ${PC_LIBGIT2_INCLUDEDIR} | ||
20 | ${PC_LIBGIT2_INCLUDE_DIRS} | ||
21 | ) | ||
22 | |||
23 | FIND_LIBRARY(LIBGIT2_LIBRARIES NAMES git2 | ||
24 | HINTS | ||
25 | ${PC_LIBGIT2_LIBDIR} | ||
26 | ${PC_LIBGIT2_LIBRARY_DIRS} | ||
27 | ) | ||
28 | |||
29 | |||
30 | INCLUDE(FindPackageHandleStandardArgs) | ||
31 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(libgit2 DEFAULT_MSG LIBGIT2_LIBRARIES LIBGIT2_INCLUDE_DIR) | ||
32 | |||
33 | MARK_AS_ADVANCED(LIBGIT2_INCLUDE_DIR LIBGIT2_LIBRARIES) | ||
diff --git a/tests/hawd/CMakeLists.txt b/tests/hawd/CMakeLists.txt index 413c86b..6400baf 100644 --- a/tests/hawd/CMakeLists.txt +++ b/tests/hawd/CMakeLists.txt | |||
@@ -1,6 +1,12 @@ | |||
1 | project(hawd) | 1 | project(hawd) |
2 | 2 | ||
3 | include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) | 3 | find_package(Libgit2) |
4 | |||
5 | if (LIBGIT2_FOUND) | ||
6 | add_definitions(-DHAVE_LIBGIT2) | ||
7 | endif (LIBGIT2_FOUND) | ||
8 | |||
9 | include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${LIBGIT2_INCLUDE_DIR}) | ||
4 | 10 | ||
5 | set(lib_SRCS | 11 | set(lib_SRCS |
6 | dataset.cpp | 12 | dataset.cpp |
@@ -18,11 +24,11 @@ set(SRCS | |||
18 | 24 | ||
19 | add_library(libhawd ${lib_SRCS}) | 25 | add_library(libhawd ${lib_SRCS}) |
20 | qt5_use_modules(libhawd Core) | 26 | qt5_use_modules(libhawd Core) |
21 | target_link_libraries(libhawd akonadi2common) | 27 | target_link_libraries(libhawd akonadi2common ${LIBGIT2_LIBRARIES}) |
22 | install(TARGETS libhawd DESTINATION lib) | 28 | install(TARGETS libhawd DESTINATION lib) |
23 | 29 | ||
24 | add_executable(${PROJECT_NAME} ${SRCS}) | 30 | add_executable(${PROJECT_NAME} ${SRCS}) |
25 | qt5_use_modules(${PROJECT_NAME} Core) | 31 | qt5_use_modules(${PROJECT_NAME} Core) |
26 | target_link_libraries(${PROJECT_NAME} libhawd) | 32 | target_link_libraries(${PROJECT_NAME} libhawd ${LIBGIT2_LIBRARIES}) |
27 | install(TARGETS ${PROJECT_NAME} DESTINATION bin) | 33 | install(TARGETS ${PROJECT_NAME} DESTINATION bin) |
28 | 34 | ||
diff --git a/tests/hawd/dataset.cpp b/tests/hawd/dataset.cpp index 6fc85ce..592612e 100644 --- a/tests/hawd/dataset.cpp +++ b/tests/hawd/dataset.cpp | |||
@@ -34,6 +34,8 @@ Dataset::Row::Row(const Row &other) | |||
34 | : m_key(other.m_key), | 34 | : m_key(other.m_key), |
35 | m_columns(other.m_columns), | 35 | m_columns(other.m_columns), |
36 | m_data(other.m_data), | 36 | m_data(other.m_data), |
37 | m_annotation(other.m_annotation), | ||
38 | m_commitHash(other.m_commitHash), | ||
37 | m_dataset(other.m_dataset) | 39 | m_dataset(other.m_dataset) |
38 | { | 40 | { |
39 | } | 41 | } |
@@ -57,6 +59,8 @@ Dataset::Row &Dataset::Row::operator=(const Row &rhs) | |||
57 | m_columns = rhs.m_columns; | 59 | m_columns = rhs.m_columns; |
58 | m_data = rhs.m_data; | 60 | m_data = rhs.m_data; |
59 | m_dataset = rhs.m_dataset; | 61 | m_dataset = rhs.m_dataset; |
62 | m_annotation = rhs.m_annotation; | ||
63 | m_commitHash = rhs.m_commitHash; | ||
60 | return *this; | 64 | return *this; |
61 | } | 65 | } |
62 | 66 | ||
@@ -74,6 +78,11 @@ void Dataset::Row::annotate(const QString ¬e) | |||
74 | m_annotation = note; | 78 | m_annotation = note; |
75 | } | 79 | } |
76 | 80 | ||
81 | void Dataset::Row::setCommitHash(const QString &hash) | ||
82 | { | ||
83 | m_commitHash = hash; | ||
84 | } | ||
85 | |||
77 | qint64 Dataset::Row::key() const | 86 | qint64 Dataset::Row::key() const |
78 | { | 87 | { |
79 | if (m_key < 1) { | 88 | if (m_key < 1) { |
@@ -90,11 +99,16 @@ void Dataset::Row::fromBinary(QByteArray &data) | |||
90 | QDataStream stream(&data, QIODevice::ReadOnly); | 99 | QDataStream stream(&data, QIODevice::ReadOnly); |
91 | 100 | ||
92 | while (!stream.atEnd()) { | 101 | while (!stream.atEnd()) { |
93 | stream >> key >> value; | 102 | stream >> key; |
103 | if (stream.atEnd()) { | ||
104 | break; | ||
105 | } | ||
106 | |||
107 | stream >> value; | ||
94 | if (key == s_annotationKey) { | 108 | if (key == s_annotationKey) { |
95 | m_annotation = value.toString(); | 109 | m_annotation = value.toString(); |
96 | } else if (key == s_hashKey) { | 110 | } else if (key == s_hashKey) { |
97 | m_hash = value.toString(); | 111 | m_commitHash = value.toString(); |
98 | } else { | 112 | } else { |
99 | setValue(key, value); | 113 | setValue(key, value); |
100 | } | 114 | } |
@@ -105,19 +119,23 @@ QByteArray Dataset::Row::toBinary() const | |||
105 | { | 119 | { |
106 | QByteArray data; | 120 | QByteArray data; |
107 | QDataStream stream(&data, QIODevice::WriteOnly); | 121 | QDataStream stream(&data, QIODevice::WriteOnly); |
122 | |||
108 | QHashIterator<QString, QVariant> it(m_data); | 123 | QHashIterator<QString, QVariant> it(m_data); |
109 | while (it.hasNext()) { | 124 | while (it.hasNext()) { |
110 | it.next(); | 125 | it.next(); |
111 | stream << it.key() << it.value(); | 126 | if (it.value().isValid()) { |
127 | stream << it.key() << it.value(); | ||
128 | } | ||
112 | } | 129 | } |
113 | 130 | ||
114 | if (!m_hash.isEmpty()) { | 131 | if (!m_commitHash.isEmpty()) { |
115 | stream << s_hashKey << m_hash; | 132 | stream << s_hashKey << QVariant(m_commitHash); |
116 | } | 133 | } |
117 | 134 | ||
118 | if (!m_annotation.isEmpty()) { | 135 | if (!m_annotation.isEmpty()) { |
119 | stream << s_annotationKey << m_annotation; | 136 | stream << s_annotationKey << QVariant(m_annotation); |
120 | } | 137 | } |
138 | |||
121 | return data; | 139 | return data; |
122 | } | 140 | } |
123 | 141 | ||
@@ -169,7 +187,7 @@ QString Dataset::Row::toString(const QStringList &cols, int standardCols, const | |||
169 | } | 187 | } |
170 | 188 | ||
171 | if (standardCols & CommitHash) { | 189 | if (standardCols & CommitHash) { |
172 | strings << m_hash; | 190 | strings << m_commitHash; |
173 | } | 191 | } |
174 | 192 | ||
175 | QHashIterator<QString, QVariant> it(m_data); | 193 | QHashIterator<QString, QVariant> it(m_data); |
@@ -189,9 +207,9 @@ QString Dataset::Row::toString(const QStringList &cols, int standardCols, const | |||
189 | 207 | ||
190 | Dataset::Dataset(const QString &name, const State &state) | 208 | Dataset::Dataset(const QString &name, const State &state) |
191 | : m_definition(state.datasetDefinition(name)), | 209 | : m_definition(state.datasetDefinition(name)), |
192 | m_storage(state.resultsPath(), name, Storage::ReadWrite) | 210 | m_storage(state.resultsPath(), name, Storage::ReadWrite), |
211 | m_commitHash(state.commitHash()) | ||
193 | { | 212 | { |
194 | //TODO: it should use a different file name if the data columns have changed | ||
195 | m_storage.startTransaction(); | 213 | m_storage.startTransaction(); |
196 | } | 214 | } |
197 | 215 | ||
@@ -252,7 +270,9 @@ void Dataset::eachRow(const std::function<void(const Row &row)> &resultHandler) | |||
252 | Dataset::Row Dataset::row(qint64 key) | 270 | Dataset::Row Dataset::row(qint64 key) |
253 | { | 271 | { |
254 | if (key < 1) { | 272 | if (key < 1) { |
255 | return Row(*this); | 273 | Row row(*this); |
274 | row.setCommitHash(m_commitHash); | ||
275 | return row; | ||
256 | } | 276 | } |
257 | 277 | ||
258 | Row row(*this, key); | 278 | Row row(*this, key); |
diff --git a/tests/hawd/dataset.h b/tests/hawd/dataset.h index f23d67c..b91bc24 100644 --- a/tests/hawd/dataset.h +++ b/tests/hawd/dataset.h | |||
@@ -47,6 +47,7 @@ public: | |||
47 | void setValue(const QString &column, const QVariant &value); | 47 | void setValue(const QString &column, const QVariant &value); |
48 | QVariant value(const QString &column); | 48 | QVariant value(const QString &column); |
49 | void annotate(const QString ¬e); | 49 | void annotate(const QString ¬e); |
50 | void setCommitHash(const QString &hash); | ||
50 | qint64 key() const; | 51 | qint64 key() const; |
51 | QByteArray toBinary() const; | 52 | QByteArray toBinary() const; |
52 | QString toString(const QStringList &cols = QStringList(), int standardCols = All, const QString &seperator = "\t") const; | 53 | QString toString(const QStringList &cols = QStringList(), int standardCols = All, const QString &seperator = "\t") const; |
@@ -60,12 +61,11 @@ public: | |||
60 | QHash<QString, DataDefinition> m_columns; | 61 | QHash<QString, DataDefinition> m_columns; |
61 | QHash<QString, QVariant> m_data; | 62 | QHash<QString, QVariant> m_data; |
62 | QString m_annotation; | 63 | QString m_annotation; |
63 | QString m_hash; | 64 | QString m_commitHash; |
64 | const Dataset *m_dataset; | 65 | const Dataset *m_dataset; |
65 | friend class Dataset; | 66 | friend class Dataset; |
66 | }; | 67 | }; |
67 | 68 | ||
68 | Dataset(const DatasetDefinition &definition); | ||
69 | Dataset(const QString &name, const State &state); | 69 | Dataset(const QString &name, const State &state); |
70 | ~Dataset(); | 70 | ~Dataset(); |
71 | 71 | ||
@@ -83,6 +83,7 @@ public: | |||
83 | private: | 83 | private: |
84 | DatasetDefinition m_definition; | 84 | DatasetDefinition m_definition; |
85 | Storage m_storage; | 85 | Storage m_storage; |
86 | QString m_commitHash; | ||
86 | }; | 87 | }; |
87 | 88 | ||
88 | } // namespace HAWD | 89 | } // namespace HAWD |
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 | |||
29 | static const QString configFileName("hawd.conf"); | 33 | static const QString configFileName("hawd.conf"); |
30 | 34 | ||
31 | namespace HAWD | 35 | namespace HAWD |
@@ -34,6 +38,7 @@ namespace HAWD | |||
34 | State::State(const QString &_configPath) | 38 | State::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 | ||
106 | const 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 | |||
115 | void 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 |
diff --git a/tests/hawd/state.h b/tests/hawd/state.h index 72ac528..fa76724 100644 --- a/tests/hawd/state.h +++ b/tests/hawd/state.h | |||
@@ -37,10 +37,14 @@ public: | |||
37 | QString resultsPath() const; | 37 | QString resultsPath() const; |
38 | QString projectPath() const; | 38 | QString projectPath() const; |
39 | DatasetDefinition datasetDefinition(const QString &name) const; | 39 | DatasetDefinition datasetDefinition(const QString &name) const; |
40 | const char *commitHash() const; | ||
40 | 41 | ||
41 | private: | 42 | private: |
43 | void findGitHash(); | ||
44 | |||
42 | bool m_valid; | 45 | bool m_valid; |
43 | QJsonObject m_configData; | 46 | QJsonObject m_configData; |
47 | char m_commitHash[10]; | ||
44 | }; | 48 | }; |
45 | 49 | ||
46 | } // namespace HAWD | 50 | } // namespace HAWD |
diff --git a/tests/storagebenchmark.cpp b/tests/storagebenchmark.cpp index ba14990..31cef06 100644 --- a/tests/storagebenchmark.cpp +++ b/tests/storagebenchmark.cpp | |||
@@ -66,6 +66,7 @@ private Q_SLOTS: | |||
66 | store.removeFromDisk(); | 66 | store.removeFromDisk(); |
67 | } | 67 | } |
68 | 68 | ||
69 | public: | ||
69 | void testWriteRead_data() | 70 | void testWriteRead_data() |
70 | { | 71 | { |
71 | QTest::addColumn<bool>("useDb"); | 72 | QTest::addColumn<bool>("useDb"); |
@@ -178,6 +179,7 @@ private Q_SLOTS: | |||
178 | } | 179 | } |
179 | } | 180 | } |
180 | 181 | ||
182 | private Q_SLOTS: | ||
181 | void testBufferCreation() | 183 | void testBufferCreation() |
182 | { | 184 | { |
183 | HAWD::Dataset dataset("buffer_creation", m_hawdState); | 185 | HAWD::Dataset dataset("buffer_creation", m_hawdState); |