# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1605892658 28800
#      Fri Nov 20 09:17:38 2020 -0800
# Node ID 600aec73f3091af53677c4dda374c4343a360007
# Parent  98399dd1b96cb4d1990bb693e748a095cd7cb43c
errors: format "abort: " text in a new Abort.format() method

This remove some duplication we had.

Differential Revision: https://phab.mercurial-scm.org/D9348

diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
--- a/mercurial/chgserver.py
+++ b/mercurial/chgserver.py
@@ -512,9 +512,7 @@
             self.cresult.write(b'exit 255')
             return
         except error.Abort as inst:
-            self.ui.error(_(b"abort: %s\n") % inst.message)
-            if inst.hint:
-                self.ui.error(_(b"(%s)\n") % inst.hint)
+            self.ui.error(inst.format())
             self.ui.flush()
             self.cresult.write(b'exit 255')
             return
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -256,9 +256,7 @@
             if req.fmsg:
                 req.ui.fmsg = req.fmsg
         except error.Abort as inst:
-            ferr.write(_(b"abort: %s\n") % inst.message)
-            if inst.hint:
-                ferr.write(_(b"(%s)\n") % inst.hint)
+            ferr.write(inst.format())
             return -1
         except error.ParseError as inst:
             ferr.write(inst.format())
diff --git a/mercurial/error.py b/mercurial/error.py
--- a/mercurial/error.py
+++ b/mercurial/error.py
@@ -182,6 +182,14 @@
             # may raise another exception.
             return pycompat.sysstr(self.__bytes__())
 
+    def format(self):
+        from .i18n import _
+
+        message = _(b"abort: %s\n") % self.message
+        if self.hint:
+            message += _(b"(%s)\n") % self.hint
+        return message
+
 
 class InputError(Abort):
     """Indicates that the user made an error in their input.
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -230,9 +230,7 @@
             detailed_exit_code = 30
         elif isinstance(inst, error.CanceledError):
             detailed_exit_code = 250
-        ui.error(_(b"abort: %s\n") % inst.message)
-        if inst.hint:
-            ui.error(_(b"(%s)\n") % inst.hint)
+        ui.error(inst.format())
     except error.WorkerError as inst:
         # Don't print a message -- the worker already should have
         return inst.status_code
diff --git a/mercurial/wireprotov1server.py b/mercurial/wireprotov1server.py
--- a/mercurial/wireprotov1server.py
+++ b/mercurial/wireprotov1server.py
@@ -685,9 +685,7 @@
                     # We did not change it to minimise code change.
                     # This need to be moved to something proper.
                     # Feel free to do it.
-                    procutil.stderr.write(b"abort: %s\n" % exc.message)
-                    if exc.hint is not None:
-                        procutil.stderr.write(b"(%s)\n" % exc.hint)
+                    procutil.stderr.write(exc.format())
                     procutil.stderr.flush()
                     return wireprototypes.pushres(
                         0, output.getvalue() if output else b''