[llvm] e48c7fe - Reland '[lineeditor] Add `setHistorySize()` method for adjusting history size' (#115442)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 2 05:17:54 PST 2024
Author: Devajith
Date: 2024-12-02T15:17:51+02:00
New Revision: e48c7fe49f8575b7737d07ac5a71d1fc924d37f7
URL: https://github.com/llvm/llvm-project/commit/e48c7fe49f8575b7737d07ac5a71d1fc924d37f7
DIFF: https://github.com/llvm/llvm-project/commit/e48c7fe49f8575b7737d07ac5a71d1fc924d37f7.diff
LOG: Reland '[lineeditor] Add `setHistorySize()` method for adjusting history size' (#115442)
Reland: https://github.com/llvm/llvm-project/pull/110092
Buildbot was failing due to an unused variable warning as there were 2
implementations (with and without libedit). Compared to last version,
wrap the variable inside the `#ifdef HAVE_LIBEDIT`.
Apologies for the oversight @vgvassilev
Added:
Modified:
llvm/include/llvm/LineEditor/LineEditor.h
llvm/lib/LineEditor/LineEditor.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/LineEditor/LineEditor.h b/llvm/include/llvm/LineEditor/LineEditor.h
index 29fdf9f85c6fa5..ca0312bf6297f5 100644
--- a/llvm/include/llvm/LineEditor/LineEditor.h
+++ b/llvm/include/llvm/LineEditor/LineEditor.h
@@ -41,6 +41,7 @@ class LineEditor {
void saveHistory();
void loadHistory();
+ void setHistorySize(int size);
static std::string getDefaultHistoryPath(StringRef ProgName);
diff --git a/llvm/lib/LineEditor/LineEditor.cpp b/llvm/lib/LineEditor/LineEditor.cpp
index d0d138bb1f9d8d..c7d5fd7dcf8ac5 100644
--- a/llvm/lib/LineEditor/LineEditor.cpp
+++ b/llvm/lib/LineEditor/LineEditor.cpp
@@ -17,6 +17,7 @@
#include <cstdio>
#ifdef HAVE_LIBEDIT
#include <histedit.h>
+constexpr int DefaultHistorySize = 800;
#endif
using namespace llvm;
@@ -220,8 +221,8 @@ LineEditor::LineEditor(StringRef ProgName, StringRef HistoryPath, FILE *In,
NULL); // Fix the delete key.
::el_set(Data->EL, EL_CLIENTDATA, Data.get());
+ setHistorySize(DefaultHistorySize);
HistEvent HE;
- ::history(Data->Hist, &HE, H_SETSIZE, 800);
::history(Data->Hist, &HE, H_SETUNIQUE, 1);
loadHistory();
}
@@ -248,6 +249,11 @@ void LineEditor::loadHistory() {
}
}
+void LineEditor::setHistorySize(int size) {
+ HistEvent HE;
+ ::history(Data->Hist, &HE, H_SETSIZE, size);
+}
+
std::optional<std::string> LineEditor::readLine() const {
// Call el_gets to prompt the user and read the user's input.
int LineLen = 0;
@@ -291,6 +297,7 @@ LineEditor::~LineEditor() {
void LineEditor::saveHistory() {}
void LineEditor::loadHistory() {}
+void LineEditor::setHistorySize(int size) {}
std::optional<std::string> LineEditor::readLine() const {
::fprintf(Data->Out, "%s", Prompt.c_str());
More information about the llvm-commits
mailing list