Class: DmSvn::Svn::Changeset
- Inherits:
-
Object
- Object
- DmSvn::Svn::Changeset
- Includes:
- Comparable
- Defined in:
- lib/dm-svn/svn/changeset.rb
Overview
Store information about a particular changeset, and runs the actual updates for that changeset. Aside from handling the list of changes, it can be passed to methods that need the revision, date and author.
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#changes ⇒ Object
readonly
Returns the value of attribute changes.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#repos ⇒ Object
readonly
Returns the value of attribute repos.
-
#revision ⇒ Object
readonly
Returns the value of attribute revision.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Changesets are sorted by revision number, ascending.
-
#fs_path(path) ⇒ Object
Path used to communicate with svn repos.
-
#initialize(changes, revision, author, date, sync) ⇒ Changeset
constructor
A new instance of Changeset.
-
#process ⇒ Object
Process this changeset.
-
#short_path(path) ⇒ Object
Get the relative path from config.uri.
Constructor Details
#initialize(changes, revision, author, date, sync) ⇒ Changeset
Returns a new instance of Changeset.
13 14 15 16 |
# File 'lib/dm-svn/svn/changeset.rb', line 13 def initialize(changes, revision, , date, sync) @changes, @revision, @author, @date = changes, revision, , date @model, @config, @repos, @sync = sync.model, sync.config, sync.repos, sync end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
11 12 13 |
# File 'lib/dm-svn/svn/changeset.rb', line 11 def @author end |
#changes ⇒ Object (readonly)
Returns the value of attribute changes.
11 12 13 |
# File 'lib/dm-svn/svn/changeset.rb', line 11 def changes @changes end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/dm-svn/svn/changeset.rb', line 11 def config @config end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
11 12 13 |
# File 'lib/dm-svn/svn/changeset.rb', line 11 def date @date end |
#repos ⇒ Object (readonly)
Returns the value of attribute repos.
11 12 13 |
# File 'lib/dm-svn/svn/changeset.rb', line 11 def repos @repos end |
#revision ⇒ Object (readonly)
Returns the value of attribute revision.
11 12 13 |
# File 'lib/dm-svn/svn/changeset.rb', line 11 def revision @revision end |
Instance Method Details
#<=>(other) ⇒ Object
Changesets are sorted by revision number, ascending.
19 20 21 |
# File 'lib/dm-svn/svn/changeset.rb', line 19 def <=>(other) self.revision <=> other.revision end |
#fs_path(path) ⇒ Object
Path used to communicate with svn repos.
92 93 94 95 96 |
# File 'lib/dm-svn/svn/changeset.rb', line 92 def fs_path(path) path = path[@config.path_from_root.length..-1].to_s path = path[1..-1] if path[0] == ?/ path end |
#process ⇒ Object
Process this changeset. This doesn’t account for possible move/replace conflicts (A node is moved, then the old node is replaced by a new one). I assume those are rare enough that I won’t code around them, for now.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/dm-svn/svn/changeset.rb', line 27 def process return if changes.nil? modified, deleted, copied = [], [], [] changes.each_pair do |path, change| next if short_path(path).blank? || !path_in_root?(path) case change.action when "M", "A", "R" # Modified, Added or Replaced modified << path when "D" deleted << path end copied << [path, change.copyfrom_path] if change.copyfrom_path end # Perform moves copied.each do |copy| del = deleted.find { |d| d == copy[1] } if del # Change the path. No need to perform other updates, as this is an # "A" or "R" and thus is in the +modified+ Array. record = get(del) record.move_to(short_path(copy[0])) if record end end # Perform deletes deleted.each do |path| record = get(path) record.destroy if record # May have been moved or refer to a directory end # Perform modifies and adds modified.each do |path| node = Node.new(self, path) if @config.extension && node.file? && path !~ /\.#{@config.extension}\Z/ if path =~ /\.yml\Z/ && @model.svn_category_model # Update parent directory, if applicable path = path.split("/")[0..-2].join("/") node = Node.new(self, path) else next end end record = get(path) || new_record(node) # update record record.update_from_svn(node) end end |
#short_path(path) ⇒ Object
Get the relative path from config.uri
85 86 87 88 89 |
# File 'lib/dm-svn/svn/changeset.rb', line 85 def short_path(path) path = fs_path(path) path = path.sub(/\.#{@config.extension}\Z/, '') if @config.extension path end |