Patch #5117
closedmercurial_adapter should ensure the right LANG environment variable
100%
Description
http://www.redmine.org/projects/redmine/repository/revisions/3506/entry/trunk/lib/redmine/scm/adapters/mercurial_adapter.rb#L47 matches with a regular expression which may not work on some locales.
$ locale | grep LANG LANG="it_IT.UTF-8" $ hg --version Mercurial SCM Distribuito (versione 1.5+20100307)
To ensure the correct behaviour you may set LANG='C'
before calling hg.
rake test error snippets
2) Error: test_annotate(RepositoriesMercurialControllerTest): NoMethodError: You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] lib/redmine/scm/adapters/mercurial_adapter.rb:47:in `hgversion_from_command_line' lib/redmine/scm/adapters/mercurial_adapter.rb:40:in `hgversion' lib/redmine/scm/adapters/mercurial_adapter.rb:33:in `client_version' lib/redmine/scm/adapters/mercurial_adapter.rb:51:in `template_path' lib/redmine/scm/adapters/mercurial_adapter.rb:108:in `revisions' lib/redmine/scm/adapters/mercurial_adapter.rb:72:in `info' lib/redmine/scm/adapters/abstract_adapter.rb:162:in `retrieve_root_url' lib/redmine/scm/adapters/abstract_adapter.rb:54:in `initialize' app/models/repository.rb:41:in `new' app/models/repository.rb:41:in `scm' app/models/repository.rb:75:in `default_branch' app/controllers/repositories_controller.rb:205:in `find_repository' /test/functional/repositories_mercurial_controller_test.rb:125:in `test_annotate' 3) Error: test_changes(RepositoriesMercurialControllerTest): NoMethodError: You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] lib/redmine/scm/adapters/mercurial_adapter.rb:47:in `hgversion_from_command_line' lib/redmine/scm/adapters/mercurial_adapter.rb:40:in `hgversion' lib/redmine/scm/adapters/mercurial_adapter.rb:33:in `client_version' lib/redmine/scm/adapters/mercurial_adapter.rb:51:in `template_path' lib/redmine/scm/adapters/mercurial_adapter.rb:108:in `revisions' lib/redmine/scm/adapters/mercurial_adapter.rb:72:in `info' lib/redmine/scm/adapters/abstract_adapter.rb:162:in `retrieve_root_url' lib/redmine/scm/adapters/abstract_adapter.rb:54:in `initialize' app/models/repository.rb:41:in `new' app/models/repository.rb:41:in `scm' app/models/repository.rb:75:in `default_branch' app/controllers/repositories_controller.rb:205:in `find_repository' /test/functional/repositories_mercurial_controller_test.rb:79:in `test_changes' 4) Error: test_diff(RepositoriesMercurialControllerTest): NoMethodError: You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] lib/redmine/scm/adapters/mercurial_adapter.rb:47:in `hgversion_from_command_line' lib/redmine/scm/adapters/mercurial_adapter.rb:40:in `hgversion' lib/redmine/scm/adapters/mercurial_adapter.rb:33:in `client_version' lib/redmine/scm/adapters/mercurial_adapter.rb:51:in `template_path' lib/redmine/scm/adapters/mercurial_adapter.rb:108:in `revisions' lib/redmine/scm/adapters/mercurial_adapter.rb:72:in `info' lib/redmine/scm/adapters/abstract_adapter.rb:162:in `retrieve_root_url' lib/redmine/scm/adapters/abstract_adapter.rb:54:in `initialize' app/models/repository.rb:41:in `new' app/models/repository.rb:41:in `scm' app/models/repository.rb:87:in `diff' app/controllers/repositories_controller.rb:167:in `diff' /test/functional/repositories_mercurial_controller_test.rb:113:in `test_diff' 5) Error: test_directory_entry(RepositoriesMercurialControllerTest): NoMethodError: You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] lib/redmine/scm/adapters/mercurial_adapter.rb:47:in `hgversion_from_command_line' lib/redmine/scm/adapters/mercurial_adapter.rb:40:in `hgversion' lib/redmine/scm/adapters/mercurial_adapter.rb:33:in `client_version' lib/redmine/scm/adapters/mercurial_adapter.rb:51:in `template_path' lib/redmine/scm/adapters/mercurial_adapter.rb:108:in `revisions' lib/redmine/scm/adapters/mercurial_adapter.rb:72:in `info' lib/redmine/scm/adapters/abstract_adapter.rb:162:in `retrieve_root_url' lib/redmine/scm/adapters/abstract_adapter.rb:54:in `initialize' app/models/repository.rb:41:in `new' app/models/repository.rb:41:in `scm' app/models/repository.rb:75:in `default_branch' app/controllers/repositories_controller.rb:205:in `find_repository' /test/functional/repositories_mercurial_controller_test.rb:104:in `test_directory_entry' 6) Error: test_entry_download(RepositoriesMercurialControllerTest): NoMethodError: You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] lib/redmine/scm/adapters/mercurial_adapter.rb:47:in `hgversion_from_command_line' lib/redmine/scm/adapters/mercurial_adapter.rb:40:in `hgversion' lib/redmine/scm/adapters/mercurial_adapter.rb:33:in `client_version' lib/redmine/scm/adapters/mercurial_adapter.rb:51:in `template_path' lib/redmine/scm/adapters/mercurial_adapter.rb:108:in `revisions' lib/redmine/scm/adapters/mercurial_adapter.rb:72:in `info' lib/redmine/scm/adapters/abstract_adapter.rb:162:in `retrieve_root_url' lib/redmine/scm/adapters/abstract_adapter.rb:54:in `initialize' app/models/repository.rb:41:in `new' app/models/repository.rb:41:in `scm' app/models/repository.rb:75:in `default_branch' app/controllers/repositories_controller.rb:205:in `find_repository' /test/functional/repositories_mercurial_controller_test.rb:97:in `test_entry_download' 7) Error: test_entry_show(RepositoriesMercurialControllerTest): NoMethodError: You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] lib/redmine/scm/adapters/mercurial_adapter.rb:47:in `hgversion_from_command_line' lib/redmine/scm/adapters/mercurial_adapter.rb:40:in `hgversion' lib/redmine/scm/adapters/mercurial_adapter.rb:33:in `client_version' lib/redmine/scm/adapters/mercurial_adapter.rb:51:in `template_path' lib/redmine/scm/adapters/mercurial_adapter.rb:108:in `revisions' lib/redmine/scm/adapters/mercurial_adapter.rb:72:in `info' lib/redmine/scm/adapters/abstract_adapter.rb:162:in `retrieve_root_url' lib/redmine/scm/adapters/abstract_adapter.rb:54:in `initialize' app/models/repository.rb:41:in `new' app/models/repository.rb:41:in `scm' app/models/repository.rb:75:in `default_branch' app/controllers/repositories_controller.rb:205:in `find_repository' /test/functional/repositories_mercurial_controller_test.rb:86:in `test_entry_show' 8) Error: test_show(RepositoriesMercurialControllerTest): NoMethodError: You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] lib/redmine/scm/adapters/mercurial_adapter.rb:47:in `hgversion_from_command_line' lib/redmine/scm/adapters/mercurial_adapter.rb:40:in `hgversion' lib/redmine/scm/adapters/mercurial_adapter.rb:33:in `client_version' lib/redmine/scm/adapters/mercurial_adapter.rb:51:in `template_path' lib/redmine/scm/adapters/mercurial_adapter.rb:108:in `revisions' lib/redmine/scm/adapters/mercurial_adapter.rb:72:in `info' lib/redmine/scm/adapters/abstract_adapter.rb:162:in `retrieve_root_url' lib/redmine/scm/adapters/abstract_adapter.rb:54:in `initialize' app/models/repository.rb:41:in `new' app/models/repository.rb:41:in `scm' app/models/repository.rb:75:in `default_branch' app/controllers/repositories_controller.rb:205:in `find_repository' /test/functional/repositories_mercurial_controller_test.rb:40:in `test_show' 9) Error: test_show_at_given_revision(RepositoriesMercurialControllerTest): NoMethodError: You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] lib/redmine/scm/adapters/mercurial_adapter.rb:47:in `hgversion_from_command_line' lib/redmine/scm/adapters/mercurial_adapter.rb:40:in `hgversion' lib/redmine/scm/adapters/mercurial_adapter.rb:33:in `client_version' lib/redmine/scm/adapters/mercurial_adapter.rb:51:in `template_path' lib/redmine/scm/adapters/mercurial_adapter.rb:108:in `revisions' lib/redmine/scm/adapters/mercurial_adapter.rb:72:in `info' lib/redmine/scm/adapters/abstract_adapter.rb:162:in `retrieve_root_url' lib/redmine/scm/adapters/abstract_adapter.rb:54:in `initialize' app/models/repository.rb:41:in `new' app/models/repository.rb:41:in `scm' app/models/repository/mercurial.rb:33:in `entries' app/controllers/repositories_controller.rb:72:in `show' /test/functional/repositories_mercurial_controller_test.rb:71:in `test_show_at_given_revision' 10) Error: test_show_directory(RepositoriesMercurialControllerTest): NoMethodError: You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] lib/redmine/scm/adapters/mercurial_adapter.rb:47:in `hgversion_from_command_line' lib/redmine/scm/adapters/mercurial_adapter.rb:40:in `hgversion' lib/redmine/scm/adapters/mercurial_adapter.rb:33:in `client_version' lib/redmine/scm/adapters/mercurial_adapter.rb:51:in `template_path' lib/redmine/scm/adapters/mercurial_adapter.rb:108:in `revisions' lib/redmine/scm/adapters/mercurial_adapter.rb:72:in `info' lib/redmine/scm/adapters/abstract_adapter.rb:162:in `retrieve_root_url' lib/redmine/scm/adapters/abstract_adapter.rb:54:in `initialize' app/models/repository.rb:41:in `new' app/models/repository.rb:41:in `scm' app/models/repository.rb:75:in `default_branch' app/controllers/repositories_controller.rb:205:in `find_repository' /test/functional/repositories_mercurial_controller_test.rb:59:in `test_show_directory' 11) Error: test_show_root(RepositoriesMercurialControllerTest): NoMethodError: You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] lib/redmine/scm/adapters/mercurial_adapter.rb:47:in `hgversion_from_command_line' lib/redmine/scm/adapters/mercurial_adapter.rb:40:in `hgversion' lib/redmine/scm/adapters/mercurial_adapter.rb:33:in `client_version' lib/redmine/scm/adapters/mercurial_adapter.rb:51:in `template_path' lib/redmine/scm/adapters/mercurial_adapter.rb:108:in `revisions' lib/redmine/scm/adapters/mercurial_adapter.rb:72:in `info' lib/redmine/scm/adapters/abstract_adapter.rb:162:in `retrieve_root_url' lib/redmine/scm/adapters/abstract_adapter.rb:54:in `initialize' app/models/repository.rb:41:in `new' app/models/repository.rb:41:in `scm' app/models/repository.rb:75:in `default_branch' app/controllers/repositories_controller.rb:205:in `find_repository' /test/functional/repositories_mercurial_controller_test.rb:48:in `test_show_root'
This patch applies on redmine 0.9.3
$ script/about About your application's environment Ruby version 1.8.7 (universal-darwin10.0) RubyGems version 1.3.6 Rack version 1.0 Rails version 2.3.5 Active Record version 2.3.5 Active Resource version 2.3.5 Action Mailer version 2.3.5 Active Support version 2.3.5 Application root /Users/nolith/Documents/Projects/redmine-hg Environment development Database adapter sqlite3 Database schema version 20100222000000
Files
Related issues
Updated by Toshi MARUYAMA over 14 years ago
- File windows-lang-c.png windows-lang-c.png added
This patch does not work on windows.
Updated by Toshi MARUYAMA over 14 years ago
$ hg diff diff -r 8152d1bdeac5 lib/redmine/scm/adapters/mercurial_adapter.rb --- a/lib/redmine/scm/adapters/mercurial_adapter.rb Sun Feb 28 22:12:54 2010 +0900 +++ b/lib/redmine/scm/adapters/mercurial_adapter.rb Thu Mar 18 23:30:34 2010 +0900 @@ -23,7 +23,8 @@ class MercurialAdapter < AbstractAdapter # Mercurial executable name - HG_BIN = "hg" + # HG_BIN = "hg" + HG_BIN = "env LANG=C hg" TEMPLATES_DIR = File.dirname(__FILE__) + "/mercurial" TEMPLATE_NAME = "hg-template" TEMPLATE_EXTENSION = "tmpl"
$ env LANG=ja_JP.UTF-8 hg --version Mercurial - 分散構成管理ツール(バージョン 1.5+99-bedef1c228d3)
Updated by Toshi MARUYAMA over 14 years ago
MSysGit has env.exe in "C:\Program Files\Git\bin".
But TortoiseHg does not have env.exe in "C:\Program Files\TortoiseHg".
This is not solution.
Updated by Alessio Caiazza over 14 years ago
Toshi Maruyama wrote:
MSysGit has env.exe in "C:Program FilesGitin".
But TortoiseHg does not have env.exe in "C:Program FilesTortoiseHg".
This is not solution.
Does it install python?
# HG changeset patch # Parent 0dc60afda5722afecf6f7fc5c13552d3f008bdf2 sets LANG variable before calling hg diff --git a/lib/redmine/scm/adapters/mercurial_adapter.rb b/lib/redmine/scm/adapters/mercurial_adapter.rb --- a/lib/redmine/scm/adapters/mercurial_adapter.rb +++ b/lib/redmine/scm/adapters/mercurial_adapter.rb @@ -45,6 +45,12 @@ def hgversion_from_command_line %x{#{HG_BIN} --version}.match(/\(version (.*)\)/)[1] + rescue NoMethodError + hgversion_from_python + end + + def hgversion_from_python + %x{python -c "from mercurial import util; print util.version()"}.strip end def template_path
Updated by Alessio Caiazza over 14 years ago
TortoiseHG didn't install python, it compiles hg.
Not a solution.
Updated by Toshi MARUYAMA over 14 years ago
- File hg-lang-c.patch hg-lang-c.patch added
I create patch and finish test on Windows.
This patch for Redmine 0.9.3.
Updated by Jean-Philippe Lang over 14 years ago
IMHO, it would be simplier to assume that the version number is of the first line of the output.
Just like we do for other SCM:
if m = io.gets.to_s.match(%r{((\d+\.)+\d+)}) version = m[0].scan(%r{\d+}).collect(&:to_i) end
Updated by Alessio Caiazza over 14 years ago
Patch based on Jean's advice.
Updated by Toshi MARUYAMA about 14 years ago
- File hg-version-20100929.diff hg-version-20100929.diff added
- % Done changed from 0 to 100
I fixed Yuya's MQ which fails source:tags/1.0.2/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb and added new test.
Updated by Toshi MARUYAMA about 14 years ago
Updated by Toshi MARUYAMA about 14 years ago
Yuya reviewed and updated my previous patch and imported to his MQ.
- http://bitbucket.org/yuja/redmine-mq-issue4455/issue/7/request-for-refreshing-hg-versiondiff
- http://bitbucket.org/yuja/redmine-mq-issue4455/changeset/c5a47a5f63f5
I attach new patch and pushed my github.
- http://github.com/marutosi/redmine/commits/hg-version-yuya-mq-c5a47a5f63
- http://github.com/marutosi/redmine/commits/e2334dcb4b85976a1224
I wish to set target of this issue to next stable 1.0.3.
Updated by Toshi MARUYAMA about 14 years ago
- File hg-version-20101114.diff hg-version-20101114.diff added
Updated by Yuya Nishihara about 14 years ago
- File hg-version-2010-11-15.patch hg-version-2010-11-15.patch added
- File hg-version-minimal-2010-11-15.patch hg-version-minimal-2010-11-15.patch added
Toshi MARUYAMA wrote:
Hi, I think your patch is overengineerd. Here's a patch to fix this issue with minimal changes: hg-version-minimal-2010-11-15.patch
I have another one to fix this, hg-version-2010-11-15.patch, but it contains more changes to simplify the codes.
Updated by Jean-Philippe Lang about 14 years ago
- Status changed from New to Closed
- Target version set to 1.0.4
I've committed hg-version-minimal-2010-11-15.patch in trunk and 1.0-stable as it solves the reported error.
Thanks.
Updated by Toshi MARUYAMA about 14 years ago
- Status changed from Closed to Reopened
Unit test fails.
$ LANG=C ruby test/unit/repository_mercurial_test.rb ./test/unit/../test_helper.rb:405: warning: don't put space before argument parentheses /usr/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/gem_dependency.rb:119:Warning: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010. Use #requirement Loaded suite test/unit/repository_mercurial_test Started .EEEEE Finished in 2.508805 seconds. 1) Error: test_cat(RepositoryMercurialTest): NoMethodError: undefined method `lines' for #<String:0x7fa9541f9a28> lib/redmine/scm/adapters/mercurial_adapter.rb:47:in `hgversion_from_command_line' lib/redmine/scm/adapters/mercurial_adapter.rb:40:in `hgversion' lib/redmine/scm/adapters/mercurial_adapter.rb:33:in `client_version' lib/redmine/scm/adapters/mercurial_adapter.rb:51:in `template_path' lib/redmine/scm/adapters/mercurial_adapter.rb:108:in `revisions' lib/redmine/scm/adapters/mercurial_adapter.rb:72:in `info' lib/redmine/scm/adapters/abstract_adapter.rb:162:in `retrieve_root_url' lib/redmine/scm/adapters/abstract_adapter.rb:54:in `initialize' app/models/repository.rb:41:in `new' app/models/repository.rb:41:in `scm' test/unit/repository_mercurial_test.rb:67:in `test_cat'
Updated by Toshi MARUYAMA about 14 years ago
I refresh a patch for SVN trunk based on Yuya's hg-version-2010-11-15.patch.
Updated by Yuya Nishihara about 14 years ago
Toshi MARUYAMA wrote:
Unit test fails.
Gee, Ruby 1.8.6 doesn't seem to have String#lines method, sorry. Could you test the attached patch? mercurial_adapter_each_line.patch
Updated by Toshi MARUYAMA about 14 years ago
Yuya Nishihara wrote:
Toshi MARUYAMA wrote:
Unit test fails.
Gee, Ruby 1.8.6 doesn't seem to have String#lines method, sorry. Could you test the attached patch? mercurial_adapter_each_line.patch
It fails.
$ ruby test/unit/repository_mercurial_test.rb ./test/unit/../test_helper.rb:405: warning: don't put space before argument parentheses /usr/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/gem_dependency.rb:119:Warning: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010. Use #requirement Loaded suite test/unit/repository_mercurial_test Started .EEEEE Finished in 3.546667 seconds. 1) Error: test_cat(RepositoryMercurialTest): LocalJumpError: no block given lib/redmine/scm/adapters/mercurial_adapter.rb:47:in `each_line' lib/redmine/scm/adapters/mercurial_adapter.rb:47:in `hgversion_from_command_line' lib/redmine/scm/adapters/mercurial_adapter.rb:40:in `hgversion' lib/redmine/scm/adapters/mercurial_adapter.rb:33:in `client_version' lib/redmine/scm/adapters/mercurial_adapter.rb:51:in `template_path' lib/redmine/scm/adapters/mercurial_adapter.rb:108:in `revisions' lib/redmine/scm/adapters/mercurial_adapter.rb:72:in `info' lib/redmine/scm/adapters/abstract_adapter.rb:162:in `retrieve_root_url' lib/redmine/scm/adapters/abstract_adapter.rb:54:in `initialize' app/models/repository.rb:41:in `new' app/models/repository.rb:41:in `scm' test/unit/repository_mercurial_test.rb:67:in `test_cat'
$ ruby --version ruby 1.8.6 (2010-02-05 patchlevel 399) [x86_64-linux]
$ LANG=C rpm -qi ruby Name : ruby Relocations: (not relocatable) Version : 1.8.6.399 Vendor: Fedora Project Release : 6.fc13 Build Date: Mon Aug 23 02:56:25 2010 Install Date: Wed Sep 1 10:42:01 2010 Build Host: x86-14.phx2.fedoraproject.org Group : Development/Languages Source RPM: ruby-1.8.6.399-6.fc13.src.rpm Size : 1740271 License: Ruby or GPLv2 Signature : RSA/SHA256, Tue Aug 24 02:03:58 2010, Key ID 7edc6ad6e8e40fde Packager : Fedora Project URL : http://www.ruby-lang.org/ Summary : An interpreter of object-oriented scripting language Description : Ruby is the interpreted scripting language for quick and easy object-oriented programming. It has many features to process text files and to do system management tasks (as in Perl). It is simple, straight-forward, and extensible.
Updated by Yuya Nishihara about 14 years ago
Toshi MARUYAMA wrote:
It fails.
Hmm, #each_line => Enumerator
seems also introduced in 1.8.7, according to string.c:rb_str_each_line().
I changed #hgversion_from_command_line to return whole lines and updated the test case accordingly:
mercurial_adapter_1.8.6fix.patch
This should fix the problem on Ruby 1.8.6.
We could use String#to_a (only for 1.8.x) or String#split("\n"), but I think it's simple just not to eliminate trailing lines.
Updated by Toshi MARUYAMA about 14 years ago
Updated by Jean-Philippe Lang about 14 years ago
- Status changed from Reopened to Closed