File indexing completed on 2024-05-19 16:47:12

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  * http://kdesvn.alwins-world.de
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/svnqt_defines.h"
0035 #include "svnqt/path.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     Status_private();
0046     virtual ~Status_private();
0047     /**
0048      * Initialize structures
0049      *
0050      * @param path
0051      * @param status if NULL isVersioned will be false
0052      */
0053     void init(const QString &path, const svn_client_status_t *status);
0054     void init(const QString &path, const Status_private &src);
0055     void init(const QString &url, const DirEntry &src);
0056     void init(const QString &url, const InfoEntry &src);
0057 
0058     void setPath(const QString &);
0059 
0060     QString m_Path;
0061     bool m_isVersioned;
0062     bool m_hasReal;
0063     LockEntry m_Lock;
0064     Entry m_entry;
0065 
0066     svn_wc_status_kind m_node_status, m_text_status, m_prop_status, m_repos_text_status, m_repos_prop_status;
0067     bool m_copied, m_switched;
0068 };
0069 
0070 Status_private::Status_private()
0071     : m_Path()
0072     , m_isVersioned(false)
0073     , m_hasReal(false)
0074     , m_node_status(svn_wc_status_none)
0075     , m_text_status(svn_wc_status_none)
0076     , m_prop_status(svn_wc_status_none)
0077     , m_repos_text_status(svn_wc_status_none)
0078     , m_repos_prop_status(svn_wc_status_none)
0079     , m_copied(false)
0080     , m_switched(false)
0081 {
0082 }
0083 
0084 Status_private::~ Status_private()
0085 {
0086 }
0087 
0088 void Status_private::setPath(const QString &aPath)
0089 {
0090     Pool pool;
0091     if (!Url::isValid(aPath)) {
0092         m_Path = aPath;
0093     } else {
0094         const char *int_path = svn_path_uri_decode(aPath.toUtf8(), pool.pool());
0095         m_Path = QString::fromUtf8(int_path);
0096     }
0097 }
0098 
0099 void Status_private::init(const QString &path, const svn_client_status_t *status)
0100 {
0101     setPath(path);
0102     if (!status) {
0103         m_isVersioned = false;
0104         m_hasReal = false;
0105         m_entry = Entry();
0106         m_Lock = LockEntry();
0107     } else {
0108         // now duplicate the contents
0109         // svn 1.7 does not count ignored entries as versioned but we do here...
0110         m_isVersioned = status->node_status > svn_wc_status_unversioned;
0111         m_hasReal = m_isVersioned &&
0112                     status->node_status != svn_wc_status_ignored;
0113         m_entry = Entry(status);
0114         m_node_status = status->node_status;
0115         m_text_status = status->text_status;
0116         m_prop_status = status->prop_status;
0117         m_copied = status->copied != 0;
0118         m_switched = status->switched != 0;
0119         m_repos_text_status = status->repos_text_status;
0120         m_repos_prop_status = status->repos_prop_status;
0121         if (status->repos_lock) {
0122             m_Lock.init(status->repos_lock->creation_date,
0123                         status->repos_lock->expiration_date,
0124                         status->repos_lock->owner,
0125                         status->repos_lock->comment,
0126                         status->repos_lock->token);
0127         } else {
0128             m_Lock = LockEntry();
0129         }
0130     }
0131 }
0132 
0133 void
0134 Status_private::init(const QString &path, const Status_private &src)
0135 {
0136     setPath(path);
0137     m_Lock = src.m_Lock;
0138     m_entry = src.m_entry;
0139     m_isVersioned = src.m_isVersioned;
0140     m_hasReal = src.m_hasReal;
0141     m_node_status = src.m_node_status;
0142     m_text_status = src.m_text_status;
0143     m_prop_status = src.m_prop_status;
0144     m_repos_text_status = src.m_repos_text_status;
0145     m_repos_prop_status = src.m_repos_prop_status;
0146     m_copied = src.m_copied;
0147     m_switched = src.m_switched;
0148 }
0149 
0150 void Status_private::init(const QString &url, const DirEntry &src)
0151 {
0152     m_entry = Entry(url, src);
0153     setPath(url);
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     if (!src.isEmpty()) {
0158         m_Lock = src.lockEntry();
0159         m_isVersioned = true;
0160         m_hasReal = true;
0161     }
0162     m_switched = false;
0163     m_repos_text_status = svn_wc_status_normal;
0164     m_repos_prop_status = svn_wc_status_normal;
0165 }
0166 
0167 void Status_private::init(const QString &url, const InfoEntry &src)
0168 {
0169     m_entry = Entry(url, src);
0170     setPath(url);
0171     m_Lock = src.lockEntry();
0172     m_node_status = svn_wc_status_normal;
0173     m_text_status = svn_wc_status_normal;
0174     m_prop_status = svn_wc_status_normal;
0175     m_repos_text_status = svn_wc_status_normal;
0176     m_repos_prop_status = svn_wc_status_normal;
0177     m_isVersioned = true;
0178     m_hasReal = true;
0179 }
0180 
0181 Status::Status(const Status &src)
0182     : m_Data(new Status_private())
0183 {
0184     if (&src != this) {
0185         if (src.m_Data) {
0186             m_Data->init(src.m_Data->m_Path, *(src.m_Data));
0187         } else {
0188             m_Data->init(QString(), nullptr);
0189         }
0190     }
0191 }
0192 
0193 Status::Status(const char *path, const svn_client_status_t *status)
0194   : m_Data(new Status_private())
0195 {
0196     m_Data->init(QString::fromUtf8(path), status);
0197 }
0198 
0199 Status::Status(const QString &path)
0200     : m_Data(new Status_private())
0201 {
0202     m_Data->init(path, nullptr);
0203 }
0204 
0205 Status::Status(const QString &url, const DirEntry &src)
0206     : m_Data(new Status_private())
0207 {
0208     m_Data->init(url, src);
0209 }
0210 
0211 Status::Status(const QString &url, const InfoEntry &src)
0212     : m_Data(new Status_private())
0213 {
0214     m_Data->init(url, src);
0215 }
0216 
0217 Status::~Status()
0218 {
0219     delete m_Data;
0220 }
0221 
0222 Status &
0223 Status::operator=(const Status &status)
0224 {
0225     if (this == &status) {
0226         return *this;
0227     }
0228     if (status.m_Data) {
0229         m_Data->init(status.m_Data->m_Path, *(status.m_Data));
0230     } else {
0231         m_Data->init(status.m_Data->m_Path, nullptr);
0232     }
0233     return *this;
0234 }
0235 
0236 const LockEntry &
0237 Status::lockEntry() const
0238 {
0239     return m_Data->m_Lock;
0240 }
0241 svn_wc_status_kind
0242 Status::reposPropStatus() const
0243 {
0244     return m_Data->m_repos_prop_status;
0245 }
0246 svn_wc_status_kind
0247 Status::reposTextStatus() const
0248 {
0249     return m_Data->m_repos_text_status;
0250 }
0251 bool
0252 Status::isSwitched() const
0253 {
0254     return m_Data->m_switched != 0;
0255 }
0256 bool
0257 Status::isCopied() const
0258 {
0259     return m_Data->m_copied;
0260 }
0261 
0262 bool
0263 Status::isLocked() const
0264 {
0265     return m_Data->m_Lock.Locked();
0266 }
0267 
0268 bool
0269 Status::isModified()const
0270 {
0271     return textStatus() == svn_wc_status_modified || propStatus() == svn_wc_status_modified
0272            || textStatus() == svn_wc_status_replaced;
0273 }
0274 
0275 bool
0276 Status::isRealVersioned()const
0277 {
0278     return m_Data->m_hasReal;
0279 }
0280 
0281 bool
0282 Status::isVersioned() const
0283 {
0284     return m_Data->m_isVersioned;
0285 }
0286 
0287 svn_wc_status_kind
0288 Status::nodeStatus() const
0289 {
0290     return m_Data->m_node_status;
0291 }
0292 
0293 svn_wc_status_kind
0294 Status::propStatus() const
0295 {
0296     return m_Data->m_prop_status;
0297 }
0298 
0299 svn_wc_status_kind
0300 Status::textStatus() const
0301 {
0302     return m_Data->m_text_status;
0303 }
0304 
0305 const Entry &
0306 Status::entry() const
0307 {
0308     return m_Data->m_entry;
0309 }
0310 
0311 const QString &
0312 Status::path() const
0313 {
0314     return m_Data->m_Path;
0315 }
0316 
0317 bool
0318 Status::validReposStatus()const
0319 {
0320     return reposTextStatus() != svn_wc_status_none || reposPropStatus() != svn_wc_status_none;
0321 }
0322 
0323 bool
0324 Status::validLocalStatus()const
0325 {
0326     return textStatus() != svn_wc_status_none || propStatus() != svn_wc_status_none;
0327 }
0328 }