##// END OF EJS Templates
dirstate: add a function to update tracking status while "moving" parents...
marmoute -
r48392:0f5c203e default
parent child Browse files
Show More
@@ -72,6 +72,17 b' def _getfsnow(vfs):'
72 vfs.unlink(tmpname)
72 vfs.unlink(tmpname)
73
73
74
74
75 def requires_parents_change(func):
76 def wrap(self, *args, **kwargs):
77 if not self.pendingparentchange():
78 msg = 'calling `%s` outside of a parentchange context'
79 msg %= func.__name__
80 raise error.ProgrammingError(msg)
81 return func(self, *args, **kwargs)
82
83 return wrap
84
85
75 @interfaceutil.implementer(intdirstate.idirstate)
86 @interfaceutil.implementer(intdirstate.idirstate)
76 class dirstate(object):
87 class dirstate(object):
77 def __init__(
88 def __init__(
@@ -440,6 +451,44 b' class dirstate(object):'
440 def copies(self):
451 def copies(self):
441 return self._map.copymap
452 return self._map.copymap
442
453
454 @requires_parents_change
455 def update_file_reference(
456 self,
457 filename,
458 p1_tracked,
459 ):
460 """Set a file as tracked in the parent (or not)
461
462 This is to be called when adjust the dirstate to a new parent after an history
463 rewriting operation.
464
465 It should not be called during a merge (p2 != nullid) and only within
466 a `with dirstate.parentchange():` context.
467 """
468 if self.in_merge:
469 msg = b'update_file_reference should not be called when merging'
470 raise error.ProgrammingError(msg)
471 entry = self._map.get(filename)
472 if entry is None:
473 wc_tracked = False
474 else:
475 wc_tracked = entry.tracked
476 if p1_tracked and wc_tracked:
477 # the underlying reference might have changed, we will have to
478 # check it.
479 self.normallookup(filename)
480 elif not (p1_tracked or wc_tracked):
481 # the file is no longer relevant to anyone
482 self._drop(filename)
483 elif (not p1_tracked) and wc_tracked:
484 if not entry.added:
485 self._add(filename)
486 elif p1_tracked and not wc_tracked:
487 if entry is None or not entry.removed:
488 self._remove(filename)
489 else:
490 assert False, 'unreachable'
491
443 def _addpath(
492 def _addpath(
444 self,
493 self,
445 f,
494 f,
@@ -1485,25 +1485,15 b' def movedirstate(repo, newctx, match=Non'
1485 copies = dict(ds.copies())
1485 copies = dict(ds.copies())
1486 ds.setparents(newctx.node(), repo.nullid)
1486 ds.setparents(newctx.node(), repo.nullid)
1487 s = newctx.status(oldctx, match=match)
1487 s = newctx.status(oldctx, match=match)
1488
1488 for f in s.modified:
1489 for f in s.modified:
1489 if ds[f] == b'r':
1490 ds.update_file_reference(f, p1_tracked=True)
1490 # modified + removed -> removed
1491 continue
1492 ds.normallookup(f)
1493
1491
1494 for f in s.added:
1492 for f in s.added:
1495 if ds[f] == b'r':
1493 ds.update_file_reference(f, p1_tracked=False)
1496 # added + removed -> unknown
1497 ds.drop(f)
1498 elif ds[f] != b'a':
1499 ds.add(f)
1500
1494
1501 for f in s.removed:
1495 for f in s.removed:
1502 if ds[f] == b'a':
1496 ds.update_file_reference(f, p1_tracked=True)
1503 # removed + added -> normal
1504 ds.normallookup(f)
1505 elif ds[f] != b'r':
1506 ds.remove(f)
1507
1497
1508 # Merge old parent and old working dir copies
1498 # Merge old parent and old working dir copies
1509 oldcopies = copiesmod.pathcopies(newctx, oldctx, match)
1499 oldcopies = copiesmod.pathcopies(newctx, oldctx, match)
General Comments 0
You need to be logged in to leave comments. Login now