# HG changeset patch # User Eric Hopper # Date 1128739869 25200 # Node ID 02099220ad4952b5e8d56197566b0df82f802140 # Parent 40d08cf1c54430d19202d68a79d8b4e88ae3d78a Implementing clone -r, which clones all changesets needed to reach a particular revision. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -627,7 +627,7 @@ def clone(ui, source, dest=None, **opts) copy = False if other.dev() != -1: abspath = os.path.abspath(source) - if not opts['pull']: + if not opts['pull'] and not opts['rev']: copy = True if copy: @@ -655,7 +655,10 @@ def clone(ui, source, dest=None, **opts) else: repo = hg.repository(ui, dest, create=1) - repo.pull(other) + rev = None + if opts['rev']: + rev = [other.lookup(opts['rev'])] + repo.pull(other, heads = rev) f = repo.opener("hgrc", "w", text=True) f.write("[paths]\n") @@ -1782,6 +1785,7 @@ table = { (clone, [('U', 'noupdate', None, 'skip update after cloning'), ('e', 'ssh', "", 'ssh command'), + ('r', 'rev', "", 'only clone changesets needed to create revision'), ('', 'pull', None, 'use pull protocol to copy metadata'), ('', 'remotecmd', "", 'remote hg command')], 'hg clone [OPTION]... SOURCE [DEST]'), diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -850,7 +850,7 @@ class localrepository: # this is the set of all roots we have to push return subset - def pull(self, remote): + def pull(self, remote, heads = None): lock = self.lock() # if we have an empty repo, fetch everything @@ -864,7 +864,10 @@ class localrepository: self.ui.status("no changes found\n") return 1 - cg = remote.changegroup(fetch) + if heads is None: + cg = remote.changegroup(fetch) + else: + cg = remote.changegroupsubset(fetch, heads) return self.addchangegroup(cg) def push(self, remote, force=False):