File indexing completed on 2024-05-12 17:16:23
0001 /*************************************************************************** 0002 * Copyright (C) 2008-2009 by Rajko Albrecht ral@alwins-world.de * 0003 * http://kdesvn.alwins-world.de/ * 0004 * * 0005 * This program is free software; you can redistribute it and/or * 0006 * modify it under the terms of the GNU Lesser General Public * 0007 * License as published by the Free Software Foundation; either * 0008 * version 2.1 of the License, or (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 0013 * Lesser General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU Lesser General Public * 0016 * License along with this program (in the file LGPL.txt); if not, * 0017 * write to the Free Software Foundation, Inc., 51 Franklin St, * 0018 * Fifth Floor, Boston, MA 02110-1301 USA * 0019 * * 0020 * This software consists of voluntary contributions made by many * 0021 * individuals. For exact contribution history, see the revision * 0022 * history and logs, available at http://kdesvn.alwins-world.de. * 0023 ***************************************************************************/ 0024 #include "diff_data.h" 0025 #include "exception.h" 0026 #include "helper.h" 0027 0028 #include <QFile> 0029 0030 #include <svn_io.h> 0031 #include <svn_path.h> 0032 0033 namespace svn 0034 { 0035 DiffData::DiffData(const Path &aTmpPath, const Path &_p1, const Revision &_r1, const Path &_p2, const Revision &_r2) 0036 : m_Pool() 0037 #if SVN_API_VERSION >= SVN_VERSION_CHECK(1,8,0) 0038 , m_outStream(new stream::SvnByteStream) 0039 , m_errStream(new stream::SvnByteStream) 0040 #else 0041 , m_tmpPath(aTmpPath) 0042 , m_outFile(nullptr) 0043 , m_errFile(nullptr) 0044 , m_outFileName(nullptr) 0045 , m_errFileName(nullptr) 0046 #endif 0047 , m_p1(_p1) 0048 , m_p2(_p2) 0049 , m_r1(_r1) 0050 , m_r2(_r2) 0051 , m_working_copy_present(false) 0052 , m_url_is_present(false) 0053 { 0054 #if SVN_API_VERSION >= SVN_VERSION_CHECK(1,8,0) 0055 Q_UNUSED(aTmpPath) 0056 #endif 0057 init(); 0058 } 0059 0060 void DiffData::init() 0061 { 0062 #if SVN_API_VERSION < SVN_VERSION_CHECK(1,8,0) 0063 svn_error_t *error; 0064 Pool scratchPool; 0065 error = svn_io_open_unique_file3(&m_outFile, &m_outFileName, 0066 m_tmpPath.path().toUtf8(), 0067 svn_io_file_del_on_pool_cleanup, m_Pool, scratchPool); 0068 0069 if (error != 0) { 0070 clean(); 0071 throw ClientException(error); 0072 } 0073 error = svn_io_open_unique_file3(&m_errFile, &m_errFileName, 0074 m_tmpPath.path().toUtf8(), 0075 svn_io_file_del_on_pool_cleanup, m_Pool, scratchPool); 0076 if (error != 0) { 0077 clean(); 0078 throw ClientException(error); 0079 } 0080 #endif 0081 if (svn_path_is_url(m_p1.cstr())) { 0082 m_url_is_present = true; 0083 } else { 0084 m_working_copy_present = true; 0085 } 0086 if (svn_path_is_url(m_p2.cstr())) { 0087 m_url_is_present = true; 0088 } else { 0089 m_working_copy_present = true; 0090 } 0091 0092 if (m_r1.revision()->kind == svn_opt_revision_unspecified && m_working_copy_present) { 0093 m_r1 = svn_opt_revision_base; 0094 } 0095 if (m_r2.revision()->kind == svn_opt_revision_unspecified) { 0096 m_r2 = m_working_copy_present ? svn_opt_revision_working : svn_opt_revision_head; 0097 } 0098 } 0099 0100 DiffData::~DiffData() 0101 { 0102 close(); 0103 } 0104 0105 void DiffData::close() 0106 { 0107 #if SVN_API_VERSION >= SVN_VERSION_CHECK(1,8,0) 0108 delete m_outStream; 0109 m_outStream = nullptr; 0110 delete m_errStream; 0111 m_errStream = nullptr; 0112 #else 0113 if (m_outFile) { 0114 svn_io_file_close(m_outFile, m_Pool); 0115 m_outFile = nullptr; 0116 } 0117 if (m_errFile) { 0118 svn_io_file_close(m_errFile, m_Pool); 0119 m_errFile = nullptr; 0120 } 0121 #endif 0122 } 0123 0124 QByteArray DiffData::content() 0125 { 0126 #if SVN_API_VERSION >= SVN_VERSION_CHECK(1,8,0) 0127 return m_outStream->content(); 0128 #else 0129 if (!m_outFileName) { 0130 return QByteArray(); 0131 } 0132 close(); 0133 QFile fi(QString::fromUtf8(m_outFileName)); 0134 if (!fi.open(QIODevice::ReadOnly)) { 0135 throw ClientException(QStringLiteral("%1 '%2'").arg(fi.errorString(), fi.fileName())); 0136 } 0137 0138 QByteArray res = fi.readAll(); 0139 fi.close(); 0140 return res; 0141 #endif 0142 } 0143 }