Patchwork D7593: status: split morestatus data loading from display

login
register
mail settings
Submitter phabricator
Date Dec. 10, 2019, 6:40 a.m.
Message ID <differential-rev-PHID-DREV-7pxx6fmmkpat6soju7uv-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/43661/
State Superseded
Headers show

Comments

phabricator - Dec. 10, 2019, 6:40 a.m.
rdamazio created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This is a small refactoring in preparation for adding more morestatus
  functionality (notably for templated/JSON output) - the goal is to
  use the data inside the status display loop, as well as output the
  overall state in a templatable/structured way.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D7593

AFFECTED FILES
  mercurial/cmdutil.py
  mercurial/commands.py

CHANGE DETAILS




To: rdamazio, #hg-reviewers
Cc: mercurial-devel
phabricator - Dec. 10, 2019, 3:55 p.m.
pulkit added a comment.
pulkit added a subscriber: martinvonz.


  I pushed @martinvonz D7591 <https://phab.mercurial-scm.org/D7591>, so these need to be rebased. Thanks!

REPOSITORY
  rHG Mercurial

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7593/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7593

To: rdamazio, #hg-reviewers, pulkit
Cc: martinvonz, mercurial-devel
phabricator - Dec. 10, 2019, 6:12 p.m.
rdamazio added a comment.


  In D7593#111696 <https://phab.mercurial-scm.org/D7593#111696>, @pulkit wrote:
  
  > I pushed @martinvonz D7591 <https://phab.mercurial-scm.org/D7591>, so these need to be rebased. Thanks!
  
  Are you asking me to do something, or are you going to?
  This supersedes his change completely.

REPOSITORY
  rHG Mercurial

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7593/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7593

To: rdamazio, #hg-reviewers, pulkit
Cc: martinvonz, mercurial-devel
phabricator - Dec. 10, 2019, 6:16 p.m.
rdamazio added a comment.


  Just phabsended after a rebase onto hg-committed, let me know if that's not what you expected.

REPOSITORY
  rHG Mercurial

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7593/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7593

To: rdamazio, #hg-reviewers, pulkit
Cc: martinvonz, mercurial-devel
phabricator - Dec. 10, 2019, 6:17 p.m.
martinvonz added a comment.


  In D7593#111728 <https://phab.mercurial-scm.org/D7593#111728>, @rdamazio wrote:
  
  > In D7593#111696 <https://phab.mercurial-scm.org/D7593#111696>, @pulkit wrote:
  >
  >> I pushed @martinvonz D7591 <https://phab.mercurial-scm.org/D7591>, so these need to be rebased. Thanks!
  >
  > Are you asking me to do something, or are you going to?
  > This supersedes his change completely.
  
  He's asking you to rebase this series. Pull from http://mercurial-scm.org/repo/hg-committed and then rebase on top of `@`.
  
  Even if my patch had not been queued, I would have preferred if you had split that change out from this patch since it's a separate change from what the commit message says.

REPOSITORY
  rHG Mercurial

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7593/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7593

To: rdamazio, #hg-reviewers, pulkit
Cc: martinvonz, mercurial-devel
phabricator - Dec. 11, 2019, 12:05 a.m.
rdamazio added a comment.


  In D7593#111733 <https://phab.mercurial-scm.org/D7593#111733>, @martinvonz wrote:
  
  > In D7593#111728 <https://phab.mercurial-scm.org/D7593#111728>, @rdamazio wrote:
  >
  >> In D7593#111696 <https://phab.mercurial-scm.org/D7593#111696>, @pulkit wrote:
  >>
  >>> I pushed @martinvonz D7591 <https://phab.mercurial-scm.org/D7591>, so these need to be rebased. Thanks!
  >>
  >> Are you asking me to do something, or are you going to?
  >> This supersedes his change completely.
  >
  > He's asking you to rebase this series. Pull from http://mercurial-scm.org/repo/hg-committed and then rebase on top of `@`.
  > Even if my patch had not been queued, I would have preferred if you had split that change out from this patch since it's a separate change from what the commit message says.
  
  Thanks. Yes, that's what I did :)

REPOSITORY
  rHG Mercurial

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7593/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7593

To: rdamazio, #hg-reviewers, pulkit
Cc: martinvonz, mercurial-devel

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -6867,6 +6867,12 @@ 
     ) and not opts.get(b'no_status'):
         copy = copies.pathcopies(ctx1, ctx2, m)
 
