D974: py3: handle keyword arguments correctly in hgext/patchbomb.py
This revision was automatically updated to reflect the committed changes. Closed by commit rHG71e63fe6b1ab: py3: handle keyword arguments correctly in hgext/patchbomb.py (authored by pulkit, committed by ). REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D974?vs=3376&id=3444 REVISION DETAIL https://phab.mercurial-scm.org/D974 AFFECTED FILES hgext/patchbomb.py CHANGE DETAILS diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py --- a/hgext/patchbomb.py +++ b/hgext/patchbomb.py @@ -89,6 +89,7 @@ mail, node as nodemod, patch, +pycompat, registrar, repair, scmutil, @@ -318,7 +319,7 @@ tmpfn = os.path.join(tmpdir, 'bundle') btype = ui.config('patchbomb', 'bundletype') if btype: -opts['type'] = btype +opts[r'type'] = btype try: commands.bundle(ui, repo, tmpfn, dest, **opts) return util.readfile(tmpfn) @@ -338,8 +339,8 @@ the user through the editor. """ ui = repo.ui -if opts.get('desc'): -body = open(opts.get('desc')).read() +if opts.get(r'desc'): +body = open(opts.get(r'desc')).read() else: ui.write(_('\nWrite the introductory message for the ' 'patch series.\n\n')) @@ -359,21 +360,21 @@ """ ui = repo.ui _charsets = mail._charsets(ui) -subj = (opts.get('subject') +subj = (opts.get(r'subject') or prompt(ui, 'Subject:', 'A bundle for your repository')) body = _getdescription(repo, '', sender, **opts) msg = emailmod.MIMEMultipart.MIMEMultipart() if body: -msg.attach(mail.mimeencode(ui, body, _charsets, opts.get('test'))) +msg.attach(mail.mimeencode(ui, body, _charsets, opts.get(r'test'))) datapart = emailmod.MIMEBase.MIMEBase('application', 'x-mercurial-bundle') datapart.set_payload(bundle) -bundlename = '%s.hg' % opts.get('bundlename', 'bundle') +bundlename = '%s.hg' % opts.get(r'bundlename', 'bundle') datapart.add_header('Content-Disposition', 'attachment', filename=bundlename) emailmod.Encoders.encode_base64(datapart) msg.attach(datapart) -msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get('test')) +msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get(r'test')) return [(msg, subj, None)] def _makeintro(repo, sender, revs, patches, **opts): @@ -384,27 +385,27 @@ _charsets = mail._charsets(ui) # use the last revision which is likely to be a bookmarked head -prefix = _formatprefix(ui, repo, revs.last(), opts.get('flag'), +prefix = _formatprefix(ui, repo, revs.last(), opts.get(r'flag'), 0, len(patches), numbered=True) -subj = (opts.get('subject') or +subj = (opts.get(r'subject') or prompt(ui, '(optional) Subject: ', rest=prefix, default='')) if not subj: return None # skip intro if the user doesn't bother subj = prefix + ' ' + subj body = '' -if opts.get('diffstat'): +if opts.get(r'diffstat'): # generate a cumulative diffstat of the whole patch series diffstat = patch.diffstat(sum(patches, [])) body = '\n' + diffstat else: diffstat = None body = _getdescription(repo, body, sender, **opts) -msg = mail.mimeencode(ui, body, _charsets, opts.get('test')) +msg = mail.mimeencode(ui, body, _charsets, opts.get(r'test')) msg['Subject'] = mail.headencode(ui, subj, _charsets, - opts.get('test')) + opts.get(r'test')) return (msg, subj, diffstat) def _getpatchmsgs(repo, sender, revs, patchnames=None, **opts): @@ -414,6 +415,7 @@ This function returns a list of "email" tuples (subject, content, None). """ +bytesopts = pycompat.byteskwargs(opts) ui = repo.ui _charsets = mail._charsets(ui) patches = list(_getpatches(repo, revs, **opts)) @@ -423,7 +425,7 @@ % len(patches)) # build the intro message, or skip it if the user declines -if introwanted(ui, opts, len(patches)): +if introwanted(ui, bytesopts, len(patches)): msg = _makeintro(repo, sender, revs, patches, **opts) if msg: msgs.append(msg) @@ -437,8 +439,8 @@ for i, (r, p) in enumerate(zip(revs, patches)): if patchnames: name = patchnames[i] -msg = makepatch(ui, repo, r, p, opts, _charsets, i + 1, -len(patches), numbered, name) +msg = makepatch(ui, repo, r, p, bytesopts, _charsets, +i + 1, len(patches), numbered, name) msgs.append(msg) return msgs @@ -579,6 +581,7 @@ Before using this command, you will need to enable email in your hgrc. See the [email] section in hgrc(5) for details. ''' +opts = pycompat.byteskwargs(opts) _charsets = mail._cha
D974: py3: handle keyword arguments correctly in hgext/patchbomb.py
yuja accepted this revision. yuja added a comment. This revision is now accepted and ready to land. Queued this, thanks. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D974 To: pulkit, #hg-reviewers, yuja Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D974: py3: handle keyword arguments correctly in hgext/patchbomb.py
pulkit updated this revision to Diff 3376. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D974?vs=3231&id=3376 REVISION DETAIL https://phab.mercurial-scm.org/D974 AFFECTED FILES hgext/patchbomb.py CHANGE DETAILS diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py --- a/hgext/patchbomb.py +++ b/hgext/patchbomb.py @@ -89,6 +89,7 @@ mail, node as nodemod, patch, +pycompat, registrar, repair, scmutil, @@ -318,7 +319,7 @@ tmpfn = os.path.join(tmpdir, 'bundle') btype = ui.config('patchbomb', 'bundletype') if btype: -opts['type'] = btype +opts[r'type'] = btype try: commands.bundle(ui, repo, tmpfn, dest, **opts) return util.readfile(tmpfn) @@ -338,8 +339,8 @@ the user through the editor. """ ui = repo.ui -if opts.get('desc'): -body = open(opts.get('desc')).read() +if opts.get(r'desc'): +body = open(opts.get(r'desc')).read() else: ui.write(_('\nWrite the introductory message for the ' 'patch series.\n\n')) @@ -359,21 +360,21 @@ """ ui = repo.ui _charsets = mail._charsets(ui) -subj = (opts.get('subject') +subj = (opts.get(r'subject') or prompt(ui, 'Subject:', 'A bundle for your repository')) body = _getdescription(repo, '', sender, **opts) msg = emailmod.MIMEMultipart.MIMEMultipart() if body: -msg.attach(mail.mimeencode(ui, body, _charsets, opts.get('test'))) +msg.attach(mail.mimeencode(ui, body, _charsets, opts.get(r'test'))) datapart = emailmod.MIMEBase.MIMEBase('application', 'x-mercurial-bundle') datapart.set_payload(bundle) -bundlename = '%s.hg' % opts.get('bundlename', 'bundle') +bundlename = '%s.hg' % opts.get(r'bundlename', 'bundle') datapart.add_header('Content-Disposition', 'attachment', filename=bundlename) emailmod.Encoders.encode_base64(datapart) msg.attach(datapart) -msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get('test')) +msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get(r'test')) return [(msg, subj, None)] def _makeintro(repo, sender, revs, patches, **opts): @@ -384,27 +385,27 @@ _charsets = mail._charsets(ui) # use the last revision which is likely to be a bookmarked head -prefix = _formatprefix(ui, repo, revs.last(), opts.get('flag'), +prefix = _formatprefix(ui, repo, revs.last(), opts.get(r'flag'), 0, len(patches), numbered=True) -subj = (opts.get('subject') or +subj = (opts.get(r'subject') or prompt(ui, '(optional) Subject: ', rest=prefix, default='')) if not subj: return None # skip intro if the user doesn't bother subj = prefix + ' ' + subj body = '' -if opts.get('diffstat'): +if opts.get(r'diffstat'): # generate a cumulative diffstat of the whole patch series diffstat = patch.diffstat(sum(patches, [])) body = '\n' + diffstat else: diffstat = None body = _getdescription(repo, body, sender, **opts) -msg = mail.mimeencode(ui, body, _charsets, opts.get('test')) +msg = mail.mimeencode(ui, body, _charsets, opts.get(r'test')) msg['Subject'] = mail.headencode(ui, subj, _charsets, - opts.get('test')) + opts.get(r'test')) return (msg, subj, diffstat) def _getpatchmsgs(repo, sender, revs, patchnames=None, **opts): @@ -414,6 +415,7 @@ This function returns a list of "email" tuples (subject, content, None). """ +bytesopts = pycompat.byteskwargs(opts) ui = repo.ui _charsets = mail._charsets(ui) patches = list(_getpatches(repo, revs, **opts)) @@ -423,7 +425,7 @@ % len(patches)) # build the intro message, or skip it if the user declines -if introwanted(ui, opts, len(patches)): +if introwanted(ui, bytesopts, len(patches)): msg = _makeintro(repo, sender, revs, patches, **opts) if msg: msgs.append(msg) @@ -437,8 +439,8 @@ for i, (r, p) in enumerate(zip(revs, patches)): if patchnames: name = patchnames[i] -msg = makepatch(ui, repo, r, p, opts, _charsets, i + 1, -len(patches), numbered, name) +msg = makepatch(ui, repo, r, p, bytesopts, _charsets, +i + 1, len(patches), numbered, name) msgs.append(msg) return msgs @@ -579,6 +581,7 @@ Before using this command, you will need to enable email in your hgrc. See the [email] section in hgrc(5) for details. ''' +opts = pycompat.byteskwargs(opts) _charsets = mail._charsets(ui) @@ -672,12 +675,13 @@ prompt(ui, 'From', ui.username())) if bundle: -bundledata = _getbundle(repo, dest, **opts) -b
D974: py3: handle keyword arguments correctly in hgext/patchbomb.py
yuja requested changes to this revision. yuja added inline comments. This revision now requires changes to proceed. INLINE COMMENTS > yuja wrote in patchbomb.py:618 > opts is modified here, but stropts isn't. Perhaps we shouldn't > keep the copy for long. I think it's better to use a single bytes dict instead of managing two copies carefully. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D974 To: pulkit, #hg-reviewers, yuja Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D974: py3: handle keyword arguments correctly in hgext/patchbomb.py
pulkit updated this revision to Diff 3231. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D974?vs=2497&id=3231 REVISION DETAIL https://phab.mercurial-scm.org/D974 AFFECTED FILES hgext/patchbomb.py CHANGE DETAILS diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py --- a/hgext/patchbomb.py +++ b/hgext/patchbomb.py @@ -89,6 +89,7 @@ mail, node as nodemod, patch, +pycompat, registrar, repair, scmutil, @@ -318,7 +319,7 @@ tmpfn = os.path.join(tmpdir, 'bundle') btype = ui.config('patchbomb', 'bundletype') if btype: -opts['type'] = btype +opts[r'type'] = btype try: commands.bundle(ui, repo, tmpfn, dest, **opts) return util.readfile(tmpfn) @@ -338,8 +339,8 @@ the user through the editor. """ ui = repo.ui -if opts.get('desc'): -body = open(opts.get('desc')).read() +if opts.get(r'desc'): +body = open(opts.get(r'desc')).read() else: ui.write(_('\nWrite the introductory message for the ' 'patch series.\n\n')) @@ -359,21 +360,21 @@ """ ui = repo.ui _charsets = mail._charsets(ui) -subj = (opts.get('subject') +subj = (opts.get(r'subject') or prompt(ui, 'Subject:', 'A bundle for your repository')) body = _getdescription(repo, '', sender, **opts) msg = emailmod.MIMEMultipart.MIMEMultipart() if body: -msg.attach(mail.mimeencode(ui, body, _charsets, opts.get('test'))) +msg.attach(mail.mimeencode(ui, body, _charsets, opts.get(r'test'))) datapart = emailmod.MIMEBase.MIMEBase('application', 'x-mercurial-bundle') datapart.set_payload(bundle) -bundlename = '%s.hg' % opts.get('bundlename', 'bundle') +bundlename = '%s.hg' % opts.get(r'bundlename', 'bundle') datapart.add_header('Content-Disposition', 'attachment', filename=bundlename) emailmod.Encoders.encode_base64(datapart) msg.attach(datapart) -msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get('test')) +msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get(r'test')) return [(msg, subj, None)] def _makeintro(repo, sender, revs, patches, **opts): @@ -384,27 +385,27 @@ _charsets = mail._charsets(ui) # use the last revision which is likely to be a bookmarked head -prefix = _formatprefix(ui, repo, revs.last(), opts.get('flag'), +prefix = _formatprefix(ui, repo, revs.last(), opts.get(r'flag'), 0, len(patches), numbered=True) -subj = (opts.get('subject') or +subj = (opts.get(r'subject') or prompt(ui, '(optional) Subject: ', rest=prefix, default='')) if not subj: return None # skip intro if the user doesn't bother subj = prefix + ' ' + subj body = '' -if opts.get('diffstat'): +if opts.get(r'diffstat'): # generate a cumulative diffstat of the whole patch series diffstat = patch.diffstat(sum(patches, [])) body = '\n' + diffstat else: diffstat = None body = _getdescription(repo, body, sender, **opts) -msg = mail.mimeencode(ui, body, _charsets, opts.get('test')) +msg = mail.mimeencode(ui, body, _charsets, opts.get(r'test')) msg['Subject'] = mail.headencode(ui, subj, _charsets, - opts.get('test')) + opts.get(r'test')) return (msg, subj, diffstat) def _getpatchmsgs(repo, sender, revs, patchnames=None, **opts): @@ -414,6 +415,7 @@ This function returns a list of "email" tuples (subject, content, None). """ +bytesopts = pycompat.byteskwargs(opts) ui = repo.ui _charsets = mail._charsets(ui) patches = list(_getpatches(repo, revs, **opts)) @@ -423,7 +425,7 @@ % len(patches)) # build the intro message, or skip it if the user declines -if introwanted(ui, opts, len(patches)): +if introwanted(ui, bytesopts, len(patches)): msg = _makeintro(repo, sender, revs, patches, **opts) if msg: msgs.append(msg) @@ -437,8 +439,8 @@ for i, (r, p) in enumerate(zip(revs, patches)): if patchnames: name = patchnames[i] -msg = makepatch(ui, repo, r, p, opts, _charsets, i + 1, -len(patches), numbered, name) +msg = makepatch(ui, repo, r, p, bytesopts, _charsets, +i + 1, len(patches), numbered, name) msgs.append(msg) return msgs @@ -579,6 +581,8 @@ Before using this command, you will need to enable email in your hgrc. See the [email] section in hgrc(5) for details. ''' +stropts = opts +opts = pycompat.byteskwargs(opts) _charsets = mail._charsets(ui) @@ -625,6 +629,7 @@ revs = _getoutgoing(repo, dest, revs) if bundle: opts['revs'] = [str(r) for r in revs] +
D974: py3: handle keyword arguments correctly in hgext/patchbomb.py
pulkit abandoned this revision. pulkit added a comment. Will revisit after the freeze. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D974 To: pulkit, #hg-reviewers, yuja Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D974: py3: handle keyword arguments correctly in hgext/patchbomb.py
pulkit added a comment. In https://phab.mercurial-scm.org/D974#16430, @yuja wrote: > and missing import of pycompat. Please make sure all tests pass. Oops, sorry. I am not sure ow this one slipped in without passing tests. I will be more careful from now. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D974 To: pulkit, #hg-reviewers, yuja Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D974: py3: handle keyword arguments correctly in hgext/patchbomb.py
yuja requested changes to this revision. yuja added a comment. This revision now requires changes to proceed. and missing import of pycompat. Please make sure all tests pass. INLINE COMMENTS > patchbomb.py:618 > if bundle: > opts['revs'] = [str(r) for r in revs] > opts is modified here, but stropts isn't. Perhaps we shouldn't keep the copy for long. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D974 To: pulkit, #hg-reviewers, yuja Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D974: py3: handle keyword arguments correctly in hgext/patchbomb.py
pulkit created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY The keys of keyword arguments must be str on Python 3 which is unicode. This patch make sure we pass keyword arguments with keys are str everywhere in this file and access the keys depending on whether they are bytes or str. This patch uses pycompat.{byteskwargs|strkwargs} and somewhere it also added r'' to prevent transformer from adding a b'' over there. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D974 AFFECTED FILES hgext/patchbomb.py CHANGE DETAILS diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py --- a/hgext/patchbomb.py +++ b/hgext/patchbomb.py @@ -306,7 +306,7 @@ tmpfn = os.path.join(tmpdir, 'bundle') btype = ui.config('patchbomb', 'bundletype') if btype: -opts['type'] = btype +opts[r'type'] = btype try: commands.bundle(ui, repo, tmpfn, dest, **opts) return util.readfile(tmpfn) @@ -326,8 +326,8 @@ the user through the editor. """ ui = repo.ui -if opts.get('desc'): -body = open(opts.get('desc')).read() +if opts.get(r'desc'): +body = open(opts.get(r'desc')).read() else: ui.write(_('\nWrite the introductory message for the ' 'patch series.\n\n')) @@ -347,21 +347,21 @@ """ ui = repo.ui _charsets = mail._charsets(ui) -subj = (opts.get('subject') +subj = (opts.get(r'subject') or prompt(ui, 'Subject:', 'A bundle for your repository')) body = _getdescription(repo, '', sender, **opts) msg = emailmod.MIMEMultipart.MIMEMultipart() if body: -msg.attach(mail.mimeencode(ui, body, _charsets, opts.get('test'))) +msg.attach(mail.mimeencode(ui, body, _charsets, opts.get(r'test'))) datapart = emailmod.MIMEBase.MIMEBase('application', 'x-mercurial-bundle') datapart.set_payload(bundle) -bundlename = '%s.hg' % opts.get('bundlename', 'bundle') +bundlename = '%s.hg' % opts.get(r'bundlename', 'bundle') datapart.add_header('Content-Disposition', 'attachment', filename=bundlename) emailmod.Encoders.encode_base64(datapart) msg.attach(datapart) -msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get('test')) +msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get(r'test')) return [(msg, subj, None)] def _makeintro(repo, sender, revs, patches, **opts): @@ -372,27 +372,27 @@ _charsets = mail._charsets(ui) # use the last revision which is likely to be a bookmarked head -prefix = _formatprefix(ui, repo, revs.last(), opts.get('flag'), +prefix = _formatprefix(ui, repo, revs.last(), opts.get(r'flag'), 0, len(patches), numbered=True) -subj = (opts.get('subject') or +subj = (opts.get(r'subject') or prompt(ui, '(optional) Subject: ', rest=prefix, default='')) if not subj: return None # skip intro if the user doesn't bother subj = prefix + ' ' + subj body = '' -if opts.get('diffstat'): +if opts.get(r'diffstat'): # generate a cumulative diffstat of the whole patch series diffstat = patch.diffstat(sum(patches, [])) body = '\n' + diffstat else: diffstat = None body = _getdescription(repo, body, sender, **opts) -msg = mail.mimeencode(ui, body, _charsets, opts.get('test')) +msg = mail.mimeencode(ui, body, _charsets, opts.get(r'test')) msg['Subject'] = mail.headencode(ui, subj, _charsets, - opts.get('test')) + opts.get(r'test')) return (msg, subj, diffstat) def _getpatchmsgs(repo, sender, revs, patchnames=None, **opts): @@ -402,6 +402,7 @@ This function returns a list of "email" tuples (subject, content, None). """ +bytesopts = pycompat.byteskwargs(opts) ui = repo.ui _charsets = mail._charsets(ui) patches = list(_getpatches(repo, revs, **opts)) @@ -411,7 +412,7 @@ % len(patches)) # build the intro message, or skip it if the user declines -if introwanted(ui, opts, len(patches)): +if introwanted(ui, bytesopts, len(patches)): msg = _makeintro(repo, sender, revs, patches, **opts) if msg: msgs.append(msg) @@ -425,8 +426,8 @@ for i, (r, p) in enumerate(zip(revs, patches)): if patchnames: name = patchnames[i] -msg = makepatch(ui, repo, r, p, opts, _charsets, i + 1, -len(patches), numbered, name) +msg = makepatch(ui, repo, r, p, bytesopts, _charsets, +i + 1, len(patches), numbered, name) msgs.append(msg) return msgs @@ -567,6 +568,8 @@ Before using this command, you will need to enable email in your hgrc. See the [email] section in hgr