# HG changeset patch # User Matt Mackall # Date 1180741214 18000 # Node ID b2b55acbacdd6d52f62911cd7df242a4ce610460 # Parent 6cbfa740c1291eb69e842747a47cbcbae72ee12c Add support for url#id syntax This allows you to do: hg clone http://server/repo#stable which is equivalent to: hg clone -r stable http://server/repo Future incoming, outgoing, and push commands will default to using this id because it's recorded in the default path. Other commands that accept URLs (push, pull, bundle, incoming, and outgoing) also accept this syntax. diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -11,6 +11,15 @@ import os, sys, mdiff, bdiff, util, temp revrangesep = ':' +def parseurl(url, revs): + '''parse url#branch, returning url, branch + revs''' + + if '#' not in url: + return url, (revs or None) + + url, rev = url.split('#', 1) + return url, revs + [rev] + def revpair(repo, revs): '''return pair of nodes, given list of revisions. second item can be None, meaning use working dir.''' diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -336,7 +336,8 @@ def bundle(ui, repo, fname, dest=None, * visit.append(p) else: setremoteconfig(ui, opts) - dest = ui.expandpath(dest or 'default-push', dest or 'default') + dest, revs = cmdutil.parseurl( + ui.expandpath(dest or 'default-push', dest or 'default'), revs) other = hg.repository(ui, dest) o = repo.findoutgoing(other, force=opts['force']) @@ -407,7 +408,7 @@ def clone(ui, source, dest=None, **opts) about ssh:// URLs. """ setremoteconfig(ui, opts) - hg.clone(ui, ui.expandpath(source), dest, + hg.clone(ui, source, dest, pull=opts['pull'], stream=opts['uncompressed'], rev=opts['rev'], @@ -1588,15 +1589,14 @@ def incoming(ui, repo, source="default", See pull for valid source format details. """ - source = ui.expandpath(source) + source, revs = cmdutil.parseurl(ui.expandpath(source), opts['rev']) setremoteconfig(ui, opts) other = hg.repository(ui, source) ui.status(_('comparing with %s\n') % source) - revs = None - if opts['rev']: + if revs: if 'lookup' in other.capabilities: - revs = [other.lookup(rev) for rev in opts['rev']] + revs = [other.lookup(rev) for rev in revs] else: error = _("Other repository doesn't support revision lookup, so a rev cannot be specified.") raise util.Abort(error) @@ -1891,11 +1891,11 @@ def outgoing(ui, repo, dest=None, **opts See pull for valid destination format details. """ - dest = ui.expandpath(dest or 'default-push', dest or 'default') + dest, revs = cmdutil.parseurl( + ui.expandpath(dest or 'default-push', dest or 'default'), opts['rev']) setremoteconfig(ui, opts) - revs = None - if opts['rev']: - revs = [repo.lookup(rev) for rev in opts['rev']] + if revs: + revs = [repo.lookup(rev) for rev in revs] other = hg.repository(ui, dest) ui.status(_('comparing with %s\n') % dest) @@ -1989,6 +1989,9 @@ def pull(ui, repo, source="default", **o allows access to a Mercurial repository where you simply use a web server to publish the .hg directory as static content. + An optional identifier after # indicates a particular branch, tag, + or changeset to pull. + Some notes about using SSH with Mercurial: - SSH requires an accessible shell account on the destination machine and a copy of hg in the remote path or specified with as remotecmd. @@ -2004,18 +2007,18 @@ def pull(ui, repo, source="default", **o Alternatively specify "ssh -C" as your ssh command in your hgrc or with the --ssh command line option. """ - source = ui.expandpath(source) + source, revs = cmdutil.parseurl(ui.expandpath(source), opts['rev']) setremoteconfig(ui, opts) other = hg.repository(ui, source) ui.status(_('pulling from %s\n') % (source)) - revs = None - if opts['rev']: + if revs: if 'lookup' in other.capabilities: - revs = [other.lookup(rev) for rev in opts['rev']] + revs = [other.lookup(rev) for rev in revs] else: error = _("Other repository doesn't support revision lookup, so a rev cannot be specified.") raise util.Abort(error) + modheads = repo.pull(other, heads=revs, force=opts['force']) return postincoming(ui, repo, modheads, opts['update']) @@ -2040,20 +2043,23 @@ def push(ui, repo, dest=None, **opts): http://[user@]host[:port]/[path] https://[user@]host[:port]/[path] + An optional identifier after # indicates a particular branch, tag, + or changeset to push. + Look at the help text for the pull command for important details about ssh:// URLs. Pushing to http:// and https:// URLs is only possible, if this feature is explicitly enabled on the remote Mercurial server. """ - dest = ui.expandpath(dest or 'default-push', dest or 'default') + dest, revs = cmdutil.parseurl( + ui.expandpath(dest or 'default-push', dest or 'default'), opts['rev']) setremoteconfig(ui, opts) other = hg.repository(ui, dest) ui.status('pushing to %s\n' % (dest)) - revs = None - if opts['rev']: - revs = [repo.lookup(rev) for rev in opts['rev']] + if revs: + revs = [repo.lookup(rev) for rev in revs] r = repo.push(other, opts['force'], revs=revs) return r == 0 diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -10,7 +10,7 @@ from node import * from repo import * from i18n import _ import localrepo, bundlerepo, httprepo, sshrepo, statichttprepo -import errno, lock, os, shutil, util +import errno, lock, os, shutil, util, cmdutil import merge as _merge import verify as _verify @@ -97,6 +97,10 @@ def clone(ui, source, dest=None, pull=Fa update: update working directory after clone completes, if destination is local repository """ + + origsource = source + source, rev = cmdutil.parseurl(ui.expandpath(source), rev) + if isinstance(source, str): src_repo = repository(ui, source) else: @@ -134,10 +138,10 @@ def clone(ui, source, dest=None, pull=Fa if islocal(dest): dir_cleanup = DirCleanup(dest) - abspath = source + abspath = origsource copy = False if src_repo.local() and islocal(dest): - abspath = os.path.abspath(source) + abspath = os.path.abspath(origsource) copy = not pull and not rev src_lock, dest_lock = None, None