hgext/histedit.py
changeset 33351 154298576d44
parent 33350 b320ff822c7e
child 33444 c4e39512a661
equal deleted inserted replaced
33350:b320ff822c7e 33351:154298576d44
  1171                     for n in succs[1:]:
  1171                     for n in succs[1:]:
  1172                         ui.debug(m % node.short(n))
  1172                         ui.debug(m % node.short(n))
  1173 
  1173 
  1174     if not state.keep:
  1174     if not state.keep:
  1175         if mapping:
  1175         if mapping:
  1176             movebookmarks(ui, repo, mapping, state.topmost, ntm)
  1176             movetopmostbookmarks(repo, state.topmost, ntm)
  1177             # TODO update mq state
  1177             # TODO update mq state
  1178     else:
  1178     else:
  1179         mapping = {}
  1179         mapping = {}
  1180 
  1180 
  1181     for n in tmpnodes:
  1181     for n in tmpnodes:
  1182         mapping[n] = ()
  1182         mapping[n] = ()
  1183 
  1183 
  1184     safecleanupnode(ui, repo, mapping)
  1184     # remove entries about unknown nodes
       
  1185     nodemap = repo.unfiltered().changelog.nodemap
       
  1186     mapping = {k: v for k, v in mapping.items()
       
  1187                if k in nodemap and all(n in nodemap for n in v)}
       
  1188     scmutil.cleanupnodes(repo, mapping, 'histedit')
  1185 
  1189 
  1186     state.clear()
  1190     state.clear()
  1187     if os.path.exists(repo.sjoin('undo')):
  1191     if os.path.exists(repo.sjoin('undo')):
  1188         os.unlink(repo.sjoin('undo'))
  1192         os.unlink(repo.sjoin('undo'))
  1189     if repo.vfs.exists('histedit-last-edit.txt'):
  1193     if repo.vfs.exists('histedit-last-edit.txt'):
  1559             marks = repo._bookmarks
  1563             marks = repo._bookmarks
  1560             for name in oldbmarks:
  1564             for name in oldbmarks:
  1561                 marks[name] = newtopmost
  1565                 marks[name] = newtopmost
  1562             marks.recordchange(tr)
  1566             marks.recordchange(tr)
  1563 
  1567 
  1564 def movebookmarks(ui, repo, mapping, oldtopmost, newtopmost):
       
  1565     """Move bookmark from old to newly created node"""
       
  1566     if not mapping:
       
  1567         # if nothing got rewritten there is not purpose for this function
       
  1568         return
       
  1569     movetopmostbookmarks(repo, oldtopmost, newtopmost)
       
  1570     moves = []
       
  1571     for bk, old in sorted(repo._bookmarks.iteritems()):
       
  1572         base = old
       
  1573         new = mapping.get(base, None)
       
  1574         if new is None:
       
  1575             continue
       
  1576         while not new:
       
  1577             # base is killed, trying with parent
       
  1578             base = repo[base].p1().node()
       
  1579             new = mapping.get(base, (base,))
       
  1580             # nothing to move
       
  1581         moves.append((bk, new[-1]))
       
  1582     if moves:
       
  1583         lock = tr = None
       
  1584         try:
       
  1585             lock = repo.lock()
       
  1586             tr = repo.transaction('histedit')
       
  1587             marks = repo._bookmarks
       
  1588             for mark, new in moves:
       
  1589                 old = marks[mark]
       
  1590                 marks[mark] = new
       
  1591             marks.recordchange(tr)
       
  1592             tr.close()
       
  1593         finally:
       
  1594             release(tr, lock)
       
  1595 
       
  1596 def cleanupnode(ui, repo, nodes):
  1568 def cleanupnode(ui, repo, nodes):
  1597     """strip a group of nodes from the repository
  1569     """strip a group of nodes from the repository
  1598 
  1570 
  1599     The set of node to strip may contains unknown nodes."""
  1571     The set of node to strip may contains unknown nodes."""
  1600     with repo.lock():
  1572     with repo.lock():
  1608         nodes = sorted(n for n in nodes if n in nm)
  1580         nodes = sorted(n for n in nodes if n in nm)
  1609         roots = [c.node() for c in repo.set("roots(%ln)", nodes)]
  1581         roots = [c.node() for c in repo.set("roots(%ln)", nodes)]
  1610         if roots:
  1582         if roots:
  1611             repair.strip(ui, repo, roots)
  1583             repair.strip(ui, repo, roots)
  1612 
  1584 
  1613 def safecleanupnode(ui, repo, nodes):
       
  1614     """strip or obsolete nodes
       
  1615 
       
  1616     nodes could be either a set or dict which maps to replacements.
       
  1617     nodes could be unknown (outside the repo).
       
  1618     """
       
  1619     supportsmarkers = obsolete.isenabled(repo, obsolete.createmarkersopt)
       
  1620     if supportsmarkers:
       
  1621         if util.safehasattr(nodes, 'get'):
       
  1622             # nodes is a dict-like mapping
       
  1623             # use unfiltered repo for successors in case they are hidden
       
  1624             urepo = repo.unfiltered()
       
  1625             def getmarker(prec):
       
  1626                 succs = tuple(urepo[n] for n in nodes.get(prec, ()))
       
  1627                 return (repo[prec], succs)
       
  1628         else:
       
  1629             # nodes is a set-like
       
  1630             def getmarker(prec):
       
  1631                 return (repo[prec], ())
       
  1632         # sort by revision number because it sound "right"
       
  1633         sortednodes = sorted([n for n in nodes if n in repo],
       
  1634                              key=repo.changelog.rev)
       
  1635         markers = [getmarker(t) for t in sortednodes]
       
  1636         if markers:
       
  1637             obsolete.createmarkers(repo, markers, operation='histedit')
       
  1638     else:
       
  1639         return cleanupnode(ui, repo, nodes)
       
  1640 
       
  1641 def stripwrapper(orig, ui, repo, nodelist, *args, **kwargs):
  1585 def stripwrapper(orig, ui, repo, nodelist, *args, **kwargs):
  1642     if isinstance(nodelist, str):
  1586     if isinstance(nodelist, str):
  1643         nodelist = [nodelist]
  1587         nodelist = [nodelist]
  1644     if os.path.exists(os.path.join(repo.path, 'histedit-state')):
  1588     if os.path.exists(os.path.join(repo.path, 'histedit-state')):
  1645         state = histeditstate(repo)
  1589         state = histeditstate(repo)