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

0001 /*
0002  * Port for usage with qt-framework and development for kdesvn
0003  * Copyright (C) 2005-2009 by Rajko Albrecht (ral@alwins-world.de)
0004  * https://kde.org/applications/development/org.kde.kdesvn
0005  */
0006 /*
0007  * ====================================================================
0008  * Copyright (c) 2002-2005 The RapidSvn Group.  All rights reserved.
0009  * dev@rapidsvn.tigris.org
0010  *
0011  * This library is free software; you can redistribute it and/or
0012  * modify it under the terms of the GNU Lesser General Public
0013  * License as published by the Free Software Foundation; either
0014  * version 2.1 of the License, or (at your option) any later version.
0015  *
0016  * This library is distributed in the hope that it will be useful,
0017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0019  * Lesser General Public License for more details.
0020  *
0021  * You should have received a copy of the GNU Lesser General Public
0022  * License along with this library (in the file LGPL.txt); if not,
0023  * write to the Free Software Foundation, Inc., 51 Franklin St,
0024  * Fifth Floor, Boston, MA  02110-1301  USA
0025  *
0026  * This software consists of voluntary contributions made by many
0027  * individuals.  For exact contribution history, see the revision
0028  * history and logs, available at http://rapidsvn.tigris.org/.
0029  * ====================================================================
0030  */
0031 
0032 // svncpp
0033 #include "status.h"
0034 #include "svnqt/path.h"
0035 #include "svnqt/svnqt_defines.h"
0036 #include "svnqt/url.h"
0037 
0038 #include "svn_path.h"
0039 
0040 namespace svn
0041 {
0042 class SVNQT_NOEXPORT Status_private
0043 {
0044 public:
0045     /**
0046      * Initialize structures
0047      *
0048      * @param path
0049      * @param status if NULL isVersioned will be false
0050      */
0051     void init(const QString &path, const svn_client_status_t *status);
0052     void init(const QString &path, const Status_private &src);
0053     void init(const QString &url, const DirEntry &src);
0054     void init(const QString &url, const InfoEntry &src);
0055 
0056     void setPath(const QString &);
0057 
0058     QString m_Path;
0059     LockEntry m_Lock;
0060     Entry m_entry;
0061     svn_wc_status_kind m_node_status = svn_wc_status_none;
0062     svn_wc_status_kind m_text_status = svn_wc_status_none;
0063     svn_wc_status_kind m_prop_status = svn_wc_status_none;
0064     svn_wc_status_kind m_repos_text_status = svn_wc_status_none;
0065     svn_wc_status_kind m_repos_prop_status = svn_wc_status_none;
0066     bool m_isVersioned = false;
0067     bool m_hasReal = false;
0068     bool m_copied = false;
0069     bool m_switched = false;
0070 };
0071 
0072 void Status_private::setPath(const QString &aPath)
0073 {
0074     Pool pool;
0075     if (!Url::isValid(aPath)) {
0076         m_Path = aPath;
0077     } else {
0078         const char *int_path = svn_path_uri_decode(aPath.toUtf8(), pool.pool());
0079         m_Path = QString::fromUtf8(int_path);
0080     }
0081 }
0082 
0083 void Status_private::init(const QString &path, const svn_client_status_t *status)
0084 {
0085     setPath(path);
0086     if (!status) {
0087         m_isVersioned = false;
0088         m_hasReal = false;
0089         m_entry = Entry();
0090         m_Lock = LockEntry();
0091     } else {
0092         // now duplicate the contents
0093         // svn 1.7 does not count ignored entries as versioned but we do here...
0094         m_isVersioned = status->node_status > svn_wc_status_unversioned;
0095         m_hasReal = m_isVersioned && status->node_status != svn_wc_status_ignored;
0096         m_entry = Entry(status);
0097         m_node_status = status->node_status;
0098         m_text_status = status->text_status;
0099         m_prop_status = status->prop_status;
0100         m_copied = status->copied != 0;
0101         m_switched = status->switched != 0;
0102         m_repos_text_status = status->repos_text_status;
0103         m_repos_prop_status = status->repos_prop_status;
0104         if (status->repos_lock) {
0105             m_Lock.init(status->repos_lock->creation_date,
0106                         status->repos_lock->expiration_date,
0107                         status->repos_lock->owner,
0108                         status->repos_lock->comment,
0109                         status->repos_lock->token);
0110         } else {
0111             m_Lock = LockEntry();
0112         }
0113     }
0114 }
0115 
0116 void Status_private::init(const QString &path, const Status_private &src)
0117 {
0118     setPath(path);
0119     m_Lock = src.m_Lock;
0120     m_entry = src.m_entry;
0121     m_node_status = src.m_node_status;
0122     m_text_status = src.m_text_status;
0123     m_prop_status = src.m_prop_status;
0124     m_repos_text_status = src.m_repos_text_status;
0125     m_repos_prop_status = src.m_repos_prop_status;
0126     m_isVersioned = src.m_isVersioned;
0127     m_hasReal = src.m_hasReal;
0128     m_copied = src.m_copied;
0129     m_switched = src.m_switched;
0130 }
0131 
0132 void Status_private::init(const QString &url, const DirEntry &src)
0133 {
0134     m_entry = Entry(url, src);
0135     setPath(url);
0136     m_node_status = svn_wc_status_normal;
0137     m_text_status = svn_wc_status_normal;
0138     m_prop_status = svn_wc_status_normal;
0139     if (!src.isEmpty()) {
0140         m_Lock = src.lockEntry();
0141         m_isVersioned = true;
0142         m_hasReal = true;
0143     }
0144     m_switched = false;
0145     m_repos_text_status = svn_wc_status_normal;
0146     m_repos_prop_status = svn_wc_status_normal;
0147 }
0148 
0149 void Status_private::init(const QString &url, const InfoEntry &src)
0150 {
0151     m_entry = Entry(url, src);
0152     setPath(url);
0153     m_Lock = src.lockEntry();
0154     m_node_status = svn_wc_status_normal;
0155     m_text_status = svn_wc_status_normal;
0156     m_prop_status = svn_wc_status_normal;
0157     m_repos_text_status = svn_wc_status_normal;
0158     m_repos_prop_status = svn_wc_status_normal;
0159     m_isVersioned = true;
0160     m_hasReal = true;
0161 }
0162 
0163 Status::Status(const Status &src)
0164     : m_Data(new Status_private())
0165 {
0166     if (&src != this) {
0167         if (src.m_Data) {
0168             m_Data->init(src.m_Data->m_Path, *(src.m_Data));
0169         } else {
0170             m_Data->init(QString(), nullptr);
0171         }
0172     }
0173 }
0174 
0175 Status::Status(const char *path, const svn_client_status_t *status)
0176     : m_Data(new Status_private())
0177 {
0178     m_Data->init(QString::fromUtf8(path), status);
0179 }
0180 
0181 Status::Status(const QString &path)
0182     : m_Data(new Status_private())
0183 {
0184     m_Data->init(path, nullptr);
0185 }
0186 
0187 Status::Status(const QString &url, const DirEntry &src)
0188     : m_Data(new Status_private())
0189 {
0190     m_Data->init(url, src);
0191 }
0192 
0193 Status::Status(const QString &url, const InfoEntry &src)
0194     : m_Data(new Status_private())
0195 {
0196     m_Data->init(url, src);
0197 }
0198 
0199 Status::~Status()
0200 {
0201     delete m_Data;
0202 }
0203 
0204 Status &Status::operator=(const Status &status)
0205 {
0206     if (this == &status) {
0207         return *this;
0208     }
0209     if (status.m_Data) {
0210         m_Data->init(status.m_Data->m_Path, *(status.m_Data));
0211     } else {
0212         m_Data->init(status.m_Data->m_Path, nullptr);
0213     }
0214     return *this;
0215 }
0216 
0217 const LockEntry &Status::lockEntry() const
0218 {
0219     return m_Data->m_Lock;
0220 }
0221 svn_wc_status_kind Status::reposPropStatus() const
0222 {
0223     return m_Data->m_repos_prop_status;
0224 }
0225 svn_wc_status_kind Status::reposTextStatus() const
0226 {
0227     return m_Data->m_repos_text_status;
0228 }
0229 bool Status::isSwitched() const
0230 {
0231     return m_Data->m_switched != 0;
0232 }
0233 bool Status::isCopied() const
0234 {
0235     return m_Data->m_copied;
0236 }
0237 
0238 bool Status::isLocked() const
0239 {
0240     return m_Data->m_Lock.Locked();
0241 }
0242 
0243 bool Status::isModified() const
0244 {
0245     return textStatus() == svn_wc_status_modified || propStatus() == svn_wc_status_modified || textStatus() == svn_wc_status_replaced;
0246 }
0247 
0248 bool Status::isRealVersioned() const
0249 {
0250     return m_Data->m_hasReal;
0251 }
0252 
0253 bool Status::isVersioned() const
0254 {
0255     return m_Data->m_isVersioned;
0256 }
0257 
0258 svn_wc_status_kind Status::nodeStatus() const
0259 {
0260     return m_Data->m_node_status;
0261 }
0262 
0263 svn_wc_status_kind Status::propStatus() const
0264 {
0265     return m_Data->m_prop_status;
0266 }
0267 
0268 svn_wc_status_kind Status::textStatus() const
0269 {
0270     return m_Data->m_text_status;
0271 }
0272 
0273 const Entry &Status::entry() const
0274 {
0275     return m_Data->m_entry;
0276 }
0277 
0278 const QString &Status::path() const
0279 {
0280     return m_Data->m_Path;
0281 }
0282 
0283 bool Status::validReposStatus() const
0284 {
0285     return reposTextStatus() != svn_wc_status_none || reposPropStatus() != svn_wc_status_none;
0286 }
0287 
0288 bool Status::validLocalStatus() const
0289 {
0290     return textStatus() != svn_wc_status_none || propStatus() != svn_wc_status_none;
0291 }
0292 }