fromupstream: add --debug option
To print more verbose logs.
BUG=None
TEST=1. cros lint fromupstream.py
2. fromupstream.py -b none -t none -d pw://11123203
3. fromupstream.py -b none -t none -d linux://d85f6b93a76e
4. fromupstream.py -b none -t none -d git://mark/for-next/96ed76983307
5. fromupstream.py -b none -t none -d https://cros#master/eb8e661
Change-Id: I3042de69e6c2d95957e828887426e2a8cdfb8863
Signed-off-by: Tzung-Bi Shih <tzungbi@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/1780425
Reviewed-by: Douglas Anderson <dianders@chromium.org>
diff --git a/contrib/fromupstream.py b/contrib/fromupstream.py
index 470b41d..19f56da 100755
--- a/contrib/fromupstream.py
+++ b/contrib/fromupstream.py
@@ -12,6 +12,7 @@
import argparse
import mailbox
import os
+import pprint
import re
import signal
import subprocess
@@ -141,6 +142,8 @@
'updating commits.')
parser.add_argument('--nosignoff',
dest='signoff', action='store_false')
+ parser.add_argument('--debug', '-d', action='store_true',
+ help='Prints more verbose logs.')
parser.add_argument('--tag',
help='Overrides the tag from the title')
@@ -192,9 +195,15 @@
parser.error('BUG=/TEST= lines are required; --replace can help '
'automate, or set via --bug/--test')
+ if args['debug']:
+ pprint.pprint(args)
+
while len(args['locations']) > 0:
location = args['locations'].pop(0)
+ if args['debug']:
+ print('location=%s' % location)
+
patchwork_match = re.match(
r'pw://(([^/]+)/)?(\d+)', location
)
@@ -212,6 +221,10 @@
pw_project = patchwork_match.group(2)
patch_id = int(patchwork_match.group(3))
+ if args['debug']:
+ print('patchwork match: pw_project=%s, patch_id=%d' %
+ (pw_project, patch_id))
+
if args['tag'] is None:
args['tag'] = 'FROMLIST: '
@@ -244,6 +257,9 @@
elif linux_match:
commit = linux_match.group(1)
+ if args['debug']:
+ print('linux match: commit=%s' % commit)
+
# Confirm a 'linux' remote is setup.
linux_remote = _find_linux_remote()
if not linux_remote:
@@ -276,6 +292,10 @@
branch = fromgit_match.group(3)
commit = fromgit_match.group(4)
+ if args['debug']:
+ print('fromgit match: remote=%s branch=%s commit=%s' %
+ (remote, branch, commit))
+
ret = subprocess.call(['git', 'merge-base', '--is-ancestor',
commit, '%s/%s' % (remote, branch)])
if ret:
@@ -307,6 +327,10 @@
branch = gitfetch_match.group(3)
commit = gitfetch_match.group(4)
+ if args['debug']:
+ print('gitfetch match: remote=%s branch=%s commit=%s' %
+ (remote, branch, commit))
+
ret = subprocess.call(['git', 'fetch', remote, branch])
if ret:
sys.stderr.write('Error: Branch not in %s\n' % remote)