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/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/diff_tree.rb,
lib/gitlab/git/wiki_file.rb,
lib/gitlab/git/wiki_page.rb,
lib/gitlab/git/base_error.rb,
lib/gitlab/git/blame_mode.rb,
lib/gitlab/git/cross_repo.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/changed_path.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/blame_pagination.rb,
lib/gitlab/git/declared_license.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/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/finders/refs_finder.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/reference_update_error.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, Finders, Patches, RepositoryMirroring, RuggedImpl, Util, Version, WrapsGitalyErrors Classes: AttributesAtRefParser, AttributesParser, BaseError, Blame, BlameLine, BlameMode, BlamePagination, Blob, Branch, BundleFile, ChangedPath, Changes, Commit, CommitStats, Compare, CrossRepo, DeclaredLicense, Diff, DiffCollection, DiffStatsCollection, DiffTree, GitmodulesParser, HookEnv, Index, KeepAround, LfsChanges, LfsPointerFile, MergeBase, ObjectPool, OperationService, PathHelper, PreReceiveError, Push, RawDiffChange, Ref, ReferenceUpdateError, RemoteMirror, Repository, RepositoryCleaner, ResourceExhaustedError, Tag, Tree, User, WikiFile, WikiPage, WikiPageVersion

Constant Summary collapse

EMPTY_TREE_ID =
'4b825dc642cb6eb9a060e54bf8d69288fbee4904'
BLANK_SHA =
('0' * 40).freeze
COMMIT_ID =
/\A#{Gitlab::Git::Commit::RAW_FULL_SHA_PATTERN}\z/
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)
AmbiguousRef =
Class.new(BaseError)
CommandTimedOut =
Class.new(CommandError)
InvalidPageToken =
Class.new(BaseError)
InvalidRefFormatError =
Class.new(BaseError)
ReferencesLockedError =
Class.new(BaseError)
ReferenceStateMismatchError =
Class.new(BaseError)

Constants included from EncodingHelper

EncodingHelper::BOM_UTF8, EncodingHelper::ENCODING_CONFIDENCE_THRESHOLD, EncodingHelper::ESCAPED_CHARS, EncodingHelper::UNICODE_REPLACEMENT_CHARACTER

Class Method Summary collapse

Methods included from EncodingHelper

binary_io, detect_binary?, detect_encoding, detect_libgit2_binary?, encode!, encode_binary, encode_utf8, encode_utf8_no_detect, encode_utf8_with_escaping!, encode_utf8_with_replacement_character, strip_bom, unquote_path

Class Method Details

.blank_ref?(ref) ⇒ Boolean

Returns:

  • (Boolean)


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

def blank_ref?(ref)
  ref == BLANK_SHA
end

.branch_name(ref) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/gitlab/git.rb', line 48

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)


70
71
72
# File 'lib/gitlab/git.rb', line 70

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

.check_namespace!(*objects) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/gitlab/git.rb', line 86

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)


78
79
80
# File 'lib/gitlab/git.rb', line 78

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

.diff_line_code(file_path, new_line_position, old_line_position) ⇒ Object



95
96
97
# File 'lib/gitlab/git.rb', line 95

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



44
45
46
# File 'lib/gitlab/git.rb', line 44

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

.shas_eql?(sha1, sha2) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/gitlab/git.rb', line 99

def shas_eql?(sha1, sha2)
  return true if sha1.nil? && sha2.nil?
  return false if sha1.nil? || sha2.nil?
  return false unless sha1.instance_of?(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

  # Optimization: prevent unnecessary substring creation
  if sha1.length == sha2.length
    sha1 == sha2
  else
    sha1[0, length] == sha2[0, length]
  end
end

.tag_name(ref) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/gitlab/git.rb', line 57

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)


66
67
68
# File 'lib/gitlab/git.rb', line 66

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

.versionObject



82
83
84
# File 'lib/gitlab/git.rb', line 82

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