2011-05-12 11:41:29 +04:00
|
|
|
# Redmine - project management software
|
|
|
|
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
2007-06-24 23:30:38 +04:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-05-12 11:41:29 +04:00
|
|
|
#
|
2007-06-24 23:30:38 +04:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2011-05-12 11:41:29 +04:00
|
|
|
#
|
2007-06-24 23:30:38 +04:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
require 'redmine/scm/adapters/darcs_adapter'
|
|
|
|
|
|
|
|
class Repository::Darcs < Repository
|
2011-03-01 13:27:30 +03:00
|
|
|
validates_presence_of :url, :log_encoding
|
2007-06-24 23:30:38 +04:00
|
|
|
|
2011-12-18 17:20:19 +04:00
|
|
|
def self.human_attribute_name(attribute_key_name, *args)
|
2012-02-24 18:58:43 +04:00
|
|
|
attr_name = attribute_key_name.to_s
|
2011-04-23 11:37:03 +04:00
|
|
|
if attr_name == "url"
|
|
|
|
attr_name = "path_to_repository"
|
|
|
|
end
|
2011-12-18 17:20:19 +04:00
|
|
|
super(attr_name, *args)
|
2011-03-01 08:14:03 +03:00
|
|
|
end
|
|
|
|
|
2011-02-14 11:45:34 +03:00
|
|
|
def self.scm_adapter_class
|
2007-06-24 23:30:38 +04:00
|
|
|
Redmine::Scm::Adapters::DarcsAdapter
|
|
|
|
end
|
2011-02-14 11:45:34 +03:00
|
|
|
|
2007-06-24 23:30:38 +04:00
|
|
|
def self.scm_name
|
|
|
|
'Darcs'
|
|
|
|
end
|
2011-02-14 11:45:34 +03:00
|
|
|
|
2011-04-17 10:28:16 +04:00
|
|
|
def supports_directory_revisions?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2008-08-25 18:33:30 +04:00
|
|
|
def entry(path=nil, identifier=nil)
|
|
|
|
patch = identifier.nil? ? nil : changesets.find_by_revision(identifier)
|
|
|
|
scm.entry(path, patch.nil? ? nil : patch.scmid)
|
|
|
|
end
|
2011-04-12 09:44:48 +04:00
|
|
|
|
2007-06-24 23:30:38 +04:00
|
|
|
def entries(path=nil, identifier=nil)
|
2011-04-12 09:45:37 +04:00
|
|
|
patch = nil
|
|
|
|
if ! identifier.nil?
|
|
|
|
patch = changesets.find_by_revision(identifier)
|
|
|
|
return nil if patch.nil?
|
|
|
|
end
|
2008-04-06 14:35:55 +04:00
|
|
|
entries = scm.entries(path, patch.nil? ? nil : patch.scmid)
|
2007-06-24 23:30:38 +04:00
|
|
|
if entries
|
|
|
|
entries.each do |entry|
|
|
|
|
# Search the DB for the entry's last change
|
2011-04-12 09:44:48 +04:00
|
|
|
if entry.lastrev && !entry.lastrev.scmid.blank?
|
|
|
|
changeset = changesets.find_by_scmid(entry.lastrev.scmid)
|
|
|
|
end
|
2007-06-24 23:30:38 +04:00
|
|
|
if changeset
|
|
|
|
entry.lastrev.identifier = changeset.revision
|
2011-04-12 09:44:48 +04:00
|
|
|
entry.lastrev.name = changeset.revision
|
|
|
|
entry.lastrev.time = changeset.committed_on
|
|
|
|
entry.lastrev.author = changeset.committer
|
2007-06-24 23:30:38 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
entries
|
|
|
|
end
|
2011-04-12 09:44:48 +04:00
|
|
|
|
2008-08-25 18:33:30 +04:00
|
|
|
def cat(path, identifier=nil)
|
2008-12-06 20:20:37 +03:00
|
|
|
patch = identifier.nil? ? nil : changesets.find_by_revision(identifier.to_s)
|
2008-08-25 18:33:30 +04:00
|
|
|
scm.cat(path, patch.nil? ? nil : patch.scmid)
|
|
|
|
end
|
2011-04-12 09:44:48 +04:00
|
|
|
|
2008-06-08 20:28:42 +04:00
|
|
|
def diff(path, rev, rev_to)
|
2007-06-24 23:30:38 +04:00
|
|
|
patch_from = changesets.find_by_revision(rev)
|
2008-03-12 23:28:49 +03:00
|
|
|
return nil if patch_from.nil?
|
2007-06-24 23:30:38 +04:00
|
|
|
patch_to = changesets.find_by_revision(rev_to) if rev_to
|
|
|
|
if path.blank?
|
|
|
|
path = patch_from.changes.collect{|change| change.path}.join(' ')
|
|
|
|
end
|
2008-06-08 20:28:42 +04:00
|
|
|
patch_from ? scm.diff(path, patch_from.scmid, patch_to ? patch_to.scmid : nil) : nil
|
2007-06-24 23:30:38 +04:00
|
|
|
end
|
2011-04-12 09:44:48 +04:00
|
|
|
|
2007-06-24 23:30:38 +04:00
|
|
|
def fetch_changesets
|
|
|
|
scm_info = scm.info
|
|
|
|
if scm_info
|
|
|
|
db_last_id = latest_changeset ? latest_changeset.scmid : nil
|
2011-05-12 11:41:29 +04:00
|
|
|
next_rev = latest_changeset ? latest_changeset.revision.to_i + 1 : 1
|
2007-06-24 23:30:38 +04:00
|
|
|
# latest revision in the repository
|
2011-05-12 11:41:29 +04:00
|
|
|
scm_revision = scm_info.lastrev.scmid
|
2007-06-24 23:30:38 +04:00
|
|
|
unless changesets.find_by_scmid(scm_revision)
|
|
|
|
revisions = scm.revisions('', db_last_id, nil, :with_path => true)
|
|
|
|
transaction do
|
|
|
|
revisions.reverse_each do |revision|
|
2011-04-13 15:53:33 +04:00
|
|
|
changeset = Changeset.create(:repository => self,
|
|
|
|
:revision => next_rev,
|
|
|
|
:scmid => revision.scmid,
|
2011-05-12 11:41:29 +04:00
|
|
|
:committer => revision.author,
|
2007-06-24 23:30:38 +04:00
|
|
|
:committed_on => revision.time,
|
2011-04-13 15:53:33 +04:00
|
|
|
:comments => revision.message)
|
2007-06-24 23:30:38 +04:00
|
|
|
revision.paths.each do |change|
|
2010-02-02 20:02:32 +03:00
|
|
|
changeset.create_change(change)
|
2007-06-24 23:30:38 +04:00
|
|
|
end
|
|
|
|
next_rev += 1
|
|
|
|
end if revisions
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|