mirror of
https://github.com/mnauw/git-remote-hg.git
synced 2025-11-06 11:35:40 +01:00
Separate head checking and revision pushing
Also remove some superfluous function parameters and add another one to avoid using global var.
This commit is contained in:
@@ -1078,7 +1078,7 @@ def write_tag(repo, tag, node, msg, author):
|
|||||||
|
|
||||||
return (tagnode, branch)
|
return (tagnode, branch)
|
||||||
|
|
||||||
def checkheads_bmark(repo, ref, ctx):
|
def checkheads_bmark(repo, ref, ctx, force):
|
||||||
bmark = ref[len('refs/heads/'):]
|
bmark = ref[len('refs/heads/'):]
|
||||||
if bmark not in bmarks:
|
if bmark not in bmarks:
|
||||||
# new bmark
|
# new bmark
|
||||||
@@ -1092,7 +1092,7 @@ def checkheads_bmark(repo, ref, ctx):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
if not repo.changelog.descendant(ctx_old.rev(), ctx_new.rev()):
|
if not repo.changelog.descendant(ctx_old.rev(), ctx_new.rev()):
|
||||||
if force_push:
|
if force:
|
||||||
print "ok %s forced update" % ref
|
print "ok %s forced update" % ref
|
||||||
else:
|
else:
|
||||||
print "error %s non-fast forward" % ref
|
print "error %s non-fast forward" % ref
|
||||||
@@ -1100,7 +1100,7 @@ def checkheads_bmark(repo, ref, ctx):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def checkheads(repo, remote, p_revs):
|
def checkheads(repo, remote, p_revs, force):
|
||||||
|
|
||||||
remotemap = remote.branchmap()
|
remotemap = remote.branchmap()
|
||||||
if not remotemap:
|
if not remotemap:
|
||||||
@@ -1118,7 +1118,7 @@ def checkheads(repo, remote, p_revs):
|
|||||||
continue
|
continue
|
||||||
if not ref.startswith('refs/heads/branches'):
|
if not ref.startswith('refs/heads/branches'):
|
||||||
if ref.startswith('refs/heads/'):
|
if ref.startswith('refs/heads/'):
|
||||||
if not checkheads_bmark(repo, ref, ctx):
|
if not checkheads_bmark(repo, ref, ctx, force):
|
||||||
ret = False
|
ret = False
|
||||||
|
|
||||||
# only check branches
|
# only check branches
|
||||||
@@ -1144,7 +1144,7 @@ def checkheads(repo, remote, p_revs):
|
|||||||
|
|
||||||
node = repo.changelog.node(rev)
|
node = repo.changelog.node(rev)
|
||||||
ref = p_revs[node]
|
ref = p_revs[node]
|
||||||
if force_push:
|
if force:
|
||||||
print "ok %s forced update" % ref
|
print "ok %s forced update" % ref
|
||||||
else:
|
else:
|
||||||
print "error %s non-fast forward" % ref
|
print "error %s non-fast forward" % ref
|
||||||
@@ -1152,9 +1152,7 @@ def checkheads(repo, remote, p_revs):
|
|||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def push_unsafe(repo, remote, parsed_refs, p_revs):
|
def push_unsafe(repo, remote, p_revs, force):
|
||||||
|
|
||||||
force = force_push
|
|
||||||
|
|
||||||
fci = discovery.findcommonincoming
|
fci = discovery.findcommonincoming
|
||||||
commoninc = fci(repo, remote, force=force)
|
commoninc = fci(repo, remote, force=force)
|
||||||
@@ -1162,9 +1160,6 @@ def push_unsafe(repo, remote, parsed_refs, p_revs):
|
|||||||
fco = discovery.findcommonoutgoing
|
fco = discovery.findcommonoutgoing
|
||||||
outgoing = fco(repo, remote, onlyheads=list(p_revs), commoninc=commoninc, force=force)
|
outgoing = fco(repo, remote, onlyheads=list(p_revs), commoninc=commoninc, force=force)
|
||||||
|
|
||||||
if not checkheads(repo, remote, p_revs):
|
|
||||||
return False
|
|
||||||
|
|
||||||
# nice to know about this rather than assume a bogus error
|
# nice to know about this rather than assume a bogus error
|
||||||
# also, some remote peertypes might otherwise be surprised further down
|
# also, some remote peertypes might otherwise be surprised further down
|
||||||
if not outgoing.missing:
|
if not outgoing.missing:
|
||||||
@@ -1193,7 +1188,7 @@ def push_unsafe(repo, remote, parsed_refs, p_revs):
|
|||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def push(repo, remote, parsed_refs, p_revs):
|
def push(repo, remote, p_revs, force):
|
||||||
if hasattr(remote, 'canpush') and not remote.canpush():
|
if hasattr(remote, 'canpush') and not remote.canpush():
|
||||||
print "error cannot push"
|
print "error cannot push"
|
||||||
|
|
||||||
@@ -1206,7 +1201,7 @@ def push(repo, remote, parsed_refs, p_revs):
|
|||||||
if not unbundle:
|
if not unbundle:
|
||||||
lock = remote.lock()
|
lock = remote.lock()
|
||||||
try:
|
try:
|
||||||
ret = push_unsafe(repo, remote, parsed_refs, p_revs)
|
ret = push_unsafe(repo, remote, p_revs, force)
|
||||||
finally:
|
finally:
|
||||||
if lock is not None:
|
if lock is not None:
|
||||||
lock.release()
|
lock.release()
|
||||||
@@ -1338,12 +1333,14 @@ def do_push_hg(parser):
|
|||||||
|
|
||||||
if dry_run:
|
if dry_run:
|
||||||
if peer and not force_push:
|
if peer and not force_push:
|
||||||
checkheads(parser.repo, peer, p_revs)
|
checkheads(parser.repo, peer, p_revs, force_push)
|
||||||
return
|
return
|
||||||
|
|
||||||
success = True
|
success = True
|
||||||
if peer:
|
if peer:
|
||||||
ret = push(parser.repo, peer, parsed_refs, p_revs)
|
if not checkheads(parser.repo, peer, p_revs, force_push):
|
||||||
|
return False
|
||||||
|
ret = push(parser.repo, peer, p_revs, force_push)
|
||||||
# None ok: nothing to push
|
# None ok: nothing to push
|
||||||
if ret != None and not ret:
|
if ret != None and not ret:
|
||||||
# do not update bookmarks
|
# do not update bookmarks
|
||||||
|
|||||||
Reference in New Issue
Block a user