gitlab_git 7.0.0.rc7 → 7.0.0.rc8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a017d97f4752bc24ff9fc7abe49b9fc0143301a9
4
- data.tar.gz: c5bc10d54d6c635549c0d04a5cd71e29bf272247
3
+ metadata.gz: 73f18b742e441f8974c658139ba8e543bfea6f46
4
+ data.tar.gz: 35e4be4dc66c78ff87694794deec5f394666e9d3
5
5
  SHA512:
6
- metadata.gz: 84a528cad4b97c3e8ec7e177e59830b51eab8963d44eb491c09069cfa130cd62b3fb19df8ee1fb2cce5add69d452f891906bd1f8fe732ebc999de01d92276ba3
7
- data.tar.gz: db2d09da3da1c07af108da6ee783f39b298408351e9161d697864b01d66a799443acd6b106489bf772e1b192036778c358d090bd892e611ada5146305b4fb908
6
+ metadata.gz: 77de354a1a19bf8bb5588946e3d705a97c4f87b2712e610f9dfd5298c7bc72b6ebbaa34a77c36f82a9d090f49215099311121c8c944e5386090fa52702dc81d9
7
+ data.tar.gz: f29427c0a612a57cabf3e6988f30fd276778c9c28732563ad0a404450dea2cd5d650f3de81f42a4752ba141903ccbab1070dcf5392eae2f6d0ea10f91cef349b
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.0.0.rc7
1
+ 7.0.0.rc8
data/lib/gitlab_git.rb CHANGED
@@ -6,7 +6,6 @@ require 'active_support/core_ext/hash/keys'
6
6
  require 'active_support/core_ext/object/try'
7
7
  require 'rugged'
8
8
  require "charlock_holmes"
9
- require "zip"
10
9
 
11
10
  # Gitlab::Git
12
11
  require_relative "gitlab_git/popen"
@@ -22,6 +22,8 @@ module Gitlab
22
22
  # Rugged repo object
23
23
  attr_reader :rugged
24
24
 
25
+ # 'path' must be the path to a _bare_ git repository, e.g.
26
+ # /path/to/my-repo.git
25
27
  def initialize(path)
26
28
  @path = path
27
29
  @name = path.split("/").last
@@ -131,6 +133,7 @@ module Gitlab
131
133
  return nil unless commit
132
134
 
133
135
  extension = nil
136
+ git_archive_format = nil
134
137
  pipe_cmd = nil
135
138
 
136
139
  case format
@@ -142,10 +145,12 @@ module Gitlab
142
145
  pipe_cmd = %W(cat)
143
146
  when "zip"
144
147
  extension = ".zip"
148
+ git_archive_format = "zip"
145
149
  pipe_cmd = %W(cat)
146
150
  else
147
151
  # everything else should fall back to tar.gz
148
152
  extension = ".tar.gz"
153
+ git_archive_format = nil
149
154
  pipe_cmd = %W(gzip -n)
150
155
  end
151
156
 
@@ -153,12 +158,24 @@ module Gitlab
153
158
  file_name = self.name.gsub("\.git", "") + "-" + commit.id.to_s + extension
154
159
  file_path = File.join(storage_path, self.name, file_name)
155
160
 
156
- # Create dir for archive file
157
- parent_path = File.join(storage_path, self.name)
158
- FileUtils.mkdir_p(parent_path) unless File.directory?(parent_path)
161
+ # Put files into a directory before archiving
162
+ prefix = File.basename(self.name) + "/"
159
163
 
160
164
  # Create file if not exists
161
- create_archive(ref, pipe_cmd, file_path) unless File.exist?(file_path)
165
+ unless File.exists?(file_path)
166
+ FileUtils.mkdir_p File.dirname(file_path)
167
+
168
+ # Create the archive in temp file, to avoid leaving a corrupt archive
169
+ # to be downloaded by the next user if we get interrupted while
170
+ # creating the archive. Note that we do not care about cleaning up
171
+ # the temp file in that scenario, because GitLab cleans up the
172
+ # directory holding the archive files periodically.
173
+ temp_file_path = file_path + ".#{Process.pid}-#{Time.now.to_i}"
174
+ archive_to_file(ref, prefix, temp_file_path, git_archive_format, pipe_cmd)
175
+
176
+ # move temp file to persisted location
177
+ FileUtils.move(temp_file_path, file_path)
178
+ end
162
179
 
163
180
  file_path
164
181
  end
@@ -816,79 +833,35 @@ module Gitlab
816
833
  end
817
834
  end
818
835
 
