Skip to contentSkip to conversation

tools: Only add unique entries to readline history

PATCH In review Luiz Augusto von Dentz 2 participants 4 messages Sep 18, 2017 – Sep 20, 2017 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/1 tools: Only add unique entries to readline history

From: Luiz Augusto von Dentz <[email protected]>

Don't add duplicate commands to historym this is similar to what HISTCONTROL=ignoredups does.

---
 client/main.c            | 3 ++-
 tools/bluetooth-player.c | 4 +++-
 tools/btmgmt.c           | 3 ++-
 tools/obex-client-tool.c | 3 ++-
 tools/obexctl.c          | 3 ++-
 5 files changed, 11 insertions(+), 5 deletions(-)
client/main.c +2 -1
index 2cb449fd5..282e84003 100644
@@ -2644,7 +2644,8 @@ static void rl_handler(char *input)
 	if (!rl_release_prompt(input))
 		goto done;
 
-	add_history(input);
+	if (history_search(input, -1))
+		add_history(input);
 
 	cmd = strtok_r(input, " ", &arg);
 	if (!cmd)
tools/bluetooth-player.c +3 -1
index 9e199970d..c95b7497f 100644
@@ -1086,7 +1086,9 @@ static void rl_handler(char *input)
 		goto done;
 
 	g_strstrip(input);
-	add_history(input);
+
+	if (history_search(input, -1))
+		add_history(input);
 
 	argv = g_strsplit(input, " ", -1);
 	if (argv == NULL)
tools/btmgmt.c +2 -1
index e7ea69937..e454d864d 100644
@@ -4664,7 +4664,8 @@ static void rl_handler(char *input)
 	if (prompt_input(input))
 		goto done;
 
-	add_history(input);
+	if (history_search(input, -1))
+		add_history(input);
 
 	if (wordexp(input, &w, WRDE_NOCMD))
 		goto done;
tools/obex-client-tool.c +2 -1
index d0ba8a651..d74ac77a1 100644
@@ -242,7 +242,8 @@ static void parse_line(char *line_read)
 		return;
 	}
 
-	add_history(line_read);
+	if (history_search(input, -1))
+		add_history(input);
 
 	g_shell_parse_argv(line_read, &argcp, &argvp, NULL);
 
tools/obexctl.c +2 -1
index 46943d682..ece50f682 100644
@@ -2081,7 +2081,8 @@ static void rl_handler(char *input)
 	if (!strlen(input))
 		goto done;
 
-	add_history(input);
+	if (history_search(input, -1))
+		add_history(input);
 
 	if (wordexp(input, &w, WRDE_NOCMD))
 		goto done;
Signature · 1 line
2.13.5
#1 lore raw

Hi Luiz,

Quoted 17 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Don't add duplicate commands to historym this is similar to what HISTCONTROL=ignoredups does.

---
 client/main.c            | 3 ++-
 tools/bluetooth-player.c | 4 +++-
 tools/btmgmt.c           | 3 ++-
 tools/obex-client-tool.c | 3 ++-
 tools/obexctl.c          | 3 ++-
 5 files changed, 11 insertions(+), 5 deletions(-)
client/main.c +0 -0
index 2cb449fd5..282e84003 100644

client/main.c static void rl_handler(char *input) · line 2649

Quoted 7 lines
client/main.c +2 -1
@@ -2644,7 +2644,8 @@ static void rl_handler(char *input)
 	if (!rl_release_prompt(input))
 		goto done;
 
-	add_history(input);
+	if (history_search(input, -1))
+		add_history(input);
 

I think it is better to add g_strstrip(), since this patch adds a command typed all characters to history and then adds the complemented command to history when it have white-space.

Quoted 36 lines
client/main.c +0 -0
 	cmd = strtok_r(input, " ", &arg);
 	if (!cmd)
tools/bluetooth-player.c +3 -1
index 9e199970d..c95b7497f 100644
@@ -1086,7 +1086,9 @@ static void rl_handler(char *input)
 		goto done;
 
 	g_strstrip(input);
-	add_history(input);
+
+	if (history_search(input, -1))
+		add_history(input);
 
 	argv = g_strsplit(input, " ", -1);
 	if (argv == NULL)
