Skip to content

Commit e48c7fe

Browse files
authored
Reland '[lineeditor] Add setHistorySize() method for adjusting history size' (#115442)
Reland: #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
1 parent c1dcf75 commit e48c7fe

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

llvm/include/llvm/LineEditor/LineEditor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class LineEditor {
4141

4242
void saveHistory();
4343
void loadHistory();
44+
void setHistorySize(int size);
4445

4546
static std::string getDefaultHistoryPath(StringRef ProgName);
4647

llvm/lib/LineEditor/LineEditor.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <cstdio>
1818
#ifdef HAVE_LIBEDIT
1919
#include <histedit.h>
20+
constexpr int DefaultHistorySize = 800;
2021
#endif
2122

2223
using namespace llvm;
@@ -220,8 +221,8 @@ LineEditor::LineEditor(StringRef ProgName, StringRef HistoryPath, FILE *In,
220221
NULL); // Fix the delete key.
221222
::el_set(Data->EL, EL_CLIENTDATA, Data.get());
222223

224+
setHistorySize(DefaultHistorySize);
223225
HistEvent HE;
224-
::history(Data->Hist, &HE, H_SETSIZE, 800);
225226
::history(Data->Hist, &HE, H_SETUNIQUE, 1);
226227
loadHistory();
227228
}
@@ -248,6 +249,11 @@ void LineEditor::loadHistory() {
248249
}
249250
}
250251

252+
void LineEditor::setHistorySize(int size) {
253+
HistEvent HE;
254+
::history(Data->Hist, &HE, H_SETSIZE, size);
255+
}
256+
251257
std::optional<std::string> LineEditor::readLine() const {
252258
// Call el_gets to prompt the user and read the user's input.
253259
int LineLen = 0;
@@ -291,6 +297,7 @@ LineEditor::~LineEditor() {
291297

292298
void LineEditor::saveHistory() {}
293299
void LineEditor::loadHistory() {}
300+
void LineEditor::setHistorySize(int size) {}
294301

295302
std::optional<std::string> LineEditor::readLine() const {
296303
::fprintf(Data->Out, "%s", Prompt.c_str());

0 commit comments

Comments
 (0)