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

Constructor Details

#initialize(options) ⇒ Tree

Returns a new instance of Tree.



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

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



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

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



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

def name
  encode! @name
end

#pathObject



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

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, recursive, skip_flat_paths, rescue_not_found, pagination_params = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gitlab/git/tree.rb', line 26

def tree_entries(repository, sha, path, recursive, skip_flat_paths, rescue_not_found, pagination_params = nil)
  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

.where(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 Uses rugged for raw objects

Gitaly migration: gitlab.com/gitlab-org/gitaly/issues/320



18
19
20
21
22
23
24
# File 'lib/gitlab/git/tree.rb', line 18

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

  tree_entries(repository, sha, path, recursive, skip_flat_paths, rescue_not_found, pagination_params)
end

Instance Method Details

#contributing?Boolean

Returns:

  • (Boolean)


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

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

#dir?Boolean

Returns:

  • (Boolean)


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

def dir?
  type == :tree
end

#file?Boolean

Returns:

  • (Boolean)


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

def file?
  type == :blob
end

#readme?Boolean

Returns:

  • (Boolean)


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

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

#submodule?Boolean

Returns:

  • (Boolean)


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

def submodule?
  type == :commit
end