File indexing completed on 2024-05-12 05:44:23

0001 /***************************************************************************
0002  *   Copyright (C) 2006-2009 by Rajko Albrecht                             *
0003  *   ral@alwins-world.de                                                   *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (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         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
0019  ***************************************************************************/
0020 #include "fillcachethread.h"
0021 #include "tcontextlistener.h"
0022 
0023 #include "svnqt/cache/ReposConfig.h"
0024 #include "svnqt/cache/ReposLog.h"
0025 #include "svnqt/url.h"
0026 
0027 #include <KLocalizedString>
0028 
0029 // FillCacheThread
0030 FillCacheThread::FillCacheThread(QObject *_parent, const QString &aPath, bool startup)
0031     : SvnThread(_parent)
0032     , m_path(aPath)
0033     , m_startup(startup)
0034 {
0035 }
0036 
0037 FillCacheThread::~FillCacheThread()
0038 {
0039 }
0040 
0041 const QString &FillCacheThread::Path() const
0042 {
0043     return m_path;
0044 }
0045 
0046 const QString &FillCacheThread::reposRoot() const
0047 {
0048     return m_what;
0049 }
0050 
0051 void FillCacheThread::fillInfo()
0052 {
0053     m_what.clear();
0054     if (m_path.isEmpty()) {
0055         return;
0056     }
0057     svn::InfoEntry e;
0058     itemInfo(Path(), e);
0059     if (!e.reposRoot().isEmpty()) {
0060         m_what = e.reposRoot().toString();
0061     }
0062 }
0063 
0064 void FillCacheThread::run()
0065 {
0066     bool breakit = false;
0067     try {
0068         fillInfo();
0069 
0070         if (m_what.isEmpty() || svn::Url::isLocal(m_what)) {
0071             return;
0072         }
0073         if (m_startup && svn::cache::ReposConfig::self()->readEntry(m_what, "no_update_cache", false)) {
0074             m_SvnContextListener->contextNotify(i18n("Not filling log cache because it is disabled due setting for this repository."));
0075         } else {
0076             m_SvnContextListener->contextNotify(i18n("Filling log cache in background."));
0077 
0078             svn::cache::ReposLog rl(m_Svnclient, m_what);
0079             svn::Revision latestCache = rl.latestCachedRev();
0080             svn::Revision Head = rl.latestHeadRev();
0081             qlonglong i = latestCache.revnum();
0082             if (i < 0) {
0083                 i = 0;
0084             }
0085             qlonglong j = Head.revnum();
0086 
0087             qlonglong _max = j - i;
0088             qlonglong _cur = 0;
0089 
0090             emit fillCacheStatus(_cur, _max);
0091 
0092             if (i < j) {
0093                 for (; i < j; i += 200) {
0094                     _cur += 200;
0095                     rl.fillCache(i);
0096 
0097                     if (m_SvnContextListener->contextCancel()) {
0098                         m_SvnContextListener->contextNotify(i18n("Filling cache canceled."));
0099                         breakit = true;
0100                         break;
0101                     }
0102                     if (latestCache == rl.latestCachedRev()) {
0103                         break;
0104                     }
0105                     emit fillCacheStatus(_cur > _max ? _max : _cur, _max);
0106 
0107                     latestCache = rl.latestCachedRev();
0108                 }
0109                 if (latestCache.revnum() < Head.revnum()) {
0110                     rl.fillCache(Head.revnum());
0111                 }
0112                 i = Head.revnum();
0113                 m_SvnContextListener->contextNotify(i18n("Cache filled up to revision %1.", i));
0114             }
0115         }
0116     } catch (const svn::Exception &e) {
0117         m_SvnContextListener->contextNotify(e.msg());
0118     }
0119     if (!breakit) {
0120         m_SvnContextListener->contextNotify(i18n("Filling log cache in background finished."));
0121         emit fillCacheFinished();
0122     }
0123 }
0124 
0125 #include "moc_fillcachethread.cpp"