[PATCH 1 of 2] cmdutil: factor out pushdest functionality for easier extensibility
Ryan McElroy
rmcelroy at fb.com
Thu Feb 12 08:41:04 UTC 2015
# HG changeset patch
# User Ryan McElroy <rmcelroy at fb.com>
# Date 1423729187 28800
# Thu Feb 12 00:19:47 2015 -0800
# Node ID 05e7d10145be0af89e1eb6cf70c56e97f81101ab
# Parent ff5caa8dfd993680d9602ca6ebb14da9de10d5f4
cmdutil: factor out pushdest functionality for easier extensibility
In the remotenames extension, we replace large parts of the functionality of
the push command. By factoring out this code, we can call it from the extension
and no longer have a copy of it in the extension.
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -15,6 +15,7 @@ import changelog
import bookmarks
import encoding
import lock as lockmod
+import hg
def parsealiases(cmd):
return cmd.lstrip("^").split("|")
@@ -2960,3 +2961,19 @@ def clearunfinished(repo):
for f, clearable, allowcommit, msg, hint in unfinishedstates:
if clearable and repo.vfs.exists(f):
util.unlink(repo.join(f))
+
+def pushdest(ui, repo, dest, opts):
+ dest = ui.expandpath(dest or 'default-push', dest or 'default')
+ dest, branches = hg.parseurl(dest, opts.get('branch'))
+ ui.status(_('pushing to %s\n') % util.hidepassword(dest))
+ revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev'))
+ try:
+ other = hg.peer(repo, opts, dest)
+ except error.RepoError:
+ if dest == "default-push":
+ raise util.Abort(_("default repository not configured!"),
+ hint=_('see the "path" section in "hg help config"'))
+ else:
+ raise
+
+ return (dest, branches, revs, other)
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5083,18 +5083,7 @@ def push(ui, repo, dest=None, **opts):
# this lets simultaneous -r, -b options continue working
opts.setdefault('rev', []).append("null")
- dest = ui.expandpath(dest or 'default-push', dest or 'default')
- dest, branches = hg.parseurl(dest, opts.get('branch'))
- ui.status(_('pushing to %s\n') % util.hidepassword(dest))
- revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev'))
- try:
- other = hg.peer(repo, opts, dest)
- except error.RepoError:
- if dest == "default-push":
- raise util.Abort(_("default repository not configured!"),
- hint=_('see the "path" section in "hg help config"'))
- else:
- raise
+ dest, branches, revs, other = cmdutil.pushdest(ui, repo, dest, opts)
if revs:
revs = [repo.lookup(r) for r in scmutil.revrange(repo, revs)]
More information about the Mercurial-devel
mailing list