Module: Gitlab::Git

Extended by:
EncodingHelper
Defined in:
lib/gitlab/git.rb,
lib/gitlab/git/ref.rb,
lib/gitlab/git/tag.rb,
lib/gitlab/git/blob.rb,
lib/gitlab/git/diff.rb,
lib/gitlab/git/push.rb,
lib/gitlab/git/tree.rb,
lib/gitlab/git/user.rb,
lib/gitlab/git/util.rb,
lib/gitlab/git/wiki.rb,
lib/gitlab/git/blame.rb,
lib/gitlab/git/index.rb,
lib/gitlab/git/branch.rb,
lib/gitlab/git/commit.rb,
lib/gitlab/git/changes.rb,
lib/gitlab/git/compare.rb,
lib/gitlab/git/version.rb,
lib/gitlab/git/hook_env.rb,
lib/gitlab/git/wiki_file.rb,
lib/gitlab/git/wiki_page.rb,
lib/gitlab/git/base_error.rb,
lib/gitlab/git/merge_base.rb,
lib/gitlab/git/repository.rb,
lib/gitlab/git/bundle_file.rb,
lib/gitlab/git/keep_around.rb,
lib/gitlab/git/lfs_changes.rb,
lib/gitlab/git/object_pool.rb,
lib/gitlab/git/path_helper.rb,
lib/gitlab/git/commit_stats.rb,
lib/gitlab/git/conflict/file.rb,
lib/gitlab/git/patches/patch.rb,
lib/gitlab/git/remote_mirror.rb,
lib/gitlab/git/conflict/parser.rb,
lib/gitlab/git/diff_collection.rb,
lib/gitlab/git/raw_diff_change.rb,
lib/gitlab/git/rugged_impl/ref.rb,
lib/gitlab/git/lfs_pointer_file.rb,
lib/gitlab/git/rugged_impl/blob.rb,
lib/gitlab/git/rugged_impl/tree.rb,
lib/gitlab/git/attributes_parser.rb,
lib/gitlab/git/conflict/resolver.rb,
lib/gitlab/git/gitmodules_parser.rb,
lib/gitlab/git/operation_service.rb,
lib/gitlab/git/pre_receive_error.rb,
lib/gitlab/git/remote_repository.rb,
lib/gitlab/git/wiki_page_version.rb,
lib/gitlab/git/patches/collection.rb,
lib/gitlab/git/repository_cleaner.rb,
lib/gitlab/git/rugged_impl/commit.rb,
lib/gitlab/git/conflict/resolution.rb,
lib/gitlab/git/cross_repo_comparer.rb,
lib/gitlab/git/wraps_gitaly_errors.rb,
lib/gitlab/git/repository_mirroring.rb,
lib/gitlab/git/diff_stats_collection.rb,
lib/gitlab/git/patches/commit_patches.rb,
lib/gitlab/git/rugged_impl/repository.rb,
lib/gitlab/git/rugged_impl/use_rugged.rb,
lib/gitlab/git/attributes_at_ref_parser.rb

Defined Under Namespace

Modules: Conflict, Patches, RepositoryMirroring, RuggedImpl, Util, Version, WrapsGitalyErrors Classes: AttributesAtRefParser, AttributesParser, BaseError, Blame, BlameLine, Blob, Branch, BundleFile, Changes, Commit, CommitStats, Compare, CrossRepoComparer, Diff, DiffCollection, DiffStatsCollection, GitmodulesParser, HookEnv, Index, KeepAround, LfsChanges, LfsPointerFile, MergeBase, ObjectPool, OperationService, PathHelper, PreReceiveError, Push, RawDiffChange, Ref, RemoteMirror, RemoteRepository, Repository, RepositoryCleaner, Tag, Tree, User, Wiki, WikiFile, WikiPage, WikiPageVersion

Constant Summary collapse

