##// END OF EJS Templates
push over http: server support....
Vadim Gelfer -
r2464:09b1c9ef default
parent child Browse files
Show More
@@ -10,7 +10,7 import os
10 import os.path
10 import os.path
11 import mimetypes
11 import mimetypes
12 from mercurial.demandload import demandload
12 from mercurial.demandload import demandload
13 demandload(globals(), "re zlib ConfigParser cStringIO")
13 demandload(globals(), "re zlib ConfigParser cStringIO sys tempfile")
14 demandload(globals(), "mercurial:mdiff,ui,hg,util,archival,templater")
14 demandload(globals(), "mercurial:mdiff,ui,hg,util,archival,templater")
15 demandload(globals(), "mercurial.hgweb.request:hgrequest")
15 demandload(globals(), "mercurial.hgweb.request:hgrequest")
16 demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile")
16 demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile")
@@ -835,7 +835,57 class hgweb(object):
835 or self.t("error", error="%r not found" % fname))
835 or self.t("error", error="%r not found" % fname))
836
836
837 def do_capabilities(self, req):
837 def do_capabilities(self, req):
838 resp = ''
838 resp = 'unbundle'
839 req.httphdr("application/mercurial-0.1", length=len(resp))
839 req.httphdr("application/mercurial-0.1", length=len(resp))
840 req.write(resp)
840 req.write(resp)
841
841
842 def do_unbundle(self, req):
843 their_heads = req.form['heads'][0].split(' ')
844
845 def check_heads():
846 heads = map(hex, self.repo.heads())
847 return their_heads == [hex('force')] or their_heads == heads
848
849 req.httphdr("application/mercurial-0.1")
850
851 # fail early if possible
852 if not check_heads():
853 req.write('0\n')
854 req.write(_('unsynced changes\n'))
855 return
856
857 # do not lock repo until all changegroup data is
858 # streamed. save to temporary file.
859
860 fd, tempname = tempfile.mkstemp(prefix='hg-unbundle-')
861 fp = os.fdopen(fd, 'wb+')
862 try:
863 length = int(req.env['CONTENT_LENGTH'])
864 for s in util.filechunkiter(req, limit=length):
865 fp.write(s)
866
867 lock = self.repo.lock()
868 try:
869 if not check_heads():
870 req.write('0\n')
871 req.write(_('unsynced changes\n'))
872 return
873
874 fp.seek(0)
875
876 # send addchangegroup output to client
877
878 old_stdout = sys.stdout
879 sys.stdout = cStringIO.StringIO()
880
881 try:
882 ret = self.repo.addchangegroup(fp, 'serve')
883 req.write('%d\n' % ret)
884 req.write(sys.stdout.getvalue())
885 finally:
886 sys.stdout = old_stdout
887 finally:
888 lock.release()
889 finally:
890 fp.close()
891 os.unlink(tempname)
@@ -18,6 +18,9 class hgrequest(object):
18 self.form = cgi.parse(self.inp, self.env, keep_blank_values=1)
18 self.form = cgi.parse(self.inp, self.env, keep_blank_values=1)
19 self.will_close = True
19 self.will_close = True
20
20
21 def read(self, count=-1):
22 return self.inp.read(count)
23
21 def write(self, *things):
24 def write(self, *things):
22 for thing in things:
25 for thing in things:
23 if hasattr(thing, "__iter__"):
26 if hasattr(thing, "__iter__"):
General Comments 0
You need to be logged in to leave comments. Login now