Class: Mercurial::CommitFactory
- Inherits:
-
Object
- Object
- Mercurial::CommitFactory
- Includes:
- Helper
- Defined in:
- lib/mercurial-ruby/factories/commit_factory.rb
Overview
This class represents a factory for Commit instances.
Instance Attribute Summary collapse
-
#repository ⇒ Object
readonly
Instance of Repository.
Instance Method Summary collapse
-
#after(hash_id, options = {}, cmd_options = {}) ⇒ Object
Return an array of Commit instances that appear in hg log after the specified revision id.
-
#all(options = {}, cmd_options = {}) ⇒ Object
Return an array of Commit instances for all changesets in the repository.
-
#ancestors_of(hash_id, options = {}, cmd_options = {}) ⇒ Object
Return an array of Commit instances that appear in hg log as ancestors of the specified commit ID.
-
#before(hash_id, options = {}, cmd_options = {}) ⇒ Object
Return an array of Commit instances that appear in hg log before the specified revision id.
-
#by_branch(branch, cmd_options = {}) ⇒ Object
Return an array of Commit instances for changesets in a specific branch.
-
#by_hash_id(hash, cmd_options = {}) ⇒ Object
Return an instance of Commit for a changeset with a specified id.
-
#by_hash_ids(*args) ⇒ Object
Return an array of Commit instances for changesets with specified ids.
-
#count(cmd_options = {}) ⇒ Object
Count all changesets in the repository.
-
#count_range(hash_a, hash_b, cmd_options = {}) ⇒ Object
Count changesets in the range from hash_a to hash_b in the repository.
-
#each(cmd_options = {}, &block) ⇒ Object
Run a block for every Commit instance of all changesets in the repository.
-
#for_range(hash_a, hash_b, options = {}, cmd_options = {}) ⇒ Object
Return an array of Commit instances for a specified range of changeset ids.
-
#initialize(repository) ⇒ CommitFactory
constructor
:nodoc:.
-
#parent(cmd_options = {}) ⇒ Object
Return a parent commit for this working copy.
-
#tip(cmd_options = {}) ⇒ Object
(also: #latest)
Return an instance of Commit for a repository’s tip changeset (latest).
Methods included from Helper
Constructor Details
#initialize(repository) ⇒ CommitFactory
:nodoc:
12 13 14 |
# File 'lib/mercurial-ruby/factories/commit_factory.rb', line 12 def initialize(repository) #:nodoc: @repository = repository end |
Instance Attribute Details
#repository ⇒ Object (readonly)
Instance of Repository.
10 11 12 |
# File 'lib/mercurial-ruby/factories/commit_factory.rb', line 10 def repository @repository end |
Instance Method Details
#after(hash_id, options = {}, cmd_options = {}) ⇒ Object
Return an array of Commit instances that appear in hg log after the specified revision id.
Example:
repository.commits.after('bf6386c0a0cc')
144 145 146 |
# File 'lib/mercurial-ruby/factories/commit_factory.rb', line 144 def after(hash_id, ={}, ={}) in_direction(:after, hash_id, , ) end |
#all(options = {}, cmd_options = {}) ⇒ Object
Return an array of Commit instances for all changesets in the repository. Accept a :limit setting.
Example:
repository.commits.all
repository.commits.all(:limit => 15)
34 35 36 37 38 39 40 |
# File 'lib/mercurial-ruby/factories/commit_factory.rb', line 34 def all(={}, ={}) cmd = command_with_limit(["log --style ?", style], [:limit]) hg_to_array(cmd, {:separator => changeset_separator}, ) do |line| build(line) end end |
#ancestors_of(hash_id, options = {}, cmd_options = {}) ⇒ Object
Return an array of Commit instances that appear in hg log as ancestors of the specified commit ID.
Example:
repository.commits.ancestors_of('bf6386c0a0cc')
165 166 167 168 169 170 |
# File 'lib/mercurial-ruby/factories/commit_factory.rb', line 165 def ancestors_of(hash_id, ={}, ={}) cmd = command_with_limit(["log -r \"ancestors(?)\" --style ?", hash_id, style], [:limit]) hg_to_array(cmd, {:separator => changeset_separator}, ) do |line| build(line) end end |
#before(hash_id, options = {}, cmd_options = {}) ⇒ Object
Return an array of Commit instances that appear in hg log before the specified revision id.
Example:
repository.commits.before('bf6386c0a0cc')
135 136 137 |
# File 'lib/mercurial-ruby/factories/commit_factory.rb', line 135 def before(hash_id, ={}, ={}) in_direction(:before, hash_id, , ) end |
#by_branch(branch, cmd_options = {}) ⇒ Object
Return an array of Commit instances for changesets in a specific branch.
Example:
repository.commits.by_branch('brancname')
80 81 82 83 84 |
# File 'lib/mercurial-ruby/factories/commit_factory.rb', line 80 def by_branch(branch, ={}) hg_to_array(["log -b ? --style ?", branch, style], {:separator => changeset_separator}, ) do |line| build(line) end end |
#by_hash_id(hash, cmd_options = {}) ⇒ Object
Return an instance of Commit for a changeset with a specified id.
Example:
repository.commits.by_hash_id('291a498f04e9')
91 92 93 94 95 |
# File 'lib/mercurial-ruby/factories/commit_factory.rb', line 91 def by_hash_id(hash, ={}) build do hg(["log -r ? --style ?", hash, style], ) end end |
#by_hash_ids(*args) ⇒ Object
Return an array of Commit instances for changesets with specified ids.
Example:
repository.commits.by_hash_ids('291a498f04e9', '63f70b2314ed')
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/mercurial-ruby/factories/commit_factory.rb', line 102 def by_hash_ids(*args) = args.last.kind_of?(Hash) ? args.last : {} if args.size == 1 && args.first.kind_of?(Array) array = args.first else array = args end return [] if array.empty? args = array.map{|hash| " -r#{ hash }"} hg_to_array ["log#{ args.join('') } --style ?", style], {:separator => changeset_separator}, do |line| build(line) end end |
#count(cmd_options = {}) ⇒ Object
Count all changesets in the repository.
Example:
repository.commits.count
58 59 60 61 62 |
# File 'lib/mercurial-ruby/factories/commit_factory.rb', line 58 def count(={}) hg_to_array(%Q[log --template "{node}\n"], {}, ) do |line| line end.size end |
#count_range(hash_a, hash_b, cmd_options = {}) ⇒ Object
Count changesets in the range from hash_a to hash_b in the repository.
Example:
repository.commits.count_range(hash_a, hash_b)
69 70 71 72 73 |
# File 'lib/mercurial-ruby/factories/commit_factory.rb', line 69 def count_range(hash_a, hash_b, ={}) hg_to_array([%Q[log -r ?:? --template "{node}\n"], hash_a, hash_b], {}, ) do |line| line end.size end |
#each(cmd_options = {}, &block) ⇒ Object
Run a block for every Commit instance of all changesets in the repository.
Example:
repository.commits.each {|commit| ... }
47 48 49 50 51 |
# File 'lib/mercurial-ruby/factories/commit_factory.rb', line 47 def each(={}, &block) all().each do |commit| block.call(commit) end end |
#for_range(hash_a, hash_b, options = {}, cmd_options = {}) ⇒ Object
Return an array of Commit instances for a specified range of changeset ids.
Example:
repository.commits.for_range('bf6386c0a0cc', '63f70b2314ed')
123 124 125 126 127 128 |
# File 'lib/mercurial-ruby/factories/commit_factory.rb', line 123 def for_range(hash_a, hash_b, ={}, ={}) cmd = command_with_limit(["log -r ?:? --style ?", hash_a, hash_b, style], [:limit]) hg_to_array(cmd, {:separator => changeset_separator}, ) do |line| build(line) end end |
#parent(cmd_options = {}) ⇒ Object
Return a parent commit for this working copy.
Example:
repository.commits.parent
21 22 23 24 25 |
# File 'lib/mercurial-ruby/factories/commit_factory.rb', line 21 def parent(={}) build do hg(["parent --style ?", style], ) end end |
#tip(cmd_options = {}) ⇒ Object Also known as: latest
Return an instance of Commit for a repository’s tip changeset (latest).
Example:
repository.commits.tip
153 154 155 156 157 |
# File 'lib/mercurial-ruby/factories/commit_factory.rb', line 153 def tip(={}) build do hg(["tip --style ?", style], ) end end |