mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-16 00:15:59 +08:00
Streams the file content into a collectable
This commit is contained in:
parent
362a27f850
commit
d89e196bd0
2 changed files with 21 additions and 6 deletions
|
@ -116,7 +116,13 @@ defimpl Livebook.FileSystem, for: Livebook.FileSystem.Git do
|
|||
|
||||
def write_stream_halt(_file_system, _state), do: raise("not implemented")
|
||||
|
||||
def read_stream_into(_file_system, _path, _collectable), do: raise("not implemented")
|
||||
def read_stream_into(file_system, path, collectable) do
|
||||
try do
|
||||
Git.Client.stream_file(file_system, path, collectable)
|
||||
rescue
|
||||
error in File.Error -> FileSystem.Utils.posix_error(error.reason)
|
||||
end
|
||||
end
|
||||
|
||||
def load(file_system, %{"hub_id" => _} = fields) do
|
||||
load(file_system, %{
|
||||
|
|
|
@ -43,7 +43,20 @@ defmodule Livebook.FileSystem.Git.Client do
|
|||
path = relative_path(path)
|
||||
|
||||
with {:ok, git_dir} <- fetch_repository(file_system) do
|
||||
show(git_dir, file_system.branch, path)
|
||||
git(git_dir, ["show", "#{file_system.branch}:#{path}"])
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Streams the content of the given file from given repository.
|
||||
"""
|
||||
@spec stream_file(FileSystem.Git.t(), String.t(), Collectable.t()) ::
|
||||
{:ok, String.t()} | {:error, FileSystem.error()}
|
||||
def stream_file(%FileSystem.Git{} = file_system, path, collectable) do
|
||||
path = relative_path(path)
|
||||
|
||||
with {:ok, git_dir} <- fetch_repository(file_system) do
|
||||
git(git_dir, ["show", "#{file_system.branch}:#{path}"], into: collectable)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -90,10 +103,6 @@ defmodule Livebook.FileSystem.Git.Client do
|
|||
end
|
||||
end
|
||||
|
||||
defp show(git_dir, branch, path) do
|
||||
git(git_dir, ["show", "#{branch}:#{path}"])
|
||||
end
|
||||
|
||||
defp rev_parse(git_dir, branch, path) do
|
||||
with {:ok, etag} <- git(git_dir, ["rev-parse", "#{branch}:#{path}"]) do
|
||||
{:ok, String.trim(etag)}
|
||||
|
|
Loading…
Add table
Reference in a new issue