Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] Fix hexdump command used for mercurial dirstate parsing



Damn - I had no idea `xxd` was a part of Vim, sorry!  The original version
of my patch was `hexdump -n 20 -e '20/1 "%02x"' ${dirstatefile}` - I only
switched to xxd at Daniel Shahaf's suggestion.

I sadly can't provide a full dirstate file for a repro, but I can provide
the relevant part as a hexdump:
❯ hexdump dirstate | head -n3

                0000000 77 bb a6 65 e9 70 14 6b d2 be 0b 2d a4 00 92 e3
0000010 40 40 88 04 00 00 00 00 00 00 00 00 00 00 00 00
0000020 00 00 00 00 00 00 00 00 6e 00 00 81 a4 00 00 04
❯ hexdump -n20 -e '1/1 "%02x"' dirstate

          77bba665e970146bd2be0b2da40092e340*
8804%

From the limited research I've done, the issue in the output is that '*' is
used to represent repetitions:
 -
http://superuser.com/questions/494245/what-does-an-asterisk-mean-in-hexdump-output
 - also described (partially?) in `man hexdump` in the description of the
`-v` option.

In other words, if you have repeated octets in your commit hash, the old
command doesn't work properly.

So, based on that, there are two versions of the command that work
correctly on this particular case for me:
hexdump -n 20 -e '20/1 "%02x"' ${dirstatefile}
hexdump -n 20 -v -e '1/1 "%02x"' ${dirstatefile}

Do you have any preference between them?

Thanks,
Reed

On Sun, Oct 30, 2016 at 7:11 AM, Frank Terbeck <ft@xxxxxxxxxxxxxxxxxxx>
wrote:

> Hi,
>
> Reed Riley wrote:
> > Normally, the old command works.  But very rarely, it outputs a string
> > like the following instead:
> > ❯ hexdump -n20 -e '1/1 "%02x"' .hg/dirstate
> > 77bba665e970146bd2be0b2da40092e340*
> > 8804
> [...]
> > -        r_csetid=$(hexdump -n 20 -e '1/1 "%02x"' ${dirstatefile})
> > +        r_csetid=$(xxd -p -l20 ${dirstatefile})
>
> I would much rather know, what causes hexdump to behave like that. Is
> the way we are using it documented behavior? If so, that would suggest a
> bug in hexdump, that should be resolved instead. If no, we're probably
> using hexdump in a wrong way — maybe just in a non-portable way, and we
> should fix the way we're using hexdump.
>
> Are you able to provides example data, that causes the bug? Maybe even
> formulate a supposition as to what it is exactly, that triggers this
> behaviour.
>
> "xxd" is a command shipped with vim. Adding such a dependency is out of
> the question for me. 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.
>
>
> Regards, Frank
>



-- 
Reed Riley <john.reed.riley@xxxxxxxxx>

--------------------------------------------
Q: Why is this email five sentences or less?
A: http://five.sentenc.es


Messages sorted by: Reverse Date, Date, Thread, Author