Skip to content

Commit

Permalink
use run-context-manager in gitworktree.py
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-monch committed Oct 26, 2023
1 parent 9aec6ee commit 839ca42
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions datalad_next/iter_collections/gitworktree.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
from datalad_next.runners import (
DEVNULL,
LineSplitter,
ThreadedRunner,
StdOutCaptureGeneratorProtocol,
)

from datalad_next.runners.run import run
from .utils import (
FileSystemItem,
FileSystemItemType,
Expand Down Expand Up @@ -250,8 +249,7 @@ def _lsfiles_line2props(


def _git_ls_files(path, *args):
# we use a plain runner to avoid the overhead of a GitRepo instance
runner = ThreadedRunner(
with run(
cmd=[
'git', 'ls-files',
# we rely on zero-byte splitting below
Expand All @@ -261,12 +259,12 @@ def _git_ls_files(path, *args):
],
protocol_class=StdOutCaptureGeneratorProtocol,
stdin=DEVNULL,
# run in the directory we want info on
cwd=path,
)
line_splitter = LineSplitter('\0', keep_ends=False)
# for each command output chunk received by the runner
for content in runner.run():
# for each zerobyte-delimited "line" in the output
for line in line_splitter.process(content.decode('utf-8')):
yield line
) as r:
# we use a plain runner to avoid the overhead of a GitRepo instance
line_splitter = LineSplitter('\0', keep_ends=False)
# for each command output chunk received by the runner
for content in r:
# for each zerobyte-delimited "line" in the output
for line in line_splitter.process(content.decode('utf-8')):
yield line

0 comments on commit 839ca42

Please sign in to comment.