File indexing completed on 2024-04-28 05:42:11

0001 /*
0002     <one line to give the library's name and an idea of what it does.>
0003     Copyright (C) 2012  Rajko Albrecht <ral@alwins-world.de>
0004 
0005     This library is free software; you can redistribute it and/or
0006     modify it under the terms of the GNU Lesser General Public
0007     License as published by the Free Software Foundation; either
0008     version 2.1 of the License, or (at your option) any later version.
0009 
0010     This library is distributed in the hope that it will be useful,
0011     but WITHOUT ANY WARRANTY; without even the implied warranty of
0012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013     Lesser General Public License for more details.
0014 
0015     You should have received a copy of the GNU Lesser General Public
0016     License along with this library; if not, write to the Free Software
0017     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0018 */
0019 
0020 #include "svnqt/reposnotify.h"
0021 #include "svnqt/helper.h"
0022 #include "svnqt/path.h"
0023 #include "svnqt/revision.h"
0024 #include "svnqt/svnqt_defines.h"
0025 
0026 #include <svn_props.h>
0027 #include <svn_repos.h>
0028 
0029 namespace svn
0030 {
0031 namespace repository
0032 {
0033 
0034 class ReposNotifyData
0035 {
0036     QString _warning_msg;
0037 
0038     /// TODO own datatype
0039     svn_repos_notify_action_t _action;
0040     svn::Revision _rev;
0041     /// TODO own datatype
0042     svn_repos_notify_warning_t _warning;
0043     qlonglong _shard;
0044 
0045     svn::Revision _oldrev;
0046     svn::Revision _newrev;
0047 
0048     /// TODO own datatype
0049     svn_node_action _node_action;
0050 
0051     svn::Path _path;
0052 
0053     mutable QString _msg;
0054 
0055 public:
0056     ReposNotifyData(const svn_repos_notify_t *notify)
0057         : _warning_msg(QString())
0058         , _msg(QString())
0059     {
0060         if (!notify) {
0061             return;
0062         }
0063         _action = notify->action;
0064         _rev = notify->revision;
0065         if (notify->warning_str) {
0066             _warning_msg = QString::fromUtf8(notify->warning_str);
0067         }
0068         _warning = notify->warning;
0069         _shard = notify->shard;
0070         _oldrev = notify->old_revision;
0071         _newrev = notify->new_revision;
0072         _node_action = notify->node_action;
0073         if (notify->path != nullptr) {
0074             _path = svn::Path(QString::fromUtf8(notify->path));
0075         }
0076     }
0077 
0078     ~ReposNotifyData()
0079     {
0080     }
0081 
0082     const QString &toString() const
0083     {
0084         if (_msg.isEmpty()) {
0085             switch (_action) {
0086             case svn_repos_notify_warning: {
0087                 switch (_warning) {
0088                 case svn_repos_notify_warning_found_old_reference:
0089                     _msg = QStringLiteral("Old Reference: ");
0090                     break;
0091                 case svn_repos_notify_warning_found_old_mergeinfo:
0092                     _msg = QStringLiteral("Old mergeinfo found: ");
0093                     break;
0094                 case svn_repos_notify_warning_invalid_fspath:
0095                     _msg = QStringLiteral("Invalid path: ");
0096                     break;
0097                 default:
0098                     _msg.clear();
0099                 }
0100                 _msg += _warning_msg;
0101             } break;
0102             case svn_repos_notify_dump_rev_end:
0103             case svn_repos_notify_verify_rev_end: {
0104                 _msg = QStringLiteral("Revision %1 finished.").arg(_rev.toString());
0105             } break;
0106             case svn_repos_notify_dump_end: {
0107                 _msg = QStringLiteral("Dump finished");
0108             } break;
0109             case svn_repos_notify_verify_end: {
0110                 _msg = QStringLiteral("Verification finished");
0111             } break;
0112             case svn_repos_notify_pack_shard_start: {
0113                 _msg = QStringLiteral("Packing revisions in shard %1").arg(_shard);
0114             } break;
0115             case svn_repos_notify_pack_shard_end_revprop:
0116             case svn_repos_notify_pack_shard_end:
0117             case svn_repos_notify_load_node_done: {
0118                 _msg = QStringLiteral("Done");
0119             } break;
0120             case svn_repos_notify_pack_shard_start_revprop: {
0121                 _msg = QStringLiteral("Packing revsion properties in shard %1").arg(_shard);
0122             } break;
0123             case svn_repos_notify_load_txn_start: {
0124                 _msg = QStringLiteral("Start loading old revision %1").arg(_oldrev.toString());
0125             } break;
0126             case svn_repos_notify_load_txn_committed: {
0127                 _msg = QStringLiteral("Committed new revision %1").arg(_newrev.toString());
0128                 if (_oldrev.isValid()) {
0129                     _msg.append(QLatin1String(" loaded from original revision ")).append(_oldrev.toString());
0130                 }
0131             } break;
0132             case svn_repos_notify_load_node_start: {
0133                 QString action;
0134                 switch (_node_action) {
0135                 case svn_node_action_change:
0136                     action = QStringLiteral("changing");
0137                     break;
0138                 case svn_node_action_add:
0139                     action = QStringLiteral("adding");
0140                     break;
0141                 case svn_node_action_delete:
0142                     action = QStringLiteral("deletion");
0143                     break;
0144                 case svn_node_action_replace:
0145                     action = QStringLiteral("replacing");
0146                     break;
0147                 }
0148                 _msg = QLatin1String("Start ") + action + QLatin1String(" on node ") + _path.native();
0149             } break;
0150             case svn_repos_notify_load_copied_node: {
0151                 _msg = QStringLiteral("Copied");
0152             } break;
0153             case svn_repos_notify_load_normalized_mergeinfo: {
0154                 _msg = QStringLiteral("Removing \\r from ") + QLatin1String(SVN_PROP_MERGEINFO);
0155             } break;
0156             case svn_repos_notify_mutex_acquired: {
0157             } break;
0158             case svn_repos_notify_recover_start: {
0159             } break;
0160             case svn_repos_notify_upgrade_start: {
0161             } break;
0162             }
0163         }
0164         return _msg;
0165     }
0166 };
0167 
0168 ReposNotify::ReposNotify(const svn_repos_notify_t *notify)
0169 {
0170     m_data = new ReposNotifyData(notify);
0171 }
0172 
0173 ReposNotify::~ReposNotify()
0174 {
0175     delete m_data;
0176 }
0177 
0178 ReposNotify::operator const QString &() const
0179 {
0180     return m_data->toString();
0181 }
0182 
0183 }
0184 }