diff mercurial/changelog.py @ 42142:5382d8f8530b

changelog: parse copy metadata if available in extras This lets read back the copy metadata we just started writing. There are still many places left to teach about getting the copy information from the changeset, but we have enough ({file_copies}, specifically) that we can add it now and have some test coverage of it. Differential Revision: https://phab.mercurial-scm.org/D6186
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 27 Dec 2017 22:05:20 -0800
parents 0e41f40b01cc
children 278dcb24e535
line wrap: on
line diff
--- a/mercurial/changelog.py	Wed Dec 27 19:49:36 2017 -0800
+++ b/mercurial/changelog.py	Wed Dec 27 22:05:20 2017 -0800
@@ -87,6 +87,18 @@
     ]
     return "\n".join(items)
 
+def decodecopies(data):
+    try:
+        copies = {}
+        for l in data.split('\n'):
+            k, v = l.split('\0')
+            copies[k] = v
+        return copies
+    except ValueError:
+        # Perhaps someone had chosen the same key name (e.g. "p1copies") and
+        # used different syntax for the value.
+        return None
+
 def stripdesc(desc):
     """strip trailing whitespace and leading and trailing empty lines"""
     return '\n'.join([l.rstrip() for l in desc.splitlines()]).strip('\n')
@@ -286,6 +298,16 @@
         return self._text[off[2] + 1:off[3]].split('\n')
 
     @property
+    def p1copies(self):
+        rawcopies = self.extra.get('p1copies')
+        return rawcopies and decodecopies(rawcopies)
+
+    @property
+    def p2copies(self):
+        rawcopies = self.extra.get('p2copies')
+        return rawcopies and decodecopies(rawcopies)
+
+    @property
     def description(self):
         return encoding.tolocal(self._text[self._offsets[3] + 2:])