[PATCH 1 of 7 🚿🍦] patchbomb: extract 'getoutgoing' closure in its own function
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Thu Nov 6 15:46:20 UTC 2014
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1415136179 0
# Tue Nov 04 21:22:59 2014 +0000
# Node ID 66beee640558544d50494f67ae281ccec34eae06
# Parent 2d54aa5397cdb1c697673ba10b7618d5ac25c69e
patchbomb: extract 'getoutgoing' closure in its own function
The patchbomb command is a gigantic 300 lines function full of closures. As a
first step to simplify it in smaller bits, I'm extraction the closures into full
featured functions. The first victim is 'getoutgoing'. It gain a docstring in
the process.
diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -151,10 +151,29 @@ def makepatch(ui, repo, patchlines, opts
msg['X-Mercurial-Node'] = node
msg['X-Mercurial-Series-Index'] = '%i' % idx
msg['X-Mercurial-Series-Total'] = '%i' % total
return msg, subj, ds
+def _getoutgoing(repo, dest, revs):
+ '''Return the revisions present locally but not in dest
+
+ Revisions are returned as a list of short hashes.'''
+ ui = repo.ui
+ url = ui.expandpath(dest or 'default-push', dest or 'default')
+ url = hg.parseurl(url)[0]
+ ui.status(_('comparing with %s\n') % util.hidepassword(url))
+
+ revs = [r for r in scmutil.revrange(repo, revs) if r >= 0]
+ if not revs:
+ revs = [len(repo) - 1]
+ revs = repo.revs('outgoing(%s) and ::%ld', dest or '', revs)
+ if not revs:
+ ui.status(_("no changes found\n"))
+ return []
+ return [str(r) for r in revs]
+
+
emailopts = [
('', 'body', None, _('send patches as inline message text (default)')),
('a', 'attach', None, _('send patches as attachments')),
('i', 'inline', None, _('send patches as inline attachments')),
('', 'bcc', [], _('email addresses of blind carbon copy recipients')),
@@ -275,25 +294,10 @@ def patchbomb(ui, repo, *revs, **opts):
outgoing = opts.get('outgoing')
rev = opts.get('rev')
# internal option used by pbranches
patches = opts.get('patches')
- def getoutgoing(dest, revs):
- '''Return the revisions present locally but not in dest'''
- url = ui.expandpath(dest or 'default-push', dest or 'default')
- url = hg.parseurl(url)[0]
- ui.status(_('comparing with %s\n') % util.hidepassword(url))
-
- revs = [r for r in scmutil.revrange(repo, revs) if r >= 0]
- if not revs:
- revs = [len(repo) - 1]
- revs = repo.revs('outgoing(%s) and ::%ld', dest or '', revs)
- if not revs:
- ui.status(_("no changes found\n"))
- return []
- return [str(r) for r in revs]
-
def getpatches(revs):
prev = repo['.'].rev()
for r in scmutil.revrange(repo, revs):
if r == prev and (repo[None].files() or repo[None].deleted()):
ui.warn(_('warning: working directory has '
@@ -340,11 +344,11 @@ def patchbomb(ui, repo, *revs, **opts):
if revs:
raise util.Abort(_('use only one form to specify the revision'))
revs = rev
if outgoing:
- revs = getoutgoing(dest, rev)
+ revs = _getoutgoing(repo, dest, rev)
if bundle:
opts['revs'] = revs
# start
if date:
More information about the Mercurial-devel
mailing list