##// END OF EJS Templates
scm: model: mercurial: set revision graph support true (#5501)...
Toshi MARUYAMA -
r7598:9e238171cafe
parent child
Show More
@@ -1,154 +1,158
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 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/mercurial_adapter'
19 19
20 20 class Repository::Mercurial < Repository
21 21 # sort changesets by revision number
22 22 has_many :changesets,
23 23 :order => "#{Changeset.table_name}.id DESC",
24 24 :foreign_key => 'repository_id'
25 25
26 26 attr_protected :root_url
27 27 validates_presence_of :url
28 28
29 29 # number of changesets to fetch at once
30 30 FETCH_AT_ONCE = 100
31 31
32 32 def self.human_attribute_name(attribute_key_name)
33 33 attr_name = attribute_key_name
34 34 if attr_name == "url"
35 35 attr_name = "path_to_repository"
36 36 end
37 37 super(attr_name)
38 38 end
39 39
40 40 def self.scm_adapter_class
41 41 Redmine::Scm::Adapters::MercurialAdapter
42 42 end
43 43
44 44 def self.scm_name
45 45 'Mercurial'
46 46 end
47 47
48 48 def supports_directory_revisions?
49 49 true
50 50 end
51 51
52 def supports_revision_graph?
53 true
54 end
55
52 56 def repo_log_encoding
53 57 'UTF-8'
54 58 end
55 59
56 60 # Returns the readable identifier for the given mercurial changeset
57 61 def self.format_changeset_identifier(changeset)
58 62 "#{changeset.revision}:#{changeset.scmid}"
59 63 end
60 64
61 65 # Returns the identifier for the given Mercurial changeset
62 66 def self.changeset_identifier(changeset)
63 67 changeset.scmid
64 68 end
65 69
66 70 def diff_format_revisions(cs, cs_to, sep=':')
67 71 super(cs, cs_to, ' ')
68 72 end
69 73
70 74 # Finds and returns a revision with a number or the beginning of a hash
71 75 def find_changeset_by_name(name)
72 76 return nil if name.nil? || name.empty?
73 77 if /[^\d]/ =~ name or name.to_s.size > 8
74 78 e = changesets.find(:first, :conditions => ['scmid = ?', name.to_s])
75 79 else
76 80 e = changesets.find(:first, :conditions => ['revision = ?', name.to_s])
77 81 end
78 82 return e if e
79 83 changesets.find(:first, :conditions => ['scmid LIKE ?', "#{name}%"]) # last ditch
80 84 end
81 85
82 86 # Returns the latest changesets for +path+; sorted by revision number
83 87 #
84 88 # Because :order => 'id DESC' is defined at 'has_many',
85 89 # there is no need to set 'order'.
86 90 # But, MySQL test fails.
87 91 # Sqlite3 and PostgreSQL pass.
88 92 # Is this MySQL bug?
89 93 def latest_changesets(path, rev, limit=10)
90 94 changesets.find(:all,
91 95 :include => :user,
92 96 :conditions => latest_changesets_cond(path, rev, limit),
93 97 :limit => limit,
94 98 :order => "#{Changeset.table_name}.id DESC")
95 99 end
96 100
97 101 def latest_changesets_cond(path, rev, limit)
98 102 cond, args = [], []
99 103 if scm.branchmap.member? rev
100 104 # Mercurial named branch is *stable* in each revision.
101 105 # So, named branch can be stored in database.
102 106 # Mercurial provides *bookmark* which is equivalent with git branch.
103 107 # But, bookmark is not implemented.
104 108 cond << "#{Changeset.table_name}.scmid IN (?)"
105 109 # Revisions in root directory and sub directory are not equal.
106 110 # So, in order to get correct limit, we need to get all revisions.
107 111 # But, it is very heavy.
108 112 # Mercurial does not treat direcotry.
109 113 # So, "hg log DIR" is very heavy.
110 114 branch_limit = path.blank? ? limit : ( limit * 5 )
111 115 args << scm.nodes_in_branch(rev, :limit => branch_limit)
112 116 elsif last = rev ? find_changeset_by_name(scm.tagmap[rev] || rev) : nil
113 117 cond << "#{Changeset.table_name}.id <= ?"
114 118 args << last.id
115 119 end
116 120 unless path.blank?
117 121 cond << "EXISTS (SELECT * FROM #{Change.table_name}
118 122 WHERE #{Change.table_name}.changeset_id = #{Changeset.table_name}.id
119 123 AND (#{Change.table_name}.path = ?
120 124 OR #{Change.table_name}.path LIKE ? ESCAPE ?))"
121 125 args << path.with_leading_slash
122 126 args << "#{path.with_leading_slash.gsub(%r{[%_\\]}) { |s| "\\#{s}" }}/%" << '\\'
123 127 end
124 128 [cond.join(' AND '), *args] unless cond.empty?
125 129 end
126 130 private :latest_changesets_cond
127 131
128 132 def fetch_changesets
129 133 return if scm.info.nil?
130 134 scm_rev = scm.info.lastrev.revision.to_i
131 135 db_rev = latest_changeset ? latest_changeset.revision.to_i : -1
132 136 return unless db_rev < scm_rev # already up-to-date
133 137
134 138 logger.debug "Fetching changesets for repository #{url}" if logger
135 139 (db_rev + 1).step(scm_rev, FETCH_AT_ONCE) do |i|
136 140 transaction do
137 141 scm.each_revision('', i, [i + FETCH_AT_ONCE - 1, scm_rev].min) do |re|
138 142 cs = Changeset.create(:repository => self,
139 143 :revision => re.revision,
140 144 :scmid => re.scmid,
141 145 :committer => re.author,
142 146 :committed_on => re.time,
143 147 :comments => re.message)
144 148 re.paths.each { |e| cs.create_change(e) }
145 149 parents = {}
146 150 parents[cs] = re.parents unless re.parents.nil?
147 151 parents.each do |ch, chparents|
148 152 ch.parents = chparents.collect{|rp| find_changeset_by_name(rp)}.compact
149 153 end
150 154 end
151 155 end
152 156 end
153 157 end
154 158 end
General Comments 0
You need to be logged in to leave comments. Login now