comparison app/models/repository/mercurial.rb @ 441:cbce1fd3b1b7 redmine-1.2

Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author Chris Cannam
date Mon, 06 Jun 2011 14:24:13 +0100
parents 051f544170fe
children 753f1380d6bc 0c939c159af4
comparison
equal deleted inserted replaced
245:051f544170fe 441:cbce1fd3b1b7
1 # redMine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang 2 # Copyright (C) 2006-2011 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'
24 attr_protected :root_url 24 attr_protected :root_url
25 validates_presence_of :url 25 validates_presence_of :url
26 26
27 FETCH_AT_ONCE = 100 # number of changesets to fetch at once 27 FETCH_AT_ONCE = 100 # number of changesets to fetch at once
28 28
29 ATTRIBUTE_KEY_NAMES = {
30 "url" => "Root directory",
31 }
32 def self.human_attribute_name(attribute_key_name) 29 def self.human_attribute_name(attribute_key_name)
33 ATTRIBUTE_KEY_NAMES[attribute_key_name] || super 30 attr_name = attribute_key_name
31 if attr_name == "url"
32 attr_name = "path_to_repository"
33 end
34 super(attr_name)
34 end 35 end
35 36
36 def self.scm_adapter_class 37 def self.scm_adapter_class
37 Redmine::Scm::Adapters::MercurialAdapter 38 Redmine::Scm::Adapters::MercurialAdapter
38 end 39 end
39 40
40 def self.scm_name 41 def self.scm_name
41 'Mercurial' 42 'Mercurial'
43 end
44
45 def supports_directory_revisions?
46 true
42 end 47 end
43 48
44 def repo_log_encoding 49 def repo_log_encoding
45 'UTF-8' 50 'UTF-8'
46 end 51 end
51 end 56 end
52 57
53 # Returns the identifier for the given Mercurial changeset 58 # Returns the identifier for the given Mercurial changeset
54 def self.changeset_identifier(changeset) 59 def self.changeset_identifier(changeset)
55 changeset.scmid 60 changeset.scmid
56 end
57
58 def branches
59 nil
60 end
61
62 def tags
63 nil
64 end 61 end
65 62
66 def diff_format_revisions(cs, cs_to, sep=':') 63 def diff_format_revisions(cs, cs_to, sep=':')
67 super(cs, cs_to, ' ') 64 super(cs, cs_to, ' ')
68 end 65 end
78 return e if e 75 return e if e
79 changesets.find(:first, :conditions => ['scmid LIKE ?', "#{name}%"]) # last ditch 76 changesets.find(:first, :conditions => ['scmid LIKE ?', "#{name}%"]) # last ditch
80 end 77 end
81 78
82 # Returns the latest changesets for +path+; sorted by revision number 79 # Returns the latest changesets for +path+; sorted by revision number
83 # Default behavior is to search in cached changesets 80 #
81 # Because :order => 'id DESC' is defined at 'has_many',
82 # there is no need to set 'order'.
83 # But, MySQL test fails.
84 # Sqlite3 and PostgreSQL pass.
85 # Is this MySQL bug?
84 def latest_changesets(path, rev, limit=10) 86 def latest_changesets(path, rev, limit=10)
85 if path.blank? 87 changesets.find(:all, :include => :user,
86 changesets.find(:all, :include => :user, :limit => limit) 88 :conditions => latest_changesets_cond(path, rev, limit),
87 else 89 :limit => limit, :order => "#{Changeset.table_name}.id DESC")
88 changesets.find(:all, :select => "DISTINCT #{Changeset.table_name}.*", 90 end
89 :joins => :changes, 91
90 :conditions => ["#{Change.table_name}.path = ? OR #{Change.table_name}.path LIKE ? ESCAPE ?", 92 def latest_changesets_cond(path, rev, limit)
91 path.with_leading_slash, 93 cond, args = [], []
92 "#{path.with_leading_slash.gsub(/[%_\\]/) { |s| "\\#{s}" }}/%", '\\'], 94 if scm.branchmap.member? rev
93 :include => :user, :limit => limit) 95 # Mercurial named branch is *stable* in each revision.
96 # So, named branch can be stored in database.
97 # Mercurial provides *bookmark* which is equivalent with git branch.
98 # But, bookmark is not implemented.
99 cond << "#{Changeset.table_name}.scmid IN (?)"
100 # Revisions in root directory and sub directory are not equal.
101 # So, in order to get correct limit, we need to get all revisions.
102 # But, it is very heavy.
103 # Mercurial does not treat direcotry.
104 # So, "hg log DIR" is very heavy.
105 branch_limit = path.blank? ? limit : ( limit * 5 )
106 args << scm.nodes_in_branch(rev, :limit => branch_limit)
107 elsif last = rev ? find_changeset_by_name(scm.tagmap[rev] || rev) : nil
108 cond << "#{Changeset.table_name}.id <= ?"
109 args << last.id
94 end 110 end
111
112 unless path.blank?
113 cond << "EXISTS (SELECT * FROM #{Change.table_name}
114 WHERE #{Change.table_name}.changeset_id = #{Changeset.table_name}.id
115 AND (#{Change.table_name}.path = ?
116 OR #{Change.table_name}.path LIKE ? ESCAPE ?))"
117 args << path.with_leading_slash
118 args << "#{path.with_leading_slash.gsub(/[%_\\]/) { |s| "\\#{s}" }}/%" << '\\'
119 end
120
121 [cond.join(' AND '), *args] unless cond.empty?
95 end 122 end
123 private :latest_changesets_cond
96 124
97 def fetch_changesets 125 def fetch_changesets
98 scm_rev = scm.info.lastrev.revision.to_i 126 scm_rev = scm.info.lastrev.revision.to_i
99 db_rev = latest_changeset ? latest_changeset.revision.to_i : -1 127 db_rev = latest_changeset ? latest_changeset.revision.to_i : -1
100 return unless db_rev < scm_rev # already up-to-date 128 return unless db_rev < scm_rev # already up-to-date