summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@gmail.com>2013-11-07 00:47:50 +0000
committerRichard Maw <richard.maw@gmail.com>2013-11-07 00:47:50 +0000
commit4145cf6f384ea7a0d9df7564d2a091826a4c8338 (patch)
tree901abed77855de18fc9b94110a1bb9aedad1654a
parente51dc6c345665dec4632301516553e5cde875298 (diff)
downloadtar-clone-4145cf6f384ea7a0d9df7564d2a091826a4c8338.tar.bz2
Handle repos with a large number of filesHEADmaster
It would previously blow the stack when trying to run spawn, since it unpacks the args at one point.
-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()