From 97243fe091ab7ce2abc824676cc912cc88e8b7145578103c723b81062b5dc881 Mon Sep 17 00:00:00 2001 From: "Dr. Werner Fink" Date: Fri, 21 Jul 2023 11:26:28 +0000 Subject: [PATCH 1/3] Skip workaround but disable fastMergeErase instead to really be able to merge currently history with history file OBS-URL: https://build.opensuse.org/package/show/shells/tcsh?expand=0&rev=156 --- tcsh-6.24.10-history-merge.dif | 74 +++++++++------------------------- tcsh.changes | 7 ++++ 2 files changed, 26 insertions(+), 55 deletions(-) diff --git a/tcsh-6.24.10-history-merge.dif b/tcsh-6.24.10-history-merge.dif index 8f00107..a340f76 100644 --- a/tcsh-6.24.10-history-merge.dif +++ b/tcsh-6.24.10-history-merge.dif @@ -1,60 +1,24 @@ --- - sh.hist.c | 22 +++++++++++++++++----- - 1 file changed, 17 insertions(+), 5 deletions(-) + sh.hist.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) --- sh.hist.c -+++ sh.hist.c 2023-07-13 09:18:13.149624778 +0000 -@@ -105,7 +105,7 @@ hremove(struct Hist *hp) ++++ sh.hist.c 2023-07-21 09:38:31.303857784 +0000 +@@ -64,7 +64,7 @@ static void hfree (struct Hist *); - /* Prune length of history list to specified size by history variable. */ - PG_STATIC void --discardExcess(int hlen) -+discardExcess(int hlen, int mflg) - { - struct Hist *hp, *np; - if (histTail == NULL) { -@@ -116,13 +116,13 @@ discardExcess(int hlen) - * the list is still too long scan the whole list as before. But only do a - * full scan if the list is more than 6% (1/16th) too long. */ - while (histCount > (unsigned)hlen && (np = Histlist.Hnext)) { -- if (eventno - np->Href >= hlen || hlen == 0) -+ if ((eventno - np->Href >= hlen || hlen == 0) && !mflg) - hremove(np), hfree(np); - else - break; - } - while (histCount > (unsigned)hlen && (np = histTail) != &Histlist) { -- if (eventno - np->Href >= hlen || hlen == 0) -+ if (eventno - np->Href >= hlen || hlen == 0 || mflg) - hremove(np), hfree(np); - else - break; -@@ -148,7 +148,7 @@ savehist( - return; - if (sp) - (void) enthist(++eventno, sp, 1, mflg, histlen); -- discardExcess(histlen); -+ discardExcess(histlen, mflg); - } + /* #define DEBUG_HIST 1 */ - #define USE_JENKINS_HASH 1 -@@ -1404,6 +1404,18 @@ loadhist(Char *fname, int mflg) - void - sethistory(int n) - { -+ int mflg = 0; -+ struct varent *shist; -+ -+ if ((shist = adrof(STRsavehist)) != NULL && shist->vec != NULL) { -+ size_t i; -+ for (i = 1; shist->vec[i]; i++) { -+ if (eq(shist->vec[i], STRmerge)) { -+ mflg++; -+ break; -+ } -+ } -+ } - histlen = n; -- discardExcess(histlen); -+ discardExcess(histlen, mflg); - } +-static const int fastMergeErase = 1; ++static const int fastMergeErase = 0; /* Was true, now false to merge even with full history list */ + static unsigned histCount = 0; /* number elements on history list */ + static int histlen = 0; + static struct Hist *histTail = NULL; /* last element on history list */ +@@ -1393,7 +1393,7 @@ loadhist(Char *fname, int mflg) + /* During history merging (enthist sees mflg set), we disable management of + * Hnum and Href (because fastMergeErase is true). So now reset all the + * values based on the final ordering of the history list. */ +- if (mflg) { ++ if (mflg && fastMergeErase) { + int n = eventno; + struct Hist *hp = &Histlist; + while ((hp = hp->Hnext)) diff --git a/tcsh.changes b/tcsh.changes index c18021c..b0ec957 100644 --- a/tcsh.changes +++ b/tcsh.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Fri Jul 21 09:19:02 UTC 2023 - Dr. Werner Fink + +- Modify tcsh-6.24.10-history-merge.dif + * Skip workaround but disable fastMergeErase instead to really be + able to merge currently history with history file (bsc#1213484) + ------------------------------------------------------------------- Fri Jul 14 11:29:02 UTC 2023 - Dr. Werner Fink From 760b8e23d6bcfcadac88c3eed4346a0042b4c087913015a8dbafdafd8941b555 Mon Sep 17 00:00:00 2001 From: "Dr. Werner Fink" Date: Fri, 21 Jul 2023 12:26:09 +0000 Subject: [PATCH 2/3] Avoid failed history erase mode OBS-URL: https://build.opensuse.org/package/show/shells/tcsh?expand=0&rev=157 --- tcsh-6.24.10-history-merge.dif | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tcsh-6.24.10-history-merge.dif b/tcsh-6.24.10-history-merge.dif index a340f76..039b07c 100644 --- a/tcsh-6.24.10-history-merge.dif +++ b/tcsh-6.24.10-history-merge.dif @@ -1,19 +1,27 @@ --- - sh.hist.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) + sh.hist.c | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) --- sh.hist.c -+++ sh.hist.c 2023-07-21 09:38:31.303857784 +0000 ++++ sh.hist.c 2023-07-21 12:21:55.518480015 +0000 @@ -64,7 +64,7 @@ static void hfree (struct Hist *); /* #define DEBUG_HIST 1 */ -static const int fastMergeErase = 1; -+static const int fastMergeErase = 0; /* Was true, now false to merge even with full history list */ ++static int fastMergeErase = 1; static unsigned histCount = 0; /* number elements on history list */ static int histlen = 0; static struct Hist *histTail = NULL; /* last element on history list */ -@@ -1393,7 +1393,7 @@ loadhist(Char *fname, int mflg) +@@ -1321,6 +1321,7 @@ rechist(Char *xfname, int ref) + } + + if (merge) { ++ fastMergeErase = 0; /* Was true, now false to merge even with full history list */ + jmp_buf_t osetexit; + if (lock) { + #ifndef WINNT_NATIVE +@@ -1393,7 +1394,7 @@ loadhist(Char *fname, int mflg) /* During history merging (enthist sees mflg set), we disable management of * Hnum and Href (because fastMergeErase is true). So now reset all the * values based on the final ordering of the history list. */ From dcef063dbb340e9c2e12430b72b7a729760aca44ad1663ac20408634ba562068 Mon Sep 17 00:00:00 2001 From: "Dr. Werner Fink" Date: Mon, 24 Jul 2023 08:12:57 +0000 Subject: [PATCH 3/3] Add a test case for history merge OBS-URL: https://build.opensuse.org/package/show/shells/tcsh?expand=0&rev=158 --- tcsh-6.24.10-history-merge.dif | 57 +++++++++++++++++++++++++++++++++- tcsh.changes | 6 ++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/tcsh-6.24.10-history-merge.dif b/tcsh-6.24.10-history-merge.dif index 039b07c..4dc4bf7 100644 --- a/tcsh-6.24.10-history-merge.dif +++ b/tcsh-6.24.10-history-merge.dif @@ -26,7 +26,62 @@ * Hnum and Href (because fastMergeErase is true). So now reset all the * values based on the final ordering of the history list. */ - if (mflg) { -+ if (mflg && fastMergeErase) { ++ if (mflg /* && fastMergeErase */) { int n = eventno; struct Hist *hp = &Histlist; while ((hp = hp->Hnext)) +--- tests/history.at ++++ tests/history.at 2023-07-24 07:53:41.471413277 +0000 +@@ -218,6 +218,52 @@ dnl savehist) set to 0 instead of 1. + + AT_CLEANUP() + ++AT_SETUP([History merge]) ++dnl Check if history merge really works out ++ ++AT_DATA([hist-merge.csh], ++[[set histfile=test.history histdup=prev history=(6 "%h TIME %R\n") ++set savehist=(6 merge) ++printf "'%s' %s\n" "$histdup" "$history" ++history -c ++: 1 ++: 2 ++: 3 ++: 4 ++: 5 ++history -S ++: a ++: b ++: c ++: d ++: e ++history -S ++history -L ++history 6 ++]]) ++ ++AT_CHECK([tcsh -f -q -i < hist-merge.csh], , ++[> 'prev' 6 %h TIME %R\n ++ 24 TIME : b ++ 25 TIME : c ++ 26 TIME : d ++ 27 TIME : e ++ 28 TIME history -S ++ 29 TIME history 6 ++> exit ++],) ++ ++dnl In broken case we see the former history instead ++dnl > 'prev' 6 %h TIME %R\n ++dnl 24 TIME : 4 ++dnl 25 TIME : 3 ++dnl 26 TIME : 2 ++dnl 27 TIME : 1 ++dnl 28 TIME history -S ++dnl 29 TIME history 6 ++dnl > exit ++ ++AT_CLEANUP() + + dnl + dnl History faults diff --git a/tcsh.changes b/tcsh.changes index b0ec957..cdf8cc8 100644 --- a/tcsh.changes +++ b/tcsh.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Mon Jul 24 08:12:01 UTC 2023 - Dr. Werner Fink + +- Extend tcsh-6.24.10-history-merge.dif + * Add a test case + ------------------------------------------------------------------- Fri Jul 21 09:19:02 UTC 2023 - Dr. Werner Fink