Merge pull request #8 from mingshun/master

Fixed some small stuffs
This commit is contained in:
Carlos Martín Nieto
2015-12-20 03:31:50 +01:00
7 changed files with 33 additions and 34 deletions

View File

@@ -57,7 +57,7 @@ geef_config_set_bool(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
ErlNifBinary bin; ErlNifBinary bin;
int error, val; int error, val;
ERL_NIF_TERM ret; ERL_NIF_TERM ret;
ret = extract(&cfg, &bin, env, argv); ret = extract(&cfg, &bin, env, argv);
if (ret != atoms.ok) if (ret != atoms.ok)
return ret; return ret;
@@ -80,7 +80,7 @@ geef_config_get_bool(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
ErlNifBinary bin; ErlNifBinary bin;
int error, val; int error, val;
ERL_NIF_TERM ret; ERL_NIF_TERM ret;
ret = extract(&cfg, &bin, env, argv); ret = extract(&cfg, &bin, env, argv);
if (ret != atoms.ok) if (ret != atoms.ok)
return ret; return ret;
@@ -100,10 +100,10 @@ geef_config_set_int(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{ {
geef_config *cfg; geef_config *cfg;
ErlNifBinary bin; ErlNifBinary bin;
int64_t val; ErlNifSInt64 val;
int error; int error;
ERL_NIF_TERM ret; ERL_NIF_TERM ret;
ret = extract(&cfg, &bin, env, argv); ret = extract(&cfg, &bin, env, argv);
if (ret != atoms.ok) if (ret != atoms.ok)
return ret; return ret;

View File

@@ -1,6 +1,10 @@
require Record require Record
defmodule Geef.Object do defmodule Geef.Object do
@behaviour Access
alias Geef.Object
alias Geef.Tree
defstruct type: nil, id: nil, handle: nil defstruct type: nil, id: nil, handle: nil
def lookup(repo, id) do def lookup(repo, id) do
@@ -32,4 +36,24 @@ defmodule Geef.Object do
end end
end end
def fetch(tree = %Object{type: :tree}, key) when is_number(key) do
Tree.nth(tree, key)
end
def fetch(tree = %Object{type: :tree}, key) do
Tree.get(tree, key)
end
def get(tree = %Object{type: :tree}, key) do
case fetch(tree, key) do
{:ok, entry} -> entry
{:error, _} -> nil
end
end
# Git data is immutable
def get_and_update(_tree, _key, _fun) do
raise ArgumentError
end
end end

View File

@@ -33,31 +33,6 @@ defmodule Geef.Tree do
end end
defimpl Access, for: Geef.Object do
alias Geef.Object
alias Geef.Tree
def get(tree = %Object{type: :tree}, key) when is_number(key) do
case Tree.nth(tree, key) do
{:ok, entry} -> entry
{:error, _} -> nil
end
end
def get(tree = %Object{type: :tree}, key) do
case Tree.get(tree, key) do
{:ok, entry} -> entry
{:error, _} -> nil
end
end
# Git data is immutable
def get_and_update(_tree, _key, _fun) do
raise ArgumentError
end
end
defmodule Geef.TreeError do defmodule Geef.TreeError do
defexception [reason: nil] defexception [reason: nil]

View File

@@ -10,7 +10,7 @@ defmodule Mix.Tasks.Compile.Nif do
`["c_src"]`. Can be configured as: `["c_src"]`. Can be configured as:
```` ````
[ptahs: ["c_src", "vendor/src"]] [paths: ["c_src", "vendor/src"]]
```` ````
* `:exts` - extensions of the source files. Defaults to `[:c]`, can * `:exts` - extensions of the source files. Defaults to `[:c]`, can
@@ -118,7 +118,7 @@ defmodule Geef.Mixfile do
end end
def nif do def nif do
[ file: "priv/geef.so", [ file: "#{Path.join [__DIR__, "priv", "geef.so"]}",
flags: "-lgit2" ] flags: "-lgit2" ]
end end

View File

@@ -24,7 +24,7 @@ default(Repo) ->
%% @doc Create a signature with the specified username and email, with %% @doc Create a signature with the specified username and email, with
%% a timestamp of now %% a timestamp of now
now(Name, Email) -> now(Name, Email) ->
Now = now(), Now = os:timestamp(),
%% We ask two questions "what's the time here?" and "what's the %% We ask two questions "what's the time here?" and "what's the
%% time in UTC-Land?". The difference in minutes is our offset. %% time in UTC-Land?". The difference in minutes is our offset.
Local = calendar:datetime_to_gregorian_seconds(calendar:now_to_local_time(Now)), Local = calendar:datetime_to_gregorian_seconds(calendar:now_to_local_time(Now)),

View File

@@ -8,7 +8,7 @@ config_test_() ->
fun string_test/1]}. fun string_test/1]}.
start() -> start() ->
{A, B, C} = now(), {A, B, C} = os:timestamp(),
N = node(), N = node(),
TmpFile = io_lib:format("/tmp/geef-~p~p~p~p.gitconfig", [N, A, B, C]), TmpFile = io_lib:format("/tmp/geef-~p~p~p~p.gitconfig", [N, A, B, C]),
{ok, Config} = geef_config:open(TmpFile), {ok, Config} = geef_config:open(TmpFile),

View File

@@ -11,7 +11,7 @@ repo_test_() ->
fun commit_tree_test/1]}. fun commit_tree_test/1]}.
start() -> start() ->
{A, B, C} = now(), {A, B, C} = os:timestamp(),
N = node(), N = node(),
TmpDir = io_lib:format("/tmp/geef-~p~p~p~p.git", [N, A, B, C]), TmpDir = io_lib:format("/tmp/geef-~p~p~p~p.git", [N, A, B, C]),
{ok, Repo} = geef_repo:init(TmpDir, true), {ok, Repo} = geef_repo:init(TmpDir, true),