annotate app/models/repository/.svn/text-base/darcs.rb.svn-base @ 245:051f544170fe

* Update to SVN trunk revision 4993
author Chris Cannam
date Thu, 03 Mar 2011 11:42:28 +0000
parents 513646585e45
children cbce1fd3b1b7
rev   line source
Chris@0 1 # redMine - project management software
Chris@0 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@0 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@0 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 require 'redmine/scm/adapters/darcs_adapter'
Chris@0 19
Chris@0 20 class Repository::Darcs < Repository
Chris@245 21 validates_presence_of :url, :log_encoding
Chris@0 22
Chris@245 23 ATTRIBUTE_KEY_NAMES = {
Chris@245 24 "url" => "Root directory",
Chris@245 25 "log_encoding" => "Commit messages encoding",
Chris@245 26 }
Chris@245 27 def self.human_attribute_name(attribute_key_name)
Chris@245 28 ATTRIBUTE_KEY_NAMES[attribute_key_name] || super
Chris@245 29 end
Chris@245 30
Chris@245 31 def self.scm_adapter_class
Chris@0 32 Redmine::Scm::Adapters::DarcsAdapter
Chris@0 33 end
Chris@245 34
Chris@0 35 def self.scm_name
Chris@0 36 'Darcs'
Chris@0 37 end
Chris@245 38
Chris@0 39 def entry(path=nil, identifier=nil)
Chris@0 40 patch = identifier.nil? ? nil : changesets.find_by_revision(identifier)
Chris@0 41 scm.entry(path, patch.nil? ? nil : patch.scmid)
Chris@0 42 end
Chris@0 43
Chris@0 44 def entries(path=nil, identifier=nil)
Chris@0 45 patch = identifier.nil? ? nil : changesets.find_by_revision(identifier)
Chris@0 46 entries = scm.entries(path, patch.nil? ? nil : patch.scmid)
Chris@0 47 if entries
Chris@0 48 entries.each do |entry|
Chris@0 49 # Search the DB for the entry's last change
Chris@0 50 changeset = changesets.find_by_scmid(entry.lastrev.scmid) if entry.lastrev && !entry.lastrev.scmid.blank?
Chris@0 51 if changeset
Chris@0 52 entry.lastrev.identifier = changeset.revision
Chris@0 53 entry.lastrev.name = changeset.revision
Chris@0 54 entry.lastrev.time = changeset.committed_on
Chris@0 55 entry.lastrev.author = changeset.committer
Chris@0 56 end
Chris@0 57 end
Chris@0 58 end
Chris@0 59 entries
Chris@0 60 end
Chris@0 61
Chris@0 62 def cat(path, identifier=nil)
Chris@0 63 patch = identifier.nil? ? nil : changesets.find_by_revision(identifier.to_s)
Chris@0 64 scm.cat(path, patch.nil? ? nil : patch.scmid)
Chris@0 65 end
Chris@0 66
Chris@0 67 def diff(path, rev, rev_to)
Chris@0 68 patch_from = changesets.find_by_revision(rev)
Chris@0 69 return nil if patch_from.nil?
Chris@0 70 patch_to = changesets.find_by_revision(rev_to) if rev_to
Chris@0 71 if path.blank?
Chris@0 72 path = patch_from.changes.collect{|change| change.path}.join(' ')
Chris@0 73 end
Chris@0 74 patch_from ? scm.diff(path, patch_from.scmid, patch_to ? patch_to.scmid : nil) : nil
Chris@0 75 end
Chris@0 76
Chris@0 77 def fetch_changesets
Chris@0 78 scm_info = scm.info
Chris@0 79 if scm_info
Chris@0 80 db_last_id = latest_changeset ? latest_changeset.scmid : nil
Chris@0 81 next_rev = latest_changeset ? latest_changeset.revision.to_i + 1 : 1
Chris@0 82 # latest revision in the repository
Chris@0 83 scm_revision = scm_info.lastrev.scmid
Chris@0 84 unless changesets.find_by_scmid(scm_revision)
Chris@0 85 revisions = scm.revisions('', db_last_id, nil, :with_path => true)
Chris@0 86 transaction do
Chris@0 87 revisions.reverse_each do |revision|
Chris@0 88 changeset = Changeset.create(:repository => self,
Chris@0 89 :revision => next_rev,
Chris@0 90 :scmid => revision.scmid,
Chris@0 91 :committer => revision.author,
Chris@0 92 :committed_on => revision.time,
Chris@0 93 :comments => revision.message)
Chris@0 94
Chris@0 95 revision.paths.each do |change|
Chris@0 96 changeset.create_change(change)
Chris@0 97 end
Chris@0 98 next_rev += 1
Chris@0 99 end if revisions
Chris@0 100 end
Chris@0 101 end
Chris@0 102 end
Chris@0 103 end
Chris@0 104 end