stack: get stack data directly from stack and remove stackdata()
authorAnton Shestakov <av6@dwimlabs.net>
Sun, 05 May 2019 17:39:46 +0800
changeset 4650 7c05b1625921
parent 4649 6b7ad4b50d00
child 4651 55c347b4874f
stack: get stack data directly from stack and remove stackdata() stackdata function began its life in 137f8b04901e as a proto-stack: it computed stack revs on its own and only had one property to return, "changesetcount". Later it started to prepare and return more properties, but since b933a8068c17 it was computing revs using a getstack function. And then finally in 17749d9d3968 it started to rely on stack class entirely. It was a good function, but now, when all the logic it provided was factored into stack class, I'd say it's finally time for it to be put to rest.
hgext3rd/topic/stack.py
--- a/hgext3rd/topic/stack.py	Sun May 05 16:14:53 2019 +0800
+++ b/hgext3rd/topic/stack.py	Sun May 05 17:39:46 2019 +0800
@@ -242,38 +242,38 @@
     if topic == repo.currenttopic:
         label = 'topic.active'
 
-    data = stackdata(repo, branch=branch, topic=topic)
+    st = stack(repo, branch, topic)
     empty = False
-    if data['changesetcount'] == 0:
+    if st.changesetcount == 0:
         empty = True
     if topic is not None:
         fm.plain(_('### topic: %s')
                  % ui.label(topic, label),
                  label='topic.stack.summary.topic')
 
-        if 1 < data['headcount']:
+        if 1 < len(st.heads):
             fm.plain(' (')
-            fm.plain('%d heads' % data['headcount'],
+            fm.plain('%d heads' % len(st.heads),
                      label='topic.stack.summary.headcount.multiple')
             fm.plain(')')
         fm.plain('\n')
     fm.plain(_('### target: %s (branch)')
-             % '+'.join(data['branches']), # XXX handle multi branches
+             % '+'.join(st.branches), # XXX handle multi branches
              label='topic.stack.summary.branches')
     if topic is None:
-        if 1 < data['headcount']:
+        if 1 < len(st.heads):
             fm.plain(' (')
-            fm.plain('%d heads' % data['headcount'],
+            fm.plain('%d heads' % len(st.heads),
                      label='topic.stack.summary.headcount.multiple')
             fm.plain(')')
     else:
-        if data['behindcount'] == -1:
+        if st.behindcount == -1:
             fm.plain(', ')
-            fm.plain('ambiguous rebase destination - %s' % data['behinderror'],
+            fm.plain('ambiguous rebase destination - %s' % st.behinderror,
                      label='topic.stack.summary.behinderror')
-        elif data['behindcount']:
+        elif st.behindcount:
             fm.plain(', ')
-            fm.plain('%d behind' % data['behindcount'], label='topic.stack.summary.behindcount')
+            fm.plain('%d behind' % st.behindcount, label='topic.stack.summary.behindcount')
     fm.plain('\n')
 
     if empty:
@@ -376,21 +376,3 @@
                      label='topic.stack.state ' + labelsgen('topic.stack.state.%s', states))
         fm.plain('\n')
     fm.end()
-
-def stackdata(repo, branch=None, topic=None):
-    """get various data about a stack
-
-    :changesetcount: number of non-obsolete changesets in the stack
-    :unstablecount: number of unstable changesets
-    :headcount: number of heads on the topic
-    :behindcount: number of changeset on rebase destination
-    """
-    data = {}
-    current = stack(repo, branch, topic)
-    data['changesetcount'] = current.changesetcount
-    data['unstablecount'] = current.unstablecount
-    data['headcount'] = len(current.heads)
-    data['behindcount'] = current.behindcount
-    data['behinderror'] = current.behinderror
-    data['branches'] = current.branches
-    return data