Mercurial > hgrepos > DevTools > mercurial-extensions
changeset 243:6b8a6329875a
Read all mergeblock types into separate dicts -- but preserve the order in the standard dict
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Tue, 06 Nov 2018 23:16:41 +0100 |
| parents | aba2e1d3ac96 |
| children | 6df0980520a2 |
| files | extensions/timestamps.py |
| diffstat | 1 files changed, 64 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/extensions/timestamps.py Mon Nov 05 09:38:58 2018 +0100 +++ b/extensions/timestamps.py Tue Nov 06 23:16:41 2018 +0100 @@ -615,8 +615,15 @@ self._init() def _init(self): + self._version = self._encoding = None + # the standard data (defined also the order) self._d = collections.OrderedDict() - self._version = self._encoding = None + # the local merge block + self._local = collections.OrderedDict() + # the base merge block + self._base = collections.OrderedDict() + # the other merge block + self._other = collections.OrderedDict() @classmethod def create(cls_, ui, @@ -675,7 +682,16 @@ datano = 0 for lineno, mergeblock_type, record in db_reader(fp): if mergeblock_type: - continue + if mergeblock_type == '<': + mdata = self._local + elif mergeblock_type == '|': + mdata = self._base + elif mergeblock_type == '=': + mdata = self._other + else: + raise ValueError("unknown mergeblock_type") + else: + mdata = None if len(record) == 2: k, v = record if self._version is None: @@ -683,36 +699,59 @@ if k.startswith("/"): raise ValueError( "invalid absolute path in line %d" % lineno) - self._d[k] = v - datano += 1 + if mergeblock_type: + mdata[k] = v + self._d[k] = None + else: + self._d[k] = v + datano += 1 elif not record: - self._d["/-%d/" % lineno] = None + if mergeblock_type: + mdata["/-%d/" % lineno] = '' + self._d["/-%d/" % lineno] = None + else: + self._d["/-%d/" % lineno] = '' elif len(record) == 1: if record[0].startswith("#"): - self._d["/comment-%d" % lineno] = record[0] + if mergeblock_type: + mdata = record[0] + self._d["/comment-%d" % lineno] = None + else: + self._d["/comment-%d" % lineno] = record[0] elif record[0].startswith("version="): - if self._version is None: - self._d["/version/"] = self._version = \ - int(record[0][8:], 10) - if self._version != 1: + if mergeblock_type: + mdata["/version/"] = int(record[0][8:], 10) + self._d["/version/"] = None + else: + if self._version is None: + self._d["/version/"] = self._version = \ + int(record[0][8:], 10) + + if self._version != 1: + raise ValueError( + "unknown version: %d" % self._version) + else: raise ValueError( - "unknown version: %d" % self._version) - else: - raise ValueError("duplicate version record in database") + "duplicate version record in database") elif record[0].startswith("encoding="): - if self._version is None: - raise ValueError("no version record given yet") - if self._encoding is None: - if datano: + if mergeblock_type: + mdata["/encoding/"] = record[0][9:] + self._d["/encoding/"] = None + else: + if self._version is None: + raise ValueError("no version record given yet") + if self._encoding is None: + if datano: + raise ValueError( + "cannot change encoding after reading some" + " data in line %d" % lineno) + self._d["/encoding/"] = self._encoding = \ + record[0][9:] + if self._encoding != "binary": + raise ValueError("unknown encoding in database") + else: raise ValueError( - "cannot change encoding after reading some" - " data in line %d" % lineno) - self._d["/encoding/"] = self._encoding = record[0][9:] - if self._encoding != "binary": - raise ValueError("unknown encoding in database") - else: - raise ValueError( - "duplicate encoding record in database") + "duplicate encoding record in database") else: raise ValueError("unknown record type in line %d" % lineno)
