mklog.py: Add --commit option.

Message ID ada6da15-ba5e-1959-91ae-3ed9c44faf1f@gmail.com
State Accepted
Headers
Series mklog.py: Add --commit option. |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Robin Dapp May 11, 2023, 8:29 a.m. UTC
  Hi,

this patch allows mklog.py to be called with a commit hash directly.
So, instead of

 git show <commit> | git gcc-mklog

 git gcc-mklog --commit <commit>

can be used.

When no <commit> is given but --commit is specified, HEAD is used
instead.  The behavior without --commit is the same as before.

Is that useful/OK?  I find that option a bit easier to work with.

Regards
 Robin

contrib/ChangeLog:

	* mklog.py:  Add optional --commit <commit> argument.
---
 contrib/mklog.py | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
  

Comments

Jeff Law May 11, 2023, 2:46 p.m. UTC | #1
On 5/11/23 02:29, Robin Dapp via Gcc-patches wrote:
> Hi,
> 
> this patch allows mklog.py to be called with a commit hash directly.
> So, instead of
> 
>   git show <commit> | git gcc-mklog
> 
>   git gcc-mklog --commit <commit>
> 
> can be used.
> 
> When no <commit> is given but --commit is specified, HEAD is used
> instead.  The behavior without --commit is the same as before.
> 
> Is that useful/OK?  I find that option a bit easier to work with.
> 
> Regards
>   Robin
> 
> contrib/ChangeLog:
> 
> 	* mklog.py:  Add optional --commit <commit> argument.
Seems reasonable to me and probably works better with the flows some 
people are using :-)

Jeff
  

Patch

diff --git a/contrib/mklog.py b/contrib/mklog.py
index 777212c98d7..25a3b6c0757 100755
--- a/contrib/mklog.py
+++ b/contrib/mklog.py
@@ -358,13 +358,23 @@  if __name__ == '__main__':
                              'file')
     parser.add_argument('--update-copyright', action='store_true',
                         help='Update copyright in ChangeLog files')
+    parser.add_argument('--commit', const='HEAD', nargs='?',
+                        help='Use a specific commit instead of a '
+                             'patch file or stdin. (essentially git show '
+                             'commit-id | git gcc-mklog)')
     args = parser.parse_args()
     if args.input == '-':
         args.input = None
     if args.directory:
         root = args.directory
 
-    data = open(args.input, newline='\n') if args.input else sys.stdin
+    if args.commit:
+        args.input = None
+        data = subprocess.check_output('git show {}'.format(args.commit),
+                                       shell=True, encoding='utf8').strip()
+    else:
+        data = open(args.input, newline='\n') if args.input else sys.stdin
+
     if args.update_copyright:
         update_copyright(data)
     else: