Skip to content

Commit

Permalink
Refactor listing repo files into a dedicated method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kentzo committed Feb 9, 2020
1 parent 5ed3f4a commit 1443832
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
29 changes: 17 additions & 12 deletions git_archive_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,29 +300,19 @@ def walk_git_files(self, repo_path=fspath('')):
@param repo_path: Path to the git submodule repository relative to main_repo_abspath.
@return: Iterator to traverse files under git control relative to main_repo_abspath.
@return: Generator to traverse files under git control relative to main_repo_abspath.
"""
repo_abspath = path.join(self.main_repo_abspath, fspath(repo_path))
assert repo_abspath not in self._check_attr_gens
self._check_attr_gens[repo_abspath] = self.check_git_attr(repo_abspath, ['export-ignore'])

try:
repo_file_paths = self.run_git_shell(
'git ls-files -z --cached --full-name --no-empty-directory',
cwd=repo_abspath
)
repo_file_paths = repo_file_paths.split(b'\0')[:-1]

if sys.platform.startswith('win32'):
repo_file_paths = (git_fspath(p.replace(b'/', b'\\')) for p in repo_file_paths)
else:
repo_file_paths = map(git_fspath, repo_file_paths)
repo_file_paths = self.list_repo_files(repo_abspath)

for repo_file_path in repo_file_paths:
repo_file_abspath = path.join(repo_abspath, repo_file_path) # absolute file path
main_repo_file_path = path.join(repo_path, repo_file_path) # relative to main_repo_abspath

# Only list symlinks and files.
if not path.islink(repo_file_abspath) and path.isdir(repo_file_abspath):
continue

Expand Down Expand Up @@ -526,6 +516,21 @@ def get_git_version(cls):
cls.LOG.warning("Unable to parse Git version \"%s\".", version)
return None

@classmethod
def list_repo_files(cls, repo_abspath):
repo_file_paths = cls.run_git_shell(
'git ls-files -z --cached --full-name --no-empty-directory',
cwd=repo_abspath
)
repo_file_paths = repo_file_paths.split(b'\0')[:-1]

if sys.platform.startswith('win32'):
repo_file_paths = (git_fspath(p.replace(b'/', b'\\')) for p in repo_file_paths)
else:
repo_file_paths = map(git_fspath, repo_file_paths)

return repo_file_paths


def main(argv=None):
if argv is None:
Expand Down
5 changes: 4 additions & 1 deletion git_archive_all.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@ class GitArchiver(object):
def run_git_shell(cls, cmd: str, cwd: PathStr = None) -> bytes: ...

@classmethod
def get_git_version(cls) -> Optional[Tuple[int]]: ...
def get_git_version(cls) -> Optional[Tuple[int]]: ...

@classmethod
def list_repo_files(cls, repo_abspath: PathStr) -> Generator[PathStr, None, None]: ...

0 comments on commit 1443832

Please sign in to comment.