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