Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] Fix hexdump command used for mercurial dirstate parsing
- X-seq: zsh-workers 39776
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Frank Terbeck <ft@xxxxxxxxxxxxxxxxxxx>
- Subject: Re: [PATCH] Fix hexdump command used for mercurial dirstate parsing
- Date: Sun, 30 Oct 2016 17:06:58 +0000
- Cc: Reed Riley <john.reed.riley@xxxxxxxxx>, zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=lQbbMJM+uMTXDR8 urC7c81LbAEU=; b=Fh0CUrgXSDwnZvY8a/1oETqWCsALBTV4gidOLzZKP5BQndo xb9k7aBs2tRSZXZYm+peWiI6DhmFz3yqHlo7iA9WoW45kaKpK8VHrKgyubRvSszy R9ubzJrggtSREjMlo/NkJWQIyaKhYtY04taeQbk+tZSdvyReudc7Qx/HptnE=
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=smtpout; bh=lQbbMJM+uMTXDR 8urC7c81LbAEU=; b=lqOwPH9vByAIKBI5Te3rx/h5kQlegEdnLrSY0BLIb02vww HuiFbjVXVX8r2e+c5EJG/psHKiWDT9CSOYSxDkBuNOBBogmWuHBzfZea//U6awK7 EhxsqteOY5Og8wku21iJveHJBeLuOt4KXt7FQ8vwbDYqjQMwU9PrkIGeYxafQ=
- In-reply-to: <20161030155530.GC12137@fujitsu.shahaf.local2>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20161030024723.62832-1-john.reed.riley@gmail.com> <87y416drcq.fsf@ft.bewatermyfriend.org> <20161030155530.GC12137@fujitsu.shahaf.local2>
Daniel Shahaf wrote on Sun, Oct 30, 2016 at 15:55:30 +0000:
> Frank Terbeck wrote on Sun, Oct 30, 2016 at 12:11:01 +0100:
> > It would be conceivable to make the command that is called in these
> > places configurable via styles. But that is a separate issue to the
> > one that fixes our use of hexdump.
>
> Couldn't we replace hexdump by a pure zsh solution? We simply need to
> read 20 octets and print their hexadecimal values.
This seems to do the job:
% f() {
local fname=$1 bytecount=$2
# Read 20 bytes
setopt localoptions nomultibyte
integer fd; local val
exec {fd}<$fname
read -k $bytecount -r -u $fd val
exec {fd}<&-
# Convert them to hex
setopt localoptions extendedglob
local -r -A pad=( $'\0' 0 $'\1' 0 $'\2' 0 $'\3' 0 $'\4' 0 $'\5' 0 $'\6' 0 $'\7' 0 $'\10' 0 $'\11' 0 $'\12' 0 $'\13' 0 $'\14' 0 $'\15' 0 $'\16' 0 $'\17' 0 )
REPLY=${(L)val//(#b)(?)/$pad[$match[1]]$(( [##16] ##${match[1]} ))}
}
% f dirstate 20
% typeset -p REPLY
typeset REPLY=77bba665e970146bd2be0b2da40092e340408804
% xxd -l20 -p < dirstate
77bba665e970146bd2be0b2da40092e340408804
%
Would something along these lines be preferable?
Thanks to Mikael for the inner loop.
Cheers,
Daniel
Messages sorted by:
Reverse Date,
Date,
Thread,
Author