Browse files

added simple log function

  • Loading branch information...
1 parent 04013c2 commit 99420eb47bc35556bdd38fc4b33ca67ca08238c1 @schacon schacon committed Dec 4, 2009
Showing with 64 additions and 12 deletions.
  1. +23 −0 bin/egit
  2. +3 −12 src/git.erl
  3. +30 −0 src/git_io.erl
  4. +8 −0 t/007-git-simple-log.t
View
23 bin/egit
@@ -0,0 +1,23 @@
+#!/usr/bin/env escript
+%% -*- erlang -*-
+%%! -pa ./ebin -sasl -boot start_sasl -noshell
+
+main([Command|_Args]) ->
+ try
+ Git = git:open("test_git"), %% TODO: look for real git repo from cwd
+ case Command of
+ "log" ->
+ RevList = git:rev_list(Git, ["25daa907ccb6feb267bfec70a130d5fe13e48a79"]), %% blob
+ io:fwrite("RevList: ~p~n", [RevList]);
+ _Else ->
+ usage()
+ end
+ catch
+ _:_ ->
+ usage()
+ end.
+
+usage() ->
+ io:format("usage: egit command\n"),
+ halt(1).
+
View
15 src/git.erl
@@ -3,12 +3,11 @@
%%
-module(git).
--export([open/1, read_object/2, object_exists/2, rev_list/2]).
+-export([open/1, read_object/2, object_exists/2, rev_list/2, commit/2]).
-include("git.hrl").
%%-define(cassandra_ZERO, 0).
-%-record(git_dir, {path}).
open(Path) ->
% normalize the path (look for .git, etc)
@@ -18,14 +17,6 @@ open(Path) ->
% read all the refs from disk/packed-refs and return an array
%{Git}.
-%print_branches(Git) ->
- % print branches out to stdout
- %io:fwrite("Branches:~n").
-
-%print_log(Git, Ref) ->
- % traverse the reference, printing out all the log information to stdout
- %io:fwrite("Log:~n").
-
rev_list(Git, Shas) ->
Graph = digraph:new(),
rev_list(Git, Graph, Shas),
@@ -37,7 +28,7 @@ rev_list(Git, Graph, [Sha|Shas]) ->
Parents = Commit#commit.parents,
AddParents = rev_list_add_edges(Graph, Sha, Parents),
rev_list(Git, Graph, AddParents ++ Shas);
-rev_list(_Git, Graph, []) ->
+rev_list(_Git, _Graph, []) ->
ok.
rev_list_add_edges(Graph, Sha, [Parent|Rest]) ->
@@ -49,7 +40,7 @@ rev_list_add_edges(Graph, Sha, [Parent|Rest]) ->
end,
digraph:add_edge(Graph, Sha, Parent),
[Vertex|rev_list_add_edges(Graph, Sha, Rest)];
-rev_list_add_edges(Graph, Commit, []) ->
+rev_list_add_edges(_Graph, _Commit, []) ->
[].
commit(Git, Sha) ->
View
30 src/git_io.erl
@@ -0,0 +1,30 @@
+%%
+%% Git Output Printing Functions
+%%
+
+-module(git_io).
+-export([print_log/2]).
+
+-include("git.hrl").
+
+%print_branches(Git) ->
+ % print branches out to stdout
+ %io:fwrite("Branches:~n").
+
+print_log(Git, Refs) ->
+ % traverse the reference, printing out all the log information to stdout
+ Shas = Refs, % TODO - revparse these
+ RevList = git:rev_list(Git, Shas),
+ print_log_entries(Git, RevList).
+
+print_log_entries(Git, [Sha|Rest]) ->
+ {ok, Commit} = git:commit(Git, Sha),
+ io:fwrite("commit ~s~n", [Commit#commit.sha]),
+ io:fwrite("Author: ~s~n", [Commit#commit.author]),
+ io:fwrite("~n"),
+ io:fwrite("~s~n", [Commit#commit.message]),
+ io:fwrite("~n"),
+ print_log_entries(Git, Rest);
+print_log_entries(_Git, []) ->
+ ok.
+
View
8 t/007-git-simple-log.t
@@ -0,0 +1,8 @@
+#!/usr/bin/env escript
+%% -*- erlang -*-
+%%! -pa ./ebin -sasl -boot start_sasl -noshell
+
+main(_) ->
+ Git = git:open("test_git"),
+ git_io:print_log(Git, ["25daa907ccb6feb267bfec70a130d5fe13e48a79"]).
+

0 comments on commit 99420eb

Please sign in to comment.