##// END OF EJS Templates
rust-dirstate: call rust dirstatemap from Python...
Raphaël Gomès -
r42982:39674659 default draft
parent child Browse files
Show More
@@ -459,7 +459,7 b' def overridecalculateupdates(origfn, rep'
459 lfiles = set()
459 lfiles = set()
460 for f in actions:
460 for f in actions:
461 splitstandin = lfutil.splitstandin(f)
461 splitstandin = lfutil.splitstandin(f)
462 if splitstandin in p1:
462 if splitstandin is not None and splitstandin in p1:
463 lfiles.add(splitstandin)
463 lfiles.add(splitstandin)
464 elif lfutil.standin(f) in p1:
464 elif lfutil.standin(f) in p1:
465 lfiles.add(f)
465 lfiles.add(f)
@@ -27,14 +27,14 b' from . import ('
27 util,
27 util,
28 )
28 )
29
29
30 orig_parsers = policy.importmod(r'parsers')
30 parsers = policy.importmod(r'parsers')
31 parsers = policy.importrust(r'parsers', default=orig_parsers)
31 rustmod = policy.importrust(r'dirstate')
32
32
33 propertycache = util.propertycache
33 propertycache = util.propertycache
34 filecache = scmutil.filecache
34 filecache = scmutil.filecache
35 _rangemask = 0x7fffffff
35 _rangemask = 0x7fffffff
36
36
37 dirstatetuple = orig_parsers.dirstatetuple
37 dirstatetuple = parsers.dirstatetuple
38
38
39 class repocache(filecache):
39 class repocache(filecache):
40 """filecache for files in .hg/"""
40 """filecache for files in .hg/"""
@@ -652,7 +652,8 b' class dirstate(object):'
652 delaywrite = self._ui.configint('debug', 'dirstate.delaywrite')
652 delaywrite = self._ui.configint('debug', 'dirstate.delaywrite')
653 if delaywrite > 0:
653 if delaywrite > 0:
654 # do we have any files to delay for?
654 # do we have any files to delay for?
655 for f, e in self._map.iteritems():
655 items = self._map.iteritems()
656 for f, e in items:
656 if e[0] == 'n' and e[3] == now:
657 if e[0] == 'n' and e[3] == now:
657 import time # to avoid useless import
658 import time # to avoid useless import
658 # rather than sleep n seconds, sleep until the next
659 # rather than sleep n seconds, sleep until the next
@@ -663,6 +664,12 b' class dirstate(object):'
663 time.sleep(end - clock)
664 time.sleep(end - clock)
664 now = end # trust our estimate that the end is near now
665 now = end # trust our estimate that the end is near now
665 break
666 break
667 # since the iterator is potentially not depleted,
668 # delete the iterator to release the reference for the Rust
669 # implementation.
670 # TODO make the Rust implementation behave like Python
671 # since this would not work with a non ref-counting GC.
672 del items
666
673
667 self._map.write(st, now)
674 self._map.write(st, now)
668 self._lastnormaltime = 0
675 self._lastnormaltime = 0
@@ -1516,3 +1523,187 b' class dirstatemap(object):'
1516 for name in self._dirs:
1523 for name in self._dirs:
1517 f[normcase(name)] = name
1524 f[normcase(name)] = name
1518 return f
1525 return f
1526
1527
1528 if rustmod is not None:
1529 class dirstatemap(object):
1530 def __init__(self, ui, opener, root):
1531 self._ui = ui
1532 self._opener = opener
1533 self._root = root
1534 self._filename = 'dirstate'
1535 self._parents = None
1536 self._dirtyparents = False
1537
1538 # for consistent view between _pl() and _read() invocations
1539 self._pendingmode = None
1540
1541
1542 def addfile(self, *args, **kwargs):
1543 return self._rustmap.addfile(*args, **kwargs)
1544
1545 def removefile(self, *args, **kwargs):
1546 return self._rustmap.removefile(*args, **kwargs)
1547
1548 def dropfile(self, *args, **kwargs):
1549 return self._rustmap.dropfile(*args, **kwargs)
1550
1551 def clearambiguoustimes(self, *args, **kwargs):
1552 return self._rustmap.clearambiguoustimes(*args, **kwargs)
1553
1554 def nonnormalentries(self):
1555 return self._rustmap.nonnormalentries()
1556
1557 def get(self, *args, **kwargs):
1558 return self._rustmap.get(*args, **kwargs)
1559
1560 @propertycache
1561 def _rustmap(self):
1562 self._rustmap = rustmod.DirstateMap(self._root)
1563 self.read()
1564 return self._rustmap
1565
1566 @property
1567 def copymap(self):
1568 return self._rustmap.copymap()
1569
1570 def preload(self):
1571 self._rustmap
1572
1573 def clear(self):
1574 self._rustmap.clear()
1575 self.setparents(nullid, nullid)
1576 util.clearcachedproperty(self, "_dirs")
1577 util.clearcachedproperty(self, "_alldirs")
1578 util.clearcachedproperty(self, "dirfoldmap")
1579
1580 def items(self):
1581 return self._rustmap.items()
1582
1583 def keys(self):
1584 return iter(self._rustmap)
1585
1586 def __contains__(self, key):
1587 return key in self._rustmap
1588
1589 def __getitem__(self, item):
1590 return self._rustmap[item]
1591
1592 def __len__(self):
1593 return len(self._rustmap)
1594
1595 def __iter__(self):
1596 return iter(self._rustmap)
1597
1598 # forward for python2,3 compat
1599 iteritems = items
1600
1601 def _opendirstatefile(self):
1602 fp, mode = txnutil.trypending(self._root, self._opener,
1603 self._filename)
1604 if self._pendingmode is not None and self._pendingmode != mode:
1605 fp.close()
1606 raise error.Abort(_('working directory state may be '
1607 'changed parallelly'))
1608 self._pendingmode = mode
1609 return fp
1610
1611 def setparents(self, p1, p2):
1612 self._rustmap.setparents(p1, p2)
1613 self._parents = (p1, p2)
1614 self._dirtyparents = True
1615
1616 def parents(self):
1617 if not self._parents:
1618 try:
1619 fp = self._opendirstatefile()
1620 st = fp.read(40)
1621 fp.close()
1622 except IOError as err:
1623 if err.errno != errno.ENOENT:
1624 raise
1625 # File doesn't exist, so the current state is empty
1626 st = ''
1627
1628 try:
1629 self._parents = self._rustmap.parents(st)
1630 except ValueError:
1631 raise error.Abort(_('working directory state appears '
1632 'damaged!'))
1633
1634 return self._parents
1635
1636 def read(self):
1637 # ignore HG_PENDING because identity is used only for writing
1638 self.identity = util.filestat.frompath(
1639 self._opener.join(self._filename))
1640
1641 try:
1642 fp = self._opendirstatefile()
1643 try:
1644 st = fp.read()
1645 finally:
1646 fp.close()
1647 except IOError as err:
1648 if err.errno != errno.ENOENT:
1649 raise
1650 return
1651 if not st:
1652 return
1653
1654 parse_dirstate = util.nogc(self._rustmap.read)
1655 parents = parse_dirstate(st)
1656 if parents and not self._dirtyparents:
1657 self.setparents(*parents)
1658
1659 def write(self, st, now):
1660 parents = self.parents()
1661 st.write(self._rustmap.write(parents[0], parents[1], now))
1662 st.close()
1663 self._dirtyparents = False
1664
1665 @propertycache
1666 def filefoldmap(self):
1667 """Returns a dictionary mapping normalized case paths to their
1668 non-normalized versions.
1669 """
1670 return self._rustmap.filefoldmapasdict()
1671
1672 def hastrackeddir(self, d):
1673 self._dirs # Trigger Python's propertycache
1674 return self._rustmap.hastrackeddir(d)
1675
1676 def hasdir(self, d):
1677 self._dirs # Trigger Python's propertycache
1678 return self._rustmap.hasdir(d)
1679
1680 @propertycache
1681 def _dirs(self):
1682 return self._rustmap.getdirs()
1683
1684 @propertycache
1685 def _alldirs(self):
1686 return self._rustmap.getalldirs()
1687
1688 @propertycache
1689 def identity(self):
1690 self._rustmap
1691 return self.identity
1692
1693 @property
1694 def nonnormalset(self):
1695 nonnorm, otherparents = self._rustmap.nonnormalentries()
1696 return nonnorm
1697
1698 @property
1699 def otherparentset(self):
1700 nonnorm, otherparents = self._rustmap.nonnormalentries()
1701 return otherparents
1702
1703 @propertycache
1704 def dirfoldmap(self):
1705 f = {}
1706 normcase = util.normcase
1707 for name in self._dirs:
1708 f[normcase(name)] = name
1709 return f
General Comments 0
You need to be logged in to leave comments. Login now