add Geef.Revwalk module for Elixir
This commit is contained in:
committed by
Carlos Martín Nieto
parent
01254f2f90
commit
79f89bcd41
@@ -4,10 +4,10 @@
|
||||
|
||||
repo_test_() ->
|
||||
case os:getenv("GEEF_RESOURCES") of
|
||||
false ->
|
||||
[];
|
||||
_ ->
|
||||
{foreach, fun start/0, fun stop/1, [fun amount_test/1]}
|
||||
false ->
|
||||
[];
|
||||
_ ->
|
||||
{foreach, fun start/0, fun stop/1, [fun amount_test/1]}
|
||||
end.
|
||||
|
||||
start() ->
|
||||
@@ -18,10 +18,10 @@ start() ->
|
||||
|
||||
count_walk(Walk, Acc) ->
|
||||
case geef_revwalk:next(Walk) of
|
||||
{ok, _} ->
|
||||
count_walk(Walk, Acc + 1);
|
||||
{error, iterover} ->
|
||||
Acc
|
||||
{ok, _} ->
|
||||
count_walk(Walk, Acc + 1);
|
||||
{error, iterover} ->
|
||||
Acc
|
||||
end.
|
||||
|
||||
amount_test(Repo) ->
|
||||
|
||||
29
test/revwalk_test.exs
Normal file
29
test/revwalk_test.exs
Normal file
@@ -0,0 +1,29 @@
|
||||
defmodule RevwalkTest do
|
||||
use ExUnit.Case
|
||||
use Geef
|
||||
import RepoHelpers
|
||||
|
||||
|
||||
setup do
|
||||
{repo, path, head, boring_ancestor} = tmp_commit_line
|
||||
Process.link(repo)
|
||||
{:ok, walk} = Repository.revwalk(repo)
|
||||
on_exit(fn -> File.rm_rf!(path) end)
|
||||
{:ok, [walk: walk, head: head, boring_ancestor: boring_ancestor]}
|
||||
end
|
||||
|
||||
test "walk and count", meta do
|
||||
walk = meta[:walk]
|
||||
Revwalk.push(walk, meta[:head])
|
||||
Revwalk.hide(walk, meta[:boring_ancestor])
|
||||
assert 3 = count_walk(walk)
|
||||
end
|
||||
|
||||
defp count_walk walk, acc \\ 0
|
||||
defp count_walk walk, acc do
|
||||
case Revwalk.next(walk) do
|
||||
{:ok, _} -> count_walk(walk, acc + 1)
|
||||
{:error, :iterover} -> acc
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,12 +1,33 @@
|
||||
ExUnit.start
|
||||
|
||||
defmodule RepoHelpers do
|
||||
use Geef
|
||||
|
||||
def tmp_bare do
|
||||
{a, b, c} = :erlang.timestamp()
|
||||
n = node()
|
||||
dir = :io_lib.format("geef-~p~p~p~p.git", [n, a, b, c])
|
||||
path = Path.join(System.tmp_dir!, dir)
|
||||
{:ok, repo} = Geef.Repository.init(path, true)
|
||||
{:ok, repo} = Repository.init(path, true)
|
||||
{repo, path}
|
||||
end
|
||||
|
||||
def tmp_commit_line do
|
||||
{repo, path} = tmp_bare()
|
||||
sig = Signature.now("Geef Test", "test@geef")
|
||||
message = "commit message"
|
||||
{:ok, idx} = Index.new()
|
||||
{:ok, empty_index} = Index.write_tree(idx, repo)
|
||||
|
||||
{:ok, c} = Commit.create(repo, sig, sig, message, empty_index, [])
|
||||
{:ok, c} = Commit.create(repo, sig, sig, message, empty_index, [c])
|
||||
{:ok, c} = Commit.create(repo, sig, sig, message, empty_index, [c])
|
||||
boring_ancestor = c
|
||||
{:ok, c} = Commit.create(repo, sig, sig, message, empty_index, [c])
|
||||
{:ok, c} = Commit.create(repo, sig, sig, message, empty_index, [c])
|
||||
{:ok, c} = Commit.create(repo, sig, sig, message, empty_index, [c])
|
||||
head = c
|
||||
|
||||
{repo, path, head, boring_ancestor}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user