# HG changeset patch # User Siddharth Agarwal # Date 1426630000 25200 # Node ID a0004402776b13ede193d4682b0e116dfd809795 # Parent 98d9d33dfd9571d7ec7d5fb014e52eb70d3dc0fd 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. diff -r 98d9d33dfd95 -r a0004402776b mercurial/cmdutil.py --- 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: