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 #include #include -#include + +#ifdef HAVE_GIT2 +#include +#include +#include +#endif + //END includes = #if 0 @@ -4522,7 +4528,7 @@ void KTextEditor::DocumentPrivate::slotDelayedHandleM= odOnHd() { // compare git hash with the one we have (if we have one) const QByteArray oldDigest =3D checksum(); - if (!oldDigest.isEmpty() && url().isLocalFile()) { + if (!oldDigest.isEmpty() && !url().isEmpty() && url().isLocalFile()) { /** * if current checksum =3D=3D checksum of new file =3D> unmodified */ @@ -4531,17 +4537,29 @@ void KTextEditor::DocumentPrivate::slotDelayedHandl= eModOnHd() m_modOnHdReason =3D 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() =3D=3D 0) { + /** + * try to discover the git repo of this file + * libgit2 docs state that UTF-8 is the right encoding, even o= n windows + * I hope that is correct! + */ + git_repository *repository =3D Q_NULLPTR; + if (git_repository_open_ext(&repository, url().toLocalFile().t= oUtf8().data(), 0, Q_NULLPTR) =3D=3D 0) { + /** + * if we have repo, convert the git hash to an OID + */ + git_oid oid; + if (git_oid_fromstr(&oid, oldDigest.toHex().data()) =3D=3D= 0) { + /** + * finally: is there a blob for this git hash? + */ + git_blob *blob =3D Q_NULLPTR; + if (git_blob_lookup(&blob, repository, &oid) =3D=3D 0)= { /** * this hash exists still in git =3D> just reload */ @@ -4549,9 +4567,13 @@ void KTextEditor::DocumentPrivate::slotDelayedHandle= ModOnHd() m_modOnHdReason =3D OnDiskUnmodified; documentReload(); } + git_blob_free(blob); } + } + git_repository_free(repository); } +#endif } = /**