Add revwalk support
This commit is contained in:
20
src/geef.erl
20
src/geef.erl
@@ -19,8 +19,13 @@
|
||||
% git_libgit2
|
||||
-export([library_version/0]).
|
||||
|
||||
% revision walker
|
||||
-export([revwalk_new/1, revwalk_push/3, revwalk_next/1, revwalk_sorting/2, revwalk_reset/1]).
|
||||
|
||||
-on_load(load_enif/0).
|
||||
|
||||
-define(NIF_FN, nif_error(?LINE)).
|
||||
|
||||
-spec repository_open(iolist()) -> {ok, term()} | {error, term()}.
|
||||
repository_open(_Val) ->
|
||||
nif_error(?LINE).
|
||||
@@ -112,6 +117,21 @@ blob_content(_ObjHandle) ->
|
||||
library_version() ->
|
||||
nif_error(?LINE).
|
||||
|
||||
revwalk_new(_Repo) ->
|
||||
?NIF_FN.
|
||||
|
||||
revwalk_push(_Walk, _Id, _Hide) ->
|
||||
?NIF_FN.
|
||||
|
||||
revwalk_next(_Walk) ->
|
||||
?NIF_FN.
|
||||
|
||||
revwalk_sorting(_Walk, _Sort) ->
|
||||
?NIF_FN.
|
||||
|
||||
revwalk_reset(_Walk) ->
|
||||
?NIF_FN.
|
||||
|
||||
nif_error(Line) ->
|
||||
erlang:nif_error({nif_not_loaded,module,?MODULE,line,Line}).
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
-record(ref, {handle, type :: atom()}).
|
||||
-record(repo, {handle}).
|
||||
-record(odb, {handle}).
|
||||
-record(revwalk, {handle}).
|
||||
-record(oid, {oid}).
|
||||
-record(object, {type :: atom(), handle}).
|
||||
|
||||
-type ref() :: #ref{}.
|
||||
-type repo() :: #repo{}.
|
||||
-type revwalk() :: #revwalk{}.
|
||||
-type odb() :: #odb{}.
|
||||
-type oid() :: #oid{}.
|
||||
-type object() :: #object{}.
|
||||
|
||||
45
src/geef_revwalk.erl
Normal file
45
src/geef_revwalk.erl
Normal file
@@ -0,0 +1,45 @@
|
||||
-module(geef_revwalk).
|
||||
|
||||
-export([new/1, push/2, hide/2, next/1, sorting/2]).
|
||||
|
||||
-include("geef_records.hrl").
|
||||
|
||||
|
||||
%% @doc Create a revision walker
|
||||
-spec new(repo()) -> {ok, revwalk()} | {error, term}.
|
||||
new(#repo{handle=Handle}) ->
|
||||
case geef:revwalk_new(Handle) of
|
||||
{ok, WalkHandle} ->
|
||||
{ok, #revwalk{handle=WalkHandle}};
|
||||
Other ->
|
||||
Other
|
||||
end.
|
||||
|
||||
|
||||
%% @doc Push a commit. This commit and its parents will be included in
|
||||
%% the walk as long as they haven't been hidden. At least one commit
|
||||
%% must be pushed before starting a walk.
|
||||
-spec push(revwalk(), oid()) -> ok | {error, binary()}.
|
||||
push(#revwalk{handle=Handle}, #oid{oid=Oid}) ->
|
||||
geef:revwalk_push(Handle, Oid, false).
|
||||
|
||||
%% @doc Hide a commit. Hide a commit and its parents. Any Parent of
|
||||
%% this commit won't be included in the walk.
|
||||
-spec hide(revwalk(), oid()) -> ok | {error, binary()}.
|
||||
hide(#revwalk{handle=Handle}, #oid{oid=Oid}) ->
|
||||
geef:revwalk_push(Handle, Oid, true).
|
||||
|
||||
%% @doc Next commit in the walk
|
||||
next(#revwalk{handle=Handle}) ->
|
||||
case geef:revwalk_next(Handle) of
|
||||
{ok, Oid} ->
|
||||
{ok, #oid{oid=Oid}};
|
||||
Other ->
|
||||
Other
|
||||
end.
|
||||
|
||||
sorting(#revwalk{handle=Handle}, Opts) when is_list(Opts) ->
|
||||
geef:revwalk_sorting(Handle, Opts);
|
||||
sorting(Walk = #revwalk{}, Opt) when is_atom(Opt) ->
|
||||
sorting(Walk, [Opt]).
|
||||
|
||||
Reference in New Issue
Block a user