##// END OF EJS Templates
patch: turn patch.diff() into a generator...
Dirkjan Ochtman -
r7308:b6f5490e default
parent child Browse files
Show More
@@ -44,9 +44,7 b' def maketemplater(ui, repo, tmpl):'
44 44
45 45 def changedlines(ui, repo, ctx1, ctx2):
46 46 lines = 0
47 ui.pushbuffer()
48 patch.diff(repo, ctx1.node(), ctx2.node())
49 diff = ui.popbuffer()
47 diff = ''.join(patch.diff(repo, ctx1.node(), ctx2.node()))
50 48 for l in diff.split('\n'):
51 49 if (l.startswith("+") and not l.startswith("+++ ") or
52 50 l.startswith("-") and not l.startswith("--- ")):
@@ -92,8 +92,10 b' def difftree(ui, repo, node1=None, node2'
92 92 if opts['pretty']:
93 93 catcommit(ui, repo, node2, "")
94 94 m = cmdutil.match(repo, files)
95 patch.diff(repo, node1, node2, match=m,
95 chunks = patch.diff(repo, node1, node2, match=m,
96 96 opts=patch.diffopts(ui, {'git': True}))
97 for chunk in chunks:
98 repo.ui.write(chunk)
97 99 else:
98 100 __difftree(repo, node1, node2, files=files)
99 101 if not opts['stdin']:
@@ -501,15 +501,15 b' def reposetup(ui, repo):'
501 501 # shrink keywords read from working dir
502 502 self.lines = kwt.shrinklines(self.fname, self.lines)
503 503
504 def kw_diff(orig, repo, node1=None, node2=None, match=None,
505 fp=None, changes=None, opts=None):
504 def kw_diff(orig, repo, node1=None, node2=None, match=None, changes=None,
505 opts=None):
506 506 '''Monkeypatch patch.diff to avoid expansion except when
507 507 comparing against working dir.'''
508 508 if node2 is not None:
509 509 kwt.matcher = util.never
510 510 elif node1 is not None and node1 != repo['.'].node():
511 511 kwt.restrict = True
512 orig(repo, node1, node2, match, fp, changes, opts)
512 return orig(repo, node1, node2, match, changes, opts)
513 513
514 514 def kwweb_skip(orig, web, req, tmpl):
515 515 '''Wraps webcommands.x turning off keyword expansion.'''
@@ -321,7 +321,10 b' class queue:'
321 321 def printdiff(self, repo, node1, node2=None, files=None,
322 322 fp=None, changes=None, opts={}):
323 323 m = cmdutil.match(repo, files, opts)
324 patch.diff(repo, node1, node2, m, fp, changes, self.diffopts())
324 chunks = patch.diff(repo, node1, node2, m, changes, self.diffopts())
325 write = fp is None and repo.ui.write or fp.write
326 for chunk in chunks:
327 write(chunk)
325 328
326 329 def mergeone(self, repo, mergeq, head, patch, rev):
327 330 # first try just applying the patch
@@ -697,8 +700,10 b' class queue:'
697 700 diffopts = self.diffopts()
698 701 if opts.get('git'): diffopts.git = True
699 702 parent = self.qparents(repo, n)
700 patch.diff(repo, node1=parent, node2=n, fp=p,
703 chunks = patch.diff(repo, node1=parent, node2=n,
701 704 match=match, opts=diffopts)
705 for chunk in chunks:
706 p.write(chunk)
702 707 p.close()
703 708 wlock = None
704 709 r = self.qrepo()
@@ -1139,8 +1144,10 b' class queue:'
1139 1144 a = util.unique(aa)
1140 1145 c = [filter(matchfn, l) for l in (m, a, r)]
1141 1146 match = cmdutil.matchfiles(repo, util.unique(c[0] + c[1] + c[2]))
1142 patch.diff(repo, patchparent, match=match,
1143 fp=patchf, changes=c, opts=self.diffopts())
1147 chunks = patch.diff(repo, patchparent, match=match,
1148 changes=c, opts=self.diffopts())
1149 for chunk in chunks:
1150 patchf.write(chunk)
1144 1151 patchf.close()
1145 1152
1146 1153 repo.dirstate.setparents(*cparents)
@@ -238,9 +238,8 b' class notifier(object):'
238 238 maxdiff = int(self.ui.config('notify', 'maxdiff', 300))
239 239 prev = self.repo.changelog.parents(node)[0]
240 240
241 self.ui.pushbuffer()
242 patch.diff(self.repo, prev, ref, opts=patch.diffopts(self.ui))
243 difflines = self.ui.popbuffer().splitlines()
241 chunks = patch.diff(self.repo, prev, ref, opts=patch.diffopts(self.ui))
242 difflines = ''.join(chunks).splitlines()
244 243
245 244 if self.ui.configbool('notify', 'diffstat', True):
246 245 s = patch.diffstat(difflines)
@@ -413,9 +413,10 b' def dorecord(ui, repo, committer, *pats,'
413 413 modified, added, removed = changes
414 414 match = cmdutil.matchfiles(repo, modified + added + removed)
415 415 diffopts = mdiff.diffopts(git=True, nodates=True)
416 chunks = patch.diff(repo, repo.dirstate.parents()[0], match=match,
417 changes=changes, opts=diffopts)
416 418 fp = cStringIO.StringIO()
417 patch.diff(repo, repo.dirstate.parents()[0], match=match,
418 changes=changes, opts=diffopts, fp=fp)
419 fp.write(''.join(chunks))
419 420 fp.seek(0)
420 421
421 422 # 1. filter patch, so we have intending-to apply subset of it
@@ -138,7 +138,9 b' class transplanter:'
138 138 else:
139 139 fd, patchfile = tempfile.mkstemp(prefix='hg-transplant-')
140 140 fp = os.fdopen(fd, 'w')
141 patch.diff(source, parents[0], node, fp=fp, opts=diffopts)
141 gen = patch.diff(source, parents[0], node, opts=diffopts)
142 for chunk in gen:
143 fp.write(chunk)
142 144 fp.close()
143 145
144 146 del revmap[rev]
@@ -405,7 +407,8 b' def browserevs(ui, repo, nodes, opts):'
405 407 action = None
406 408 elif action == 'p':
407 409 parent = repo.changelog.parents(node)[0]
408 patch.diff(repo, parent, node)
410 for chunk in patch.diff(repo, parent, node):
411 repo.ui.write(chunk)
409 412 action = None
410 413 elif action not in ('y', 'n', 'm', 'c', 'q'):
411 414 ui.write('no such option\n')
@@ -673,8 +673,10 b' class changeset_printer(object):'
673 673 def showpatch(self, node):
674 674 if self.patch:
675 675 prev = self.repo.changelog.parents(node)[0]
676 patch.diff(self.repo, prev, node, match=self.patch, fp=self.ui,
676 chunks = patch.diff(self.repo, prev, node, match=self.patch,
677 677 opts=patch.diffopts(self.ui))
678 for chunk in chunks:
679 self.ui.write(chunk)
678 680 self.ui.write("\n")
679 681
680 682 def _meaningful_parentrevs(self, log, rev):
@@ -1010,7 +1010,9 b' def diff(ui, repo, *pats, **opts):'
1010 1010 node1, node2 = cmdutil.revpair(repo, opts.get('rev'))
1011 1011
1012 1012 m = cmdutil.match(repo, pats, opts)
1013 patch.diff(repo, node1, node2, match=m, opts=patch.diffopts(ui, opts))
1013 it = patch.diff(repo, node1, node2, match=m, opts=patch.diffopts(ui, opts))
1014 for chunk in it:
1015 repo.ui.write(chunk)
1014 1016
1015 1017 def export(ui, repo, *changesets, **opts):
1016 1018 """dump the header and diffs for one or more changesets
@@ -1169,9 +1169,8 b' def _addmodehdr(header, omode, nmode):'
1169 1169 header.append('old mode %s\n' % omode)
1170 1170 header.append('new mode %s\n' % nmode)
1171 1171
1172 def diff(repo, node1=None, node2=None, match=None,
1173 fp=None, changes=None, opts=None):
1174 '''print diff of changes to files between two nodes, or node and
1172 def diff(repo, node1=None, node2=None, match=None, changes=None, opts=None):
1173 '''yields diff of changes to files between two nodes, or node and
1175 1174 working directory.
1176 1175
1177 1176 if node1 is None, use first dirstate parent instead.
@@ -1182,8 +1181,6 b' def diff(repo, node1=None, node2=None, m'
1182 1181
1183 1182 if opts is None:
1184 1183 opts = mdiff.defaultopts
1185 if fp is None:
1186 fp = repo.ui
1187 1184
1188 1185 if not node1:
1189 1186 node1 = repo.dirstate.parents()[0]
@@ -1274,9 +1271,10 b' def diff(repo, node1=None, node2=None, m'
1274 1271 # ctx2 date may be dynamic
1275 1272 tn, util.datestr(ctx2.date()),
1276 1273 a, b, r, opts=opts)
1277 if text or len(header) > 1:
1278 fp.write(''.join(header))
1279 fp.write(text)
1274 if header and (text or len(header) > 1):
1275 yield ''.join(header)
1276 if text:
1277 yield text
1280 1278
1281 1279 def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False,
1282 1280 opts=None):
@@ -1312,7 +1310,8 b" def export(repo, revs, template='hg-%h.p"
1312 1310 fp.write(ctx.description().rstrip())
1313 1311 fp.write("\n\n")
1314 1312
1315 diff(repo, prev, node, fp=fp, opts=opts)
1313 for chunk in diff(repo, prev, node, opts=opts):
1314 fp.write(chunk)
1316 1315 if fp not in (sys.stdout, repo.ui):
1317 1316 fp.close()
1318 1317
General Comments 0
You need to be logged in to leave comments. Login now