Class: RJGit::Tree
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#id ⇒ Object
(also: #get_name)
readonly
Returns the value of attribute id.
-
#jtree ⇒ Object
readonly
Returns the value of attribute jtree.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Class Method Summary collapse
- .find_tree(repository, file_path, revstring = Constants::HEAD) ⇒ Object
- .new_from_hashmap(repository, hashmap, base_tree = nil) ⇒ Object
Instance Method Summary collapse
- #/(file) ⇒ Object
- #blobs ⇒ Object
- #data ⇒ Object
- #each(&block) ⇒ Object
- #find(&block) ⇒ Object
- #find_all(&block) ⇒ Object
- #find_blob(&block) ⇒ Object
- #find_tree(&block) ⇒ Object
-
#initialize(repository, mode, path, jtree) ⇒ Tree
constructor
A new instance of Tree.
- #recursive_contents_array(limit = nil) ⇒ Object
- #recursive_count(limit = nil) ⇒ Object
- #trees ⇒ Object
Constructor Details
#initialize(repository, mode, path, jtree) ⇒ Tree
Returns a new instance of Tree.
13 14 15 16 17 18 19 20 |
# File 'lib/tree.rb', line 13 def initialize(repository, mode, path, jtree) @jrepo = RJGit.repository_type(repository) @mode = mode @path = path @name = @path ? File.basename(path) : nil @jtree = jtree @id = ObjectId.to_string(jtree.get_id) end |
Instance Attribute Details
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
8 9 10 |
# File 'lib/tree.rb', line 8 def contents @contents end |
#id ⇒ Object (readonly) Also known as: get_name
Returns the value of attribute id.
8 9 10 |
# File 'lib/tree.rb', line 8 def id @id end |
#jtree ⇒ Object (readonly)
Returns the value of attribute jtree.
8 9 10 |
# File 'lib/tree.rb', line 8 def jtree @jtree end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
8 9 10 |
# File 'lib/tree.rb', line 8 def mode @mode end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/tree.rb', line 8 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/tree.rb', line 8 def path @path end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
8 9 10 |
# File 'lib/tree.rb', line 8 def repo @repo end |
Class Method Details
.find_tree(repository, file_path, revstring = Constants::HEAD) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/tree.rb', line 98 def self.find_tree(repository, file_path, revstring=Constants::HEAD) jrepo = RJGit.repository_type(repository) return nil if jrepo.nil? last_commit = jrepo.resolve(revstring) return nil if last_commit.nil? walk = RevWalk.new(jrepo) commit = walk.parse_commit(last_commit) treewalk = TreeWalk.new(jrepo) jtree = commit.get_tree treewalk.add_tree(jtree) treewalk.set_filter(PathFilter.create(file_path)) if treewalk.next jsubtree = walk.lookup_tree(treewalk.get_object_id(0)) if jsubtree mode = RJGit.get_file_mode_with_path(jrepo, file_path, jtree) Tree.new(jrepo, mode, file_path, jsubtree) end else nil end end |
.new_from_hashmap(repository, hashmap, base_tree = nil) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/tree.rb', line 88 def self.new_from_hashmap(repository, hashmap, base_tree = nil) jrepo = RJGit.repository_type(repository) tree_builder = Plumbing::TreeBuilder.new(jrepo) base_tree = RJGit.tree_type(base_tree) new_tree = tree_builder.build_tree(base_tree, hashmap, true) walk = RevWalk.new(jrepo) new_tree = walk.lookup_tree(new_tree) Tree.new(jrepo, TREE_TYPE, nil, new_tree) end |
Instance Method Details
#/(file) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/tree.rb', line 74 def /(file) if file =~ /^\/+$/ self else treewalk = TreeWalk.forPath(@jrepo, file, @jtree) if treewalk mode = treewalk.get_file_mode(0) wrap_tree_or_blob(obj_type(mode), mode.get_bits, treewalk.get_path_string, treewalk.get_object_id(0)) else nil end end end |
#blobs ⇒ Object
66 67 68 |
# File 'lib/tree.rb', line 66 def blobs @content_blobs ||= contents_array.select {|x| x.is_a?(Blob)} end |
#data ⇒ Object
22 23 24 25 26 27 |
# File 'lib/tree.rb', line 22 def data return @contents if @contents strio = StringIO.new RJGit::Porcelain.ls_tree(@jrepo, @path, Constants::HEAD, ={:print => true, :io => strio}) @contents = strio.string end |
#each(&block) ⇒ Object
62 63 64 |
# File 'lib/tree.rb', line 62 def each(&block) contents_array.each(&block) end |
#find(&block) ⇒ Object
52 53 54 55 |
# File 'lib/tree.rb', line 52 def find(&block) return nil unless block_given? _find(nil) {|tree_entry| yield tree_entry} end |
#find_all(&block) ⇒ Object
57 58 59 60 |
# File 'lib/tree.rb', line 57 def find_all(&block) return nil unless block_given? _find(nil, true) {|tree_entry| yield tree_entry} end |
#find_blob(&block) ⇒ Object
42 43 44 45 |
# File 'lib/tree.rb', line 42 def find_blob(&block) return nil unless block_given? _find(:Blob) {|tree_entry| yield tree_entry } end |
#find_tree(&block) ⇒ Object
47 48 49 50 |
# File 'lib/tree.rb', line 47 def find_tree(&block) return nil unless block_given? _find(:Tree) {|tree_entry| yield tree_entry } end |
#recursive_contents_array(limit = nil) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/tree.rb', line 29 def recursive_contents_array(limit = nil) if @recursive_contents.nil? || @recursive_contents[:limit] != limit @recursive_contents = {} @recursive_contents[:objects] = jtree_entries({recursive: true, limit: limit}) @recursive_contents[:limit] = limit end @recursive_contents[:objects] end |
#recursive_count(limit = nil) ⇒ Object
38 39 40 |
# File 'lib/tree.rb', line 38 def recursive_count(limit = nil) recursive_contents_array(limit).size end |
#trees ⇒ Object
70 71 72 |
# File 'lib/tree.rb', line 70 def trees @content_trees ||= contents_array.select {|x| x.is_a?(Tree)} end |