diff options
author | Andy Doan <andy.doan@linaro.org> | 2015-04-13 10:18:10 -0500 |
---|---|---|
committer | Andy Doan <andy.doan@linaro.org> | 2015-04-13 10:18:10 -0500 |
commit | 2e6d642aaf0a03bc22f34e169f68bbd0852c4e91 (patch) | |
tree | 75617067a791171b2dec2555ccd083105b5c3c99 /import_emails.py | |
parent | a05355ea09c73d776ec0af295f259f67e53f5ea1 (diff) |
update import script to handle superseded patch revisions
Diffstat (limited to 'import_emails.py')
-rwxr-xr-x | import_emails.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/import_emails.py b/import_emails.py index 079492f..7c9467e 100755 --- a/import_emails.py +++ b/import_emails.py @@ -3,18 +3,52 @@ from bin import django_setup, get_logger django_setup() # must be called to get sys.path and django settings in place +import difflib import email +import re import imaplib from patchwork.bin import parsemail +from patchwork.models import Patch, State log = get_logger('import_emails') +def find_old_revisions(patch): + log.debug('looking for old versions of patch %d', patch.id) + proj = patch.project + submitter = patch.submitter + potential = Patch.objects.filter(project=proj, submitter=submitter) + exclude_states = State.objects.filter(name__in=('Accepted', 'Superseded')) + + for p in potential.exclude(state__in=exclude_states): + if p.id == patch.id: + continue # skip ourself + matcher = difflib.SequenceMatcher(None, p.name, patch.name) + if matcher.ratio() > 0.9: + # title's seem to match, check commit + matcher = difflib.SequenceMatcher(None, p.content, patch.content) + if matcher.ratio() > 0.9: + # 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. + pot = re.sub(r'\[[^\]]*\]', '', p.name).strip() + cur = re.sub(r'\[[^\]]*\]', '', patch.name).strip() + if (pot.startswith('Revert') and not cur.startswith('Revert')): + continue + yield p + + def process_message(msg): msg = email.message_from_string(msg) # TODO how could we better check for errors in parse_mail parsemail.parse_mail(msg) + for patch in Patch.objects.filter(msgid=msg.get('Message-Id').strip()): + for old in find_old_revisions(patch): + log.info('marking patch %d as superseded by %d', patch.id, old.id) + old.state = State.objects.get(name='Superseded') + old.save() def move_message(mail, uid, folder): |