##// END OF EJS Templates
scm: mercurial: temporary disable tags and branches at model (#1981, #7246, #4455)....
Toshi MARUYAMA -
r4751:0247a149c43c
parent child
Show More
@@ -1,99 +1,107
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 # 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, :order => "#{Changeset.table_name}.id DESC", :foreign_key => 'repository_id'
23
23
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 def self.scm_adapter_class
29 def self.scm_adapter_class
30 Redmine::Scm::Adapters::MercurialAdapter
30 Redmine::Scm::Adapters::MercurialAdapter
31 end
31 end
32
32
33 def self.scm_name
33 def self.scm_name
34 'Mercurial'
34 'Mercurial'
35 end
35 end
36
36
37 # Returns the readable identifier for the given mercurial changeset
37 # Returns the readable identifier for the given mercurial changeset
38 def self.format_changeset_identifier(changeset)
38 def self.format_changeset_identifier(changeset)
39 "#{changeset.revision}:#{changeset.scmid}"
39 "#{changeset.revision}:#{changeset.scmid}"
40 end
40 end
41
41
42 # Returns the identifier for the given Mercurial changeset
42 # Returns the identifier for the given Mercurial changeset
43 def self.changeset_identifier(changeset)
43 def self.changeset_identifier(changeset)
44 changeset.scmid
44 changeset.scmid
45 end
45 end
46
46
47 def branches
48 nil
49 end
50
51 def tags
52 nil
53 end
54
47 def diff_format_revisions(cs, cs_to, sep=':')
55 def diff_format_revisions(cs, cs_to, sep=':')
48 super(cs, cs_to, ' ')
56 super(cs, cs_to, ' ')
49 end
57 end
50
58
51 # Finds and returns a revision with a number or the beginning of a hash
59 # Finds and returns a revision with a number or the beginning of a hash
52 def find_changeset_by_name(name)
60 def find_changeset_by_name(name)
53 return nil if name.nil? || name.empty?
61 return nil if name.nil? || name.empty?
54 if /[^\d]/ =~ name or name.to_s.size > 8
62 if /[^\d]/ =~ name or name.to_s.size > 8
55 e = changesets.find(:first, :conditions => ['scmid = ?', name.to_s])
63 e = changesets.find(:first, :conditions => ['scmid = ?', name.to_s])
56 else
64 else
57 e = changesets.find(:first, :conditions => ['revision = ?', name.to_s])
65 e = changesets.find(:first, :conditions => ['revision = ?', name.to_s])
58 end
66 end
59 return e if e
67 return e if e
60 changesets.find(:first, :conditions => ['scmid LIKE ?', "#{name}%"]) # last ditch
68 changesets.find(:first, :conditions => ['scmid LIKE ?', "#{name}%"]) # last ditch
61 end
69 end
62
70
63 # Returns the latest changesets for +path+; sorted by revision number
71 # Returns the latest changesets for +path+; sorted by revision number
64 # Default behavior is to search in cached changesets
72 # Default behavior is to search in cached changesets
65 def latest_changesets(path, rev, limit=10)
73 def latest_changesets(path, rev, limit=10)
66 if path.blank?
74 if path.blank?
67 changesets.find(:all, :include => :user, :limit => limit)
75 changesets.find(:all, :include => :user, :limit => limit)
68 else
76 else
69 changesets.find(:all, :select => "DISTINCT #{Changeset.table_name}.*",
77 changesets.find(:all, :select => "DISTINCT #{Changeset.table_name}.*",
70 :joins => :changes,
78 :joins => :changes,
71 :conditions => ["#{Change.table_name}.path = ? OR #{Change.table_name}.path LIKE ? ESCAPE ?",
79 :conditions => ["#{Change.table_name}.path = ? OR #{Change.table_name}.path LIKE ? ESCAPE ?",
72 path.with_leading_slash,
80 path.with_leading_slash,
73 "#{path.with_leading_slash.gsub(/[%_\\]/) { |s| "\\#{s}" }}/%", '\\'],
81 "#{path.with_leading_slash.gsub(/[%_\\]/) { |s| "\\#{s}" }}/%", '\\'],
74 :include => :user, :limit => limit)
82 :include => :user, :limit => limit)
75 end
83 end
76 end
84 end
77
85
78 def fetch_changesets
86 def fetch_changesets
79 scm_rev = scm.info.lastrev.revision.to_i
87 scm_rev = scm.info.lastrev.revision.to_i
80 db_rev = latest_changeset ? latest_changeset.revision.to_i : -1
88 db_rev = latest_changeset ? latest_changeset.revision.to_i : -1
81 return unless db_rev < scm_rev # already up-to-date
89 return unless db_rev < scm_rev # already up-to-date
82
90
83 logger.debug "Fetching changesets for repository #{url}" if logger
91 logger.debug "Fetching changesets for repository #{url}" if logger
84 (db_rev + 1).step(scm_rev, FETCH_AT_ONCE) do |i|
92 (db_rev + 1).step(scm_rev, FETCH_AT_ONCE) do |i|
85 transaction do
93 transaction do
86 scm.each_revision('', i, [i + FETCH_AT_ONCE - 1, scm_rev].min) do |re|
94 scm.each_revision('', i, [i + FETCH_AT_ONCE - 1, scm_rev].min) do |re|
87 cs = Changeset.create(:repository => self,
95 cs = Changeset.create(:repository => self,
88 :revision => re.revision,
96 :revision => re.revision,
89 :scmid => re.scmid,
97 :scmid => re.scmid,
90 :committer => re.author,
98 :committer => re.author,
91 :committed_on => re.time,
99 :committed_on => re.time,
92 :comments => re.message)
100 :comments => re.message)
93 re.paths.each { |e| cs.create_change(e) }
101 re.paths.each { |e| cs.create_change(e) }
94 end
102 end
95 end
103 end
96 end
104 end
97 self
105 self
98 end
106 end
99 end
107 end
General Comments 0
You need to be logged in to leave comments. Login now