Class: Git::Log
Overview
Builds and executes a git log query
This class provides a fluent interface for building complex git log queries.
Queries default to returning 30 commits; call #max_count with :all to
return every matching commit. Calling #all adds the --all flag to include
all refs in the search but does not change the number of commits returned.
The query is lazily executed when results are requested either via the modern
#execute method or the deprecated Enumerable methods.
Defined Under Namespace
Classes: Result
Deprecated Enumerable Interface collapse
-
#[](index)
deprecated
Deprecated.
Use #execute and call the method on the result.
-
#each
deprecated
Deprecated.
Use #execute and call
eachon the result. -
#first
deprecated
Deprecated.
Use #execute and call the method on the result.
-
#last
deprecated
Deprecated.
Use #execute and call the method on the result.
-
#size
deprecated
Deprecated.
Use #execute and call
sizeon the result. -
#to_s
deprecated
Deprecated.
Use #execute and call
to_son the result.
Instance Method Summary collapse
- #all
- #author(regex)
- #between(val1, val2 = nil)
- #cherry
-
#execute ⇒ Git::Log::Result
Executes the git log command and returns an immutable result object.
- #grep(regex)
-
#initialize(base, max_count = 30) ⇒ Log
constructor
Create a new Git::Log object.
-
#max_count(num)
Set query options using a fluent interface.
- #merges
- #object(objectish)
- #path(path)
- #since(date)
- #skip(num)
- #until(date)
Constructor Details
#initialize(base, max_count = 30) ⇒ Log
Create a new Git::Log object
53 54 55 56 57 58 |
# File 'lib/git/log.rb', line 53 def initialize(base, max_count = 30) @base = base @options = {} @dirty = true self.max_count(max_count) end |
Instance Method Details
#[](index)
Use #execute and call the method on the result.
144 145 146 147 148 149 150 |
# File 'lib/git/log.rb', line 144 def [](index) Git::Deprecation.warn( 'Calling Git::Log#[] is deprecated. Call #execute and then #[] on the result object.' ) run_log_if_dirty @commits&.[](index) end |
#all
64 |
# File 'lib/git/log.rb', line 64 def all = set_option(:all, true) |
#author(regex)
66 |
# File 'lib/git/log.rb', line 66 def (regex) = set_option(:author, regex) |
#between(val1, val2 = nil)
72 |
# File 'lib/git/log.rb', line 72 def between(val1, val2 = nil) = set_option(:between, [val1, val2]) |
#cherry
73 |
# File 'lib/git/log.rb', line 73 def cherry = set_option(:cherry, true) |
#each
Use #execute and call each on the result.
99 100 101 102 103 104 105 |
# File 'lib/git/log.rb', line 99 def each(&) Git::Deprecation.warn( 'Calling Git::Log#each is deprecated. Call #execute and then #each on the result object.' ) run_log_if_dirty @commits.each(&) end |
#execute ⇒ Git::Log::Result
Executes the git log command and returns an immutable result object
This is the preferred way to get log data. It separates the query building from the execution, making the API more predictable.
91 92 93 94 |
# File 'lib/git/log.rb', line 91 def execute run_log_if_dirty Result.new(@commits) end |
#first
Use #execute and call the method on the result.
126 127 128 129 130 131 132 |
# File 'lib/git/log.rb', line 126 def first Git::Deprecation.warn( 'Calling Git::Log#first is deprecated. Call #execute and then #first on the result object.' ) run_log_if_dirty @commits&.first end |
#grep(regex)
67 |
# File 'lib/git/log.rb', line 67 def grep(regex) = set_option(:grep, regex) |
#last
Use #execute and call the method on the result.
135 136 137 138 139 140 141 |
# File 'lib/git/log.rb', line 135 def last Git::Deprecation.warn( 'Calling Git::Log#last is deprecated. Call #execute and then #last on the result object.' ) run_log_if_dirty @commits&.last end |
#max_count(num)
Set query options using a fluent interface.
Each method returns self to allow for chaining.
63 |
# File 'lib/git/log.rb', line 63 def max_count(num) = set_option(:count, num == :all ? nil : num) |
#merges
74 |
# File 'lib/git/log.rb', line 74 def merges = set_option(:merges, true) |
#object(objectish)
65 |
# File 'lib/git/log.rb', line 65 def object(objectish) = set_option(:object, objectish) |
#path(path)
68 |
# File 'lib/git/log.rb', line 68 def path(path) = set_option(:path_limiter, path) |
#since(date)
70 |
# File 'lib/git/log.rb', line 70 def since(date) = set_option(:since, date) |
#size
Use #execute and call size on the result.
108 109 110 111 112 113 114 |
# File 'lib/git/log.rb', line 108 def size Git::Deprecation.warn( 'Calling Git::Log#size is deprecated. Call #execute and then #size on the result object.' ) run_log_if_dirty @commits&.size end |
#skip(num)
69 |
# File 'lib/git/log.rb', line 69 def skip(num) = set_option(:skip, num) |
#to_s
Use #execute and call to_s on the result.
117 118 119 120 121 122 123 |
# File 'lib/git/log.rb', line 117 def to_s Git::Deprecation.warn( 'Calling Git::Log#to_s is deprecated. Call #execute and then #to_s on the result object.' ) run_log_if_dirty @commits&.join("\n") end |
#until(date)
71 |
# File 'lib/git/log.rb', line 71 def until(date) = set_option(:until, date) |