Mercurial > hg
comparison mercurial/dirstate.py @ 47510:94c58f3aab56
dirstate: add a `in_merge` property
This factor the "p2 is not null" check and is fairly simpler to read.
Differential Revision: https://phab.mercurial-scm.org/D10952
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sat, 03 Jul 2021 20:12:46 +0200 |
parents | 8b7e47802deb |
children | eaae39894312 |
comparison
equal
deleted
inserted
replaced
47509:80dc1d452993 | 47510:94c58f3aab56 |
---|---|
334 def p1(self): | 334 def p1(self): |
335 return self._validate(self._pl[0]) | 335 return self._validate(self._pl[0]) |
336 | 336 |
337 def p2(self): | 337 def p2(self): |
338 return self._validate(self._pl[1]) | 338 return self._validate(self._pl[1]) |
339 | |
340 @property | |
341 def in_merge(self): | |
342 """True if a merge is in progress""" | |
343 return self._pl[1] != self._nodeconstants.nullid | |
339 | 344 |
340 def branch(self): | 345 def branch(self): |
341 return encoding.tolocal(self._branch) | 346 return encoding.tolocal(self._branch) |
342 | 347 |
343 def setparents(self, p1, p2=None): | 348 def setparents(self, p1, p2=None): |
511 # modifications that happen within the same timeslot. | 516 # modifications that happen within the same timeslot. |
512 self._lastnormaltime = mtime | 517 self._lastnormaltime = mtime |
513 | 518 |
514 def normallookup(self, f): | 519 def normallookup(self, f): |
515 '''Mark a file normal, but possibly dirty.''' | 520 '''Mark a file normal, but possibly dirty.''' |
516 if self._pl[1] != self._nodeconstants.nullid: | 521 if self.in_merge: |
517 # if there is a merge going on and the file was either | 522 # if there is a merge going on and the file was either |
518 # in state 'm' (-1) or coming from other parent (-2) before | 523 # in state 'm' (-1) or coming from other parent (-2) before |
519 # being removed, restore that state. | 524 # being removed, restore that state. |
520 entry = self._map.get(f) | 525 entry = self._map.get(f) |
521 if entry is not None: | 526 if entry is not None: |
533 self._addpath(f, b'n', 0, possibly_dirty=True) | 538 self._addpath(f, b'n', 0, possibly_dirty=True) |
534 self._map.copymap.pop(f, None) | 539 self._map.copymap.pop(f, None) |
535 | 540 |
536 def otherparent(self, f): | 541 def otherparent(self, f): |
537 '''Mark as coming from the other parent, always dirty.''' | 542 '''Mark as coming from the other parent, always dirty.''' |
538 if self._pl[1] == self._nodeconstants.nullid: | 543 if not self.in_merge: |
539 msg = _(b"setting %r to other parent only allowed in merges") % f | 544 msg = _(b"setting %r to other parent only allowed in merges") % f |
540 raise error.Abort(msg) | 545 raise error.Abort(msg) |
541 if f in self and self[f] == b'n': | 546 if f in self and self[f] == b'n': |
542 # merge-like | 547 # merge-like |
543 self._addpath(f, b'm', 0, from_p2=True) | 548 self._addpath(f, b'm', 0, from_p2=True) |
554 def remove(self, f): | 559 def remove(self, f): |
555 '''Mark a file removed.''' | 560 '''Mark a file removed.''' |
556 self._dirty = True | 561 self._dirty = True |
557 oldstate = self[f] | 562 oldstate = self[f] |
558 size = 0 | 563 size = 0 |
559 if self._pl[1] != self._nodeconstants.nullid: | 564 if self.in_merge: |
560 entry = self._map.get(f) | 565 entry = self._map.get(f) |
561 if entry is not None: | 566 if entry is not None: |
562 # backup the previous state | 567 # backup the previous state |
563 if entry[0] == b'm': # merge | 568 if entry[0] == b'm': # merge |
564 size = NONNORMAL | 569 size = NONNORMAL |
570 if size == 0: | 575 if size == 0: |
571 self._map.copymap.pop(f, None) | 576 self._map.copymap.pop(f, None) |
572 | 577 |
573 def merge(self, f): | 578 def merge(self, f): |
574 '''Mark a file merged.''' | 579 '''Mark a file merged.''' |
575 if self._pl[1] == self._nodeconstants.nullid: | 580 if not self.in_merge: |
576 return self.normallookup(f) | 581 return self.normallookup(f) |
577 return self.otherparent(f) | 582 return self.otherparent(f) |
578 | 583 |
579 def drop(self, f): | 584 def drop(self, f): |
580 '''Drop a file from the dirstate''' | 585 '''Drop a file from the dirstate''' |