# HG changeset patch # User Matt Mackall # Date 2011-02-10 19:46:28 # Node ID ddddb76f2da3e9b83ff638f42b844780245d2d0e # Parent 999f616b09dc854f63ea1d77c27c8059e1030641 bookmarks: merge low-level push/pull support into core diff --git a/hgext/bookmarks.py b/hgext/bookmarks.py --- a/hgext/bookmarks.py +++ b/hgext/bookmarks.py @@ -134,54 +134,6 @@ def reposetup(ui, repo): return class bookmark_repo(repo.__class__): - def pull(self, remote, heads=None, force=False): - result = super(bookmark_repo, self).pull(remote, heads, force) - - self.ui.debug("checking for updated bookmarks\n") - rb = remote.listkeys('bookmarks') - changed = False - for k in rb.keys(): - if k in self._bookmarks: - nr, nl = rb[k], self._bookmarks[k] - if nr in self: - cr = self[nr] - cl = self[nl] - if cl.rev() >= cr.rev(): - continue - if cr in cl.descendants(): - self._bookmarks[k] = cr.node() - changed = True - self.ui.status(_("updating bookmark %s\n") % k) - else: - self.ui.warn(_("not updating divergent" - " bookmark %s\n") % k) - if changed: - bookmarks.write(repo) - - return result - - def push(self, remote, force=False, revs=None, newbranch=False): - result = super(bookmark_repo, self).push(remote, force, revs, - newbranch) - - self.ui.debug("checking for updated bookmarks\n") - rb = remote.listkeys('bookmarks') - for k in rb.keys(): - if k in self._bookmarks: - nr, nl = rb[k], hex(self._bookmarks[k]) - if nr in self: - cr = self[nr] - cl = self[nl] - if cl in cr.descendants(): - r = remote.pushkey('bookmarks', k, nr, nl) - if r: - self.ui.status(_("updating bookmark %s\n") % k) - else: - self.ui.warn(_('updating bookmark %s' - ' failed!\n') % k) - - return result - def addchangegroup(self, *args, **kwargs): result = super(bookmark_repo, self).addchangegroup(*args, **kwargs) if result > 1: diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -1301,26 +1301,50 @@ class localrepository(repo.repository): common, fetch, rheads = tmp if not fetch: self.ui.status(_("no changes found\n")) - return 0 - - if heads is None and fetch == [nullid]: - self.ui.status(_("requesting all changes\n")) - elif heads is None and remote.capable('changegroupsubset'): - # issue1320, avoid a race if remote changed after discovery - heads = rheads + result = 0 + else: + if heads is None and fetch == [nullid]: + self.ui.status(_("requesting all changes\n")) + elif heads is None and remote.capable('changegroupsubset'): + # issue1320, avoid a race if remote changed after discovery + heads = rheads - if heads is None: - cg = remote.changegroup(fetch, 'pull') - else: - if not remote.capable('changegroupsubset'): + if heads is None: + cg = remote.changegroup(fetch, 'pull') + elif not remote.capable('changegroupsubset'): raise util.Abort(_("partial pull cannot be done because " - "other repository doesn't support " - "changegroupsubset.")) - cg = remote.changegroupsubset(fetch, heads, 'pull') - return self.addchangegroup(cg, 'pull', remote.url(), lock=lock) + "other repository doesn't support " + "changegroupsubset.")) + else: + cg = remote.changegroupsubset(fetch, heads, 'pull') + result = self.addchangegroup(cg, 'pull', remote.url(), + lock=lock) finally: lock.release() + self.ui.debug("checking for updated bookmarks\n") + rb = remote.listkeys('bookmarks') + changed = False + for k in rb.keys(): + if k in self._bookmarks: + nr, nl = rb[k], self._bookmarks[k] + if nr in self: + cr = self[nr] + cl = self[nl] + if cl.rev() >= cr.rev(): + continue + if cr in cl.descendants(): + self._bookmarks[k] = cr.node() + changed = True + self.ui.status(_("updating bookmark %s\n") % k) + else: + self.ui.warn(_("not updating divergent" + " bookmark %s\n") % k) + if changed: + bookmarks.write(self) + + return result + def checkpush(self, force, revs): """Extensions can override this function if additional checks have to be performed before pushing, or call it if they override push @@ -1350,30 +1374,46 @@ class localrepository(repo.repository): if not unbundle: lock = remote.lock() try: - ret = discovery.prepush(self, remote, force, revs, newbranch) - if ret[0] is None: - # and here we return 0 for "nothing to push" or 1 for - # "something to push but I refuse" - return ret[1] - - cg, remote_heads = ret - if unbundle: - # local repo finds heads on server, finds out what revs it must - # push. once revs transferred, if server finds it has - # different heads (someone else won commit/push race), server - # aborts. - if force: - remote_heads = ['force'] - # ssh: return remote's addchangegroup() - # http: return remote's addchangegroup() or 0 for error - return remote.unbundle(cg, remote_heads, 'push') - else: - # we return an integer indicating remote head count change - return remote.addchangegroup(cg, 'push', self.url(), lock=lock) + cg, remote_heads = discovery.prepush(self, remote, force, revs, + newbranch) + ret = remote_heads + if cg is not None: + if unbundle: + # local repo finds heads on server, finds out what + # revs it must push. once revs transferred, if server + # finds it has different heads (someone else won + # commit/push race), server aborts. + if force: + remote_heads = ['force'] + # ssh: return remote's addchangegroup() + # http: return remote's addchangegroup() or 0 for error + ret = remote.unbundle(cg, remote_heads, 'push') + else: + # we return an integer indicating remote head count change + ret = remote.addchangegroup(cg, 'push', self.url(), + lock=lock) finally: if lock is not None: lock.release() + self.ui.debug("checking for updated bookmarks\n") + rb = remote.listkeys('bookmarks') + for k in rb.keys(): + if k in self._bookmarks: + nr, nl = rb[k], hex(self._bookmarks[k]) + if nr in self: + cr = self[nr] + cl = self[nl] + if cl in cr.descendants(): + r = remote.pushkey('bookmarks', k, nr, nl) + if r: + self.ui.status(_("updating bookmark %s\n") % k) + else: + self.ui.warn(_('updating bookmark %s' + ' failed!\n') % k) + + return ret + def changegroupinfo(self, nodes, source): if self.ui.verbose or source == 'bundle': self.ui.status(_("%d changesets found\n") % len(nodes)) diff --git a/tests/test-acl.t b/tests/test-acl.t --- a/tests/test-acl.t +++ b/tests/test-acl.t @@ -141,6 +141,7 @@ Extension disabled for lack of a hook files: 3/3 chunks (100.00%) added 3 changesets with 3 changes to 3 files updating the branch cache + checking for updated bookmarks rolling back to revision 0 (undo push) 0:6675d58eff77 @@ -219,6 +220,7 @@ Extension disabled for lack of acl.sourc calling hook pretxnchangegroup.acl: hgext.acl.hook acl: changes have source "push" - skipping updating the branch cache + checking for updated bookmarks rolling back to revision 0 (undo push) 0:6675d58eff77 @@ -307,6 +309,7 @@ No [acl.allow]/[acl.deny] acl: branch access granted: "911600dab2ae" on branch "default" acl: allowing changeset 911600dab2ae updating the branch cache + checking for updated bookmarks rolling back to revision 0 (undo push) 0:6675d58eff77 @@ -941,6 +944,7 @@ barney is allowed everywhere acl: branch access granted: "911600dab2ae" on branch "default" acl: allowing changeset 911600dab2ae updating the branch cache + checking for updated bookmarks rolling back to revision 0 (undo push) 0:6675d58eff77 @@ -1336,6 +1340,7 @@ acl.config can set only [acl.allow]/[acl acl: branch access granted: "911600dab2ae" on branch "default" acl: allowing changeset 911600dab2ae updating the branch cache + checking for updated bookmarks rolling back to revision 0 (undo push) 0:6675d58eff77 @@ -1432,6 +1437,7 @@ fred is always allowed acl: branch access granted: "911600dab2ae" on branch "default" acl: allowing changeset 911600dab2ae updating the branch cache + checking for updated bookmarks rolling back to revision 0 (undo push) 0:6675d58eff77 @@ -1621,6 +1627,7 @@ OS-level groups acl: branch access granted: "911600dab2ae" on branch "default" acl: allowing changeset 911600dab2ae updating the branch cache + checking for updated bookmarks rolling back to revision 0 (undo push) 0:6675d58eff77 diff --git a/tests/test-http-proxy.t b/tests/test-http-proxy.t --- a/tests/test-http-proxy.t +++ b/tests/test-http-proxy.t @@ -104,13 +104,21 @@ do not use the proxy if it is in the no * - - [*] "GET http://localhost:$HGPORT/?pairs=0000000000000000000000000000000000000000-0000000000000000000000000000000000000000&cmd=between HTTP/1.1" - - (glob) * - - [*] "GET http://localhost:$HGPORT/?cmd=heads HTTP/1.1" - - (glob) * - - [*] "GET http://localhost:$HGPORT/?cmd=changegroup&roots=0000000000000000000000000000000000000000 HTTP/1.1" - - (glob) + * - - [*] "GET http://localhost:$HGPORT/?cmd=capabilities HTTP/1.1" - - (glob) + * - - [*] "GET http://localhost:$HGPORT/?cmd=listkeys&namespace=bookmarks HTTP/1.1" - - (glob) * - - [*] "GET http://localhost:$HGPORT/?pairs=0000000000000000000000000000000000000000-0000000000000000000000000000000000000000&cmd=between HTTP/1.1" - - (glob) * - - [*] "GET http://localhost:$HGPORT/?cmd=heads HTTP/1.1" - - (glob) * - - [*] "GET http://localhost:$HGPORT/?cmd=changegroup&roots=0000000000000000000000000000000000000000 HTTP/1.1" - - (glob) + * - - [*] "GET http://localhost:$HGPORT/?cmd=capabilities HTTP/1.1" - - (glob) + * - - [*] "GET http://localhost:$HGPORT/?cmd=listkeys&namespace=bookmarks HTTP/1.1" - - (glob) * - - [*] "GET http://localhost:$HGPORT/?pairs=0000000000000000000000000000000000000000-0000000000000000000000000000000000000000&cmd=between HTTP/1.1" - - (glob) * - - [*] "GET http://localhost:$HGPORT/?cmd=heads HTTP/1.1" - - (glob) * - - [*] "GET http://localhost:$HGPORT/?cmd=changegroup&roots=0000000000000000000000000000000000000000 HTTP/1.1" - - (glob) + * - - [*] "GET http://localhost:$HGPORT/?cmd=capabilities HTTP/1.1" - - (glob) + * - - [*] "GET http://localhost:$HGPORT/?cmd=listkeys&namespace=bookmarks HTTP/1.1" - - (glob) * - - [*] "GET http://localhost:$HGPORT/?pairs=0000000000000000000000000000000000000000-0000000000000000000000000000000000000000&cmd=between HTTP/1.1" - - (glob) * - - [*] "GET http://localhost:$HGPORT/?cmd=heads HTTP/1.1" - - (glob) * - - [*] "GET http://localhost:$HGPORT/?cmd=changegroup&roots=0000000000000000000000000000000000000000 HTTP/1.1" - - (glob) + * - - [*] "GET http://localhost:$HGPORT/?cmd=capabilities HTTP/1.1" - - (glob) + * - - [*] "GET http://localhost:$HGPORT/?cmd=listkeys&namespace=bookmarks HTTP/1.1" - - (glob)