changeset 24431:a0004402776b

cmdutil.diffordiffstat: add support for diffs relative to a subdirectory It's possible that some of the match patterns are outside the relative root. We warn in that case. In upcoming patches we'll add tests for this.
author Siddharth Agarwal <sid0@fb.com>
date Tue, 17 Mar 2015 15:06:40 -0700
parents 98d9d33dfd95
children e22248f6d257
files mercurial/cmdutil.py
diffstat 1 files changed, 18 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Sun Mar 22 19:19:16 2015 -0700
+++ b/mercurial/cmdutil.py	Tue Mar 17 15:06:40 2015 -0700
@@ -1008,7 +1008,7 @@
 
 def diffordiffstat(ui, repo, diffopts, node1, node2, match,
                    changes=None, stat=False, fp=None, prefix='',
-                   listsubrepos=False):
+                   relative='', listsubrepos=False):
     '''show diff or diffstat.'''
     if fp is None:
         write = ui.write
@@ -1016,20 +1016,35 @@
         def write(s, **kw):
             fp.write(s)
 
+    if relative:
+        relroot = pathutil.canonpath(repo.root, repo.getcwd(), relative)
+    else:
+        relroot = ''
+    if relroot != '':
+        # XXX relative roots currently don't work if the root is within a
+        # subrepo
+        uirelroot = match.uipath(relroot)
+        relroot += '/'
+        for matchroot in match.files():
+            if not matchroot.startswith(relroot):
+                ui.warn(_('warning: %s not inside relative root %s\n') % (
+                    match.uipath(matchroot), uirelroot))
+
     if stat:
         diffopts = diffopts.copy(context=0)
         width = 80
         if not ui.plain():
             width = ui.termwidth()
         chunks = patch.diff(repo, node1, node2, match, changes, diffopts,
-                            prefix=prefix)
+                            prefix=prefix, relroot=relroot)
         for chunk, label in patch.diffstatui(util.iterlines(chunks),
                                              width=width,
                                              git=diffopts.git):
             write(chunk, label=label)
     else:
         for chunk, label in patch.diffui(repo, node1, node2, match,
-                                         changes, diffopts, prefix=prefix):
+                                         changes, diffopts, prefix=prefix,
+                                         relroot=relroot):
             write(chunk, label=label)
 
     if listsubrepos: