Class: SimpleGit::Revwalk

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/simple_git/revwalk.rb

Defined Under Namespace

Classes: RevwalkWrapper

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo) ⇒ Revwalk

Returns a new instance of Revwalk.



7
8
9
10
11
12
13
14
15
# File 'lib/simple_git/revwalk.rb', line 7

def initialize(repo)
  wrapper = RevwalkWrapper.new
  Git2.git_revwalk_new(wrapper, repo.ptr)

  @repo = repo
  @ptr = wrapper[:revwalk]

  ObjectSpace.define_finalizer(self, self.class.finalize(@ptr))
end

Instance Attribute Details

#ptrObject

Returns the value of attribute ptr.



5
6
7
# File 'lib/simple_git/revwalk.rb', line 5

def ptr
  @ptr
end

Class Method Details

.finalize(ptr) ⇒ Object



35
36
37
# File 'lib/simple_git/revwalk.rb', line 35

def self.finalize(ptr)
  proc { Git2.git_revwalk_free(ptr) }
end

Instance Method Details

#eachObject



25
26
27
28
29
30
31
# File 'lib/simple_git/revwalk.rb', line 25

def each
  oid = Oid.new

  while Git2.git_revwalk_next(oid.ptr, @ptr) == 0
    yield Commit.new(@repo, oid)
  end
end

#push_headObject



21
22
23
# File 'lib/simple_git/revwalk.rb', line 21

def push_head
  Git2.git_revwalk_push_head(@ptr)
end

#sort(sort_type) ⇒ Object



17
18
19
# File 'lib/simple_git/revwalk.rb', line 17

def sort(sort_type)
  Git2.git_revwalk_sorting(@ptr, sort_type)
end