comparison hgext/patchbomb.py @ 39035:cecb05c371f7

patchbomb: don't unintentionally duplicate headers This dict-like of headers is only mostly dict-like: if you set a key that already exists, you it appends another value, rather than replacing the one that was already present. This fixes test-patchbomb-bookmark.t on Python 3. Differential Revision: https://phab.mercurial-scm.org/D4229
author Augie Fackler <augie@google.com>
date Thu, 09 Aug 2018 19:39:33 -0400
parents 751caa6a2936
children 2161faf0d24b
comparison
equal deleted inserted replaced
39034:751caa6a2936 39035:cecb05c371f7
787 m['Reply-To'] = ', '.join(replyto) 787 m['Reply-To'] = ', '.join(replyto)
788 # Fix up all headers to be native strings. 788 # Fix up all headers to be native strings.
789 # TODO(durin42): this should probably be cleaned up above in the future. 789 # TODO(durin42): this should probably be cleaned up above in the future.
790 if pycompat.ispy3: 790 if pycompat.ispy3:
791 for hdr, val in list(m.items()): 791 for hdr, val in list(m.items()):
792 change = False
792 if isinstance(hdr, bytes): 793 if isinstance(hdr, bytes):
793 del m[hdr] 794 del m[hdr]
794 hdr = pycompat.strurl(hdr) 795 hdr = pycompat.strurl(hdr)
796 change = True
795 if isinstance(val, bytes): 797 if isinstance(val, bytes):
796 val = pycompat.strurl(val) 798 val = pycompat.strurl(val)
797 m[hdr] = val 799 if not change:
800 # prevent duplicate headers
801 del m[hdr]
802 change = True
803 if change:
804 m[hdr] = val
798 if opts.get('test'): 805 if opts.get('test'):
799 ui.status(_('displaying '), subj, ' ...\n') 806 ui.status(_('displaying '), subj, ' ...\n')
800 ui.pager('email') 807 ui.pager('email')
801 generator = emailgen.Generator(_bytesgenerator(ui), 808 generator = emailgen.Generator(_bytesgenerator(ui),
802 mangle_from_=False) 809 mangle_from_=False)