lib/gitlab_git/repository.rb in gitlab_git-7.2.6 vs lib/gitlab_git/repository.rb in gitlab_git-7.2.8

- old
+ new

@@ -51,12 +51,16 @@ end # Returns an Array of Branches def branches rugged.branches.map do |rugged_ref| - Branch.new(rugged_ref.name, rugged_ref.target) - end.sort_by(&:name) + begin + Branch.new(rugged_ref.name, rugged_ref.target) + rescue Rugged::ReferenceError + # Omit invalid branch + end + end.compact.sort_by(&:name) end # Returns an Array of tag names def tag_names rugged.tags.map { |t| t.name } @@ -133,11 +137,11 @@ end # Archive Project to .tar.gz # # Already packed repo archives stored at - # app_root/tmp/repositories/project_name/project_name-commit-id.tag.gz + # app_root/tmp/repositories/<project_name>.git/<project_name>-<ref>-<commit id>.tar.gz # def archive_repo(ref, storage_path, format = "tar.gz") ref ||= root_ref file_path = archive_file_path(ref, storage_path, format) @@ -145,20 +149,19 @@ return file_path if File.exist?(file_path) case format when "tar.bz2", "tbz", "tbz2", "tb2", "bz2" - pipe_cmd = %W(bzip2) + compress_cmd = %W(bzip2) when "tar" - pipe_cmd = %W(cat) + compress_cmd = %W(cat) when "zip" git_archive_format = "zip" - pipe_cmd = %W(cat) + compress_cmd = %W(cat) else # everything else should fall back to tar.gz - git_archive_format = nil - pipe_cmd = %W(gzip -n) + compress_cmd = %W(gzip -n) end FileUtils.mkdir_p File.dirname(file_path) pid_file_path = archive_pid_file_path(ref, storage_path, format) @@ -172,11 +175,11 @@ # to be downloaded by the next user if we get interrupted while # creating the archive. temp_file_path = "#{file_path}.#{Process.pid}-#{Time.now.to_i}" begin - archive_to_file(ref, temp_file_path, git_archive_format, pipe_cmd) + archive_to_file(ref, temp_file_path, git_archive_format, compress_cmd) rescue FileUtils.rm(temp_file_path) raise ensure FileUtils.rm(pid_file_path) @@ -186,30 +189,38 @@ FileUtils.move(temp_file_path, file_path) file_path end - def archive_file_path(ref, storage_path, format = "tar.gz") + def archive_name(ref) ref ||= root_ref commit = Gitlab::Git::Commit.find(self, ref) return nil unless commit + project_name = self.name.sub(/\.git\z/, "") + file_name = "#{project_name}-#{ref}-#{commit.id}" + end + + def archive_file_path(ref, storage_path, format = "tar.gz") + # Build file path + name = archive_name(ref) + return nil unless name + extension = case format when "tar.bz2", "tbz", "tbz2", "tb2", "bz2" - ".tar.bz2" + "tar.bz2" when "tar" - ".tar" + "tar" when "zip" - ".zip" + "zip" else # everything else should fall back to tar.gz - ".tar.gz" + "tar.gz" end - # Build file path - file_name = self.name.gsub("\.git", "") + "-" + commit.id.to_s + extension + file_name = "#{name}.#{extension}" File.join(storage_path, self.name, file_name) end def archive_pid_file_path(*args) "#{archive_file_path(*args)}.pid" @@ -287,16 +298,19 @@ # Return a collection of Rugged::Commits between the two SHA arguments. # def commits_between(from, to) walker = Rugged::Walker.new(rugged) + walker.sorting(Rugged::SORT_DATE | Rugged::SORT_REVERSE) + walker.push(to) walker.hide(from) + commits = walker.to_a walker.reset - commits.reverse + commits end # Returns the SHA of the most recent common ancestor of +from+ and +to+ def merge_base_commit(from, to) rugged.merge_base(from, to) @@ -942,17 +956,19 @@ end end end end - def archive_to_file(treeish = 'master', filename = 'archive.tar.gz', format = nil, compress_cmd = %W(gzip)) + def archive_to_file(treeish = 'master', filename = 'archive.tar.gz', format = nil, compress_cmd = %W(gzip -n)) git_archive_cmd = %W(git --git-dir=#{path} archive) # Put files into a directory before archiving - prefix = File.basename(self.name) + "/" + prefix = "#{archive_name(treeish)}/" git_archive_cmd << "--prefix=#{prefix}" + # Format defaults to tar git_archive_cmd << "--format=#{format}" if format + git_archive_cmd += %W(-- #{treeish}) open(filename, 'w') do |file| # Create a pipe to act as the '|' in 'git archive ... | gzip' pipe_rd, pipe_wr = IO.pipe