[PATCH 3 of 3 STABLE] statichttprepo: prevent loading dirstate over HTTP on node lookup (issue5717)

Yuya Nishihara yuya at tcha.org
Wed Oct 25 09:51:02 EDT 2017


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1508936283 -32400
#      Wed Oct 25 21:58:03 2017 +0900
# Branch stable
# Node ID 02ddbac3ecc6a3da75553d290ee8e8ee2dd3367e
# Parent  6a3ea1e90c40e0d67602116f04b985efc135470a
statichttprepo: prevent loading dirstate over HTTP on node lookup (issue5717)

This seems a bit hacky, but works well. There should be no reason that
static-http repo had to load dirstate.

Initially I tried to proxy os.stat() call through vfs so that statichttpvfs
could hook it, but there wasn't a good error value which the statichttpvfs
could return to get around the util.filestat issue.

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -471,7 +471,8 @@ class changectx(basectx):
                 self._node = repo.changelog.tip()
                 self._rev = repo.changelog.rev(self._node)
                 return
-            if changeid == '.' or changeid == repo.dirstate.p1():
+            if (changeid == '.'
+                or repo.local() and changeid == repo.dirstate.p1()):
                 # this is a hack to delay/avoid loading obsmarkers
                 # when we know that '.' won't be hidden
                 self._node = repo.dirstate.p1()
@@ -536,7 +537,8 @@ class changectx(basectx):
             #
             # XXX we could avoid the unfiltered if we had a recognizable
             # exception for filtered changeset access
-            if changeid in repo.unfiltered().dirstate.parents():
+            if (repo.local()
+                and changeid in repo.unfiltered().dirstate.parents()):
                 msg = _("working directory has unknown parent '%s'!")
                 raise error.Abort(msg % short(changeid))
             try:
diff --git a/tests/test-static-http.t b/tests/test-static-http.t
--- a/tests/test-static-http.t
+++ b/tests/test-static-http.t
@@ -222,7 +222,6 @@ List of files accessed over HTTP:
   /.hg/bookmarks
   /.hg/bookmarks.current
   /.hg/cache/hgtagsfnodes1
-  /.hg/dirstate
   /.hg/requires
   /.hg/store/00changelog.i
   /.hg/store/00manifest.i
@@ -236,7 +235,6 @@ List of files accessed over HTTP:
   /remote-with-names/.hg/cache/branch2-served
   /remote-with-names/.hg/cache/hgtagsfnodes1
   /remote-with-names/.hg/cache/tags2-served
-  /remote-with-names/.hg/dirstate
   /remote-with-names/.hg/localtags
   /remote-with-names/.hg/requires
   /remote-with-names/.hg/store/00changelog.i
@@ -251,7 +249,6 @@ List of files accessed over HTTP:
   /remote/.hg/cache/hgtagsfnodes1
   /remote/.hg/cache/rbc-names-v1
   /remote/.hg/cache/tags2-served
-  /remote/.hg/dirstate
   /remote/.hg/localtags
   /remote/.hg/requires
   /remote/.hg/store/00changelog.i
@@ -268,7 +265,6 @@ List of files accessed over HTTP:
   /sub/.hg/bookmarks
   /sub/.hg/bookmarks.current
   /sub/.hg/cache/hgtagsfnodes1
-  /sub/.hg/dirstate
   /sub/.hg/requires
   /sub/.hg/store/00changelog.i
   /sub/.hg/store/00manifest.i


More information about the Mercurial-devel mailing list