在新项目中开发人员有6个,目标环境有aix和hp,以前没有采用版本管理,感觉版本有点乱;
先在自己的笔记本上对hg考察了一段时间,感觉还挺好的。准备安装到开发环境下正式使用;
安装和配置过程中遇到了点问题,解决了,记录安装过程如下,方便后来者:
1.由于没有root权限,再说也不方便安装扩展包,如zip等,就从www.activestate.com下载了编译好的aix和
hp下的python2.5.2的安装包;
2.安装是解压缩遇到问题,提示crc校验错误;在xp下解压缩后删除doc目录后重新tar后上传;
3.执行install.sh按照提示安装python到用户python目录下(/home/test/python);在.profile中加入路径
/home/test/python/bin,重新登录或者 . .profile 激活配置项目;
4.从http://www.selenic.com/mercurial/下载最新版本1.0.1;解压缩后进入目录,由于aix,hp默认make不识别gnu格式的makefile 手工执行makefile中命令安装:
python setup.py build_ext -i
python setup.py build_py -c -d .
python setup.py build
python setup.py install
执行hg 成功运行,说明安装ok了;
5.把xp上的版本库clone过去;
hp clone http://192.168.0.1:8000/refas
6.此时在aix执行hg log update pull等操作均正常;
启动web服务 hg serve
浏览器一访问,hg就core了;追踪多个文件,发现是core在revlog.py 中
在import sha
_sha = sha.new时core
手工执行上面的代码又不core,真是奇怪,后来在commands.py中加入上面两行,再运行就好了,真是奇怪
。
7.不过新的问题出现了,hg log查看的变更记录,以及浏览器中的注释和代码中的中文全部都是??
放狗一搜,搜到http://jostudio.blogspot.com/2008/05/mercurial.html
Josh提到中文是会乱码的,要输入英文注释,对我来说,英文看起来没有中文亲切。再加上刚刚解决前面的core问题时对hg的代码结构有了基本的了解,就干脆动手追踪一下吧。一层层追踪代码到了util.py中,有个tolocal函数,负责把hq内部存储的utf8编码转换为本地编码;具体本地编码是什么是在util.py中初始化从环境变量中读取的,如果没有读取到就默认转换为ascii了,中文就被转换为??;
设置环境变量:
HGENCODING=GBK
export HGENCODING
具体相关代码如下:
[code]
try:
set = set
frozenset = frozenset
except NameError:
from sets import Set as set, ImmutableSet as frozenset
try:
_encoding = os.environ.get("HGENCODING")
if sys.platform == 'darwin' and not _encoding:
# On darwin, getpreferredencoding ignores the locale environment and
# always returns mac-roman. We override this if the environment is
# not C (has been customized by the user).
locale.setlocale(locale.LC_CTYPE, '')
_encoding = locale.getlocale()[1]
if not _encoding:
_encoding = locale.getpreferredencoding() or 'ascii'
except locale.Error:
_encoding = 'ascii'
_encodingmode = os.environ.get("HGENCODINGMODE", "strict")
_fallbackencoding = 'ISO-8859-1'
def tolocal(s):
"""
Convert a string from internal UTF-8 to local encoding
All internal strings should be UTF-8 but some repos before the
implementation of locale support may contain latin1 or possibly
other character sets. We attempt to decode everything strictly
using UTF-8, then Latin-1, and failing that, we use UTF-8 and
replace unknown characters.
"""
for e in ('UTF-8', _fallbackencoding):
try:
u = s.decode(e) # attempt strict decoding
return u.encode(_encoding, "replace")
except LookupError, k:
raise Abort(_("%s, please check your locale settings") % k)
except UnicodeDecodeError:
pass
u = s.decode("utf-8", "replace") # last ditch
return u.encode(_encoding, "replace")
def fromlocal(s):
"""
Convert a string from the local character encoding to UTF-8
We attempt to decode strings using the encoding mode set by
HGENCODINGMODE, which defaults to 'strict'. In this mode, unknown
characters will cause an error message. Other modes include
'replace', which replaces unknown characters with a special
Unicode character, and 'ignore', which drops the character.
"""
try:
return s.decode(_encoding, _encodingmode).encode("utf-8")
except UnicodeDecodeError, inst:
sub = s[max(0, inst.start-10):inst.start+10]
raise Abort("decoding near '%s': %s!" % (sub, inst))
except LookupError, k:
raise Abort(_("%s, please check your locale settings") % k)
[/code]
设置环境变量后再运行hg log hg serve 中文都显示正常了。呵呵,问题解决!!