Skip to content

Commit 9d79740

Browse files
author
Toshi MARUYAMA
committed
mercurial: work around faulty parsing of early command options (#27516)
Use -sVALUE and --long=VALUE instead of "-s VALUE" and "--long VALUE" respectively. Contributed by Yuya Nishihara. git-svn-id: http://svn.redmine.org/redmine/trunk@17062 e93f8b46-1217-0410-a6f0-8f06a7374b81
1 parent 58ed865 commit 9d79740

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

Diff for: lib/redmine/scm/adapters/mercurial_adapter.rb

+14-13
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def summary
140140

141141
def entries(path=nil, identifier=nil, options={})
142142
p1 = scm_iconv(@path_encoding, 'UTF-8', path)
143-
manifest = hg('rhmanifest', '-r', CGI.escape(hgrev(identifier)),
143+
manifest = hg('rhmanifest', "-r#{CGI.escape(hgrev(identifier))}",
144144
'--', CGI.escape(without_leading_slash(p1.to_s))) do |io|
145145
output = io.read.force_encoding('UTF-8')
146146
begin
@@ -181,9 +181,9 @@ def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
181181
# Iterates the revisions by using a template file that
182182
# makes Mercurial produce a xml output.
183183
def each_revision(path=nil, identifier_from=nil, identifier_to=nil, options={})
184-
hg_args = ['log', '--debug', '-C', '--style', self.class.template_path]
185-
hg_args << '-r' << "#{hgrev(identifier_from)}:#{hgrev(identifier_to)}"
186-
hg_args << '--limit' << options[:limit] if options[:limit]
184+
hg_args = ['log', '--debug', '-C', "--style=#{self.class.template_path}"]
185+
hg_args << "-r#{hgrev(identifier_from)}:#{hgrev(identifier_to)}"
186+
hg_args << "--limit=#{options[:limit]}" if options[:limit]
187187
hg_args << '--' << hgtarget(path) unless path.blank?
188188
log = hg(*hg_args) do |io|
189189
output = io.read.force_encoding('UTF-8')
@@ -224,19 +224,19 @@ def each_revision(path=nil, identifier_from=nil, identifier_to=nil, options={})
224224

225225
# Returns list of nodes in the specified branch
226226
def nodes_in_branch(branch, options={})
227-
hg_args = ['rhlog', '--template', '{node}\n', '--rhbranch', CGI.escape(branch)]
228-
hg_args << '--from' << CGI.escape(branch)
229-
hg_args << '--to' << '0'
230-
hg_args << '--limit' << options[:limit] if options[:limit]
227+
hg_args = ['rhlog', '--template={node}\n', "--rhbranch=#{CGI.escape(branch)}"]
228+
hg_args << "--from=#{CGI.escape(branch)}"
229+
hg_args << '--to=0'
230+
hg_args << "--limit=#{options[:limit]}" if options[:limit]
231231
hg(*hg_args) { |io| io.readlines.map { |e| e.chomp } }
232232
end
233233

234234
def diff(path, identifier_from, identifier_to=nil)
235235
hg_args = %w|rhdiff|
236236
if identifier_to
237-
hg_args << '-r' << hgrev(identifier_to) << '-r' << hgrev(identifier_from)
237+
hg_args << "-r#{hgrev(identifier_to)}" << "-r#{hgrev(identifier_from)}"
238238
else
239-
hg_args << '-c' << hgrev(identifier_from)
239+
hg_args << "-c#{hgrev(identifier_from)}"
240240
end
241241
unless path.blank?
242242
p = scm_iconv(@path_encoding, 'UTF-8', path)
@@ -255,7 +255,7 @@ def diff(path, identifier_from, identifier_to=nil)
255255

256256
def cat(path, identifier=nil)
257257
p = CGI.escape(scm_iconv(@path_encoding, 'UTF-8', path))
258-
hg 'rhcat', '-r', CGI.escape(hgrev(identifier)), '--', hgtarget(p) do |io|
258+
hg 'rhcat', "-r#{CGI.escape(hgrev(identifier))}", '--', hgtarget(p) do |io|
259259
io.binmode
260260
io.read
261261
end
@@ -266,7 +266,7 @@ def cat(path, identifier=nil)
266266
def annotate(path, identifier=nil)
267267
p = CGI.escape(scm_iconv(@path_encoding, 'UTF-8', path))
268268
blame = Annotate.new
269-
hg 'rhannotate', '-ncu', '-r', CGI.escape(hgrev(identifier)), '--', hgtarget(p) do |io|
269+
hg 'rhannotate', '-ncu', "-r#{CGI.escape(hgrev(identifier))}", '--', hgtarget(p) do |io|
270270
io.each_line do |line|
271271
line.force_encoding('ASCII-8BIT')
272272
next unless line =~ %r{^([^:]+)\s(\d+)\s([0-9a-f]+):\s(.*)$}
@@ -304,7 +304,8 @@ def hg(*args, &block)
304304
end
305305

306306
repo_path = root_url || url
307-
full_args = ['-R', repo_path, '--encoding', 'utf-8']
307+
full_args = ["-R#{repo_path}", '--encoding=utf-8']
308+
# don't use "--config=<value>" form for compatibility with ancient Mercurial
308309
full_args << '--config' << "extensions.redminehelper=#{HG_HELPER_EXT}"
309310
full_args << '--config' << 'diff.git=false'
310311
full_args += args

Diff for: test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class MercurialAdapterTest < ActiveSupport::TestCase
2121
HELPERS_DIR = Redmine::Scm::Adapters::MercurialAdapter::HELPERS_DIR
2222
TEMPLATE_NAME = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_NAME
2323
TEMPLATE_EXTENSION = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_EXTENSION
24+
HgCommandAborted = Redmine::Scm::Adapters::MercurialAdapter::HgCommandAborted
2425
HgCommandArgumentError = Redmine::Scm::Adapters::MercurialAdapter::HgCommandArgumentError
2526

2627
REPOSITORY_PATH = repository_path('mercurial')
@@ -445,19 +446,18 @@ def test_path_encoding_default_utf8
445446
end
446447

447448
def test_bad_early_options
448-
assert_raise HgCommandArgumentError do
449-
@adapter.diff('sources/welcome_controller.rb', '--config=alias.rhdiff=!xterm')
450-
end
449+
assert_nil @adapter.diff('sources/welcome_controller.rb',
450+
'--config=alias.rhdiff=!xterm')
451451
assert_raise HgCommandArgumentError do
452452
@adapter.entries('--debugger')
453453
end
454-
assert_raise HgCommandArgumentError do
454+
assert_raise HgCommandAborted do
455455
@adapter.revisions(nil, nil, nil, limit: '--repo=otherrepo')
456456
end
457-
assert_raise HgCommandArgumentError do
457+
assert_raise HgCommandAborted do
458458
@adapter.nodes_in_branch('default', limit: '--repository=otherrepo')
459459
end
460-
assert_raise HgCommandArgumentError do
460+
assert_raise HgCommandAborted do
461461
@adapter.nodes_in_branch('-Rotherrepo')
462462
end
463463
end

0 commit comments

Comments
 (0)