update: add update.name-cache, update.path-cache config options

These set default values of the --name-cache and --path-cache command
line options, respectively.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
Martí Bolívar 2021-04-07 15:12:55 -07:00 committed by Marti Bolivar
parent 4cb03b0fd5
commit aba4164ca9
2 changed files with 58 additions and 29 deletions

View File

@ -817,6 +817,10 @@ class Update(_ProjectCommand):
self.narrow = args.narrow or config.getboolean('update', 'narrow',
fallback=False)
self.path_cache = args.path_cache or config.get('update', 'path-cache',
fallback=None)
self.name_cache = args.name_cache or config.get('update', 'name-cache',
fallback=None)
self.group_filter: List[str] = []
@ -1151,26 +1155,29 @@ class Update(_ProjectCommand):
def project_cache(self, project):
# Find the absolute path to a pre-existing local clone of a project
# and return it. If the search fails, return None.
name_cache, path_cache = self.args.name_cache, self.args.path_cache
if name_cache is not None:
maybe = Path(name_cache) / project.name
if self.name_cache is not None:
maybe = Path(self.name_cache) / project.name
if maybe.is_dir():
log.dbg(f'found {project.name} in --name-cache {name_cache}',
level=log.VERBOSE_VERY)
log.dbg(
f'found {project.name} in --name-cache {self.name_cache}',
level=log.VERBOSE_VERY)
return os.fspath(maybe)
else:
log.dbg(f'{project.name} not in --name-cache {name_cache}',
level=log.VERBOSE_VERY)
elif self.args.path_cache is not None:
maybe = Path(self.args.path_cache) / project.path
log.dbg(
f'{project.name} not in --name-cache {self.name_cache}',
level=log.VERBOSE_VERY)
elif self.path_cache is not None:
maybe = Path(self.path_cache) / project.path
if maybe.is_dir():
log.dbg(f'found {project.path} in --path-cache {path_cache}',
level=log.VERBOSE_VERY)
log.dbg(
f'found {project.path} in --path-cache {self.path_cache}',
level=log.VERBOSE_VERY)
return os.fspath(maybe)
else:
log.dbg(f'{project.path} not in --path-cache {path_cache}',
level=log.VERBOSE_VERY)
log.dbg(
f'{project.path} not in --path-cache {self.path_cache}',
level=log.VERBOSE_VERY)
return None

View File

@ -969,23 +969,34 @@ def test_update_name_cache(tmpdir):
# network if it doesn't have to.
name_cache_dir = tmpdir / 'name_cache'
create_repo(name_cache_dir / 'foo')
create_repo(name_cache_dir / 'bar')
foo_head = rev_parse(name_cache_dir / 'foo', 'HEAD')
bar_head = rev_parse(name_cache_dir / 'bar', 'HEAD')
workspace = tmpdir / 'workspace'
setup_cache_workspace(workspace, foo_head, bar_head)
workspace.chdir()
foo = workspace / 'subdir' / 'foo'
bar = workspace / 'bar'
cmd(f'update --name-cache {name_cache_dir}', cwd=workspace)
# Test the command line option.
cmd(f'update --name-cache {name_cache_dir}')
assert foo.check(dir=1)
assert bar.check(dir=1)
assert rev_parse(foo, 'HEAD') == foo_head
assert rev_parse(bar, 'HEAD') == bar_head
assert (workspace / 'subdir' / 'foo').check(dir=1)
assert (workspace / 'bar').check(dir=1)
assert rev_parse(workspace / 'subdir' / 'foo', 'HEAD') == foo_head
assert rev_parse(workspace / 'bar', 'HEAD') == bar_head
# Move the repositories out of the way and test the configuration option.
# (We can't use shutil.rmtree here because Windows.)
shutil.move(os.fspath(foo), os.fspath(tmpdir))
shutil.move(os.fspath(bar), os.fspath(tmpdir))
cmd(f'config update.name-cache {name_cache_dir}')
cmd('update')
assert foo.check(dir=1)
assert bar.check(dir=1)
assert rev_parse(foo, 'HEAD') == foo_head
assert rev_parse(bar, 'HEAD') == bar_head
def test_update_path_cache(tmpdir):
@ -993,23 +1004,34 @@ def test_update_path_cache(tmpdir):
# network if it doesn't have to.
path_cache_dir = tmpdir / 'path_cache_dir'
create_repo(path_cache_dir / 'subdir' / 'foo')
create_repo(path_cache_dir / 'bar')
foo_head = rev_parse(path_cache_dir / 'subdir' / 'foo', 'HEAD')
bar_head = rev_parse(path_cache_dir / 'bar', 'HEAD')
workspace = tmpdir / 'workspace'
setup_cache_workspace(workspace, foo_head, bar_head)
workspace.chdir()
foo = workspace / 'subdir' / 'foo'
bar = workspace / 'bar'
cmd(f'update --path-cache {path_cache_dir}', cwd=workspace)
# Test the command line option.
cmd(f'update --path-cache {path_cache_dir}')
assert foo.check(dir=1)
assert bar.check(dir=1)
assert rev_parse(foo, 'HEAD') == foo_head
assert rev_parse(bar, 'HEAD') == bar_head
assert (workspace / 'subdir' / 'foo').check(dir=1)
assert (workspace / 'bar').check(dir=1)
assert rev_parse(workspace / 'subdir' / 'foo', 'HEAD') == foo_head
assert rev_parse(workspace / 'bar', 'HEAD') == bar_head
# Move the repositories out of the way and test the configuration option.
# (We can't use shutil.rmtree here because Windows.)
shutil.move(os.fspath(foo), os.fspath(tmpdir))
shutil.move(os.fspath(bar), os.fspath(tmpdir))
cmd(f'config update.path-cache {path_cache_dir}')
cmd('update')
assert foo.check(dir=1)
assert bar.check(dir=1)
assert rev_parse(foo, 'HEAD') == foo_head
assert rev_parse(bar, 'HEAD') == bar_head
def setup_narrow(tmpdir):