tools/btmgmt.c +2 -1
index e7ea69937..e454d864d 100644
@@ -4664,7 +4664,8 @@ static void rl_handler(char *input)
 	if (prompt_input(input))
 		goto done;
 
-	add_history(input);
+	if (history_search(input, -1))
+		add_history(input);
 
 	if (wordexp(input, &w, WRDE_NOCMD))
 		goto done;
tools/obex-client-tool.c +0 -0
index d0ba8a651..d74ac77a1 100644

tools/obex-client-tool.c static void parse_line(char *line_read) · line 246

Quoted 6 lines
tools/obex-client-tool.c +2 -1
@@ -242,7 +242,8 @@ static void parse_line(char *line_read)
 		return;
 	}
 
-	add_history(line_read);
+	if (history_search(input, -1))
+		add_history(input);

line_read is correct.

Quoted 9 lines
tools/obex-client-tool.c +0 -0
 	g_shell_parse_argv(line_read, &argcp, &argvp, NULL);
 
tools/obexctl.c +0 -0
index 46943d682..ece50f682 100644

tools/obexctl.c static void rl_handler(char *input) · line 2088

Quoted 9 lines
tools/obexctl.c +2 -1
@@ -2081,7 +2081,8 @@ static void rl_handler(char *input)
 	if (!strlen(input))
 		goto done;
 
-	add_history(input);
+	if (history_search(input, -1))
+		add_history(input);
 
 	if (wordexp(input, &w, WRDE_NOCMD))
 		goto done;

Regards,
Eramoto

author maintainer
#2 lore raw

Hi Eramoto,

Quoted 23 lines · ERAMOTO Masaya

Hi Luiz,

Quoted 20 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Don't add duplicate commands to historym this is similar to what HISTCONTROL=ignoredups does.

---
 client/main.c            | 3 ++-
 tools/bluetooth-player.c | 4 +++-
 tools/btmgmt.c           | 3 ++-
 tools/obex-client-tool.c | 3 ++-
 tools/obexctl.c          | 3 ++-
 5 files changed, 11 insertions(+), 5 deletions(-)
client/main.c +0 -0
index 2cb449fd5..282e84003 100644
@@ -2644,7 +2644,8 @@ static void rl_handler(char *input)
      if (!rl_release_prompt(input))
              goto done;
 
Quoted 8 lines

client/main.c static void rl_handler(char *input) · line 2649

Quoted 4 lines
client/main.c +2 -1
-     add_history(input);
+     if (history_search(input, -1))
+             add_history(input);
 

I think it is better to add g_strstrip(), since this patch adds a command typed all characters to history and then adds the complemented command to history when it have white-space.

Yep, but as a separate change, this part of handling should really go into a common code so we don't have to keep duplicating this on every tool.

Quoted 39 lines
Quoted 39 lines
client/main.c +0 -0
      cmd = strtok_r(input, " ", &arg);
      if (!cmd)
tools/bluetooth-player.c +3 -1
index 9e199970d..c95b7497f 100644
@@ -1086,7 +1086,9 @@ static void rl_handler(char *input)
              goto done;
 
      g_strstrip(input);
-     add_history(input);
+
+     if (history_search(input, -1))
+             add_history(input);
 
      argv = g_strsplit(input, " ", -1);
      if (argv == NULL)
tools/btmgmt.c +2 -1
index e7ea69937..e454d864d 100644
@@ -4664,7 +4664,8 @@ static void rl_handler(char *input)
      if (prompt_input(input))
              goto done;
 
-     add_history(input);
+     if (history_search(input, -1))
+             add_history(input);
 
      if (wordexp(input, &w, WRDE_NOCMD))
              goto done;
tools/obex-client-tool.c +0 -0
index d0ba8a651..d74ac77a1 100644
@@ -242,7 +242,8 @@ static void parse_line(char *line_read)
              return;
      }
 
Quoted 5 lines

tools/obex-client-tool.c static void parse_line(char *line_read) · line 246

Quoted 3 lines
tools/obex-client-tool.c +2 -1
-     add_history(line_read);
+     if (history_search(input, -1))
+             add_history(input);

line_read is correct.

Good catch, will fix it.

