Skip to content

Commit

Permalink
deduplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiosantoscode committed Jan 10, 2020
1 parent 1f2eed8 commit f3d234e
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions dvc/repo/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ def __init__(self):
)


def _forbid_absolute_path(path):
if os.path.isabs(path):
raise FileNotFoundError


@staticmethod
def get(url, path, out=None, rev=None):
out = resolve_output(path, out)
Expand All @@ -46,6 +41,7 @@ def get(url, path, out=None, rev=None):
# and won't work with reflink/hardlink.
dpath = os.path.dirname(os.path.abspath(out))
tmp_dir = os.path.join(dpath, "." + str(shortuuid.uuid()))
repo_dir = None
try:
try:
with external_repo(cache_dir=tmp_dir, url=url, rev=rev) as repo:
Expand All @@ -70,18 +66,20 @@ def get(url, path, out=None, rev=None):
return

# Either an uncached out with absolute path or a user error
_forbid_absolute_path(path)

fs_copy(os.path.join(repo.root_dir, path), out)
return
repo_dir = repo.root_dir

except NotDvcRepoError:
# Not a DVC repository, continue below and copy from git
pass

_forbid_absolute_path(path)
raw_git_dir = cached_clone(url, rev=rev)
fs_copy(os.path.join(raw_git_dir, path), out)
if os.path.isabs(path):
raise FileNotFoundError

if not repo_dir:
repo_dir = cached_clone(url, rev=rev)

fs_copy(os.path.join(repo_dir, path), out)
except (OutputNotFoundError, FileNotFoundError):
raise PathMissingError(path, url)
finally:
Expand Down

0 comments on commit f3d234e

Please sign in to comment.