lib/grit/git-ruby.rb in gitlab-grit-2.5.2 vs lib/grit/git-ruby.rb in gitlab-grit-2.6.0

- old
+ new

@@ -114,31 +114,33 @@ end def refs(options, prefix) refs = [] already = {} - Dir.chdir(@git_dir) do - files = Dir.glob(prefix + '/**/*') - files.each do |ref| - next if !File.file?(ref) - id = File.read(ref).chomp - name = ref.sub("#{prefix}/", '') - if !already[name] - refs << "#{name} #{id}" - already[name] = true - end + orig_prefix = prefix + prefix = File.join @git_dir, prefix + + files = Dir.glob(prefix + '/**/*') + files.each do |ref| + next if !File.file?(ref) + id = File.read(ref).chomp + name = ref.sub("#{prefix}/", '') + if !already[name] + refs << "#{name} #{id}" + already[name] = true end + end - if File.file?('packed-refs') - File.readlines('packed-refs').each do |line| - if m = /^(\w{40}) (.*?)$/.match(line) - next if !Regexp.new('^' + prefix).match(m[2]) - name = m[2].sub("#{prefix}/", '') - if !already[name] - refs << "#{name} #{m[1]}" - already[name] = true - end + packed = File.join(@git_dir, 'packed-refs') + if File.file?(packed) + File.readlines(packed).each do |line| + if m = /^(\w{40}) (.*?)$/.match(line) + next if !Regexp.new('^' + orig_prefix).match(m[2]) + name = m[2].sub("#{orig_prefix}/", '') + if !already[name] + refs << "#{name} #{m[1]}" + already[name] = true end end end end @@ -147,46 +149,48 @@ def tags(options, prefix) refs = [] already = {} - Dir.chdir(repo.path) do - files = Dir.glob(prefix + '/**/*') + orig_prefix = prefix + prefix = File.join @git_dir, prefix - files.each do |ref| - next if !File.file?(ref) + files = Dir.glob(prefix + '/**/*') - id = File.read(ref).chomp - name = ref.sub("#{prefix}/", '') + files.each do |ref| + next if !File.file?(ref) - if !already[name] - refs << "#{name} #{id}" - already[name] = true - end + id = File.read(ref).chomp + name = ref.sub("#{prefix}/", '') + + if !already[name] + refs << "#{name} #{id}" + already[name] = true end + end - if File.file?('packed-refs') - lines = File.readlines('packed-refs') - lines.each_with_index do |line, i| - if m = /^(\w{40}) (.*?)$/.match(line) - next if !Regexp.new('^' + prefix).match(m[2]) - name = m[2].sub("#{prefix}/", '') + packed = File.join(@git_dir, 'packed-refs') + if File.file?(packed) + lines = File.readlines('packed-refs') + lines.each_with_index do |line, i| + if m = /^(\w{40}) (.*?)$/.match(line) + next if !Regexp.new('^' + orig_prefix).match(m[2]) + name = m[2].sub("#{orig_prefix}/", '') - # Annotated tags in packed-refs include a reference - # to the commit object on the following line. - next_line = lines[i + 1] + # Annotated tags in packed-refs include a reference + # to the commit object on the following line. + next_line = lines[i + 1] - id = + id = if next_line && next_line[0] == ?^ next_line[1..-1].chomp else m[1] end - if !already[name] - refs << "#{name} #{id}" - already[name] = true - end + if !already[name] + refs << "#{name} #{id}" + already[name] = true end end end end