hgext/evolve.py
branchstable
changeset 1330 efb75f4d55aa
parent 1311 d6a740947197
child 1331 5e82d78f5872
child 1335 50a40a8cf7be
equal deleted inserted replaced
1329:344774ef5a05 1330:efb75f4d55aa
   804     tr = repo.transaction('relocate')
   804     tr = repo.transaction('relocate')
   805     try:
   805     try:
   806         try:
   806         try:
   807             if repo['.'].rev() != dest.rev():
   807             if repo['.'].rev() != dest.rev():
   808                 merge.update(repo, dest, False, True, False)
   808                 merge.update(repo, dest, False, True, False)
   809             if repo._bookmarkcurrent:
   809             if bmactive(repo):
   810                 repo.ui.status(_("(leaving bookmark %s)\n") %
   810                 repo.ui.status(_("(leaving bookmark %s)\n") % bmactive(repo))
   811                                repo._bookmarkcurrent)
   811             bmdeactivate(repo)
   812             bookmarks.unsetcurrent(repo)
       
   813             if keepbranch:
   812             if keepbranch:
   814                 repo.dirstate.setbranch(orig.branch())
   813                 repo.dirstate.setbranch(orig.branch())
   815             r = merge.graft(repo, orig, orig.p1(), ['local', 'graft'])
   814             r = merge.graft(repo, orig, orig.p1(), ['local', 'graft'])
   816             if r[-1]:  #some conflict
   815             if r[-1]:  #some conflict
   817                 raise util.Abort(
   816                 raise util.Abort(
   862 
   861 
   863 def _bookmarksupdater(repo, oldid):
   862 def _bookmarksupdater(repo, oldid):
   864     """Return a callable update(newid) updating the current bookmark
   863     """Return a callable update(newid) updating the current bookmark
   865     and bookmarks bound to oldid to newid.
   864     and bookmarks bound to oldid to newid.
   866     """
   865     """
   867     bm = bookmarks.readcurrent(repo)
   866     bm = bmactive(repo)
   868     def updatebookmarks(newid):
   867     def updatebookmarks(newid):
   869         dirty = False
   868         dirty = False
   870         if bm:
   869         if bm:
   871             repo._bookmarks[bm] = newid
   870             repo._bookmarks[bm] = newid
   872             dirty = True
   871             dirty = True
   876                 repo._bookmarks[b] = newid
   875                 repo._bookmarks[b] = newid
   877             dirty = True
   876             dirty = True
   878         if dirty:
   877         if dirty:
   879             repo._bookmarks.write()
   878             repo._bookmarks.write()
   880     return updatebookmarks
   879     return updatebookmarks
       
   880 
       
   881 ### bookmarks api compatibility layer ###
       
   882 def bmdeactivate(repo):
       
   883     try:
       
   884         return bookmarks.deactivate(repo)
       
   885     except AttributeError:
       
   886         return bookmarks.unsetcurrent(repo)
       
   887 
       
   888 def bmactive(repo):
       
   889     try:
       
   890         return repo._activebookmark
       
   891     except AttributeError:
       
   892         return repo._bookmarkcurrent
   881 
   893 
   882 ### new command
   894 ### new command
   883 #############################
   895 #############################
   884 metadataopts = [
   896 metadataopts = [
   885     ('d', 'date', '',
   897     ('d', 'date', '',
  1591 
  1603 
  1592 shorttemplate = '[{rev}] {desc|firstline}\n'
  1604 shorttemplate = '[{rev}] {desc|firstline}\n'
  1593 
  1605 
  1594 @command('^previous',
  1606 @command('^previous',
  1595          [('B', 'move-bookmark', False,
  1607          [('B', 'move-bookmark', False,
  1596              _('Move current active bookmark after update'))],
  1608              _('Move active bookmark after update'))],
  1597          '[-B]')
  1609          '[-B]')
  1598 def cmdprevious(ui, repo, **opts):
  1610 def cmdprevious(ui, repo, **opts):
  1599     """update to parent and display summary lines"""
  1611     """update to parent and display summary lines"""
  1600     wkctx = repo[None]
  1612     wkctx = repo[None]
  1601     wparents = wkctx.parents()
  1613     wparents = wkctx.parents()
  1604 
  1616 
  1605     parents = wparents[0].parents()
  1617     parents = wparents[0].parents()
  1606     displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
  1618     displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
  1607     if len(parents) == 1:
  1619     if len(parents) == 1:
  1608         p = parents[0]
  1620         p = parents[0]
  1609         bm = bookmarks.readcurrent(repo)
  1621         bm = bmactive(repo)
  1610         shouldmove = opts.get('move_bookmark') and bm is not None
  1622         shouldmove = opts.get('move_bookmark') and bm is not None
  1611         ret = hg.update(repo, p.rev())
  1623         ret = hg.update(repo, p.rev())
  1612         if not ret:
  1624         if not ret:
  1613             if shouldmove:
  1625             if shouldmove:
  1614                 repo._bookmarks[bm] = p.node()
  1626                 repo._bookmarks[bm] = p.node()
  1615                 repo._bookmarks.write()
  1627                 repo._bookmarks.write()
  1616             else:
  1628             else:
  1617                 bookmarks.unsetcurrent(repo)
  1629                 bmdeactivate(repo)
  1618         displayer.show(p)
  1630         displayer.show(p)
  1619         return 0
  1631         return 0
  1620     else:
  1632     else:
  1621         for p in parents:
  1633         for p in parents:
  1622             displayer.show(p)
  1634             displayer.show(p)
  1623         ui.warn(_('multiple parents, explicitly update to one\n'))
  1635         ui.warn(_('multiple parents, explicitly update to one\n'))
  1624         return 1
  1636         return 1
  1625 
  1637 
  1626 @command('^next',
  1638 @command('^next',
  1627          [('B', 'move-bookmark', False,
  1639          [('B', 'move-bookmark', False,
  1628              _('Move current active bookmark after update'))],
  1640              _('Move active bookmark after update'))],
  1629          '[-B]')
  1641          '[-B]')
  1630 def cmdnext(ui, repo, **opts):
  1642 def cmdnext(ui, repo, **opts):
  1631     """update to child and display summary lines"""
  1643     """update to child and display summary lines"""
  1632     wkctx = repo[None]
  1644     wkctx = repo[None]
  1633     wparents = wkctx.parents()
  1645     wparents = wkctx.parents()
  1639     if not children:
  1651     if not children:
  1640         ui.warn(_('no non-obsolete children\n'))
  1652         ui.warn(_('no non-obsolete children\n'))
  1641         return 1
  1653         return 1
  1642     if len(children) == 1:
  1654     if len(children) == 1:
  1643         c = children[0]
  1655         c = children[0]
  1644         bm = bookmarks.readcurrent(repo)
  1656         bm = bmactive(repo)
  1645         shouldmove = opts.get('move_bookmark') and bm is not None
  1657         shouldmove = opts.get('move_bookmark') and bm is not None
  1646         ret = hg.update(repo, c.rev())
  1658         ret = hg.update(repo, c.rev())
  1647         if not ret:
  1659         if not ret:
  1648             if shouldmove:
  1660             if shouldmove:
  1649                 repo._bookmarks[bm] = c.node()
  1661                 repo._bookmarks[bm] = c.node()
  1650                 repo._bookmarks.write()
  1662                 repo._bookmarks.write()
  1651             else:
  1663             else:
  1652                 bookmarks.unsetcurrent(repo)
  1664                 bmdeactivate(repo)
  1653         displayer.show(c)
  1665         displayer.show(c)
  1654         return 0
  1666         return 0
  1655     else:
  1667     else:
  1656         for c in children:
  1668         for c in children:
  1657             displayer.show(c)
  1669             displayer.show(c)