Quoted 23 lines
Quoted 9 lines
tools/obex-client-tool.c +0 -0
      g_shell_parse_argv(line_read, &argcp, &argvp, NULL);
 
tools/obexctl.c +0 -0
index 46943d682..ece50f682 100644

tools/obexctl.c static void rl_handler(char *input) · line 2088

Quoted 9 lines
tools/obexctl.c +2 -1
@@ -2081,7 +2081,8 @@ static void rl_handler(char *input)
      if (!strlen(input))
              goto done;
 
-     add_history(input);
+     if (history_search(input, -1))
+             add_history(input);
 
      if (wordexp(input, &w, WRDE_NOCMD))
              goto done;

Regards,
Eramoto

Signature · 1 line
Luiz Augusto von Dentz
author maintainer Applied
#3 lore raw

Hi,

Quoted 79 lines · Luiz Augusto von Dentz

Hi Eramoto,

Quoted 23 lines · ERAMOTO Masaya

Hi Luiz,

Quoted 20 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Don't add duplicate commands to historym this is similar to what HISTCONTROL=ignoredups does.

---
 client/main.c            | 3 ++-
 tools/bluetooth-player.c | 4 +++-
 tools/btmgmt.c           | 3 ++-
 tools/obex-client-tool.c | 3 ++-
 tools/obexctl.c          | 3 ++-
 5 files changed, 11 insertions(+), 5 deletions(-)
client/main.c +0 -0
index 2cb449fd5..282e84003 100644
@@ -2644,7 +2644,8 @@ static void rl_handler(char *input)
      if (!rl_release_prompt(input))
              goto done;
 
Quoted 8 lines

client/main.c static void rl_handler(char *input) · line 2649

Quoted 4 lines
client/main.c +2 -1
-     add_history(input);
+     if (history_search(input, -1))
+             add_history(input);
 

I think it is better to add g_strstrip(), since this patch adds a command typed all characters to history and then adds the complemented command to history when it have white-space.

Yep, but as a separate change, this part of handling should really go into a common code so we don't have to keep duplicating this on every tool.

Quoted 39 lines
Quoted 39 lines
client/main.c +0 -0
      cmd = strtok_r(input, " ", &arg);
      if (!cmd)
tools/bluetooth-player.c +3 -1
index 9e199970d..c95b7497f 100644
@@ -1086,7 +1086,9 @@ static void rl_handler(char *input)
              goto done;
 
      g_strstrip(input);
-     add_history(input);
+
+     if (history_search(input, -1))
+             add_history(input);
 
      argv = g_strsplit(input, " ", -1);
      if (argv == NULL)
tools/btmgmt.c +2 -1
index e7ea69937..e454d864d 100644
@@ -4664,7 +4664,8 @@ static void rl_handler(char *input)
      if (prompt_input(input))
              goto done;
 
-     add_history(input);
+     if (history_search(input, -1))
+             add_history(input);
 
      if (wordexp(input, &w, WRDE_NOCMD))
              goto done;
tools/obex-client-tool.c +0 -0
index d0ba8a651..d74ac77a1 100644
@@ -242,7 +242,8 @@ static void parse_line(char *line_read)
              return;
      }
 
Quoted 31 lines
Quoted 5 lines

tools/obex-client-tool.c static void parse_line(char *line_read) · line 246

Quoted 3 lines
tools/obex-client-tool.c +2 -1
-     add_history(line_read);
+     if (history_search(input, -1))
+             add_history(input);

line_read is correct.

Good catch, will fix it.

Quoted 23 lines
Quoted 9 lines
tools/obex-client-tool.c +0 -0
      g_shell_parse_argv(line_read, &argcp, &argvp, NULL);
 
tools/obexctl.c +0 -0
index 46943d682..ece50f682 100644

tools/obexctl.c static void rl_handler(char *input) · line 2088

Quoted 9 lines
tools/obexctl.c +2 -1
@@ -2081,7 +2081,8 @@ static void rl_handler(char *input)
      if (!strlen(input))
              goto done;
 
-     add_history(input);
+     if (history_search(input, -1))
+             add_history(input);
 
      if (wordexp(input, &w, WRDE_NOCMD))
              goto done;

Regards,
Eramoto

Applied.

Signature · 1 line
Luiz Augusto von Dentz