Patchwork [1,of,3,relative-diff] cmdutil.diffordiffstat: add support for diffs relative to a subdirectory

login
register
mail settings
Submitter Siddharth Agarwal
Date March 24, 2015, 12:36 a.m.
Message ID <f236bca9db2623e0a9a9.1427157394@devbig136.prn2.facebook.com>
Download mbox | patch
Permalink /patch/8224/
State Accepted
Commit a0004402776b13ede193d4682b0e116dfd809795
Headers show

Comments

Siddharth Agarwal - March 24, 2015, 12:36 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1426630000 25200
#      Tue Mar 17 15:06:40 2015 -0700
# Node ID f236bca9db2623e0a9a978639e51017d4b98e4a2
# Parent  811a1842cfe5f632145912d9bf2dc859e6ee3eeb
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.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -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: