D7593: status: split morestatus data loading from display

2019-12-11 Thread rdamazio (Rodrigo Damazio Bovendorp)
Closed by commit rHGfb4a6d584756: status: split morestatus data loading from 
display (authored by rdamazio).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7593?vs=18586=18605

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

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

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

CHANGE DETAILS

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,47 +779,66 @@
 return b'\n'.join(commentedlines) + b'\n'
 
 
-def _conflictsmsg(repo):
-mergestate = mergemod.mergestate.read(repo)
-if not mergestate.active():
-return
-
-unresolvedlist = sorted(mergestate.unresolved())
-if unresolvedlist:
-mergeliststr = b'\n'.join(
-[
-b'%s' % util.pathto(repo.root, encoding.getcwd(), path)
-for path in 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):



To: rdamazio, #hg-reviewers, pulkit
Cc: martinvonz, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7593: status: split morestatus data loading from display

2019-12-10 Thread rdamazio (Rodrigo Damazio Bovendorp)
rdamazio updated this revision to Diff 18586.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7593?vs=18560=18586

BRANCH
  default

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

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

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

CHANGE DETAILS

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,47 +779,66 @@
 return b'\n'.join(commentedlines) + b'\n'
 
 
-def _conflictsmsg(repo):
-mergestate = mergemod.mergestate.read(repo)
-if not mergestate.active():
-return
-
-unresolvedlist = sorted(mergestate.unresolved())
-if unresolvedlist:
-mergeliststr = b'\n'.join(
-[
-b'%s' % util.pathto(repo.root, encoding.getcwd(), path)
-for path in 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):



To: rdamazio, #hg-reviewers, pulkit
Cc: martinvonz, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7593: status: split morestatus data loading from display

2019-12-10 Thread martinvonz (Martin von Zweigbergk)
martinvonz added a comment.


  In D7593#111728 , @rdamazio 
wrote:
  
  > In D7593#111696 , @pulkit 
wrote:
  >
  >> I pushed @martinvonz 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
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7593: status: split morestatus data loading from display

2019-12-10 Thread rdamazio (Rodrigo Damazio Bovendorp)
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
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7593: status: split morestatus data loading from display

2019-12-10 Thread rdamazio (Rodrigo Damazio Bovendorp)
rdamazio added a comment.


  In D7593#111696 , @pulkit wrote:
  
  > I pushed @martinvonz 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
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7593: status: split morestatus data loading from display

2019-12-10 Thread pulkit (Pulkit Goyal)
pulkit added a comment.
pulkit added a subscriber: martinvonz.


  I pushed @martinvonz 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
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D7593: status: split morestatus data loading from display

2019-12-09 Thread rdamazio (Rodrigo Damazio Bovendorp)
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

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):



To: rdamazio, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org