From f0074dfd57dc6238c730b462cdda6d048eaabbd3 Mon Sep 17 00:00:00 2001 From: Konstantin Ryabitsev Date: Mon, 23 Mar 2020 13:58:04 -0400 Subject: Use more unique mbx names by adding subjects When the same person sends multiple sets of patches on the same day, we risk colliding between them. Use mbx names with cover/1st-patch subjects in them, to help disambiguate in such cases. Reported-by: Mark Brown Signed-off-by: Konstantin Ryabitsev --- b4/__init__.py | 12 +++++++++--- b4/mbox.py | 8 +++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/b4/__init__.py b/b4/__init__.py index 467da13..ee5f1dc 100644 --- a/b4/__init__.py +++ b/b4/__init__.py @@ -337,7 +337,7 @@ class LoreSeries: self.patches[lmsg.counter] = lmsg self.complete = not (None in self.patches[1:]) - def get_slug(self): + def get_slug(self, extended=False): # Find the first non-None entry lmsg = None for lmsg in self.patches: @@ -349,8 +349,14 @@ class LoreSeries: prefix = lmsg.date.strftime('%Y%m%d') authorline = email.utils.getaddresses(lmsg.msg.get_all('from', []))[0] - author = re.sub(r'\W+', '_', authorline[1]).strip('_').lower() - slug = '%s_%s' % (prefix, author) + if extended: + local = authorline[1].split('@')[0] + unsafe = '%s_%s_%s' % (prefix, local, lmsg.subject) + slug = re.sub(r'\W+', '_', unsafe).strip('_').lower() + else: + author = re.sub(r'\W+', '_', authorline[1]).strip('_').lower() + slug = '%s_%s' % (prefix, author) + if self.revision != 1: slug = 'v%s_%s' % (self.revision, slug) diff --git a/b4/mbox.py b/b4/mbox.py index f4ae178..bb18fc9 100644 --- a/b4/mbox.py +++ b/b4/mbox.py @@ -128,8 +128,10 @@ def mbox_to_am(mboxfile, config, cmdargs): slug = wantname if wantname.find('.') > -1: slug = '.'.join(wantname.split('.')[:-1]) + gitbranch = slug else: - slug = lser.get_slug() + slug = lser.get_slug(extended=True) + gitbranch = lser.get_slug(extended=False) am_filename = os.path.join(outdir, '%s.mbx' % slug) am_cover = os.path.join(outdir, '%s.cover' % slug) @@ -193,11 +195,11 @@ def mbox_to_am(mboxfile, config, cmdargs): if base_commit: logger.critical(' Base: %s', base_commit) - logger.critical(' git checkout -b %s %s', slug, base_commit) + 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', slug) + logger.critical(' git checkout -b %s master', gitbranch) logger.critical(' git am %s', am_filename) am_mbx.close() -- cgit v1.2.3