Mercurial > hg
changeset 24417:f2e1e097cda1
patch.diff: add support for diffs relative to a subdirectory
For now this implementation is pretty naive -- it filters out files right
before passing them into trydiff. In upcoming patches we'll add some more
smarts.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Tue, 17 Mar 2015 13:41:24 -0700 |
parents | f07047a506d1 |
children | 0e41f110e69e |
files | mercurial/patch.py |
diffstat | 1 files changed, 19 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/patch.py Tue Mar 17 12:59:41 2015 -0700 +++ b/mercurial/patch.py Tue Mar 17 13:41:24 2015 -0700 @@ -2059,7 +2059,7 @@ return mdiff.diffopts(**buildopts) def diff(repo, node1=None, node2=None, match=None, changes=None, opts=None, - losedatafn=None, prefix=''): + losedatafn=None, prefix='', relroot=''): '''yields diff of changes to files between two nodes, or node and working directory. @@ -2076,7 +2076,9 @@ prefix is a filename prefix that is prepended to all filenames on display (used for subrepos). - ''' + + relroot, if not empty, must be normalized with a trailing /. Any match + patterns that fall outside it will be ignored.''' if opts is None: opts = mdiff.defaultopts @@ -2120,9 +2122,23 @@ if opts.git or opts.upgrade: copy = copies.pathcopies(ctx1, ctx2) + if relroot is not None: + # XXX this would ideally be done in the matcher, but that is generally + # meant to 'or' patterns, not 'and' them. In this case we need to 'and' + # all the patterns from the matcher with relroot. + def filterrel(l): + return [f for f in l if f.startswith(relroot)] + modified = filterrel(modified) + added = filterrel(added) + removed = filterrel(removed) + # filter out copies where either side isn't inside the relative root + copy = dict(((dst, src) for (dst, src) in copy.iteritems() + if dst.startswith(relroot) + and src.startswith(relroot))) + def difffn(opts, losedata): return trydiff(repo, revs, ctx1, ctx2, modified, added, removed, - copy, getfilectx, opts, losedata, prefix, '') + copy, getfilectx, opts, losedata, prefix, relroot) if opts.upgrade and not opts.git: try: def losedata(fn):