comparison 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
comparison
equal deleted inserted replaced
42141:0e41f40b01cc 42142:5382d8f8530b
85 '%s\0%s' % (k, copies[k]) 85 '%s\0%s' % (k, copies[k])
86 for k in sorted(copies) 86 for k in sorted(copies)
87 ] 87 ]
88 return "\n".join(items) 88 return "\n".join(items)
89 89
90 def decodecopies(data):
91 try:
92 copies = {}
93 for l in data.split('\n'):
94 k, v = l.split('\0')
95 copies[k] = v
96 return copies
97 except ValueError:
98 # Perhaps someone had chosen the same key name (e.g. "p1copies") and
99 # used different syntax for the value.
100 return None
101
90 def stripdesc(desc): 102 def stripdesc(desc):
91 """strip trailing whitespace and leading and trailing empty lines""" 103 """strip trailing whitespace and leading and trailing empty lines"""
92 return '\n'.join([l.rstrip() for l in desc.splitlines()]).strip('\n') 104 return '\n'.join([l.rstrip() for l in desc.splitlines()]).strip('\n')
93 105
94 class appender(object): 106 class appender(object):
282 off = self._offsets 294 off = self._offsets
283 if off[2] == off[3]: 295 if off[2] == off[3]:
284 return [] 296 return []
285 297
286 return self._text[off[2] + 1:off[3]].split('\n') 298 return self._text[off[2] + 1:off[3]].split('\n')
299
300 @property
301 def p1copies(self):
302 rawcopies = self.extra.get('p1copies')
303 return rawcopies and decodecopies(rawcopies)
304
305 @property
306 def p2copies(self):
307 rawcopies = self.extra.get('p2copies')
308 return rawcopies and decodecopies(rawcopies)
287 309
288 @property 310 @property
289 def description(self): 311 def description(self):
290 return encoding.tolocal(self._text[self._offsets[3] + 2:]) 312 return encoding.tolocal(self._text[self._offsets[3] + 2:])
291 313