##// END OF EJS Templates
patch: replace "prefix" and "relroot" arguments by "pathfn" (API)...
Martin von Zweigbergk -
r41795:d4c9eebd default
parent child Browse files
Show More
@@ -294,7 +294,7 b' class basectx(object):'
294 294 listsubrepos=listsubrepos, badfn=badfn)
295 295
296 296 def diff(self, ctx2=None, match=None, changes=None, opts=None,
297 losedatafn=None, prefix='', relroot='', copy=None,
297 losedatafn=None, pathfn=None, copy=None,
298 298 copysourcematch=None, hunksfilterfn=None):
299 299 """Returns a diff generator for the given contexts and matcher"""
300 300 if ctx2 is None:
@@ -302,9 +302,8 b' class basectx(object):'
302 302 if ctx2 is not None:
303 303 ctx2 = self._repo[ctx2]
304 304 return patch.diff(self._repo, ctx2, self, match=match, changes=changes,
305 opts=opts, losedatafn=losedatafn, prefix=prefix,
306 relroot=relroot, copy=copy,
307 copysourcematch=copysourcematch,
305 opts=opts, losedatafn=losedatafn, pathfn=pathfn,
306 copy=copy, copysourcematch=copysourcematch,
308 307 hunksfilterfn=hunksfilterfn)
309 308
310 309 def dirs(self):
@@ -9,6 +9,7 b' from __future__ import absolute_import'
9 9
10 10 import itertools
11 11 import os
12 import posixpath
12 13
13 14 from .i18n import _
14 15 from .node import (
@@ -65,6 +66,8 b' def diffordiffstat(ui, repo, diffopts, n'
65 66 else:
66 67 relroot = ''
67 68 copysourcematch = None
69 def pathfn(f):
70 return posixpath.join(prefix, f)
68 71 if relroot != '':
69 72 # XXX relative roots currently don't work if the root is within a
70 73 # subrepo
@@ -79,14 +82,22 b' def diffordiffstat(ui, repo, diffopts, n'
79 82 match = matchmod.intersectmatchers(match, relrootmatch)
80 83 copysourcematch = relrootmatch
81 84
85 checkroot = (repo.ui.configbool('devel', 'all-warnings') or
86 repo.ui.configbool('devel', 'check-relroot'))
87 def pathfn(f):
88 if checkroot and not f.startswith(relroot):
89 raise AssertionError(
90 "file %s doesn't start with relroot %s" % (f, relroot))
91 return posixpath.join(prefix, f[len(relroot):])
92
82 93 if stat:
83 94 diffopts = diffopts.copy(context=0, noprefix=False)
84 95 width = 80
85 96 if not ui.plain():
86 97 width = ui.termwidth() - graphwidth
87 98
88 chunks = ctx2.diff(ctx1, match, changes, opts=diffopts, prefix=prefix,
89 relroot=relroot, copysourcematch=copysourcematch,
99 chunks = ctx2.diff(ctx1, match, changes, opts=diffopts, pathfn=pathfn,
100 copysourcematch=copysourcematch,
90 101 hunksfilterfn=hunksfilterfn)
91 102
92 103 if fp is not None or ui.canwritewithoutlabels():
@@ -15,7 +15,6 b' import email'
15 15 import errno
16 16 import hashlib
17 17 import os
18 import posixpath
19 18 import re
20 19 import shutil
21 20 import zlib
@@ -2239,7 +2238,7 b' diffallopts = diffutil.diffallopts'
2239 2238 difffeatureopts = diffutil.difffeatureopts
2240 2239
2241 2240 def diff(repo, node1=None, node2=None, match=None, changes=None,
2242 opts=None, losedatafn=None, prefix='', relroot='', copy=None,
2241 opts=None, losedatafn=None, pathfn=None, copy=None,
2243 2242 copysourcematch=None, hunksfilterfn=None):
2244 2243 '''yields diff of changes to files between two nodes, or node and
2245 2244 working directory.
@@ -2277,9 +2276,8 b' def diff(repo, node1=None, node2=None, m'
2277 2276 ctx2 = repo[node2]
2278 2277
2279 2278 for fctx1, fctx2, hdr, hunks in diffhunks(
2280 repo, ctx1=ctx1, ctx2=ctx2,
2281 match=match, changes=changes, opts=opts,
2282 losedatafn=losedatafn, prefix=prefix, relroot=relroot, copy=copy,
2279 repo, ctx1=ctx1, ctx2=ctx2, match=match, changes=changes, opts=opts,
2280 losedatafn=losedatafn, pathfn=pathfn, copy=copy,
2283 2281 copysourcematch=copysourcematch):
2284 2282 if hunksfilterfn is not None:
2285 2283 # If the file has been removed, fctx2 is None; but this should
@@ -2294,9 +2292,8 b' def diff(repo, node1=None, node2=None, m'
2294 2292 if text:
2295 2293 yield text
2296 2294
2297 def diffhunks(repo, ctx1, ctx2, match=None, changes=None,
2298 opts=None, losedatafn=None, prefix='', relroot='', copy=None,
2299 copysourcematch=None):
2295 def diffhunks(repo, ctx1, ctx2, match=None, changes=None, opts=None,
2296 losedatafn=None, pathfn=None, copy=None, copysourcematch=None):
2300 2297 """Yield diff of changes to files in the form of (`header`, `hunks`) tuples
2301 2298 where `header` is a list of diff headers and `hunks` is an iterable of
2302 2299 (`hunkrange`, `hunklines`) tuples.
@@ -2376,7 +2373,7 b' def diffhunks(repo, ctx1, ctx2, match=No'
2376 2373
2377 2374 def difffn(opts, losedata):
2378 2375 return trydiff(repo, revs, ctx1, ctx2, modified, added, removed,
2379 copy, getfilectx, opts, losedata, prefix, relroot)
2376 copy, getfilectx, opts, losedata, pathfn)
2380 2377 if opts.upgrade and not opts.git:
2381 2378 try:
2382 2379 def losedata(fn):
@@ -2591,16 +2588,14 b' def _filepairs(modified, added, removed,'
2591 2588 yield f1, f2, copyop
2592 2589
2593 2590 def trydiff(repo, revs, ctx1, ctx2, modified, added, removed,
2594 copy, getfilectx, opts, losedatafn, prefix, relroot):
2591 copy, getfilectx, opts, losedatafn, pathfn):
2595 2592 '''given input data, generate a diff and yield it in blocks
2596 2593
2597 2594 If generating a diff would lose data like flags or binary data and
2598 2595 losedatafn is not None, it will be called.
2599 2596
2600 relroot is removed and prefix is added to every path in the diff output.
2601
2602 If relroot is not empty, this function expects every path in modified,
2603 added, removed and copy to start with it.'''
2597 pathfn is applied to every path in the diff output.
2598 '''
2604 2599
2605 2600 def gitindex(text):
2606 2601 if not text:
@@ -2628,12 +2623,8 b' def trydiff(repo, revs, ctx1, ctx2, modi'
2628 2623
2629 2624 gitmode = {'l': '120000', 'x': '100755', '': '100644'}
2630 2625
2631 if relroot != '' and (repo.ui.configbool('devel', 'all-warnings')
2632 or repo.ui.configbool('devel', 'check-relroot')):
2633 for f in modified + added + removed + list(copy) + list(copy.values()):
2634 if f is not None and not f.startswith(relroot):
2635 raise AssertionError(
2636 "file %s doesn't start with relroot %s" % (f, relroot))
2626 if not pathfn:
2627 pathfn = lambda f: f
2637 2628
2638 2629 for f1, f2, copyop in _filepairs(modified, added, removed, copy, opts):
2639 2630 content1 = None
@@ -2670,10 +2661,8 b' def trydiff(repo, revs, ctx1, ctx2, modi'
2670 2661 (f1 and f2 and flag1 != flag2)):
2671 2662 losedatafn(f2 or f1)
2672 2663
2673 path1 = f1 or f2
2674 path2 = f2 or f1
2675 path1 = posixpath.join(prefix, path1[len(relroot):])
2676 path2 = posixpath.join(prefix, path2[len(relroot):])
2664 path1 = pathfn(f1 or f2)
2665 path2 = pathfn(f2 or f1)
2677 2666 header = []
2678 2667 if opts.git:
2679 2668 header.append('diff --git %s%s %s%s' %
General Comments 0
You need to be logged in to leave comments. Login now