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 // svncpp
0032 #include "log_entry.h"
0033 #include "helper.h"
0034 #include "pool.h"
0035 #include "stringarray.h"
0036 
0037 // subversion api
0038 #include "svn_compat.h"
0039 #include "svn_time.h"
0040 
0041 #include <QDataStream>
0042 
0043 namespace svn
0044 {
0045 
0046 LogEntry::LogEntry()
0047     : revision(-1)
0048     , date(0)
0049 {
0050 }
0051 
0052 LogEntry::LogEntry(svn_log_entry_t *log_entry, const StringArray &excludeList)
0053     : revision(-1)
0054     , date(0)
0055 {
0056     Pool pool;
0057     const char *author_ = nullptr;
0058     const char *date_ = nullptr;
0059     const char *message_ = nullptr;
0060     svn_compat_log_revprops_out(&author_, &date_, &message_, log_entry->revprops);
0061 
0062     author = author_ == nullptr ? QString() : QString::fromUtf8(author_);
0063     message = message_ == nullptr ? QString() : QString::fromUtf8(message_);
0064     apr_time_t apr_time = 0;
0065     if (date_) {
0066         svn_error_t *err = svn_time_from_cstring(&apr_time, date_, pool);
0067         svn_error_clear(err); // clear possible error
0068     }
0069     date = apr_time;
0070     revision = log_entry->revision;
0071     if (log_entry->changed_paths2) {
0072         bool blocked = false;
0073         for (apr_hash_index_t *hi = apr_hash_first(pool, log_entry->changed_paths2); hi != nullptr; hi = apr_hash_next(hi)) {
0074             const void *pv;
0075             void *val;
0076             blocked = false;
0077             apr_hash_this(hi, &pv, nullptr, &val);
0078             svn_log_changed_path2_t *log_item = reinterpret_cast<svn_log_changed_path2_t *>(val);
0079             const char *path = reinterpret_cast<const char *>(pv);
0080             QString _p(QString::fromUtf8(path));
0081             for (const QString &exclude : excludeList.data()) {
0082                 if (_p.startsWith(exclude)) {
0083                     blocked = true;
0084                     break;
0085                 }
0086             }
0087             if (!blocked) {
0088                 changedPaths.push_back(LogChangePathEntry(_p, log_item->action, QString::fromUtf8(log_item->copyfrom_path), log_item->copyfrom_rev));
0089             }
0090         }
0091     }
0092 }
0093 }
0094 
0095 SVNQT_EXPORT QDataStream &operator<<(QDataStream &s, const svn::LogEntry &r)
0096 {
0097     s << r.revision << r.author << r.message << r.changedPaths << r.date;
0098     return s;
0099 }
0100 
0101 SVNQT_EXPORT QDataStream &operator<<(QDataStream &s, const svn::LogChangePathEntry &r)
0102 {
0103     short ac = r.action;
0104     s << r.path << ac << r.copyFromPath << r.copyFromRevision << r.copyToPath << r.copyToRevision;
0105     return s;
0106 }
0107 
0108 SVNQT_EXPORT QDataStream &operator>>(QDataStream &s, svn::LogEntry &r)
0109 {
0110     s >> r.revision >> r.author >> r.message >> r.changedPaths >> r.date;
0111     return s;
0112 }
0113 
0114 SVNQT_EXPORT QDataStream &operator>>(QDataStream &s, svn::LogChangePathEntry &r)
0115 {
0116     short ac;
0117     s >> r.path >> ac >> r.copyFromPath >> r.copyFromRevision >> r.copyToPath >> r.copyToRevision;
0118     r.action = ac;
0119     return s;
0120 }