Class: RJGit::Tree
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#id ⇒ Object
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.
-
#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
From Grit.
- #blobs ⇒ Object
- #contents_array ⇒ Object
- #data ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(repository, mode, path, jtree) ⇒ Tree
constructor
A new instance of Tree.
- #trees ⇒ Object
Constructor Details
#initialize(repository, mode, path, jtree) ⇒ Tree
Returns a new instance of Tree.
12 13 14 15 16 17 18 19 |
# File 'lib/tree.rb', line 12 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)
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 |
#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
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/tree.rb', line 70 def self.find_tree(repository, file_path, revstring=Constants::HEAD) jrepo = RJGit.repository_type(repository) return nil if jrepo.nil? last_commit_hash = jrepo.resolve(revstring) return nil if last_commit_hash.nil? walk = RevWalk.new(jrepo) commit = walk.parse_commit(last_commit_hash) 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.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
60 61 62 63 64 65 66 67 68 |
# File 'lib/tree.rb', line 60 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
From Grit
52 53 54 55 56 57 58 |
# File 'lib/tree.rb', line 52 def /(file) if file =~ /\// file.split("/").inject(self) { |acc, x| acc/x } rescue nil else self.contents_array.find { |c| c.name == file } end end |
#blobs ⇒ Object
43 44 45 |
# File 'lib/tree.rb', line 43 def blobs contents_array.select {|x| x.is_a?(Blob)} end |
#contents_array ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tree.rb', line 28 def contents_array return @contents_ary if @contents_ary results = [] RJGit::Porcelain.ls_tree(@jrepo, @jtree).each do |item| walk = RevWalk.new(@jrepo) results << Tree.new(@jrepo, item[:mode], item[:path], walk.lookup_tree(ObjectId.from_string(item[:id]))) if item[:type] == 'tree' results << Blob.new(@jrepo, item[:mode], item[:path], walk.lookup_blob(ObjectId.from_string(item[:id]))) if item[:type] == 'blob' end @contents_ary = results end |
#data ⇒ Object
21 22 23 24 25 26 |
# File 'lib/tree.rb', line 21 def data return @contents if @contents strio = StringIO.new RJGit::Porcelain.ls_tree(@jrepo, @jtree, ={:print => true, :io => strio}) @contents = strio.string end |
#each(&block) ⇒ Object
39 40 41 |
# File 'lib/tree.rb', line 39 def each(&block) contents_array.each(&block) end |
#trees ⇒ Object
47 48 49 |
# File 'lib/tree.rb', line 47 def trees contents_array.select {|x| x.is_a?(Tree)} end |