Hi
I suggest we also handle PcdShellMaxHistoryCommandCount == 0 case.
I think we can add below at the begging of function.
if (MaxHistoryCmdCount == 0) {
return ;
}
Other change seems good. Reviewed by: jiewen@intel.com
Thank you
Yao Jiewen
-Original Message-
From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Qiu
Shumin
Sent: Wednesday, December 23, 2015 2:15 PM
To: edk2-devel@lists.01.org
Cc: Carsey, Jaben; Ni, Ruiyu; Qiu, Shumin
Subject: [edk2] [PATCH v3 2/4] ShellPkg: Refine the code logic of 'command
history'.
Add the PCD to PcdShellMaxHistoryCommandCount indicate the max count of history
commands.
Cc: Jaben Carsey <jaben.car...@intel.com>
Cc: Ruiyu Ni <ruiyu...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qiu Shumin <shumin@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu...@intel.com>
Reviewed-by: Jaben Carsey <jaben.car...@intel.com>
---
ShellPkg/Application/Shell/Shell.c | 24 +++-
ShellPkg/Application/Shell/Shell.inf | 25 +
ShellPkg/ShellPkg.dec| 3 +++
3 files changed, 39 insertions(+), 13 deletions(-)
diff --git a/ShellPkg/Application/Shell/Shell.c
b/ShellPkg/Application/Shell/Shell.c
index 3606322..41c8a03 100644
--- a/ShellPkg/Application/Shell/Shell.c
+++ b/ShellPkg/Application/Shell/Shell.c
@@ -1288,13 +1288,35 @@ AddLineToCommandHistory(
)
{
BUFFER_LIST *Node;
+ BUFFER_LIST *Walker;
+ UINT16 MaxHistoryCmdCount;
+ UINT16 Count;
+
+ Count = 0;
+ MaxHistoryCmdCount = PcdGet16(PcdShellMaxHistoryCommandCount);
Node = AllocateZeroPool(sizeof(BUFFER_LIST));
ASSERT(Node != NULL);
Node->Buffer = AllocateCopyPool(StrSize(Buffer), Buffer);
ASSERT(Node->Buffer != NULL);
- InsertTailList(,
>Link);
+ for ( Walker =
(BUFFER_LIST*)GetFirstNode()
+ ; !IsNull(,
>Link)
+ ; Walker =
(BUFFER_LIST*)GetNextNode(,
>Link)
+ ){
+Count++;
+ }
+ if (Count < MaxHistoryCmdCount){
+
+ InsertTailList(,
>Link); } else {
+Walker =
(BUFFER_LIST*)GetFirstNode();
+RemoveEntryList(>Link);
+if (Walker->Buffer != NULL) {
+ FreePool(Walker->Buffer);
+}
+FreePool(Walker);
+
+ InsertTailList(,
+ >Link); }
}
/**
diff --git a/ShellPkg/Application/Shell/Shell.inf
b/ShellPkg/Application/Shell/Shell.inf
index 09aecf7..253bfdb 100644
--- a/ShellPkg/Application/Shell/Shell.inf
+++ b/ShellPkg/Application/Shell/Shell.inf
@@ -95,18 +95,19 @@
gEfiDevicePathProtocolGuid ## CONSUMES
[Pcd]
- gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel ## CONSUMES
- gEfiShellPkgTokenSpaceGuid.PcdShellSupportOldProtocols ## CONSUMES
- gEfiShellPkgTokenSpaceGuid.PcdShellRequireHiiPlatform ## CONSUMES
- gEfiShellPkgTokenSpaceGuid.PcdShellSupportFrameworkHii ## CONSUMES
- gEfiShellPkgTokenSpaceGuid.PcdShellPageBreakDefault ## CONSUMES
- gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize## CONSUMES
- gEfiShellPkgTokenSpaceGuid.PcdShellInsertModeDefault## CONSUMES
- gEfiShellPkgTokenSpaceGuid.PcdShellScreenLogCount ## CONSUMES
- gEfiShellPkgTokenSpaceGuid.PcdShellMapNameLength## CONSUMES
- gEfiShellPkgTokenSpaceGuid.PcdShellPrintBufferSize ## CONSUMES
- gEfiShellPkgTokenSpaceGuid.PcdShellForceConsole ## CONSUMES
- gEfiShellPkgTokenSpaceGuid.PcdShellSupplier ## CONSUMES
+ gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel ## CONSUMES
+ gEfiShellPkgTokenSpaceGuid.PcdShellSupportOldProtocols## CONSUMES
+ gEfiShellPkgTokenSpaceGuid.PcdShellRequireHiiPlatform ## CONSUMES
+ gEfiShellPkgTokenSpaceGuid.PcdShellSupportFrameworkHii## CONSUMES
+ gEfiShellPkgTokenSpaceGuid.PcdShellPageBreakDefault ## CONSUMES
+ gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize ## CONSUMES
+ gEfiShellPkgTokenSpaceGuid.PcdShellInsertModeDefault ## CONSUMES
+ gEfiShellPkgTokenSpaceGuid.PcdShellScreenLogCount ## CONSUMES
+ gEfiShellPkgTokenSpaceGuid.PcdShellMapNameLength ## CONSUMES
+ gEfiShellPkgTokenSpaceGuid.PcdShellPrintBufferSize## CONSUMES
+ gEfiShellPkgTokenSpaceGuid.PcdShellForceConsole ## CONSUMES
+ gEfiShellPkgTokenSpaceGuid.PcdShellSupplier ## CONSUMES
+ gEfiShellPkgTokenSpaceGuid.PcdShellMaxHistoryCommandCount ## CONSUMES
[BuildOptions.AARCH64]
# The tiny code model used by AARCH64 only supports binaries of up to 1 MB
in diff --git a/ShellPkg/ShellPkg.dec b/ShellPkg/ShellPkg.dec index
b2f6326..76a2b7d 100644
--- a/ShellPkg/ShellPkg.dec
+++ b/ShellPkg/ShellPkg.dec
@@ -101,6 +101,9 @@
## This determines how many bytes are read out of files at a time for file
operations (type, copy, etc...)
gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize|0x1000|UINT32|0x000A
+
+ ## This determines the max count of history commands
+
+ gEfiShellPk