Simple version of index_add

This commit is contained in:
Carlos Martín Nieto
2013-05-03 14:05:00 +02:00
parent a5bbfa681b
commit 3f4d51c0e1
8 changed files with 82 additions and 30 deletions

View File

@@ -12,7 +12,7 @@
%% API
-export([start_link/1]).
-export([new/0, write/1, write_tree/1, write_tree/2, clear/1, stop/1, read_tree/2]).
-export([new/0, write/1, write_tree/1, write_tree/2, clear/1, stop/1, read_tree/2, add/2]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
@@ -51,6 +51,11 @@ write_tree(Pid, Repo) ->
read_tree(Pid, #object{type=tree, handle=TreeHandle}) ->
gen_server:call(Pid, {read_tree, TreeHandle}).
%% @doc Add an entry to the index
-spec add(pid(), index_entry()) -> ok | {error, term()}.
add(Pid, Entry) ->
gen_server:call(Pid, {add, Entry}).
%% @doc Clear the contents of the index.
-spec clear(pid()) -> ok.
clear(Pid) ->
@@ -83,7 +88,7 @@ handle_call(write_tree, _From, State = #state{handle=Handle}) ->
handle_call({write_tree, Repo}, _From, State = #state{handle=Handle}) ->
RepoHandle = geef_repo:handle(Repo),
{ok, Oid} = geef_nif:index_write_tree(Handle, RepoHandle),
Reply = #oid{oid=Oid},
Reply = {ok, #oid{oid=Oid}},
{reply, Reply, State};
handle_call(clear, _From, State = #state{handle=Handle}) ->
Reply = geef_nif:index_clear(Handle),
@@ -92,6 +97,9 @@ handle_call(stop, _From, State) ->
{stop, normal, ok, State};
handle_call({read_tree, TreeHandle}, _From, State = #state{handle=Handle}) ->
Reply = geef_nif:index_read_tree(Handle, TreeHandle),
{reply, Reply, State};
handle_call({add, Entry}, _From, State = #state{handle=Handle}) ->
Reply = geef_nif:index_add(Handle, Entry),
{reply, Reply, State}.
%% @private

View File

@@ -2,29 +2,7 @@
%%% NIF functions, not to be used directly.
-module(geef_nif).
-export([reference_list/1, reference_create/5,
reference_to_id/2, reference_glob/2, reference_lookup/2, reference_resolve/1,
reference_target/1, reference_type/1, odb_object_exists/2, odb_write/3]).
% repository operations
-export([repository_get_path/1, repository_get_odb/1, repository_open/1, repository_init/2,
repository_is_bare/1, repository_get_workdir/1, repository_discover/1]).
% oid parsing
-export([oid_fmt/1, oid_parse/1]).
% objects
-export([object_lookup/2, object_id/1, commit_tree_id/1, commit_tree/1, tree_bypath/2, blob_size/1, blob_content/1]).
% git_libgit2
-export([library_version/0]).
% revision walker
-export([revwalk_new/1, revwalk_push/3, revwalk_next/1, revwalk_sorting/2, revwalk_reset/1]).
% index
-export([index_new/0, index_write/1, index_write_tree/1, index_write_tree/2,
index_clear/1, index_read_tree/2]).
-compile(export_all).
-on_load(load_enif/0).
@@ -154,6 +132,9 @@ index_write_tree(_Handle, _RepoHandle) ->
index_read_tree(_Handle, _TreeHandle) ->
?NIF_FN.
index_add(_Handle, _Entry) ->
?NIF_FN.
index_clear(_Handle) ->
?NIF_FN.

View File

@@ -4,6 +4,7 @@
-record(revwalk, {handle}).
-record(oid, {oid}).
-record(object, {type :: atom(), handle}).
-record(index_entry, {mode, id :: oid(), path :: iolist()}).
-type ref() :: #ref{}.
-type repo() :: #repo{}.
@@ -11,3 +12,4 @@
-type odb() :: #odb{}.
-type oid() :: #oid{}.
-type object() :: #object{}.
-type index_entry() :: #index_entry{}.

View File

@@ -139,9 +139,8 @@ handle_call(stop, _From, State) ->
handle_call(revwalk, _From, State = #state{handle=Handle}) ->
Reply = handle_revwalk(Handle),
{reply, Reply, State};
handle_call(_Request, _From, State) ->
Reply = {error, "Unkown call"},
{reply, Reply, State}.
handle_call(handle, _From, State = #state{handle=Handle}) ->
{reply, Handle, State}.
%% @private
handle_cast(_Msg, State) ->