Advertisement
Guest User

Perforce-VCS-plugin-fix-top-level-directory-detectio.patch

a guest
Sep 10th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 10.82 KB | None | 0 0
  1. From c111318c78acb2b7ddd41533de3577fa7dc64b1d Mon Sep 17 00:00:00 2001
  2. From: Alexander Drozdov <adrozdoff@gmail.com>
  3. Date: Tue, 10 Sep 2013 17:33:55 +1100
  4. Subject: [PATCH] Perforce VCS plugin: fix top-level directory detection
  5.  
  6. ---
  7. src/plugins/perforce/perforcechecker.cpp        | 21 ++++++++-
  8.  src/plugins/perforce/perforcechecker.h          |  5 ++-
  9.  src/plugins/perforce/perforceconstants.h        |  2 +-
  10.  src/plugins/perforce/perforceplugin.cpp         | 57 ++++++++++++++++++++-----
  11.  src/plugins/perforce/perforceplugin.h           | 16 ++++++-
  12.  src/plugins/perforce/perforceversioncontrol.cpp |  2 +-
  13.  6 files changed, 86 insertions(+), 17 deletions(-)
  14.  
  15. diff --git a/src/plugins/perforce/perforcechecker.cpp b/src/plugins/perforce/perforcechecker.cpp
  16. index 5971c00..b9b0395 100644
  17. --- a/src/plugins/perforce/perforcechecker.cpp
  18. +++ b/src/plugins/perforce/perforcechecker.cpp
  19. @@ -28,6 +28,7 @@
  20.  ****************************************************************************/
  21.  
  22.  #include "perforcechecker.h"
  23. +#include "perforceconstants.h"
  24.  
  25.  #include <utils/qtcassert.h>
  26.  #include <utils/synchronousprocess.h>
  27. @@ -78,7 +79,8 @@ void PerforceChecker::resetOverrideCursor()
  28.  
  29.  void PerforceChecker::start(const QString &binary,
  30.                              const QStringList &basicArgs,
  31. -                            int timeoutMS)
  32. +                            int timeoutMS,
  33. +                            const QString &workingDirectory)
  34.  {
  35.      if (isRunning()) {
  36.          emitFailed(QLatin1String("Internal error: process still running"));
  37. @@ -91,6 +93,15 @@ void PerforceChecker::start(const QString &binary,
  38.      m_binary = binary;
  39.      QStringList args = basicArgs;
  40.      args << QLatin1String("client") << QLatin1String("-o");
  41. +
  42. +    if (Perforce::Constants::debug)
  43. +        qDebug() << "PerforceChecker::start: [" << workingDirectory << "]" << m_binary << args;
  44. +
  45. +    if (!workingDirectory.isEmpty())
  46. +    {
  47. +        m_process.setWorkingDirectory(workingDirectory);
  48. +    }
  49. +
  50.      m_process.start(m_binary, args);
  51.      m_process.closeWriteChannel();
  52.      // Timeout handling
  53. @@ -105,6 +116,11 @@ void PerforceChecker::start(const QString &binary,
  54.      }
  55.  }
  56.  
  57. +bool PerforceChecker::waitForFinished(int msec)
  58. +{
  59. +    return m_process.waitForFinished(msec);
  60. +}
  61. +
  62.  void PerforceChecker::slotTimeOut()
  63.  {
  64.      if (!isRunning())
  65. @@ -169,6 +185,9 @@ static inline QString clientRootFromOutput(const QString &in)
  66.  
  67.  void PerforceChecker::parseOutput(const QString &response)
  68.  {
  69. +    if (Perforce::Constants::debug)
  70. +        qDebug() << "PerforceChecker::parseOutput: " << response;
  71. +
  72.      if (!response.contains(QLatin1String("View:")) && !response.contains(QLatin1String("//depot/"))) {
  73.          emitFailed(tr("The client does not seem to contain any mapped files."));
  74.          return;
  75. diff --git a/src/plugins/perforce/perforcechecker.h b/src/plugins/perforce/perforcechecker.h
  76. index e466250..aada848 100644
  77. --- a/src/plugins/perforce/perforcechecker.h
  78. +++ b/src/plugins/perforce/perforcechecker.h
  79. @@ -50,10 +50,13 @@ public:
  80.  public slots:
  81.      void start(const QString &binary,
  82.                 const QStringList &basicArgs = QStringList(),
  83. -               int timeoutMS = -1);
  84. +               int timeoutMS = -1,
  85. +               const QString &workingDirectory = QString());
  86.  
  87.      bool isRunning() const;
  88.  
  89. +    bool waitForFinished(int msec = -1);
  90. +
  91.      bool useOverideCursor() const;
  92.      void setUseOverideCursor(bool v);
  93.  
  94. diff --git a/src/plugins/perforce/perforceconstants.h b/src/plugins/perforce/perforceconstants.h
  95. index 316fc24..1f8c2a1 100644
  96. --- a/src/plugins/perforce/perforceconstants.h
  97. +++ b/src/plugins/perforce/perforceconstants.h
  98. @@ -55,7 +55,7 @@ const char SUBMIT_CURRENT[] = "Perforce.SubmitCurrentLog";
  99.  const char DIFF_SELECTED[] = "Perforce.DiffSelectedFilesInLog";
  100.  const char SUBMIT_MIMETYPE[] = "text/vnd.qtcreator.p4.submit";
  101.  
  102. -enum { debug = 0 };
  103. +enum { debug = 1 };
  104.  
  105.  } // Constants
  106.  } // Perforce
  107. diff --git a/src/plugins/perforce/perforceplugin.cpp b/src/plugins/perforce/perforceplugin.cpp
  108. index 8fd5957..1f9480d 100644
  109. --- a/src/plugins/perforce/perforceplugin.cpp
  110. +++ b/src/plugins/perforce/perforceplugin.cpp
  111. @@ -824,7 +824,11 @@ bool PerforcePlugin::managesDirectory(const QString &directory, QString *topLeve
  112.      const bool rc = managesDirectoryFstat(directory);
  113.      if (topLevel) {
  114.          if (rc)
  115. +        {
  116. +            if (Perforce::Constants::debug)
  117. +                qDebug() << "Top Level: " << m_settings.topLevelSymLinkTarget();
  118.              *topLevel = m_settings.topLevelSymLinkTarget();
  119. +        }
  120.          else
  121.              topLevel->clear();
  122.      }
  123. @@ -834,28 +838,48 @@ bool PerforcePlugin::managesDirectory(const QString &directory, QString *topLeve
  124.  bool PerforcePlugin::managesDirectoryFstat(const QString &directory)
  125.  {
  126.      if (!m_settings.isValid())
  127. +    {
  128. +        if (Perforce::Constants::debug)
  129. +            qDebug() << "Settings invalid";
  130.          return false;
  131. +    }
  132.      // Cached?
  133.      const ManagedDirectoryCache::const_iterator cit = m_managedDirectoryCache.constFind(directory);
  134.      if (cit != m_managedDirectoryCache.constEnd())
  135. -        return cit.value();
  136. +    {
  137. +        const DirectoryCacheEntry &entry = cit.value();
  138. +        if (Perforce::Constants::debug)
  139. +            qDebug() << "Directory: " << directory << " is cached and managed: " << entry.isManaged;
  140. +
  141. +        setNewTopLevel(entry.topLevel);
  142. +
  143. +        return entry.isManaged;
  144. +    }
  145.      // Determine value and insert into cache
  146.      bool managed = false;
  147.      do {
  148.          // Quick check: Must be at or below top level and not "../../other_path"
  149.          const QStringList relativeDirArgs = m_settings.relativeToTopLevelArguments(directory);
  150.          if (!relativeDirArgs.empty() && relativeDirArgs.front().startsWith(QLatin1String("..")))
  151. -            break;
  152. +        {
  153. +            if (Perforce::Constants::debug)
  154. +                qDebug() << "Directory " << directory << " is a relative path to current top level dir [" << relativeDirArgs << "], try find new top level.";
  155. +            getTopLevel(directory, true);
  156. +        }
  157.          // Is it actually managed by perforce?
  158.          QStringList args;
  159.          args << QLatin1String("fstat") << QLatin1String("-m1") << perforceRelativeFileArguments(relativeDirArgs);
  160.          const PerforceResponse result = runP4Cmd(m_settings.topLevel(), args,
  161.                                                   RunFullySynchronous);
  162. +
  163. +        if (Perforce::Constants::debug)
  164. +            qDebug() << "Perforce result:\n" << result.stdOut << "\n---\n" << result.stdErr << "\n---\n" << result.message;
  165. +
  166.          managed = result.stdOut.contains(QLatin1String("depotFile"))
  167.                    || result.stdErr.contains(QLatin1String("... - no such file(s)"));
  168.      } while (false);
  169.  
  170. -    m_managedDirectoryCache.insert(directory, managed);
  171. +    m_managedDirectoryCache.insert(directory, DirectoryCacheEntry(managed, m_settings.topLevel()));
  172.      return managed;
  173.  }
  174.  
  175. @@ -1489,12 +1513,7 @@ PerforceVersionControl *PerforcePlugin::perforceVersionControl() const
  176.  
  177.  void PerforcePlugin::slotTopLevelFound(const QString &t)
  178.  {
  179. -    m_settings.setTopLevel(t);
  180. -    const QString msg = tr("Perforce repository: %1").
  181. -                        arg(QDir::toNativeSeparators(t));
  182. -    VcsBase::VcsBaseOutputWindow::instance()->appendSilently(msg);
  183. -    if (Perforce::Constants::debug)
  184. -        qDebug() << "P4: " << t;
  185. +    setNewTopLevel(t);
  186.  }
  187.  
  188.  void PerforcePlugin::slotTopLevelFailed(const QString &errorMessage)
  189. @@ -1504,7 +1523,7 @@ void PerforcePlugin::slotTopLevelFailed(const QString &errorMessage)
  190.          qDebug() << errorMessage;
  191.  }
  192.  
  193. -void PerforcePlugin::getTopLevel()
  194. +void PerforcePlugin::getTopLevel(const QString &workingDirectory, bool isSync)
  195.  {
  196.      // Run a new checker
  197.      if (m_settings.p4BinaryPath().isEmpty())
  198. @@ -1514,7 +1533,23 @@ void PerforcePlugin::getTopLevel()
  199.      connect(checker, SIGNAL(failed(QString)), checker, SLOT(deleteLater()));
  200.      connect(checker, SIGNAL(succeeded(QString)), this, SLOT(slotTopLevelFound(QString)));
  201.      connect(checker, SIGNAL(succeeded(QString)),checker, SLOT(deleteLater()));
  202. -    checker->start(m_settings.p4BinaryPath(), m_settings.commonP4Arguments(QString()), 30000);
  203. +    checker->start(m_settings.p4BinaryPath(), m_settings.commonP4Arguments(QString()), 30000, workingDirectory);
  204. +
  205. +    if (isSync)
  206. +        checker->waitForFinished();
  207. +}
  208. +
  209. +void PerforcePlugin::setNewTopLevel(const QString &newTopLevel)
  210. +{
  211. +    if (m_settings.topLevel() != newTopLevel)
  212. +    {
  213. +        m_settings.setTopLevel(newTopLevel);
  214. +        const QString msg = tr("Perforce repository: %1").
  215. +                            arg(QDir::toNativeSeparators(newTopLevel));
  216. +        VcsBase::VcsBaseOutputWindow::instance()->appendSilently(msg);
  217. +        if (Perforce::Constants::debug)
  218. +            qDebug() << "P4: " << newTopLevel;
  219. +    }
  220.  }
  221.  
  222.  #ifdef WITH_TESTS
  223. diff --git a/src/plugins/perforce/perforceplugin.h b/src/plugins/perforce/perforceplugin.h
  224. index 8eeb1e2..8e08500 100644
  225. --- a/src/plugins/perforce/perforceplugin.h
  226. +++ b/src/plugins/perforce/perforceplugin.h
  227. @@ -146,7 +146,18 @@ protected:
  228.  
  229.  
  230.  private:
  231. -    typedef QHash<QString, bool> ManagedDirectoryCache;
  232. +    struct DirectoryCacheEntry
  233. +    {
  234. +        DirectoryCacheEntry(bool isManaged, const QString &topLevel)
  235. +            : isManaged(isManaged),
  236. +              topLevel(topLevel)
  237. +        {}
  238. +
  239. +        bool    isManaged;
  240. +        QString topLevel;
  241. +    };
  242. +
  243. +    typedef QHash<QString, DirectoryCacheEntry> ManagedDirectoryCache;
  244.  
  245.      Core::IEditor *showOutputInEditor(const QString& title, const QString output,
  246.                                        int editorType, const QString &source,
  247. @@ -193,7 +204,8 @@ private:
  248.      bool isCommitEditorOpen() const;
  249.      QSharedPointer<Utils::TempFileSaver> createTemporaryArgumentFile(const QStringList &extraArgs,
  250.                                                                       QString *errorString) const;
  251. -    void getTopLevel();
  252. +    void getTopLevel(const QString &workingDirectory = QString(), bool isSync = false);
  253. +    void setNewTopLevel(const QString &newTopLevel);
  254.      QString pendingChangesData();
  255.  
  256.      void updateCheckout(const QString &workingDir = QString(),
  257. diff --git a/src/plugins/perforce/perforceversioncontrol.cpp b/src/plugins/perforce/perforceversioncontrol.cpp
  258. index 19303a6..ad4f35b 100644
  259. --- a/src/plugins/perforce/perforceversioncontrol.cpp
  260. +++ b/src/plugins/perforce/perforceversioncontrol.cpp
  261. @@ -178,7 +178,7 @@ bool PerforceVersionControl::managesDirectory(const QString &directory, QString
  262.          QDebug nsp = qDebug().nospace();
  263.          nsp << "managesDirectory" << directory << rc;
  264.          if (topLevel)
  265. -            nsp << topLevel;
  266. +            nsp << *topLevel;
  267.      }
  268.      return rc;
  269.  }
  270. --
  271. 1.8.3.msysgit.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement