Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

checkpoint: can seek into a packfile, starting to parse the data

  • Loading branch information...
commit 2e46f3f77a808c90a50b59f9f6455e1ee78b438a 1 parent 96c8fc7
@schacon authored
Showing with 16 additions and 5 deletions.
  1. +9 −3 src/git.erl
  2. +7 −2 src/packindex.erl
View
12 src/git.erl
@@ -71,8 +71,9 @@ get_packfile_object_data(Git, ObjectSha) ->
{ok, Filenames} ->
Indexes = lists:filter(fun(X) -> string_ends_with(X, ".idx") end, Filenames),
case get_packfile_with_object(Git, Indexes, ObjectSha) of
- {ok, Packfile} ->
- io:fwrite("Packfile:~p~n", [Packfile]);
+ {ok, Packfile, Offset} ->
+ PackFilePath = git_dir(Git) ++ "/objects/pack/" ++ Packfile,
+ packfile:get_packfile_data(PackFilePath, Offset);
_Else ->
invalid
end;
@@ -94,7 +95,8 @@ get_packfile_with_object(Git, [Index|Rest], ObjectSha) ->
io:fwrite("IndexData:~p~n", [IndexData]),
case packindex:object_offset(IndexData, ObjectSha) of
{ok, Offset} ->
- io:fwrite("Object Offset:~p~n", [Offset]);
+ Packfile = replace_string_ending(Index, ".idx", ".pack"),
+ {ok, Packfile, Offset};
not_found ->
get_packfile_with_object(Git, Rest, ObjectSha)
end;
@@ -108,6 +110,10 @@ get_packfile_with_object(Git, [Index|Rest], ObjectSha) ->
get_packfile_with_object(Git, [], ObjectSha) ->
not_found.
+replace_string_ending(String, Ending, NewEnding) ->
+ Base = string:substr(String, 1, length(String) - length(Ending)),
+ Base ++ NewEnding.
+
string_ends_with(File, Ending) ->
FileEnding = string:substr(File, length(File) - length(Ending) + 1, length(Ending)),
FileEnding =:= Ending.
View
9 src/packindex.erl
@@ -7,12 +7,17 @@
-include("packindex.hrl").
-
%%%
% get an object offset from an index record
%%%
object_offset(Index, ObjectSha) ->
- not_found.
+ ShaOffsets = lists:zip(Index#index.shalist, Index#index.offsets),
+ case lists:keyfind(ObjectSha, 1, ShaOffsets) of
+ {ObjectSha, Offset} ->
+ {ok, Offset};
+ _Else ->
+ not_found
+ end.
%%%
% extract a sha offset from packfile index data
Please sign in to comment.
Something went wrong with that request. Please try again.