mercurial/exchange.py
changeset 20967 984850270acb
parent 20956 dbf0fa39a5b8
child 20968 33d5fdd9bd99
--- a/mercurial/exchange.py	Mon Apr 07 18:10:50 2014 -0700
+++ b/mercurial/exchange.py	Fri Apr 04 17:15:25 2014 -0700
@@ -611,3 +611,20 @@
         temp.write(c)
     temp.seek(0)
     return bundle2.unbundle20(repo.ui, temp)
+
+class PushRaced(RuntimeError):
+    """An exception raised during unbunding that indicate a push race"""
+
+def check_heads(repo, their_heads, context):
+    """check if the heads of a repo have been modified
+
+    Used by peer for unbundling.
+    """
+    heads = repo.heads()
+    heads_hash = util.sha1(''.join(sorted(heads))).digest()
+    if not (their_heads == ['force'] or their_heads == heads or
+            their_heads == ['hashed', heads_hash]):
+        # someone else committed/pushed/unbundled while we
+        # were transferring data
+        raise PushRaced('repository changed while %s - '
+                        'please try again' % context)