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

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 "client_impl.h"
0034 #include "exception.h"
0035 #include "helper.h"
0036 #include "svnqt_defines.h"
0037 
0038 #include <svn_opt.h>
0039 #include <svn_ra.h>
0040 
0041 namespace svn
0042 {
0043 
0044 Client_impl::Client_impl(const ContextP &context)
0045     : Client()
0046 {
0047     setContext(context);
0048 }
0049 
0050 Client_impl::~Client_impl()
0051 {
0052 }
0053 
0054 const ContextP Client_impl::getContext() const
0055 {
0056     return m_context;
0057 }
0058 
0059 void Client_impl::setContext(const ContextP &context)
0060 {
0061     m_context = context;
0062 }
0063 
0064 void Client_impl::url2Revision(const QString &revstring, Revision &start, Revision &end)
0065 {
0066     Pool pool;
0067     int n = svn_opt_parse_revision(start, end, revstring.toUtf8(), pool);
0068 
0069     if (n < 0) {
0070         start = Revision::UNDEFINED;
0071         end = Revision::UNDEFINED;
0072     }
0073 }
0074 
0075 void Client_impl::url2Revision(const QString &revstring, Revision &start)
0076 {
0077     if (revstring == QLatin1String("WORKING")) {
0078         start = Revision::WORKING;
0079     } else if (revstring == QLatin1String("BASE")) {
0080         start = Revision::BASE;
0081     } else if (revstring == QLatin1String("START")) {
0082         start = Revision::START;
0083     } else {
0084         Revision end;
0085         url2Revision(revstring, start, end);
0086     }
0087 }
0088 
0089 apr_hash_t *Client_impl::map2hash(const PropertiesMap &aMap, const Pool &pool)
0090 {
0091     return svn::internal::Map2Hash(aMap).hash(pool);
0092 }
0093 
0094 bool Client_impl::RepoHasCapability(const Path &repository, Capability capability)
0095 {
0096     svn_error_t *error = nullptr;
0097     Pool pool;
0098 
0099     svn_ra_session_t *session = nullptr;
0100     // todo svn 1.8: svn_client_open_ra_session2
0101     error = svn_client_open_ra_session(&session, repository.cstr(), *m_context, pool);
0102     if (error != nullptr) {
0103         throw ClientException(error);
0104     }
0105     if (!session) {
0106         return false;
0107     }
0108     const char *capa = nullptr;
0109     switch (capability) {
0110     case CapabilityMergeinfo:
0111         capa = SVN_RA_CAPABILITY_MERGEINFO;
0112         break;
0113     case CapabilityDepth:
0114         capa = SVN_RA_CAPABILITY_DEPTH;
0115         break;
0116     case CapabilityCommitRevProps:
0117         capa = SVN_RA_CAPABILITY_COMMIT_REVPROPS;
0118         break;
0119     case CapabilityLogRevProps:
0120         capa = SVN_RA_CAPABILITY_LOG_REVPROPS;
0121         break;
0122     default:
0123         return false;
0124     }
0125     svn_boolean_t has = 0;
0126     error = svn_ra_has_capability(session, &has, capa, pool);
0127     if (error != nullptr) {
0128         throw ClientException(error);
0129     }
0130     return has;
0131 }
0132 }
0133 
0134 /* -----------------------------------------------------------------
0135  * local variables:
0136  * eval: (load-file "../../rapidsvn-dev.el")
0137  * end:
0138  */