diff options
author | kballou <kballou@devnulllabs.io> | 2017-02-08 19:48:24 -0700 |
---|---|---|
committer | kballou <kballou@devnulllabs.io> | 2017-02-08 19:48:24 -0700 |
commit | 557ef577085017887cfbc8bcc8445b719a78cf95 (patch) | |
tree | 31ec88be55288a7b83e6603b7eca9188832d1914 | |
parent | fefd791ed686d9dd0f5551be4c0c339b14998051 (diff) | |
download | exgit-557ef577085017887cfbc8bcc8445b719a78cf95.tar.gz exgit-557ef577085017887cfbc8bcc8445b719a78cf95.tar.xz |
WIP: initial packfile parser
-rw-r--r-- | lib/exgit/packfile.ex | 13 | ||||
-rw-r--r-- | test/exgit/packfile_test.exs | 24 | ||||
-rw-r--r-- | test/fixtures/packfiles/pack-simple.idx | bin | 0 -> 1156 bytes | |||
-rw-r--r-- | test/fixtures/packfiles/pack-simple.pack | bin | 0 -> 210 bytes | |||
-rw-r--r-- | test/fixtures/packfiles/pack-simple3.pack | bin | 0 -> 210 bytes |
5 files changed, 37 insertions, 0 deletions
diff --git a/lib/exgit/packfile.ex b/lib/exgit/packfile.ex index 4fda345..3823259 100644 --- a/lib/exgit/packfile.ex +++ b/lib/exgit/packfile.ex @@ -2,4 +2,17 @@ defmodule Exgit.Packfile do @moduledoc """ Module for parsing Git Packfiles """ + + @spec parse_header(binary) :: {:pack, 2|3, integer} + def parse_header(packfile) do + <<"PACK" :: utf8, 2 :: size(32), n :: size(32)>> <> rest = packfile + {:pack, 2, n, rest} + end + + @spec parse_objects(integer, binary) :: [{:commit|:blob|:tree, + binary, + binary}] + def parse_objects(n, pack) do + nil + end end diff --git a/test/exgit/packfile_test.exs b/test/exgit/packfile_test.exs index fd49787..a3c5d4c 100644 --- a/test/exgit/packfile_test.exs +++ b/test/exgit/packfile_test.exs @@ -1,4 +1,28 @@ defmodule Exgit.Packfile.Test do use ExUnit.Case + import Exgit.Packfile + doctest Exgit.Packfile + + @fixtures_dir "test/fixtures/packfiles/" + + describe "can parse header information" do + test "header with version 2" do + filename = Path.join(@fixtures_dir, "pack-simple.pack") + packfile = File.read!(filename) + assert {:pack, 2, 3, _} = parse_header(packfile) + end + end + + describe "parse objects from pack" do + test "can return all objects from pack" do + filename = Path.join(@fixtures_dir, "pack-simple.pack") + packfile = File.read!(filename) + {:pack, 2, 3, rest} = parse_header(packfile) + assert [{:commit, "ca5bae75ae512b3e3a3d86f6009452d24cc3873f", }, + {:blob, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", _}, + {:tree, "4d5fcadc293a348e88f777dc0920f11e7d71441c", _}] = + parse_objects(3, rest) + end + end end diff --git a/test/fixtures/packfiles/pack-simple.idx b/test/fixtures/packfiles/pack-simple.idx Binary files differnew file mode 100644 index 0000000..0bd43fd --- /dev/null +++ b/test/fixtures/packfiles/pack-simple.idx diff --git a/test/fixtures/packfiles/pack-simple.pack b/test/fixtures/packfiles/pack-simple.pack Binary files differnew file mode 100644 index 0000000..58a2362 --- /dev/null +++ b/test/fixtures/packfiles/pack-simple.pack diff --git a/test/fixtures/packfiles/pack-simple3.pack b/test/fixtures/packfiles/pack-simple3.pack Binary files differnew file mode 100644 index 0000000..58a2362 --- /dev/null +++ b/test/fixtures/packfiles/pack-simple3.pack |