lib/gitlab_git/repository.rb in gitlab_git-7.0.0.rc3 vs lib/gitlab_git/repository.rb in gitlab_git-7.0.0.rc4

- old
+ new

@@ -324,11 +324,11 @@ # # Ex. # repo.branch_names_contains('master') # def branch_names_contains(commit) - branches_contains(commit).map { |c| c.target_id } + branches_contains(commit).map { |c| c.name } end # Returns branch collection that contains the special commit(SHA1 or name) # # Ex. @@ -811,37 +811,37 @@ def create_archive(ref_name, pipe_cmd, file_path) # Put files into a prefix directory in the archive prefix = File.basename(name) extension = Pathname.new(file_path).extname - if extension == ".zip" + if extension == '.zip' create_zip_archive(ref_name, file_path, prefix) else - # Create a tarfile in memory - tarfile = tar_string_io(ref_name, prefix) + rd_pipe, rw_pipe = IO.pipe + tar_pid = fork do + # Send the tar file to the write pipe + rd_pipe.close + Gem::Package::TarWriter.new(rw_pipe) do |tar| + tar.mkdir(prefix, 33261) - if extension == ".tar" - File.new(file_path, "wb").write(tarfile.read) - else - compress_tar(tarfile, file_path, pipe_cmd) + populated_index(ref_name).each do |entry| + add_archive_entry(tar, prefix, entry) + end + end + rw_pipe.close end - end - end - # Return a StringIO with the contents of the repo's tar file - def tar_string_io(ref_name, prefix) - tarfile = StringIO.new - Gem::Package::TarWriter.new(tarfile) do |tar| - tar.mkdir(prefix, 33261) + # Use the other end of the pipe to compress with bzip2 or gzip + FileUtils.mkdir_p(Pathname.new(file_path).dirname) + archive_file = File.new(file_path, 'wb') + rw_pipe.close + system(*pipe_cmd, in: rd_pipe, out: archive_file) - populated_index(ref_name).each do |entry| - add_archive_entry(tar, prefix, entry) - end + Process.waitpid(tar_pid) + rd_pipe.close + archive_file.close end - - tarfile.rewind - tarfile end # Create a zip file with the contents of the repo def create_zip_archive(ref_name, archive_path, prefix) Zip::File.open(archive_path, Zip::File::CREATE) do |zipfile| @@ -852,60 +852,39 @@ end # Add a file or directory from the index to the given tar or zip file def add_archive_entry(archive, prefix, entry) prefixed_path = File.join(prefix, entry[:path]) - content = rugged.lookup(entry[:oid]).content unless submodule?(entry) - # Create a file in the archive for each index entry - if archive.is_a?(Zip::File) - unless submodule?(entry) + if submodule?(entry) + # Create an empty directory for submodules + mask = case archive + when Zip::File then 0755 + else '100755'.to_i(8) + end + archive.mkdir(prefixed_path, mask) + else + blob = rugged.lookup(entry[:oid]) + content = blob.content + + # Write the blob contents to the archive + if archive.is_a?(Zip::File) archive.get_output_stream(prefixed_path) do |os| os.write(content) end - end - else - if submodule?(entry) - # Create directories for submodules - archive.mkdir(prefixed_path, 33261) else - # Write the blob contents to the file - archive.add_file(prefixed_path, entry[:mode]) do |tf| + archive.add_file_simple(prefixed_path, + entry[:mode], blob.size) do |tf| tf.write(content) end end end end # Returns true if the index entry has the special file mode that denotes # a submodule. def submodule?(index_entry) index_entry[:mode] == 57344 - end - - # Send the +tar_string+ StringIO to +pipe_cmd+ for bzip2 or gzip - # compression. - def compress_tar(tar_string, file_path, pipe_cmd) - # Write the in-memory tarfile to a pipe - rd_pipe, rw_pipe = IO.pipe - tar_pid = fork do - rd_pipe.close - rw_pipe.write(tar_string.read) - rw_pipe.close - end - - # Use the other end of the pipe to compress with bzip2 or gzip - FileUtils.mkdir_p(Pathname.new(file_path).dirname) - archive_file = File.new(file_path, "wb") - rw_pipe.close - compress_pid = spawn(*pipe_cmd, in: rd_pipe, out: archive_file) - rd_pipe.close - - Process.waitpid(tar_pid) - Process.waitpid(compress_pid) - - archive_file.close - tar_string.close end # Return a Rugged::Index that has read from the tree at +ref_name+ def populated_index(ref_name) tree = rugged.lookup(rugged.rev_parse_oid(ref_name)).tree