Re: [PATCH v3 1/5] patman: Fix implicit command inserting

2022-07-17 Thread Simon Glass
The logic to insert an implicit command has always been a bit broken
but it was masked by another bug fixed in the patch ("patman: Don't
look at sys.argv when parsing settings"). Specifically, imagine that
you're just calling patman like this:

  patman -c1

After the parse_known_args() command then the "-c1" will have been
parsed and we'll have no command. The "rest" variable will be an empty
list. Going into the logic you can see that nargs = 0. The implicit
insertion of send ideally would create an argument list of:
  ['-c1', 'send']
...but it doesn't because argv[:-0] is the same as argv[:0] and that's
an empty list.

Let's fix this little glitch.

Signed-off-by: Douglas Anderson 
Tested-by: Brian Norris 
Reviewed-by: Brian Norris 
Reviewed-by: Simon Glass 
---

(no changes since v1)

 tools/patman/main.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Applied to u-boot-dm, thanks!


[PATCH v3 1/5] patman: Fix implicit command inserting

2022-07-07 Thread Douglas Anderson
The logic to insert an implicit command has always been a bit broken
but it was masked by another bug fixed in the patch ("patman: Don't
look at sys.argv when parsing settings"). Specifically, imagine that
you're just calling patman like this:

  patman -c1

After the parse_known_args() command then the "-c1" will have been
parsed and we'll have no command. The "rest" variable will be an empty
list. Going into the logic you can see that nargs = 0. The implicit
insertion of send ideally would create an argument list of:
  ['-c1', 'send']
...but it doesn't because argv[:-0] is the same as argv[:0] and that's
an empty list.

Let's fix this little glitch.

Signed-off-by: Douglas Anderson 
Tested-by: Brian Norris 
Reviewed-by: Brian Norris 
Reviewed-by: Simon Glass 
---

(no changes since v1)

 tools/patman/main.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/patman/main.py b/tools/patman/main.py
index 66d4806c8d8f..e868878ad5a7 100755
--- a/tools/patman/main.py
+++ b/tools/patman/main.py
@@ -119,7 +119,9 @@ else:
 # No command, so insert it after the known arguments and before the ones
 # that presumably relate to the 'send' subcommand
 nargs = len(rest)
-argv = argv[:-nargs] + ['send'] + rest
+if nargs:
+argv = argv[:-nargs]
+argv = argv + ['send'] + rest
 args = parser.parse_args(argv)
 
 if __name__ != "__main__":
-- 
2.37.0.rc0.161.g10f37bed90-goog