zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] Fix hexdump command used for mercurial dirstate parsing
Date: Sun, 30 Oct 2016 20:33:14 +0000	[thread overview]
Message-ID: <20161030203314.GA4276@fujitsu.shahaf.local2> (raw)
In-Reply-To: <161030112832.ZM14753@torch.brasslantern.com>

Bart Schaefer wrote on Sun, Oct 30, 2016 at 11:28:32 -0700:
> On Oct 30,  5:06pm, Daniel Shahaf wrote:
> }
> }     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]} ))}
> 
> I can't help thinking here must be an easier way to do that.
> 
> f() {                                              
>   setopt localoptions nomultibyte extendedglob
>   local val
>   read -k $2 -u 0 val <$1
>   print -r -- ${(Lj::)${(l:2::0:)${(@s//)val}//(#m)*/$(( [##16] ##$MATCH ))}}
> }

Thanks; that's now VCS_INFO_hexdump:

diff --git a/Functions/VCS_Info/VCS_INFO_hexdump b/Functions/VCS_Info/VCS_INFO_hexdump
index e69de29..11f1c1a 100644
--- a/Functions/VCS_Info/VCS_INFO_hexdump
+++ b/Functions/VCS_Info/VCS_INFO_hexdump
@@ -0,0 +1,16 @@
+## vim:ft=zsh
+
+# VCS_INFO_hexdump FILENAME BYTECOUNT
+#
+# Return in $REPLY a hexadecimal representation (lowercase, no whitespace)
+# of the first BYTECOUNT bytes of FILENAME.
+
+if [[ -r $1 ]]; then
+  setopt localoptions nomultibyte extendedglob
+  local val
+  read -k $2 -u 0 val <$1
+  REPLY=${(Lj::)${(l:2::0:)${(@s//)val}//(#m)*/$(( [##16] ##$MATCH ))}}
+else
+  return 1
+fi
+
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
index f35ad59..4ad4089 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
@@ -40,9 +40,9 @@ VCS_INFO_adjust
 # Disabled by default anyway, so no harm done.
 if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision ; then
     if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" use-simple \
-            && ( VCS_INFO_check_com hexdump ) && [[ -r ${dirstatefile} ]] ; then
+            && VCS_INFO_hexdump ${dirstatefile} 20 ; then
         # Calling hexdump is (much) faster than hg but doesn't get the local rev
-        r_csetid=$(hexdump -n 20 -e '1/1 "%02x"' ${dirstatefile})
+        r_csetid=$REPLY
     else
         # Settling for a short (but unique!) hash because getting the full
         # 40-char hash in addition to all the other info we want isn't
diff --git a/Functions/VCS_Info/vcs_info b/Functions/VCS_Info/vcs_info
index f13f6b5..c0c1182 100644
--- a/Functions/VCS_Info/vcs_info
+++ b/Functions/VCS_Info/vcs_info
@@ -19,6 +19,7 @@ static_functions=(
     VCS_INFO_check_com
     VCS_INFO_formats
     VCS_INFO_get_cmd
+    VCS_INFO_hexdump
     VCS_INFO_hook
     VCS_INFO_maxexports
     VCS_INFO_nvcsformats


  reply	other threads:[~2016-10-30 20:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-30  2:47 Reed Riley
2016-10-30  5:34 ` Bart Schaefer
2016-10-30  7:01 ` Mikael Magnusson
2016-10-30 11:11 ` Frank Terbeck
2016-10-30 14:43   ` Reed Riley
2016-10-30 16:58     ` Reed Riley
2016-10-30 19:57       ` Frank Terbeck
2016-10-30 15:55   ` Daniel Shahaf
2016-10-30 17:06     ` Daniel Shahaf
2016-10-30 18:28       ` Bart Schaefer
2016-10-30 20:33         ` Daniel Shahaf [this message]
2016-10-31  9:04           ` Frank Terbeck
2016-10-31 18:37             ` Daniel Shahaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161030203314.GA4276@fujitsu.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).