Mercurial > hg
comparison hgext/histedit.py @ 31528:2b599f5468a4
histedit: inline cleanupnode
Move "cleanupnode" (unsafe strip) into "safecleanupnode" so it's impossible
to call the unsafe function directly.
This helps reduce future programming errors.
author | Jun Wu <quark@fb.com> |
---|---|
date | Mon, 13 Mar 2017 22:30:07 -0700 |
parents | 6f0b7475cf9a |
children | c4dd1e7c1dab |
comparison
equal
deleted
inserted
replaced
31527:6f0b7475cf9a | 31528:2b599f5468a4 |
---|---|
1578 marks.recordchange(tr) | 1578 marks.recordchange(tr) |
1579 tr.close() | 1579 tr.close() |
1580 finally: | 1580 finally: |
1581 release(tr, lock) | 1581 release(tr, lock) |
1582 | 1582 |
1583 def cleanupnode(ui, repo, name, nodes): | |
1584 """strip a group of nodes from the repository | |
1585 | |
1586 The set of node to strip may contains unknown nodes.""" | |
1587 ui.debug('should strip %s nodes %s\n' % | |
1588 (name, ', '.join([node.short(n) for n in nodes]))) | |
1589 with repo.lock(): | |
1590 # do not let filtering get in the way of the cleanse | |
1591 # we should probably get rid of obsolescence marker created during the | |
1592 # histedit, but we currently do not have such information. | |
1593 repo = repo.unfiltered() | |
1594 # Find all nodes that need to be stripped | |
1595 # (we use %lr instead of %ln to silently ignore unknown items) | |
1596 nm = repo.changelog.nodemap | |
1597 nodes = sorted(n for n in nodes if n in nm) | |
1598 roots = [c.node() for c in repo.set("roots(%ln)", nodes)] | |
1599 for c in roots: | |
1600 # We should process node in reverse order to strip tip most first. | |
1601 # but this trigger a bug in changegroup hook. | |
1602 # This would reduce bundle overhead | |
1603 repair.strip(ui, repo, c) | |
1604 | |
1605 def safecleanupnode(ui, repo, name, nodes): | 1583 def safecleanupnode(ui, repo, name, nodes): |
1606 """strip or obsolete nodes | 1584 """strip or obsolete nodes |
1607 | 1585 |
1608 nodes could be either a set or dict which maps to replacements. | 1586 nodes could be either a set or dict which maps to replacements. |
1609 nodes could be unknown (outside the repo). | 1587 nodes could be unknown (outside the repo). |
1626 key=repo.changelog.rev) | 1604 key=repo.changelog.rev) |
1627 markers = [getmarker(t) for t in sortednodes] | 1605 markers = [getmarker(t) for t in sortednodes] |
1628 if markers: | 1606 if markers: |
1629 obsolete.createmarkers(repo, markers) | 1607 obsolete.createmarkers(repo, markers) |
1630 else: | 1608 else: |
1631 return cleanupnode(ui, repo, name, nodes) | 1609 ui.debug('should strip %s nodes %s\n' % |
1610 (name, ', '.join([node.short(n) for n in nodes]))) | |
1611 with repo.lock(): | |
1612 # Do not let filtering get in the way of the cleanse we should | |
1613 # probably get rid of obsolescence marker created during the | |
1614 # histedit, but we currently do not have such information. | |
1615 repo = repo.unfiltered() | |
1616 # Find all nodes that need to be stripped | |
1617 # (we use %lr instead of %ln to silently ignore unknown items) | |
1618 nm = repo.changelog.nodemap | |
1619 nodes = sorted(n for n in nodes if n in nm) | |
1620 roots = [c.node() for c in repo.set("roots(%ln)", nodes)] | |
1621 for c in roots: | |
1622 # We should process node in reverse order to strip tip most | |
1623 # first, but this trigger a bug in changegroup hook. This | |
1624 # would reduce bundle overhead | |
1625 repair.strip(ui, repo, c) | |
1632 | 1626 |
1633 def stripwrapper(orig, ui, repo, nodelist, *args, **kwargs): | 1627 def stripwrapper(orig, ui, repo, nodelist, *args, **kwargs): |
1634 if isinstance(nodelist, str): | 1628 if isinstance(nodelist, str): |
1635 nodelist = [nodelist] | 1629 nodelist = [nodelist] |
1636 if os.path.exists(os.path.join(repo.path, 'histedit-state')): | 1630 if os.path.exists(os.path.join(repo.path, 'histedit-state')): |