EMPTY_TREE_ID =
'4b825dc642cb6eb9a060e54bf8d69288fbee4904'
BLANK_SHA =
('0' * 40).freeze
COMMIT_ID =
/\A[0-9a-f]{40}\z/.freeze
TAG_REF_PREFIX =
"refs/tags/"
BRANCH_REF_PREFIX =
"refs/heads/"
CommandError =
Class.new(BaseError)
CommitError =
Class.new(BaseError)
OSError =
Class.new(BaseError)
UnknownRef =
Class.new(BaseError)

Constants included from EncodingHelper

EncodingHelper::ENCODING_CONFIDENCE_THRESHOLD

Class Method Summary collapse

Methods included from EncodingHelper

binary_io, detect_binary?, detect_libgit2_binary?, encode!, encode_binary, encode_utf8

Class Method Details

.blank_ref?(ref) ⇒ Boolean

Returns:

  • (Boolean)

54
55
56
# File 'lib/gitlab/git.rb', line 54

def blank_ref?(ref)
  ref == BLANK_SHA
end

.branch_name(ref) ⇒ Object


28
29
30
31
32
33
34
35
# File 'lib/gitlab/git.rb', line 28

def branch_name(ref)
  ref = ref.to_s
  if self.branch_ref?(ref)
    self.ref_name(ref)
  else
    nil
  end
end

.branch_ref?(ref) ⇒ Boolean

Returns:

  • (Boolean)

50
51
52
# File 'lib/gitlab/git.rb', line 50

def branch_ref?(ref)
  ref =~ /^#{BRANCH_REF_PREFIX}.+/
end

.check_namespace!(*objects) ⇒ Object


66
67
68
69
70
71
72
73
# File 'lib/gitlab/git.rb', line 66

def check_namespace!(*objects)
  expected_namespace = self.name + '::'
  objects.each do |object|
    unless object.class.name.start_with?(expected_namespace)
      raise ArgumentError, "expected object in #{expected_namespace}, got #{object}"
    end
  end
end

.commit_id?(ref) ⇒ Boolean

Returns:

  • (Boolean)

58
59
60
# File 'lib/gitlab/git.rb', line 58

def commit_id?(ref)
  COMMIT_ID.match?(ref)
end

.diff_line_code(file_path, new_line_position, old_line_position) ⇒ Object


75
76
77
# File 'lib/gitlab/git.rb', line 75

def diff_line_code(file_path, new_line_position, old_line_position)
  "#{Digest::SHA1.hexdigest(file_path)}_#{old_line_position}_#{new_line_position}"
end

.ref_name(ref) ⇒ Object


24
25
26
# File 'lib/gitlab/git.rb', line 24

def ref_name(ref)
  encode!(ref).sub(%r{\Arefs/(tags|heads|remotes)/}, '')
end

.shas_eql?(sha1, sha2) ⇒ Boolean

Returns:

  • (Boolean)

79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/gitlab/git.rb', line 79

def shas_eql?(sha1, sha2)
  return true if sha1.nil? && sha2.nil?
  return false if sha1.nil? || sha2.nil?
  return false unless sha1.class == sha2.class

  # If either of the shas is below the minimum length, we cannot be sure
  # that they actually refer to the same commit because of hash collision.
  length = [sha1.length, sha2.length].min
  return false if length < Gitlab::Git::Commit::MIN_SHA_LENGTH

  sha1[0, length] == sha2[0, length]
end

.tag_name(ref) ⇒ Object


37
38
39
40
41
42
43
44
# File 'lib/gitlab/git.rb', line 37

def tag_name(ref)
  ref = ref.to_s
  if self.tag_ref?(ref)
    self.ref_name(ref)
  else
    nil
  end
end

.tag_ref?(ref) ⇒ Boolean

Returns:

  • (Boolean)

46
47
48
# File 'lib/gitlab/git.rb', line 46

def tag_ref?(ref)
  ref =~ /^#{TAG_REF_PREFIX}.+/
end

.versionObject


62
63
64
# File 'lib/gitlab/git.rb', line 62

def version
  Gitlab::Git::Version.git_version
end