evolve: move OBSEXC message in a dedicated function
authorPierre-Yves David <pierre-yves.david@fb.com>
Fri, 08 Aug 2014 16:48:38 -0700
changeset 1033 908273755215
parent 1032 0fcddde7dae6
child 1034 5fd28e46e8f5
evolve: move OBSEXC message in a dedicated function This will help use to rework them.
hgext/evolve.py
--- a/hgext/evolve.py	Fri Aug 08 15:55:04 2014 -0700
+++ b/hgext/evolve.py	Fri Aug 08 16:48:38 2014 -0700
@@ -2225,6 +2225,11 @@
 ### Obsolescence marker exchange experimenation                   ###
 #####################################################################
 
+def obsexcmsg(ui, message):
+    message = 'OBSEXC: ' + message
+    ui.status(message)
+
+
 @command('debugobsoleterelevant',
          [],
          'REVSET')
@@ -2384,19 +2389,19 @@
             pushop.stepsdone.add('obsmarkers')
             markers = _obsmarkersdiscovery(pushop)
             if not markers:
-                repo.ui.status("OBSEXC: no marker to push\n")
-                repo.ui.status("OBSEXC: DONE\n")
+                obsexcmsg(repo.ui, "no marker to push\n")
+                obsexcmsg(repo.ui, "DONE\n")
                 return
             obsdata = pushobsmarkerStringIO()
             _encodemarkersstream(obsdata, markers)
             obsdata.seek(0)
             obsdata.ui = repo.ui
-            repo.ui.status("OBSEXC: pushing %i markers (%i bytes)\n"
-                           % (len(markers), len(obsdata.getvalue())))
+            obsexcmsg(repo.ui, "pushing %i markers (%i bytes)\n"
+                               % (len(markers), len(obsdata.getvalue())))
             bundler.newpart('EVOLVE:B2X:OBSMARKERV1', data=obsdata)
             def callback(op):
                 repo.ui.progress('OBSEXC', None)
-                repo.ui.status("OBSEXC: DONE\n")
+                obsexcmsg(repo.ui, "DONE\n")
             return callback
     bundle2partsgenerators.append(_pushb2phases)
     bundle2partsgenerators.append(_pushb2obsmarker)
@@ -2424,21 +2429,21 @@
             commonheads = pushop.outgoing.missingheads
     if (obsolete._enabled and repo.obsstore and
         'obsolete' in remote.listkeys('namespaces')):
-        repo.ui.status("OBSEXC: computing relevant nodes\n")
+        obsexcmsg(repo.ui, "computing relevant nodes\n")
         revs = unfi.revs('::%ln', commonheads)
         common = []
         if remote.capable('_evoext_obshash_0'):
-            repo.ui.status("OBSEXC: looking for common markers in %i nodes\n"
-                           % len(revs))
+            obsexcmsg(repo.ui, "looking for common markers in %i nodes\n"
+                               % len(revs))
             common = findcommonobsmarkers(pushop.ui, unfi, remote, revs)
             revs = list(unfi.revs('%ld - (::%ln)', revs, common))
         nodes = [cl.node(r) for r in revs]
         if nodes:
-            repo.ui.status("OBSEXC: computing markers relevant to %i nodes\n"
-                           % len(nodes))
+            obsexcmsg(repo.ui, "computing markers relevant to %i nodes\n"
+                               % len(nodes))
             markers = repo.obsstore.relevantmarkers(nodes)
         else:
-            repo.ui.status("OBSEXC: markers already in sync\n")
+            obsexcmsg(repo.ui, "markers already in sync\n")
             markers = []
         return markers
 
@@ -2459,14 +2464,14 @@
         'obsolete' in remote.listkeys('namespaces')):
         markers = _obsmarkersdiscovery(pushop)
         if not markers:
-            repo.ui.status("OBSEXC: no marker to push\n")
+            obsexcmsg(repo.ui, "no marker to push\n")
         elif remote.capable('_evoext_b2x_obsmarkers_0'):
             obsdata = pushobsmarkerStringIO()
             _encodemarkersstream(obsdata, markers)
             obsdata.seek(0)
             obsdata.ui = repo.ui
-            repo.ui.status("OBSEXC: pushing %i markers (%i bytes)\n"
-                           % (len(markers), len(obsdata.getvalue())))
+            obsexcmsg(repo.ui, "pushing %i markers (%i bytes)\n"
+                               % (len(markers), len(obsdata.getvalue())))
             bundler = bundle2.bundle20(pushop.ui, {})
             capsblob = bundle2.encodecaps(pushop.repo.bundle2caps)
             bundler.addpart(bundle2.bundlepart('b2x:replycaps', data=capsblob))
