This involves dirstatemap data mostly. Moving this one level down will remove
the needs for the dirstatemap to expose some of its internals.
This will help us to simplify more code further.
( )
Alphare |
hg-reviewers |
This involves dirstatemap data mostly. Moving this one level down will remove
the needs for the dirstatemap to expose some of its internals.
This will help us to simplify more code further.
No Linters Available |
No Unit Test Coverage |
I'm not a huge fan of simply copy-pasting the setparents logic, but I see that the next patches make them differ
Path | Packages | |||
---|---|---|---|---|
M | mercurial/dirstate.py (35 lines) | |||
M | mercurial/dirstatemap.py (66 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
92a3aa7c9015 | d97863b15cef | Pierre-Yves David | Sep 22 2021, 9:17 AM |
Status | Author | Revision | |
---|---|---|---|
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | marmoute | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin | ||
Closed | SimonSapin |
b"cannot set dirstate parent outside of " | b"cannot set dirstate parent outside of " | ||||
b"dirstate.parentchange context manager" | b"dirstate.parentchange context manager" | ||||
) | ) | ||||
self._dirty = True | self._dirty = True | ||||
oldp2 = self._pl[1] | oldp2 = self._pl[1] | ||||
if self._origpl is None: | if self._origpl is None: | ||||
self._origpl = self._pl | self._origpl = self._pl | ||||
self._map.setparents(p1, p2) | |||||
copies = {} | |||||
nullid = self._nodeconstants.nullid | nullid = self._nodeconstants.nullid | ||||
if oldp2 != nullid and p2 == nullid: | # True if we need to fold p2 related state back to a linear case | ||||
candidatefiles = self._map.non_normal_or_other_parent_paths() | fold_p2 = oldp2 != nullid and p2 == nullid | ||||
return self._map.setparents(p1, p2, fold_p2=fold_p2) | |||||
for f in candidatefiles: | |||||
s = self._map.get(f) | |||||
if s is None: | |||||
continue | |||||
# Discard "merged" markers when moving away from a merge state | |||||
if s.merged: | |||||
source = self._map.copymap.get(f) | |||||
if source: | |||||
copies[f] = source | |||||
self._map.reset_state( | |||||
f, | |||||
wc_tracked=True, | |||||
p1_tracked=True, | |||||
possibly_dirty=True, | |||||
) | |||||
# Also fix up otherparent markers | |||||
elif s.from_p2: | |||||
source = self._map.copymap.get(f) | |||||
if source: | |||||
copies[f] = source | |||||
self._map.reset_state( | |||||
f, | |||||
p1_tracked=False, | |||||
wc_tracked=True, | |||||
) | |||||
return copies | |||||
def setbranch(self, branch): | def setbranch(self, branch): | ||||
self.__class__._branch.set(self, encoding.fromlocal(branch)) | self.__class__._branch.set(self, encoding.fromlocal(branch)) | ||||
f = self._opener(b'branch', b'w', atomictemp=True, checkambig=True) | f = self._opener(b'branch', b'w', atomictemp=True, checkambig=True) | ||||
try: | try: | ||||
f.write(self._branch + b'\n') | f.write(self._branch + b'\n') | ||||
f.close() | f.close() | ||||
) | ) | ||||
else: | else: | ||||
raise error.Abort( | raise error.Abort( | ||||
_(b'working directory state appears damaged!') | _(b'working directory state appears damaged!') | ||||
) | ) | ||||
return self._parents | return self._parents | ||||
def setparents(self, p1, p2): | def setparents(self, p1, p2, fold_p2=False): | ||||
self._parents = (p1, p2) | self._parents = (p1, p2) | ||||
self._dirtyparents = True | self._dirtyparents = True | ||||
copies = {} | |||||
if fold_p2: | |||||
candidatefiles = self.non_normal_or_other_parent_paths() | |||||
for f in candidatefiles: | |||||
s = self.get(f) | |||||
if s is None: | |||||
continue | |||||
# Discard "merged" markers when moving away from a merge state | |||||
if s.merged: | |||||
source = self.copymap.get(f) | |||||
if source: | |||||
copies[f] = source | |||||
self.reset_state( | |||||
f, | |||||
wc_tracked=True, | |||||
p1_tracked=True, | |||||
possibly_dirty=True, | |||||
) | |||||
# Also fix up otherparent markers | |||||
elif s.from_p2: | |||||
source = self.copymap.get(f) | |||||
if source: | |||||
copies[f] = source | |||||
self.reset_state( | |||||
f, | |||||
p1_tracked=False, | |||||
wc_tracked=True, | |||||
) | |||||
return copies | |||||
def read(self): | def read(self): | ||||
# ignore HG_PENDING because identity is used only for writing | # ignore HG_PENDING because identity is used only for writing | ||||
self.identity = util.filestat.frompath( | self.identity = util.filestat.frompath( | ||||
self._opener.join(self._filename) | self._opener.join(self._filename) | ||||
) | ) | ||||
try: | try: | ||||
with self._opendirstatefile() as fp: | with self._opendirstatefile() as fp: | ||||
return fp.read(size) | return fp.read(size) | ||||
except IOError as err: | except IOError as err: | ||||
if err.errno != errno.ENOENT: | if err.errno != errno.ENOENT: | ||||
raise | raise | ||||
# File doesn't exist, so the current state is empty | # File doesn't exist, so the current state is empty | ||||
return b'' | return b'' | ||||
def setparents(self, p1, p2): | def setparents(self, p1, p2, fold_p2=False): | ||||
self._parents = (p1, p2) | self._parents = (p1, p2) | ||||
self._dirtyparents = True | self._dirtyparents = True | ||||
copies = {} | |||||
if fold_p2: | |||||
candidatefiles = self.non_normal_or_other_parent_paths() | |||||
for f in candidatefiles: | |||||
s = self.get(f) | |||||
if s is None: | |||||
continue | |||||
# Discard "merged" markers when moving away from a merge state | |||||
if s.merged: | |||||
source = self.copymap.get(f) | |||||
if source: | |||||
copies[f] = source | |||||
self.reset_state( | |||||
f, | |||||
wc_tracked=True, | |||||
p1_tracked=True, | |||||
possibly_dirty=True, | |||||
) | |||||
# Also fix up otherparent markers | |||||
elif s.from_p2: | |||||
source = self.copymap.get(f) | |||||
if source: | |||||
copies[f] = source | |||||
self.reset_state( | |||||
f, | |||||
p1_tracked=False, | |||||
wc_tracked=True, | |||||
) | |||||
return copies | |||||
def parents(self): | def parents(self): | ||||
if not self._parents: | if not self._parents: | ||||
if self._use_dirstate_v2: | if self._use_dirstate_v2: | ||||
self._parents = self.docket.parents | self._parents = self.docket.parents | ||||
else: | else: | ||||
read_len = self._nodelen * 2 | read_len = self._nodelen * 2 | ||||
st = self._readdirstatefile(read_len) | st = self._readdirstatefile(read_len) |