[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [ktexteditor] /: use libgit2 instead of qprocess hack
From: Christoph Cullmann <cullmann () kde ! org>
Date: 2014-09-12 9:10:03
Message-ID: E1XSMrj-0000Yd-9B () scm ! kde ! org
[Download RAW message or body]
Git commit 48a26b065491a0d1d56cba32954d01516c904859 by Christoph Cullmann.
Committed on 12/09/2014 at 09:09.
Pushed by cullmann into branch 'master'.
use libgit2 instead of qprocess hack
M +1 -0 CMakeLists.txt
M +1 -0 src/CMakeLists.txt
M +30 -8 src/document/katedocument.cpp
http://commits.kde.org/ktexteditor/48a26b065491a0d1d56cba32954d01516c904859
diff --git a/CMakeLists.txt b/CMakeLists.txt
index aeeddb6..5397a48 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,6 +46,7 @@ find_package(KF5Sonnet ${KF5_DEP_VERSION} REQUIRED)
find_package(GIT2)
if(GIT2_FOUND)
add_definitions(-DHAVE_GIT2)
+ set (KTEXTEDITOR_OPTIONAL_LIBS ${KTEXTEDITOR_OPTIONAL_LIBS} GIT2::GIT2)
endif()
# vi mode on per default
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f2d0151..0893fff 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -278,6 +278,7 @@ PRIVATE
KF5::IconThemes
KF5::ItemViews
KF5::SonnetCore
+ ${KTEXTEDITOR_OPTIONAL_LIBS}
)
set_target_properties(KF5TextEditor
diff --git a/src/document/katedocument.cpp b/src/document/katedocument.cpp
index 57ce088..bf28943 100644
--- a/src/document/katedocument.cpp
+++ b/src/document/katedocument.cpp
@@ -77,7 +77,13 @@
#include <QFileDialog>
#include <QMimeDatabase>
#include <QTemporaryFile>
-#include <QProcess>
+
+#ifdef HAVE_GIT2
+#include <git2.h>
+#include <git2/oid.h>
+#include <git2/repository.h>
+#endif
+
//END includes
#if 0
@@ -4522,7 +4528,7 @@ void KTextEditor::DocumentPrivate::slotDelayedHandleModOnHd()
{
// compare git hash with the one we have (if we have one)
const QByteArray oldDigest = checksum();
- if (!oldDigest.isEmpty() && url().isLocalFile()) {
+ if (!oldDigest.isEmpty() && !url().isEmpty() && url().isLocalFile()) {
/**
* if current checksum == checksum of new file => unmodified
*/
@@ -4531,17 +4537,29 @@ void KTextEditor::DocumentPrivate::slotDelayedHandleModOnHd()
m_modOnHdReason = OnDiskUnmodified;
}
+#ifdef HAVE_GIT2
/**
* if still modified, try to take a look at git
* skip that, if document is modified!
*/
if (m_modOnHd && !isModified()) {
- QProcess git;
- git.start(QLatin1String("git"), QStringList() << \
QLatin1String("cat-file") << QLatin1String("-e") << \
QLatin1String(oldDigest.toHex()));
- if (git.waitForStarted()) {
- git.closeWriteChannel();
- if (git.waitForFinished()) {
- if (git.exitCode() == 0) {
+ /**
+ * try to discover the git repo of this file
+ * libgit2 docs state that UTF-8 is the right encoding, even on windows
+ * I hope that is correct!
+ */
+ git_repository *repository = Q_NULLPTR;
+ if (git_repository_open_ext(&repository, \
url().toLocalFile().toUtf8().data(), 0, Q_NULLPTR) == 0) { + /**
+ * if we have repo, convert the git hash to an OID
+ */
+ git_oid oid;
+ if (git_oid_fromstr(&oid, oldDigest.toHex().data()) == 0) {
+ /**
+ * finally: is there a blob for this git hash?
+ */
+ git_blob *blob = Q_NULLPTR;
+ if (git_blob_lookup(&blob, repository, &oid) == 0) {
/**
* this hash exists still in git => just reload
*/
@@ -4549,9 +4567,13 @@ void KTextEditor::DocumentPrivate::slotDelayedHandleModOnHd()
m_modOnHdReason = OnDiskUnmodified;
documentReload();
}
+ git_blob_free(blob);
}
+
}
+ git_repository_free(repository);
}
+#endif
}
/**
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic