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) ⇒ Git::Object::Commit, ...
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 ⇒ Git::Log
Includes commits reachable from all refs.
-
#author(regex) ⇒ Git::Log
Filters commits by author pattern.
-
#between(val1, val2 = nil) ⇒ Git::Log
Limits commits to the given revision range.
-
#cherry ⇒ Git::Log
Omits commits equivalent to cherry-picked commits.
-
#execute ⇒ Git::Log::Result
Executes the git log command and returns an immutable result object.
-
#grep(regex) ⇒ Git::Log
Filters commits by commit message pattern.
-
#initialize(base, max_count = 30) ⇒ Log
constructor
Create a new Git::Log object.
-
#max_count(num) ⇒ Git::Log
Set query options using a fluent interface.
-
#merges ⇒ Git::Log
Includes only merge commits.
-
#object(objectish) ⇒ Git::Log
Sets the revision range expression for the log query.
-
#path(path) ⇒ Git::Log
Limits commits to those that touch the given path or paths.
- #perl_regexp ⇒ Git::Log
-
#since(date) ⇒ Git::Log
Includes only commits newer than the given date expression.
-
#skip(num) ⇒ Git::Log
Skips a number of commits before returning results.
-
#until(date) ⇒ Git::Log
Includes only commits older than the given date expression.
Constructor Details
#initialize(base, max_count = 30) ⇒ Log
Create a new Git::Log object
96 97 98 99 100 101 |
# File 'lib/git/log.rb', line 96 def initialize(base, max_count = 30) @base = base @options = {} @dirty = true self.max_count(max_count) end |
Instance Method Details
#[](index) ⇒ Git::Object::Commit, ...
Use #execute and call the method on the result.
Returns the selected commit or commits.
298 299 300 301 302 303 304 305 |
# File 'lib/git/log.rb', line 298 def [](index) Git::Deprecation.warn( 'Calling Git::Log#[] is deprecated and will be removed in v6.0.0. ' \ 'Call #execute and then #[] on the result object.' ) run_log_if_dirty @commits[index] end |
#all ⇒ Git::Log
Includes commits reachable from all refs
119 |
# File 'lib/git/log.rb', line 119 def all = set_option(:all, true) |
#author(regex) ⇒ Git::Log
Filters commits by author pattern
135 |
# File 'lib/git/log.rb', line 135 def (regex) = set_option(:author, regex) |
#between(val1, val2 = nil) ⇒ Git::Log
Limits commits to the given revision range
205 |
# File 'lib/git/log.rb', line 205 def between(val1, val2 = nil) = set_option(:between, [val1, val2]) |
#cherry ⇒ Git::Log
Omits commits equivalent to cherry-picked commits
211 |
# File 'lib/git/log.rb', line 211 def cherry = set_option(:cherry, true) |
#each
Use #execute and call each on the result.
242 243 244 245 246 247 248 249 |
# File 'lib/git/log.rb', line 242 def each(&) Git::Deprecation.warn( 'Calling Git::Log#each is deprecated and will be removed in v6.0.0. ' \ '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.
234 235 236 237 |
# File 'lib/git/log.rb', line 234 def execute run_log_if_dirty Result.new(@commits) end |
#first
Use #execute and call the method on the result.
272 273 274 275 276 277 278 279 |
# File 'lib/git/log.rb', line 272 def first Git::Deprecation.warn( 'Calling Git::Log#first is deprecated and will be removed in v6.0.0. ' \ 'Call #execute and then #first on the result object.' ) run_log_if_dirty @commits.first end |
#grep(regex) ⇒ Git::Log
Filters commits by commit message pattern
143 |
# File 'lib/git/log.rb', line 143 def grep(regex) = set_option(:grep, regex) |
#last
Use #execute and call the method on the result.
282 283 284 285 286 287 288 289 |
# File 'lib/git/log.rb', line 282 def last Git::Deprecation.warn( 'Calling Git::Log#last is deprecated and will be removed in v6.0.0. ' \ 'Call #execute and then #last on the result object.' ) run_log_if_dirty @commits.last end |
#max_count(num) ⇒ Git::Log
Set query options using a fluent interface.
Each method returns self to allow for chaining.
Sets the maximum number of commits to return
113 |
# File 'lib/git/log.rb', line 113 def max_count(num) = set_option(:count, num == :all ? nil : num) |
#merges ⇒ Git::Log
Includes only merge commits
217 |
# File 'lib/git/log.rb', line 217 def merges = set_option(:merges, true) |
#object(objectish) ⇒ Git::Log
Sets the revision range expression for the log query
127 |
# File 'lib/git/log.rb', line 127 def object(objectish) = set_option(:object, objectish) |
#path(path) ⇒ Git::Log
Limits commits to those that touch the given path or paths
170 |
# File 'lib/git/log.rb', line 170 def path(path) = set_option(:path_limiter, path) |
#perl_regexp ⇒ Git::Log
On Git for Windows, git's default regex engine matches bytes rather
than characters, so a metacharacter such as . or a POSIX class such as
[[:alpha:]] never matches a whole multi-byte character. The match fails
silently: git exits zero and the result is empty. PCRE does match characters
on that platform, but it is a different dialect than git's default, so
selecting it is a deliberate choice by the caller.
Interprets #grep and #author patterns as Perl-compatible regular expressions
Selects PCRE instead of git's default POSIX basic regular expressions for every pattern in the query. Requires a git built with PCRE support.
162 |
# File 'lib/git/log.rb', line 162 def perl_regexp = set_option(:perl_regexp, true) |
#since(date) ⇒ Git::Log
Includes only commits newer than the given date expression
186 |
# File 'lib/git/log.rb', line 186 def since(date) = set_option(:since, date) |
#size
Use #execute and call size on the result.
252 253 254 255 256 257 258 259 |
# File 'lib/git/log.rb', line 252 def size Git::Deprecation.warn( 'Calling Git::Log#size is deprecated and will be removed in v6.0.0. ' \ 'Call #execute and then #size on the result object.' ) run_log_if_dirty @commits.size end |
#skip(num) ⇒ Git::Log
Skips a number of commits before returning results
178 |
# File 'lib/git/log.rb', line 178 def skip(num) = set_option(:skip, num) |
#to_s
Use #execute and call to_s on the result.
262 263 264 265 266 267 268 269 |
# File 'lib/git/log.rb', line 262 def to_s Git::Deprecation.warn( 'Calling Git::Log#to_s is deprecated and will be removed in v6.0.0. ' \ 'Call #execute and then #to_s on the result object.' ) run_log_if_dirty @commits.join("\n") end |
#until(date) ⇒ Git::Log
Includes only commits older than the given date expression
194 |
# File 'lib/git/log.rb', line 194 def until(date) = set_option(:until, date) |