mercurial/merge.py
changeset 37110 1b158ca37ea4
parent 37109 a532b2f54f95
child 37111 aa5199c7aa42
equal deleted inserted replaced
37109:a532b2f54f95 37110:1b158ca37ea4
    59 RECORD_LABELS = b'l'
    59 RECORD_LABELS = b'l'
    60 RECORD_OVERRIDE = b't'
    60 RECORD_OVERRIDE = b't'
    61 RECORD_UNSUPPORTED_MANDATORY = b'X'
    61 RECORD_UNSUPPORTED_MANDATORY = b'X'
    62 RECORD_UNSUPPORTED_ADVISORY = b'x'
    62 RECORD_UNSUPPORTED_ADVISORY = b'x'
    63 
    63 
       
    64 MERGE_DRIVER_STATE_UNMARKED = b'u'
       
    65 MERGE_DRIVER_STATE_MARKED = b'm'
       
    66 MERGE_DRIVER_STATE_SUCCESS = b's'
       
    67 
    64 class mergestate(object):
    68 class mergestate(object):
    65     '''track 3-way merge state of individual files
    69     '''track 3-way merge state of individual files
    66 
    70 
    67     The merge state is stored on disk when needed. Two files are used: one with
    71     The merge state is stored on disk when needed. Two files are used: one with
    68     an old format (version 1), and one with a new format (version 2). Version 2
    72     an old format (version 1), and one with a new format (version 2). Version 2
   145         if node:
   149         if node:
   146             self._local = node
   150             self._local = node
   147             self._other = other
   151             self._other = other
   148         self._readmergedriver = None
   152         self._readmergedriver = None
   149         if self.mergedriver:
   153         if self.mergedriver:
   150             self._mdstate = 's'
   154             self._mdstate = MERGE_DRIVER_STATE_SUCCESS
   151         else:
   155         else:
   152             self._mdstate = 'u'
   156             self._mdstate = MERGE_DRIVER_STATE_UNMARKED
   153         shutil.rmtree(self._repo.vfs.join('merge'), True)
   157         shutil.rmtree(self._repo.vfs.join('merge'), True)
   154         self._results = {}
   158         self._results = {}
   155         self._dirty = False
   159         self._dirty = False
   156 
   160 
   157     def _read(self):
   161     def _read(self):
   166         self._other = None
   170         self._other = None
   167         for var in ('localctx', 'otherctx'):
   171         for var in ('localctx', 'otherctx'):
   168             if var in vars(self):
   172             if var in vars(self):
   169                 delattr(self, var)
   173                 delattr(self, var)
   170         self._readmergedriver = None
   174         self._readmergedriver = None
   171         self._mdstate = 's'
   175         self._mdstate = MERGE_DRIVER_STATE_SUCCESS
   172         unsupported = set()
   176         unsupported = set()
   173         records = self._readrecords()
   177         records = self._readrecords()
   174         for rtype, record in records:
   178         for rtype, record in records:
   175             if rtype == RECORD_LOCAL:
   179             if rtype == RECORD_LOCAL:
   176                 self._local = bin(record)
   180                 self._local = bin(record)
   177             elif rtype == RECORD_OTHER:
   181             elif rtype == RECORD_OTHER:
   178                 self._other = bin(record)
   182                 self._other = bin(record)
   179             elif rtype == RECORD_MERGE_DRIVER_STATE:
   183             elif rtype == RECORD_MERGE_DRIVER_STATE:
   180                 bits = record.split('\0', 1)
   184                 bits = record.split('\0', 1)
   181                 mdstate = bits[1]
   185                 mdstate = bits[1]
   182                 if len(mdstate) != 1 or mdstate not in 'ums':
   186                 if len(mdstate) != 1 or mdstate not in (
       
   187                     MERGE_DRIVER_STATE_UNMARKED, MERGE_DRIVER_STATE_MARKED,
       
   188                     MERGE_DRIVER_STATE_SUCCESS):
   183                     # the merge driver should be idempotent, so just rerun it
   189                     # the merge driver should be idempotent, so just rerun it
   184                     mdstate = 'u'
   190                     mdstate = MERGE_DRIVER_STATE_UNMARKED
   185 
   191 
   186                 self._readmergedriver = bits[0]
   192                 self._readmergedriver = bits[0]
   187                 self._mdstate = mdstate
   193                 self._mdstate = mdstate
   188             elif rtype in (RECORD_MERGED, RECORD_CHANGEDELETE_CONFLICT,
   194             elif rtype in (RECORD_MERGED, RECORD_CHANGEDELETE_CONFLICT,
   189                            RECORD_PATH_CONFLICT, RECORD_MERGE_DRIVER_MERGE):
   195                            RECORD_PATH_CONFLICT, RECORD_MERGE_DRIVER_MERGE):
  1663     finally:
  1669     finally:
  1664         ms.commit()
  1670         ms.commit()
  1665 
  1671 
  1666     unresolved = ms.unresolvedcount()
  1672     unresolved = ms.unresolvedcount()
  1667 
  1673 
  1668     if usemergedriver and not unresolved and ms.mdstate() != 's':
  1674     if (usemergedriver and not unresolved
       
  1675         and ms.mdstate() != MERGE_DRIVER_STATE_SUCCESS):
  1669         if not driverconclude(repo, ms, wctx, labels=labels):
  1676         if not driverconclude(repo, ms, wctx, labels=labels):
  1670             # XXX setting unresolved to at least 1 is a hack to make sure we
  1677             # XXX setting unresolved to at least 1 is a hack to make sure we
  1671             # error out
  1678             # error out
  1672             unresolved = max(unresolved, 1)
  1679             unresolved = max(unresolved, 1)
  1673 
  1680