]> Sergey Matveev's repositories - zsh-autoenv.git/commitdiff
Use cksum instead of sha1sum for checksums (#54)
authorDaniel Hahler <github@thequod.de>
Thu, 5 Jan 2017 00:16:21 +0000 (01:16 +0100)
committerGitHub <noreply@github.com>
Thu, 5 Jan 2017 00:16:21 +0000 (01:16 +0100)
This provides better performance, but requires you to re-authenticate all files.

Fixes https://github.com/Tarrasch/zsh-autoenv/issues/53.

autoenv.zsh
tests/_autoenv_utils.t

index 5882f9f6564143d3b41976133455d7ce05073593..ed570c07a28b1802c0d715e221a338f0258902aa 100644 (file)
@@ -173,15 +173,16 @@ _autoenv_debug() {
 # The format is ":$file:$hash:$version".
 _autoenv_hash_pair() {
   local env_file=${1:A}
-  local env_shasum=${2:-}
-  if [[ -z $env_shasum ]]; then
+  local env_cksum=${2:-}
+  if [[ -z $env_cksum ]]; then
     if ! [[ -e $env_file ]]; then
       echo "Missing file argument for _autoenv_hash_pair!" >&2
       return 1
     fi
-    env_shasum=$(sha1sum $env_file | cut -d' ' -f1)
+    # Get the output from `cksum` and join the first two words with a dot.
+    env_cksum=${(j:.:)${:-$(cksum "$env_file")}[1,2]}
   fi
-  echo ":${env_file}:${env_shasum}:1"
+  echo ":${env_file}:${env_cksum}:1"
 }
 
 _autoenv_authorized_env_file() {
index 06025b67827c3562296052ec21e0e004099e298b..bf46c836654f6b1375f470473d9d6603e9d58179 100644 (file)
@@ -35,41 +35,41 @@ Now adding some auth pair.
   $ echo first > first
   $ _autoenv_authorize first
   $ cat $AUTOENV_AUTH_FILE
-  :/tmp/cramtests-*/_autoenv_utils.t/first:271ac93c44ac198d92e706c6d6f1d84aefcfa337:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/first:2715464726.6:1 (glob)
 
 And a second one.
 
   $ echo second > second
   $ _autoenv_authorize second
   $ cat $AUTOENV_AUTH_FILE
-  :/tmp/cramtests-*/_autoenv_utils.t/first:271ac93c44ac198d92e706c6d6f1d84aefcfa337:1 (glob)
-  :/tmp/cramtests-*/_autoenv_utils.t/second:7bee8f3b184e1e141ff76efe369c3b8bfc50e64c:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/first:2715464726.6:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/second:594940475.7:1 (glob)
 
 And a third.
 
   $ echo third > third
   $ _autoenv_authorize third
   $ cat $AUTOENV_AUTH_FILE
-  :/tmp/cramtests-*/_autoenv_utils.t/first:271ac93c44ac198d92e706c6d6f1d84aefcfa337:1 (glob)
-  :/tmp/cramtests-*/_autoenv_utils.t/second:7bee8f3b184e1e141ff76efe369c3b8bfc50e64c:1 (glob)
-  :/tmp/cramtests-*/_autoenv_utils.t/third:ad180453bf8a374a15df3e90a78c180230146a7c:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/first:2715464726.6:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/second:594940475.7:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/third:451243482.6:1 (glob)
 
 Re-add the second one, with the same hash.
 
   $ _autoenv_authorize second
   $ cat $AUTOENV_AUTH_FILE
-  :/tmp/cramtests-*/_autoenv_utils.t/first:271ac93c44ac198d92e706c6d6f1d84aefcfa337:1 (glob)
-  :/tmp/cramtests-*/_autoenv_utils.t/third:ad180453bf8a374a15df3e90a78c180230146a7c:1 (glob)
-  :/tmp/cramtests-*/_autoenv_utils.t/second:7bee8f3b184e1e141ff76efe369c3b8bfc50e64c:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/first:2715464726.6:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/third:451243482.6:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/second:594940475.7:1 (glob)
 
 Re-add the first one, with a new hash.
 
   $ echo one more line >> first
   $ _autoenv_authorize first
   $ cat $AUTOENV_AUTH_FILE
-  :/tmp/cramtests-*/_autoenv_utils.t/third:ad180453bf8a374a15df3e90a78c180230146a7c:1 (glob)
-  :/tmp/cramtests-*/_autoenv_utils.t/second:7bee8f3b184e1e141ff76efe369c3b8bfc50e64c:1 (glob)
-  :/tmp/cramtests-*/_autoenv_utils.t/first:65eb010197b73ddc109b7210080f97a87f53451e:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/third:451243482.6:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/second:594940475.7:1 (glob)
+  :/tmp/cramtests-*/_autoenv_utils.t/first:3620404822.20:1 (glob)
 }}}