From 47bcb02ef1749d057889c643631a205cdbf004b9 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Sat, 6 Mar 2021 02:54:13 +0200 Subject: [PATCH] fs: git: use pygit2 (#5559) --- dvc/fs/git.py | 6 ------ dvc/scm/git/__init__.py | 2 +- dvc/scm/git/backend/pygit2.py | 3 +++ 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/dvc/fs/git.py b/dvc/fs/git.py index ef8c4b684..5c1293b40 100644 --- a/dvc/fs/git.py +++ b/dvc/fs/git.py @@ -158,12 +158,6 @@ class GitFileSystem(BaseFileSystem): # pylint:disable=abstract-method errno.ENOENT, os.strerror(errno.ENOENT), path ) - @property - def hash_jobs(self): # pylint: disable=invalid-overridden-method - # NOTE: gitpython is not threadsafe. See - # https://github.com/iterative/dvc/issues/4079 - return 1 - def walk_files(self, top): # pylint: disable=arguments-differ for root, _, files in self.walk(top): for file in files: diff --git a/dvc/scm/git/__init__.py b/dvc/scm/git/__init__.py index eb8f88473..9a325431c 100644 --- a/dvc/scm/git/__init__.py +++ b/dvc/scm/git/__init__.py @@ -352,7 +352,7 @@ class Git(Base): from .objects import GitTrie resolved = self.resolve_rev(rev) - tree_obj = self._backend_func("get_tree_obj", rev=resolved) + tree_obj = self.pygit2.get_tree_obj(rev=resolved) trie = GitTrie(tree_obj, resolved) return GitFileSystem(self.root_dir, trie, **kwargs) diff --git a/dvc/scm/git/backend/pygit2.py b/dvc/scm/git/backend/pygit2.py index e8cb3a6e7..bc80c51de 100644 --- a/dvc/scm/git/backend/pygit2.py +++ b/dvc/scm/git/backend/pygit2.py @@ -1,6 +1,7 @@ import locale import logging import os +import stat from io import BytesIO, StringIO from typing import Callable, Iterable, List, Mapping, Optional, Tuple, Union @@ -31,6 +32,8 @@ class Pygit2Object(GitObject): @property def mode(self): + if not self.obj.filemode and self.obj.type_str == "tree": + return stat.S_IFDIR return self.obj.filemode def scandir(self) -> Iterable["Pygit2Object"]: