# HG changeset patch # User Benoit Boissinot # Date 1139947917 -3600 # Node ID 284fc722c34297b4bbb2618ac74e1dcc007aaf4c # Parent 40346aa66b0f8c285c65f93be5fdeb21f4f364f6 add an optional argument to push only the specified revisions (push -r) diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1764,7 +1764,7 @@ def pull(ui, repo, source="default", **o return r -def push(ui, repo, dest="default-push", force=False, ssh=None, remotecmd=None): +def push(ui, repo, dest="default-push", **opts): """push changes to the specified destination Push changes from the local repository to the given destination. @@ -1789,13 +1789,16 @@ def push(ui, repo, dest="default-push", dest = ui.expandpath(dest, repo.root) ui.status('pushing to %s\n' % (dest)) - if ssh: - ui.setconfig("ui", "ssh", ssh) - if remotecmd: - ui.setconfig("ui", "remotecmd", remotecmd) + if opts['ssh']: + ui.setconfig("ui", "ssh", opts['ssh']) + if opts['remotecmd']: + ui.setconfig("ui", "remotecmd", opts['remotecmd']) other = hg.repository(ui, dest) - r = repo.push(other, force) + revs = None + if opts['rev']: + revs = [repo.lookup(rev) for rev in opts['rev']] + r = repo.push(other, opts['force'], revs=revs) return r def rawcommit(ui, repo, *flist, **rc): @@ -2417,14 +2420,15 @@ table = { ('r', 'rev', [], _('a specific revision you would like to pull')), ('', 'remotecmd', '', _('specify hg command to run on the remote side'))], - _('hg pull [-u] [-e FILE] [-r rev] [--remotecmd FILE] [SOURCE]')), + _('hg pull [-u] [-e FILE] [-r rev]... [--remotecmd FILE] [SOURCE]')), "^push": (push, [('f', 'force', None, _('force push')), ('e', 'ssh', '', _('specify ssh command to use')), + ('r', 'rev', [], _('a specific revision you would like to push')), ('', 'remotecmd', '', _('specify hg command to run on the remote side'))], - _('hg push [-f] [-e FILE] [--remotecmd FILE] [DEST]')), + _('hg push [-f] [-e FILE] [-r rev]... [--remotecmd FILE] [DEST]')), "rawcommit": (rawcommit, [('p', 'parent', [], _('parent')), diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -952,7 +952,7 @@ class localrepository(object): cg = remote.changegroupsubset(fetch, heads) return self.addchangegroup(cg) - def push(self, remote, force=False): + def push(self, remote, force=False, revs=None): lock = remote.lock() base = {} @@ -964,17 +964,25 @@ class localrepository(object): return 1 update = self.findoutgoing(remote, base) - if not update: + if revs is not None: + msng_cl, bases, heads = self.changelog.nodesbetween(update, revs) + else: + bases, heads = update, self.changelog.heads() + + if not bases: self.ui.status(_("no changes found\n")) return 1 elif not force: - if len(heads) < len(self.changelog.heads()): + if len(bases) < len(heads): self.ui.warn(_("abort: push creates new remote branches!\n")) self.ui.status(_("(did you forget to merge?" " use push -f to force)\n")) return 1 - cg = self.changegroup(update) + if revs is None: + cg = self.changegroup(update) + else: + cg = self.changegroupsubset(update, revs) return remote.addchangegroup(cg) def changegroupsubset(self, bases, heads): diff --git a/tests/test-push-r b/tests/test-push-r new file mode 100755 --- /dev/null +++ b/tests/test-push-r @@ -0,0 +1,61 @@ +#!/bin/bash + +hg init test +cd test +cat >>afile <>afile <>afile <>afile <>afile <>afile <fred <>afile <