Encoding problem and bug running hookscript ?
Yannick CHARLES
yannick.charles at gmail.com
Thu Nov 29 14:54:35 UTC 2012
Ah yes, you're right. I didn't realise the script would be run by the
apache user www-data, with this user's environment.
So called by a hook, echo -e "`hg help -v | grep encoding`\n" gives:
remote: --encoding ENCODE set the charset encoding (default: ascii)
remote: --encodingmode MODE set the charset encoding mode (default:
strict)
and echo `locale | grep CTYPE`:
remote: LC_CTYPE="C"
So I added LANG=en_US.UTF-8 in the beginning of the shell script called by
the hook, so it also fixes other encoding problems.
I have the following construct to get a proper patchname, create the
corresponding folder (where I'll export built files) and calling make
wherever it's needed in the project (Makefiles then take care of moving
built files to the created folder):
# Building 'patchname'
date=`hg log -l 1 --template '{date|isodate}'`
desc=`hg log -l 1 --template '{desc|firstline|strip|fill68}'`
patchspace="${date% *}-${desc%%[,;:!?=@<>%*+&./()\"]*}"
patchname="${patchspace// /_}"
# Creating patch directory and building all files
mkdir -p /mnt/Mercurial_data/Patches/$1/$patchname
find .. -type f -name 'Makefile' -execdir make devname=$1
patchname=$patchname \;
Without defining the LANG variable, patchname was filled with strange
characters (tested with echo $patchname but I guess mkdir wouldn't have
liked it).
Also I ran into the problem that /bin/sh is the default shell for user
www-data, so the script crashed due to some parts using bash syntax. I
fixed the problem by explicitly calling bash in the hook line:
changegroup.01autobuild_patch = bash ../patch_chgrouphook.sh Yann
(instead of just changegroup.01autobuild_patch = ../patch_chgrouphook.sh
Yann )
Thanks again for your advice, helped me to fix the two above problems ! :)
2012/11/28 Matt Mackall <mpm at selenic.com>
> On Wed, 2012-11-28 at 22:18 +0100, Yannick CHARLES wrote:
> > Yes, with
> >
> > hg qpush -a --encoding utf-8
> >
> > it works perfectly.
> >
> > I also checked the encodings (with hg help -v and locale) on the
> > server side, I get the same results as in your example.
>
> But did you check _in the hook script_? The environment of hgweb is very
> often completely different from your shell command line on the same
> machine. Different user, path, environment, permissions, config, etc.
>
> --
> Mathematics is the supreme nostalgia of our time.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial/attachments/20121129/a42209d5/attachment-0002.html>
More information about the Mercurial
mailing list