tags

in lib/grit/git-ruby.rb [149:199]


    def tags(options, prefix)
      refs = []
      already = {}

      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

      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}/", '')

            
            
            next_line = lines[i + 1]

            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
          end
        end
      end

      refs.join("\n")
    end