Skip to content

Commit

Permalink
erepo: move handling of source repo resource to _fix_upstream (iter…
Browse files Browse the repository at this point in the history
  • Loading branch information
tizoc committed Feb 23, 2020
1 parent ce3b511 commit 9b6261f
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions dvc/external_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,35 +126,30 @@ def _set_cache_dir(self):
def _fix_upstream(self):
if os.path.isdir(self.url):
upstream_name = self.config["core"].get("remote")
if upstream_name:
self._fix_local_remote(upstream_name)
else:
self._add_upstream()

def _fix_local_remote(self, remote_name):
src_repo = Repo(self.url)
try:
if upstream_name:
self._fix_local_remote(src_repo, upstream_name)
else:
self._add_upstream(src_repo)
finally:
src_repo.close()

def _fix_local_remote(self, src_repo, remote_name):
# Keep the relative path for a local remote relative
# to the original repo.
src_repo = Repo(self.url)
try:
new_remote = self.config["remote"][remote_name]
old_remote = src_repo.config["remote"][remote_name]
# NOTE: it is assumed that only local+relative urls
# will be different from their old version. Revise this
# test if that stops being true.
if new_remote["url"] != old_remote["url"]:
new_remote["url"] = old_remote["url"]
finally:
src_repo.close()

def _add_upstream(self):
new_remote = self.config["remote"][remote_name]
old_remote = src_repo.config["remote"][remote_name]
# NOTE: it is assumed that only local+relative urls
# will be different from their old version. Revise this
# test if that stops being true.
if new_remote["url"] != old_remote["url"]:
new_remote["url"] = old_remote["url"]

def _add_upstream(self, src_repo):
# Fill the empty upstream entry with a new remote pointing to the
# original repo's cache location.
src_repo = Repo(self.url)
try:
cache_dir = src_repo.cache.local.cache_dir
finally:
src_repo.close()

cache_dir = src_repo.cache.local.cache_dir
self.config["remote"]["auto-generated-upstream"] = {"url": cache_dir}
self.config["core"]["remote"] = "auto-generated-upstream"

Expand Down

0 comments on commit 9b6261f

Please sign in to comment.