@@ -1,96 +1,99 | |||
|
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 | 47 | def diff_format_revisions(cs, cs_to, sep=':') |
|
48 | 48 | super(cs, cs_to, ' ') |
|
49 | 49 | end |
|
50 | 50 | |
|
51 | 51 | # Finds and returns a revision with a number or the beginning of a hash |
|
52 | 52 | def find_changeset_by_name(name) |
|
53 | 53 | return nil if name.nil? || name.empty? |
|
54 | 54 | if /[^\d]/ =~ name or name.to_s.size > 8 |
|
55 | 55 | e = changesets.find(:first, :conditions => ['scmid = ?', name.to_s]) |
|
56 | 56 | else |
|
57 | 57 | e = changesets.find(:first, :conditions => ['revision = ?', name.to_s]) |
|
58 | 58 | end |
|
59 | 59 | return e if e |
|
60 | 60 | changesets.find(:first, :conditions => ['scmid LIKE ?', "#{name}%"]) # last ditch |
|
61 | 61 | end |
|
62 | 62 | |
|
63 | 63 | # Returns the latest changesets for +path+; sorted by revision number |
|
64 | # Default behavior is to search in cached changesets | |
|
64 | 65 | def latest_changesets(path, rev, limit=10) |
|
65 | 66 | if path.blank? |
|
66 | 67 | changesets.find(:all, :include => :user, :limit => limit) |
|
67 | 68 | else |
|
68 |
changes.find(:all, : |
|
|
69 |
|
|
|
70 |
|
|
|
71 | :limit => limit).collect(&:changeset) | |
|
69 | changesets.find(:all, :select => "DISTINCT #{Changeset.table_name}.*", | |
|
70 | :joins => :changes, | |
|
71 | :conditions => ["#{Change.table_name}.path = ? OR #{Change.table_name}.path LIKE ? ESCAPE ?", | |
|
72 | path.with_leading_slash, | |
|
73 | "#{path.with_leading_slash.gsub(/[%_\\]/) { |s| "\\#{s}" }}/%", '\\'], | |
|
74 | :include => :user, :limit => limit) | |
|
72 | 75 | end |
|
73 | 76 | end |
|
74 | 77 | |
|
75 | 78 | def fetch_changesets |
|
76 | 79 | scm_rev = scm.info.lastrev.revision.to_i |
|
77 | 80 | db_rev = latest_changeset ? latest_changeset.revision.to_i : -1 |
|
78 | 81 | return unless db_rev < scm_rev # already up-to-date |
|
79 | 82 | |
|
80 | 83 | logger.debug "Fetching changesets for repository #{url}" if logger |
|
81 | 84 | (db_rev + 1).step(scm_rev, FETCH_AT_ONCE) do |i| |
|
82 | 85 | transaction do |
|
83 | 86 | scm.each_revision('', i, [i + FETCH_AT_ONCE - 1, scm_rev].min) do |re| |
|
84 | 87 | cs = Changeset.create(:repository => self, |
|
85 | 88 | :revision => re.revision, |
|
86 | 89 | :scmid => re.scmid, |
|
87 | 90 | :committer => re.author, |
|
88 | 91 | :committed_on => re.time, |
|
89 | 92 | :comments => re.message) |
|
90 | 93 | re.paths.each { |e| cs.create_change(e) } |
|
91 | 94 | end |
|
92 | 95 | end |
|
93 | 96 | end |
|
94 | 97 | self |
|
95 | 98 | end |
|
96 | 99 | end |
General Comments 0
You need to be logged in to leave comments.
Login now