summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-04-15 18:31:36 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-04-15 18:31:36 -0400
commitd6d552386ad2fc7b215a4a4e9860144975a3240f (patch)
tree35636d3c35e38eb9d29ae3486e8c82e362c96ab8
parent4b017e7ccadfe95f88fdd5c6834960eb4c6b0a11 (diff)
downloadb4-d6d552386ad2fc7b215a4a4e9860144975a3240f.tar.gz
Changes to b4 ty based on developer feedback
- Properly expand ~ and env vars like $HOME in template paths - Allow partial matching of series (with a warning) - Allow using remote branches with -b - Always fall back to subject matching for patches - Tweak to the summary output Suggested-by: Mark Brown <broonie@kernel.org> Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r--b4/command.py2
-rw-r--r--b4/ty.py41
2 files changed, 31 insertions, 12 deletions
diff --git a/b4/command.py b/b4/command.py
index 6d5e054..d5f06dc 100644
--- a/b4/command.py
+++ b/b4/command.py
@@ -191,7 +191,7 @@ if __name__ == '__main__':
dotgit = os.path.join(base, '.git')
ecode, short = b4.git_run_command(dotgit, ['rev-parse', '--short', 'HEAD'])
if ecode == 0:
- b4.__VERSION__ = '%s-%s' % (b4.__VERSION__, short.strip())
+ b4.__VERSION__ = '%s-%.5s' % (b4.__VERSION__, short.strip())
except Exception as ex:
# Any failures above are non-fatal
pass
diff --git a/b4/ty.py b/b4/ty.py
index 0592af5..629fa30 100644
--- a/b4/ty.py
+++ b/b4/ty.py
@@ -165,30 +165,33 @@ def get_all_commits(gitdir, branch, since='1.week', committer=None):
return MY_COMMITS
-def auto_locate_series(gitdir, jsondata, branch, since='1.week', loose=False):
+def auto_locate_series(gitdir, jsondata, branch, since='1.week'):
commits = get_all_commits(gitdir, branch, since)
patchids = set(commits.keys())
# We need to find all of them in the commits
found = list()
+ matches = 0
for patch in jsondata['patches']:
logger.debug('Checking %s', patch)
if patch[1] in patchids:
logger.debug('Found: %s', patch[0])
found.append(commits[patch[1]])
- elif loose:
+ matches += 1
+ else:
# try to locate by subject
success = False
for pwhash, commit in commits.items():
if commit[1] == patch[0]:
found.append(commit)
success = True
+ matches += 1
break
if not success:
logger.debug(' Failed to find a match for: %s', patch[0])
+ found.append((None, patch[0]))
- if len(found) == len(jsondata['patches']):
- logger.debug('Found all the patches')
+ if matches > 0:
return found
return None
@@ -197,6 +200,10 @@ def auto_locate_series(gitdir, jsondata, branch, since='1.week', loose=False):
def read_template(tptfile):
# bubbles up FileNotFound
tpt = ''
+ if tptfile.find('~') >= 0:
+ tptfile = os.path.expanduser(tptfile)
+ if tptfile.find('$') >= 0:
+ tptfile = os.path.expandvars(tptfile)
with open(tptfile, 'r', encoding='utf-8') as fh:
for line in fh:
if len(line) and line[0] == '#':
@@ -245,22 +252,34 @@ def generate_am_thanks(gitdir, jsondata, branch, since):
config['thanks-am-template'])
sys.exit(2)
if 'commits' not in jsondata:
- commits = auto_locate_series(gitdir, jsondata, branch, since, loose=True)
+ commits = auto_locate_series(gitdir, jsondata, branch, since)
else:
commits = jsondata['commits']
if commits is None:
- logger.critical('Could not match all commits for: %s', jsondata['subject'])
+ logger.critical('Could not match any commits for: %s', jsondata['subject'])
logger.critical('Not thanking for this series')
return None
cidmask = config['thanks-commit-url-mask']
if not cidmask:
cidmask = 'commit: %s'
slines = list()
+ counter = 1
+ partial = False
+ padlen = len(str(len(commits)))
for commit in commits:
- slines.append('- %s' % commit[1])
- slines.append(' %s' % (cidmask % commit[0]))
+ prefix = '[%s/%s] ' % (str(counter).zfill(padlen), len(commits))
+ slines.append('%s%s' % (prefix, commit[1]))
+ if commit[0] is None:
+ slines.append('%s(not applied)' % (' ' * len(prefix)))
+ partial = True
+ else:
+ slines.append('%s%s' % (' ' * len(prefix), cidmask % commit[0]))
+ counter += 1
jsondata['summary'] = '\n'.join(slines)
+ if partial:
+ logger.critical(' WARNING: Not all patches matched for: %s', jsondata['subject'])
+ logger.critical(' Please review the resulting message')
msg = make_reply(thanks_template, jsondata)
return msg
@@ -482,13 +501,13 @@ def get_wanted_branch(cmdargs):
logger.debug('will check branch=%s', wantbranch)
else:
# Make sure it's a real branch
- gitargs = ['branch', '--format=%(refname:short)', '--list']
+ gitargs = ['branch', '--format=%(refname:short)', '--list', '--all']
lines = b4.git_get_command_lines(gitdir, gitargs)
if not len(lines):
- logger.critical('Not able to get a list of branches (git branch --list)')
+ logger.critical('Not able to get a list of branches (git branch --list --all)')
sys.exit(1)
if cmdargs.branch not in lines:
- logger.critical('Requested branch %s not found in git branch --list', cmdargs.branch)
+ logger.critical('Requested branch %s not found in git branch --list --all', cmdargs.branch)
sys.exit(1)
wantbranch = cmdargs.branch