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