PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/kdesdk-4.8.97/cervisia/cvsservice/repository.cpp

#
C++ | 271 lines | 161 code | 58 blank | 52 comment | 12 complexity | 37f82c566fb4f70e59da14ab8ddbdabd MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-2.0, GPL-2.0, CC-BY-SA-3.0
  1. /*
  2. * Copyright (c) 2002-2004 Christian Loose <christian.loose@kdemail.net>
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Library General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Library General Public License
  15. * along with this program; see the file COPYING. If not, write to
  16. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. * Boston, MA 02110-1301, USA.
  18. *
  19. */
  20. #include "repository.h"
  21. #include <qdir.h>
  22. #include <qfile.h>
  23. #include <qstring.h>
  24. //Added by qt3to4:
  25. #include <QTextStream>
  26. #include <ksharedconfig.h>
  27. #include <kdirwatch.h>
  28. #include <kstandarddirs.h>
  29. #include <kglobal.h>
  30. #include "sshagent.h"
  31. #include <QDBusConnection>
  32. #include <repositoryadaptor.h>
  33. #include <kconfiggroup.h>
  34. struct Repository::Private
  35. {
  36. Private() : compressionLevel(0) {}
  37. QString configFileName;
  38. QString workingCopy;
  39. QString location;
  40. QString client;
  41. QString rsh;
  42. QString server;
  43. int compressionLevel;
  44. bool retrieveCvsignoreFile;
  45. void readConfig();
  46. void readGeneralConfig();
  47. };
  48. Repository::Repository()
  49. : QObject()
  50. , d(new Private)
  51. {
  52. d->readGeneralConfig();
  53. new RepositoryAdaptor(this );
  54. QDBusConnection::sessionBus().registerObject("/CvsRepository", this);
  55. // other cvsservice instances might change the configuration file
  56. // so we watch it for changes
  57. d->configFileName = KStandardDirs::locate("config", "cvsservicerc");
  58. KDirWatch* fileWatcher = new KDirWatch(this);
  59. connect(fileWatcher, SIGNAL(dirty(QString)),
  60. this, SLOT(slotConfigDirty(QString)));
  61. fileWatcher->addFile(d->configFileName);
  62. }
  63. Repository::Repository(const QString& repository)
  64. : QObject()
  65. , d(new Private)
  66. {
  67. d->location = repository;
  68. d->readGeneralConfig();
  69. d->readConfig();
  70. //TODO verify it before : DCOPObject()
  71. new RepositoryAdaptor(this );
  72. QDBusConnection::sessionBus().registerObject("/CvsRepository", this);
  73. // other cvsservice instances might change the configuration file
  74. // so we watch it for changes
  75. d->configFileName = KStandardDirs::locate("config", "cvsservicerc");
  76. KDirWatch* fileWatcher = new KDirWatch(this);
  77. connect(fileWatcher, SIGNAL(dirty(QString)),
  78. this, SLOT(slotConfigDirty(QString)));
  79. fileWatcher->addFile(d->configFileName);
  80. }
  81. Repository::~Repository()
  82. {
  83. delete d;
  84. }
  85. QString Repository::cvsClient() const
  86. {
  87. QString client(d->client);
  88. // suppress reading of the '.cvsrc' file
  89. client += " -f";
  90. // we don't need the command line option if there is no compression level set
  91. if( d->compressionLevel > 0 )
  92. {
  93. client += " -z" + QString::number(d->compressionLevel) + ' ';
  94. }
  95. return client;
  96. }
  97. QString Repository::clientOnly() const
  98. {
  99. return d->client;
  100. }
  101. QString Repository::rsh() const
  102. {
  103. return d->rsh;
  104. }
  105. QString Repository::server() const
  106. {
  107. return d->server;
  108. }
  109. bool Repository::setWorkingCopy(const QString& dirName)
  110. {
  111. const QFileInfo fi(dirName);
  112. const QString path = fi.absoluteFilePath();
  113. // is this really a cvs-controlled directory?
  114. const QFileInfo cvsDirInfo(path + "/CVS");
  115. if( !cvsDirInfo.exists() || !cvsDirInfo.isDir() ||
  116. !QFile::exists( cvsDirInfo.filePath() + "/Entries" ) ||
  117. !QFile::exists( cvsDirInfo.filePath() + "/Repository" ) ||
  118. !QFile::exists( cvsDirInfo.filePath() + "/Root" ) )
  119. return false;
  120. d->workingCopy = path;
  121. d->location.clear();
  122. // determine path to the repository
  123. QFile rootFile(path + "/CVS/Root");
  124. if( rootFile.open(QIODevice::ReadOnly) )
  125. {
  126. QTextStream stream(&rootFile);
  127. d->location = stream.readLine();
  128. }
  129. rootFile.close();
  130. // add identities (ssh-add) to ssh-agent
  131. // TODO CL make sure this is called only once
  132. if( d->location.contains(":ext:", Qt::CaseInsensitive) )
  133. {
  134. SshAgent ssh;
  135. ssh.addSshIdentities();
  136. }
  137. QDir::setCurrent(path);
  138. d->readConfig();
  139. return true;
  140. }
  141. QString Repository::workingCopy() const
  142. {
  143. return d->workingCopy;
  144. }
  145. QString Repository::location() const
  146. {
  147. return d->location;
  148. }
  149. bool Repository::retrieveCvsignoreFile() const
  150. {
  151. return d->retrieveCvsignoreFile;
  152. }
  153. void Repository::slotConfigDirty(const QString& fileName)
  154. {
  155. if( fileName == d->configFileName )
  156. {
  157. // reread the configuration data from disk
  158. KGlobal::config()->reparseConfiguration();
  159. d->readConfig();
  160. }
  161. }
  162. void Repository::Private::readGeneralConfig()
  163. {
  164. // get path to cvs client program
  165. KConfigGroup cg(KGlobal::config(), "General");
  166. client = cg.readPathEntry("CVSPath", "cvs");
  167. }
  168. void Repository::Private::readConfig()
  169. {
  170. KSharedConfig::Ptr config = KGlobal::config();
  171. // Sometimes the location can be unequal to the entry in the CVS/Root.
  172. //
  173. // This can happen when the checkout was done with a repository name
  174. // like :pserver:user@cvs.kde.org:/home/kde. When cvs then saves the
  175. // name into the .cvspass file, it adds the default cvs port to it like
  176. // this :pserver:user@cvs.kde.org:2401/home/kde. This name is then also
  177. // used for the configuration group.
  178. //
  179. // In order to be able to read this group, we then have to manually add
  180. // the port number to it.
  181. QString repositoryGroup = QLatin1String("Repository-") + location;
  182. if( !config->hasGroup(repositoryGroup) )
  183. {
  184. // find the position of the first path separator
  185. const int insertPos = repositoryGroup.indexOf('/');
  186. if( insertPos > 0 )
  187. {
  188. // add port to location
  189. // (1) :pserver:user@hostname.com:/path
  190. if( repositoryGroup.at(insertPos - 1) == ':' )
  191. repositoryGroup.insert(insertPos, "2401");
  192. // (2) :pserver:user@hostname.com/path
  193. else
  194. repositoryGroup.insert(insertPos, ":2401");
  195. }
  196. }
  197. KConfigGroup group = config->group(repositoryGroup);
  198. // should we retrieve the CVSROOT/cvsignore file from the cvs server?
  199. retrieveCvsignoreFile = group.readEntry("RetrieveCvsignore", false);
  200. // see if there is a specific compression level set for this repository
  201. compressionLevel = group.readEntry("Compression", -1);
  202. // use default global compression level instead?
  203. if( compressionLevel < 0 )
  204. {
  205. KConfigGroup cs(config, "General");
  206. compressionLevel = cs.readEntry("Compression", 0);
  207. }
  208. // get remote shell client to access the remote repository
  209. rsh = group.readPathEntry("rsh", QString());
  210. // get program to start on the server side
  211. server = group.readEntry("cvs_server");
  212. }
  213. #include "repository.moc"