To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / models / repository / darcs.rb @ 1298:4f746d8966dd

History | View | Annotate | Download (3.86 KB)

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