comparison app/models/repository/.svn/text-base/mercurial.rb.svn-base @ 0:513646585e45

* Import Redmine trunk SVN rev 3859
author Chris Cannam
date Fri, 23 Jul 2010 15:52:44 +0100
parents
children af80e5618e9b 8661b858af72
comparison
equal deleted inserted replaced
-1:000000000000 0:513646585e45
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
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 #
9 # 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 #
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require 'redmine/scm/adapters/mercurial_adapter'
19
20 class Repository::Mercurial < Repository
21 attr_protected :root_url
22 validates_presence_of :url
23
24 def scm_adapter
25 Redmine::Scm::Adapters::MercurialAdapter
26 end
27
28 def self.scm_name
29 'Mercurial'
30 end
31
32 def entries(path=nil, identifier=nil)
33 entries=scm.entries(path, identifier)
34 if entries
35 entries.each do |entry|
36 next unless entry.is_file?
37 # Set the filesize unless browsing a specific revision
38 if identifier.nil?
39 full_path = File.join(root_url, entry.path)
40 entry.size = File.stat(full_path).size if File.file?(full_path)
41 end
42 # Search the DB for the entry's last change
43 change = changes.find(:first, :conditions => ["path = ?", scm.with_leading_slash(entry.path)], :order => "#{Changeset.table_name}.committed_on DESC")
44 if change
45 entry.lastrev.identifier = change.changeset.revision
46 entry.lastrev.name = change.changeset.revision
47 entry.lastrev.author = change.changeset.committer
48 entry.lastrev.revision = change.revision
49 end
50 end
51 end
52 entries
53 end
54
55 def fetch_changesets
56 scm_info = scm.info
57 if scm_info
58 # latest revision found in database
59 db_revision = latest_changeset ? latest_changeset.revision.to_i : -1
60 # latest revision in the repository
61 latest_revision = scm_info.lastrev
62 return if latest_revision.nil?
63 scm_revision = latest_revision.identifier.to_i
64 if db_revision < scm_revision
65 logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
66 identifier_from = db_revision + 1
67 while (identifier_from <= scm_revision)
68 # loads changesets by batches of 100
69 identifier_to = [identifier_from + 99, scm_revision].min
70 revisions = scm.revisions('', identifier_from, identifier_to, :with_paths => true)
71 transaction do
72 revisions.each do |revision|
73 changeset = Changeset.create(:repository => self,
74 :revision => revision.identifier,
75 :scmid => revision.scmid,
76 :committer => revision.author,
77 :committed_on => revision.time,
78 :comments => revision.message)
79
80 revision.paths.each do |change|
81 changeset.create_change(change)
82 end
83 end
84 end unless revisions.nil?
85 identifier_from = identifier_to + 1
86 end
87 end
88 end
89 end
90 end