+    morestatus = None
+    if (
+        ui.verbose or ui.configbool(b'commands', b'status.verbose')
+    ) and not ui.plain():
+        morestatus = cmdutil.readmorestatus(repo)
+
     ui.pager(b'status')
     fm = ui.formatter(b'status', opts)
     fmt = b'%s' + end
@@ -6888,10 +6894,8 @@ 
                         label=b'status.copied',
                     )
 
-    if (
-        ui.verbose or ui.configbool(b'commands', b'status.verbose')
-    ) and not ui.plain():
-        cmdutil.morestatus(repo, fm)
+    if morestatus:
+        morestatus.formatfooter(fm)
     fm.end()
 
 
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -24,6 +24,7 @@ 
     open,
     setattr,
 )
+from .thirdparty import attr
 
 from . import (
     bookmarks,
@@ -778,48 +779,66 @@ 
     return b'\n'.join(commentedlines) + b'\n'
 
 
-def _conflictsmsg(repo):
-    mergestate = mergemod.mergestate.read(repo)
-    if not mergestate.active():
-        return
-
-    m = scmutil.match(repo[None])
-    unresolvedlist = [f for f in mergestate.unresolved() if m(f)]
-    if unresolvedlist:
-        mergeliststr = b'\n'.join(
-            [
-                b'    %s' % util.pathto(repo.root, encoding.getcwd(), path)
-                for path in sorted(unresolvedlist)
-            ]
-        )
-        msg = (
-            _(
-                '''Unresolved merge conflicts:
+@attr.s(frozen=True)
+class morestatus(object):
+    reporoot = attr.ib()
+    unfinishedop = attr.ib()
+    unfinishedmsg = attr.ib()
+    inmergestate = attr.ib()
+    unresolvedpaths = attr.ib()
+    _label = b'status.morestatus'
+
+    def formatfooter(self, fm):
+        statemsg = _(b'The repository is in an unfinished *%s* state.'
+                     ) % self.unfinishedop
+        fm.plain(b'%s\n' % _commentlines(statemsg), label=self._label)
+
+        self._formatconflicts(fm)
+        if self.unfinishedmsg:
+            fm.plain(b'%s\n' % _commentlines(self.unfinishedmsg),
+                     label=self._label)
+
+    def _formatconflicts(self, fm):
+        if not self.inmergestate:
+            return
+
+        if self.unresolvedpaths:
+            mergeliststr = b'\n'.join(
+                [
+                    b'    %s' % util.pathto(self.reporoot, encoding.getcwd(),
+                                            path)
+                    for path in self.unresolvedpaths
+                ]
+            )
+            msg = (
+                _(
+                    '''Unresolved merge conflicts:
 
 %s
 
 To mark files as resolved:  hg resolve --mark FILE'''
+                )
+                % mergeliststr
             )
-            % mergeliststr
-        )
-    else:
-        msg = _(b'No unresolved merge conflicts.')
-
-    return _commentlines(msg)
-
-
-def morestatus(repo, fm):
+        else:
+            msg = _(b'No unresolved merge conflicts.')
+
+        fm.plain(b'%s\n' % _commentlines(msg), label=self._label)
+
+
+def readmorestatus(repo):
+    """Returns a morestatus object if the repo has unfinished state."""
     statetuple = statemod.getrepostate(repo)
-    label = b'status.morestatus'
-    if statetuple:
-        state, helpfulmsg = statetuple
-        statemsg = _(b'The repository is in an unfinished *%s* state.') % state
-        fm.plain(b'%s\n' % _commentlines(statemsg), label=label)
-        conmsg = _conflictsmsg(repo)
-        if conmsg:
-            fm.plain(b'%s\n' % conmsg, label=label)
-        if helpfulmsg:
-            fm.plain(b'%s\n' % _commentlines(helpfulmsg), label=label)
+    if not statetuple:
+        return None
+
+    unfinishedop, unfinishedmsg = statetuple
+    mergestate = mergemod.mergestate.read(repo)
+    unresolved = None
+    if mergestate.active():
+        unresolved = sorted(mergestate.unresolved())
+    return morestatus(repo.root, unfinishedop, unfinishedmsg,
+                      unresolved is not None, unresolved)
 
 
 def findpossible(cmd, table, strict=False):