Mercurial > hg
comparison mercurial/cmdutil.py @ 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 | 2bdd35ea0a03 |
children | 5b85a5bc5bbb |
comparison
equal
deleted
inserted
replaced
24430:98d9d33dfd95 | 24431:a0004402776b |
---|---|
1006 for seqno, rev in enumerate(revs): | 1006 for seqno, rev in enumerate(revs): |
1007 single(rev, seqno + 1, fp) | 1007 single(rev, seqno + 1, fp) |
1008 | 1008 |
1009 def diffordiffstat(ui, repo, diffopts, node1, node2, match, | 1009 def diffordiffstat(ui, repo, diffopts, node1, node2, match, |
1010 changes=None, stat=False, fp=None, prefix='', | 1010 changes=None, stat=False, fp=None, prefix='', |
1011 listsubrepos=False): | 1011 relative='', listsubrepos=False): |
1012 '''show diff or diffstat.''' | 1012 '''show diff or diffstat.''' |
1013 if fp is None: | 1013 if fp is None: |
1014 write = ui.write | 1014 write = ui.write |
1015 else: | 1015 else: |
1016 def write(s, **kw): | 1016 def write(s, **kw): |
1017 fp.write(s) | 1017 fp.write(s) |
1018 | 1018 |
1019 if relative: | |
1020 relroot = pathutil.canonpath(repo.root, repo.getcwd(), relative) | |
1021 else: | |
1022 relroot = '' | |
1023 if relroot != '': | |
1024 # XXX relative roots currently don't work if the root is within a | |
1025 # subrepo | |
1026 uirelroot = match.uipath(relroot) | |
1027 relroot += '/' | |
1028 for matchroot in match.files(): | |
1029 if not matchroot.startswith(relroot): | |
1030 ui.warn(_('warning: %s not inside relative root %s\n') % ( | |
1031 match.uipath(matchroot), uirelroot)) | |
1032 | |
1019 if stat: | 1033 if stat: |
1020 diffopts = diffopts.copy(context=0) | 1034 diffopts = diffopts.copy(context=0) |
1021 width = 80 | 1035 width = 80 |
1022 if not ui.plain(): | 1036 if not ui.plain(): |
1023 width = ui.termwidth() | 1037 width = ui.termwidth() |
1024 chunks = patch.diff(repo, node1, node2, match, changes, diffopts, | 1038 chunks = patch.diff(repo, node1, node2, match, changes, diffopts, |
1025 prefix=prefix) | 1039 prefix=prefix, relroot=relroot) |
1026 for chunk, label in patch.diffstatui(util.iterlines(chunks), | 1040 for chunk, label in patch.diffstatui(util.iterlines(chunks), |
1027 width=width, | 1041 width=width, |
1028 git=diffopts.git): | 1042 git=diffopts.git): |
1029 write(chunk, label=label) | 1043 write(chunk, label=label) |
1030 else: | 1044 else: |
1031 for chunk, label in patch.diffui(repo, node1, node2, match, | 1045 for chunk, label in patch.diffui(repo, node1, node2, match, |
1032 changes, diffopts, prefix=prefix): | 1046 changes, diffopts, prefix=prefix, |
1047 relroot=relroot): | |
1033 write(chunk, label=label) | 1048 write(chunk, label=label) |
1034 | 1049 |
1035 if listsubrepos: | 1050 if listsubrepos: |
1036 ctx1 = repo[node1] | 1051 ctx1 = repo[node1] |
1037 ctx2 = repo[node2] | 1052 ctx2 = repo[node2] |