Skip to content

Commit 42b2abd

Browse files
committed
Lib: Return the archive contents instead of writing to a temporary file
1 parent 83703ce commit 42b2abd

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

lib/git/lib.rb

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -836,22 +836,19 @@ def archive(sha, file = nil, opts = {})
836836
opts[:add_gzip] = true
837837
end
838838

839-
if !file
840-
tempfile = Tempfile.new('archive')
841-
file = tempfile.path
842-
# delete it now, before we write to it, so that Ruby doesn't delete it
843-
# when it finalizes the Tempfile.
844-
tempfile.close!
845-
end
846-
847839
arr_opts = []
848840
arr_opts << "--format=#{opts[:format]}" if opts[:format]
849841
arr_opts << "--prefix=#{opts[:prefix]}" if opts[:prefix]
850842
arr_opts << "--remote=#{opts[:remote]}" if opts[:remote]
851843
arr_opts << sha
852844
arr_opts << '--' << opts[:path] if opts[:path]
853-
command('archive', arr_opts, true, (opts[:add_gzip] ? '| gzip' : '') + " > #{escape file}")
854-
return file
845+
846+
if file
847+
command('archive', arr_opts, true, (opts[:add_gzip] ? '| gzip' : '') + " > #{escape file}")
848+
return file
849+
else
850+
command('archive', arr_opts, true, (opts[:add_gzip] ? '| gzip' : ''))
851+
end
855852
end
856853

857854
# returns the current version of git, as an Array of Fixnums.

0 commit comments

Comments
 (0)