diff options
author | Felipe Contreras <felipe.contreras@gmail.com> | 2013-05-24 21:29:49 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-05-28 08:02:04 -0700 |
commit | 4f37bdbdb6229931c464b99eb9f6e198de01d0a7 (patch) | |
tree | 31855913ba4102cc1677e7185bac0f828bc69216 | |
parent | remote-hg: only update necessary revisions (diff) | |
download | tgif-4f37bdbdb6229931c464b99eb9f6e198de01d0a7.tar.xz |
remote-hg: implement custom push()
The one from mercurial does a ton of things we are not interested in,
and we need some special modifications which are impossible otherwise.
Most of the code is borrowed from Mercurial, and cleaned up, but should
be functionally the same for our purposes, except that multiple heads
are not detected.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rwxr-xr-x | contrib/remote-helpers/git-remote-hg | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/contrib/remote-helpers/git-remote-hg b/contrib/remote-helpers/git-remote-hg index 7added3b33..c2c1cb8b52 100755 --- a/contrib/remote-helpers/git-remote-hg +++ b/contrib/remote-helpers/git-remote-hg @@ -12,7 +12,7 @@ # For remote repositories a local clone is stored in # "$GIT_DIR/hg/origin/clone/.hg/". -from mercurial import hg, ui, bookmarks, context, encoding, node, error, extensions +from mercurial import hg, ui, bookmarks, context, encoding, node, error, extensions, discovery import re import sys @@ -854,6 +854,46 @@ def write_tag(repo, tag, node, msg, author): return tagnode +def push_unsafe(repo, remote, parsed_refs, p_revs): + + force = force_push + + fci = discovery.findcommonincoming + commoninc = fci(repo, remote, force=force) + common, _, remoteheads = commoninc + + # TODO checkheads + + cg = repo.getbundle('push', heads=list(p_revs), common=common) + + unbundle = remote.capable('unbundle') + if unbundle: + if force: + remoteheads = ['force'] + return remote.unbundle(cg, remoteheads, 'push') + else: + return remote.addchangegroup(cg, 'push', repo.url()) + +def push(repo, remote, parsed_refs, p_revs): + if hasattr(remote, 'canpush') and not remote.canpush(): + print "error cannot push" + + if not p_revs: + # nothing to push + return + + lock = None + unbundle = remote.capable('unbundle') + if not unbundle: + lock = remote.lock() + try: + ret = push_unsafe(repo, remote, parsed_refs, p_revs) + finally: + if lock is not None: + lock.release() + + return ret + def do_export(parser): global parsed_refs, bmarks, peer @@ -919,7 +959,7 @@ def do_export(parser): continue if peer: - parser.repo.push(peer, force=force_push, newbranch=True, revs=list(p_revs)) + push(parser.repo, peer, parsed_refs, p_revs) # update remote bookmarks remote_bmarks = peer.listkeys('bookmarks') |