diff options
author | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-05-01 17:35:42 -0400 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-05-01 17:35:42 -0400 |
commit | e38edc300448da8b365a819b7f178cfb0a4f69e7 (patch) | |
tree | f856e2111f53a7590d131c40768add9d1f64aa02 /b4/mbox.py | |
parent | ba6c790d0ca342b2069d71315ae0c835e5bdc599 (diff) | |
download | b4-e38edc300448da8b365a819b7f178cfb0a4f69e7.tar.gz |
Check if mbox applies to current tree
Check if all patches in the mbox would apply cleanly to the current
tree:
- find index hash..hash information in each patch
- check if git-hash-object shows exact same hashes for the current tree
- if not, try the last 10 tags to see if any of them would be a good
base-commit for the patch/series
Not sure how useful the latter part it, but it hopefully shouldn't slow
down regular operations, so I'm going to leave it in for now.
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Diffstat (limited to 'b4/mbox.py')
-rw-r--r-- | b4/mbox.py | 40 |
1 files changed, 38 insertions, 2 deletions
@@ -131,8 +131,44 @@ def mbox_to_am(mboxfile, cmdargs): logger.critical(' git checkout -b %s %s', gitbranch, base_commit) logger.critical(' git am %s', am_filename) else: - logger.critical(' Base: not found, sorry') - logger.critical(' git checkout -b %s master', gitbranch) + cleanmsg = '' + # Are we in a git tree and if so, what is our toplevel? + gitargs = ['rev-parse', '--show-toplevel'] + lines = b4.git_get_command_lines(None, gitargs) + if len(lines) == 1: + topdir = lines[0] + checked, mismatches = lser.check_applies_clean(topdir) + if mismatches == 0 and checked != mismatches: + cleanmsg = ' (applies clean to current tree)' + else: + # Look at the last 10 tags and see if it applies cleanly to + # any of them. I'm not sure how useful this is, but I'm going + # to put it in for now and maybe remove later if it causes + # problems or slowness + if checked != mismatches: + best_matches = mismatches + cleanmsg = ' (best guess: current tree)' + else: + best_matches = None + # sort the tags by authordate + gitargs = ['tag', '-l', '--sort=-creatordate'] + lines = b4.git_get_command_lines(None, gitargs) + if lines: + # Check last 10 tags + for tag in lines[:10]: + logger.debug('Checking base-commit possibility for %s', tag) + checked, mismatches = lser.check_applies_clean(topdir, tag) + if mismatches == 0 and checked != mismatches: + base_commit = tag + break + # did they all mismatch? + if checked == mismatches: + continue + if best_matches is None or mismatches < best_matches: + best_matches = mismatches + cleanmsg = ' (best guess: %s)' % tag + + logger.critical(' Base: not found%s', cleanmsg) logger.critical(' git am %s', am_filename) am_mbx.close() |