Show More
@@ -611,3 +611,20 b' def getbundle(repo, source, heads=None, ' | |||
|
611 | 611 | temp.write(c) |
|
612 | 612 | temp.seek(0) |
|
613 | 613 | return bundle2.unbundle20(repo.ui, temp) |
|
614 | ||
|
615 | class PushRaced(RuntimeError): | |
|
616 | """An exception raised during unbunding that indicate a push race""" | |
|
617 | ||
|
618 | def check_heads(repo, their_heads, context): | |
|
619 | """check if the heads of a repo have been modified | |
|
620 | ||
|
621 | Used by peer for unbundling. | |
|
622 | """ | |
|
623 | heads = repo.heads() | |
|
624 | heads_hash = util.sha1(''.join(sorted(heads))).digest() | |
|
625 | if not (their_heads == ['force'] or their_heads == heads or | |
|
626 | their_heads == ['hashed', heads_hash]): | |
|
627 | # someone else committed/pushed/unbundled while we | |
|
628 | # were transferring data | |
|
629 | raise PushRaced('repository changed while %s - ' | |
|
630 | 'please try again' % context) |
@@ -9,7 +9,7 b' import urllib, tempfile, os, sys' | |||
|
9 | 9 | from i18n import _ |
|
10 | 10 | from node import bin, hex |
|
11 | 11 | import changegroup as changegroupmod |
|
12 | import peer, error, encoding, util, store | |
|
12 | import peer, error, encoding, util, store, exchange | |
|
13 | 13 | |
|
14 | 14 | |
|
15 | 15 | class abstractserverproto(object): |
@@ -754,18 +754,10 b' def stream(repo, proto):' | |||
|
754 | 754 | def unbundle(repo, proto, heads): |
|
755 | 755 | their_heads = decodelist(heads) |
|
756 | 756 | |
|
757 | def check_heads(): | |
|
758 | heads = repo.heads() | |
|
759 | heads_hash = util.sha1(''.join(sorted(heads))).digest() | |
|
760 | return (their_heads == ['force'] or their_heads == heads or | |
|
761 | their_heads == ['hashed', heads_hash]) | |
|
762 | ||
|
757 | try: | |
|
763 | 758 | proto.redirect() |
|
764 | 759 | |
|
765 | # fail early if possible | |
|
766 | if not check_heads(): | |
|
767 | return pusherr('repository changed while preparing changes - ' | |
|
768 | 'please try again') | |
|
760 | exchange.check_heads(repo, their_heads, 'preparing changes') | |
|
769 | 761 | |
|
770 | 762 | # write bundle data to temporary file because it can be big |
|
771 | 763 | fd, tempname = tempfile.mkstemp(prefix='hg-unbundle-') |
@@ -775,11 +767,7 b' def unbundle(repo, proto, heads):' | |||
|
775 | 767 | proto.getfile(fp) |
|
776 | 768 | lock = repo.lock() |
|
777 | 769 | try: |
|
778 | if not check_heads(): | |
|
779 | # someone else committed/pushed/unbundled while we | |
|
780 | # were transferring data | |
|
781 | return pusherr('repository changed while uploading changes - ' | |
|
782 | 'please try again') | |
|
770 | exchange.check_heads(repo, their_heads, 'uploading changes') | |
|
783 | 771 | |
|
784 | 772 | # push can proceed |
|
785 | 773 | fp.seek(0) |
@@ -797,3 +785,5 b' def unbundle(repo, proto, heads):' | |||
|
797 | 785 | finally: |
|
798 | 786 | fp.close() |
|
799 | 787 | os.unlink(tempname) |
|
788 | except exchange.PushRaced, exc: | |
|
789 | return pusherr(str(exc)) |
General Comments 0
You need to be logged in to leave comments.
Login now