changeset 41658:ec37db02fc72

diff: make `hg diff --root=subrepo` work The root prefix is currently stripped before adding the subrepo prefix. It seems to me that if you run `hg diff --root=subrepo` and a subrepo/ path is visited (say "subrepo/foo"), then the path generated for the diff would initially be just "foo" and we then fail (if the developer warning is active) to strip the "subrepo/" from the path. It seems like we should first add the prefix in order to produce a path that's relative to the top-level repo, and then we can remove the root prefix from that. There are no tests for this, it seems, and I don't care enough to add one. Differential Revision: https://phab.mercurial-scm.org/D5895
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 06 Feb 2019 23:56:59 -0800
parents d4c9eebdd72d
children d8cdd5320f75
files mercurial/logcmdutil.py
diffstat 1 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/logcmdutil.py	Wed Feb 06 23:12:56 2019 -0800
+++ b/mercurial/logcmdutil.py	Wed Feb 06 23:56:59 2019 -0800
@@ -66,6 +66,8 @@
     else:
         relroot = ''
     copysourcematch = None
+    def compose(f, g):
+        return lambda x: f(g(x))
     def pathfn(f):
         return posixpath.join(prefix, f)
     if relroot != '':
@@ -84,11 +86,12 @@
 
         checkroot = (repo.ui.configbool('devel', 'all-warnings') or
                      repo.ui.configbool('devel', 'check-relroot'))
-        def pathfn(f):
+        def relrootpathfn(f):
             if checkroot and not f.startswith(relroot):
                 raise AssertionError(
                     "file %s doesn't start with relroot %s" % (f, relroot))
-            return posixpath.join(prefix, f[len(relroot):])
+            return f[len(relroot):]
+        pathfn = compose(relrootpathfn, pathfn)
 
     if stat:
         diffopts = diffopts.copy(context=0, noprefix=False)