If we know we expect data from sidedata, we read them from sidedata and nothing
else.
This avoid looking into extra for revision without sidedata entries. Such
revision will be introduced in the next changesets.
( )
hg-reviewers |
If we know we expect data from sidedata, we read them from sidedata and nothing
else.
This avoid looking into extra for revision without sidedata entries. Such
revision will be introduced in the next changesets.
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/changelog.py (29 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
eb78a2f4a537 | a5b04863dbff | Pierre-Yves David | Oct 2 2019, 2:16 PM |
the manifest node, user, and date. This object exposes a view into | the manifest node, user, and date. This object exposes a view into | ||||
the parsed object. | the parsed object. | ||||
""" | """ | ||||
__slots__ = ( | __slots__ = ( | ||||
r'_offsets', | r'_offsets', | ||||
r'_text', | r'_text', | ||||
r'_sidedata', | r'_sidedata', | ||||
r'_cpsd', | |||||
) | ) | ||||
def __new__(cls, text, sidedata): | def __new__(cls, text, sidedata, cpsd): | ||||
if not text: | if not text: | ||||
return _changelogrevision(extra=_defaultextra) | return _changelogrevision(extra=_defaultextra) | ||||
self = super(changelogrevision, cls).__new__(cls) | self = super(changelogrevision, cls).__new__(cls) | ||||
# We could return here and implement the following as an __init__. | # We could return here and implement the following as an __init__. | ||||
# But doing it here is equivalent and saves an extra function call. | # But doing it here is equivalent and saves an extra function call. | ||||
# format used: | # format used: | ||||
if text[nl3 + 1 : nl3 + 2] == b'\n': | if text[nl3 + 1 : nl3 + 2] == b'\n': | ||||
doublenl = nl3 | doublenl = nl3 | ||||
else: | else: | ||||
doublenl = text.index(b'\n\n', nl3 + 1) | doublenl = text.index(b'\n\n', nl3 + 1) | ||||
self._offsets = (nl1, nl2, nl3, doublenl) | self._offsets = (nl1, nl2, nl3, doublenl) | ||||
self._text = text | self._text = text | ||||
self._sidedata = sidedata | self._sidedata = sidedata | ||||
self._cpsd = cpsd | |||||
return self | return self | ||||
@property | @property | ||||
def manifest(self): | def manifest(self): | ||||
return bin(self._text[0 : self._offsets[0]]) | return bin(self._text[0 : self._offsets[0]]) | ||||
@property | @property | ||||
off = self._offsets | off = self._offsets | ||||
if off[2] == off[3]: | if off[2] == off[3]: | ||||
return [] | return [] | ||||
return self._text[off[2] + 1 : off[3]].split(b'\n') | return self._text[off[2] + 1 : off[3]].split(b'\n') | ||||
@property | @property | ||||
def filesadded(self): | def filesadded(self): | ||||
if sidedatamod.SD_FILESADDED in self._sidedata: | if self._cpsd: | ||||
rawindices = self._sidedata.get(sidedatamod.SD_FILESADDED) | rawindices = self._sidedata.get(sidedatamod.SD_FILESADDED) | ||||
if not rawindices: | |||||
return [] | |||||
else: | else: | ||||
rawindices = self.extra.get(b'filesadded') | rawindices = self.extra.get(b'filesadded') | ||||
if rawindices is None: | if rawindices is None: | ||||
return None | return None | ||||
return copies.decodefileindices(self.files, rawindices) | return copies.decodefileindices(self.files, rawindices) | ||||
@property | @property | ||||
def filesremoved(self): | def filesremoved(self): | ||||
if sidedatamod.SD_FILESREMOVED in self._sidedata: | if self._cpsd: | ||||
rawindices = self._sidedata.get(sidedatamod.SD_FILESREMOVED) | rawindices = self._sidedata.get(sidedatamod.SD_FILESREMOVED) | ||||
if not rawindices: | |||||
return [] | |||||
else: | else: | ||||
rawindices = self.extra.get(b'filesremoved') | rawindices = self.extra.get(b'filesremoved') | ||||
if rawindices is None: | if rawindices is None: | ||||
return None | return None | ||||
return copies.decodefileindices(self.files, rawindices) | return copies.decodefileindices(self.files, rawindices) | ||||
@property | @property | ||||
def p1copies(self): | def p1copies(self): | ||||
if sidedatamod.SD_P1COPIES in self._sidedata: | if self._cpsd: | ||||
rawcopies = self._sidedata.get(sidedatamod.SD_P1COPIES) | rawcopies = self._sidedata.get(sidedatamod.SD_P1COPIES) | ||||
if not rawcopies: | |||||
return {} | |||||
else: | else: | ||||
rawcopies = self.extra.get(b'p1copies') | rawcopies = self.extra.get(b'p1copies') | ||||
if rawcopies is None: | if rawcopies is None: | ||||
return None | return None | ||||
return copies.decodecopies(self.files, rawcopies) | return copies.decodecopies(self.files, rawcopies) | ||||
@property | @property | ||||
def p2copies(self): | def p2copies(self): | ||||
if sidedatamod.SD_P2COPIES in self._sidedata: | if self._cpsd: | ||||
rawcopies = self._sidedata.get(sidedatamod.SD_P2COPIES) | rawcopies = self._sidedata.get(sidedatamod.SD_P2COPIES) | ||||
if not rawcopies: | |||||
return {} | |||||
else: | else: | ||||
rawcopies = self.extra.get(b'p2copies') | rawcopies = self.extra.get(b'p2copies') | ||||
if rawcopies is None: | if rawcopies is None: | ||||
return None | return None | ||||
return copies.decodecopies(self.files, rawcopies) | return copies.decodecopies(self.files, rawcopies) | ||||
@property | @property | ||||
def description(self): | def description(self): | ||||
- list of files | - list of files | ||||
- commit message as a localstr | - commit message as a localstr | ||||
- dict of extra metadata | - dict of extra metadata | ||||
Unless you need to access all fields, consider calling | Unless you need to access all fields, consider calling | ||||
``changelogrevision`` instead, as it is faster for partial object | ``changelogrevision`` instead, as it is faster for partial object | ||||
access. | access. | ||||
""" | """ | ||||
c = changelogrevision(*self._revisiondata(node)) | d, s = self._revisiondata(node) | ||||
c = changelogrevision( | |||||
d, s, self._copiesstorage == b'changeset-sidedata' | |||||
) | |||||
return (c.manifest, c.user, c.date, c.files, c.description, c.extra) | return (c.manifest, c.user, c.date, c.files, c.description, c.extra) | ||||
def changelogrevision(self, nodeorrev): | def changelogrevision(self, nodeorrev): | ||||
"""Obtain a ``changelogrevision`` for a node or revision.""" | """Obtain a ``changelogrevision`` for a node or revision.""" | ||||
text, sidedata = self._revisiondata(nodeorrev) | text, sidedata = self._revisiondata(nodeorrev) | ||||
return changelogrevision(text, sidedata) | return changelogrevision( | ||||
text, sidedata, self._copiesstorage == b'changeset-sidedata' | |||||
) | |||||
def readfiles(self, node): | def readfiles(self, node): | ||||
""" | """ | ||||
short version of read that only returns the files modified by the cset | short version of read that only returns the files modified by the cset | ||||
""" | """ | ||||
text = self.revision(node) | text = self.revision(node) | ||||
if not text: | if not text: | ||||
return [] | return [] |