summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-09-08 21:27:57 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-09-08 21:27:57 +0100
commit02c686dcc0b70ad66f55c2873f083e68eab0b089 (patch)
treea98e50d7de11d1cb4c53bcc4cd68380a153301b7
parentf0613b4cc5763d3de7dd65b89e6b4f9d3c6e6190 (diff)
downloadgall-02c686dcc0b70ad66f55c2873f083e68eab0b089.tar.gz
GALL: Initial git2 support, saves a litle under 30% of git spawns in the test suite
-rw-r--r--Makefile14
-rw-r--r--lib/gall/object.lua24
-rw-r--r--lib/gall/repository.lua9
3 files changed, 42 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index f5e2a5c..3be2c1a 100644
--- a/Makefile
+++ b/Makefile
@@ -54,18 +54,28 @@ example:
.PHONY: test
test: cmodule
- @$(RM) luacov.stats.out
- @ERR=0; \
+ @$(RM) luacov.stats.out; \
+ ERR=0; \
for MOD in $(sort $(MODULES)); do \
echo -n "$${MOD}: "; \
$(LUA) test/test-$${MOD}.lua; \
test "x$$?" = "x0" || ERR=1; \
+ done; \
+ $(LUA) extras/luacov/src/bin/luacov -X luacov. -X test. $(MODULES); \
+ mv luacov.report.out luacov.report.git2.out; \
+ for MOD in $(sort $(MODULES)); do \
echo -n "$${MOD} [no git2]: "; \
GALL_DISABLE_GIT2=1 $(LUA) test/test-$${MOD}.lua; \
test "x$$?" = "x0" || ERR=1; \
done; \
$(LUA) extras/luacov/src/bin/luacov -X luacov. -X test. $(MODULES); \
exit $$ERR
+ @echo -n "GIT2 saves "; \
+ PRE=$$(grep sp.spawn_simple luacov.report.git2.out | awk '{print $$1}'); \
+ POST=$$(grep sp.spawn_simple luacov.report.out | awk '{print $$1}'); \
+ NORM=$$((POST - PRE)); \
+ echo -n $$((NORM - PRE)) / $${NORM}; \
+ echo " calls out to git."
.PHONY: interactive
interactive:
diff --git a/lib/gall/object.lua b/lib/gall/object.lua
index 2772587..bedc6f1 100644
--- a/lib/gall/object.lua
+++ b/lib/gall/object.lua
@@ -12,6 +12,7 @@ local tree = require "gall.tree"
local tag = require "gall.tag"
local repos = setmetatable({}, {__mode="k"})
+local blobs = setmetatable({}, {__mode="k"})
local known_types = {
blob = true, commit = true, tree = true, tag = true,
@@ -19,12 +20,25 @@ local known_types = {
local function _objectindex(obj, field)
local ok, ret
+ local blob = blobs[obj]
if field == "type" then
- ok, ret = repos[obj]:gather("cat-file", "-t", obj.sha)
+ if blob then
+ ok, ret = 0, blob:type()
+ else
+ ok, ret = repos[obj]:gather("cat-file", "-t", obj.sha)
+ end
elseif field == "size" then
- ok, ret = repos[obj]:gather("cat-file", "-s", obj.sha)
+ if blob then
+ ok, ret = 0, blob:size()
+ else
+ ok, ret = repos[obj]:gather("cat-file", "-s", obj.sha)
+ end
elseif field == "raw" then
- ok, ret = repos[obj]:rawgather("cat-file", (obj.type == "tag" and "tag" or "-p"), obj.sha)
+ if blob and obj.type ~= "tree" then
+ ok, ret = 0, blob:data()
+ else
+ ok, ret = repos[obj]:rawgather("cat-file", (obj.type == "tag" and "tag" or "-p"), obj.sha)
+ end
elseif field == "content" then
assert(known_types[obj.type], "Unknown type: " .. obj.type)
if obj.type == "blob" then
@@ -61,6 +75,10 @@ local objectmeta = {
local function _new(repo, sha)
local ret = setmetatable({sha=sha}, objectmeta)
repos[ret] = repo
+ if ll.git2 then
+ local oid = ll.git2.OID.hex(sha)
+ blobs[ret] = repo.git2.odb:read(oid)
+ end
return ret
end
diff --git a/lib/gall/repository.lua b/lib/gall/repository.lua
index 5c157d8..32be33c 100644
--- a/lib/gall/repository.lua
+++ b/lib/gall/repository.lua
@@ -263,6 +263,15 @@ local function _new(path)
retrepo.work = workpath
retrepo.HEAD = symref
+ if ll.git2 then
+ local git2, msg = ll.git2.Repository(retrepo.path)
+ if not git2 then
+ return nil, msg
+ end
+ local odb = git2:odb()
+ retrepo.git2 = { repo = git2, odb = odb }
+ end
+
return setmetatable(retrepo, repomt)
end