class Mercurial::Commit
The class represents Mercurial
changeset. Obtained by running an +hg log+ command. Contains a lot of information, including commit's ID, author name, email, list of changed files, etc.
The class represents Commit
object itself, {Mercurial::CommitFactory CommitFactory} is responsible for assembling instances of Commit
. For the list of all possible commit-related operations check {Mercurial::CommitFactory CommitFactory}.
For general information on Mercurial
commits:
Attributes
Name of a branch associated with the commit.
Array of {Mercurial::ChangedFile ChangedFile} objects.
Exact date and time of the commit. Contains Ruby Time object.
Mercurial
changeset ID. 40-chars long SHA1 hash.
Mercurial
changeset ID. 40-chars long SHA1 hash.
Full commit message, with line breaks and other stuff.
Array of commit's parents.
Instance of {Mercurial::Repository Repository}.
Public Instance Methods
# File lib/mercurial-ruby/commit.rb, line 83 def ancestors repository.commits.ancestors_of(hash_id) end
# File lib/mercurial-ruby/commit.rb, line 67 def blank? hash_id == '0'*40 end
# File lib/mercurial-ruby/commit.rb, line 71 def diffs(cmd_options={}) repository.diffs.for_commit(self, cmd_options) end
# File lib/mercurial-ruby/commit.rb, line 91 def exist_in_branches repository.branches.for_commit(hash_id) end
# File lib/mercurial-ruby/commit.rb, line 63 def merge? parents.size > 1 end
# File lib/mercurial-ruby/commit.rb, line 87 def parent_id parents_ids.first end
# File lib/mercurial-ruby/commit.rb, line 75 def parents repository.commits.by_hash_ids(parents_ids) end
# File lib/mercurial-ruby/commit.rb, line 95 def short_hash_id hash_id.to_s[0,12] end
Returns a Hash of diffstat-style summary of changes for the commit.
# File lib/mercurial-ruby/commit.rb, line 102 def stats(cmd_options={}) raw = hg(["log -r ? --stat --template '{node}\n'", hash_id], cmd_options) result = raw.scan(/(\d+) files changed, (\d+) insertions\(\+\), (\d+) deletions\(\-\)$/).flatten.map{|r| r.to_i} return {} if result.empty? # that commit has no stats { 'files' => result[0], 'additions' => result[1], 'deletions' => result[2], 'total' => result[1] + result[2] } end
# File lib/mercurial-ruby/commit.rb, line 114 def to_hash { 'id' => hash_id, 'parents' => parents_ids, 'branch' => branch_name, 'tags' => tags_names, 'message' => message, 'date' => date, 'author' => { 'name' => author, 'email' => author_email } } end
# File lib/mercurial-ruby/commit.rb, line 79 def trivial_parents_ids hg(["parents -r ? --template '{node}\n'", hash_id]).split("\n") end
Protected Instance Methods
# File lib/mercurial-ruby/commit.rb, line 131 def files_to_array(array) [].tap do |returning| array.each do |files| if files files.split(';').map do |file_with_mode| returning << Mercurial::ChangedFileFactory.new_from_hg(file_with_mode) end end end remove_files_duplicates(returning) end end
# File lib/mercurial-ruby/commit.rb, line 173 def hg_hash_to_hash_id(hg_hash) hg_hash.split(':').last end
# File lib/mercurial-ruby/commit.rb, line 155 def parents_to_array(string) string_to_array(string) do |returning| string.split(' ').map do |hg_hash| returning << hg_hash_to_hash_id(hg_hash) end end end
# File lib/mercurial-ruby/commit.rb, line 145 def remove_files_duplicates(files) Mercurial::ChangedFileFactory.delete_hg_artefacts(files) end
# File lib/mercurial-ruby/commit.rb, line 163 def string_to_array(string, &block) if string && !string.empty? [].tap do |returning| block.call(returning) end else [] end end