2007-06-24 23:30:38 +04:00
|
|
|
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-03-01 08:14:03 +03:00
|
|
|
ATTRIBUTE_KEY_NAMES = {
|
|
|
|
"url" => "Root directory",
|
2011-03-01 13:27:30 +03:00
|
|
|
"log_encoding" => "Commit messages encoding",
|
2011-03-01 08:14:03 +03:00
|
|
|
}
|
|
|
|
def self.human_attribute_name(attribute_key_name)
|
|
|
|
ATTRIBUTE_KEY_NAMES[attribute_key_name] || super
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
2007-06-24 23:30:38 +04:00
|
|
|
def entries(path=nil, identifier=nil)
|
2008-04-06 14:35:55 +04:00
|
|
|
patch = identifier.nil? ? nil : changesets.find_by_revision(identifier)
|
|
|
|
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
|
|
|
|
changeset = changesets.find_by_scmid(entry.lastrev.scmid) if entry.lastrev && !entry.lastrev.scmid.blank?
|
|
|
|
if changeset
|
|
|
|
entry.lastrev.identifier = changeset.revision
|
|
|
|
entry.lastrev.name = changeset.revision
|
|
|
|
entry.lastrev.time = changeset.committed_on
|
|
|
|
entry.lastrev.author = changeset.committer
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
entries
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def fetch_changesets
|
|
|
|
scm_info = scm.info
|
|
|
|
if scm_info
|
|
|
|
db_last_id = latest_changeset ? latest_changeset.scmid : nil
|
2008-03-12 23:28:49 +03: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
|
|
|
|
scm_revision = scm_info.lastrev.scmid
|
|
|
|
unless changesets.find_by_scmid(scm_revision)
|
|
|
|
revisions = scm.revisions('', db_last_id, nil, :with_path => true)
|
|
|
|
transaction do
|
|
|
|
revisions.reverse_each do |revision|
|
|
|
|
changeset = Changeset.create(:repository => self,
|
|
|
|
:revision => next_rev,
|
|
|
|
:scmid => revision.scmid,
|
|
|
|
:committer => revision.author,
|
|
|
|
:committed_on => revision.time,
|
|
|
|
:comments => revision.message)
|
2008-03-12 23:28:49 +03:00
|
|
|
|
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
|