Class: Mercurial::Commit
- Inherits:
-
Object
- Object
- Mercurial::Commit
- Includes:
- Helper
- Defined in:
- lib/mercurial-ruby/commit.rb
Overview
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, CommitFactory is responsible for assembling instances of Commit. For the list of all possible commit-related operations check CommitFactory.
For general information on Mercurial commits:
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Name of the user committed the change.
-
#author_email ⇒ Object
readonly
Email of the user committed the change.
-
#branch_name ⇒ Object
readonly
Name of a branch associated with the commit.
-
#changed_files ⇒ Object
readonly
Array of ChangedFile objects.
-
#date ⇒ Object
readonly
Exact date and time of the commit.
-
#hash_id ⇒ Object
(also: #id)
readonly
Mercurial changeset ID.
-
#message ⇒ Object
readonly
Full commit message, with line breaks and other stuff.
-
#parents_ids ⇒ Object
readonly
Array of commit’s parents.
-
#repository ⇒ Object
readonly
Instance of Repository.
-
#tags_names ⇒ Object
readonly
Array of commit’s tags.
Instance Method Summary collapse
- #ancestors ⇒ Object
- #blank? ⇒ Boolean
- #diffs(cmd_options = {}) ⇒ Object
- #exist_in_branches ⇒ Object
-
#initialize(repository, opts = {}) ⇒ Commit
constructor
:nodoc:.
- #merge? ⇒ Boolean
- #parent_id ⇒ Object
- #parents ⇒ Object
- #short_hash_id ⇒ Object
-
#stats(cmd_options = {}) ⇒ Object
Returns a Hash of diffstat-style summary of changes for the commit.
- #to_hash ⇒ Object
- #trivial_parents_ids ⇒ Object
Methods included from Helper
Constructor Details
#initialize(repository, opts = {}) ⇒ Commit
:nodoc:
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/mercurial-ruby/commit.rb', line 50 def initialize(repository, opts={}) #:nodoc: @repository = repository @hash_id = opts[:hash_id] @author = opts[:author] @author_email = opts[:author_email] @date = Time.iso8601(opts[:date]) @message = opts[:message] @changed_files = files_to_array(opts[:changed_files]) @branch_name = opts[:branch_name] @tags_names = (opts[:tags_names]) @parents_ids = parents_to_array(opts[:parents]) end |
Instance Attribute Details
#author ⇒ Object (readonly)
Name of the user committed the change.
25 26 27 |
# File 'lib/mercurial-ruby/commit.rb', line 25 def @author end |
#author_email ⇒ Object (readonly)
Email of the user committed the change.
28 29 30 |
# File 'lib/mercurial-ruby/commit.rb', line 28 def @author_email end |
#branch_name ⇒ Object (readonly)
Name of a branch associated with the commit.
40 41 42 |
# File 'lib/mercurial-ruby/commit.rb', line 40 def branch_name @branch_name end |
#changed_files ⇒ Object (readonly)
Array of ChangedFile objects.
37 38 39 |
# File 'lib/mercurial-ruby/commit.rb', line 37 def changed_files @changed_files end |
#date ⇒ Object (readonly)
Exact date and time of the commit. Contains Ruby Time object.
31 32 33 |
# File 'lib/mercurial-ruby/commit.rb', line 31 def date @date end |
#hash_id ⇒ Object (readonly) Also known as: id
Mercurial changeset ID. 40-chars long SHA1 hash.
22 23 24 |
# File 'lib/mercurial-ruby/commit.rb', line 22 def hash_id @hash_id end |
#message ⇒ Object (readonly)
Full commit message, with line breaks and other stuff.
34 35 36 |
# File 'lib/mercurial-ruby/commit.rb', line 34 def @message end |
#parents_ids ⇒ Object (readonly)
Array of commit’s parents.
46 47 48 |
# File 'lib/mercurial-ruby/commit.rb', line 46 def parents_ids @parents_ids end |
#repository ⇒ Object (readonly)
Instance of Repository.
19 20 21 |
# File 'lib/mercurial-ruby/commit.rb', line 19 def repository @repository end |
#tags_names ⇒ Object (readonly)
Array of commit’s tags.
43 44 45 |
# File 'lib/mercurial-ruby/commit.rb', line 43 def @tags_names end |
Instance Method Details
#ancestors ⇒ Object
83 84 85 |
# File 'lib/mercurial-ruby/commit.rb', line 83 def ancestors repository.commits.ancestors_of(hash_id) end |
#blank? ⇒ Boolean
67 68 69 |
# File 'lib/mercurial-ruby/commit.rb', line 67 def blank? hash_id == '0'*40 end |
#diffs(cmd_options = {}) ⇒ Object
71 72 73 |
# File 'lib/mercurial-ruby/commit.rb', line 71 def diffs(={}) repository.diffs.for_commit(self, ) end |
#exist_in_branches ⇒ Object
91 92 93 |
# File 'lib/mercurial-ruby/commit.rb', line 91 def exist_in_branches repository.branches.for_commit(hash_id) end |
#merge? ⇒ Boolean
63 64 65 |
# File 'lib/mercurial-ruby/commit.rb', line 63 def merge? parents.size > 1 end |
#parent_id ⇒ Object
87 88 89 |
# File 'lib/mercurial-ruby/commit.rb', line 87 def parent_id parents_ids.first end |
#parents ⇒ Object
75 76 77 |
# File 'lib/mercurial-ruby/commit.rb', line 75 def parents repository.commits.by_hash_ids(parents_ids) end |
#short_hash_id ⇒ Object
95 96 97 |
# File 'lib/mercurial-ruby/commit.rb', line 95 def short_hash_id hash_id.to_s[0,12] end |
#stats(cmd_options = {}) ⇒ Object
Returns a Hash of diffstat-style summary of changes for the commit.
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/mercurial-ruby/commit.rb', line 102 def stats(={}) raw = hg(["log -r ? --stat --template '{node}\n'", hash_id], ) 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 |
#to_hash ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/mercurial-ruby/commit.rb', line 114 def to_hash { 'id' => hash_id, 'parents' => parents_ids, 'branch' => branch_name, 'tags' => , 'message' => , 'date' => date, 'author' => { 'name' => , 'email' => } } end |
#trivial_parents_ids ⇒ Object
79 80 81 |
# File 'lib/mercurial-ruby/commit.rb', line 79 def trivial_parents_ids hg(["parents -r ? --template '{node}\n'", hash_id]).split("\n") end |