Class: Gitlab::Git::Tree

Inherits:
Object
  • Object
show all
Extended by:
WrapsGitalyErrors
Includes:
EncodingHelper
Defined in:
lib/gitlab/git/tree.rb

Constant Summary

Constants included from EncodingHelper

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from WrapsGitalyErrors

wrapped_gitaly_errors

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, #force_encode_utf8, #strip_bom, #unquote_path

Constructor Details

#initialize(options) ⇒ Tree

Returns a new instance of Tree.



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

def initialize(options)
  %w[id name path flat_path type mode commit_id].each do |key|
    self.send("#{key}=", options[key.to_sym]) # rubocop:disable GitlabSecurity/PublicSend
  end
end

Instance Attribute Details

#commit_idObject

Returns the value of attribute commit_id.



9
10
11
# File 'lib/gitlab/git/tree.rb', line 9

def commit_id
  @commit_id
end

#flat_pathObject



86
87
88
# File 'lib/gitlab/git/tree.rb', line 86

def flat_path
  encode! @flat_path
end

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/gitlab/git/tree.rb', line 9

def id
  @id
end

#modeObject

Returns the value of attribute mode.



9
10
11
# File 'lib/gitlab/git/tree.rb', line 9

def mode
  @mode
end

#nameObject



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

def name
  encode! @name
end

#pathObject



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

def path
  encode! @path
end

#ref_typeObject

Returns the value of attribute ref_type.



9
10
11
# File 'lib/gitlab/git/tree.rb', line 9

def ref_type
  @ref_type
end

#submodule_urlObject

Returns the value of attribute submodule_url.



9
10
11
# File 'lib/gitlab/git/tree.rb', line 9

def submodule_url
  @submodule_url
end

#typeObject

Returns the value of attribute type.



9
10
11
# File 'lib/gitlab/git/tree.rb', line 9

def type
  @type
end

Class Method Details

.tree_entries(repository:, sha:, path: nil, recursive: false, skip_flat_paths: true, rescue_not_found: true, pagination_params: nil) ⇒ Object

Get list of tree objects for repository based on commit sha and path



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gitlab/git/tree.rb', line 15

def tree_entries(
  repository:,
  sha:,
  path: nil,
  recursive: false,
  skip_flat_paths: true,
  rescue_not_found:  true,
  pagination_params: nil
)
  path = nil if path == '' || path == '/'

  wrapped_gitaly_errors do
    repository.gitaly_commit_client.tree_entries(
      repository, sha, path, recursive, skip_flat_paths, pagination_params)
  end

# Incorrect revision or path could lead to index error.
# We silently handle such errors by returning an empty set of entries and cursor
# unless the parameter rescue_not_found is set to false.
rescue Gitlab::Git::Index::IndexError => e
  return [[], nil] if rescue_not_found

  raise e
end

Instance Method Details

#contributing?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/gitlab/git/tree.rb', line 106

def contributing?
  name =~ /^contributing/i
end

#dir?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/gitlab/git/tree.rb', line 90

def dir?
  type == :tree
end

#file?Boolean

Returns:

  • (Boolean)


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

def file?
  type == :blob
end

#readme?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/gitlab/git/tree.rb', line 102

def readme?
  name =~ /^readme/i
end

#submodule?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/gitlab/git/tree.rb', line 98

def submodule?
  type == :commit
end