819
- # Create an archive with the repository's files
820
- def create_archive(ref_name, pipe_cmd, file_path)
821
- # Put files into a prefix directory in the archive
822
- prefix = File.basename(name)
823
- extension = Pathname.new(file_path).extname
824
-
825
- if extension == '.zip'
826
- create_zip_archive(ref_name, file_path, prefix)
827
- else
828
- # Open the file with the final result
829
- FileUtils.mkdir_p(Pathname.new(file_path).dirname)
830
- archive_file = File.new(file_path, 'wb')
836
+ def archive_to_file(treeish = 'master', prefix = nil, filename = 'archive.tar.gz', format = nil, compress_cmd = %W(gzip))
837
+ git_archive_cmd = %W(git --git-dir=#{path} archive)
838
+ git_archive_cmd << "--prefix=#{prefix}" if prefix
839
+ git_archive_cmd << "--format=#{format}" if format
840
+ git_archive_cmd += %W(-- #{treeish})
831
841
 
832
- # Create a pipe to communicate with the compressor process
842
+ open(filename, 'w') do |file|
843
+ # Create a pipe to act as the '|' in 'git archive ... | gzip'
833
844
  pipe_rd, pipe_wr = IO.pipe
834
- compress_pid = spawn(*pipe_cmd, in: pipe_rd, out: archive_file)
835
- # pipe_rd and archive_file belong to the compressor process now; close
836
- # them straightaway in our process.
837
- pipe_rd.close
838
- archive_file.close
839
845
 
840
- # Change the external encoding of pipe_wr to prevent Ruby from trying
841
- # to convert binary to UTF-8.
842
- pipe_wr = IO.new(pipe_wr.fileno, 'w:ASCII-8BIT')
843
- Gem::Package::TarWriter.new(pipe_wr) do |tar|
844
- tar.mkdir(prefix, 33261)
846
+ # Get the compression process ready to accept data from the read end
847
+ # of the pipe
848
+ compress_pid = spawn(*compress_cmd, :in => pipe_rd, :out => file)
849
+ # The read end belongs to the compression process now; we should
850
+ # close our file descriptor for it.
851
+ pipe_rd.close
845
852
 
846
- populated_index(ref_name).each do |entry|
847
- add_archive_entry(tar, prefix, entry)
848
- end
849
- end
850
- # We are done with pipe_wr, close it straightaway.
853
+ # Start 'git archive' and tell it to write into the write end of the
854
+ # pipe.
855
+ git_archive_pid = spawn(*git_archive_cmd, :out => pipe_wr)
856
+ # The write end belongs to 'git archive' now; close it.
851
857
  pipe_wr.close
852
858
 
859
+ # When 'git archive' and the compression process are finished, we are
860
+ # done.
861
+ Process.waitpid(git_archive_pid)
862
+ raise "#{git_archive_cmd.join(' ')} failed" unless $?.success?
853
863
  Process.waitpid(compress_pid)
854
- end
855
- end
856
-
857
- # Create a zip file with the contents of the repo
858
- def create_zip_archive(ref_name, archive_path, prefix)
859
- Zip::File.open(archive_path, Zip::File::CREATE) do |zipfile|
860
- populated_index(ref_name).each do |entry|
861
- add_archive_entry(zipfile, prefix, entry)
862
- end
863
- end
864
- end
865
-
866
- # Add a file or directory from the index to the given tar or zip file
867
- def add_archive_entry(archive, prefix, entry)
868
- prefixed_path = File.join(prefix, entry[:path])
869
-
870
- if submodule?(entry)
871
- # Create an empty directory for submodules
872
- mask = case archive
873
- when Zip::File then 0755
874
- else '100755'.to_i(8)
875
- end
876
- archive.mkdir(prefixed_path, mask)
877
- else
878
- blob = rugged.lookup(entry[:oid])
879
- content = blob.content
880
-
881
- # Write the blob contents to the archive
882
- if archive.is_a?(Zip::File)
883
- archive.get_output_stream(prefixed_path) do |os|
884
- os.write(content)
885
- end
886
- else
887
- archive.add_file_simple(prefixed_path,
888
- entry[:mode], blob.size) do |tf|
889
- tf.write(content)
890
- end
891
- end
864
+ raise "#{compress_cmd.join(' ')} failed" unless $?.success?
892
865
  end
893
866
  end
894
867
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab_git
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0.rc7
4
+ version: 7.0.0.rc8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitriy Zaporozhets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-30 00:00:00.000000000 Z
11
+ date: 2014-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gitlab-linguist
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.6'
69
- - !ruby/object:Gem::Dependency
70
- name: rubyzip
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.1'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.1'
83
69
  description: GitLab wrapper around git objects
84
70
  email: dmitriy.zaporozhets@gmail.com
85
71
  executables: []