##// END OF EJS Templates
unbundle: extract the core logic in another function...
Pierre-Yves David -
r20968:33d5fdd9 default
parent child Browse files
Show More
@@ -5,6 +5,7 b''
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 import sys
8 from i18n import _
9 from i18n import _
9 from node import hex, nullid
10 from node import hex, nullid
10 import cStringIO
11 import cStringIO
@@ -628,3 +629,28 b' def check_heads(repo, their_heads, conte'
628 # were transferring data
629 # were transferring data
629 raise PushRaced('repository changed while %s - '
630 raise PushRaced('repository changed while %s - '
630 'please try again' % context)
631 'please try again' % context)
632
633 def unbundle(repo, cg, heads, source, url):
634 """Apply a bundle to a repo.
635
636 this function makes sure the repo is locked during the application and have
637 mechanism to check that no push race occured between the creation of the
638 bundle and its application.
639
640 If the push was raced as PushRaced exception is raised."""
641 r = 0
642 lock = repo.lock()
643 try:
644 check_heads(repo, heads, 'uploading changes')
645 # push can proceed
646 try:
647 r = changegroup.addchangegroup(repo, cg, source, url)
648 except util.Abort, inst:
649 # The old code we moved used sys.stderr directly.
650 # We did not changed it to minise code change.
651 # This need to be moved to something proper.
652 # Feel free to do it.
653 sys.stderr.write("abort: %s\n" % inst)
654 finally:
655 lock.release()
656 return r
@@ -765,21 +765,10 b' def unbundle(repo, proto, heads):'
765 r = 0
765 r = 0
766 try:
766 try:
767 proto.getfile(fp)
767 proto.getfile(fp)
768 lock = repo.lock()
768 fp.seek(0)
769 try:
769 gen = changegroupmod.readbundle(fp, None)
770 exchange.check_heads(repo, their_heads, 'uploading changes')
770 r = exchange.unbundle(repo, gen, their_heads, 'serve',
771
771 proto._client())
772 # push can proceed
773 fp.seek(0)
774 gen = changegroupmod.readbundle(fp, None)
775
776 try:
777 r = changegroupmod.addchangegroup(repo, gen, 'serve',
778 proto._client())
779 except util.Abort, inst:
780 sys.stderr.write("abort: %s\n" % inst)
781 finally:
782 lock.release()
783 return pushres(r)
772 return pushres(r)
784
773
785 finally:
774 finally:
General Comments 0
You need to be logged in to leave comments. Login now