darcs.rb
114 lines
| 3.8 KiB
| text/x-ruby
|
RubyLexer
|
r5635 | # Redmine - project management software | ||
|
r9453 | # Copyright (C) 2006-2012 Jean-Philippe Lang | ||
|
r570 | # | ||
# 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. | ||||
|
r5635 | # | ||
|
r570 | # 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. | ||||
|
r5635 | # | ||
|
r570 | # 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 | ||||
|
r4862 | validates_presence_of :url, :log_encoding | ||
|
r570 | |||
|
r8166 | def self.human_attribute_name(attribute_key_name, *args) | ||
|
r8853 | attr_name = attribute_key_name.to_s | ||
|
r5409 | if attr_name == "url" | ||
attr_name = "path_to_repository" | ||||
end | ||||
|
r8166 | super(attr_name, *args) | ||
|
r4855 | end | ||
|
r4702 | def self.scm_adapter_class | ||
|
r570 | Redmine::Scm::Adapters::DarcsAdapter | ||
end | ||||
|
r4702 | |||
|
r570 | def self.scm_name | ||
'Darcs' | ||||
end | ||||
|
r4702 | |||
|
r5358 | def supports_directory_revisions? | ||
true | ||||
end | ||||
|
r1758 | def entry(path=nil, identifier=nil) | ||
patch = identifier.nil? ? nil : changesets.find_by_revision(identifier) | ||||
scm.entry(path, patch.nil? ? nil : patch.scmid) | ||||
end | ||||
|
r5312 | |||
|
r570 | def entries(path=nil, identifier=nil) | ||
|
r5313 | patch = nil | ||
if ! identifier.nil? | ||||
patch = changesets.find_by_revision(identifier) | ||||
return nil if patch.nil? | ||||
end | ||||
|
r1314 | entries = scm.entries(path, patch.nil? ? nil : patch.scmid) | ||
|
r570 | if entries | ||
entries.each do |entry| | ||||
# Search the DB for the entry's last change | ||||
|
r5312 | if entry.lastrev && !entry.lastrev.scmid.blank? | ||
changeset = changesets.find_by_scmid(entry.lastrev.scmid) | ||||
end | ||||
|
r570 | if changeset | ||
entry.lastrev.identifier = changeset.revision | ||||
|
r5312 | entry.lastrev.name = changeset.revision | ||
entry.lastrev.time = changeset.committed_on | ||||
entry.lastrev.author = changeset.committer | ||||
|
r570 | end | ||
end | ||||
end | ||||
|
r9622 | load_entries_changesets(entries) | ||
|
r570 | entries | ||
end | ||||
|
r5312 | |||
|
r1758 | def cat(path, identifier=nil) | ||
|
r2093 | patch = identifier.nil? ? nil : changesets.find_by_revision(identifier.to_s) | ||
|
r1758 | scm.cat(path, patch.nil? ? nil : patch.scmid) | ||
end | ||||
|
r5312 | |||
|
r1499 | def diff(path, rev, rev_to) | ||
|
r570 | patch_from = changesets.find_by_revision(rev) | ||
|
r1222 | return nil if patch_from.nil? | ||
|
r570 | patch_to = changesets.find_by_revision(rev_to) if rev_to | ||
if path.blank? | ||||
|
r9576 | path = patch_from.filechanges.collect{|change| change.path}.join(' ') | ||
|
r570 | end | ||
|
r1499 | patch_from ? scm.diff(path, patch_from.scmid, patch_to ? patch_to.scmid : nil) : nil | ||
|
r570 | end | ||
|
r5312 | |||
|
r570 | def fetch_changesets | ||
scm_info = scm.info | ||||
if scm_info | ||||
db_last_id = latest_changeset ? latest_changeset.scmid : nil | ||||
|
r5635 | next_rev = latest_changeset ? latest_changeset.revision.to_i + 1 : 1 | ||
|
r570 | # latest revision in the repository | ||
|
r5635 | scm_revision = scm_info.lastrev.scmid | ||
|
r570 | unless changesets.find_by_scmid(scm_revision) | ||
revisions = scm.revisions('', db_last_id, nil, :with_path => true) | ||||
transaction do | ||||
revisions.reverse_each do |revision| | ||||
|
r5328 | changeset = Changeset.create(:repository => self, | ||
:revision => next_rev, | ||||
:scmid => revision.scmid, | ||||
|
r5635 | :committer => revision.author, | ||
|
r570 | :committed_on => revision.time, | ||
|
r5328 | :comments => revision.message) | ||
|
r570 | revision.paths.each do |change| | ||
|
r3246 | changeset.create_change(change) | ||
|
r570 | end | ||
next_rev += 1 | ||||
end if revisions | ||||
end | ||||
end | ||||
end | ||||
end | ||||
end | ||||