hgext/git/dirstate.py
changeset 49077 20d151e43429
parent 48946 642e31cb55f0
child 49078 020328be00cb
--- a/hgext/git/dirstate.py	Mon Apr 18 11:15:29 2022 -0400
+++ b/hgext/git/dirstate.py	Mon Apr 18 11:21:09 2022 -0400
@@ -4,6 +4,7 @@
 
 from mercurial.node import sha1nodeconstants
 from mercurial import (
+    dirstatemap,
     error,
     extensions,
     match as matchmod,
@@ -11,6 +12,9 @@
     scmutil,
     util,
 )
+from mercurial.dirstateutils import (
+    timestamp,
+)
 from mercurial.interfaces import (
     dirstate as intdirstate,
     util as interfaceutil,
@@ -18,6 +22,9 @@
 
 from . import gitutil
 
+
+DirstateItem = dirstatemap.DirstateItem
+propertycache = util.propertycache
 pygit2 = gitutil.get_pygit2()
 
 
@@ -67,13 +74,28 @@
 
 @interfaceutil.implementer(intdirstate.idirstate)
 class gitdirstate:
-    def __init__(self, ui, root, gitrepo):
+    def __init__(self, ui, vfs, gitrepo, use_dirstate_v2):
         self._ui = ui
-        self._root = os.path.dirname(root)
+        self._root = os.path.dirname(vfs.base)
+        self._opener = vfs
         self.git = gitrepo
         self._plchangecallbacks = {}
         # TODO: context.poststatusfixup is bad and uses this attribute
         self._dirty = False
+        self._mapcls = dirstatemap.dirstatemap
+        self._use_dirstate_v2 = use_dirstate_v2
+
+    @propertycache
+    def _map(self):
+        """Return the dirstate contents (see documentation for dirstatemap)."""
+        self._map = self._mapcls(
+            self._ui,
+            self._opener,
+            self._root,
+            sha1nodeconstants,
+            self._use_dirstate_v2,
+        )
+        return self._map
 
     def p1(self):
         try:
@@ -142,6 +164,13 @@
             [],
             [],
         )
+
+        try:
+            mtime_boundary = timestamp.get_fs_now(self._opener)
+        except OSError:
+            # In largefiles or readonly context
+            mtime_boundary = None
+
         gstatus = self.git.status()
         for path, status in gstatus.items():
             path = pycompat.fsencode(path)
@@ -193,6 +222,7 @@
             scmutil.status(
                 modified, added, removed, deleted, unknown, ignored, clean
             ),
+            mtime_boundary,
         )
 
     def flagfunc(self, buildfallback):
@@ -205,6 +235,13 @@
             os.path.dirname(pycompat.fsencode(self.git.path))
         )
 
+    def get_entry(self, path):
+        """return a DirstateItem for the associated path"""
+        entry = self._map.get(path)
+        if entry is None:
+            return DirstateItem()
+        return entry
+
     def normalize(self, path):
         normed = util.normcase(path)
         assert normed == path, b"TODO handling of case folding: %s != %s" % (