[X2Go-Commits] [x2goclient] 01/03: x2goutils.{cpp, h}: implement new git_changelog_extract_commit_sha helper, extracting the most recent commit shasum from a git changelog string.

git-admin at x2go.org git-admin at x2go.org
Thu Apr 23 04:12:30 CEST 2015


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository x2goclient.

commit 95f1ee1e2299aa61f02dda591452fb2c3b1c96f3
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Thu Apr 23 04:07:55 2015 +0200

    x2goutils.{cpp,h}: implement new git_changelog_extract_commit_sha helper, extracting the most recent commit shasum from a git changelog string.
---
 debian/changelog  |    3 +++
 src/x2goutils.cpp |   40 ++++++++++++++++++++++++++++++++++++++++
 src/x2goutils.h   |    1 +
 3 files changed, 44 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index 79c83c6..7aaf7f8 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -290,6 +290,9 @@ x2goclient (4.0.4.0-0x2go1) UNRELEASED; urgency=low
       maximum length of parameters + 4 (for the trailing 4 spaces).
       Calculations via terminal_cols and remaining do not work, if
       terminal_cols is unknown.
+    - x2goutils.{cpp,h}: implement new git_changelog_extract_commit_sha
+      helper, extracting the most recent commit shasum from a git changelog
+      string.
 
   [ Fernando Pedemonte ]
   * New upstream release (4.0.4.0):
diff --git a/src/x2goutils.cpp b/src/x2goutils.cpp
index 7f6eb5b..f07578e 100644
--- a/src/x2goutils.cpp
+++ b/src/x2goutils.cpp
@@ -23,6 +23,8 @@
 #include <QMessageBox>
 
 #include "x2goutils.h"
+#include "onmainwindow.h"
+#include "x2gologdebug.h"
 
 QString expandHome( QString path )
 {
@@ -101,3 +103,41 @@ void show_RichText_WarningMsgBox (const QString& main_text, const QString& infor
   msg_box.setWindowModality (Qt::WindowModal);
   msg_box.exec ();
 }
+
+QString git_changelog_extract_commit_sha (const QString &gitlog) {
+  QString ret = "";
+
+  /*
+   * Do a poor man's split.
+   * We know that a newline character should be somewhere at the beginning of the string.
+   * We don't need to have Qt split the string up completely as we only care about
+   * a substring: from start to the first newline character.
+   */
+  std::ptrdiff_t pos = gitlog.indexOf ("\n");
+
+  if (0 < pos) {
+    ret = gitlog.left (pos + 1);
+
+    x2goDebug << "First line of git changelog: " << ret;
+
+    pos = ret.lastIndexOf (")");
+
+    if (0 < pos) {
+      std::ptrdiff_t pos_paren_start = ret.lastIndexOf ("(");
+
+      if ((0 < pos_paren_start) && (pos_paren_start < pos)) {
+        ret = ret.mid (pos_paren_start + 1, pos - pos_paren_start - 1);
+      }
+      else {
+        // Either starting parenthesis not found or starting parenthesis comes first.
+        ret = "";
+      }
+    }
+    else {
+      // End parenthesis not found.
+      ret = "";
+    }
+  }
+
+  return (ret);
+}
diff --git a/src/x2goutils.h b/src/x2goutils.h
index cf95b58..6b6f5d0 100644
--- a/src/x2goutils.h
+++ b/src/x2goutils.h
@@ -28,5 +28,6 @@ QString fixup_resource_URIs (const QString& res_path);
 QString wrap_legacy_resource_URIs (const QString& res_path);
 QString convert_to_rich_text (const QString &text, bool force = false);
 void show_RichText_WarningMsgBox (const QString& main_text, const QString& informative_text = "");
+QString git_changelog_extract_commit_sha (const QString &gitlog);
 
 #endif /* !defined (X2GOUTILS_H) */

--
Alioth's /srv/git/code.x2go.org/x2goclient.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2goclient.git


More information about the x2go-commits mailing list