Commit 60df0a6b authored by Wez Furlong's avatar Wez Furlong Committed by Facebook Github Bot

getdeps: memoize eden prefetched dirs

Summary:
currently, the implementation of `eden prefetch` calls into
a mercurial function that is overly eager in making network connections,
which results in what should be a fast NOP second prefetch call taking
more time than is desirable.

This diff adds a little cache to avoid repeatedly calling prefetch
for the same directory more than once for the life of the getdeps
process.

Given the usage pattern of getdeps it is OK that we don't provide
a way to invalidate this cache.

Reviewed By: fanzeyi

Differential Revision: D18005408

fbshipit-source-id: 0ec3f477da1043a5a715704b512c81fcfaa0acde
parent 6e0a487c
...@@ -10,6 +10,9 @@ import shutil ...@@ -10,6 +10,9 @@ import shutil
import subprocess import subprocess
PREFETCHED_DIRS = set()
def is_eden(dirpath): def is_eden(dirpath):
"""Returns True if the specified directory is the root directory of, """Returns True if the specified directory is the root directory of,
or is a sub-directory of an Eden mount.""" or is a sub-directory of an Eden mount."""
...@@ -29,7 +32,8 @@ def prefetch_dir_if_eden(dirpath): ...@@ -29,7 +32,8 @@ def prefetch_dir_if_eden(dirpath):
performed by copytree makes this more expensive than is desirable performed by copytree makes this more expensive than is desirable
so we help accelerate things by performing a prefetch on the so we help accelerate things by performing a prefetch on the
source directory """ source directory """
if not is_eden(dirpath): global PREFETCHED_DIRS
if not is_eden(dirpath) or dirpath in PREFETCHED_DIRS:
return return
root = find_eden_root(dirpath) root = find_eden_root(dirpath)
rel = os.path.relpath(dirpath, root) rel = os.path.relpath(dirpath, root)
...@@ -37,6 +41,7 @@ def prefetch_dir_if_eden(dirpath): ...@@ -37,6 +41,7 @@ def prefetch_dir_if_eden(dirpath):
# TODO: this should be edenfsctl but until I swing through a new # TODO: this should be edenfsctl but until I swing through a new
# package deploy, I only have `eden` on my mac to test this # package deploy, I only have `eden` on my mac to test this
subprocess.call(["eden", "prefetch", "--repo", root, "--silent", "%s/**" % rel]) subprocess.call(["eden", "prefetch", "--repo", root, "--silent", "%s/**" % rel])
PREFETCHED_DIRS.add(dirpath)
def copytree(src_dir, dest_dir, ignore=None): def copytree(src_dir, dest_dir, ignore=None):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment