File indexing completed on 2024-04-28 05:42:10
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 #include "path.h" 0033 #include "helper.h" 0034 0035 // subversion api 0036 #include <svn_dirent_uri.h> 0037 #include <svn_path.h> 0038 0039 // apr api 0040 #include <apr_file_io.h> 0041 0042 // svncpp 0043 #include "exception.h" 0044 #include "pool.h" 0045 #include "revision.h" 0046 #include "svnqt_defines.h" 0047 #include "url.h" 0048 0049 #include <QDir> 0050 #include <QUrl> 0051 0052 namespace svn 0053 { 0054 Path::Path(const QString &path) 0055 { 0056 init(path); 0057 } 0058 0059 void Path::init(const QString &path) 0060 { 0061 Pool pool; 0062 0063 if (path.isEmpty()) { 0064 m_path.clear(); 0065 } else { 0066 QByteArray int_path = path.toUtf8(); 0067 0068 if (Url::isValid(path)) { 0069 if (!svn_path_is_uri_safe(int_path)) { 0070 int_path = svn_path_uri_encode(int_path, pool); 0071 } 0072 } else { 0073 int_path = svn_dirent_internal_style(int_path, pool.pool()); 0074 } 0075 0076 m_path = QString::fromUtf8(int_path); 0077 while (m_path.endsWith(QLatin1Char('/')) && m_path.size() > 1) { 0078 m_path.chop(1); 0079 } 0080 } 0081 } 0082 0083 bool Path::isUrl() const 0084 { 0085 return Url::isValid(m_path); 0086 } 0087 0088 const QString &Path::path() const 0089 { 0090 return m_path; 0091 } 0092 0093 const QByteArray Path::cstr() const 0094 { 0095 return m_path.toUtf8(); 0096 } 0097 0098 bool Path::isSet() const 0099 { 0100 return !m_path.isEmpty(); 0101 } 0102 0103 void Path::addComponent(const QString &_component) 0104 { 0105 Pool pool; 0106 QString component = _component; 0107 while (component.endsWith(QLatin1Char('/'))) { 0108 component.chop(1); 0109 } 0110 if (Url::isValid(m_path)) { 0111 const char *newPath = svn_path_url_add_component2(m_path.toUtf8(), component.toUtf8(), pool); 0112 m_path = QString::fromUtf8(newPath); 0113 } else { 0114 svn_stringbuf_t *pathStringbuf = svn_stringbuf_create(m_path.toUtf8(), pool); 0115 0116 svn_path_add_component(pathStringbuf, component.toUtf8()); 0117 m_path = QString::fromUtf8(pathStringbuf->data); 0118 } 0119 } 0120 0121 void Path::removeLast() 0122 { 0123 Pool pool; 0124 if (m_path.length() <= 1) { 0125 m_path.clear(); 0126 } 0127 svn_stringbuf_t *pathStringbuf = svn_stringbuf_create(m_path.toUtf8(), pool); 0128 svn_path_remove_component(pathStringbuf); 0129 m_path = QString::fromUtf8(pathStringbuf->data); 0130 } 0131 0132 void Path::parsePeg(const QString &pathorurl, Path &_path, svn::Revision &_peg) 0133 { 0134 const QByteArray _buf = pathorurl.toUtf8(); 0135 const char *truepath = nullptr; 0136 svn_opt_revision_t pegr; 0137 0138 Pool pool; 0139 svn_error_t *error = svn_opt_parse_path(&pegr, &truepath, _buf, pool); 0140 if (error != nullptr) { 0141 throw ClientException(error); 0142 } 0143 // qDebug("Path: %s",truepath); 0144 _peg = svn::Revision(&pegr); 0145 _path = Path(QString::fromUtf8(truepath)); 0146 } 0147 0148 unsigned int Path::length() const 0149 { 0150 return m_path.length(); 0151 } 0152 0153 QString Path::native() const 0154 { 0155 if (isUrl()) { 0156 return m_path; 0157 } 0158 Pool pool; 0159 return QString::fromUtf8(svn_dirent_local_style(m_path.toUtf8(), pool)); 0160 } 0161 0162 } 0163 0164 /* ----------------------------------------------------------------- 0165 * local variables: 0166 * eval: (load-file "../../rapidsvn-dev.el") 0167 * end: 0168 */