zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: [RFC or so] Add HASH_LOOKUP option
Date: Mon, 23 Aug 2010 16:09:45 +0200	[thread overview]
Message-ID: <AANLkTim0NXjt4hp-UV4PK_7wNS2+tvf8NOu9W8F9RUSD@mail.gmail.com> (raw)

When this is unset, external commands are always resolved with a full
path search, but still inserted into the hash for spell correction if
those options are on.

Caveat: I have not verified all possible paths that use the hash check
for this, but at least =cmd and which -p cmd and actually running cmd
do check it.
---

This was motivated by wycats (Yehuda Katz) on IRC having troubles with
his users running gem install bundler or so, and then getting
segfaults because of mismatches between ruby versions and whatnot, and
they didn't know to run rehash. Adding this option of course doesn't
help him that much since I'm not sure if A) we want to 1) have it at
all 2) default it to on B) it would reach distros anytime soon.

Also by the fact that doing a full path search is probably not that
slow for most people, and I know that some people have resorted to
putting hash -r in their precmd() functions which is of course slower
than just doing the path search since HASH_DIRS defaults to on.

If it turns out to be a good idea, I will of course include
documentation in the followup patch, but for now I won't bother.

 Src/exec.c    |   10 ++++++++--
 Src/options.c |    1 +
 Src/zsh.h     |    1 +
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/Src/exec.c b/Src/exec.c
index 93d1b26..9a488fe 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -754,7 +754,7 @@ findcmd(char *arg0, int docopy)
 	    }
 	    break;
 	}
-    if (cn) {
+    if (cn && isset(HASHLOOKUP)) {
 	char nn[PATH_MAX];

 	if (cn->node.flags & HASHED)
@@ -2708,7 +2708,13 @@ execcmd(Estate state, int input, int output,
int how, int last1)
 	    char **checkpath = pathchecked;
 	    int dohashcmd = isset(HASHCMDS);

-	    hn = cmdnamtab->getnode(cmdnamtab, cmdarg);
+            if (isset(HASHLOOKUP))
+		hn = cmdnamtab->getnode(cmdnamtab, cmdarg);
+            else {
+                hn = NULL;
+                dohashcmd = 1;
+                checkpath = path;
+            }
 	    if (hn && trycd && !isreallycom((Cmdnam)hn)) {
 		if (!(((Cmdnam)hn)->node.flags & HASHED)) {
 		    checkpath = path;
diff --git a/Src/options.c b/Src/options.c
index dedbf0c..fe720fd 100644
--- a/Src/options.c
+++ b/Src/options.c
@@ -141,6 +141,7 @@ static struct optname optns[] = {
 {{NULL, "hashcmds",	      OPT_ALL},			 HASHCMDS},
 {{NULL, "hashdirs",	      OPT_ALL},			 HASHDIRS},
 {{NULL, "hashlistall",	      OPT_ALL},			 HASHLISTALL},
+{{NULL, "hashlookup",         OPT_ALL},                  HASHLOOKUP},
 {{NULL, "histallowclobber",   0},			 HISTALLOWCLOBBER},
 {{NULL, "histbeep",	      OPT_ALL},			 HISTBEEP},
 {{NULL, "histexpiredupsfirst",0},			 HISTEXPIREDUPSFIRST},
diff --git a/Src/zsh.h b/Src/zsh.h
index 4485bd3..1dd5760 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -1928,6 +1928,7 @@ enum {
     HASHCMDS,
     HASHDIRS,
     HASHLISTALL,
+    HASHLOOKUP,
     HISTALLOWCLOBBER,
     HISTBEEP,
     HISTEXPIREDUPSFIRST,
-- 
1.7.2

http://git.mika.l3ib.org/?p=zsh-cvs.git;a=patch;h=5e75cf283aa470ac28c94c6c3dd9e2bb0ea9cec1
if anyone actually wants to try it since I usually post garbled
patches.

-- 
Mikael Magnusson


             reply	other threads:[~2010-08-23 14:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-23 14:09 Mikael Magnusson [this message]
2010-08-23 14:55 ` Peter Stephenson
2010-08-23 17:46 ` Bart Schaefer
2010-08-23 18:25   ` Mikael Magnusson
2010-08-24  8:37     ` Bart Schaefer
2011-06-02 15:11   ` Mikael Magnusson

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=AANLkTim0NXjt4hp-UV4PK_7wNS2+tvf8NOu9W8F9RUSD@mail.gmail.com \
    --to=mikachu@gmail.com \
    --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).