D7595: status: outputting structured unfinished-operation information

rdamazio (Rodrigo Damazio Bovendorp) phabricator at mercurial-scm.org
Tue Dec 10 06:40:50 UTC 2019


rdamazio created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This adds a new item in the json/template output for morestatus. For backwards
  compatibility, I put this behind a config option (but I'd be happy to remove
  that if nobody thinks it's a concern), and added item types to all entries.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/cmdutil.py
  mercurial/commands.py
  mercurial/configitems.py
  tests/test-conflict.t
  tests/test-status.t

CHANGE DETAILS

diff --git a/tests/test-status.t b/tests/test-status.t
--- a/tests/test-status.t
+++ b/tests/test-status.t
@@ -254,35 +254,43 @@
   $ hg status -A -Tjson
   [
    {
+    "itemtype": "file",
     "path": "added",
     "status": "A"
    },
    {
+    "itemtype": "file",
     "path": "copied",
     "source": "modified",
     "status": "A"
    },
    {
+    "itemtype": "file",
     "path": "removed",
     "status": "R"
    },
    {
+    "itemtype": "file",
     "path": "deleted",
     "status": "!"
    },
    {
+    "itemtype": "file",
     "path": "unknown",
     "status": "?"
    },
    {
+    "itemtype": "file",
     "path": "ignored",
     "status": "I"
    },
    {
+    "itemtype": "file",
     "path": ".hgignore",
     "status": "C"
    },
    {
+    "itemtype": "file",
     "path": "modified",
     "status": "C"
    }
@@ -558,6 +566,7 @@
   $ hg status --config ui.formatdebug=True --rev 1 1
   status = [
       {
+          'itemtype': 'file',
           'path': '1/2/3/4/5/b.txt',
           'status': 'R'
       },
diff --git a/tests/test-conflict.t b/tests/test-conflict.t
--- a/tests/test-conflict.t
+++ b/tests/test-conflict.t
@@ -63,16 +63,38 @@
   $ hg status -Tjson
   [
    {
+    "itemtype": "file",
     "path": "a",
     "status": "M",
     "unresolved": true
    },
    {
+    "itemtype": "file",
     "path": "a.orig",
     "status": "?"
    }
   ]
 
+  $ hg status -Tjson --config commands.status.morestatus-item=1
+  [
+   {
+    "itemtype": "file",
+    "path": "a",
+    "status": "M",
+    "unresolved": true
+   },
+   {
+    "itemtype": "file",
+    "path": "a.orig",
+    "status": "?"
+   },
+   {
+    "itemtype": "morestatus",
+    "unfinished": "merge",
+    "unfinishedmsg": "To continue:    hg commit\nTo abort:       hg merge --abort"
+   }
+  ]
+
   $ cat a
   Small Mathematical Series.
   1
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -244,6 +244,9 @@
     b'commands', b'show.aliasprefix', default=list,
 )
 coreconfigitem(
+    b'commands', b'status.morestatus-item', default=False,
+)
+coreconfigitem(
     b'commands', b'status.relative', default=False,
 )
 coreconfigitem(
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -6884,7 +6884,7 @@
             for f in files:
                 fm.startitem()
                 fm.context(ctx=ctx2)
-                fm.data(path=f)
+                fm.data(itemtype=b'file', path=f)
                 fm.condwrite(showchar, b'status', b'%s ', char, label=label)
                 fm.plain(fmt % uipathfn(f), label=label)
                 if f in copy:
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -786,6 +786,7 @@
     unfinishedmsg = attr.ib()
     inmergestate = attr.ib()
     unresolvedpaths = attr.ib()
+    adddataitem = attr.ib()
     _label = b'status.morestatus'
 
     def formatfile(self, path, fm):
@@ -797,6 +798,11 @@
                      ) % self.unfinishedop
         fm.plain(b'%s\n' % _commentlines(statemsg), label=self._label)
 
+        if self.adddataitem:
+            fm.startitem()
+            fm.data(itemtype=b'morestatus', unfinished=self.unfinishedop,
+                    unfinishedmsg=self.unfinishedmsg)
+
         self._formatconflicts(fm)
         if self.unfinishedmsg:
             fm.plain(b'%s\n' % _commentlines(self.unfinishedmsg),
@@ -841,8 +847,9 @@
     unresolved = None
     if mergestate.active():
         unresolved = sorted(mergestate.unresolved())
+    dataitem = repo.ui.config(b'commands', b'status.morestatus-item')
     return morestatus(repo.root, unfinishedop, unfinishedmsg,
-                      unresolved is not None, unresolved)
+                      unresolved is not None, unresolved, dataitem)
 
 
 def findpossible(cmd, table, strict=False):



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


More information about the Mercurial-devel mailing list