diff options
author | Andy Doan <andy.doan@linaro.org> | 2016-01-20 13:42:00 -0600 |
---|---|---|
committer | Andy Doan <andy.doan@linaro.org> | 2016-01-20 15:50:07 -0600 |
commit | f4d8c63596fdde7b6eac9b1f857ef4f8f6f27f9b (patch) | |
tree | 489d3fdf1c6ee05559d34871d6866e891883c97e /patch_matcher.py | |
parent | 674b48c95bf57c883cda4c6f405c28ce789387f5 (diff) |
Make patch_matcher a little smarter and easier to debug
This adds new logic to match a patch if their diff content is >.9. It
also adds debug logging for the diff ratios so its easy to find out why
a patch isn't getting marked as submitted.
Change-Id: Ic018658b3806735159dbe352646c67f2815bc428
Diffstat (limited to 'patch_matcher.py')
-rw-r--r-- | patch_matcher.py | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/patch_matcher.py b/patch_matcher.py index df69ef4..5876f4f 100644 --- a/patch_matcher.py +++ b/patch_matcher.py @@ -1,26 +1,37 @@ import difflib import email.utils +import logging import re from patchwork.models import Patch, Person, State +log = logging.getLogger('patch-matcher') + + +def _is_revert(name1, name2): + name1 = re.sub(r'\[[^\]]*\]', '', name1).strip() + name2 = re.sub(r'\[[^\]]*\]', '', name2).strip() + if name1.startswith('Revert') and not name2.startswith('Revert'): + return True + return False + def _patches_similar(name1, diff1, name2, diff2): # Be conservative and use 0.9 as the similarity ratio between the # commit's title and content to prevent false-positives. name_ratio = difflib.SequenceMatcher(None, name1, name2).ratio() + if name_ratio < 0.7: + return False + diff_ratio = difflib.SequenceMatcher(None, diff1, diff2).ratio() + log.debug( + 'name_ratio(%f) diff_ratio(%f) for: %s', name_ratio, diff_ratio, name1) + + if diff_ratio > 0.9 and not _is_revert(name1, name2): + return True if name_ratio > 0.9: - diff_ratio = difflib.SequenceMatcher(None, diff1, diff2).ratio() if diff_ratio > 0.9 or (name_ratio > .99 and diff_ratio > 0.6): - # Some commits may be just reverting a previous one and in - # these cases the title and content ratios will be high and - # pass the two tests above, so we do one last check here to - # avoid false-positives in these cases. - name1 = re.sub(r'\[[^\]]*\]', '', name1).strip() - name2 = re.sub(r'\[[^\]]*\]', '', name2).strip() - if name1.startswith('Revert') and not name2.startswith('Revert'): - return False - return True + if not _is_revert(name1, name2): + return True return False |