Skip to content

Commit

Permalink
fix: backport comparable check to <1.20
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
  • Loading branch information
sagikazarmark committed Dec 18, 2023
1 parent 58a4c3b commit 379c776
Show file tree
Hide file tree
Showing 23 changed files with 237 additions and 1 deletion.
1 change: 1 addition & 0 deletions .devenv/profile
19 changes: 19 additions & 0 deletions .direnv/bin/nix-direnv-reload
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -e
if [[ ! -d "/Users/mark/Projects/viper/mapstructure" ]]; then
echo "Cannot find source directory; Did you move it?"
echo "(Looking for "/Users/mark/Projects/viper/mapstructure")"
echo 'Cannot force reload with this script - use "direnv reload" manually and then try again'
exit 1
fi

# rebuild the cache forcefully
_nix_direnv_force_reload=1 direnv exec "/Users/mark/Projects/viper/mapstructure" true

# Update the mtime for .envrc.
# This will cause direnv to reload again - but without re-building.
touch "/Users/mark/Projects/viper/mapstructure/.envrc"

# Also update the timestamp of whatever profile_rc we have.
# This makes sure that we know we are up to date.
touch -r "/Users/mark/Projects/viper/mapstructure/.envrc" "/Users/mark/Projects/viper/mapstructure/.direnv"/*.rc
180 changes: 180 additions & 0 deletions .direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
unset shellHook
PATH=${PATH:-}
nix_saved_PATH="$PATH"
XDG_DATA_DIRS=${XDG_DATA_DIRS:-}
nix_saved_XDG_DATA_DIRS="$XDG_DATA_DIRS"
BASH='/nix/store/8rxm4jzw1dddm53rpc2zdqgafadn7d5n-bash-interactive-5.2-p21/bin/bash'
HOSTTYPE='aarch64'
IFS='
'
IN_NIX_SHELL='impure'
export IN_NIX_SHELL
LINENO='76'
MACHTYPE='aarch64-apple-darwin22.6.0'
NIX_BUILD_CORES='0'
export NIX_BUILD_CORES
NIX_STORE='/nix/store'
export NIX_STORE
OLDPWD=''
export OLDPWD
OPTERR='1'
OSTYPE='darwin22.6.0'
PATH='/path-not-set'
export PATH
PS4='+ '
builder='/nix/store/8rxm4jzw1dddm53rpc2zdqgafadn7d5n-bash-interactive-5.2-p21/bin/bash'
export builder
dontAddDisableDepTrack='1'
export dontAddDisableDepTrack
name='devenv-shell-env'
export name
out='/Users/mark/Projects/viper/mapstructure/outputs/out'
export out
outputs='out'
shellHook='
# Remove all the unnecessary noise that is set by the build env
unset NIX_BUILD_TOP NIX_BUILD_CORES NIX_STORE
unset TEMP TEMPDIR TMP
# $name variable is preserved to keep it compatible with pure shell https://github.com/sindresorhus/pure/blob/47c0c881f0e7cfdb5eaccd335f52ad17b897c060/pure.zsh#L235
unset builder out shellHook stdenv system
# Flakes stuff
unset dontAddDisableDepTrack outputs

# For `nix develop`. We get /noshell on Linux and /sbin/nologin on macOS.
if [[ "$SHELL" == "/noshell" || "$SHELL" == "/sbin/nologin" ]]; then
export SHELL=/nix/store/8rxm4jzw1dddm53rpc2zdqgafadn7d5n-bash-interactive-5.2-p21/bin/bash
fi

# https://github.com/numtide/devshell/issues/158
PATH=${PATH#/path-not-set:}

export DEVENV_PROFILE=/nix/store/7k68a83zyk7wzkjaa5kplgjqsyi4wpwd-devenv-profile

# add installed packages to PATH
export PATH="$DEVENV_PROFILE/bin:$PATH"

# prepend common compilation lookup paths
export PKG_CONFIG_PATH="$DEVENV_PROFILE/lib/pkgconfig:${PKG_CONFIG_PATH-}"
export LD_LIBRARY_PATH="$DEVENV_PROFILE/lib:${LD_LIBRARY_PATH-}"
export LIBRARY_PATH="$DEVENV_PROFILE/lib:${LIBRARY_PATH-}"
export C_INCLUDE_PATH="$DEVENV_PROFILE/include:${C_INCLUDE_PATH-}"

# these provide shell completions / default config options
export XDG_DATA_DIRS="$DEVENV_PROFILE/share:${XDG_DATA_DIRS-}"
export XDG_CONFIG_DIRS="$DEVENV_PROFILE/etc/xdg:${XDG_CONFIG_DIRS-}"

export DEVENV_DOTFILE='\''/Users/mark/Projects/viper/mapstructure/.devenv'\''
export DEVENV_PROFILE='\''/nix/store/7k68a83zyk7wzkjaa5kplgjqsyi4wpwd-devenv-profile'\''
export DEVENV_ROOT='\''/Users/mark/Projects/viper/mapstructure'\''
export DEVENV_STATE='\''/Users/mark/Projects/viper/mapstructure/.devenv/state'\''
export GOPATH='\''/Users/mark/Projects/viper/mapstructure/.devenv/state/go'\''
export GOROOT='\''/nix/store/b0rpa34hn6cgbkbn8sfr5dzv723ia3z2-go-1.21.5/share/go/'\''

export PATH=/nix/store/zf05xsah3wfzcsb667ncxlj7xkgjpi20-pre-commit-3.3.3/bin:$PATH
if ! type -t git >/dev/null; then
# This happens in pure shells, including lorri
echo 1>&2 "WARNING: pre-commit-hooks.nix: git command not found; skipping installation."
elif ! /nix/store/q7avibx4c00h7zl3jfh3r5mc4xs6wsnj-git-2.42.0/bin/git rev-parse --git-dir &> /dev/null; then
echo 1>&2 "WARNING: pre-commit-hooks.nix: .git not found; skipping installation."
else
GIT_WC=`/nix/store/q7avibx4c00h7zl3jfh3r5mc4xs6wsnj-git-2.42.0/bin/git rev-parse --show-toplevel`

# These update procedures compare before they write, to avoid
# filesystem churn. This improves performance with watch tools like lorri
# and prevents installation loops by via lorri.

if readlink "${GIT_WC}/.pre-commit-config.yaml" >/dev/null \
&& [[ $(readlink "${GIT_WC}/.pre-commit-config.yaml") == /nix/store/3ws5xna2njkw8s4l002r5w80jrgq1wl9-pre-commit-config.json ]]; then
echo 1>&2 "pre-commit-hooks.nix: hooks up to date"
else
echo 1>&2 "pre-commit-hooks.nix: updating $PWD repo"

[ -L .pre-commit-config.yaml ] && unlink .pre-commit-config.yaml

if [ -e "${GIT_WC}/.pre-commit-config.yaml" ]; then
echo 1>&2 "pre-commit-hooks.nix: WARNING: Refusing to install because of pre-existing .pre-commit-config.yaml"
echo 1>&2 " 1. Translate .pre-commit-config.yaml contents to the new syntax in your Nix file"
echo 1>&2 " see https://github.com/cachix/pre-commit-hooks.nix#getting-started"
echo 1>&2 " 2. remove .pre-commit-config.yaml"
echo 1>&2 " 3. add .pre-commit-config.yaml to .gitignore"
else
ln -fs /nix/store/3ws5xna2njkw8s4l002r5w80jrgq1wl9-pre-commit-config.json "${GIT_WC}/.pre-commit-config.yaml"
# Remove any previously installed hooks (since pre-commit itself has no convergent design)
hooks="pre-commit pre-merge-commit pre-push prepare-commit-msg commit-msg post-checkout post-commit"
for hook in $hooks; do
pre-commit uninstall -t $hook
done
/nix/store/q7avibx4c00h7zl3jfh3r5mc4xs6wsnj-git-2.42.0/bin/git config --local core.hooksPath ""
# Add hooks for configured stages (only) ...
if [ ! -z "commit" ]; then
for stage in commit; do
if [[ "$stage" == "manual" ]]; then
continue
fi
case $stage in
# if you amend these switches please also review $hooks above
commit | merge-commit | push)
stage="pre-"$stage
pre-commit install -t $stage
;;
prepare-commit-msg | commit-msg | post-checkout | post-commit)
pre-commit install -t $stage
;;
*)
echo 1>&2 "ERROR: pre-commit-hooks.nix: either $stage is not a valid stage or pre-commit-hooks.nix doesn'\''t yet support it."
exit 1
;;
esac
done
# ... or default '\''pre-commit'\'' hook
else
pre-commit install
fi
/nix/store/q7avibx4c00h7zl3jfh3r5mc4xs6wsnj-git-2.42.0/bin/git config --local core.hooksPath "$(/nix/store/q7avibx4c00h7zl3jfh3r5mc4xs6wsnj-git-2.42.0/bin/git rev-parse --git-common-dir)/hooks"
fi
fi
fi


export PATH=$GOPATH/bin:$PATH

export PS1="\[\e[0;34m\](devenv)\[\e[0m\] ${PS1-}"

# set path to locales on non-NixOS Linux hosts


# note what environments are active, but make sure we don'\''t repeat them
if [[ ! "${DIRENV_ACTIVE-}" =~ (^|:)"$PWD"(:|$) ]]; then
export DIRENV_ACTIVE="$PWD:${DIRENV_ACTIVE-}"
fi

# devenv helper
if [ ! type -p direnv &>/dev/null && -f .envrc ]; then
echo "You have .envrc but direnv command is not installed."
echo "Please install direnv: https://direnv.net/docs/installation.html"
fi

mkdir -p .devenv
rm -f .devenv/profile
ln -s /nix/store/7k68a83zyk7wzkjaa5kplgjqsyi4wpwd-devenv-profile .devenv/profile

'
export shellHook
stdenv='/nix/store/4dmdxaw0gzx9ns4n60kczbhsm0qlq3zz-naked-stdenv'
export stdenv
system='aarch64-darwin'
export system
runHook ()
{

eval "$shellHook";
unset runHook
}
PATH="$PATH${nix_saved_PATH:+:$nix_saved_PATH}"
XDG_DATA_DIRS="$XDG_DATA_DIRS${nix_saved_XDG_DATA_DIRS:+:$nix_saved_XDG_DATA_DIRS}"
export NIX_BUILD_TOP="$(mktemp -d -t nix-shell.XXXXXX)"
export TMP="$NIX_BUILD_TOP"
export TMPDIR="$NIX_BUILD_TOP"
export TEMP="$NIX_BUILD_TOP"
export TEMPDIR="$NIX_BUILD_TOP"
eval "$shellHook"
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
2 changes: 1 addition & 1 deletion mapstructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ func (d *Decoder) decodeArray(name string, data interface{}, val reflect.Value)

valArray := val

if valArray.Comparable() && valArray.Interface() == reflect.Zero(valArray.Type()).Interface() || d.config.ZeroFields {
if isComparable(valArray) && valArray.Interface() == reflect.Zero(valArray.Type()).Interface() || d.config.ZeroFields {
// Check input type
if dataValKind != reflect.Array && dataValKind != reflect.Slice {
if d.config.WeaklyTypedInput {
Expand Down
9 changes: 9 additions & 0 deletions reflect_go1_19.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build !go1.20

package mapstructure

import "reflect"

func isComparable(v reflect.Value) bool {
return false
}
10 changes: 10 additions & 0 deletions reflect_go1_20.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build go1.20

package mapstructure

import "reflect"

// TODO: remove once we drop support for Go <1.20
func isComparable(v reflect.Value) bool {
return v.Comparable()
}

0 comments on commit 379c776

Please sign in to comment.