##// END OF EJS Templates
scm: darcs: model entries returns nil if revision is not stored in database....
Toshi MARUYAMA -
r5313:37c6480e4453
parent child
Show More
@@ -1,106 +1,110
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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, :log_encoding
21 validates_presence_of :url, :log_encoding
22
22
23 ATTRIBUTE_KEY_NAMES = {
23 ATTRIBUTE_KEY_NAMES = {
24 "url" => "Root directory",
24 "url" => "Root directory",
25 "log_encoding" => "Commit messages encoding",
25 "log_encoding" => "Commit messages encoding",
26 }
26 }
27 def self.human_attribute_name(attribute_key_name)
27 def self.human_attribute_name(attribute_key_name)
28 ATTRIBUTE_KEY_NAMES[attribute_key_name] || super
28 ATTRIBUTE_KEY_NAMES[attribute_key_name] || super
29 end
29 end
30
30
31 def self.scm_adapter_class
31 def self.scm_adapter_class
32 Redmine::Scm::Adapters::DarcsAdapter
32 Redmine::Scm::Adapters::DarcsAdapter
33 end
33 end
34
34
35 def self.scm_name
35 def self.scm_name
36 'Darcs'
36 'Darcs'
37 end
37 end
38
38
39 def entry(path=nil, identifier=nil)
39 def entry(path=nil, identifier=nil)
40 patch = identifier.nil? ? nil : changesets.find_by_revision(identifier)
40 patch = identifier.nil? ? nil : changesets.find_by_revision(identifier)
41 scm.entry(path, patch.nil? ? nil : patch.scmid)
41 scm.entry(path, patch.nil? ? nil : patch.scmid)
42 end
42 end
43
43
44 def entries(path=nil, identifier=nil)
44 def entries(path=nil, identifier=nil)
45 patch = identifier.nil? ? nil : changesets.find_by_revision(identifier)
45 patch = nil
46 if ! identifier.nil?
47 patch = changesets.find_by_revision(identifier)
48 return nil if patch.nil?
49 end
46 entries = scm.entries(path, patch.nil? ? nil : patch.scmid)
50 entries = scm.entries(path, patch.nil? ? nil : patch.scmid)
47 if entries
51 if entries
48 entries.each do |entry|
52 entries.each do |entry|
49 # Search the DB for the entry's last change
53 # Search the DB for the entry's last change
50 if entry.lastrev && !entry.lastrev.scmid.blank?
54 if entry.lastrev && !entry.lastrev.scmid.blank?
51 changeset = changesets.find_by_scmid(entry.lastrev.scmid)
55 changeset = changesets.find_by_scmid(entry.lastrev.scmid)
52 end
56 end
53 if changeset
57 if changeset
54 entry.lastrev.identifier = changeset.revision
58 entry.lastrev.identifier = changeset.revision
55 entry.lastrev.name = changeset.revision
59 entry.lastrev.name = changeset.revision
56 entry.lastrev.time = changeset.committed_on
60 entry.lastrev.time = changeset.committed_on
57 entry.lastrev.author = changeset.committer
61 entry.lastrev.author = changeset.committer
58 end
62 end
59 end
63 end
60 end
64 end
61 entries
65 entries
62 end
66 end
63
67
64 def cat(path, identifier=nil)
68 def cat(path, identifier=nil)
65 patch = identifier.nil? ? nil : changesets.find_by_revision(identifier.to_s)
69 patch = identifier.nil? ? nil : changesets.find_by_revision(identifier.to_s)
66 scm.cat(path, patch.nil? ? nil : patch.scmid)
70 scm.cat(path, patch.nil? ? nil : patch.scmid)
67 end
71 end
68
72
69 def diff(path, rev, rev_to)
73 def diff(path, rev, rev_to)
70 patch_from = changesets.find_by_revision(rev)
74 patch_from = changesets.find_by_revision(rev)
71 return nil if patch_from.nil?
75 return nil if patch_from.nil?
72 patch_to = changesets.find_by_revision(rev_to) if rev_to
76 patch_to = changesets.find_by_revision(rev_to) if rev_to
73 if path.blank?
77 if path.blank?
74 path = patch_from.changes.collect{|change| change.path}.join(' ')
78 path = patch_from.changes.collect{|change| change.path}.join(' ')
75 end
79 end
76 patch_from ? scm.diff(path, patch_from.scmid, patch_to ? patch_to.scmid : nil) : nil
80 patch_from ? scm.diff(path, patch_from.scmid, patch_to ? patch_to.scmid : nil) : nil
77 end
81 end
78
82
79 def fetch_changesets
83 def fetch_changesets
80 scm_info = scm.info
84 scm_info = scm.info
81 if scm_info
85 if scm_info
82 db_last_id = latest_changeset ? latest_changeset.scmid : nil
86 db_last_id = latest_changeset ? latest_changeset.scmid : nil
83 next_rev = latest_changeset ? latest_changeset.revision.to_i + 1 : 1
87 next_rev = latest_changeset ? latest_changeset.revision.to_i + 1 : 1
84 # latest revision in the repository
88 # latest revision in the repository
85 scm_revision = scm_info.lastrev.scmid
89 scm_revision = scm_info.lastrev.scmid
86 unless changesets.find_by_scmid(scm_revision)
90 unless changesets.find_by_scmid(scm_revision)
87 revisions = scm.revisions('', db_last_id, nil, :with_path => true)
91 revisions = scm.revisions('', db_last_id, nil, :with_path => true)
88 transaction do
92 transaction do
89 revisions.reverse_each do |revision|
93 revisions.reverse_each do |revision|
90 changeset = Changeset.create(:repository => self,
94 changeset = Changeset.create(:repository => self,
91 :revision => next_rev,
95 :revision => next_rev,
92 :scmid => revision.scmid,
96 :scmid => revision.scmid,
93 :committer => revision.author,
97 :committer => revision.author,
94 :committed_on => revision.time,
98 :committed_on => revision.time,
95 :comments => revision.message)
99 :comments => revision.message)
96
100
97 revision.paths.each do |change|
101 revision.paths.each do |change|
98 changeset.create_change(change)
102 changeset.create_change(change)
99 end
103 end
100 next_rev += 1
104 next_rev += 1
101 end if revisions
105 end if revisions
102 end
106 end
103 end
107 end
104 end
108 end
105 end
109 end
106 end
110 end
General Comments 0
You need to be logged in to leave comments. Login now