Mercurial > public > mercurial-scm > hg
comparison mercurial/cmdutil.py @ 43841:fb4a6d584756
status: split morestatus data loading from display
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.
Differential Revision: https://phab.mercurial-scm.org/D7593
author | Rodrigo Damazio Bovendorp <rdamazio@google.com> |
---|---|
date | Mon, 09 Dec 2019 18:15:38 -0800 |
parents | 072b745936f1 |
children | 7315464f0613 |
comparison
equal
deleted
inserted
replaced
43840:79c0121220e3 | 43841:fb4a6d584756 |
---|---|
22 from .pycompat import ( | 22 from .pycompat import ( |
23 getattr, | 23 getattr, |
24 open, | 24 open, |
25 setattr, | 25 setattr, |
26 ) | 26 ) |
27 from .thirdparty import attr | |
27 | 28 |
28 from . import ( | 29 from . import ( |
29 bookmarks, | 30 bookmarks, |
30 changelog, | 31 changelog, |
31 copies, | 32 copies, |
776 lines = raw.splitlines() | 777 lines = raw.splitlines() |
777 commentedlines = [b'# %s' % line for line in lines] | 778 commentedlines = [b'# %s' % line for line in lines] |
778 return b'\n'.join(commentedlines) + b'\n' | 779 return b'\n'.join(commentedlines) + b'\n' |
779 | 780 |
780 | 781 |
781 def _conflictsmsg(repo): | 782 @attr.s(frozen=True) |
783 class morestatus(object): | |
784 reporoot = attr.ib() | |
785 unfinishedop = attr.ib() | |
786 unfinishedmsg = attr.ib() | |
787 inmergestate = attr.ib() | |
788 unresolvedpaths = attr.ib() | |
789 _label = b'status.morestatus' | |
790 | |
791 def formatfooter(self, fm): | |
792 statemsg = _(b'The repository is in an unfinished *%s* state.' | |
793 ) % self.unfinishedop | |
794 fm.plain(b'%s\n' % _commentlines(statemsg), label=self._label) | |
795 | |
796 self._formatconflicts(fm) | |
797 if self.unfinishedmsg: | |
798 fm.plain(b'%s\n' % _commentlines(self.unfinishedmsg), | |
799 label=self._label) | |
800 | |
801 def _formatconflicts(self, fm): | |
802 if not self.inmergestate: | |
803 return | |
804 | |
805 if self.unresolvedpaths: | |
806 mergeliststr = b'\n'.join( | |
807 [ | |
808 b' %s' % util.pathto(self.reporoot, encoding.getcwd(), | |
809 path) | |
810 for path in self.unresolvedpaths | |
811 ] | |
812 ) | |
813 msg = ( | |
814 _( | |
815 '''Unresolved merge conflicts: | |
816 | |
817 %s | |
818 | |
819 To mark files as resolved: hg resolve --mark FILE''' | |
820 ) | |
821 % mergeliststr | |
822 ) | |
823 else: | |
824 msg = _(b'No unresolved merge conflicts.') | |
825 | |
826 fm.plain(b'%s\n' % _commentlines(msg), label=self._label) | |
827 | |
828 | |
829 def readmorestatus(repo): | |
830 """Returns a morestatus object if the repo has unfinished state.""" | |
831 statetuple = statemod.getrepostate(repo) | |
832 if not statetuple: | |
833 return None | |
834 | |
835 unfinishedop, unfinishedmsg = statetuple | |
782 mergestate = mergemod.mergestate.read(repo) | 836 mergestate = mergemod.mergestate.read(repo) |
783 if not mergestate.active(): | 837 unresolved = None |
784 return | 838 if mergestate.active(): |
785 | 839 unresolved = sorted(mergestate.unresolved()) |
786 unresolvedlist = sorted(mergestate.unresolved()) | 840 return morestatus(repo.root, unfinishedop, unfinishedmsg, |
787 if unresolvedlist: | 841 unresolved is not None, unresolved) |
788 mergeliststr = b'\n'.join( | |
789 [ | |
790 b' %s' % util.pathto(repo.root, encoding.getcwd(), path) | |
791 for path in unresolvedlist | |
792 ] | |
793 ) | |
794 msg = ( | |
795 _( | |
796 '''Unresolved merge conflicts: | |
797 | |
798 %s | |
799 | |
800 To mark files as resolved: hg resolve --mark FILE''' | |
801 ) | |
802 % mergeliststr | |
803 ) | |
804 else: | |
805 msg = _(b'No unresolved merge conflicts.') | |
806 | |
807 return _commentlines(msg) | |
808 | |
809 | |
810 def morestatus(repo, fm): | |
811 statetuple = statemod.getrepostate(repo) | |
812 label = b'status.morestatus' | |
813 if statetuple: | |
814 state, helpfulmsg = statetuple | |
815 statemsg = _(b'The repository is in an unfinished *%s* state.') % state | |
816 fm.plain(b'%s\n' % _commentlines(statemsg), label=label) | |
817 conmsg = _conflictsmsg(repo) | |
818 if conmsg: | |
819 fm.plain(b'%s\n' % conmsg, label=label) | |
820 if helpfulmsg: | |
821 fm.plain(b'%s\n' % _commentlines(helpfulmsg), label=label) | |
822 | 842 |
823 | 843 |
824 def findpossible(cmd, table, strict=False): | 844 def findpossible(cmd, table, strict=False): |
825 """ | 845 """ |
826 Return cmd -> (aliases, command table entry) | 846 Return cmd -> (aliases, command table entry) |