99 self._ui = ui |
99 self._ui = ui |
100 self._filecache = {} |
100 self._filecache = {} |
101 self._parentwriters = 0 |
101 self._parentwriters = 0 |
102 self._filename = 'dirstate' |
102 self._filename = 'dirstate' |
103 self._pendingfilename = '%s.pending' % self._filename |
103 self._pendingfilename = '%s.pending' % self._filename |
|
104 self._plchangecallbacks = {} |
|
105 self._origpl = None |
104 |
106 |
105 # for consistent view between _pl() and _read() invocations |
107 # for consistent view between _pl() and _read() invocations |
106 self._pendingmode = None |
108 self._pendingmode = None |
107 |
109 |
108 def beginparentchange(self): |
110 def beginparentchange(self): |
345 raise ValueError("cannot set dirstate parent without " |
347 raise ValueError("cannot set dirstate parent without " |
346 "calling dirstate.beginparentchange") |
348 "calling dirstate.beginparentchange") |
347 |
349 |
348 self._dirty = self._dirtypl = True |
350 self._dirty = self._dirtypl = True |
349 oldp2 = self._pl[1] |
351 oldp2 = self._pl[1] |
|
352 if self._origpl is None: |
|
353 self._origpl = self._pl |
350 self._pl = p1, p2 |
354 self._pl = p1, p2 |
351 copies = {} |
355 copies = {} |
352 if oldp2 != nullid and p2 == nullid: |
356 if oldp2 != nullid and p2 == nullid: |
353 for f, s in self._map.iteritems(): |
357 for f, s in self._map.iteritems(): |
354 # Discard 'm' markers when moving away from a merge state |
358 # Discard 'm' markers when moving away from a merge state |
440 if a in self.__dict__: |
444 if a in self.__dict__: |
441 delattr(self, a) |
445 delattr(self, a) |
442 self._lastnormaltime = 0 |
446 self._lastnormaltime = 0 |
443 self._dirty = False |
447 self._dirty = False |
444 self._parentwriters = 0 |
448 self._parentwriters = 0 |
|
449 self._origpl = None |
445 |
450 |
446 def copy(self, source, dest): |
451 def copy(self, source, dest): |
447 """Mark dest as a copy of source. Unmark dest if source is None.""" |
452 """Mark dest as a copy of source. Unmark dest if source is None.""" |
448 if source == dest: |
453 if source == dest: |
449 return |
454 return |
685 else: |
690 else: |
686 self._map.pop(f, None) |
691 self._map.pop(f, None) |
687 if f in self._nonnormalset: |
692 if f in self._nonnormalset: |
688 self._nonnormalset.remove(f) |
693 self._nonnormalset.remove(f) |
689 |
694 |
|
695 if self._origpl is None: |
|
696 self._origpl = self._pl |
690 self._pl = (parent, nullid) |
697 self._pl = (parent, nullid) |
691 self._dirty = True |
698 self._dirty = True |
692 |
699 |
693 def write(self, tr): |
700 def write(self, tr): |
694 if not self._dirty: |
701 if not self._dirty: |
719 return |
726 return |
720 |
727 |
721 st = self._opener(filename, "w", atomictemp=True, checkambig=True) |
728 st = self._opener(filename, "w", atomictemp=True, checkambig=True) |
722 self._writedirstate(st) |
729 self._writedirstate(st) |
723 |
730 |
|
731 def addparentchangecallback(self, category, callback): |
|
732 """add a callback to be called when the wd parents are changed |
|
733 |
|
734 Callback will be called with the following arguments: |
|
735 dirstate, (oldp1, oldp2), (newp1, newp2) |
|
736 |
|
737 Category is a unique identifier to allow overwriting an old callback |
|
738 with a newer callback. |
|
739 """ |
|
740 self._plchangecallbacks[category] = callback |
|
741 |
724 def _writedirstate(self, st): |
742 def _writedirstate(self, st): |
|
743 # notify callbacks about parents change |
|
744 if self._origpl is not None and self._origpl != self._pl: |
|
745 for c, callback in sorted(self._plchangecallbacks.iteritems()): |
|
746 callback(self, self._origpl, self._pl) |
|
747 self._origpl = None |
725 # use the modification time of the newly created temporary file as the |
748 # use the modification time of the newly created temporary file as the |
726 # filesystem's notion of 'now' |
749 # filesystem's notion of 'now' |
727 now = util.fstat(st).st_mtime & _rangemask |
750 now = util.fstat(st).st_mtime & _rangemask |
728 |
751 |
729 # enough 'delaywrite' prevents 'pack_dirstate' from dropping |
752 # enough 'delaywrite' prevents 'pack_dirstate' from dropping |