zsh-workers
 help / color / mirror / code / Atom feed
* [RFC or so] Add HASH_LOOKUP option
@ 2010-08-23 14:09 Mikael Magnusson
  2010-08-23 14:55 ` Peter Stephenson
  2010-08-23 17:46 ` Bart Schaefer
  0 siblings, 2 replies; 6+ messages in thread
From: Mikael Magnusson @ 2010-08-23 14:09 UTC (permalink / raw)
  To: zsh workers

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-06-02 15:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-23 14:09 [RFC or so] Add HASH_LOOKUP option Mikael Magnusson
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

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).