Skip to content
This repository was archived by the owner on May 12, 2018. It is now read-only.

Commit 129e630

Browse files
committed
Merge branch 'master' into sort-commits
2 parents 495fcce + c0652a5 commit 129e630

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
v 7.2.7
22
- Order result of `Repository#commits_between` by date.
3+
- Include branch/tag name in archive file and dirname
34

45
v 7.2.6
56
- Ignore remote/symbolic refs when creating repository's refs_hash (Stan Hu)

lib/gitlab_git/repository.rb

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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|

spec/repository_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
end
6565

6666
shared_examples 'archive check' do |extenstion|
67-
it { archive.should match(/tmp\/gitlab-git-test.git\/gitlab-git-test-#{SeedRepo::LastCommit::ID}/) }
67+
it { archive.should match(/tmp\/gitlab-git-test.git\/gitlab-git-test-master-#{SeedRepo::LastCommit::ID}/) }
6868
it { archive.should end_with extenstion }
6969
it { File.exists?(archive).should be_true }
7070
it { File.size?(archive).should_not be_nil }
@@ -231,7 +231,7 @@
231231
end
232232

233233
describe :archive_repo do
234-
it { repository.archive_repo('master', '/tmp').should == "/tmp/gitlab-git-test.git/gitlab-git-test-#{SeedRepo::LastCommit::ID}.tar.gz" }
234+
it { repository.archive_repo('master', '/tmp').should == "/tmp/gitlab-git-test.git/gitlab-git-test-master-#{SeedRepo::LastCommit::ID}.tar.gz" }
235235
end
236236

237237
describe "#reset" do

0 commit comments

Comments
 (0)