BigW Consortium Gitlab

ref.rb 1.42 KB
Newer Older
1 2
# Gitaly note: JV: probably no RPC's here (just one interaction with Rugged).

Robert Speicher committed
3 4 5
module Gitlab
  module Git
    class Ref
6
      include Gitlab::EncodingHelper
Robert Speicher committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

      # Branch or tag name
      # without "refs/tags|heads" prefix
      attr_reader :name

      # Target sha.
      # Usually it is commit sha but in case
      # when tag reference on other tag it can be tag sha
      attr_reader :target

      # Dereferenced target
      # Commit object to which the Ref points to
      attr_reader :dereferenced_target

      # Extract branch name from full ref path
      #
      # Ex.
      #   Ref.extract_branch_name('refs/heads/master') #=> 'master'
      def self.extract_branch_name(str)
        str.gsub(/\Arefs\/heads\//, '')
      end

29
      # Gitaly: this method will probably be migrated indirectly via its call sites.
Robert Speicher committed
30 31 32 33 34 35
      def self.dereference_object(object)
        object = object.target while object.is_a?(Rugged::Tag::Annotation)

        object
      end

36
      def initialize(repository, name, target, derefenced_target)
37
        @name = Gitlab::Git.ref_name(name)
38
        @dereferenced_target = derefenced_target
Robert Speicher committed
39 40 41 42 43 44 45 46 47 48 49 50 51
        @target = if target.respond_to?(:oid)
                    target.oid
                  elsif target.respond_to?(:name)
                    target.name
                  elsif target.is_a? String
                    target
                  else
                    nil
                  end
      end
    end
  end
end