Skip to content

Commit

Permalink
stub out revlist functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
schacon committed Dec 3, 2009
1 parent 84e32a7 commit df87761
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
18 changes: 16 additions & 2 deletions src/git.erl
Expand Up @@ -3,9 +3,9 @@
%% %%


-module(git). -module(git).
-export([open/1, read_object/2, object_exists/2]). -export([open/1, read_object/2, object_exists/2, rev_list/2]).


-include("packindex.hrl"). -include("git.hrl").


%%-define(cassandra_ZERO, 0). %%-define(cassandra_ZERO, 0).


Expand All @@ -30,6 +30,20 @@ open(Path) ->
% traverse the reference, printing out all the log information to stdout % traverse the reference, printing out all the log information to stdout
%io:fwrite("Log:~n"). %io:fwrite("Log:~n").


rev_list(Git, Shas) ->
rev_list(Git, Shas, []).

rev_list(Git, [Sha|Shas], Gathered) ->
Commit = commit(Git, Sha),
Parents = git_object:get_parents(Commit),
rev_list(Git, Parents ++ Shas, [Sha|Gathered]);
rev_list(Git, [], Gathered) ->
Gathered.

commit(Git, Sha) ->
{Type, Size, Data} = read_object(Git, Sha),
git_object:parse_commit(Data).

git_dir(Git) -> git_dir(Git) ->
{Path} = Git, {Path} = Git,
Path. Path.
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions src/git_object.erl
@@ -0,0 +1,14 @@
%%
%% Partial Git Implementation
%%

-module(git_object).
-export([parse_commit/1, get_parents/1]).

parse_commit(Data) ->
io:format("Commit: ~p~n", [Data]),
Data.

get_parents(Commit) ->
[].

5 changes: 3 additions & 2 deletions src/packindex.erl
Expand Up @@ -5,7 +5,7 @@
-module(packindex). -module(packindex).
-export([extract_packfile_index/1, object_offset/2]). -export([extract_packfile_index/1, object_offset/2]).


-include("packindex.hrl"). -include("git.hrl").


%%% %%%
% get an object offset from an index record % get an object offset from an index record
Expand Down Expand Up @@ -33,7 +33,7 @@ extract_packfile_index(Data) ->
{OffsetList, Data7} = extract_offsets(Data6, Size), {OffsetList, Data7} = extract_offsets(Data6, Size),
{PackCs, Data8} = split_binary(Data7, 20), {PackCs, Data8} = split_binary(Data7, 20),
{_IdxCs, _Empty} = split_binary(Data8, 20), {_IdxCs, _Empty} = split_binary(Data8, 20),
Index = #index{header=Header, version=Version, size=Size, fanout=FanoutTable, Index = #index{header=Header, version=Version, size=Size, fanout=FanoutTable,
shalist=ShaList, crclist=CrcList, offsets=OffsetList, packcs=hex:bin_to_hexstr(PackCs)}, shalist=ShaList, crclist=CrcList, offsets=OffsetList, packcs=hex:bin_to_hexstr(PackCs)},
{ok, Index}. {ok, Index}.


Expand Down Expand Up @@ -85,3 +85,4 @@ extract_fanout(IndexData, Count, Fanout) ->
{Fan, IndexDataRem} = split_binary(IndexData, 4), % fanout entry {Fan, IndexDataRem} = split_binary(IndexData, 4), % fanout entry
<<FanInt:32>> = Fan, <<FanInt:32>> = Fan,
extract_fanout(IndexDataRem, Count + 1, [FanInt|Fanout]). extract_fanout(IndexDataRem, Count + 1, [FanInt|Fanout]).

9 changes: 9 additions & 0 deletions t/006-rev-list.t
@@ -0,0 +1,9 @@
#!/usr/bin/env escript
%% -*- erlang -*-
%%! -pa ./ebin -sasl -boot start_sasl -noshell

main(_) ->
Git = git:open("test_git"),
RevList = git:rev_list(Git, ["25daa907ccb6feb267bfec70a130d5fe13e48a79"]), %% blob
io:fwrite("RevList: ~p~n", [RevList]).

0 comments on commit df87761

Please sign in to comment.