##// END OF EJS Templates
Mercurial: display working directory files sizes unless browsing a specific revision (#999)....
Jean-Philippe Lang -
r1318:beff2c54bc32
parent child
Show More
@@ -1,87 +1,92
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/mercurial_adapter'
18 require 'redmine/scm/adapters/mercurial_adapter'
19
19
20 class Repository::Mercurial < Repository
20 class Repository::Mercurial < Repository
21 attr_protected :root_url
21 attr_protected :root_url
22 validates_presence_of :url
22 validates_presence_of :url
23
23
24 def scm_adapter
24 def scm_adapter
25 Redmine::Scm::Adapters::MercurialAdapter
25 Redmine::Scm::Adapters::MercurialAdapter
26 end
26 end
27
27
28 def self.scm_name
28 def self.scm_name
29 'Mercurial'
29 'Mercurial'
30 end
30 end
31
31
32 def entries(path=nil, identifier=nil)
32 def entries(path=nil, identifier=nil)
33 entries=scm.entries(path, identifier)
33 entries=scm.entries(path, identifier)
34 if entries
34 if entries
35 entries.each do |entry|
35 entries.each do |entry|
36 next unless entry.is_file?
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
37 # Search the DB for the entry's last change
42 # Search the DB for the entry's last change
38 change = changes.find(:first, :conditions => ["path = ?", scm.with_leading_slash(entry.path)], :order => "#{Changeset.table_name}.committed_on DESC")
43 change = changes.find(:first, :conditions => ["path = ?", scm.with_leading_slash(entry.path)], :order => "#{Changeset.table_name}.committed_on DESC")
39 if change
44 if change
40 entry.lastrev.identifier = change.changeset.revision
45 entry.lastrev.identifier = change.changeset.revision
41 entry.lastrev.name = change.changeset.revision
46 entry.lastrev.name = change.changeset.revision
42 entry.lastrev.author = change.changeset.committer
47 entry.lastrev.author = change.changeset.committer
43 entry.lastrev.revision = change.revision
48 entry.lastrev.revision = change.revision
44 end
49 end
45 end
50 end
46 end
51 end
47 entries
52 entries
48 end
53 end
49
54
50 def fetch_changesets
55 def fetch_changesets
51 scm_info = scm.info
56 scm_info = scm.info
52 if scm_info
57 if scm_info
53 # latest revision found in database
58 # latest revision found in database
54 db_revision = latest_changeset ? latest_changeset.revision.to_i : -1
59 db_revision = latest_changeset ? latest_changeset.revision.to_i : -1
55 # latest revision in the repository
60 # latest revision in the repository
56 scm_revision = scm_info.lastrev.identifier.to_i
61 scm_revision = scm_info.lastrev.identifier.to_i
57 if db_revision < scm_revision
62 if db_revision < scm_revision
58 logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
63 logger.debug "Fetching changesets for repository #{url}" if logger && logger.debug?
59 identifier_from = db_revision + 1
64 identifier_from = db_revision + 1
60 while (identifier_from <= scm_revision)
65 while (identifier_from <= scm_revision)
61 # loads changesets by batches of 100
66 # loads changesets by batches of 100
62 identifier_to = [identifier_from + 99, scm_revision].min
67 identifier_to = [identifier_from + 99, scm_revision].min
63 revisions = scm.revisions('', identifier_from, identifier_to, :with_paths => true)
68 revisions = scm.revisions('', identifier_from, identifier_to, :with_paths => true)
64 transaction do
69 transaction do
65 revisions.each do |revision|
70 revisions.each do |revision|
66 changeset = Changeset.create(:repository => self,
71 changeset = Changeset.create(:repository => self,
67 :revision => revision.identifier,
72 :revision => revision.identifier,
68 :scmid => revision.scmid,
73 :scmid => revision.scmid,
69 :committer => revision.author,
74 :committer => revision.author,
70 :committed_on => revision.time,
75 :committed_on => revision.time,
71 :comments => revision.message)
76 :comments => revision.message)
72
77
73 revision.paths.each do |change|
78 revision.paths.each do |change|
74 Change.create(:changeset => changeset,
79 Change.create(:changeset => changeset,
75 :action => change[:action],
80 :action => change[:action],
76 :path => change[:path],
81 :path => change[:path],
77 :from_path => change[:from_path],
82 :from_path => change[:from_path],
78 :from_revision => change[:from_revision])
83 :from_revision => change[:from_revision])
79 end
84 end
80 end
85 end
81 end unless revisions.nil?
86 end unless revisions.nil?
82 identifier_from = identifier_to + 1
87 identifier_from = identifier_to + 1
83 end
88 end
84 end
89 end
85 end
90 end
86 end
91 end
87 end
92 end
General Comments 0
You need to be logged in to leave comments. Login now