summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtar-clone.lua32
1 files changed, 24 insertions, 8 deletions
diff --git a/tar-clone.lua b/tar-clone.lua
index 582fd94..358a1b6 100755
--- a/tar-clone.lua
+++ b/tar-clone.lua
@@ -229,24 +229,38 @@ local function list_tree(repo, HEAD)
return output:gmatch"([^ ]+) ([^ ]+) ([^ ]+)\t([^%z]+)%z"
end
-local function write_index(writer, repo, HEAD, localname)
+local function update_index(repo, HEAD, index)
+ local function exec(args)
+ args.cwd = repo
+ args.env = {GIT_INDEX_FILE = index}
+ local proc = sp.spawn_simple(args)
+ local how, why = proc:wait()
+ if how == -1 then
+ error("git update-index failed: "..tostring(why))
+ end
+ end
local cmdline = {"git", "update-index", "--add"}
for mode, kind, sha1, path in list_tree(repo, HEAD) do
table.insert(cmdline, "--cacheinfo")
table.insert(cmdline, mode)
table.insert(cmdline, sha1)
table.insert(cmdline, path)
+ if #cmdline >= 50 then -- arbitrary limit
+ exec(cmdline)
+ cmdline = {"git", "update-index", "--add"}
+ end
end
+ if #cmdline > 3 then
+ exec(cmdline)
+ end
+end
+
+local function write_index(writer, repo, HEAD, localname)
local dir = mkdtemp()
local index = dir..'/index'
- cmdline.cwd = repo
- cmdline.env = {GIT_INDEX_FILE = index}
- local proc = sp.spawn_simple(cmdline)
- local how, why = proc:wait()
- if how == -1 then
- error("git update-index failed: "..tostring(why))
- end
+ update_index(repo, HEAD, index)
+
local entry = archive.entry{
sourcepath = index,
pathname = localname..'/.git/index',
@@ -293,3 +307,5 @@ write_refs(writer, repo, HEAD, localname)
write_workspace(writer, repo, HEAD, localname)
write_index(writer, repo, HEAD, localname)
+
+writer:close()