diff options
author | Shawn O. Pearce <sop@google.com> | 2011-10-11 12:00:38 -0700 |
---|---|---|
committer | Shawn O. Pearce <sop@google.com> | 2011-10-11 12:18:07 -0700 |
commit | fab96c68e3acfb5403ffe65577563f3cb39e2530 (patch) | |
tree | 972a82f40c3e7de6b88f174f5f5b2a3418f92e40 /main.py | |
parent | bf1fbb20ab33cc479881a2b755e336872971dd78 (diff) | |
download | git-repo-fab96c68e3acfb5403ffe65577563f3cb39e2530.tar.gz |
Work around Python 2.7 urllib2 bug
If the remote is using authenticated HTTP, but does not have
$GIT_URL/clone.bundle files in each repository, an initial sync
would fail around 8 projects in due to the library not resetting
the number of failures after getting a 404.
Work around this by updating the retry counter ourselves.
The urllib2 library is also not thread-safe. Make it somewhat
safer by wrapping the critical section with a lock.
Change-Id: I886e2750ef4793cbe2150c3b5396eb9f10974f7f
Signed-off-by: Shawn O. Pearce <sop@google.com>
Diffstat (limited to 'main.py')
-rwxr-xr-x | main.py | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -273,6 +273,15 @@ class _UserAgentHandler(urllib2.BaseHandler): | |||
273 | req.add_header('User-Agent', _UserAgent()) | 273 | req.add_header('User-Agent', _UserAgent()) |
274 | return req | 274 | return req |
275 | 275 | ||
276 | class _BasicAuthHandler(urllib2.HTTPBasicAuthHandler): | ||
277 | def http_error_auth_reqed(self, authreq, host, req, headers): | ||
278 | try: | ||
279 | return urllib2.AbstractBasicAuthHandler.http_error_auth_reqed( | ||
280 | self, authreq, host, req, headers) | ||
281 | except: | ||
282 | self.reset_retry_count() | ||
283 | raise | ||
284 | |||
276 | def init_http(): | 285 | def init_http(): |
277 | handlers = [_UserAgentHandler()] | 286 | handlers = [_UserAgentHandler()] |
278 | 287 | ||
@@ -287,7 +296,7 @@ def init_http(): | |||
287 | pass | 296 | pass |
288 | except IOError: | 297 | except IOError: |
289 | pass | 298 | pass |
290 | handlers.append(urllib2.HTTPBasicAuthHandler(mgr)) | 299 | handlers.append(_BasicAuthHandler(mgr)) |
291 | 300 | ||
292 | if 'http_proxy' in os.environ: | 301 | if 'http_proxy' in os.environ: |
293 | url = os.environ['http_proxy'] | 302 | url = os.environ['http_proxy'] |