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