# # # add_file "src/util/BasicIOWriter.cpp" # content [fe9b0a54b7bcd5ce91d9914f3efbf3cac736684e] # # add_file "src/util/BasicIOWriter.h" # content [052ca233a44fa5c872b699b5eee4fd4cc6187f1b] # # patch "guitone.pro" # from [f0157effd2dd01ba25b9eb05f7eb2637b511d530] # to [aca01447662a0cd5ace5f48f12d15759f1f6cb17] # # patch "res/forms/main_window.ui" # from [6c5b7e9f7df0fc48722a97cf9e48cbc51ea46e2d] # to [9f9f41d6a2d521f10475aabdd7e2901b29243dd1] # # patch "src/model/GetRevision.cpp" # from [cbb4647d0b6e8b29fd1943ea473af6a984ff03ce] # to [a46e3d6feab6b6c18cce772e8c69775ef3a7164f] # # patch "src/model/GetRevision.h" # from [0308fe66ff1749162131c693e28efe7497579d55] # to [9c2675f10e96cf957979a04a2df71ae989d1d6c6] # # patch "src/model/Inventory.cpp" # from [11326d99834f514d3a2619061715d37d89d9ffbd] # to [268c873ff30bfe89ed35f7f830b1c444cc042978] # # patch "src/model/Keys.cpp" # from [d8a57d13743b4f443bc249db66d09d67da2ded67] # to [76904a3e2d2ccb37d51c3f9b10628e63553af964] # # patch "src/model/Manifest.cpp" # from [d2f9630459f1cd73b5de8c64efb704a923e4552b] # to [fb48177633ab4c1dae360a98b8d2f7b7bfe4558e] # # patch "src/model/Tags.cpp" # from [8ddf2a8f16672cf70c49dbefdbdd33cd23ae38e6] # to [de325a5a9ad62e565e3faf21572b89c0fc1abdd8] # # patch "src/monotone/WorkspaceCommitter.cpp" # from [24c20dd54d53c980f930dc569ffd8ef77838f12d] # to [3d4219a869dd03b66d987860b578ad62d46fd2ce] # # patch "src/monotone/WorkspaceCommitter.h" # from [df5912a27f8f00ff7c954bb50dfe354125a855fc] # to [360938d22820d95f116691a962b6cb92ce9bc771] # # patch "src/util/AbstractParser.h" # from [af473981a098c6223e3d11183e1470ce86d8befe] # to [5d83ade859fbf057e5326f2bdcf8b0f6560a5be2] # # patch "src/util/BasicIOParser.cpp" # from [b0c5cce7021156332b90b152bca8a07e4ae1a0d5] # to [180cfde05b833ae0e9a0735f22dc7d4c37634098] # # patch "src/util/BasicIOParser.h" # from [2abdc40c948b2678ceeebf976e5424076036a83d] # to [b96df0f29dd64ac740c6e8a7f34c080406d3837e] # # patch "src/util/StdioParser.h" # from [8488d8ccabd54eef76d773c0ccaf91ac47d95d3d] # to [ed0742f484843b709c946a2c030cca934432335d] # # patch "src/view/MainWindow.cpp" # from [2df1db606ed6d15edf3587a46c721bacd2917328] # to [db2c472be2967d42277ce729d593f74ea0f1b811] # # patch "src/view/MainWindow.h" # from [7ea22986b3ba2005db4b604c592a91365ba78122] # to [38296ee6b6bbd5e84836949b27167abccb20bb6a] # # patch "src/vocab.h" # from [514f8d7e143232a98175232e2133efe326200cc5] # to [41e69475de03ca8f2099076d05ddfa8760b7bb60] # ============================================================ --- src/util/BasicIOWriter.cpp fe9b0a54b7bcd5ce91d9914f3efbf3cac736684e +++ src/util/BasicIOWriter.cpp fe9b0a54b7bcd5ce91d9914f3efbf3cac736684e @@ -0,0 +1,80 @@ +/*************************************************************************** +* 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 "BasicIOWriter.h" + +BasicIOWriter::BasicIOWriter(const StanzaList & st) : stanzas(st) {} + +BasicIOWriter::~BasicIOWriter() {} + +QString BasicIOWriter::write() +{ + QString out; + foreach (Stanza st, stanzas) + { + out.append(writeStanza(st)); + } + return out; +} + +QString BasicIOWriter::writeStanza(const Stanza & stanza) +{ + QString out; + foreach (StanzaEntry en, stanza) + { + // ensure that not both, a hash and a value list, are given + Q_ASSERT(!(en.hash.isNull() && en.vals.size() > 0)); + + if (!en.hash.isNull()) + { + out.append(writeHashLine(en)); + } + else + { + out.append(writeValueLine(en)); + } + } + out.append("\n"); + return out; +} + +QString BasicIOWriter::writeHashLine(const StanzaEntry & entry) +{ + return QString("%1 [%2]\n").arg(entry.sym).arg(entry.hash); +} + +QString BasicIOWriter::writeValueLine(const StanzaEntry & entry) +{ + QString vals; + foreach (QString val, entry.vals) + { + vals.append(QString(" \"%1\"").arg(escape(val))); + } + return QString("%1%2").arg(entry.sym).arg(vals); +} + +QString BasicIOWriter::escape(const QString & in) +{ + QString out(in); + out.replace("\\", "\\\\"); + out.replace("\"", "\\\""); + return out; +} + ============================================================ --- src/util/BasicIOWriter.h 052ca233a44fa5c872b699b5eee4fd4cc6187f1b +++ src/util/BasicIOWriter.h 052ca233a44fa5c872b699b5eee4fd4cc6187f1b @@ -0,0 +1,45 @@ +/*************************************************************************** +* Copyright (C) 2007 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 BASICIO_WRITER_H +#define BASICIO_WRITER_H + +#include "vocab.h" + +class BasicIOWriter +{ +public: + BasicIOWriter(const StanzaList &); + ~BasicIOWriter(); + + QString write(); + + +private: + QString writeStanza(const Stanza &); + QString writeHashLine(const StanzaEntry &); + QString writeValueLine(const StanzaEntry &); + QString escape(const QString &); + + StanzaList stanzas; +}; + +#endif + ============================================================ --- guitone.pro f0157effd2dd01ba25b9eb05f7eb2637b511d530 +++ guitone.pro aca01447662a0cd5ace5f48f12d15759f1f6cb17 @@ -63,6 +63,7 @@ HEADERS += src/view/MainWindow.h \ src/util/IconProvider.h \ src/util/AbstractParser.h \ src/util/BasicIOParser.h \ + src/util/BasicIOWriter.h \ src/util/Settings.h \ src/util/DiffParser.h \ src/util/SignalWaiter.h \ @@ -120,6 +121,7 @@ SOURCES += src/view/MainWindow.cpp \ src/util/IconProvider.cpp \ src/util/AbstractParser.cpp \ src/util/BasicIOParser.cpp \ + src/util/BasicIOWriter.cpp \ src/util/Settings.cpp \ src/util/DiffParser.cpp \ src/util/SignalWaiter.cpp \ ============================================================ --- res/forms/main_window.ui 6c5b7e9f7df0fc48722a97cf9e48cbc51ea46e2d +++ res/forms/main_window.ui 9f9f41d6a2d521f10475aabdd7e2901b29243dd1 @@ -100,7 +100,7 @@ 0 0 713 - 22 + 24 @@ -143,21 +143,6 @@ - - - Database - - - - - - - - Workspace - - - - File @@ -187,6 +172,22 @@ + + + Database + + + + + + + + Workspace + + + + + @@ -450,6 +451,14 @@ Check for updates + + + Reload workspace + + + Ctrl+R + + ============================================================ --- src/model/GetRevision.cpp cbb4647d0b6e8b29fd1943ea473af6a984ff03ce +++ src/model/GetRevision.cpp a46e3d6feab6b6c18cce772e8c69775ef3a7164f @@ -85,15 +85,15 @@ void GetRevision::parseOutput() if (j == 0 && entry.sym == "new_manifest") { - Q_ASSERT(entry.vals.size() == 1); - revision.new_manifest = entry.vals.at(0); + Q_ASSERT(!entry.hash.isNull()); + revision.new_manifest = entry.hash; break; } if (entry.sym == "old_revision") { - Q_ASSERT(entry.vals.size() == 1); - currentRevision = entry.vals.at(0); + Q_ASSERT(!entry.hash.isNull()); + currentRevision = entry.hash; QList changelist; revision.changesAgainstParent.insert(currentRevision, changelist); break; ============================================================ --- src/model/GetRevision.h 0308fe66ff1749162131c693e28efe7497579d55 +++ src/model/GetRevision.h 9c2675f10e96cf957979a04a2df71ae989d1d6c6 @@ -63,50 +63,6 @@ struct Change { return Qt::transparent; } - inline QString escape(const QString & in) - { - QString out(in); - out.replace("\\", "\\\\"); - out.replace("\"", "\\\""); - return out; - } - - inline QString getStanzaData() - { - switch (type) - { - case AddDir: - return QString("add_dir \"%1\"") - .arg(escape(stanza.at(0).vals.at(0))); - case AddFile: - return QString("add_file \"%1\"\ncontent [%2]") - .arg(escape(stanza.at(0).vals.at(0))) - .arg(stanza.at(1).vals.at(0)); - case Delete: - return QString("delete \"%1\"") - .arg(escape(stanza.at(0).vals.at(0))); - case Patch: - return QString("patch \"%1\"\nfrom [%2]\nto [%3]") - .arg(escape(stanza.at(0).vals.at(0))) - .arg(stanza.at(1).vals.at(0)) - .arg(stanza.at(2).vals.at(0)); - case Rename: - return QString("rename \"%1\"\nto \"%2\"") - .arg(escape(stanza.at(0).vals.at(0))) - .arg(escape(stanza.at(1).vals.at(0))); - case AttrClear: - return QString("clear \"%1\"\nattr \"%2\"") - .arg(escape(stanza.at(0).vals.at(0))) - .arg(escape(stanza.at(1).vals.at(0))); - case AttrSet: - return QString("set \"%1\"\nattr \"%2\"\nvalue \"%3\"") - .arg(stanza.at(0).vals.at(0)) - .arg(stanza.at(1).vals.at(0)) - .arg(stanza.at(2).vals.at(0)); - } - return QString(); - } - inline QString getDisplayData() { switch (type) ============================================================ --- src/model/Inventory.cpp 11326d99834f514d3a2619061715d37d89d9ffbd +++ src/model/Inventory.cpp 268c873ff30bfe89ed35f7f830b1c444cc042978 @@ -57,8 +57,8 @@ void Inventory::parseOutput() QMap renameMap; QMap::iterator renameIter; - InventoryItem *item; - QList tempItems; + InventoryItem * item; + QList tempItems; int status(0); int from_id(0); int to_id(0); @@ -109,6 +109,8 @@ void Inventory::parseOutput() branch->setLabel(MonotoneDelegate::getBranchName(this)); branch->setChildren(buildTreeRecursive(tempItems, NULL)); + // remove any older item + rootItem->deleteAllChildren(); rootItem->appendChild(branch); // reset the model to repaint the view completly ============================================================ --- src/model/Keys.cpp d8a57d13743b4f443bc249db66d09d67da2ded67 +++ src/model/Keys.cpp 76904a3e2d2ccb37d51c3f9b10628e63553af964 @@ -77,15 +77,15 @@ void Keys::parseOutput() if (entry.sym == "public_hash") { - Q_ASSERT(entry.vals.size() == 1); - key.public_hash = entry.vals.at(0); + Q_ASSERT(!entry.hash.isNull()); + key.public_hash = entry.hash; continue; } if (entry.sym == "private_hash") { - Q_ASSERT(entry.vals.size() == 1); - key.private_hash = entry.vals.at(0); + Q_ASSERT(!entry.hash.isNull()); + key.private_hash = entry.hash; continue; } ============================================================ --- src/model/Manifest.cpp d2f9630459f1cd73b5de8c64efb704a923e4552b +++ src/model/Manifest.cpp fb48177633ab4c1dae360a98b8d2f7b7bfe4558e @@ -114,8 +114,8 @@ void Manifest::parseOutput() if (entry.sym == "content") { - Q_ASSERT(entry.vals.size() == 1); - mEntry->hash = entry.vals.at(0); + Q_ASSERT(!entry.hash.isNull()); + mEntry->hash = entry.hash; continue; } ============================================================ --- src/model/Tags.cpp 8ddf2a8f16672cf70c49dbefdbdd33cd23ae38e6 +++ src/model/Tags.cpp de325a5a9ad62e565e3faf21572b89c0fc1abdd8 @@ -81,8 +81,8 @@ void Tags::parseOutput() if (entry.sym == "revision") { - Q_ASSERT(entry.vals.size() == 1); - tag.revision = entry.vals.at(0); + Q_ASSERT(!entry.hash.isNull()); + tag.revision = entry.hash; continue; } ============================================================ --- src/monotone/WorkspaceCommitter.cpp 24c20dd54d53c980f930dc569ffd8ef77838f12d +++ src/monotone/WorkspaceCommitter.cpp 3d4219a869dd03b66d987860b578ad62d46fd2ce @@ -22,6 +22,7 @@ #include "MonotoneDelegate.h" #include "Guitone.h" #include "BasicIOParser.h" +#include "BasicIOWriter.h" #include #include @@ -66,8 +67,8 @@ bool WorkspaceCommitter::run() QString fullRevision = data; - BasicIOParser parser(fullRevision); - if (!parser.parse()) + BasicIOParser revparser(fullRevision); + if (!revparser.parse()) { C("Could not parse basic_io."); return false; @@ -75,7 +76,7 @@ bool WorkspaceCommitter::run() QList > fileChanges; - StanzaList stanzas = parser.getStanzas(); + StanzaList stanzas = revparser.getStanzas(); foreach (Stanza st, stanzas) { QPair pair; @@ -100,7 +101,8 @@ bool WorkspaceCommitter::run() if (isPatch && en.sym == "from") { Q_ASSERT(!pair.first.isEmpty()); - pair.second = en.vals.at(0); + Q_ASSERT(!en.hash.isNull()); + pair.second = en.hash; fileChanges.append(pair); break; } @@ -155,9 +157,78 @@ bool WorkspaceCommitter::run() } D(QString("Committed revision %1").arg(revisionId)); + + // update _MTN/revision and _MTN/options + Q_ASSERT(workspaceDir.cd("_MTN")); + + return writeRevision() && writeOptions(); +} + +bool WorkspaceCommitter::writeRevision() +{ + QFile file(workspaceDir.filePath("revision")); + if (!file.open(QIODevice::WriteOnly)) + { + C("Can't open revision for writing"); + return false; + } + + StanzaList stanzas; + + Stanza format; + format.append(StanzaEntry("format_version", QStringList() << "1")); + stanzas.append(format); + + Stanza manifest; + manifest.append(StanzaEntry("format_version", + "0000000000000000000000000000000000000000")); + stanzas.append(manifest); + + Stanza oldrev; + oldrev.append(StanzaEntry("old_revision", revisionId)); + stanzas.append(oldrev); + + BasicIOWriter writer(stanzas); + QString rev = writer.write(); + Q_ASSERT(file.write(rev.toLatin1())); + file.close(); + return true; } +bool WorkspaceCommitter::writeOptions() +{ + QFile file(workspaceDir.filePath("options")); + if (!file.open(QIODevice::ReadWrite)) + { + C("Can't open options for reading and writing"); + return false; + } + + // read and parse the basic_io stanzas and set the correct branch name + BasicIOParser parser(QString::fromUtf8(file.readAll())); + Q_ASSERT(parser.parse()); + StanzaList stanzas = parser.getStanzas(); + Q_ASSERT(stanzas.size() == 1); + + for (int i=0, j=stanzas[0].size(); i #include +#include -class AbstractParser : public QObject +class AbstractParser { - Q_OBJECT public: AbstractParser(const QByteArray &); AbstractParser(const QString &); - ~AbstractParser(); + virtual ~AbstractParser(); virtual bool parse() = 0; inline QByteArray getLeftBytes() const { return input; } ============================================================ --- src/util/BasicIOParser.cpp b0c5cce7021156332b90b152bca8a07e4ae1a0d5 +++ src/util/BasicIOParser.cpp 180cfde05b833ae0e9a0735f22dc7d4c37634098 @@ -50,12 +50,11 @@ Stanza BasicIOParser::getStanza() qWarning("BasicIOParser::getStanza(): Couldn't get symbol."); } QString hash(getHash()); + // was this a hash? if (!hash.isNull()) { - // for now we do not make a distinction between normal hashes - // and content value lists - entry.vals.append(hash); + entry.hash = hash; } else { ============================================================ --- src/util/BasicIOParser.h 2abdc40c948b2678ceeebf976e5424076036a83d +++ src/util/BasicIOParser.h b96df0f29dd64ac740c6e8a7f34c080406d3837e @@ -22,20 +22,10 @@ #define BASICIO_PARSER_H #include "AbstractParser.h" +#include "vocab.h" -#include - -typedef struct { - QString sym; - QStringList vals; -} StanzaEntry; - -typedef QList Stanza; -typedef QList StanzaList; - class BasicIOParser : public AbstractParser { - Q_OBJECT public: BasicIOParser(const QString &); ============================================================ --- src/util/StdioParser.h 8488d8ccabd54eef76d773c0ccaf91ac47d95d3d +++ src/util/StdioParser.h ed0742f484843b709c946a2c030cca934432335d @@ -25,7 +25,6 @@ class StdioParser : public AbstractParse class StdioParser : public AbstractParser { - Q_OBJECT public: StdioParser(const QByteArray &); ============================================================ --- src/view/MainWindow.cpp 2df1db606ed6d15edf3587a46c721bacd2917328 +++ src/view/MainWindow.cpp db2c472be2967d42277ce729d593f74ea0f1b811 @@ -192,12 +192,7 @@ bool MainWindow::doLoadWorkspace(QString if (!invModel->readInventory()) { - QMessageBox::information( - this, - tr("Unable to execute command"), - tr("Unable to execute '%1' - maybe another command is still running?").arg("inventory"), - QMessageBox::Ok - ); + C("Could not read inventory"); return false; } @@ -658,3 +653,9 @@ void MainWindow::disableClosing() closeCounter++; } +void MainWindow::on_actionReload_workspace_triggered() +{ + bool ret = invModel->readInventory(); + if (!ret) C("Could not read inventory."); +} + ============================================================ --- src/view/MainWindow.h 7ea22986b3ba2005db4b604c592a91365ba78122 +++ src/view/MainWindow.h 38296ee6b6bbd5e84836949b27167abccb20bb6a @@ -55,8 +55,8 @@ signals: void quitApplication(); void updatePreviousWorkspacesMenu(); void updatePreviousDatabasesMenu(); - void loadDatabase(const QString &); - void loadWorkspace(const QString &); + void loadDatabase(const QString &); + void loadWorkspace(const QString &); private slots: void on_actionOpen_Workspace_triggered(); @@ -74,6 +74,7 @@ private slots: void on_actionChangeset_browser_triggered(); void on_actionBring_all_to_front_triggered(); void on_actionCheck_for_updates_triggered(); + void on_actionReload_workspace_triggered(); void openRecentWorkspace(); void openRecentDatabase(); ============================================================ --- src/vocab.h 514f8d7e143232a98175232e2133efe326200cc5 +++ src/vocab.h 41e69475de03ca8f2099076d05ddfa8760b7bb60 @@ -31,6 +31,7 @@ class Guitone; #include #include +#include // used for manifest entries, if the bool var is true, the entry is a directory typedef QPair FileEntry; @@ -44,4 +45,18 @@ typedef QList ByteArrayList; typedef QList ByteArrayList; +// used for BasicIOParser and BasicIOWriter +struct StanzaEntry { + StanzaEntry() {} + StanzaEntry(QString s, QString h) : sym(s), hash(h) {} + StanzaEntry(QString s, QStringList v) : sym(s), vals(v) {} + + QString sym; + QString hash; + QStringList vals; +}; + +typedef QList Stanza; +typedef QList StanzaList; + #endif