public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Allow space in git commit-mklog args
@ 2022-07-22  9:38 Martin Liška
  2022-07-22 10:43 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Liška @ 2022-07-22  9:38 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jonathan Wakely

Hi.

Motivation example:
$ git commit-mklog -a -b 'PR other/106370,PR other/12345'

Preserving a space from git gcc-mklog hook to contrib/mklog.py seems
pretty challenging. Thus I recommend preserving extra mklog args via
env where it's encoded in JSON format.

Thoughts?
Thanks,
Martin

contrib/ChangeLog:

	* git-commit-mklog.py: Do not parse -b argument.
        Pass mklog_args as json environment variable.
	* mklog.py: Parse GCC_MKLOG_ARGS and append it to sys.argv.
	* prepare-commit-msg: Do not append GCC_MKLOG_ARGS to args.
---
 contrib/git-commit-mklog.py | 9 +++++----
 contrib/mklog.py            | 5 +++++
 contrib/prepare-commit-msg  | 2 +-
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/contrib/git-commit-mklog.py b/contrib/git-commit-mklog.py
index eda3fc4a892..c7e90c8262f 100755
--- a/contrib/git-commit-mklog.py
+++ b/contrib/git-commit-mklog.py
@@ -24,6 +24,7 @@
 # to mklog.py script.
 
 import argparse
+import json
 import os
 import subprocess
 
@@ -32,8 +33,7 @@ if __name__ == '__main__':
     myenv = os.environ.copy()
 
     parser = argparse.ArgumentParser(description='git-commit-mklog wrapped')
-    parser.add_argument('-b', '--pr-numbers', action='store',
-                        type=lambda arg: arg.split(','), nargs='?',
+    parser.add_argument('-b', '--pr-numbers',
                         help='Add the specified PRs (comma separated)')
     parser.add_argument('-p', '--fill-up-bug-titles', action='store_true',
                         help='Download title of mentioned PRs')
@@ -44,12 +44,13 @@ if __name__ == '__main__':
     myenv['GCC_FORCE_MKLOG'] = '1'
     mklog_args = []
     if args.pr_numbers:
-        mklog_args.append(f'-b {",".join(args.pr_numbers)}')
+        mklog_args += ['-b', args.pr_numbers]
     if args.fill_up_bug_titles:
         mklog_args.append('-p')
 
     if mklog_args:
-        myenv['GCC_MKLOG_ARGS'] = ' '.join(mklog_args)
+        # wrap mklog arguments with JSON
+        myenv['GCC_MKLOG_ARGS'] = json.dumps(mklog_args)
 
     if args.co:
         for author in args.co.split(','):
diff --git a/contrib/mklog.py b/contrib/mklog.py
index cd5ef0bcc74..fe530ebf773 100755
--- a/contrib/mklog.py
+++ b/contrib/mklog.py
@@ -28,6 +28,7 @@
 
 import argparse
 import datetime
+import json
 import os
 import re
 import subprocess
@@ -336,6 +337,10 @@ def skip_line_in_changelog(line):
 
 
 if __name__ == '__main__':
+    extra_args = os.getenv('GCC_MKLOG_ARGS')
+    if extra_args:
+        sys.argv += json.loads(extra_args)
+
     parser = argparse.ArgumentParser(description=help_message)
     parser.add_argument('input', nargs='?',
                         help='Patch file (or missing, read standard input)')
diff --git a/contrib/prepare-commit-msg b/contrib/prepare-commit-msg
index 5da878458cd..969847df6f4 100755
--- a/contrib/prepare-commit-msg
+++ b/contrib/prepare-commit-msg
@@ -78,4 +78,4 @@ else
     tee="cat"
 fi
 
-git $cmd | $tee | git gcc-mklog $GCC_MKLOG_ARGS -c "$COMMIT_MSG_FILE"
+git $cmd | $tee | git gcc-mklog -c "$COMMIT_MSG_FILE"
-- 
2.37.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Allow space in git commit-mklog args
  2022-07-22  9:38 [PATCH] Allow space in git commit-mklog args Martin Liška
@ 2022-07-22 10:43 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2022-07-22 10:43 UTC (permalink / raw)
  To: Martin Liška; +Cc: gcc-patches

On Fri, 22 Jul 2022 at 10:38, Martin Liška wrote:
>
> Hi.
>
> Motivation example:
> $ git commit-mklog -a -b 'PR other/106370,PR other/12345'
>
> Preserving a space from git gcc-mklog hook to contrib/mklog.py seems
> pretty challenging. Thus I recommend preserving extra mklog args via
> env where it's encoded in JSON format.
>
> Thoughts?

This solution looks much better than trying to get the shell quoting
and word splitting right.

For the record, my suggestion was to surround each arg in double
quotes within the env var and then ...

> diff --git a/contrib/prepare-commit-msg b/contrib/prepare-commit-msg
> index 5da878458cd..969847df6f4 100755
> --- a/contrib/prepare-commit-msg
> +++ b/contrib/prepare-commit-msg
> @@ -78,4 +78,4 @@ else
>      tee="cat"
>  fi
>
> -git $cmd | $tee | git gcc-mklog $GCC_MKLOG_ARGS -c "$COMMIT_MSG_FILE"
> +git $cmd | $tee | git gcc-mklog -c "$COMMIT_MSG_FILE"

... change this to:

mklog() {
  echo "$GCC_MKLOG_ARGS" | xargs -x git gcc-mklog -c "$COMMIT_MSG_FILE"
}
git $cmd | $tee | mklog

This works because xargs respects quotes within its input and so would
pass them correctly to the git gcc-mklog command.

But avoiding this entirely by storing them as json and then not
retrieving them until the mklog.py step is more reliable.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-22 10:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-22  9:38 [PATCH] Allow space in git commit-mklog args Martin Liška
2022-07-22 10:43 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).