changeset 4029:9210fba03d16

merge with -stable
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Mon, 15 Jan 2007 18:23:21 +0100
parents 540d1059c802 (diff) de081fbb27fe (current diff)
children 84e469ce6408
files hgext/patchbomb.py mercurial/bundlerepo.py mercurial/demandload.py mercurial/httprepo.py mercurial/packagescan.py tests/test-branch tests/test-branch.out
diffstat 4 files changed, 37 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/patchbomb.py	Fri Jan 12 14:27:59 2007 +0100
+++ b/hgext/patchbomb.py	Mon Jan 15 18:23:21 2007 +0100
@@ -63,9 +63,9 @@
 #
 # That should be all.  Now your patchbomb is on its way out.
 
-import os, errno, socket, time
+import os, errno, socket
 import email.MIMEMultipart, email.MIMEText, email.Utils
-from mercurial import cmdutil, commands, hg, mail, ui, patch
+from mercurial import cmdutil, commands, hg, mail, ui, patch, util
 from mercurial.i18n import _
 from mercurial.node import *
 
@@ -164,10 +164,10 @@
         msg['X-Mercurial-Node'] = node
         return msg
 
-    start_time = int(time.time())
+    start_time = util.makedate()
 
     def genmsgid(id):
-        return '<%s.%s@%s>' % (id[:20], start_time, socket.getfqdn())
+        return '<%s.%s@%s>' % (id[:20], int(start_time[0]), socket.getfqdn())
 
     patches = []
 
@@ -243,13 +243,6 @@
         mailer = mail.connect(ui)
     parent = None
 
-    # Calculate UTC offset
-    if time.daylight: offset = time.altzone
-    else: offset = time.timezone
-    if offset <= 0: sign, offset = '+', -offset
-    else: sign = '-'
-    offset = '%s%02d%02d' % (sign, offset / 3600, (offset % 3600) / 60)
-
     sender_addr = email.Utils.parseaddr(sender)[1]
     for m in msgs:
         try:
@@ -260,9 +253,10 @@
             m['In-Reply-To'] = parent
         else:
             parent = m['Message-Id']
-        m['Date'] = time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(start_time)) + ' ' + offset
+        m['Date'] = util.datestr(date=start_time,
+                format="%a, %d %b %Y %H:%M:%S", timezone=True)
 
-        start_time += 1
+        start_time = (start_time[0] + 1, start_time[1])
         m['From'] = sender
         m['To'] = ', '.join(to)
         if cc: m['Cc']  = ', '.join(cc)
@@ -280,7 +274,8 @@
         elif opts['mbox']:
             ui.status('Writing ', m['Subject'], ' ...\n')
             fp = open(opts['mbox'], m.has_key('In-Reply-To') and 'ab+' or 'wb+')
-            date = time.asctime(time.localtime(start_time))
+            date = util.datestr(date=start_time,
+                    format='%a %b %d %H:%M:%S %Y', timezone=False)
             fp.write('From %s %s\n' % (sender_addr, date))
             fp.write(m.as_string(0))
             fp.write('\n\n')
--- a/mercurial/bundlerepo.py	Fri Jan 12 14:27:59 2007 +0100
+++ b/mercurial/bundlerepo.py	Mon Jan 15 18:23:21 2007 +0100
@@ -92,7 +92,7 @@
             if revb == rev1:
                 return self.chunk(rev2)
         elif not self.bundle(rev1) and not self.bundle(rev2):
-            return revlog.revlog.chunk(self, rev1, rev2)
+            return revlog.revlog.revdiff(self, rev1, rev2)
 
         return self.diff(self.revision(self.node(rev1)),
                          self.revision(self.node(rev2)))
--- a/mercurial/httprepo.py	Fri Jan 12 14:27:59 2007 +0100
+++ b/mercurial/httprepo.py	Mon Jan 15 18:23:21 2007 +0100
@@ -75,17 +75,25 @@
         return userpass + '@' + hostport
     return hostport
 
-class httpconnection(keepalive.HTTPConnection):
-    # must be able to send big bundle as stream.
+class httpsendfile(file):
+    def __len__(self):
+        return os.fstat(self.fileno()).st_size
 
-    def send(self, data):
-        if isinstance(data, str):
-            keepalive.HTTPConnection.send(self, data)
-        else:
+def _gen_sendfile(connection):
+    def _sendfile(self, data):
+        # send a file
+        if isinstance(data, httpsendfile):
             # if auth required, some data sent twice, so rewind here
             data.seek(0)
             for chunk in util.filechunkiter(data):
-                keepalive.HTTPConnection.send(self, chunk)
+                connection.send(self, chunk)
+        else:
+            connection.send(self, data)
+    return _sendfile
+
+class httpconnection(keepalive.HTTPConnection):
+    # must be able to send big bundle as stream.
+    send = _gen_sendfile(keepalive.HTTPConnection)
 
 class basehttphandler(keepalive.HTTPHandler):
     def http_open(self, req):
@@ -96,15 +104,7 @@
     class httpsconnection(httplib.HTTPSConnection):
         response_class = keepalive.HTTPResponse
         # must be able to send big bundle as stream.
-
-        def send(self, data):
-            if isinstance(data, str):
-                httplib.HTTPSConnection.send(self, data)
-            else:
-                # if auth required, some data sent twice, so rewind here
-                data.seek(0)
-                for chunk in util.filechunkiter(data):
-                    httplib.HTTPSConnection.send(self, chunk)
+        send = _gen_sendfile(httplib.HTTPSConnection)
 
     class httphandler(basehttphandler, urllib2.HTTPSHandler):
         def https_open(self, req):
@@ -344,14 +344,12 @@
                     break
 
         tempname = changegroup.writebundle(cg, None, type)
-        fp = file(tempname, "rb")
+        fp = httpsendfile(tempname, "rb")
         try:
-            length = os.stat(tempname).st_size
             try:
                 rfp = self.do_cmd(
                     'unbundle', data=fp,
-                    headers={'content-length': str(length),
-                             'content-type': 'application/octet-stream'},
+                    headers={'content-type': 'application/octet-stream'},
                     heads=' '.join(map(hex, heads)))
                 try:
                     ret = int(rfp.readline())
--- a/mercurial/keepalive.py	Fri Jan 12 14:27:59 2007 +0100
+++ b/mercurial/keepalive.py	Mon Jan 15 18:23:21 2007 +0100
@@ -17,6 +17,9 @@
 # This file is part of urlgrabber, a high-level cross-protocol url-grabber
 # Copyright 2002-2004 Michael D. Stenner, Ryan Tomayko
 
+# Modified by Benoit Boissinot:
+#  - fix for digest auth (inspired from urllib2.py @ Python v2.4)
+
 """An HTTP handler for urllib2 that supports HTTP 1.1 and keepalive.
 
 >>> import urllib2
@@ -302,28 +305,15 @@
         return r
 
     def _start_transaction(self, h, req):
+        headers = req.headers.copy()
+        body = req.data
+        if sys.version_info >= (2, 4):
+            headers.update(req.unredirected_hdrs)
         try:
-            if req.has_data():
-                data = req.get_data()
-                h.putrequest('POST', req.get_selector())
-                if not req.headers.has_key('Content-type'):
-                    h.putheader('Content-type',
-                                'application/x-www-form-urlencoded')
-                if not req.headers.has_key('Content-length'):
-                    h.putheader('Content-length', '%d' % len(data))
-            else:
-                h.putrequest('GET', req.get_selector())
-        except (socket.error, httplib.HTTPException), err:
+            h.request(req.get_method(), req.get_selector(), body, headers)
+        except socket.error, err: # XXX what error?
             raise urllib2.URLError(err)
 
-        for args in self.parent.addheaders:
-            h.putheader(*args)
-        for k, v in req.headers.items():
-            h.putheader(k, v)
-        h.endheaders()
-        if req.has_data():
-            h.send(data)
-
 class HTTPResponse(httplib.HTTPResponse):
     # we need to subclass HTTPResponse in order to
     # 1) add readline() and readlines() methods