Mercurial > public > mercurial-scm > hg
comparison mercurial/logcmdutil.py @ 36004:d4c210ee894f
logcmdutil: unindent diff generator of changesetprinter
Prepares for the next few patches which will make matchfn and hunksfilterfn
always available.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 21 Jan 2018 14:37:04 +0900 |
parents | fcde8946c553 |
children | dd77e36eabb6 |
comparison
equal
deleted
inserted
replaced
36003:fcde8946c553 | 36004:d4c210ee894f |
---|---|
280 ''' | 280 ''' |
281 | 281 |
282 def _showpatch(self, ctx): | 282 def _showpatch(self, ctx): |
283 matchfn = self._makefilematcher(ctx) | 283 matchfn = self._makefilematcher(ctx) |
284 hunksfilterfn = self._makehunksfilter(ctx) | 284 hunksfilterfn = self._makehunksfilter(ctx) |
285 if matchfn: | 285 if not matchfn: |
286 stat = self.diffopts.get('stat') | 286 return |
287 diff = self.diffopts.get('patch') | 287 stat = self.diffopts.get('stat') |
288 diffopts = patch.diffallopts(self.ui, self.diffopts) | 288 diff = self.diffopts.get('patch') |
289 node = ctx.node() | 289 diffopts = patch.diffallopts(self.ui, self.diffopts) |
290 prev = ctx.p1().node() | 290 node = ctx.node() |
291 if stat: | 291 prev = ctx.p1().node() |
292 diffordiffstat(self.ui, self.repo, diffopts, prev, node, | 292 if stat: |
293 match=matchfn, stat=True, | 293 diffordiffstat(self.ui, self.repo, diffopts, prev, node, |
294 hunksfilterfn=hunksfilterfn) | 294 match=matchfn, stat=True, |
295 if diff: | 295 hunksfilterfn=hunksfilterfn) |
296 if stat: | 296 if stat and diff: |
297 self.ui.write("\n") | 297 self.ui.write("\n") |
298 diffordiffstat(self.ui, self.repo, diffopts, prev, node, | 298 if diff: |
299 match=matchfn, stat=False, | 299 diffordiffstat(self.ui, self.repo, diffopts, prev, node, |
300 hunksfilterfn=hunksfilterfn) | 300 match=matchfn, stat=False, |
301 if stat or diff: | 301 hunksfilterfn=hunksfilterfn) |
302 self.ui.write("\n") | 302 if stat or diff: |
303 self.ui.write("\n") | |
303 | 304 |
304 class jsonchangeset(changesetprinter): | 305 class jsonchangeset(changesetprinter): |
305 '''format changeset information.''' | 306 '''format changeset information.''' |
306 | 307 |
307 def __init__(self, ui, repo, makefilematcher=None, makehunksfilter=None, | 308 def __init__(self, ui, repo, makefilematcher=None, makehunksfilter=None, |
381 self.ui.write((',\n "copies": {%s}') % | 382 self.ui.write((',\n "copies": {%s}') % |
382 ", ".join('"%s": "%s"' % (j(k), j(v)) | 383 ", ".join('"%s": "%s"' % (j(k), j(v)) |
383 for k, v in copies)) | 384 for k, v in copies)) |
384 | 385 |
385 matchfn = self._makefilematcher(ctx) | 386 matchfn = self._makefilematcher(ctx) |
386 if matchfn: | 387 stat = self.diffopts.get('stat') |
387 stat = self.diffopts.get('stat') | 388 diff = self.diffopts.get('patch') |
388 diff = self.diffopts.get('patch') | 389 diffopts = patch.difffeatureopts(self.ui, self.diffopts, git=True) |
389 diffopts = patch.difffeatureopts(self.ui, self.diffopts, git=True) | 390 node, prev = ctx.node(), ctx.p1().node() |
390 node, prev = ctx.node(), ctx.p1().node() | 391 if matchfn and stat: |
391 if stat: | 392 self.ui.pushbuffer() |
392 self.ui.pushbuffer() | 393 diffordiffstat(self.ui, self.repo, diffopts, prev, node, |
393 diffordiffstat(self.ui, self.repo, diffopts, prev, node, | 394 match=matchfn, stat=True) |
394 match=matchfn, stat=True) | 395 self.ui.write((',\n "diffstat": "%s"') |
395 self.ui.write((',\n "diffstat": "%s"') | 396 % j(self.ui.popbuffer())) |
396 % j(self.ui.popbuffer())) | 397 if matchfn and diff: |
397 if diff: | 398 self.ui.pushbuffer() |
398 self.ui.pushbuffer() | 399 diffordiffstat(self.ui, self.repo, diffopts, prev, node, |
399 diffordiffstat(self.ui, self.repo, diffopts, prev, node, | 400 match=matchfn, stat=False) |
400 match=matchfn, stat=False) | 401 self.ui.write((',\n "diff": "%s"') % j(self.ui.popbuffer())) |
401 self.ui.write((',\n "diff": "%s"') % j(self.ui.popbuffer())) | |
402 | 402 |
403 self.ui.write("\n }") | 403 self.ui.write("\n }") |
404 | 404 |
405 class changesettemplater(changesetprinter): | 405 class changesettemplater(changesetprinter): |
406 '''format changeset information. | 406 '''format changeset information. |