@@ -1,104 +1,106 | |||||
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 = identifier.nil? ? nil : changesets.find_by_revision(identifier) | |
46 | entries = scm.entries(path, patch.nil? ? nil : patch.scmid) |
|
46 | entries = scm.entries(path, patch.nil? ? nil : patch.scmid) | |
47 | if entries |
|
47 | if entries | |
48 | entries.each do |entry| |
|
48 | entries.each do |entry| | |
49 | # Search the DB for the entry's last change |
|
49 | # Search the DB for the entry's last change | |
50 |
|
|
50 | if entry.lastrev && !entry.lastrev.scmid.blank? | |
|
51 | changeset = changesets.find_by_scmid(entry.lastrev.scmid) | |||
|
52 | end | |||
51 | if changeset |
|
53 | if changeset | |
52 | entry.lastrev.identifier = changeset.revision |
|
54 | entry.lastrev.identifier = changeset.revision | |
53 | entry.lastrev.name = changeset.revision |
|
55 | entry.lastrev.name = changeset.revision | |
54 | entry.lastrev.time = changeset.committed_on |
|
56 | entry.lastrev.time = changeset.committed_on | |
55 | entry.lastrev.author = changeset.committer |
|
57 | entry.lastrev.author = changeset.committer | |
56 | end |
|
58 | end | |
57 | end |
|
59 | end | |
58 | end |
|
60 | end | |
59 | entries |
|
61 | entries | |
60 | end |
|
62 | end | |
61 |
|
63 | |||
62 | def cat(path, identifier=nil) |
|
64 | def cat(path, identifier=nil) | |
63 | patch = identifier.nil? ? nil : changesets.find_by_revision(identifier.to_s) |
|
65 | patch = identifier.nil? ? nil : changesets.find_by_revision(identifier.to_s) | |
64 | scm.cat(path, patch.nil? ? nil : patch.scmid) |
|
66 | scm.cat(path, patch.nil? ? nil : patch.scmid) | |
65 | end |
|
67 | end | |
66 |
|
68 | |||
67 | def diff(path, rev, rev_to) |
|
69 | def diff(path, rev, rev_to) | |
68 | patch_from = changesets.find_by_revision(rev) |
|
70 | patch_from = changesets.find_by_revision(rev) | |
69 | return nil if patch_from.nil? |
|
71 | return nil if patch_from.nil? | |
70 | patch_to = changesets.find_by_revision(rev_to) if rev_to |
|
72 | patch_to = changesets.find_by_revision(rev_to) if rev_to | |
71 | if path.blank? |
|
73 | if path.blank? | |
72 | path = patch_from.changes.collect{|change| change.path}.join(' ') |
|
74 | path = patch_from.changes.collect{|change| change.path}.join(' ') | |
73 | end |
|
75 | end | |
74 | patch_from ? scm.diff(path, patch_from.scmid, patch_to ? patch_to.scmid : nil) : nil |
|
76 | patch_from ? scm.diff(path, patch_from.scmid, patch_to ? patch_to.scmid : nil) : nil | |
75 | end |
|
77 | end | |
76 |
|
78 | |||
77 | def fetch_changesets |
|
79 | def fetch_changesets | |
78 | scm_info = scm.info |
|
80 | scm_info = scm.info | |
79 | if scm_info |
|
81 | if scm_info | |
80 | db_last_id = latest_changeset ? latest_changeset.scmid : nil |
|
82 | db_last_id = latest_changeset ? latest_changeset.scmid : nil | |
81 | next_rev = latest_changeset ? latest_changeset.revision.to_i + 1 : 1 |
|
83 | next_rev = latest_changeset ? latest_changeset.revision.to_i + 1 : 1 | |
82 | # latest revision in the repository |
|
84 | # latest revision in the repository | |
83 | scm_revision = scm_info.lastrev.scmid |
|
85 | scm_revision = scm_info.lastrev.scmid | |
84 | unless changesets.find_by_scmid(scm_revision) |
|
86 | unless changesets.find_by_scmid(scm_revision) | |
85 | revisions = scm.revisions('', db_last_id, nil, :with_path => true) |
|
87 | revisions = scm.revisions('', db_last_id, nil, :with_path => true) | |
86 | transaction do |
|
88 | transaction do | |
87 | revisions.reverse_each do |revision| |
|
89 | revisions.reverse_each do |revision| | |
88 | changeset = Changeset.create(:repository => self, |
|
90 | changeset = Changeset.create(:repository => self, | |
89 | :revision => next_rev, |
|
91 | :revision => next_rev, | |
90 | :scmid => revision.scmid, |
|
92 | :scmid => revision.scmid, | |
91 | :committer => revision.author, |
|
93 | :committer => revision.author, | |
92 | :committed_on => revision.time, |
|
94 | :committed_on => revision.time, | |
93 | :comments => revision.message) |
|
95 | :comments => revision.message) | |
94 |
|
96 | |||
95 | revision.paths.each do |change| |
|
97 | revision.paths.each do |change| | |
96 | changeset.create_change(change) |
|
98 | changeset.create_change(change) | |
97 | end |
|
99 | end | |
98 | next_rev += 1 |
|
100 | next_rev += 1 | |
99 | end if revisions |
|
101 | end if revisions | |
100 | end |
|
102 | end | |
101 | end |
|
103 | end | |
102 | end |
|
104 | end | |
103 | end |
|
105 | end | |
104 | end |
|
106 | end |
General Comments 0
You need to be logged in to leave comments.
Login now