Files
dvc/dvc/fs/git.py
T
Ruslan Kuprieiev b14a972cd0 repofs: use / as root_marker
This makes dvcfs/repofs much easier to work with and allows it to support
isabs/abspath/etc correctly, as previously any full path (with root_marker "")
would be impossible to distinguish from a relative one.

This also detaches external workspaces from the main repo workspace in
DvcFileSystem, which was necessary to be able to distinguish dvcfs abspaths
from local external output paths. Note that currently we still have limited
support for those (e.g. get/api supports them, but import doesn't) and this
change keeps it that way.
2022-05-08 17:19:53 +03:00

62 lines
1.5 KiB
Python

import os
import threading
from typing import TYPE_CHECKING, Any
from funcy import cached_property, wrap_prop
from .base import FileSystem
if TYPE_CHECKING:
from scmrepo.fs import GitFileSystem as FsspecGitFileSystem
from scmrepo.git import Git
from scmrepo.git.objects import GitTrie
class GitFileSystem(FileSystem): # pylint:disable=abstract-method
"""Proxies the repo file access methods to Git objects"""
sep = os.sep
scheme = "local"
def __init__(
self,
path: str = None,
rev: str = None,
scm: "Git" = None,
trie: "GitTrie" = None,
**kwargs: Any,
) -> None:
from dvc.scm import resolve_rev
super().__init__()
self.fs_args.update(
{
"path": path,
"rev": rev,
"scm": scm,
"trie": trie,
"rev_resolver": resolve_rev,
**kwargs,
}
)
@cached_property
def path(self):
from .path import Path
return Path(self.sep, getcwd=os.getcwd)
@wrap_prop(threading.Lock())
@cached_property
def fs(self) -> "FsspecGitFileSystem":
from scmrepo.fs import GitFileSystem as FsspecGitFileSystem
return FsspecGitFileSystem(**self.fs_args)
@property
def rev(self) -> str:
return self.fs.rev
def ls(self, path, detail=True, **kwargs):
return self.fs.ls(path, detail=detail, **kwargs) or []