Angel Ezquerra committed 1df0f23

reporegistry: improve accuracy of subrepo detection when adding a repository (refs #1672)

Up until now adding a subrepo that was contained inside another subrepo would
always mark the inner repo as a subrepo. This is not always true.

With this patch, we also check whether the added subrepo is _currently_ a
subrepo of the outer repository. We respect the "showNetworkSubrepos" flag
(i.e. we'll only check if an added repo is a subrepo if the repo is local
or if the showNetworkSubrepos flag is set).

Note that this does not a full fix issue #1672, because we only perform this
check once, when adding the repo, and because we only check whether the repo
is _currently_ a subrepo of the outer repo. However I think that it is an
improvement over the old behavior.

  • Participants
  • Parent commits 909c9cf
  • Branches stable

Comments (0)

Files changed (1)


 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
+from mercurial import util, hg, ui
 from tortoisehg.util import hglib, paths
 from tortoisehg.hgqt.i18n import _
 from tortoisehg.hgqt import qtlib
         if row < 0:
             row = rgi.childCount()
-        # Is the root of the repo that we want to add a subrepo contained
-        # within a repo or subrepo? If so, assume it is an hg subrepo
-        itemIsSubrepo = not paths.find_root(os.path.dirname(root)) is None
+        # Check whether the repo that we are adding is a subrepo
+        # This check could be expensive, particularly for network repositories
+        # Thus, only perform this check on network repos if the showNetworkSubrepos
+        # flag is set
+        itemIsSubrepo = False
+        if self.showNetworkSubrepos \
+                or not paths.netdrive_status(root):
+            outerrepopath = paths.find_root(os.path.dirname(root))
+            if outerrepopath:
+                # Check whether repo we are adding is a subrepo of
+                # its containing (outer) repo
+                # This check is currently quite imperfect, since it
+                # only checks the current repo revision
+                outerrepo = hg.repository(ui.ui(), path=outerrepopath)
+                relroot = util.normpath(root[len(outerrepopath)+1:])
+                if relroot in outerrepo['.'].substate:
+                    itemIsSubrepo = True
         self.beginInsertRows(grp, row, row)
         if itemIsSubrepo:
             ri = SubrepoItem(root)