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 "revision.h"
0034 #include "pool.h"
0035 
0036 namespace svn
0037 {
0038 const svn_opt_revision_kind Revision::START = svn_opt_revision_number;
0039 const svn_opt_revision_kind Revision::BASE = svn_opt_revision_base;
0040 const svn_opt_revision_kind Revision::HEAD = svn_opt_revision_head;
0041 const svn_opt_revision_kind Revision::WORKING = svn_opt_revision_working;
0042 const svn_opt_revision_kind Revision::UNDEFINED = svn_opt_revision_unspecified;
0043 const svn_opt_revision_kind Revision::PREV = svn_opt_revision_previous;
0044 
0045 const svn_opt_revision_kind Revision::DATE = svn_opt_revision_date;
0046 const svn_opt_revision_kind Revision::NUMBER = Revision::START;
0047 
0048 Revision::Revision(const svn_opt_revision_t *revision)
0049 {
0050     init(revision);
0051 }
0052 
0053 Revision::Revision(const svn_revnum_t revnum)
0054 {
0055     if (revnum < 0) {
0056         m_revision.kind = svn_opt_revision_unspecified;
0057         m_revision.value.number = 0;
0058     } else {
0059         m_revision.kind = svn_opt_revision_number;
0060         m_revision.value.number = revnum;
0061     }
0062 }
0063 
0064 Revision::Revision(const svn_opt_revision_kind kind)
0065 {
0066     m_revision.kind = kind;
0067     m_revision.value.number = 0;
0068 }
0069 
0070 Revision::Revision(const int revnum, const QString &revstring)
0071 {
0072     m_revision.kind = svn_opt_revision_unspecified;
0073 
0074     if (revnum > -1) {
0075         m_revision.kind = svn_opt_revision_number;
0076         m_revision.value.number = revnum;
0077     } else {
0078         assign(revstring);
0079     }
0080 }
0081 
0082 Revision::Revision(const QString &revstring)
0083 {
0084     assign(revstring);
0085 }
0086 
0087 void Revision::assign(const QString &revstring)
0088 {
0089     m_revision.kind = svn_opt_revision_unspecified;
0090     if (revstring.isEmpty()) {
0091         return;
0092     }
0093     if (revstring == QLatin1String("WORKING")) {
0094         m_revision.kind = WORKING;
0095     } else if (revstring == QLatin1String("BASE")) {
0096         m_revision.kind = BASE;
0097     } else if (revstring == QLatin1String("START")) {
0098         m_revision.kind = Revision::START;
0099         m_revision.value.number = 0;
0100     } else if (revstring == QLatin1String("PREV")) {
0101         m_revision.kind = Revision::PREV;
0102     } else if (!revstring.isNull()) {
0103         Pool pool;
0104         svn_opt_revision_t endrev;
0105         svn_opt_parse_revision(&m_revision, &endrev, revstring.toUtf8(), pool);
0106     }
0107 }
0108 
0109 void Revision::assign(const QDateTime &dateTime)
0110 {
0111     m_revision.kind = svn_opt_revision_date;
0112     DateTime dt(dateTime);
0113     m_revision.value.date = dt.GetAPRTimeT();
0114 }
0115 
0116 Revision &Revision::operator=(const QString &what)
0117 {
0118     assign(what);
0119     return *this;
0120 }
0121 
0122 Revision::Revision(const QDateTime &dateTime)
0123 {
0124     assign(dateTime);
0125 }
0126 
0127 void Revision::init(const svn_opt_revision_t *revision)
0128 {
0129     if (!revision) {
0130         m_revision.kind = svn_opt_revision_unspecified;
0131     } else {
0132         m_revision.kind = revision->kind;
0133 
0134         // m_revision.value is a union so we are not
0135         // allowed to set number if we want to use date
0136         // and vice versa
0137 
0138         switch (revision->kind) {
0139         case svn_opt_revision_number:
0140             m_revision.value.number = revision->value.number;
0141             break;
0142 
0143         case svn_opt_revision_date:
0144             m_revision.value.date = revision->value.date;
0145             break;
0146 
0147         default:
0148             m_revision.value.number = 0;
0149         }
0150     }
0151 }
0152 
0153 Revision::operator QString() const
0154 {
0155     return toString();
0156 }
0157 
0158 QString Revision::toString() const
0159 {
0160     QString value;
0161     switch (m_revision.kind) {
0162     case svn_opt_revision_number:
0163         value = QString::asprintf("%li", m_revision.value.number);
0164         break;
0165     case svn_opt_revision_date:
0166         value = DateTime(m_revision.value.date).toString(QStringLiteral("{yyyy-MM-dd}"));
0167         break;
0168     case svn_opt_revision_base:
0169         value = QLatin1String("BASE");
0170         break;
0171     case svn_opt_revision_head:
0172         value = QLatin1String("HEAD");
0173         break;
0174     case svn_opt_revision_working:
0175         value = QLatin1String("WORKING");
0176         break;
0177     case svn_opt_revision_previous:
0178         value = QLatin1String("PREVIOUS");
0179         break;
0180     case svn_opt_revision_unspecified:
0181     default:
0182         value = QLatin1String("-1");
0183         break;
0184     }
0185     return value;
0186 }
0187 
0188 const svn_opt_revision_t *Revision::revision() const
0189 {
0190     return &m_revision;
0191 }
0192 
0193 svn_revnum_t Revision::revnum() const
0194 {
0195     if (m_revision.kind == svn_opt_revision_number) {
0196         return m_revision.value.number;
0197     }
0198     return SVN_INVALID_REVNUM;
0199 }
0200 
0201 apr_time_t Revision::date() const
0202 {
0203     return m_revision.value.date;
0204 }
0205 
0206 svn_opt_revision_kind Revision::kind() const
0207 {
0208     return m_revision.kind;
0209 }
0210 
0211 bool Revision::operator==(const Revision &r) const
0212 {
0213     if (r.kind() != kind()) {
0214         return false;
0215     }
0216     if (m_revision.kind == svn_opt_revision_number) {
0217         return revnum() == r.revnum();
0218     } else if (m_revision.kind == svn_opt_revision_date) {
0219         return date() == r.date();
0220     }
0221     return true;
0222 }
0223 
0224 bool Revision::operator==(int value) const
0225 {
0226     if (m_revision.kind != svn_opt_revision_number || value != revnum()) {
0227         return false;
0228     }
0229     return true;
0230 }
0231 
0232 bool Revision::operator!=(const svn_opt_revision_kind t) const
0233 {
0234     return kind() != t;
0235 }
0236 bool Revision::operator==(const svn_opt_revision_kind t) const
0237 {
0238     return kind() == t;
0239 }
0240 
0241 bool Revision::operator!() const
0242 {
0243     return kind() == UNDEFINED;
0244 }
0245 
0246 bool Revision::operator!()
0247 {
0248     return kind() == UNDEFINED;
0249 }
0250 
0251 Revision::operator bool() const
0252 {
0253     return kind() != UNDEFINED;
0254 }
0255 
0256 Revision::operator bool()
0257 {
0258     return kind() != UNDEFINED;
0259 }
0260 
0261 bool Revision::isRemote() const
0262 {
0263     return kind() != UNDEFINED && kind() != BASE && kind() != WORKING;
0264 }
0265 
0266 bool Revision::isValid() const
0267 {
0268     return kind() != UNDEFINED;
0269 }
0270 }
0271 
0272 /* -----------------------------------------------------------------
0273  * local variables:
0274  * eval: (load-file "../../rapidsvn-dev.el")
0275  * end:
0276  */