Skip to content

Commit

Permalink
Fix small problems with multi_ack support
Browse files Browse the repository at this point in the history
See issue #8 for more details.
  • Loading branch information
redrabbit committed Dec 16, 2017
1 parent 0a94d94 commit 221a322
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
12 changes: 4 additions & 8 deletions apps/gitrekt/lib/gitrekt/wire_protocol/receive_pack.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,14 @@ defmodule GitRekt.WireProtocol.ReceivePack do
def run(%__MODULE__{state: :pack} = handle) do
:ok = apply_pack(handle.repo, handle.pack)
:ok = apply_cmds(handle.repo, handle.cmds)
run(struct(handle, state: :done))
if "report-status" in handle.caps,
do: {handle, report_status(handle.cmds)},
else: {handle, []}
end

@impl true
def run(%__MODULE__{state: :done, cmds: []} = handle) do
{handle, []}
end

def run(%__MODULE__{state: :done} = handle) do
if "report-status" in handle.caps,
do: {handle, report_status(handle.cmds)},
else: {handle, []}
{handle, []}
end

#
Expand Down
19 changes: 8 additions & 11 deletions apps/gitrekt/lib/gitrekt/wire_protocol/upload_pack.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,13 @@ defmodule GitRekt.WireProtocol.UploadPack do
acks = ack_haves(handle.haves, handle.caps)
cond do
"multi_ack_detailed" in handle.caps ->
{handle, acks ++ [:nak]}
{handle, acks ++ [{:ack, List.last(List.last(handle.haves)), :ready}, :nak]}
"multi_ack" in handle.caps ->
{handle, acks ++ [:nak]}
Enum.empty?(handle.haves) ->
{handle, [:nak]}
Enum.empty?(acks) ->
{handle, []}
true ->
{handle, [List.first(acks)]}
{handle, Enum.take(acks, 5)}
end
end

Expand All @@ -112,14 +110,15 @@ defmodule GitRekt.WireProtocol.UploadPack do
end

def run(%__MODULE__{state: :done} = handle) do
[have|_] = List.flatten(Enum.reverse(handle.haves)) # TODO
haves = List.flatten(Enum.reverse(handle.haves))
pack = create(handle.repo, handle.wants ++ Enum.map(haves, &{&1, true}))
cond do
"multi_ack_detailed" in handle.caps ->
{handle, [{:ack, have}, create(handle.repo, handle.wants ++ [{have, true}])]}
{handle, [{:ack, List.last(haves)}, pack]}
"multi_ack" in handle.caps ->
{handle, [{:ack, have}, create(handle.repo, handle.wants ++ [{have, true}])]}
{handle, [{:ack, List.last(haves)}, pack]}
true ->
{handle, [create(handle.repo, handle.wants ++ [{have, true}])]}
{handle, [pack]}
end
end

Expand Down Expand Up @@ -147,10 +146,8 @@ defmodule GitRekt.WireProtocol.UploadPack do
Enum.map(haves, &{:ack, &1, :common})
"multi_ack" in caps ->
Enum.map(haves, &{:ack, &1, :continue})
[have|_] = haves ->
[{:ack, have}]
true ->
[]
Enum.map(haves, &{:ack, &1})
end
end
end

0 comments on commit 221a322

Please sign in to comment.