Module: Amp::Core::Repositories::CommonChangesetMethods
- Included in:
- AbstractChangeset
- Defined in:
- lib/amp-core/repository/abstract/common_methods/changeset.rb
Overview
CommonVersionedFileMethods
These methods are common to all repositories, and this module is mixed into the AbstractLocalRepository class. This guarantees that all repositories will have these methods.
No methods should be placed into this module unless it relies on methods in the general API for repositories.
Instance Method Summary collapse
-
#changed_files ⇒ Hash{String => String}
A hash of the files that have been changed and their most recent diffs.
-
#changed_lines_statistics ⇒ Hash{Symbol => Integer}
Gets the number of lines added and removed in this changeset.
-
#include?(file) ⇒ Boolean
Is
file
being tracked at this point in time?. -
#template_for_options(opts = {}) ⇒ Template
Returns template to handle templating based on the options provided.
-
#to_templated_s(opts = {}) ⇒ String
Renders the changeset with a given template.
-
#useful_parents ⇒ Array<Changeset>
Gets the list of parents useful for printing in a template - no point in saying that revision 127’s only parent is 126, for example.
-
#walk(match) ⇒ Object
recursively walk.
Instance Method Details
#changed_files ⇒ Hash{String => String}
A hash of the files that have been changed and their most recent diffs. The diffs are lazily made upon access. To just get the files, use #altered_files or #changed_files.keys Checks whether this changeset included a given file or not.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/amp-core/repository/abstract/common_methods/changeset.rb', line 37 def changed_files h = {} class << h def [](*args) super(*args).call # we expect a proc end end altered_files.inject(h) do |s, k| s[k] = proc do other = parents.first[k] other.unified_diff_with self[k] end s end end |
#changed_lines_statistics ⇒ Hash{Symbol => Integer}
Gets the number of lines added and removed in this changeset.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/amp-core/repository/abstract/common_methods/changeset.rb', line 59 def changed_lines_statistics result = {:added => 0, :removed => 0} changed_files.each do |_, diffproc| diff = diffproc.call diff.split("\n").each do |line| if line.start_with?("+") && !line.start_with?("+++") result[:added] += 1 elsif line.start_with?("-") && !line.start_with?("---") result[:removed] += 1 end end end result end |
#include?(file) ⇒ Boolean
Is file
being tracked at this point in time?
79 80 81 |
# File 'lib/amp-core/repository/abstract/common_methods/changeset.rb', line 79 def include?(file) all_files.include? file end |
#template_for_options(opts = {}) ⇒ Template
Returns template to handle templating based on the options provided.
143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/amp-core/repository/abstract/common_methods/changeset.rb', line 143 def (opts = {}) type = opts[:template_type] || 'log' if opts[:"template-raw"] Support::RawERbTemplate.new(opts[:"template-raw"]) elsif opts[:template].is_a?(Support::Template) opts[:template] else template = opts[:template] template = "default-#{type}" if template.nil? || template.to_s == "default" Support::Template['mercurial', template] end end |
#to_templated_s(opts = {}) ⇒ String
Renders the changeset with a given template. Takes a few different options to control output.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/amp-core/repository/abstract/common_methods/changeset.rb', line 114 def to_templated_s(opts={}) locals = {:change_node => node, :revision => self.revision, :username => self.user, :date => self.easy_date, :files => self.altered_files, :description => self.description, :branch => self.branch, :cs_tags => self., :added => opts[:added] || [], :removed => opts[:removed] || [], :updated => opts[:updated] || [], :config => opts, :parents => useful_parents.map {|p| [p.revision, p.node.short_hex] } } return "" if opts[:no_output] (opts).render(locals, binding) end |
#useful_parents ⇒ Array<Changeset>
Gets the list of parents useful for printing in a template - no point in saying that revision 127’s only parent is 126, for example.
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/amp-core/repository/abstract/common_methods/changeset.rb', line 89 def useful_parents ret_parents = self.parents if ret_parents[1].nil? if ret_parents[0].revision >= self.revision - 1 ret_parents = [] else ret_parents = [ret_parents[0]] end end ret_parents end |
#walk(match) ⇒ Object
recursively walk
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/amp-core/repository/abstract/common_methods/changeset.rb', line 161 def walk(match) # just make it so the keys are there results = [] hash = Hash.with_keys match.files hash.delete '.' each do |file| hash.each {|f, val| (hash.delete file and break) if f == file } results << file if match.call file # yield file if match.call file end hash.keys.sort.each do |file| if match.bad file, "No such file in revision #{revision}" and match[file] results << file # yield file end end results end |