Permalink
Browse files

refactored commit into record

  • Loading branch information...
1 parent 8d201e8 commit f60fd7bcd1388c9f48e1eda0dd52a514daa4e1ee @schacon committed Dec 3, 2009
Showing with 30 additions and 16 deletions.
  1. +2 −2 src/git.erl
  2. +15 −1 src/git.hrl
  3. +13 −13 src/git_object.erl
View
@@ -34,8 +34,8 @@ rev_list(Git, Shas) ->
rev_list(Git, Shas, []).
rev_list(Git, [Sha|Shas], Gathered) ->
- Commit = commit(Git, Sha),
- Parents = git_object:get_parents(Commit),
+ {ok, Commit} = commit(Git, Sha),
+ Parents = Commit#commit.parents,
rev_list(Git, Parents ++ Shas, [Sha|Gathered]);
rev_list(Git, [], Gathered) ->
Gathered.
View
@@ -1,2 +1,16 @@
--record(index, {header, version, size, fanout, shalist, crclist, offsets, packcs}).
+-record(index, {header,
+ version,
+ size,
+ fanout,
+ shalist,
+ crclist,
+ offsets,
+ packcs}).
+
+-record(commit, {parents,
+ tree,
+ author,
+ committer,
+ encoding,
+ message}).
View
@@ -1,28 +1,33 @@
%%
-%% Partial Git Implementation
+%% Git Object Parsers
%%
-module(git_object).
--export([parse_commit/1, get_parents/1]).
+-export([parse_commit/1]).
+
+-include("git.hrl").
parse_commit(Data) ->
CommitString = binary_to_list(Data),
{match, Offset, Len} = regexp:first_match(CommitString, "\n\n"),
{Meta, Message} = lists:split(Offset + Len - 1, CommitString),
Parents = parse_commit_parents(Meta),
- Tree = extract_one(Meta, "tree (.*)"),
- Author = extract_one(Meta, "author (.*)"),
+ Tree = extract_one(Meta, "tree (.*)"),
+ Author = extract_one(Meta, "author (.*)"),
Committer = extract_one(Meta, "committer (.*)"),
- Encoding = extract_one(Meta, "encoding (.*)"),
+ Encoding = extract_one(Meta, "encoding (.*)"),
%io:format("Parents:~p~nTree:~p~nAuthor:~p~nMessage:~p~n~n", [Parents, Tree, Author, Message]),
- {Tree, Parents, Author, Committer, Encoding, Message}.
+ Commit = #commit{tree=Tree, parents=Parents,
+ author=Author, committer=Committer,
+ encoding=Encoding, message=Message},
+ {ok, Commit}.
parse_commit_parents(Data) ->
Parents = extract_multi(Data, "parent (.*)"),
extract_matches(Parents).
extract_matches([Match|Rest]) ->
- [Full, Data] = Match,
+ [_Full, Data] = Match,
[Data|extract_matches(Rest)];
extract_matches([]) ->
[].
@@ -38,13 +43,8 @@ extract_multi(Data, Regex) ->
extract_one(Data, Regex) ->
case re:run(Data, Regex, [{capture, all, list}]) of
{match, Captured} ->
- [Full, Value] = Captured,
+ [_Full, Value] = Captured,
Value;
_Else ->
""
end.
-
-get_parents(Commit) ->
- {Tree, Parents, Author, Committer, Encoding, Message} = Commit,
- Parents.
-

0 comments on commit f60fd7b

Please sign in to comment.