comparison mercurial/logcmdutil.py @ 37837:e0f30c91dfd8

log: cache diffopts instance It appears that calling patch.diff*opts() repeatedly has some cost. $ hg log -T '{rev}\n' -R mercurial --time > /dev/null (orig) time: real 4.430 secs (user 4.370+0.000 sys 0.050+0.000) (new) time: real 1.950 secs (user 1.880+0.000 sys 0.060+0.000) 'diffopts or {}' isn't necessary as patch.diff*opts() accepts opts=None.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 29 Apr 2018 15:44:17 +0900
parents 0f084741cd66
children 3fe1c9263024
comparison
equal deleted inserted replaced
37836:86e7a57449fa 37837:e0f30c91dfd8
152 def __init__(self, ui, repo, differ=None, diffopts=None, buffered=False): 152 def __init__(self, ui, repo, differ=None, diffopts=None, buffered=False):
153 self.ui = ui 153 self.ui = ui
154 self.repo = repo 154 self.repo = repo
155 self.buffered = buffered 155 self.buffered = buffered
156 self._differ = differ or changesetdiffer() 156 self._differ = differ or changesetdiffer()
157 self._diffopts = patch.diffallopts(ui, diffopts)
157 self.diffopts = diffopts or {} 158 self.diffopts = diffopts or {}
158 self.header = {} 159 self.header = {}
159 self.hunk = {} 160 self.hunk = {}
160 self.lastheader = None 161 self.lastheader = None
161 self.footer = None 162 self.footer = None
298 ''' 299 '''
299 300
300 def _showpatch(self, ctx): 301 def _showpatch(self, ctx):
301 stat = self.diffopts.get('stat') 302 stat = self.diffopts.get('stat')
302 diff = self.diffopts.get('patch') 303 diff = self.diffopts.get('patch')
303 diffopts = patch.diffallopts(self.ui, self.diffopts)
304 if stat: 304 if stat:
305 self._differ.showdiff(self.ui, ctx, diffopts, stat=True) 305 self._differ.showdiff(self.ui, ctx, self._diffopts, stat=True)
306 if stat and diff: 306 if stat and diff:
307 self.ui.write("\n") 307 self.ui.write("\n")
308 if diff: 308 if diff:
309 self._differ.showdiff(self.ui, ctx, diffopts, stat=False) 309 self._differ.showdiff(self.ui, ctx, self._diffopts, stat=False)
310 if stat or diff: 310 if stat or diff:
311 self.ui.write("\n") 311 self.ui.write("\n")
312 312
313 class changesetformatter(changesetprinter): 313 class changesetformatter(changesetprinter):
314 """Format changeset information by generic formatter""" 314 """Format changeset information by generic formatter"""
315 315
316 def __init__(self, ui, repo, fm, differ=None, diffopts=None, 316 def __init__(self, ui, repo, fm, differ=None, diffopts=None,
317 buffered=False): 317 buffered=False):
318 changesetprinter.__init__(self, ui, repo, differ, diffopts, buffered) 318 changesetprinter.__init__(self, ui, repo, differ, diffopts, buffered)
319 self._diffopts = patch.difffeatureopts(ui, diffopts, git=True)
319 self._fm = fm 320 self._fm = fm
320 321
321 def close(self): 322 def close(self):
322 self._fm.end() 323 self._fm.end()
323 324
367 fm.data(copies=fm.formatdict(copies, 368 fm.data(copies=fm.formatdict(copies,
368 key='name', value='source')) 369 key='name', value='source'))
369 370
370 stat = self.diffopts.get('stat') 371 stat = self.diffopts.get('stat')
371 diff = self.diffopts.get('patch') 372 diff = self.diffopts.get('patch')
372 diffopts = patch.difffeatureopts(self.ui, self.diffopts, git=True)
373 if stat: 373 if stat:
374 self.ui.pushbuffer() 374 self.ui.pushbuffer()
375 self._differ.showdiff(self.ui, ctx, diffopts, stat=True) 375 self._differ.showdiff(self.ui, ctx, self._diffopts, stat=True)
376 fm.data(diffstat=self.ui.popbuffer()) 376 fm.data(diffstat=self.ui.popbuffer())
377 if diff: 377 if diff:
378 self.ui.pushbuffer() 378 self.ui.pushbuffer()
379 self._differ.showdiff(self.ui, ctx, diffopts, stat=False) 379 self._differ.showdiff(self.ui, ctx, self._diffopts, stat=False)
380 fm.data(diff=self.ui.popbuffer()) 380 fm.data(diff=self.ui.popbuffer())
381 381
382 class changesettemplater(changesetprinter): 382 class changesettemplater(changesetprinter):
383 '''format changeset information. 383 '''format changeset information.
384 384