hgext3rd/topic/__init__.py
changeset 1918 a840c5b5bbaf
parent 1917 ea4675c7a028
child 1932 880aac9dbfa6
equal deleted inserted replaced
1917:ea4675c7a028 1918:a840c5b5bbaf
   212         rewrote = 0
   212         rewrote = 0
   213         needevolve = False
   213         needevolve = False
   214         l = repo.lock()
   214         l = repo.lock()
   215         txn = repo.transaction('rewrite-topics')
   215         txn = repo.transaction('rewrite-topics')
   216         try:
   216         try:
   217            for c in repo.set('%r', change):
   217             for c in repo.set('%r', change):
   218                def filectxfn(repo, ctx, path):
   218                 def filectxfn(repo, ctx, path):
   219                    try:
   219                     try:
   220                        return c[path]
   220                         return c[path]
   221                    except error.ManifestLookupError:
   221                     except error.ManifestLookupError:
   222                        return None
   222                         return None
   223                fixedextra = dict(c.extra())
   223                 fixedextra = dict(c.extra())
   224                ui.debug('old node id is %s\n' % node.hex(c.node()))
   224                 ui.debug('old node id is %s\n' % node.hex(c.node()))
   225                ui.debug('origextra: %r\n' % fixedextra)
   225                 ui.debug('origextra: %r\n' % fixedextra)
   226                newtopic = None if clear else topic
   226                 newtopic = None if clear else topic
   227                oldtopic = fixedextra.get(constants.extrakey, None)
   227                 oldtopic = fixedextra.get(constants.extrakey, None)
   228                if oldtopic == newtopic:
   228                 if oldtopic == newtopic:
   229                    continue
   229                     continue
   230                if clear:
   230                 if clear:
   231                    del fixedextra[constants.extrakey]
   231                     del fixedextra[constants.extrakey]
   232                else:
   232                 else:
   233                    fixedextra[constants.extrakey] = topic
   233                     fixedextra[constants.extrakey] = topic
   234                if 'amend_source' in fixedextra:
   234                 if 'amend_source' in fixedextra:
   235                    # TODO: right now the commitctx wrapper in
   235                     # TODO: right now the commitctx wrapper in
   236                    # topicrepo overwrites the topic in extra if
   236                     # topicrepo overwrites the topic in extra if
   237                    # amend_source is set to support 'hg commit
   237                     # amend_source is set to support 'hg commit
   238                    # --amend'. Support for amend should be adjusted
   238                     # --amend'. Support for amend should be adjusted
   239                    # to not be so invasive.
   239                     # to not be so invasive.
   240                    del fixedextra['amend_source']
   240                     del fixedextra['amend_source']
   241                ui.debug('changing topic of %s from %s to %s\n' % (
   241                 ui.debug('changing topic of %s from %s to %s\n' % (
   242                    c, oldtopic, newtopic))
   242                     c, oldtopic, newtopic))
   243                ui.debug('fixedextra: %r\n' % fixedextra)
   243                 ui.debug('fixedextra: %r\n' % fixedextra)
   244                mc = context.memctx(
   244                 mc = context.memctx(
   245                    repo, (c.p1().node(), c.p2().node()), c.description(),
   245                     repo, (c.p1().node(), c.p2().node()), c.description(),
   246                    c.files(), filectxfn,
   246                     c.files(), filectxfn,
   247                    user=c.user(), date=c.date(), extra=fixedextra)
   247                     user=c.user(), date=c.date(), extra=fixedextra)
   248                newnode = repo.commitctx(mc)
   248                 newnode = repo.commitctx(mc)
   249                ui.debug('new node id is %s\n' % node.hex(newnode))
   249                 ui.debug('new node id is %s\n' % node.hex(newnode))
   250                needevolve = needevolve or (len(c.children()) > 0)
   250                 needevolve = needevolve or (len(c.children()) > 0)
   251                obsolete.createmarkers(repo, [(c, (repo[newnode],))])
   251                 obsolete.createmarkers(repo, [(c, (repo[newnode],))])
   252                rewrote += 1
   252                 rewrote += 1
   253            txn.close()
   253             txn.close()
   254         except:
   254         except:
   255             try:
   255             try:
   256                 txn.abort()
   256                 txn.abort()
   257             finally:
   257             finally:
   258                 repo.invalidate()
   258                 repo.invalidate()