hgext/evolve.py
changeset 1506 a55c691f4cc0
parent 1505 53a6dbc33e36
child 1507 6f574c76c142
equal deleted inserted replaced
1505:53a6dbc33e36 1506:a55c691f4cc0
   803     """Return (nodeid, created) where nodeid is the identifier of the
   803     """Return (nodeid, created) where nodeid is the identifier of the
   804     changeset generated by the rewrite process, and created is True if
   804     changeset generated by the rewrite process, and created is True if
   805     nodeid was actually created. If created is False, nodeid
   805     nodeid was actually created. If created is False, nodeid
   806     references a changeset existing before the rewrite call.
   806     references a changeset existing before the rewrite call.
   807     """
   807     """
   808     if True:
   808     wlock = lock = tr = None
       
   809     try:
       
   810         wlock = repo.wlock()
       
   811         lock = repo.lock()
       
   812         tr = repo.transaction('rewrite')
   809         if len(old.parents()) > 1: #XXX remove this unecessary limitation.
   813         if len(old.parents()) > 1: #XXX remove this unecessary limitation.
   810             raise error.Abort(_('cannot amend merge changesets'))
   814             raise error.Abort(_('cannot amend merge changesets'))
   811         base = old.p1()
   815         base = old.p1()
   812         updatebookmarks = _bookmarksupdater(repo, old.node())
   816         updatebookmarks = _bookmarksupdater(repo, old.node(), tr)
   813 
   817 
   814         # commit a new version of the old changeset, including the update
   818         # commit a new version of the old changeset, including the update
   815         # collect all files which might be affected
   819         # collect all files which might be affected
   816         files = set(old.files())
   820         files = set(old.files())
   817         for u in updates:
   821         for u in updates:
   871         newid = repo.commitctx(new)
   875         newid = repo.commitctx(new)
   872         new = repo[newid]
   876         new = repo[newid]
   873         created = len(repo) != revcount
   877         created = len(repo) != revcount
   874         updatebookmarks(newid)
   878         updatebookmarks(newid)
   875 
   879 
       
   880         tr.close()
   876         return newid, created
   881         return newid, created
       
   882     finally:
       
   883         lockmod.release(lock, wlock, tr)
   877 
   884 
   878 class MergeFailure(util.Abort):
   885 class MergeFailure(util.Abort):
   879     pass
   886     pass
   880 
   887 
   881 def relocate(repo, orig, dest, keepbranch=False):
   888 def relocate(repo, orig, dest, keepbranch=False):
   970             for book in oldbookmarks:
   977             for book in oldbookmarks:
   971                 repo._bookmarks[book] = dest.node()
   978                 repo._bookmarks[book] = dest.node()
   972         for book in destbookmarks: # restore bookmark that rebase move
   979         for book in destbookmarks: # restore bookmark that rebase move
   973             repo._bookmarks[book] = dest.node()
   980             repo._bookmarks[book] = dest.node()
   974         if oldbookmarks or destbookmarks:
   981         if oldbookmarks or destbookmarks:
   975             repo._bookmarks.write()
   982             repo._bookmarks.recordchange(tr)
   976         tr.close()
   983         tr.close()
   977     finally:
   984     finally:
   978         tr.release()
   985         tr.release()
   979     return nodenew
   986     return nodenew
   980 
   987 
   981 def _bookmarksupdater(repo, oldid):
   988 def _bookmarksupdater(repo, oldid, tr):
   982     """Return a callable update(newid) updating the current bookmark
   989     """Return a callable update(newid) updating the current bookmark
   983     and bookmarks bound to oldid to newid.
   990     and bookmarks bound to oldid to newid.
   984     """
   991     """
   985     def updatebookmarks(newid):
   992     def updatebookmarks(newid):
   986         dirty = False
   993         dirty = False
   988         if oldbookmarks:
   995         if oldbookmarks:
   989             for b in oldbookmarks:
   996             for b in oldbookmarks:
   990                 repo._bookmarks[b] = newid
   997                 repo._bookmarks[b] = newid
   991             dirty = True
   998             dirty = True
   992         if dirty:
   999         if dirty:
   993             repo._bookmarks.write()
  1000             repo._bookmarks.recordchange(tr)
   994     return updatebookmarks
  1001     return updatebookmarks
   995 
  1002 
   996 ### bookmarks api compatibility layer ###
  1003 ### bookmarks api compatibility layer ###
   997 def bmdeactivate(repo):
  1004 def bmdeactivate(repo):
   998     try:
  1005     try:
  1780         repo.ui.write('hg commit --msg "bumped update to %s"')
  1787         repo.ui.write('hg commit --msg "bumped update to %s"')
  1781         return 0
  1788         return 0
  1782     if progresscb: progresscb()
  1789     if progresscb: progresscb()
  1783     newid = tmpctx = None
  1790     newid = tmpctx = None
  1784     tmpctx = bumped
  1791     tmpctx = bumped
  1785     bmupdate = _bookmarksupdater(repo, bumped.node())
       
  1786     # Basic check for common parent. Far too complicated and fragile
  1792     # Basic check for common parent. Far too complicated and fragile
  1787     tr = repo.transaction('bumped-stabilize')
  1793     tr = repo.transaction('bumped-stabilize')
       
  1794     bmupdate = _bookmarksupdater(repo, bumped.node(), tr)
  1788     try:
  1795     try:
  1789         if not list(repo.set('parents(%d) and parents(%d)', bumped, prec)):
  1796         if not list(repo.set('parents(%d) and parents(%d)', bumped, prec)):
  1790             # Need to rebase the changeset at the right place
  1797             # Need to rebase the changeset at the right place
  1791             repo.ui.status(
  1798             repo.ui.status(
  1792                 _('rebasing to destination parent: %s\n') % prec.p1())
  1799                 _('rebasing to destination parent: %s\n') % prec.p1())
  2336             #
  2343             #
  2337             # but then revset took a lazy arrow in the knee and became much
  2344             # but then revset took a lazy arrow in the knee and became much
  2338             # slower. The new forms makes as much sense and a much faster.
  2345             # slower. The new forms makes as much sense and a much faster.
  2339             for dest in ctx.ancestors():
  2346             for dest in ctx.ancestors():
  2340                 if not dest.obsolete():
  2347                 if not dest.obsolete():
  2341                     updatebookmarks = _bookmarksupdater(repo, ctx.node())
  2348                     updatebookmarks = _bookmarksupdater(repo, ctx.node(), tr)
  2342                     updatebookmarks(dest.node())
  2349                     updatebookmarks(dest.node())
  2343                     break
  2350                     break
  2344 
  2351 
  2345         tr.close()
  2352         tr.close()
  2346     finally:
  2353     finally:
  2521         if old.phase() == phases.public:
  2528         if old.phase() == phases.public:
  2522             raise util.Abort(_("cannot rewrite immutable changeset"))
  2529             raise util.Abort(_("cannot rewrite immutable changeset"))
  2523         if len(old.parents()) > 1:
  2530         if len(old.parents()) > 1:
  2524             raise util.Abort(_("cannot uncommit merge changeset"))
  2531             raise util.Abort(_("cannot uncommit merge changeset"))
  2525         oldphase = old.phase()
  2532         oldphase = old.phase()
  2526         updatebookmarks = _bookmarksupdater(repo, old.node())
       
  2527 
  2533 
  2528 
  2534 
  2529         rev = None
  2535         rev = None
  2530         if opts.get('rev'):
  2536         if opts.get('rev'):
  2531             rev = scmutil.revsingle(repo, opts.get('rev'))
  2537             rev = scmutil.revsingle(repo, opts.get('rev'))
  2538         if disallowunstable and not onahead:
  2544         if disallowunstable and not onahead:
  2539             raise util.Abort(_("cannot uncommit in the middle of a stack"))
  2545             raise util.Abort(_("cannot uncommit in the middle of a stack"))
  2540 
  2546 
  2541         # Recommit the filtered changeset
  2547         # Recommit the filtered changeset
  2542         tr = repo.transaction('uncommit')
  2548         tr = repo.transaction('uncommit')
       
  2549         updatebookmarks = _bookmarksupdater(repo, old.node(), tr)
  2543         newid = None
  2550         newid = None
  2544         includeorexclude = opts.get('include') or opts.get('exclude')
  2551         includeorexclude = opts.get('include') or opts.get('exclude')
  2545         if (pats or includeorexclude or opts.get('all')):
  2552         if (pats or includeorexclude or opts.get('all')):
  2546             match = scmutil.match(old, pats, opts)
  2553             match = scmutil.match(old, pats, opts)
  2547             newid = _commitfiltered(repo, old, match, target=rev)
  2554             newid = _commitfiltered(repo, old, match, target=rev)
  2632                 raise util.Abort(_("cannot split commit: %s not a head") % ctx)
  2639                 raise util.Abort(_("cannot split commit: %s not a head") % ctx)
  2633 
  2640 
  2634         if len(ctx.parents()) > 1:
  2641         if len(ctx.parents()) > 1:
  2635             raise util.Abort(_("cannot split merge commits"))
  2642             raise util.Abort(_("cannot split merge commits"))
  2636         prev = ctx.p1()
  2643         prev = ctx.p1()
  2637         bmupdate = _bookmarksupdater(repo, ctx.node())
  2644         bmupdate = _bookmarksupdater(repo, ctx.node(), tr)
  2638         bookactive = bmactive(repo)
  2645         bookactive = bmactive(repo)
  2639         if bookactive is not None:
  2646         if bookactive is not None:
  2640             repo.ui.status(_("(leaving bookmark %s)\n") % bmactive(repo))
  2647             repo.ui.status(_("(leaving bookmark %s)\n") % bmactive(repo))
  2641         bmdeactivate(repo)
  2648         bmdeactivate(repo)
  2642         hg.update(repo, prev)
  2649         hg.update(repo, prev)