hgext3rd/topic/topicmap.py
changeset 4814 48b30ff742cb
parent 4803 88472e743c64
child 4929 bb2b4f6c99dc
equal deleted inserted replaced
4812:67567d7f1174 4814:48b30ff742cb
    14 
    14 
    15 from . import (
    15 from . import (
    16     common,
    16     common,
    17 )
    17 )
    18 
    18 
    19 basefilter = set(['base', 'immutable'])
    19 basefilter = set([b'base', b'immutable'])
    20 def topicfilter(name):
    20 def topicfilter(name):
    21     """return a "topic" version of a filter level"""
    21     """return a "topic" version of a filter level"""
    22     if name in basefilter:
    22     if name in basefilter:
    23         return name
    23         return name
    24     elif name is None:
    24     elif name is None:
    25         return None
    25         return None
    26     elif name.endswith('-topic'):
    26     elif name.endswith(b'-topic'):
    27         return name
    27         return name
    28     else:
    28     else:
    29         return name + '-topic'
    29         return name + b'-topic'
    30 
    30 
    31 def istopicfilter(filtername):
    31 def istopicfilter(filtername):
    32     if filtername is None:
    32     if filtername is None:
    33         return False
    33         return False
    34     return filtername.endswith('-topic')
    34     return filtername.endswith(b'-topic')
    35 
    35 
    36 def gettopicrepo(repo):
    36 def gettopicrepo(repo):
    37     if not common.hastopicext(repo):
    37     if not common.hastopicext(repo):
    38         return repo
    38         return repo
    39     filtername = topicfilter(repo.filtername)
    39     filtername = topicfilter(repo.filtername)
    59         base = topicfilter(partialmap[plainname])
    59         base = topicfilter(partialmap[plainname])
    60 
    60 
    61         if newfilter not in funcmap:
    61         if newfilter not in funcmap:
    62             funcmap[newfilter] = revsfunc
    62             funcmap[newfilter] = revsfunc
    63             partialmap[newfilter] = base
    63             partialmap[newfilter] = base
    64     funcmap['unfiltered-topic'] = lambda repo: frozenset()
    64     funcmap[b'unfiltered-topic'] = lambda repo: frozenset()
    65     partialmap['unfiltered-topic'] = 'visible-topic'
    65     partialmap[b'unfiltered-topic'] = b'visible-topic'
    66 
    66 
    67 def _phaseshash(repo, maxrev):
    67 def _phaseshash(repo, maxrev):
    68     """uniq ID for a phase matching a set of rev"""
    68     """uniq ID for a phase matching a set of rev"""
    69     revs = set()
    69     revs = set()
    70     cl = repo.changelog
    70     cl = repo.changelog
    78     key = nullid
    78     key = nullid
    79     revs = sorted(revs)
    79     revs = sorted(revs)
    80     if revs:
    80     if revs:
    81         s = hashlib.sha1()
    81         s = hashlib.sha1()
    82         for rev in revs:
    82         for rev in revs:
    83             s.update('%d;' % rev)
    83             s.update(b'%d;' % rev)
    84         key = s.digest()
    84         key = s.digest()
    85     return key
    85     return key
    86 
    86 
    87 def modsetup(ui):
    87 def modsetup(ui):
    88     """call at uisetup time to install various wrappings"""
    88     """call at uisetup time to install various wrappings"""
    98 
    98 
    99 def commitstatus(orig, repo, node, branch, bheads=None, opts=None):
    99 def commitstatus(orig, repo, node, branch, bheads=None, opts=None):
   100     # wrap commit status use the topic branch heads
   100     # wrap commit status use the topic branch heads
   101     ctx = repo[node]
   101     ctx = repo[node]
   102     if ctx.topic() and ctx.branch() == branch:
   102     if ctx.topic() and ctx.branch() == branch:
   103         bheads = repo.branchheads("%s:%s" % (branch, ctx.topic()))
   103         bheads = repo.branchheads(b"%s:%s" % (branch, ctx.topic()))
   104 
   104 
   105     ret = orig(repo, node, branch, bheads=bheads, opts=opts)
   105     ret = orig(repo, node, branch, bheads=bheads, opts=opts)
   106 
   106 
   107     # logic copy-pasted from cmdutil.commitstatus()
   107     # logic copy-pasted from cmdutil.commitstatus()
   108     if opts is None:
   108     if opts is None:
   111         return ret
   111         return ret
   112     parents = ctx.parents()
   112     parents = ctx.parents()
   113 
   113 
   114     if (not opts.get(b'amend') and bheads and node not in bheads and not
   114     if (not opts.get(b'amend') and bheads and node not in bheads and not
   115         [x for x in parents if x.node() in bheads and x.branch() == branch]):
   115         [x for x in parents if x.node() in bheads and x.branch() == branch]):
   116         repo.ui.status(_("(consider using topic for lightweight branches."
   116         repo.ui.status(_(b"(consider using topic for lightweight branches."
   117                          " See 'hg help topic')\n"))
   117                          b" See 'hg help topic')\n"))
   118 
   118 
   119     return ret
   119     return ret
   120 
   120 
   121 def _wrapbmcache(ui):
   121 def _wrapbmcache(ui):
   122     class topiccache(_topiccache, branchmap.branchcache):
   122     class topiccache(_topiccache, branchmap.branchcache):
   177         new = self.__class__(_entries, self.tipnode, self.tiprev,
   177         new = self.__class__(_entries, self.tipnode, self.tiprev,
   178                              self.filteredhash, self._closednodes)
   178                              self.filteredhash, self._closednodes)
   179         new.phaseshash = self.phaseshash
   179         new.phaseshash = self.phaseshash
   180         return new
   180         return new
   181 
   181 
   182     def branchtip(self, branch, topic=''):
   182     def branchtip(self, branch, topic=b''):
   183         '''Return the tipmost open head on branch head, otherwise return the
   183         '''Return the tipmost open head on branch head, otherwise return the
   184         tipmost closed head on branch.
   184         tipmost closed head on branch.
   185         Raise KeyError for unknown branch.'''
   185         Raise KeyError for unknown branch.'''
   186         if topic:
   186         if topic:
   187             branch = '%s:%s' % (branch, topic)
   187             branch = b'%s:%s' % (branch, topic)
   188         return super(_topiccache, self).branchtip(branch)
   188         return super(_topiccache, self).branchtip(branch)
   189 
   189 
   190     def branchheads(self, branch, closed=False, topic=''):
   190     def branchheads(self, branch, closed=False, topic=b''):
   191         if topic:
   191         if topic:
   192             branch = '%s:%s' % (branch, topic)
   192             branch = b'%s:%s' % (branch, topic)
   193         return super(_topiccache, self).branchheads(branch, closed=closed)
   193         return super(_topiccache, self).branchheads(branch, closed=closed)
   194 
   194 
   195     def validfor(self, repo):
   195     def validfor(self, repo):
   196         """Is the cache content valid regarding a repo
   196         """Is the cache content valid regarding a repo
   197 
   197 
   227         unfi = repo.unfiltered()
   227         unfi = repo.unfiltered()
   228         oldgetbranchinfo = unfi.revbranchcache().branchinfo
   228         oldgetbranchinfo = unfi.revbranchcache().branchinfo
   229 
   229 
   230         def branchinfo(r, changelog=None):
   230         def branchinfo(r, changelog=None):
   231             info = oldgetbranchinfo(r)
   231             info = oldgetbranchinfo(r)
   232             topic = ''
   232             topic = b''
   233             ctx = unfi[r]
   233             ctx = unfi[r]
   234             if ctx.mutable():
   234             if ctx.mutable():
   235                 topic = ctx.topic()
   235                 topic = ctx.topic()
   236             branch = info[0]
   236             branch = info[0]
   237             if topic:
   237             if topic:
   238                 branch = '%s:%s' % (branch, topic)
   238                 branch = b'%s:%s' % (branch, topic)
   239             return (branch, info[1])
   239             return (branch, info[1])
   240         try:
   240         try:
   241             unfi.revbranchcache().branchinfo = branchinfo
   241             unfi.revbranchcache().branchinfo = branchinfo
   242             super(_topiccache, self).update(repo, revgen)
   242             super(_topiccache, self).update(repo, revgen)
   243             self.phaseshash = _phaseshash(repo, self.tiprev)
   243             self.phaseshash = _phaseshash(repo, self.tiprev)