1. Graham Helliwell
  2. thg


Graham Helliwell  committed 2c57972

Make add subrepository behaviour respect the paths set on the existing subrepository where possible

  • Participants
  • Parent commits 403d314
  • Branches default

Comments (0)

Files changed (3)

File tortoisehg/hgqt/hgrcutil.py

View file
 from tortoisehg.hgqt.i18n import _
 from tortoisehg.hgqt import qtlib
-from tortoisehg.util import wconfig
+from tortoisehg.util import wconfig, paths
 def loadIniFile(rcpath, parent=None):
     for fn in rcpath:
     return fn, wconfig.readfile(fn)
+def getRepositorySyncPaths(path):
+    fn, cfg = loadIniFile([path + "/.hg/hgrc"])
+    if 'paths' in cfg:
+        if 'default' in cfg['paths']: yield cfg['paths']['default']
+        for alias in cfg['paths']:
+            if cfg['paths'][alias]: yield cfg['paths'][alias]
 def setConfigValue(rcfilepath, cfgpath, value):
     Set a value on a config file, such as an hgrc or a .ini file

File tortoisehg/hgqt/reporegistry.py

View file
 # GNU General Public License version 2 or any later version.
 import os
+import posixpath
+import urlparse
 from mercurial import commands, error, hg, ui, util
 from tortoisehg.util import hglib, paths
 from tortoisehg.hgqt.i18n import _
-from tortoisehg.hgqt import qtlib, repotreemodel, clone, settings
+from tortoisehg.hgqt import qtlib, repotreemodel, clone, settings, hgrcutil
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
     dir = os.path.dirname(unicode(s.fileName()))
     return dir + '/' + 'thg-reporegistry.xml'
+def getRelativeSyncPath(root, sroot, default=None):
+    """Returns a relative URL for reaching sroot from root. If none exists, returns an absolute URL. If no absolute URL exists, returns the given default. """
+    parentpaths = hgrcutil.getRepositorySyncPaths(root)
+    subpaths = hgrcutil.getRepositorySyncPaths(sroot)
+    for parentpath in parentpaths:
+        for subpath in subpaths:
+            if parentpath and subpath:
+                relativeurl = paths.getRelativeUrl(parentpath, subpath)
+                if relativeurl: return relativeurl
+    try:
+        return hgrcutil.getRepositorySyncPaths(sroot).next()
+    except StopIteration:
+        return default
 class RepoTreeView(QTreeView):
     showMessage = pyqtSignal(QString)
                     # Append the new subrepo to the end of the .hgsub file
+                    syncPath = getRelativeSyncPath(root, sroot, srelroot)
                     lines.append(hglib.fromunicode('%s = %s'
-                                                   % (srelroot, srelroot)))
+                                                   % (srelroot, syncPath)))
                     lines = [line.strip(linesep) for line in lines]
                     # and update the .hgsub file

File tortoisehg/util/paths.py

View file
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2, incorporated herein by reference.
+import posixpath
+import urlparse
+from tortoisehg.hgqt import hgrcutil
     from config import icon_path, bin_path, license_path, locale_path
     global locale_path
     return locale_path or os.path.join(get_prog_root(), 'locale')
+def getRelativeUrl(base, target):
+    base=urlparse.urlparse(base)
+    target=urlparse.urlparse(target)
+    if base.netloc != target.netloc:
+        return None
+    base_dir='.'+posixpath.dirname(base.path)
+    target='.'+target.path
+    return posixpath.relpath(target,start=base_dir)
 if os.name == 'nt':
     import _winreg
     import win32net