Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: HIST_IGNORE_DUPS also ignores command lines that differ by a space between quotes



I think HIST_IGNORE_DUPS would work as expected even without
HIST_REDUCCE_BLANKS if we use the information in chwords and
hist_ring->words, as in the patch below, for example.

we can't simply replace histstrcmp() with the one that uses
the words[] array in struct histent. But I think Bart's patch
is enough for HIST_IGNORE_ALL_DUPS and history searching
(and recommend users to set HIST_REDUCCE_BLANKS).



diff --git a/Src/hist.c b/Src/hist.c
index 1a00c30ed..3a52ee038 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -1467,6 +1467,36 @@ should_ignore_line(Eprog prog)
     return 0;
 }
 
+/*
+ * compare the history entry in {chline,chwords} with the previous
+ * one in hist_ring->{node.nam,words}. Returns 0 if the two are equal
+ * (except for insignificant spaces), nonzero otherwise.
+ */
+
+/**/
+static int
+hist_compare(void)
+{
+    int i;
+
+    if (isset(HISTREDUCEBLANKS))
+	return strcmp(chline, hist_ring->node.nam);
+    if (chwordpos/2 != hist_ring->nwords)
+	return 1;
+    for (i = 0; i < chwordpos; i += 2) {
+	const char *p = &chline[chwords[i]];
+	const char *q = &hist_ring->node.nam[hist_ring->words[i]];
+	int n = chwords[i+1] - chwords[i], j;
+
+	if (n != hist_ring->words[i+1] - hist_ring->words[i])
+	    return 1;
+	for (j=0; j < n; ++j)
+	    if (p[j] != q[j])
+		return 1;
+    }
+    return 0;
+}
+
 /* say we're done using the history mechanism */
 
 /**/
@@ -1600,7 +1630,7 @@ hend(Eprog prog)
 	else
 	    newflags = 0;
 	if ((isset(HISTIGNOREDUPS) || isset(HISTIGNOREALLDUPS)) && save > 0
-	 && hist_ring && histstrcmp(chline, hist_ring->node.nam) == 0) {
+	 && hist_ring && hist_compare() == 0) {
 	    /* This history entry compares the same as the previous.
 	     * In case minor changes were made, we overwrite the
 	     * previous one with the current one.  This also gets the






Messages sorted by: Reverse Date, Date, Thread, Author