Parent

Gitlab::Git::Tree

Attributes

commit_id[RW]
id[RW]
mode[RW]
name[RW]
path[RW]
root_id[RW]
submodule_url[RW]
type[RW]

Public Class Methods

find_id_by_path(repository, root_id, path) click to toggle source

Recursive search of tree id for path

Ex.

blog/            # oid: 1a
  app/           # oid: 2a
    models/      # oid: 3a
    views/       # oid: 4a

Tree.find_id_by_path(repo, '1a', 'app/models') # => '3a'

# File lib/gitlab_git/tree.rb, line 52
def find_id_by_path(repository, root_id, path)
  root_tree = repository.lookup(root_id)
  path_arr = path.split('/')

  entry = root_tree.find do |entry|
    entry[:name] == path_arr[0] && entry[:type] == :tree
  end

  return nil unless entry

  if path_arr.size > 1
    path_arr.shift
    find_id_by_path(repository, entry[:oid], path_arr.join('/'))
  else
    entry[:oid]
  end
end
new(options) click to toggle source
# File lib/gitlab_git/tree.rb, line 71
def initialize(options)
  %(id root_id name path type mode commit_id).each do |key|
    self.send("#{key}=", options[key.to_sym])
  end
end
where(repository, sha, path = nil) click to toggle source

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

# File lib/gitlab_git/tree.rb, line 11
def where(repository, sha, path = nil)
  path = nil if path == '' || path == '/'

  commit = repository.lookup(sha)
  root_tree = commit.tree

  tree = if path
           id = Tree.find_id_by_path(repository, root_tree.oid, path)
           if id
             repository.lookup(id)
           else
             []
           end
         else
           root_tree
         end

  tree.map do |entry|
    Tree.new(
      id: entry[:oid],
      root_id: root_tree.oid,
      name: entry[:name],
      type: entry[:type],
      mode: entry[:filemode],
      path: path ? File.join(path, entry[:name]) : entry[:name],
      commit_id: sha,
    )
  end
end

Public Instance Methods

contributing?() click to toggle source
# File lib/gitlab_git/tree.rb, line 93
def contributing?
  name =~ /^contributing/
end
dir?() click to toggle source
# File lib/gitlab_git/tree.rb, line 77
def dir?
  type == :tree
end
file?() click to toggle source
# File lib/gitlab_git/tree.rb, line 81
def file?
  type == :blob
end
readme?() click to toggle source
# File lib/gitlab_git/tree.rb, line 89
def readme?
  name =~ /^readme/
end
submodule?() click to toggle source
# File lib/gitlab_git/tree.rb, line 85
def submodule?
  type == :commit
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.