@@ -2487,8 +2492,8 @@
             _encodemarkersstream(obsdata, markers)
             obsdata.seek(0)
             obsdata.ui = repo.ui
-            repo.ui.status("OBSEXC: pushing %i markers (%i bytes)\n"
-                           % (len(markers), len(obsdata.getvalue())))
+            obsexcmsg(repo.ui, "pushing %i markers (%i bytes)\n"
+                               % (len(markers), len(obsdata.getvalue())))
             remote.evoext_pushobsmarkers_0(obsdata)
             repo.ui.progress('OBSEXC', None)
         else:
@@ -2496,8 +2501,8 @@
             remotedata = _pushkeyescape(markers).items()
             totalbytes = sum(len(d) for k,d in remotedata)
             sentbytes = 0
-            repo.ui.status("OBSEXC: pushing %i markers in %i pushkey payload (%i bytes)\n"
-                            % (len(markers), len(remotedata), totalbytes))
+            obsexcmsg(repo.ui, "pushing %i markers in %i pushkey payload (%i bytes)\n"
+                                % (len(markers), len(remotedata), totalbytes))
             for key, data in remotedata:
                 repo.ui.progress('OBSEXC', sentbytes, item=key, unit="bytes",
                                  total=totalbytes)
@@ -2509,7 +2514,7 @@
             if [r for r in rslts if not r]:
                 msg = _('failed to push some obsolete markers!\n')
                 repo.ui.warn(msg)
-        repo.ui.status("OBSEXC: DONE\n")
+        obsexcmsg(repo.ui, "DONE\n")
 
 
 @eh.addattr(wireproto.wirepeer, 'evoext_pushobsmarkers_0')
@@ -2594,8 +2599,8 @@
     revs = unfi.revs('::%ln', pullop.pulledsubset)
     common = [nullid]
     if remote.capable('_evoext_obshash_0'):
-        repo.ui.status("OBSEXC: looking for common markers in %i nodes\n"
-                       % len(revs))
+        obsexcmsg(repo.ui, "looking for common markers in %i nodes\n"
+                           % len(revs))
         common = findcommonobsmarkers(repo.ui, repo, remote, revs)
     return {'heads': pullop.pulledsubset, 'common': common}
 
@@ -2640,7 +2645,7 @@
         return None # remote opted out of obsolescence marker exchange
     tr = None
     ui = pullop.repo.ui
-    ui.status("OBSEXC: pull obsolescence markers\n")
+    obsexcmsg(ui, "pull obsolescence markers\n")
     boundaries = _buildpullobsmerkersboundaries(pullop)
     new = 0
 
@@ -2663,27 +2668,27 @@
             bytes += entry.get('bytes', 0)
             new += entry.get('new', 0)
         if 5 < bytes:
-            ui.status("OBSEXC: merging obsolescence markers (%i bytes)\n"
+            obsexcmsg(ui, "merging obsolescence markers (%i bytes)\n"
                       % bytes)
-            ui.status("OBSEXC: %i markers added\n" % new)
+            obsexcmsg(ui, "%i markers added\n" % new)
             tr = op.gettransaction()
         else:
-            ui.status("OBSEXC: no unknown remote markers\n")
-        ui.status("OBSEXC: DONE\n")
+            obsexcmsg(ui, "no unknown remote markers\n")
+        obsexcmsg(ui, "DONE\n")
     elif wirepull:
         obsdata = pullop.remote.evoext_pullobsmarkers_0(**boundaries)
         obsdata = obsdata.read()
         if len(obsdata) > 5:
-            ui.status("OBSEXC: merging obsolescence markers (%i bytes)\n"
+            obsexcmsg(ui, "merging obsolescence markers (%i bytes)\n"
                            % len(obsdata))
             tr = pullop.gettransaction()
             old = len(pullop.repo.obsstore._all)
             pullop.repo.obsstore.mergemarkers(tr, obsdata)
             new = len(pullop.repo.obsstore._all) - old
-            ui.status("OBSEXC: %i markers added\n" % new)
+            obsexcmsg(ui, "%i markers added\n" % new)
         else:
-            ui.status("OBSEXC: no unknown remote markers\n")
-        ui.status("OBSEXC: DONE\n")
+            obsexcmsg(ui, "no unknown remote markers\n")
+        obsexcmsg(ui, "DONE\n")
     if new:
         pullop.repo.invalidatevolatilesets()
     return tr