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::ENCODING_CONFIDENCE_THRESHOLD

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_libgit2_binary?, #encode!, #encode_binary, #encode_utf8

Constructor Details

#initialize(options) ⇒ Tree

Returns a new instance of Tree.


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

def initialize(options)
  %w(id root_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


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

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


68
69
70
# File 'lib/gitlab/git/tree.rb', line 68

def name
  encode! @name
end

#pathObject


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

def path
  encode! @path
end

#root_idObject

Returns the value of attribute root_id


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

def root_id
  @root_id
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) ⇒ Object


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

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

.where(repository, sha, path = nil, recursive = false) ⇒ 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
# File 'lib/gitlab/git/tree.rb', line 18

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

  tree_entries(repository, sha, path, recursive)
end

Instance Method Details

#contributing?Boolean

Returns:

  • (Boolean)

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

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

#dir?Boolean

Returns:

  • (Boolean)

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

def dir?
  type == :tree
end

#file?Boolean

Returns:

  • (Boolean)

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

def file?
  type == :blob
end

#readme?Boolean

Returns:

  • (Boolean)

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

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

#submodule?Boolean

Returns:

  • (Boolean)

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

def submodule?
  type == :commit
end