2011-10-29 16:19:11 +04:00
|
|
|
#-- encoding: UTF-8
|
2011-05-30 00:11:52 +04:00
|
|
|
#-- copyright
|
|
|
|
# ChiliProject is a project management system.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# Copyright (C) 2010-2011 the ChiliProject Team
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +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-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# See doc/COPYRIGHT.rdoc for more details.
|
|
|
|
#++
|
|
|
|
|
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
|
2011-05-30 22:52:25 +04:00
|
|
|
|
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
|
2011-05-30 22:52:25 +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-05-30 22:52:25 +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-05-30 22:52:25 +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-30 22:52:25 +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-30 22:52:25 +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|
|
|
|
|
changeset = Changeset.create(:repository => self,
|
|
|
|
:revision => next_rev,
|
|
|
|
:scmid => revision.scmid,
|
2011-05-30 22:52:25 +04:00
|
|
|
:committer => revision.author,
|
2007-06-24 23:30:38 +04:00
|
|
|
:committed_on => revision.time,
|
|
|
|
:comments => revision.message)
|
2011-05-30 22:52:25 +04: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
|