##// END OF EJS Templates
bundle2: gracefully handle abort during unbundle...
Pierre-Yves David -
r21177:952af771 stable
parent child Browse files
Show More
@@ -743,3 +743,9 b' def handlereplycaps(op, inpart):'
743 if op.reply is None:
743 if op.reply is None:
744 op.reply = bundle20(op.ui, caps)
744 op.reply = bundle20(op.ui, caps)
745
745
746 @parthandler('b2x:error:abort')
747 def handlereplycaps(op, inpart):
748 """Used to transmit abort error over the wire"""
749 manargs = dict(inpart.mandatoryparams)
750 advargs = dict(inpart.advisoryparams)
751 raise util.Abort(manargs['message'], hint=advargs.get('hint'))
@@ -808,7 +808,17 b' def unbundle(repo, proto, heads):'
808 # We did not change it to minimise code change.
808 # We did not change it to minimise code change.
809 # This need to be moved to something proper.
809 # This need to be moved to something proper.
810 # Feel free to do it.
810 # Feel free to do it.
811 sys.stderr.write("abort: %s\n" % inst)
811 if getattr(inst, 'duringunbundle2', False):
812 return pushres(0)
812 bundler = bundle2.bundle20(repo.ui)
813 manargs = [('message', str(inst))]
814 advargs = []
815 if inst.hint is not None:
816 advargs.append(('hint', inst.hint))
817 bundler.addpart(bundle2.bundlepart('B2X:ERROR:ABORT',
818 manargs, advargs))
819 return streamres(bundler.getchunks())
820 else:
821 sys.stderr.write("abort: %s\n" % inst)
822 return pushres(0)
813 except exchange.PushRaced, exc:
823 except exchange.PushRaced, exc:
814 return pusherr(str(exc))
824 return pusherr(str(exc))
@@ -883,3 +883,80 b' Check final content.'
883 date: Sat Apr 30 15:24:48 2011 +0200
883 date: Sat Apr 30 15:24:48 2011 +0200
884 summary: A
884 summary: A
885
885
886
887 Error Handling
888 ==============
889
890 Check that errors are properly returned to the client during push.
891
892 Setting up
893
894 $ cat > failpush.py << EOF
895 > """A small extension that makes push fails when using bundle2
896 >
897 > used to test error handling in bundle2
898 > """
899 >
900 > from mercurial import util
901 > from mercurial import bundle2
902 > from mercurial import exchange
903 > from mercurial import extensions
904 >
905 > def _pushbundle2failpart(orig, pushop, bundler):
906 > extradata = orig(pushop, bundler)
907 > part = bundle2.bundlepart('test:abort')
908 > bundler.addpart(part)
909 > return extradata
910 >
911 > @bundle2.parthandler("test:abort")
912 > def handleabort(op, part):
913 > raise util.Abort('Abandon ship!', hint="don't panic")
914 >
915 > def uisetup(ui):
916 > extensions.wrapfunction(exchange, '_pushbundle2extraparts', _pushbundle2failpart)
917 >
918 > EOF
919
920 $ cd main
921 $ hg up tip
922 3 files updated, 0 files merged, 1 files removed, 0 files unresolved
923 $ echo 'I' > I
924 $ hg add I
925 $ hg ci -m 'I'
926 $ hg id
927 e7ec4e813ba6 tip
928 $ cd ..
929
930 $ cat << EOF >> $HGRCPATH
931 > [extensions]
932 > failpush=$TESTTMP/failpush.py
933 > EOF
934
935 $ "$TESTDIR/killdaemons.py" $DAEMON_PIDS
936 $ hg -R other serve -p $HGPORT2 -d --pid-file=other.pid -E other-error.log
937 $ cat other.pid >> $DAEMON_PIDS
938
939 Doing the actual push: Abort error
940
941 $ hg -R main push other -r e7ec4e813ba6
942 pushing to other
943 searching for changes
944 abort: Abandon ship!
945 (don't panic)
946 [255]
947
948 $ hg -R main push ssh://user@dummy/other -r e7ec4e813ba6
949 pushing to ssh://user@dummy/other
950 searching for changes
951 abort: Abandon ship!
952 (don't panic)
953 [255]
954
955 $ hg -R main push http://localhost:$HGPORT2/ -r e7ec4e813ba6
956 pushing to http://localhost:$HGPORT2/
957 searching for changes
958 abort: Abandon ship!
959 (don't panic)
960 [255]
961
962
General Comments 0
You need to be logged in to leave comments. Login now