changeset 36766:d382344c69aa

perf: teach perfbdiff to call blocks() and to use xdiff Differential Revision: https://phab.mercurial-scm.org/D2624
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 03 Mar 2018 18:55:43 -0500
parents 04d64163039a
children a148c67d8b09
files contrib/perf.py
diffstat 1 files changed, 24 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/perf.py	Tue Mar 06 19:31:17 2018 -0800
+++ b/contrib/perf.py	Sat Mar 03 18:55:43 2018 -0500
@@ -939,11 +939,16 @@
     timer(d)
     fm.end()
 
-def _bdiffworker(q, ready, done):
+def _bdiffworker(q, blocks, xdiff, ready, done):
     while not done.is_set():
         pair = q.get()
         while pair is not None:
-            mdiff.textdiff(*pair)
+            if xdiff:
+                mdiff.bdiff.xdiffblocks(*pair)
+            elif blocks:
+                mdiff.bdiff.blocks(*pair)
+            else:
+                mdiff.textdiff(*pair)
             q.task_done()
             pair = q.get()
         q.task_done() # for the None one
@@ -954,6 +959,8 @@
     ('', 'count', 1, 'number of revisions to test (when using --startrev)'),
     ('', 'alldata', False, 'test bdiffs for all associated revisions'),
     ('', 'threads', 0, 'number of thread to use (disable with 0)'),
+    ('', 'blocks', False, 'test computing diffs into blocks'),
+    ('', 'xdiff', False, 'use xdiff algorithm'),
     ],
 
     '-c|-m|FILE REV')
@@ -969,6 +976,11 @@
     measure bdiffs for all changes related to that changeset (manifest
     and filelogs).
     """
+    opts = pycompat.byteskwargs(opts)
+
+    if opts['xdiff'] and not opts['blocks']:
+        raise error.CommandError('perfbdiff', '--xdiff requires --blocks')
+
     if opts['alldata']:
         opts['changelog'] = True
 
@@ -977,6 +989,8 @@
     elif rev is None:
         raise error.CommandError('perfbdiff', 'invalid arguments')
 
+    blocks = opts['blocks']
+    xdiff = opts['xdiff']
     textpairs = []
 
     r = cmdutil.openrevlog(repo, 'perfbdiff', file_, opts)
@@ -1007,7 +1021,12 @@
     if not withthreads:
         def d():
             for pair in textpairs:
-                mdiff.textdiff(*pair)
+                if xdiff:
+                    mdiff.bdiff.xdiffblocks(*pair)
+                elif blocks:
+                    mdiff.bdiff.blocks(*pair)
+                else:
+                    mdiff.textdiff(*pair)
     else:
         q = util.queue()
         for i in xrange(threads):
@@ -1015,7 +1034,8 @@
         ready = threading.Condition()
         done = threading.Event()
         for i in xrange(threads):
-            threading.Thread(target=_bdiffworker, args=(q, ready, done)).start()
+            threading.Thread(target=_bdiffworker,
+                             args=(q, blocks, xdiff, ready, done)).start()
         q.join()
         def d():
             for pair in textpairs: