@@ -135,7 +135,7 @@ def rugged_head
135135 # Archive Project to .tar.gz
136136 #
137137 # Already packed repo archives stored at
138- # app_root/tmp/repositories/project_name/ project_name-commit-id.tag .gz
138+ # app_root/tmp/repositories/< project_name>.git/< project_name>-<ref>-<commit id>.tar .gz
139139 #
140140 def archive_repo ( ref , storage_path , format = "tar.gz" )
141141 ref ||= root_ref
@@ -147,16 +147,15 @@ def archive_repo(ref, storage_path, format = "tar.gz")
147147
148148 case format
149149 when "tar.bz2" , "tbz" , "tbz2" , "tb2" , "bz2"
150- pipe_cmd = %W( bzip2 )
150+ compress_cmd = %W( bzip2 )
151151 when "tar"
152- pipe_cmd = %W( cat )
152+ compress_cmd = %W( cat )
153153 when "zip"
154154 git_archive_format = "zip"
155- pipe_cmd = %W( cat )
155+ compress_cmd = %W( cat )
156156 else
157157 # everything else should fall back to tar.gz
158- git_archive_format = nil
159- pipe_cmd = %W( gzip -n )
158+ compress_cmd = %W( gzip -n )
160159 end
161160
162161 FileUtils . mkdir_p File . dirname ( file_path )
@@ -174,7 +173,7 @@ def archive_repo(ref, storage_path, format = "tar.gz")
174173 temp_file_path = "#{ file_path } .#{ Process . pid } -#{ Time . now . to_i } "
175174
176175 begin
177- archive_to_file ( ref , temp_file_path , git_archive_format , pipe_cmd )
176+ archive_to_file ( ref , temp_file_path , git_archive_format , compress_cmd )
178177 rescue
179178 FileUtils . rm ( temp_file_path )
180179 raise
@@ -188,26 +187,34 @@ def archive_repo(ref, storage_path, format = "tar.gz")
188187 file_path
189188 end
190189
191- def archive_file_path ( ref , storage_path , format = "tar.gz" )
190+ def archive_name ( ref )
192191 ref ||= root_ref
193192 commit = Gitlab ::Git ::Commit . find ( self , ref )
194193 return nil unless commit
195194
195+ project_name = self . name . sub ( /\. git\z / , "" )
196+ file_name = "#{ project_name } -#{ ref } -#{ commit . id } "
197+ end
198+
199+ def archive_file_path ( ref , storage_path , format = "tar.gz" )
200+ # Build file path
201+ name = archive_name ( ref )
202+ return nil unless name
203+
196204 extension =
197205 case format
198206 when "tar.bz2" , "tbz" , "tbz2" , "tb2" , "bz2"
199- ". tar.bz2"
207+ "tar.bz2"
200208 when "tar"
201- ". tar"
209+ "tar"
202210 when "zip"
203- ". zip"
211+ "zip"
204212 else
205213 # everything else should fall back to tar.gz
206- ". tar.gz"
214+ "tar.gz"
207215 end
208216
209- # Build file path
210- file_name = self . name . gsub ( "\. git" , "" ) + "-" + commit . id . to_s + extension
217+ file_name = "#{ name } .#{ extension } "
211218 File . join ( storage_path , self . name , file_name )
212219 end
213220
@@ -947,14 +954,16 @@ def detect_rename(commit, parent, path)
947954 end
948955 end
949956
950- def archive_to_file ( treeish = 'master' , filename = 'archive.tar.gz' , format = nil , compress_cmd = %W( gzip ) )
957+ def archive_to_file ( treeish = 'master' , filename = 'archive.tar.gz' , format = nil , compress_cmd = %W( gzip -n ) )
951958 git_archive_cmd = %W( git --git-dir=#{ path } archive )
952959
953960 # Put files into a directory before archiving
954- prefix = File . basename ( self . name ) + " /"
961+ prefix = " #{ archive_name ( treeish ) } /"
955962 git_archive_cmd << "--prefix=#{ prefix } "
956963
964+ # Format defaults to tar
957965 git_archive_cmd << "--format=#{ format } " if format
966+
958967 git_archive_cmd += %W( -- #{ treeish } )
959968
960969 open ( filename , 'w' ) do |file |
0 commit comments