Permalink
Browse files

full packfile index parsing

  • Loading branch information...
1 parent 37bc358 commit b038a65ccba0b2cb0aee2c9ee7c2ec370da72ce7 @schacon schacon committed Nov 17, 2009
Showing with 21 additions and 12 deletions.
  1. +7 −4 src/git.erl
  2. +12 −8 src/packindex.erl
  3. +2 −0 src/packindex.hrl
View
@@ -5,6 +5,8 @@
-module(git).
-export([open/1, read_object/2]).
+-include("packindex.hrl").
+
%%-define(cassandra_ZERO, 0).
%-record(git_dir, {path}).
@@ -85,10 +87,11 @@ get_packfile_with_object(Git, [Index|Rest], ObjectSha) ->
PackIndex = git_dir(Git) ++ "/objects/pack/" ++ Index,
case file:read_file(PackIndex) of
{ok, Data} ->
- case packindex:extract_packfile_offset(Data, ObjectSha) of
- {ok, Offset} ->
- {ok, Offset};
- _Else ->
+ case packindex:extract_packfile_index(Data) of
+ {ok, IndexData} ->
+ io:fwrite("PackIndex Size:~p~n", [IndexData#index.size]);
+ Else ->
+ io:fwrite("Invalid, Biatch~p~n", [Else]),
invalid
end;
_Else ->
View
@@ -3,23 +3,27 @@
%%
-module(packindex).
--export([extract_packfile_offset/2]).
+-export([extract_packfile_index/1]).
+
+-include("packindex.hrl").
%%%
% extract a sha offset from packfile index data
+% TODO: check to see if this is version 1 or version 2 (currently only v2)
+% TODO: parse large offset section if it exists (curr. assumes it does not)
%%%
-extract_packfile_offset(Data, ObjectSha) ->
+extract_packfile_index(Data) ->
{Header, Data2} = split_binary(Data, 4), % \377tOc
- {Header2, Data3} = split_binary(Data2, 4), % 0002
+ {Version, Data3} = split_binary(Data2, 4), % 0002
{FanoutTable, Size, Data4} = extract_fanout(Data3),
- io:fwrite("Offsets:~p~n~p~n", [FanoutTable, Size]),
{ShaList, Data5} = extract_sha_list(Data4, Size),
- io:fwrite("ShaList:~p~n~p~n", [ShaList, length(ShaList)]),
{CrcList, Data6} = extract_crc(Data5, Size),
- io:fwrite("CrcList:~p~n~p~n", [CrcList, length(CrcList)]),
{OffsetList, Data7} = extract_offsets(Data6, Size),
- io:fwrite("OffsetList:~p~n~p~n", [OffsetList, length(OffsetList)]),
- invalid.
+ {PackCs, Data8} = split_binary(Data7, 20),
+ {_IdxCs, _Empty} = split_binary(Data8, 20),
+ Index = #index{header=Header, version=Version, size=Size, fanout=FanoutTable,
+ shalist=ShaList, crclist=CrcList, offsets=OffsetList, packcs=PackCs},
+ {ok, Index}.
%%%
% extract offset list from packfile index
View
@@ -0,0 +1,2 @@
+
+-record(index, {header, version, size, fanout, shalist, crclist, offsets, packcs}).

0 comments on commit b038a65

Please sign in to comment.