1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 require 'redmine/scm/adapters/darcs_adapter'
20 class Repository::Darcs < Repository
21 validates_presence_of :url
24 Redmine::Scm::Adapters::DarcsAdapter
31 def entry(path=nil, identifier=nil)
32 patch = identifier.nil? ? nil : changesets.find_by_revision(identifier)
33 scm.entry(path, patch.nil? ? nil : patch.scmid)
36 def entries(path=nil, identifier=nil)
37 patch = identifier.nil? ? nil : changesets.find_by_revision(identifier)
38 entries = scm.entries(path, patch.nil? ? nil : patch.scmid)
40 entries.each do |entry|
41 # Search the DB for the entry's last change
42 changeset = changesets.find_by_scmid(entry.lastrev.scmid) if entry.lastrev && !entry.lastrev.scmid.blank?
44 entry.lastrev.identifier = changeset.revision
45 entry.lastrev.name = changeset.revision
46 entry.lastrev.time = changeset.committed_on
47 entry.lastrev.author = changeset.committer
54 def cat(path, identifier=nil)
55 patch = identifier.nil? ? nil : changesets.find_by_revision(identifier.to_s)
56 scm.cat(path, patch.nil? ? nil : patch.scmid)
59 def diff(path, rev, rev_to)
60 patch_from = changesets.find_by_revision(rev)
61 return nil if patch_from.nil?
62 patch_to = changesets.find_by_revision(rev_to) if rev_to
64 path = patch_from.changes.collect{|change| change.path}.join(' ')
66 patch_from ? scm.diff(path, patch_from.scmid, patch_to ? patch_to.scmid : nil) : nil
72 db_last_id = latest_changeset ? latest_changeset.scmid : nil
73 next_rev = latest_changeset ? latest_changeset.revision.to_i + 1 : 1
74 # latest revision in the repository
75 scm_revision = scm_info.lastrev.scmid
76 unless changesets.find_by_scmid(scm_revision)
77 revisions = scm.revisions('', db_last_id, nil, :with_path => true)
79 revisions.reverse_each do |revision|
80 changeset = Changeset.create(:repository => self,
81 :revision => next_rev,
82 :scmid => revision.scmid,
83 :committer => revision.author,
84 :committed_on => revision.time,
85 :comments => revision.message)
87 revision.paths.each do |change|
88 Change.create(:changeset => changeset,
89 :action => change[:action],
90 :path => change[:path],
91 :from_path => change[:from_path],
92 :from_revision => change[:from_revision])