Class: RJGit::Plumbing::Index
- Inherits:
-
Object
- Object
- RJGit::Plumbing::Index
- Defined in:
- lib/rjgit.rb
Instance Attribute Summary collapse
-
#current_tree ⇒ Object
Returns the value of attribute current_tree.
-
#jrepo ⇒ Object
readonly
Returns the value of attribute jrepo.
-
#treemap ⇒ Object
Returns the value of attribute treemap.
Class Method Summary collapse
Instance Method Summary collapse
- #add(path, data) ⇒ Object
- #commit(message, author, parents = nil, ref = nil, force = false) ⇒ Object
- #delete(path) ⇒ Object
- #do_commit(message, author, parents, new_tree) ⇒ Object
-
#initialize(repository) ⇒ Index
constructor
A new instance of Index.
Constructor Details
#initialize(repository) ⇒ Index
Returns a new instance of Index.
270 271 272 273 274 |
# File 'lib/rjgit.rb', line 270 def initialize(repository) @treemap = {} @jrepo = RJGit.repository_type(repository) @treebuilder = TreeBuilder.new(@jrepo) end |
Instance Attribute Details
#current_tree ⇒ Object
Returns the value of attribute current_tree.
267 268 269 |
# File 'lib/rjgit.rb', line 267 def current_tree @current_tree end |
#jrepo ⇒ Object (readonly)
Returns the value of attribute jrepo.
268 269 270 |
# File 'lib/rjgit.rb', line 268 def jrepo @jrepo end |
#treemap ⇒ Object
Returns the value of attribute treemap.
267 268 269 |
# File 'lib/rjgit.rb', line 267 def treemap @treemap end |
Class Method Details
.successful?(result) ⇒ Boolean
353 354 355 |
# File 'lib/rjgit.rb', line 353 def self.successful?(result) ["NEW", "FAST_FORWARD", "FORCED"].include?(result) end |
Instance Method Details
#add(path, data) ⇒ Object
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/rjgit.rb', line 276 def add(path, data) path = path[1..-1] if path[0] == '/' path = path.split('/') filename = path.pop current = self.treemap path.each do |dir| current[dir] ||= {} node = current[dir] current = node end current[filename] = data @treemap end |
#commit(message, author, parents = nil, ref = nil, force = false) ⇒ Object
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/rjgit.rb', line 327 def commit(, , parents = nil, ref = nil, force = false) ref = ref ? ref : "refs/heads/#{Constants::MASTER}" @current_tree = @current_tree ? RJGit.tree_type(@current_tree) : @jrepo.resolve("refs/heads/#{Constants::MASTER}^{tree}") @treebuilder.treemap = @treemap new_tree = @treebuilder.build_tree(@current_tree) return false if @current_tree && new_tree.name == @current_tree.name parents = parents ? parents : @jrepo.resolve(ref+"^{commit}") new_head = do_commit(, , parents, new_tree) # Point ref to the newest commit ru = @jrepo.updateRef(ref) ru.setNewObjectId(new_head) ru.setForceUpdate(force) ru.setRefLogIdent(.person_ident) ru.setRefLogMessage("commit: #{}", false) res = ru.update.to_string # @treebuilder.object_inserter.release @current_tree = new_tree log = @treebuilder.log @treebuilder.init_log sha = ObjectId.to_string(new_head) return res, log, sha end |
#delete(path) ⇒ Object
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/rjgit.rb', line 293 def delete(path) path = path[1..-1] if path[0] == '/' path = path.split('/') last = path.pop current = self.treemap path.each do |dir| current[dir] ||= {} node = current[dir] current = node end current[last] = false @treemap end |
#do_commit(message, author, parents, new_tree) ⇒ Object
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/rjgit.rb', line 310 def do_commit(, , parents, new_tree) commit_builder = CommitBuilder.new person = .person_ident commit_builder.setCommitter(person) commit_builder.setAuthor(person) commit_builder.setMessage() commit_builder.setTreeId(RJGit.tree_type(new_tree)) if parents.is_a?(Array) parents.each {|parent| commit_builder.addParentId(RJGit.commit_type(parent)) } elsif parents commit_builder.addParentId(RJGit.commit_type(parents)) end result = @treebuilder.object_inserter.insert(commit_builder) @treebuilder.object_inserter.flush result end |