equal
deleted
inserted
replaced
12 import errno |
12 import errno |
13 import os |
13 import os |
14 import stat |
14 import stat |
15 |
15 |
16 from .i18n import _ |
16 from .i18n import _ |
17 from .node import nullid |
|
18 from .pycompat import delattr |
17 from .pycompat import delattr |
19 |
18 |
20 from hgdemandimport import tracing |
19 from hgdemandimport import tracing |
21 |
20 |
22 from . import ( |
21 from . import ( |
312 return self._validate(self._pl[1]) |
311 return self._validate(self._pl[1]) |
313 |
312 |
314 def branch(self): |
313 def branch(self): |
315 return encoding.tolocal(self._branch) |
314 return encoding.tolocal(self._branch) |
316 |
315 |
317 def setparents(self, p1, p2=nullid): |
316 def setparents(self, p1, p2=None): |
318 """Set dirstate parents to p1 and p2. |
317 """Set dirstate parents to p1 and p2. |
319 |
318 |
320 When moving from two parents to one, 'm' merged entries a |
319 When moving from two parents to one, 'm' merged entries a |
321 adjusted to normal and previous copy records discarded and |
320 adjusted to normal and previous copy records discarded and |
322 returned by the call. |
321 returned by the call. |
323 |
322 |
324 See localrepo.setparents() |
323 See localrepo.setparents() |
325 """ |
324 """ |
|
325 if p2 is None: |
|
326 p2 = self._nodeconstants.nullid |
326 if self._parentwriters == 0: |
327 if self._parentwriters == 0: |
327 raise ValueError( |
328 raise ValueError( |
328 b"cannot set dirstate parent outside of " |
329 b"cannot set dirstate parent outside of " |
329 b"dirstate.parentchange context manager" |
330 b"dirstate.parentchange context manager" |
330 ) |
331 ) |
333 oldp2 = self._pl[1] |
334 oldp2 = self._pl[1] |
334 if self._origpl is None: |
335 if self._origpl is None: |
335 self._origpl = self._pl |
336 self._origpl = self._pl |
336 self._map.setparents(p1, p2) |
337 self._map.setparents(p1, p2) |
337 copies = {} |
338 copies = {} |
338 if oldp2 != nullid and p2 == nullid: |
339 if ( |
|
340 oldp2 != self._nodeconstants.nullid |
|
341 and p2 == self._nodeconstants.nullid |
|
342 ): |
339 candidatefiles = self._map.nonnormalset.union( |
343 candidatefiles = self._map.nonnormalset.union( |
340 self._map.otherparentset |
344 self._map.otherparentset |
341 ) |
345 ) |
342 for f in candidatefiles: |
346 for f in candidatefiles: |
343 s = self._map.get(f) |
347 s = self._map.get(f) |
457 # modifications that happen within the same timeslot. |
461 # modifications that happen within the same timeslot. |
458 self._lastnormaltime = mtime |
462 self._lastnormaltime = mtime |
459 |
463 |
460 def normallookup(self, f): |
464 def normallookup(self, f): |
461 '''Mark a file normal, but possibly dirty.''' |
465 '''Mark a file normal, but possibly dirty.''' |
462 if self._pl[1] != nullid: |
466 if self._pl[1] != self._nodeconstants.nullid: |
463 # if there is a merge going on and the file was either |
467 # if there is a merge going on and the file was either |
464 # in state 'm' (-1) or coming from other parent (-2) before |
468 # in state 'm' (-1) or coming from other parent (-2) before |
465 # being removed, restore that state. |
469 # being removed, restore that state. |
466 entry = self._map.get(f) |
470 entry = self._map.get(f) |
467 if entry is not None: |
471 if entry is not None: |
479 self._addpath(f, b'n', 0, -1, -1) |
483 self._addpath(f, b'n', 0, -1, -1) |
480 self._map.copymap.pop(f, None) |
484 self._map.copymap.pop(f, None) |
481 |
485 |
482 def otherparent(self, f): |
486 def otherparent(self, f): |
483 '''Mark as coming from the other parent, always dirty.''' |
487 '''Mark as coming from the other parent, always dirty.''' |
484 if self._pl[1] == nullid: |
488 if self._pl[1] == self._nodeconstants.nullid: |
485 raise error.Abort( |
489 raise error.Abort( |
486 _(b"setting %r to other parent only allowed in merges") % f |
490 _(b"setting %r to other parent only allowed in merges") % f |
487 ) |
491 ) |
488 if f in self and self[f] == b'n': |
492 if f in self and self[f] == b'n': |
489 # merge-like |
493 # merge-like |
501 def remove(self, f): |
505 def remove(self, f): |
502 '''Mark a file removed.''' |
506 '''Mark a file removed.''' |
503 self._dirty = True |
507 self._dirty = True |
504 oldstate = self[f] |
508 oldstate = self[f] |
505 size = 0 |
509 size = 0 |
506 if self._pl[1] != nullid: |
510 if self._pl[1] != self._nodeconstants.nullid: |
507 entry = self._map.get(f) |
511 entry = self._map.get(f) |
508 if entry is not None: |
512 if entry is not None: |
509 # backup the previous state |
513 # backup the previous state |
510 if entry[0] == b'm': # merge |
514 if entry[0] == b'm': # merge |
511 size = -1 |
515 size = -1 |
517 if size == 0: |
521 if size == 0: |
518 self._map.copymap.pop(f, None) |
522 self._map.copymap.pop(f, None) |
519 |
523 |
520 def merge(self, f): |
524 def merge(self, f): |
521 '''Mark a file merged.''' |
525 '''Mark a file merged.''' |
522 if self._pl[1] == nullid: |
526 if self._pl[1] == self._nodeconstants.nullid: |
523 return self.normallookup(f) |
527 return self.normallookup(f) |
524 return self.otherparent(f) |
528 return self.otherparent(f) |
525 |
529 |
526 def drop(self, f): |
530 def drop(self, f): |
527 '''Drop a file from the dirstate''' |
531 '''Drop a file from the dirstate''' |
636 to_lookup = changedfilesset & set(allfiles) |
640 to_lookup = changedfilesset & set(allfiles) |
637 to_drop = changedfilesset - to_lookup |
641 to_drop = changedfilesset - to_lookup |
638 |
642 |
639 if self._origpl is None: |
643 if self._origpl is None: |
640 self._origpl = self._pl |
644 self._origpl = self._pl |
641 self._map.setparents(parent, nullid) |
645 self._map.setparents(parent, self._nodeconstants.nullid) |
642 |
646 |
643 for f in to_lookup: |
647 for f in to_lookup: |
644 self.normallookup(f) |
648 self.normallookup(f) |
645 for f in to_drop: |
649 for f in to_drop: |
646 self.drop(f) |
650 self.drop(f) |
1457 return self.copymap |
1461 return self.copymap |
1458 |
1462 |
1459 def clear(self): |
1463 def clear(self): |
1460 self._map.clear() |
1464 self._map.clear() |
1461 self.copymap.clear() |
1465 self.copymap.clear() |
1462 self.setparents(nullid, nullid) |
1466 self.setparents(self._nodeconstants.nullid, self._nodeconstants.nullid) |
1463 util.clearcachedproperty(self, b"_dirs") |
1467 util.clearcachedproperty(self, b"_dirs") |
1464 util.clearcachedproperty(self, b"_alldirs") |
1468 util.clearcachedproperty(self, b"_alldirs") |
1465 util.clearcachedproperty(self, b"filefoldmap") |
1469 util.clearcachedproperty(self, b"filefoldmap") |
1466 util.clearcachedproperty(self, b"dirfoldmap") |
1470 util.clearcachedproperty(self, b"dirfoldmap") |
1467 util.clearcachedproperty(self, b"nonnormalset") |
1471 util.clearcachedproperty(self, b"nonnormalset") |
1634 self._parents = ( |
1638 self._parents = ( |
1635 st[: self._nodelen], |
1639 st[: self._nodelen], |
1636 st[self._nodelen : 2 * self._nodelen], |
1640 st[self._nodelen : 2 * self._nodelen], |
1637 ) |
1641 ) |
1638 elif l == 0: |
1642 elif l == 0: |
1639 self._parents = (nullid, nullid) |
1643 self._parents = ( |
|
1644 self._nodeconstants.nullid, |
|
1645 self._nodeconstants.nullid, |
|
1646 ) |
1640 else: |
1647 else: |
1641 raise error.Abort( |
1648 raise error.Abort( |
1642 _(b'working directory state appears damaged!') |
1649 _(b'working directory state appears damaged!') |
1643 ) |
1650 ) |
1644 |
1651 |
1792 self._rustmap |
1799 self._rustmap |
1793 |
1800 |
1794 def clear(self): |
1801 def clear(self): |
1795 self._rustmap.clear() |
1802 self._rustmap.clear() |
1796 self._inner_rustmap.clear() |
1803 self._inner_rustmap.clear() |
1797 self.setparents(nullid, nullid) |
1804 self.setparents( |
|
1805 self._nodeconstants.nullid, self._nodeconstants.nullid |
|
1806 ) |
1798 util.clearcachedproperty(self, b"_dirs") |
1807 util.clearcachedproperty(self, b"_dirs") |
1799 util.clearcachedproperty(self, b"_alldirs") |
1808 util.clearcachedproperty(self, b"_alldirs") |
1800 util.clearcachedproperty(self, b"dirfoldmap") |
1809 util.clearcachedproperty(self, b"dirfoldmap") |
1801 |
1810 |
1802 def items(self): |
1811 def items(self): |