OSDN Git Service

VCS base diff editor with merge conflicts
authorPeter Kuemmel <syntheticpp@gmx.net>
Sun, 30 Oct 2011 10:31:51 +0000 (11:31 +0100)
committerTobias Hunger <tobias.hunger@nokia.com>
Wed, 2 Nov 2011 09:12:51 +0000 (10:12 +0100)
'git diff' marks merge conflicts different to changes.
With this fix it is possible to jump to the merge conflicts
also by a double click.

Task-number: QTCREATORBUG-6424
Change-Id: I355274e1ded4a05b3c7db718cbe9f48453070f82
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Reviewed-by: Tobias Hunger <tobias.hunger@nokia.com>
src/plugins/vcsbase/vcsbaseeditor.cpp

index b4b636b..df38940 100644 (file)
@@ -707,19 +707,23 @@ void VCSBaseEditorWidget::slotActivateAnnotation()
     }
 }
 
-// Check for a change chunk "@@ -91,7 +95,7 @@" and return
-// the modified line number (95).
-// Note that git appends stuff after "  @@" (function names, etc.).
-static inline bool checkChunkLine(const QString &line, int *modifiedLineNumber)
-{
-    if (!line.startsWith(QLatin1String("@@ ")))
+// Check for a chunk of
+//       - changes          :  "@@ -91,7 +95,7 @@"
+//       - merged conflicts : "@@@ -91,7 +95,7 @@@"
+// and return the modified line number (here 95).
+// Note that git appends stuff after "  @@"/" @@@" (function names, etc.).
+static inline bool checkChunkLine(const QString &line, int *modifiedLineNumber, int numberOfAts)
+{
+    const QString ats(numberOfAts, QLatin1Char('@'));
+    if (!line.startsWith(ats + QLatin1Char(' ')))
         return false;
-    const int endPos = line.indexOf(QLatin1String(" @@"), 3);
+    const int len = ats.size() + 1;
+    const int endPos = line.indexOf(QLatin1Char(' ') + ats, len);
     if (endPos == -1)
         return false;
     // the first chunk range applies to the original file, the second one to
     // the modified file, the one we're interested int
-    const int plusPos = line.indexOf(QLatin1Char('+'), 3);
+    const int plusPos = line.indexOf(QLatin1Char('+'), len);
     if (plusPos == -1 || plusPos > endPos)
         return false;
     const int lineNumberPos = plusPos + 1;
@@ -732,6 +736,13 @@ static inline bool checkChunkLine(const QString &line, int *modifiedLineNumber)
     return ok;
 }
 
+static inline bool checkChunkLine(const QString &line, int *modifiedLineNumber)
+{
+    if (checkChunkLine(line, modifiedLineNumber, 2))
+        return true;
+    return checkChunkLine(line, modifiedLineNumber, 3);
+}
+
 void VCSBaseEditorWidget::jumpToChangeFromDiff(QTextCursor cursor)
 {
     int chunkStart = 0;