Patchwork [2,of,6,mergedriver] mergestate: raise structured exception for unsupported merge records

login
register
mail settings
Submitter Siddharth Agarwal
Date Nov. 17, 2015, 11:58 p.m.
Message ID <a879917dec18a4621476.1447804720@dev666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/11446/
State Accepted
Headers show

Comments

Siddharth Agarwal - Nov. 17, 2015, 11:58 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1447798312 28800
#      Tue Nov 17 14:11:52 2015 -0800
# Node ID a879917dec18a4621476c8af18724f5d5696c663
# Parent  a27ce132c9b2bdbc38884f64c1cc76fdd92e50aa
mergestate: raise structured exception for unsupported merge records

We're going to catch this exception in 'hg summary' to print a better error
message.

This code is pretty untested, so there are no changes to test output. In
upcoming patches we're going to test the output more thoroughly.

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -110,6 +110,7 @@  class mergestate(object):
             del self.otherctx
         self._readmergedriver = None
         self._mdstate = 's'
+        unsupported = set()
         records = self._readrecords()
         for rtype, record in records:
             if rtype == 'L':
@@ -129,10 +130,12 @@  class mergestate(object):
                 bits = record.split('\0')
                 self._state[bits[0]] = bits[1:]
             elif not rtype.islower():
-                raise error.Abort(_('unsupported merge state record: %s')
-                                   % rtype)
+                unsupported.add(rtype)
         self._dirty = False
 
+        if unsupported:
+            raise error.UnsupportedMergeRecords(unsupported)
+
     def _readrecords(self):
         """Read merge state from disk and return a list of record (TYPE, data)