[PATCH 1 of 3] subrepo: introduce hgsubrepo._getctx()

Matt Harbison mharbison72 at gmail.com
Mon Jun 15 04:28:57 UTC 2015


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1434333117 14400
#      Sun Jun 14 21:51:57 2015 -0400
# Node ID 9c738d2588313bb624465495a8923b293c45b999
# Parent  ee1172a5b7e0f232e4353ea6557e29030878fcfc
subrepo: introduce hgsubrepo._getctx()

This code is already used in a couple of places, and will need to be used in
others where wdir() support is needed.  Trying to get the wdir() revision stored
in self._substate[1] when creating the object in subrepo.subrepo() resulted in
breaking various status and diff tests.  This is a far less invasive change.

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -662,6 +662,15 @@
         finally:
             lock.release()
 
+    def _getctx(self):
+        '''fetch the context for this subrepo revision, possibly a workingctx
+        '''
+        if self._ctx.rev() is None:
+            return self._repo[None]  # workingctx if parent is workingctx
+        else:
+            rev = self._state[1]
+            return self._repo[rev]
+
     @annotatesubrepoerror
     def _initrepo(self, parentrepo, source, create):
         self._repo._subparent = parentrepo


More information about the Mercurial-devel mailing list