# # # add_file "guitone/src/util/DiffParser.cpp" # content [58f392cedbb7c449253eba29f00e1063480efb6d] # # add_file "guitone/src/util/DiffParser.h" # content [2365a3bdb7d636f351b969ff3e329bf8d215d318] # # patch "guitone/src/view/dialogs/ui_KeyManagment.h" # from [e532d9092f7dc09f389efb32ab2ad17e3b70e043] # to [d6f00236ec0c05503a1403bf8be82622e533f45e] # # patch "guitone/src/view/dialogs/ui_ancestry_graph.h" # from [aa2daf443204b3430afbe09b49664d7118235e79] # to [9dc2f818470796e4618942acf9d2482914ffeb7b] # # patch "guitone/src/view/dialogs/ui_preferences.h" # from [2c312b3e0473774c88af1bbe2609e1949beacaf1] # to [802866cb6c8b358fd888c210859221a9aa81c937] # # patch "guitone/src/view/dialogs/ui_switch_workspace.h" # from [a518050872fd99c4d0231c1eefa3312ef13011d5] # to [484762972dc0ae7892ea5b3f69c07b4846c3ce0c] # ============================================================ --- guitone/src/util/DiffParser.cpp 58f392cedbb7c449253eba29f00e1063480efb6d +++ guitone/src/util/DiffParser.cpp 58f392cedbb7c449253eba29f00e1063480efb6d @@ -0,0 +1,114 @@ +/*************************************************************************** +* Copyright (C) 2006 by Thomas Keller * +* address@hidden * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ + +#include "DiffParser.h" + +DiffParser::DiffParser(const QString & input) +{ + parse(input); +} + +DiffParser::~DiffParser() {} + +void DiffParser::parse(const QString & input) +{ + if (input.length() == 0) return; + + QStringList lines = input.split(QRegExp("/[\n\r]+/")); + + QString curFile; + + Diff * curDiff; + DiffHunk * curHunk; + int leftStart = 0, leftLines = 0, rightStart = 0, rightLines = 0; + + for (int i=0, s=lines.size(); i 0); + QChar firstChar = line.at(0); + + if (firstChar == '=') + { + QString nextLine(lines.at(++i)); + + // check if this is a binary + QRegExp rx = QRegExp("/^#\s(.+)\sis binary/"); + if (rx.indexIn(nextLine) != -1) + { + curDiff->is_binary = true; + fileDiffs->insert(regex.cap(1), &curDiff); + continue; + } + + // then this should be a normal file diff + QRegExp rx = QRegExp("/^---\s(.+)\s+\w{40}/"); + Q_ASSERT(rx.indexIn(nextLine) > -1); + curFile = rx.at(1); + + // create a new diff + curDiff = new Diff(); + + // skip the next line as we don't care about the content id's here + i++; + continue; + } + + if (firstChar == '@') + { + QRegExp rx = QRegExp("/^@@\s+\-(\d+)(,?)(\d*)\s+\+(\d+)(,?)(\d*)\s+@@/"); + Q_ASSERT(rx.indexIn(nextLine) > -1); + QStringList list = rx.capturedTexts(); + Q_ASSERT(list.size() >= 2); + + // extract line numbers and positions + leftStart = list.at(1).toInt(); + if (list.at(2) == ",") + leftLines = list.at(3).toInt(); + else + leftLines = 1; + rightStart = list.at(4).toInt(); + if (list.at(5) == ",") + rightLines = list.at(6).toInt(); + else + rightLines = 1; + + // create a new Hunk + curHunk = new DiffHunk(); + curDiff->hunks.push_back(curHunk); + + // now skip all unchanged lines up to the first change + minStart = leftStart > rightStart ? rightStart : leftStart; + i += minStart; + + continue; + } + + // TODO: parse single lines + // TODO: what if more than a single add/remove/add-remove comes up? + } +} + +Diff DiffParser::getDiff(const QString & filename) const +{ + Q_ASSERT(fileDiffs.contains(filename)); + return fileDiffs.value(filename); +} + ============================================================ --- guitone/src/util/DiffParser.h 2365a3bdb7d636f351b969ff3e329bf8d215d318 +++ guitone/src/util/DiffParser.h 2365a3bdb7d636f351b969ff3e329bf8d215d318 @@ -0,0 +1,50 @@ +/*************************************************************************** +* Copyright (C) 2006 by Thomas Keller * +* address@hidden * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ + +#ifndef DIFF_PARSER_H +#define DIFF_PARSER_H + +#include + +typedef struct { + int lineno; + int linecount; + enum state{ADDED, REMOVED}; + QString content; +} DiffHunk; + +typedef struct { + QVector hunks; + bool is_binary; +} Diff; + +class DiffParser : public QObject +{ + Q_OBJECT +public: + DiffParser(const QString &); + ~DiffParser(); + Diff getDiff(const QString &) const; +private: + void parse(const QString &); + QMap fileDiffs; +}; + +#endif ============================================================ --- guitone/src/view/dialogs/ui_KeyManagment.h e532d9092f7dc09f389efb32ab2ad17e3b70e043 +++ guitone/src/view/dialogs/ui_KeyManagment.h d6f00236ec0c05503a1403bf8be82622e533f45e @@ -1,8 +1,8 @@ /******************************************************************************** ** Form generated from reading ui file 'KeyManagment.ui' ** -** Created: Sun Nov 5 00:18:53 2006 -** by: Qt User Interface Compiler version 4.2.1 +** Created: Wed Nov 15 16:21:37 2006 +** by: Qt User Interface Compiler version 4.2.0 ** ** WARNING! All changes made in this file will be lost when recompiling ui file! ********************************************************************************/ ============================================================ --- guitone/src/view/dialogs/ui_ancestry_graph.h aa2daf443204b3430afbe09b49664d7118235e79 +++ guitone/src/view/dialogs/ui_ancestry_graph.h 9dc2f818470796e4618942acf9d2482914ffeb7b @@ -1,8 +1,8 @@ /******************************************************************************** ** Form generated from reading ui file 'ancestry_graph.ui' ** -** Created: Sun Nov 5 00:18:53 2006 -** by: Qt User Interface Compiler version 4.2.1 +** Created: Wed Nov 15 16:21:37 2006 +** by: Qt User Interface Compiler version 4.2.0 ** ** WARNING! All changes made in this file will be lost when recompiling ui file! ********************************************************************************/ ============================================================ --- guitone/src/view/dialogs/ui_preferences.h 2c312b3e0473774c88af1bbe2609e1949beacaf1 +++ guitone/src/view/dialogs/ui_preferences.h 802866cb6c8b358fd888c210859221a9aa81c937 @@ -1,8 +1,8 @@ /******************************************************************************** ** Form generated from reading ui file 'preferences.ui' ** -** Created: Sun Nov 5 00:18:53 2006 -** by: Qt User Interface Compiler version 4.2.1 +** Created: Wed Nov 15 16:21:37 2006 +** by: Qt User Interface Compiler version 4.2.0 ** ** WARNING! All changes made in this file will be lost when recompiling ui file! ********************************************************************************/ ============================================================ --- guitone/src/view/dialogs/ui_switch_workspace.h a518050872fd99c4d0231c1eefa3312ef13011d5 +++ guitone/src/view/dialogs/ui_switch_workspace.h 484762972dc0ae7892ea5b3f69c07b4846c3ce0c @@ -1,8 +1,8 @@ /******************************************************************************** ** Form generated from reading ui file 'switch_workspace.ui' ** -** Created: Sun Nov 5 00:18:53 2006 -** by: Qt User Interface Compiler version 4.2.1 +** Created: Wed Nov 15 16:21:37 2006 +** by: Qt User Interface Compiler version 4.2.0 ** ** WARNING! All changes made in this file will be lost when recompiling ui file! ********************************************************************************/