##// END OF EJS Templates
scm: mercurial: use 12 chars id for format_changeset_identifier (#14361)...
Toshi MARUYAMA -
r12474:5dcecec1bd8a
parent child
Show More
@@ -1,159 +1,159
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
2 # Copyright (C) 2006-2014 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,
22 has_many :changesets,
23 :order => "#{Changeset.table_name}.id DESC",
23 :order => "#{Changeset.table_name}.id DESC",
24 :foreign_key => 'repository_id'
24 :foreign_key => 'repository_id'
25
25
26 attr_protected :root_url
26 attr_protected :root_url
27 validates_presence_of :url
27 validates_presence_of :url
28
28
29 # number of changesets to fetch at once
29 # number of changesets to fetch at once
30 FETCH_AT_ONCE = 100
30 FETCH_AT_ONCE = 100
31
31
32 def self.human_attribute_name(attribute_key_name, *args)
32 def self.human_attribute_name(attribute_key_name, *args)
33 attr_name = attribute_key_name.to_s
33 attr_name = attribute_key_name.to_s
34 if attr_name == "url"
34 if attr_name == "url"
35 attr_name = "path_to_repository"
35 attr_name = "path_to_repository"
36 end
36 end
37 super(attr_name, *args)
37 super(attr_name, *args)
38 end
38 end
39
39
40 def self.scm_adapter_class
40 def self.scm_adapter_class
41 Redmine::Scm::Adapters::MercurialAdapter
41 Redmine::Scm::Adapters::MercurialAdapter
42 end
42 end
43
43
44 def self.scm_name
44 def self.scm_name
45 'Mercurial'
45 'Mercurial'
46 end
46 end
47
47
48 def supports_directory_revisions?
48 def supports_directory_revisions?
49 true
49 true
50 end
50 end
51
51
52 def supports_revision_graph?
52 def supports_revision_graph?
53 true
53 true
54 end
54 end
55
55
56 def repo_log_encoding
56 def repo_log_encoding
57 'UTF-8'
57 'UTF-8'
58 end
58 end
59
59
60 # Returns the readable identifier for the given mercurial changeset
60 # Returns the readable identifier for the given mercurial changeset
61 def self.format_changeset_identifier(changeset)
61 def self.format_changeset_identifier(changeset)
62 "#{changeset.revision}:#{changeset.scmid}"
62 "#{changeset.revision}:#{changeset.scmid[0, 12]}"
63 end
63 end
64
64
65 # Returns the identifier for the given Mercurial changeset
65 # Returns the identifier for the given Mercurial changeset
66 def self.changeset_identifier(changeset)
66 def self.changeset_identifier(changeset)
67 changeset.scmid
67 changeset.scmid
68 end
68 end
69
69
70 def diff_format_revisions(cs, cs_to, sep=':')
70 def diff_format_revisions(cs, cs_to, sep=':')
71 super(cs, cs_to, ' ')
71 super(cs, cs_to, ' ')
72 end
72 end
73
73
74 # Finds and returns a revision with a number or the beginning of a hash
74 # Finds and returns a revision with a number or the beginning of a hash
75 def find_changeset_by_name(name)
75 def find_changeset_by_name(name)
76 return nil if name.blank?
76 return nil if name.blank?
77 s = name.to_s
77 s = name.to_s
78 if /[^\d]/ =~ s or s.size > 8
78 if /[^\d]/ =~ s or s.size > 8
79 cs = changesets.where(:scmid => s).first
79 cs = changesets.where(:scmid => s).first
80 else
80 else
81 cs = changesets.where(:revision => s).first
81 cs = changesets.where(:revision => s).first
82 end
82 end
83 return cs if cs
83 return cs if cs
84 changesets.where('scmid LIKE ?', "#{s}%").first
84 changesets.where('scmid LIKE ?', "#{s}%").first
85 end
85 end
86
86
87 # Returns the latest changesets for +path+; sorted by revision number
87 # Returns the latest changesets for +path+; sorted by revision number
88 #
88 #
89 # Because :order => 'id DESC' is defined at 'has_many',
89 # Because :order => 'id DESC' is defined at 'has_many',
90 # there is no need to set 'order'.
90 # there is no need to set 'order'.
91 # But, MySQL test fails.
91 # But, MySQL test fails.
92 # Sqlite3 and PostgreSQL pass.
92 # Sqlite3 and PostgreSQL pass.
93 # Is this MySQL bug?
93 # Is this MySQL bug?
94 def latest_changesets(path, rev, limit=10)
94 def latest_changesets(path, rev, limit=10)
95 changesets.
95 changesets.
96 includes(:user).
96 includes(:user).
97 where(latest_changesets_cond(path, rev, limit)).
97 where(latest_changesets_cond(path, rev, limit)).
98 limit(limit).
98 limit(limit).
99 order("#{Changeset.table_name}.id DESC").
99 order("#{Changeset.table_name}.id DESC").
100 all
100 all
101 end
101 end
102
102
103 def latest_changesets_cond(path, rev, limit)
103 def latest_changesets_cond(path, rev, limit)
104 cond, args = [], []
104 cond, args = [], []
105 if scm.branchmap.member? rev
105 if scm.branchmap.member? rev
106 # Mercurial named branch is *stable* in each revision.
106 # Mercurial named branch is *stable* in each revision.
107 # So, named branch can be stored in database.
107 # So, named branch can be stored in database.
108 # Mercurial provides *bookmark* which is equivalent with git branch.
108 # Mercurial provides *bookmark* which is equivalent with git branch.
109 # But, bookmark is not implemented.
109 # But, bookmark is not implemented.
110 cond << "#{Changeset.table_name}.scmid IN (?)"
110 cond << "#{Changeset.table_name}.scmid IN (?)"
111 # Revisions in root directory and sub directory are not equal.
111 # Revisions in root directory and sub directory are not equal.
112 # So, in order to get correct limit, we need to get all revisions.
112 # So, in order to get correct limit, we need to get all revisions.
113 # But, it is very heavy.
113 # But, it is very heavy.
114 # Mercurial does not treat direcotry.
114 # Mercurial does not treat direcotry.
115 # So, "hg log DIR" is very heavy.
115 # So, "hg log DIR" is very heavy.
116 branch_limit = path.blank? ? limit : ( limit * 5 )
116 branch_limit = path.blank? ? limit : ( limit * 5 )
117 args << scm.nodes_in_branch(rev, :limit => branch_limit)
117 args << scm.nodes_in_branch(rev, :limit => branch_limit)
118 elsif last = rev ? find_changeset_by_name(scm.tagmap[rev] || rev) : nil
118 elsif last = rev ? find_changeset_by_name(scm.tagmap[rev] || rev) : nil
119 cond << "#{Changeset.table_name}.id <= ?"
119 cond << "#{Changeset.table_name}.id <= ?"
120 args << last.id
120 args << last.id
121 end
121 end
122 unless path.blank?
122 unless path.blank?
123 cond << "EXISTS (SELECT * FROM #{Change.table_name}
123 cond << "EXISTS (SELECT * FROM #{Change.table_name}
124 WHERE #{Change.table_name}.changeset_id = #{Changeset.table_name}.id
124 WHERE #{Change.table_name}.changeset_id = #{Changeset.table_name}.id
125 AND (#{Change.table_name}.path = ?
125 AND (#{Change.table_name}.path = ?
126 OR #{Change.table_name}.path LIKE ? ESCAPE ?))"
126 OR #{Change.table_name}.path LIKE ? ESCAPE ?))"
127 args << path.with_leading_slash
127 args << path.with_leading_slash
128 args << "#{path.with_leading_slash.gsub(%r{[%_\\]}) { |s| "\\#{s}" }}/%" << '\\'
128 args << "#{path.with_leading_slash.gsub(%r{[%_\\]}) { |s| "\\#{s}" }}/%" << '\\'
129 end
129 end
130 [cond.join(' AND '), *args] unless cond.empty?
130 [cond.join(' AND '), *args] unless cond.empty?
131 end
131 end
132 private :latest_changesets_cond
132 private :latest_changesets_cond
133
133
134 def fetch_changesets
134 def fetch_changesets
135 return if scm.info.nil?
135 return if scm.info.nil?
136 scm_rev = scm.info.lastrev.revision.to_i
136 scm_rev = scm.info.lastrev.revision.to_i
137 db_rev = latest_changeset ? latest_changeset.revision.to_i : -1
137 db_rev = latest_changeset ? latest_changeset.revision.to_i : -1
138 return unless db_rev < scm_rev # already up-to-date
138 return unless db_rev < scm_rev # already up-to-date
139
139
140 logger.debug "Fetching changesets for repository #{url}" if logger
140 logger.debug "Fetching changesets for repository #{url}" if logger
141 (db_rev + 1).step(scm_rev, FETCH_AT_ONCE) do |i|
141 (db_rev + 1).step(scm_rev, FETCH_AT_ONCE) do |i|
142 scm.each_revision('', i, [i + FETCH_AT_ONCE - 1, scm_rev].min) do |re|
142 scm.each_revision('', i, [i + FETCH_AT_ONCE - 1, scm_rev].min) do |re|
143 transaction do
143 transaction do
144 parents = (re.parents || []).collect{|rp| find_changeset_by_name(rp)}.compact
144 parents = (re.parents || []).collect{|rp| find_changeset_by_name(rp)}.compact
145 cs = Changeset.create(:repository => self,
145 cs = Changeset.create(:repository => self,
146 :revision => re.revision,
146 :revision => re.revision,
147 :scmid => re.scmid,
147 :scmid => re.scmid,
148 :committer => re.author,
148 :committer => re.author,
149 :committed_on => re.time,
149 :committed_on => re.time,
150 :comments => re.message,
150 :comments => re.message,
151 :parents => parents)
151 :parents => parents)
152 unless cs.new_record?
152 unless cs.new_record?
153 re.paths.each { |e| cs.create_change(e) }
153 re.paths.each { |e| cs.create_change(e) }
154 end
154 end
155 end
155 end
156 end
156 end
157 end
157 end
158 end
158 end
159 end
159 end
@@ -1,389 +1,400
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
2 # Copyright (C) 2006-2014 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 File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class RepositoryMercurialTest < ActiveSupport::TestCase
20 class RepositoryMercurialTest < ActiveSupport::TestCase
21 fixtures :projects
21 fixtures :projects
22
22
23 include Redmine::I18n
23 include Redmine::I18n
24
24
25 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
25 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
26 NUM_REV = 32
26 NUM_REV = 32
27 CHAR_1_HEX = "\xc3\x9c"
27 CHAR_1_HEX = "\xc3\x9c"
28
28
29 def setup
29 def setup
30 @project = Project.find(3)
30 @project = Project.find(3)
31 @repository = Repository::Mercurial.create(
31 @repository = Repository::Mercurial.create(
32 :project => @project,
32 :project => @project,
33 :url => REPOSITORY_PATH,
33 :url => REPOSITORY_PATH,
34 :path_encoding => 'ISO-8859-1'
34 :path_encoding => 'ISO-8859-1'
35 )
35 )
36 assert @repository
36 assert @repository
37 @char_1 = CHAR_1_HEX.dup
37 @char_1 = CHAR_1_HEX.dup
38 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
38 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
39 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
39 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
40 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
40 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
41 if @char_1.respond_to?(:force_encoding)
41 if @char_1.respond_to?(:force_encoding)
42 @char_1.force_encoding('UTF-8')
42 @char_1.force_encoding('UTF-8')
43 @tag_char_1.force_encoding('UTF-8')
43 @tag_char_1.force_encoding('UTF-8')
44 @branch_char_0.force_encoding('UTF-8')
44 @branch_char_0.force_encoding('UTF-8')
45 @branch_char_1.force_encoding('UTF-8')
45 @branch_char_1.force_encoding('UTF-8')
46 end
46 end
47 end
47 end
48
48
49 def test_blank_path_to_repository_error_message
49 def test_blank_path_to_repository_error_message
50 set_language_if_valid 'en'
50 set_language_if_valid 'en'
51 repo = Repository::Mercurial.new(
51 repo = Repository::Mercurial.new(
52 :project => @project,
52 :project => @project,
53 :identifier => 'test'
53 :identifier => 'test'
54 )
54 )
55 assert !repo.save
55 assert !repo.save
56 assert_include "Path to repository can't be blank",
56 assert_include "Path to repository can't be blank",
57 repo.errors.full_messages
57 repo.errors.full_messages
58 end
58 end
59
59
60 def test_blank_path_to_repository_error_message_fr
60 def test_blank_path_to_repository_error_message_fr
61 set_language_if_valid 'fr'
61 set_language_if_valid 'fr'
62 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
62 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
63 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
63 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
64 repo = Repository::Mercurial.new(
64 repo = Repository::Mercurial.new(
65 :project => @project,
65 :project => @project,
66 :url => "",
66 :url => "",
67 :identifier => 'test',
67 :identifier => 'test',
68 :path_encoding => ''
68 :path_encoding => ''
69 )
69 )
70 assert !repo.save
70 assert !repo.save
71 assert_include str, repo.errors.full_messages
71 assert_include str, repo.errors.full_messages
72 end
72 end
73
73
74 if File.directory?(REPOSITORY_PATH)
74 if File.directory?(REPOSITORY_PATH)
75 def test_scm_available
75 def test_scm_available
76 klass = Repository::Mercurial
76 klass = Repository::Mercurial
77 assert_equal "Mercurial", klass.scm_name
77 assert_equal "Mercurial", klass.scm_name
78 assert klass.scm_adapter_class
78 assert klass.scm_adapter_class
79 assert_not_equal "", klass.scm_command
79 assert_not_equal "", klass.scm_command
80 assert_equal true, klass.scm_available
80 assert_equal true, klass.scm_available
81 end
81 end
82
82
83 def test_entries
83 def test_entries
84 entries = @repository.entries
84 entries = @repository.entries
85 assert_kind_of Redmine::Scm::Adapters::Entries, entries
85 assert_kind_of Redmine::Scm::Adapters::Entries, entries
86 end
86 end
87
87
88 def test_fetch_changesets_from_scratch
88 def test_fetch_changesets_from_scratch
89 assert_equal 0, @repository.changesets.count
89 assert_equal 0, @repository.changesets.count
90 @repository.fetch_changesets
90 @repository.fetch_changesets
91 @project.reload
91 @project.reload
92 assert_equal NUM_REV, @repository.changesets.count
92 assert_equal NUM_REV, @repository.changesets.count
93 assert_equal 46, @repository.filechanges.count
93 assert_equal 46, @repository.filechanges.count
94 assert_equal "Initial import.\nThe repository contains 3 files.",
94 assert_equal "Initial import.\nThe repository contains 3 files.",
95 @repository.changesets.find_by_revision('0').comments
95 @repository.changesets.find_by_revision('0').comments
96 end
96 end
97
97
98 def test_fetch_changesets_incremental
98 def test_fetch_changesets_incremental
99 assert_equal 0, @repository.changesets.count
99 assert_equal 0, @repository.changesets.count
100 @repository.fetch_changesets
100 @repository.fetch_changesets
101 @project.reload
101 @project.reload
102 assert_equal NUM_REV, @repository.changesets.count
102 assert_equal NUM_REV, @repository.changesets.count
103 # Remove changesets with revision > 2
103 # Remove changesets with revision > 2
104 @repository.changesets.each {|c| c.destroy if c.revision.to_i > 2}
104 @repository.changesets.each {|c| c.destroy if c.revision.to_i > 2}
105 @project.reload
105 @project.reload
106 @repository.reload
106 @repository.reload
107 assert_equal 3, @repository.changesets.count
107 assert_equal 3, @repository.changesets.count
108
108
109 @repository.fetch_changesets
109 @repository.fetch_changesets
110 @project.reload
110 @project.reload
111 assert_equal NUM_REV, @repository.changesets.count
111 assert_equal NUM_REV, @repository.changesets.count
112 end
112 end
113
113
114 def test_isodatesec
114 def test_isodatesec
115 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
115 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
116 if @repository.scm.class.client_version_above?([1, 0])
116 if @repository.scm.class.client_version_above?([1, 0])
117 assert_equal 0, @repository.changesets.count
117 assert_equal 0, @repository.changesets.count
118 @repository.fetch_changesets
118 @repository.fetch_changesets
119 @project.reload
119 @project.reload
120 assert_equal NUM_REV, @repository.changesets.count
120 assert_equal NUM_REV, @repository.changesets.count
121 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
121 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
122 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
122 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
123 end
123 end
124 end
124 end
125
125
126 def test_changeset_order_by_revision
126 def test_changeset_order_by_revision
127 assert_equal 0, @repository.changesets.count
127 assert_equal 0, @repository.changesets.count
128 @repository.fetch_changesets
128 @repository.fetch_changesets
129 @project.reload
129 @project.reload
130 assert_equal NUM_REV, @repository.changesets.count
130 assert_equal NUM_REV, @repository.changesets.count
131
131
132 c0 = @repository.latest_changeset
132 c0 = @repository.latest_changeset
133 c1 = @repository.changesets.find_by_revision('0')
133 c1 = @repository.changesets.find_by_revision('0')
134 # sorted by revision (id), not by date
134 # sorted by revision (id), not by date
135 assert c0.revision.to_i > c1.revision.to_i
135 assert c0.revision.to_i > c1.revision.to_i
136 assert c0.committed_on < c1.committed_on
136 assert c0.committed_on < c1.committed_on
137 end
137 end
138
138
139 def test_latest_changesets
139 def test_latest_changesets
140 assert_equal 0, @repository.changesets.count
140 assert_equal 0, @repository.changesets.count
141 @repository.fetch_changesets
141 @repository.fetch_changesets
142 @project.reload
142 @project.reload
143 assert_equal NUM_REV, @repository.changesets.count
143 assert_equal NUM_REV, @repository.changesets.count
144
144
145 # with_limit
145 # with_limit
146 changesets = @repository.latest_changesets('', nil, 2)
146 changesets = @repository.latest_changesets('', nil, 2)
147 assert_equal %w|31 30|, changesets.collect(&:revision)
147 assert_equal %w|31 30|, changesets.collect(&:revision)
148
148
149 # with_filepath
149 # with_filepath
150 changesets = @repository.latest_changesets(
150 changesets = @repository.latest_changesets(
151 '/sql_escape/percent%dir/percent%file1.txt', nil)
151 '/sql_escape/percent%dir/percent%file1.txt', nil)
152 assert_equal %w|30 11 10 9|, changesets.collect(&:revision)
152 assert_equal %w|30 11 10 9|, changesets.collect(&:revision)
153
153
154 changesets = @repository.latest_changesets(
154 changesets = @repository.latest_changesets(
155 '/sql_escape/underscore_dir/understrike_file.txt', nil)
155 '/sql_escape/underscore_dir/understrike_file.txt', nil)
156 assert_equal %w|30 12 9|, changesets.collect(&:revision)
156 assert_equal %w|30 12 9|, changesets.collect(&:revision)
157
157
158 changesets = @repository.latest_changesets('README', nil)
158 changesets = @repository.latest_changesets('README', nil)
159 assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision)
159 assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision)
160
160
161 changesets = @repository.latest_changesets('README','8')
161 changesets = @repository.latest_changesets('README','8')
162 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
162 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
163
163
164 changesets = @repository.latest_changesets('README','8', 2)
164 changesets = @repository.latest_changesets('README','8', 2)
165 assert_equal %w|8 6|, changesets.collect(&:revision)
165 assert_equal %w|8 6|, changesets.collect(&:revision)
166
166
167 # with_dirpath
167 # with_dirpath
168 changesets = @repository.latest_changesets('images', nil)
168 changesets = @repository.latest_changesets('images', nil)
169 assert_equal %w|1 0|, changesets.collect(&:revision)
169 assert_equal %w|1 0|, changesets.collect(&:revision)
170
170
171 path = 'sql_escape/percent%dir'
171 path = 'sql_escape/percent%dir'
172 changesets = @repository.latest_changesets(path, nil)
172 changesets = @repository.latest_changesets(path, nil)
173 assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision)
173 assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision)
174
174
175 changesets = @repository.latest_changesets(path, '11')
175 changesets = @repository.latest_changesets(path, '11')
176 assert_equal %w|11 10 9|, changesets.collect(&:revision)
176 assert_equal %w|11 10 9|, changesets.collect(&:revision)
177
177
178 changesets = @repository.latest_changesets(path, '11', 2)
178 changesets = @repository.latest_changesets(path, '11', 2)
179 assert_equal %w|11 10|, changesets.collect(&:revision)
179 assert_equal %w|11 10|, changesets.collect(&:revision)
180
180
181 path = 'sql_escape/underscore_dir'
181 path = 'sql_escape/underscore_dir'
182 changesets = @repository.latest_changesets(path, nil)
182 changesets = @repository.latest_changesets(path, nil)
183 assert_equal %w|30 13 12 9|, changesets.collect(&:revision)
183 assert_equal %w|30 13 12 9|, changesets.collect(&:revision)
184
184
185 changesets = @repository.latest_changesets(path, '12')
185 changesets = @repository.latest_changesets(path, '12')
186 assert_equal %w|12 9|, changesets.collect(&:revision)
186 assert_equal %w|12 9|, changesets.collect(&:revision)
187
187
188 changesets = @repository.latest_changesets(path, '12', 1)
188 changesets = @repository.latest_changesets(path, '12', 1)
189 assert_equal %w|12|, changesets.collect(&:revision)
189 assert_equal %w|12|, changesets.collect(&:revision)
190 end
190 end
191
191
192 def test_latest_changesets_tag
192 def test_latest_changesets_tag
193 assert_equal 0, @repository.changesets.count
193 assert_equal 0, @repository.changesets.count
194 @repository.fetch_changesets
194 @repository.fetch_changesets
195 @project.reload
195 @project.reload
196 assert_equal NUM_REV, @repository.changesets.count
196 assert_equal NUM_REV, @repository.changesets.count
197
197
198 changesets = @repository.latest_changesets('', 'tag_test.00')
198 changesets = @repository.latest_changesets('', 'tag_test.00')
199 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
199 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
200
200
201 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
201 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
202 assert_equal %w|5 4|, changesets.collect(&:revision)
202 assert_equal %w|5 4|, changesets.collect(&:revision)
203
203
204 changesets = @repository.latest_changesets('sources', 'tag_test.00')
204 changesets = @repository.latest_changesets('sources', 'tag_test.00')
205 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
205 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
206
206
207 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
207 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
208 assert_equal %w|4 3|, changesets.collect(&:revision)
208 assert_equal %w|4 3|, changesets.collect(&:revision)
209 end
209 end
210
210
211 def test_latest_changesets_branch
211 def test_latest_changesets_branch
212 assert_equal 0, @repository.changesets.count
212 assert_equal 0, @repository.changesets.count
213 @repository.fetch_changesets
213 @repository.fetch_changesets
214 @project.reload
214 @project.reload
215 assert_equal NUM_REV, @repository.changesets.count
215 assert_equal NUM_REV, @repository.changesets.count
216
216
217 if @repository.scm.class.client_version_above?([1, 6])
217 if @repository.scm.class.client_version_above?([1, 6])
218 changesets = @repository.latest_changesets('', @branch_char_1)
218 changesets = @repository.latest_changesets('', @branch_char_1)
219 assert_equal %w|27 26|, changesets.collect(&:revision)
219 assert_equal %w|27 26|, changesets.collect(&:revision)
220 end
220 end
221
221
222 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
222 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
223 assert_equal %w|27|, changesets.collect(&:revision)
223 assert_equal %w|27|, changesets.collect(&:revision)
224 end
224 end
225
225
226 def test_copied_files
226 def test_copied_files
227 assert_equal 0, @repository.changesets.count
227 assert_equal 0, @repository.changesets.count
228 @repository.fetch_changesets
228 @repository.fetch_changesets
229 @project.reload
229 @project.reload
230 assert_equal NUM_REV, @repository.changesets.count
230 assert_equal NUM_REV, @repository.changesets.count
231
231
232 cs1 = @repository.changesets.find_by_revision('13')
232 cs1 = @repository.changesets.find_by_revision('13')
233 assert_not_nil cs1
233 assert_not_nil cs1
234 c1 = cs1.filechanges.sort_by(&:path)
234 c1 = cs1.filechanges.sort_by(&:path)
235 assert_equal 2, c1.size
235 assert_equal 2, c1.size
236
236
237 assert_equal 'A', c1[0].action
237 assert_equal 'A', c1[0].action
238 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
238 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
239 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
239 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
240 assert_equal '3a330eb32958', c1[0].from_revision
240 assert_equal '3a330eb32958', c1[0].from_revision
241
241
242 assert_equal 'A', c1[1].action
242 assert_equal 'A', c1[1].action
243 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
243 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
244 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
244 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
245
245
246 cs2 = @repository.changesets.find_by_revision('15')
246 cs2 = @repository.changesets.find_by_revision('15')
247 c2 = cs2.filechanges
247 c2 = cs2.filechanges
248 assert_equal 1, c2.size
248 assert_equal 1, c2.size
249
249
250 assert_equal 'A', c2[0].action
250 assert_equal 'A', c2[0].action
251 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
251 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
252 assert_equal '/README', c2[0].from_path
252 assert_equal '/README', c2[0].from_path
253 assert_equal '933ca60293d7', c2[0].from_revision
253 assert_equal '933ca60293d7', c2[0].from_revision
254
254
255 cs3 = @repository.changesets.find_by_revision('19')
255 cs3 = @repository.changesets.find_by_revision('19')
256 c3 = cs3.filechanges
256 c3 = cs3.filechanges
257 assert_equal 1, c3.size
257 assert_equal 1, c3.size
258 assert_equal 'A', c3[0].action
258 assert_equal 'A', c3[0].action
259 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
259 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
260 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
260 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
261 assert_equal '5d9891a1b425', c3[0].from_revision
261 assert_equal '5d9891a1b425', c3[0].from_revision
262 end
262 end
263
263
264 def test_find_changeset_by_name
264 def test_find_changeset_by_name
265 assert_equal 0, @repository.changesets.count
265 assert_equal 0, @repository.changesets.count
266 @repository.fetch_changesets
266 @repository.fetch_changesets
267 @project.reload
267 @project.reload
268 assert_equal NUM_REV, @repository.changesets.count
268 assert_equal NUM_REV, @repository.changesets.count
269 %w|2 400bb8672109 400|.each do |r|
269 %w|2 400bb8672109 400|.each do |r|
270 assert_equal '2', @repository.find_changeset_by_name(r).revision
270 assert_equal '2', @repository.find_changeset_by_name(r).revision
271 end
271 end
272 end
272 end
273
273
274 def test_find_changeset_by_invalid_name
274 def test_find_changeset_by_invalid_name
275 assert_equal 0, @repository.changesets.count
275 assert_equal 0, @repository.changesets.count
276 @repository.fetch_changesets
276 @repository.fetch_changesets
277 @project.reload
277 @project.reload
278 assert_equal NUM_REV, @repository.changesets.count
278 assert_equal NUM_REV, @repository.changesets.count
279 assert_nil @repository.find_changeset_by_name('100000')
279 assert_nil @repository.find_changeset_by_name('100000')
280 end
280 end
281
281
282 def test_identifier
282 def test_identifier
283 assert_equal 0, @repository.changesets.count
283 assert_equal 0, @repository.changesets.count
284 @repository.fetch_changesets
284 @repository.fetch_changesets
285 @project.reload
285 @project.reload
286 assert_equal NUM_REV, @repository.changesets.count
286 assert_equal NUM_REV, @repository.changesets.count
287 c = @repository.changesets.find_by_revision('2')
287 c = @repository.changesets.find_by_revision('2')
288 assert_equal c.scmid, c.identifier
288 assert_equal c.scmid, c.identifier
289 end
289 end
290
290
291 def test_format_identifier
291 def test_format_identifier
292 assert_equal 0, @repository.changesets.count
292 assert_equal 0, @repository.changesets.count
293 @repository.fetch_changesets
293 @repository.fetch_changesets
294 @project.reload
294 @project.reload
295 assert_equal NUM_REV, @repository.changesets.count
295 assert_equal NUM_REV, @repository.changesets.count
296 c = @repository.changesets.find_by_revision('2')
296 c = @repository.changesets.find_by_revision('2')
297 assert_equal '2:400bb8672109', c.format_identifier
297 assert_equal '2:400bb8672109', c.format_identifier
298 end
298 end
299
299
300 def test_format_identifier_long_id
301 assert_equal 0, @repository.changesets.count
302 Changeset.create!(:repository => @repository,
303 :committed_on => Time.now,
304 :revision => '0',
305 :scmid => '0885933ad4f68d77c2649cd11f8311276e7ef7ce',
306 :comments => 'test')
307 c = @repository.changesets.find_by_revision('0')
308 assert_equal '0:0885933ad4f6', c.format_identifier
309 end
310
300 def test_find_changeset_by_empty_name
311 def test_find_changeset_by_empty_name
301 assert_equal 0, @repository.changesets.count
312 assert_equal 0, @repository.changesets.count
302 @repository.fetch_changesets
313 @repository.fetch_changesets
303 @project.reload
314 @project.reload
304 assert_equal NUM_REV, @repository.changesets.count
315 assert_equal NUM_REV, @repository.changesets.count
305 ['', ' ', nil].each do |r|
316 ['', ' ', nil].each do |r|
306 assert_nil @repository.find_changeset_by_name(r)
317 assert_nil @repository.find_changeset_by_name(r)
307 end
318 end
308 end
319 end
309
320
310 def test_parents
321 def test_parents
311 assert_equal 0, @repository.changesets.count
322 assert_equal 0, @repository.changesets.count
312 @repository.fetch_changesets
323 @repository.fetch_changesets
313 @project.reload
324 @project.reload
314 assert_equal NUM_REV, @repository.changesets.count
325 assert_equal NUM_REV, @repository.changesets.count
315 r1 = @repository.changesets.find_by_revision('0')
326 r1 = @repository.changesets.find_by_revision('0')
316 assert_equal [], r1.parents
327 assert_equal [], r1.parents
317 r2 = @repository.changesets.find_by_revision('1')
328 r2 = @repository.changesets.find_by_revision('1')
318 assert_equal 1, r2.parents.length
329 assert_equal 1, r2.parents.length
319 assert_equal "0885933ad4f6",
330 assert_equal "0885933ad4f6",
320 r2.parents[0].identifier
331 r2.parents[0].identifier
321 r3 = @repository.changesets.find_by_revision('30')
332 r3 = @repository.changesets.find_by_revision('30')
322 assert_equal 2, r3.parents.length
333 assert_equal 2, r3.parents.length
323 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
334 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
324 assert_equal "3a330eb32958", r4[0]
335 assert_equal "3a330eb32958", r4[0]
325 assert_equal "a94b0528f24f", r4[1]
336 assert_equal "a94b0528f24f", r4[1]
326 end
337 end
327
338
328 def test_activities
339 def test_activities
329 c = Changeset.new(:repository => @repository,
340 c = Changeset.new(:repository => @repository,
330 :committed_on => Time.now,
341 :committed_on => Time.now,
331 :revision => '123',
342 :revision => '123',
332 :scmid => 'abc400bb8672',
343 :scmid => 'abc400bb8672',
333 :comments => 'test')
344 :comments => 'test')
334 assert c.event_title.include?('123:abc400bb8672:')
345 assert c.event_title.include?('123:abc400bb8672:')
335 assert_equal 'abc400bb8672', c.event_url[:rev]
346 assert_equal 'abc400bb8672', c.event_url[:rev]
336 end
347 end
337
348
338 def test_previous
349 def test_previous
339 assert_equal 0, @repository.changesets.count
350 assert_equal 0, @repository.changesets.count
340 @repository.fetch_changesets
351 @repository.fetch_changesets
341 @project.reload
352 @project.reload
342 assert_equal NUM_REV, @repository.changesets.count
353 assert_equal NUM_REV, @repository.changesets.count
343 %w|28 3ae45e2d177d 3ae45|.each do |r1|
354 %w|28 3ae45e2d177d 3ae45|.each do |r1|
344 changeset = @repository.find_changeset_by_name(r1)
355 changeset = @repository.find_changeset_by_name(r1)
345 %w|27 7bbf4c738e71 7bbf|.each do |r2|
356 %w|27 7bbf4c738e71 7bbf|.each do |r2|
346 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
357 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
347 end
358 end
348 end
359 end
349 end
360 end
350
361
351 def test_previous_nil
362 def test_previous_nil
352 assert_equal 0, @repository.changesets.count
363 assert_equal 0, @repository.changesets.count
353 @repository.fetch_changesets
364 @repository.fetch_changesets
354 @project.reload
365 @project.reload
355 assert_equal NUM_REV, @repository.changesets.count
366 assert_equal NUM_REV, @repository.changesets.count
356 %w|0 0885933ad4f6 0885|.each do |r1|
367 %w|0 0885933ad4f6 0885|.each do |r1|
357 changeset = @repository.find_changeset_by_name(r1)
368 changeset = @repository.find_changeset_by_name(r1)
358 assert_nil changeset.previous
369 assert_nil changeset.previous
359 end
370 end
360 end
371 end
361
372
362 def test_next
373 def test_next
363 assert_equal 0, @repository.changesets.count
374 assert_equal 0, @repository.changesets.count
364 @repository.fetch_changesets
375 @repository.fetch_changesets
365 @project.reload
376 @project.reload
366 assert_equal NUM_REV, @repository.changesets.count
377 assert_equal NUM_REV, @repository.changesets.count
367 %w|27 7bbf4c738e71 7bbf|.each do |r2|
378 %w|27 7bbf4c738e71 7bbf|.each do |r2|
368 changeset = @repository.find_changeset_by_name(r2)
379 changeset = @repository.find_changeset_by_name(r2)
369 %w|28 3ae45e2d177d 3ae45|.each do |r1|
380 %w|28 3ae45e2d177d 3ae45|.each do |r1|
370 assert_equal @repository.find_changeset_by_name(r1), changeset.next
381 assert_equal @repository.find_changeset_by_name(r1), changeset.next
371 end
382 end
372 end
383 end
373 end
384 end
374
385
375 def test_next_nil
386 def test_next_nil
376 assert_equal 0, @repository.changesets.count
387 assert_equal 0, @repository.changesets.count
377 @repository.fetch_changesets
388 @repository.fetch_changesets
378 @project.reload
389 @project.reload
379 assert_equal NUM_REV, @repository.changesets.count
390 assert_equal NUM_REV, @repository.changesets.count
380 %w|31 31eeee7395c8 31eee|.each do |r1|
391 %w|31 31eeee7395c8 31eee|.each do |r1|
381 changeset = @repository.find_changeset_by_name(r1)
392 changeset = @repository.find_changeset_by_name(r1)
382 assert_nil changeset.next
393 assert_nil changeset.next
383 end
394 end
384 end
395 end
385 else
396 else
386 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
397 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
387 def test_fake; assert true end
398 def test_fake; assert true end
388 end
399 end
389 end
400 end
General Comments 0
You need to be logged in to leave comments. Login now