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