rebase: extract ctx description logic to a function
authorJun Wu <quark@fb.com>
Sat, 08 Jul 2017 20:05:52 -0700
changeset 33841 35fc5e919675
parent 33840 627cb36b537f
child 33842 30573b3d2ebc
rebase: extract ctx description logic to a function The function will be used in a later patch. Differential Revision: https://phab.mercurial-scm.org/D22
hgext/rebase.py
--- a/hgext/rebase.py	Thu Jul 27 00:00:15 2017 -0400
+++ b/hgext/rebase.py	Sat Jul 08 20:05:52 2017 -0700
@@ -122,6 +122,16 @@
         sourceset = revset.getset(repo, smartset.fullreposet(repo), x)
     return subset & smartset.baseset([_destrebase(repo, sourceset)])
 
+def _ctxdesc(ctx):
+    """short description for a context"""
+    desc = '%d:%s "%s"' % (ctx.rev(), ctx,
+                           ctx.description().split('\n', 1)[0])
+    repo = ctx.repo()
+    names = repo.nodetags(ctx.node()) + repo.nodebookmarks(ctx.node())
+    if names:
+        desc += ' (%s)' % ' '.join(names)
+    return desc
+
 class rebaseruntime(object):
     """This class is a container for rebase runtime state"""
     def __init__(self, repo, ui, opts=None):
@@ -377,11 +387,7 @@
         pos = 0
         for rev in sortedrevs:
             ctx = repo[rev]
-            desc = '%d:%s "%s"' % (ctx.rev(), ctx,
-                                   ctx.description().split('\n', 1)[0])
-            names = repo.nodetags(ctx.node()) + repo.nodebookmarks(ctx.node())
-            if names:
-                desc += ' (%s)' % ' '.join(names)
+            desc = _ctxdesc(ctx)
             if self.state[rev] == rev:
                 ui.status(_('already rebased %s\n') % desc)
             elif self.state[rev] == revtodo: