Mercurial > hg > soundsoftware-site
comparison app/models/repository/mercurial.rb @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | 0c939c159af4 |
children | 5e80956cc792 433d4f72a19b |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
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 # sort changesets by revision number | 21 # sort changesets by revision number |
22 has_many :changesets, :order => "#{Changeset.table_name}.id DESC", :foreign_key => 'repository_id' | 22 has_many :changesets, |
23 :order => "#{Changeset.table_name}.id DESC", | |
24 :foreign_key => 'repository_id' | |
23 | 25 |
24 attr_protected :root_url | 26 attr_protected :root_url |
25 validates_presence_of :url | 27 validates_presence_of :url |
26 | 28 |
27 FETCH_AT_ONCE = 100 # number of changesets to fetch at once | 29 # number of changesets to fetch at once |
30 FETCH_AT_ONCE = 100 | |
28 | 31 |
29 def self.human_attribute_name(attribute_key_name) | 32 def self.human_attribute_name(attribute_key_name) |
30 attr_name = attribute_key_name | 33 attr_name = attribute_key_name |
31 if attr_name == "url" | 34 if attr_name == "url" |
32 attr_name = "path_to_repository" | 35 attr_name = "path_to_repository" |
41 def self.scm_name | 44 def self.scm_name |
42 'Mercurial' | 45 'Mercurial' |
43 end | 46 end |
44 | 47 |
45 def supports_directory_revisions? | 48 def supports_directory_revisions? |
49 true | |
50 end | |
51 | |
52 def supports_revision_graph? | |
46 true | 53 true |
47 end | 54 end |
48 | 55 |
49 def repo_log_encoding | 56 def repo_log_encoding |
50 'UTF-8' | 57 'UTF-8' |
82 # there is no need to set 'order'. | 89 # there is no need to set 'order'. |
83 # But, MySQL test fails. | 90 # But, MySQL test fails. |
84 # Sqlite3 and PostgreSQL pass. | 91 # Sqlite3 and PostgreSQL pass. |
85 # Is this MySQL bug? | 92 # Is this MySQL bug? |
86 def latest_changesets(path, rev, limit=10) | 93 def latest_changesets(path, rev, limit=10) |
87 changesets.find(:all, :include => :user, | 94 changesets.find(:all, |
95 :include => :user, | |
88 :conditions => latest_changesets_cond(path, rev, limit), | 96 :conditions => latest_changesets_cond(path, rev, limit), |
89 :limit => limit, :order => "#{Changeset.table_name}.id DESC") | 97 :limit => limit, |
98 :order => "#{Changeset.table_name}.id DESC") | |
90 end | 99 end |
91 | 100 |
92 def latest_changesets_cond(path, rev, limit) | 101 def latest_changesets_cond(path, rev, limit) |
93 cond, args = [], [] | 102 cond, args = [], [] |
94 if scm.branchmap.member? rev | 103 if scm.branchmap.member? rev |
106 args << scm.nodes_in_branch(rev, :limit => branch_limit) | 115 args << scm.nodes_in_branch(rev, :limit => branch_limit) |
107 elsif last = rev ? find_changeset_by_name(scm.tagmap[rev] || rev) : nil | 116 elsif last = rev ? find_changeset_by_name(scm.tagmap[rev] || rev) : nil |
108 cond << "#{Changeset.table_name}.id <= ?" | 117 cond << "#{Changeset.table_name}.id <= ?" |
109 args << last.id | 118 args << last.id |
110 end | 119 end |
111 | |
112 unless path.blank? | 120 unless path.blank? |
113 cond << "EXISTS (SELECT * FROM #{Change.table_name} | 121 cond << "EXISTS (SELECT * FROM #{Change.table_name} |
114 WHERE #{Change.table_name}.changeset_id = #{Changeset.table_name}.id | 122 WHERE #{Change.table_name}.changeset_id = #{Changeset.table_name}.id |
115 AND (#{Change.table_name}.path = ? | 123 AND (#{Change.table_name}.path = ? |
116 OR #{Change.table_name}.path LIKE ? ESCAPE ?))" | 124 OR #{Change.table_name}.path LIKE ? ESCAPE ?))" |
117 args << path.with_leading_slash | 125 args << path.with_leading_slash |
118 args << "#{path.with_leading_slash.gsub(/[%_\\]/) { |s| "\\#{s}" }}/%" << '\\' | 126 args << "#{path.with_leading_slash.gsub(%r{[%_\\]}) { |s| "\\#{s}" }}/%" << '\\' |
119 end | 127 end |
120 | |
121 [cond.join(' AND '), *args] unless cond.empty? | 128 [cond.join(' AND '), *args] unless cond.empty? |
122 end | 129 end |
123 private :latest_changesets_cond | 130 private :latest_changesets_cond |
124 | 131 |
125 def fetch_changesets | 132 def fetch_changesets |
126 return if scm.info.nil? | 133 return if scm.info.nil? |
127 scm_rev = scm.info.lastrev.revision.to_i | 134 scm_rev = scm.info.lastrev.revision.to_i |
128 db_rev = latest_changeset ? latest_changeset.revision.to_i : -1 | 135 db_rev = latest_changeset ? latest_changeset.revision.to_i : -1 |
129 return unless db_rev < scm_rev # already up-to-date | 136 return unless db_rev < scm_rev # already up-to-date |
130 | 137 |
131 logger.debug "Fetching changesets for repository #{url}" if logger | 138 logger.debug "Fetching changesets for repository #{url}" if logger |
132 (db_rev + 1).step(scm_rev, FETCH_AT_ONCE) do |i| | 139 (db_rev + 1).step(scm_rev, FETCH_AT_ONCE) do |i| |
133 transaction do | 140 transaction do |
134 scm.each_revision('', i, [i + FETCH_AT_ONCE - 1, scm_rev].min) do |re| | 141 scm.each_revision('', i, [i + FETCH_AT_ONCE - 1, scm_rev].min) do |re| |
135 cs = Changeset.create(:repository => self, | 142 cs = Changeset.create(:repository => self, |
136 :revision => re.revision, | 143 :revision => re.revision, |
137 :scmid => re.scmid, | 144 :scmid => re.scmid, |
138 :committer => re.author, | 145 :committer => re.author, |
139 :committed_on => re.time, | 146 :committed_on => re.time, |
140 :comments => re.message) | 147 :comments => re.message) |
141 re.paths.each { |e| cs.create_change(e) } | 148 re.paths.each { |e| cs.create_change(e) } |
149 parents = {} | |
150 parents[cs] = re.parents unless re.parents.nil? | |
151 parents.each do |ch, chparents| | |
152 ch.parents = chparents.collect{|rp| find_changeset_by_name(rp)}.compact | |
153 end | |
142 end | 154 end |
143 end | 155 end |
144 end | 156 end |
145 self | |
146 end | 157 end |
147 end | 158 end |