Petr Šabata 33fc6c
From f747f9ff4c8aed2d51fa54db3cb10e8118034753 Mon Sep 17 00:00:00 2001
Petr Šabata 33fc6c
From: Chet Ramey <chet.ramey@case.edu>
Petr Šabata 33fc6c
Date: Fri, 7 Feb 2020 15:17:29 -0500
Petr Šabata 33fc6c
Subject: [PATCH] Bash-5.0 patch 13: reading history entries with timestamps
Petr Šabata 33fc6c
 can result in joined entries
Petr Šabata 33fc6c
Petr Šabata 33fc6c
---
Petr Šabata 33fc6c
 lib/readline/histfile.c | 15 ++++++++++++++-
Petr Šabata 33fc6c
 patchlevel.h            |  2 +-
Petr Šabata 33fc6c
 2 files changed, 15 insertions(+), 2 deletions(-)
Petr Šabata 33fc6c
Petr Šabata 33fc6c
diff --git a/lib/readline/histfile.c b/lib/readline/histfile.c
Petr Šabata 33fc6c
index a8a92aa3..6c3adc9b 100644
Petr Šabata 33fc6c
--- a/lib/readline/histfile.c
Petr Šabata 33fc6c
+++ b/lib/readline/histfile.c
Petr Šabata 33fc6c
@@ -369,9 +369,11 @@ read_history_range (const char *filename, int from, int to)
Petr Šabata 33fc6c
     }
Petr Šabata 33fc6c
 
Petr Šabata 33fc6c
   has_timestamps = HIST_TIMESTAMP_START (buffer);
Petr Šabata 33fc6c
-  history_multiline_entries += has_timestamps && history_write_timestamps;  
Petr Šabata 33fc6c
+  history_multiline_entries += has_timestamps && history_write_timestamps;
Petr Šabata 33fc6c
 
Petr Šabata 33fc6c
   /* Skip lines until we are at FROM. */
Petr Šabata 33fc6c
+  if (has_timestamps)
Petr Šabata 33fc6c
+    last_ts = buffer;
Petr Šabata 33fc6c
   for (line_start = line_end = buffer; line_end < bufend && current_line < from; line_end++)
Petr Šabata 33fc6c
     if (*line_end == '\n')
Petr Šabata 33fc6c
       {
Petr Šabata 33fc6c
@@ -380,7 +382,18 @@ read_history_range (const char *filename, int from, int to)
Petr Šabata 33fc6c
 	   line.  We should check more extensively here... */
Petr Šabata 33fc6c
 	if (HIST_TIMESTAMP_START(p) == 0)
Petr Šabata 33fc6c
 	  current_line++;
Petr Šabata 33fc6c
+	else
Petr Šabata 33fc6c
+	  last_ts = p;
Petr Šabata 33fc6c
 	line_start = p;
Petr Šabata 33fc6c
+	/* If we are at the last line (current_line == from) but we have
Petr Šabata 33fc6c
+	   timestamps (has_timestamps), then line_start points to the
Petr Šabata 33fc6c
+	   text of the last command, and we need to skip to its end. */
Petr Šabata 33fc6c
+	if (current_line >= from && has_timestamps)
Petr Šabata 33fc6c
+	  {
Petr Šabata 33fc6c
+	    for (line_end = p; line_end < bufend && *line_end != '\n'; line_end++)
Petr Šabata 33fc6c
+	      ;
Petr Šabata 33fc6c
+	    line_start = (*line_end == '\n') ? line_end + 1 : line_end;
Petr Šabata 33fc6c
+	  }
Petr Šabata 33fc6c
       }
Petr Šabata 33fc6c
 
Petr Šabata 33fc6c
   /* If there are lines left to gobble, then gobble them now. */
Petr Šabata 33fc6c
diff --git a/patchlevel.h b/patchlevel.h
Petr Šabata 33fc6c
index 93dbe0db..779671cd 100644
Petr Šabata 33fc6c
--- a/patchlevel.h
Petr Šabata 33fc6c
+++ b/patchlevel.h
Petr Šabata 33fc6c
@@ -25,6 +25,6 @@
Petr Šabata 33fc6c
    regexp `^#define[ 	]*PATCHLEVEL', since that's what support/mkversion.sh
Petr Šabata 33fc6c
    looks for to find the patch level (for the sccs version string). */
Petr Šabata 33fc6c
 
Petr Šabata 33fc6c
-#define PATCHLEVEL 12
Petr Šabata 33fc6c
+#define PATCHLEVEL 13
Petr Šabata 33fc6c
 
Petr Šabata 33fc6c
 #endif /* _PATCHLEVEL_H_ */
Petr Šabata 33fc6c
-- 
Petr Šabata 33fc6c
2.25.1
Petr Šabata 33fc6c