File indexing completed on 2024-05-12 17:16:25
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 "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 0088 Revision::assign(const QString &revstring) 0089 { 0090 m_revision.kind = svn_opt_revision_unspecified; 0091 if (revstring.isEmpty()) { 0092 return; 0093 } 0094 if (revstring == QLatin1String("WORKING")) { 0095 m_revision.kind = WORKING; 0096 } else if (revstring == QLatin1String("BASE")) { 0097 m_revision.kind = BASE; 0098 } else if (revstring == QLatin1String("START")) { 0099 m_revision.kind = Revision::START; 0100 m_revision.value.number = 0; 0101 } else if (revstring == QLatin1String("PREV")) { 0102 m_revision.kind = Revision::PREV; 0103 } else if (!revstring.isNull()) { 0104 Pool pool; 0105 svn_opt_revision_t endrev; 0106 svn_opt_parse_revision(&m_revision, &endrev, revstring.toUtf8(), pool); 0107 } 0108 } 0109 0110 void 0111 Revision::assign(const QDateTime &dateTime) 0112 { 0113 m_revision.kind = svn_opt_revision_date; 0114 DateTime dt(dateTime); 0115 m_revision.value.date = dt.GetAPRTimeT(); 0116 } 0117 0118 Revision &Revision::operator=(const QString &what) 0119 { 0120 assign(what); 0121 return *this; 0122 } 0123 0124 Revision::Revision(const QDateTime &dateTime) 0125 { 0126 assign(dateTime); 0127 } 0128 0129 void 0130 Revision::init(const svn_opt_revision_t *revision) 0131 { 0132 if (!revision) { 0133 m_revision.kind = svn_opt_revision_unspecified; 0134 } else { 0135 m_revision.kind = revision->kind; 0136 0137 // m_revision.value is a union so we are not 0138 // allowed to set number if we want to use date 0139 // and vice versa 0140 0141 switch (revision->kind) { 0142 case svn_opt_revision_number: 0143 m_revision.value.number = revision->value.number; 0144 break; 0145 0146 case svn_opt_revision_date: 0147 m_revision.value.date = revision->value.date; 0148 break; 0149 0150 default: 0151 m_revision.value.number = 0; 0152 } 0153 } 0154 } 0155 0156 Revision::operator QString()const 0157 { 0158 return toString(); 0159 } 0160 0161 QString Revision::toString()const 0162 { 0163 QString value; 0164 switch (m_revision.kind) { 0165 case svn_opt_revision_number: 0166 value.sprintf("%li", m_revision.value.number); 0167 break; 0168 case svn_opt_revision_date: 0169 value = DateTime(m_revision.value.date).toString(QStringLiteral("{yyyy-MM-dd}")); 0170 break; 0171 case svn_opt_revision_base: 0172 value = QLatin1String("BASE"); 0173 break; 0174 case svn_opt_revision_head: 0175 value = QLatin1String("HEAD"); 0176 break; 0177 case svn_opt_revision_working: 0178 value = QLatin1String("WORKING"); 0179 break; 0180 case svn_opt_revision_previous: 0181 value = QLatin1String("PREVIOUS"); 0182 break; 0183 case svn_opt_revision_unspecified: 0184 default: 0185 value =QLatin1String( "-1"); 0186 break; 0187 } 0188 return value; 0189 } 0190 0191 const svn_opt_revision_t * 0192 Revision::revision() const 0193 { 0194 return &m_revision; 0195 } 0196 0197 svn_revnum_t 0198 Revision::revnum() const 0199 { 0200 if (m_revision.kind == svn_opt_revision_number) { 0201 return m_revision.value.number; 0202 } 0203 return SVN_INVALID_REVNUM; 0204 } 0205 0206 apr_time_t 0207 Revision::date() const 0208 { 0209 return m_revision.value.date; 0210 } 0211 0212 svn_opt_revision_kind 0213 Revision::kind() const 0214 { 0215 return m_revision.kind; 0216 } 0217 0218 bool Revision::operator==(const Revision &r)const 0219 { 0220 if (r.kind() != kind()) { 0221 return false; 0222 } 0223 if (m_revision.kind == svn_opt_revision_number) { 0224 return revnum() == r.revnum(); 0225 } else if (m_revision.kind == svn_opt_revision_date) { 0226 return date() == r.date(); 0227 } 0228 return true; 0229 } 0230 0231 bool Revision::operator==(int value)const 0232 { 0233 if (m_revision.kind != svn_opt_revision_number || value != revnum()) { 0234 return false; 0235 } 0236 return true; 0237 } 0238 0239 bool Revision::operator!=(const svn_opt_revision_kind t)const 0240 { 0241 return kind() != t; 0242 } 0243 bool Revision::operator==(const svn_opt_revision_kind t)const 0244 { 0245 return kind() == t; 0246 } 0247 0248 bool Revision::operator!()const 0249 { 0250 return kind() == UNDEFINED; 0251 } 0252 0253 bool Revision::operator!() 0254 { 0255 return kind() == UNDEFINED; 0256 } 0257 0258 Revision::operator bool()const 0259 { 0260 return kind() != UNDEFINED; 0261 } 0262 0263 Revision::operator bool() 0264 { 0265 return kind() != UNDEFINED; 0266 } 0267 0268 bool Revision::isRemote()const 0269 { 0270 return kind() != UNDEFINED && kind() != BASE && kind() != WORKING; 0271 } 0272 0273 bool Revision::isValid() const 0274 { 0275 return kind() != UNDEFINED; 0276 } 0277 } 0278 0279 /* ----------------------------------------------------------------- 0280 * local variables: 0281 * eval: (load-file "../../rapidsvn-dev.el") 0282 * end: 0283 */