comparison app/models/repository/darcs.rb @ 514:7eba09d624db live

Merge
author Chris Cannam
date Thu, 14 Jul 2011 10:50:53 +0100
parents cbce1fd3b1b7
children 433d4f72a19b
comparison
equal deleted inserted replaced
512:b9aebdd7dd40 514:7eba09d624db
1 # redMine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
8 # 8 #
9 # This program is distributed in the hope that it will be useful, 9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details. 12 # GNU General Public License for more details.
13 # 13 #
14 # You should have received a copy of the GNU General Public License 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 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. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 require 'redmine/scm/adapters/darcs_adapter' 18 require 'redmine/scm/adapters/darcs_adapter'
19 19
20 class Repository::Darcs < Repository 20 class Repository::Darcs < Repository
21 validates_presence_of :url 21 validates_presence_of :url, :log_encoding
22 22
23 def scm_adapter 23 def self.human_attribute_name(attribute_key_name)
24 attr_name = attribute_key_name
25 if attr_name == "url"
26 attr_name = "path_to_repository"
27 end
28 super(attr_name)
29 end
30
31 def self.scm_adapter_class
24 Redmine::Scm::Adapters::DarcsAdapter 32 Redmine::Scm::Adapters::DarcsAdapter
25 end 33 end
26 34
27 def self.scm_name 35 def self.scm_name
28 'Darcs' 36 'Darcs'
29 end 37 end
30 38
39 def supports_directory_revisions?
40 true
41 end
42
31 def entry(path=nil, identifier=nil) 43 def entry(path=nil, identifier=nil)
32 patch = identifier.nil? ? nil : changesets.find_by_revision(identifier) 44 patch = identifier.nil? ? nil : changesets.find_by_revision(identifier)
33 scm.entry(path, patch.nil? ? nil : patch.scmid) 45 scm.entry(path, patch.nil? ? nil : patch.scmid)
34 end 46 end
35 47
36 def entries(path=nil, identifier=nil) 48 def entries(path=nil, identifier=nil)
37 patch = identifier.nil? ? nil : changesets.find_by_revision(identifier) 49 patch = nil
50 if ! identifier.nil?
51 patch = changesets.find_by_revision(identifier)
52 return nil if patch.nil?
53 end
38 entries = scm.entries(path, patch.nil? ? nil : patch.scmid) 54 entries = scm.entries(path, patch.nil? ? nil : patch.scmid)
39 if entries 55 if entries
40 entries.each do |entry| 56 entries.each do |entry|
41 # Search the DB for the entry's last change 57 # 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? 58 if entry.lastrev && !entry.lastrev.scmid.blank?
59 changeset = changesets.find_by_scmid(entry.lastrev.scmid)
60 end
43 if changeset 61 if changeset
44 entry.lastrev.identifier = changeset.revision 62 entry.lastrev.identifier = changeset.revision
45 entry.lastrev.name = changeset.revision 63 entry.lastrev.name = changeset.revision
46 entry.lastrev.time = changeset.committed_on 64 entry.lastrev.time = changeset.committed_on
47 entry.lastrev.author = changeset.committer 65 entry.lastrev.author = changeset.committer
48 end 66 end
49 end 67 end
50 end 68 end
51 entries 69 entries
52 end 70 end
53 71
54 def cat(path, identifier=nil) 72 def cat(path, identifier=nil)
55 patch = identifier.nil? ? nil : changesets.find_by_revision(identifier.to_s) 73 patch = identifier.nil? ? nil : changesets.find_by_revision(identifier.to_s)
56 scm.cat(path, patch.nil? ? nil : patch.scmid) 74 scm.cat(path, patch.nil? ? nil : patch.scmid)
57 end 75 end
58 76
59 def diff(path, rev, rev_to) 77 def diff(path, rev, rev_to)
60 patch_from = changesets.find_by_revision(rev) 78 patch_from = changesets.find_by_revision(rev)
61 return nil if patch_from.nil? 79 return nil if patch_from.nil?
62 patch_to = changesets.find_by_revision(rev_to) if rev_to 80 patch_to = changesets.find_by_revision(rev_to) if rev_to
63 if path.blank? 81 if path.blank?
64 path = patch_from.changes.collect{|change| change.path}.join(' ') 82 path = patch_from.changes.collect{|change| change.path}.join(' ')
65 end 83 end
66 patch_from ? scm.diff(path, patch_from.scmid, patch_to ? patch_to.scmid : nil) : nil 84 patch_from ? scm.diff(path, patch_from.scmid, patch_to ? patch_to.scmid : nil) : nil
67 end 85 end
68 86
69 def fetch_changesets 87 def fetch_changesets
70 scm_info = scm.info 88 scm_info = scm.info
71 if scm_info 89 if scm_info
72 db_last_id = latest_changeset ? latest_changeset.scmid : nil 90 db_last_id = latest_changeset ? latest_changeset.scmid : nil
73 next_rev = latest_changeset ? latest_changeset.revision.to_i + 1 : 1 91 next_rev = latest_changeset ? latest_changeset.revision.to_i + 1 : 1
74 # latest revision in the repository 92 # latest revision in the repository
75 scm_revision = scm_info.lastrev.scmid 93 scm_revision = scm_info.lastrev.scmid
76 unless changesets.find_by_scmid(scm_revision) 94 unless changesets.find_by_scmid(scm_revision)
77 revisions = scm.revisions('', db_last_id, nil, :with_path => true) 95 revisions = scm.revisions('', db_last_id, nil, :with_path => true)
78 transaction do 96 transaction do
79 revisions.reverse_each do |revision| 97 revisions.reverse_each do |revision|
80 changeset = Changeset.create(:repository => self, 98 changeset = Changeset.create(:repository => self,
81 :revision => next_rev, 99 :revision => next_rev,
82 :scmid => revision.scmid, 100 :scmid => revision.scmid,
83 :committer => revision.author, 101 :committer => revision.author,
84 :committed_on => revision.time, 102 :committed_on => revision.time,
85 :comments => revision.message) 103 :comments => revision.message)
86
87 revision.paths.each do |change| 104 revision.paths.each do |change|
88 changeset.create_change(change) 105 changeset.create_change(change)
89 end 106 end
90 next_rev += 1 107 next_rev += 1
91 end if revisions 108 end if revisions