Mercurial > hg > mercurial-crew-with-dirclash
annotate mercurial/httprepo.py @ 1985:c577689006fa
Adapted behaviour of ui.username() to documentation and mention it explicitly:
Searched in this order: $HGUSER, [ui] section of hgrcs, $EMAIL
and stop searching if one of these is set.
Abort if found username is an empty string to force specifying
the commit user elsewhere, e.g. with line option or repo hgrc.
If not found, use $LOGNAME or $USERNAME +"@full.hostname".
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Tue, 21 Mar 2006 15:33:29 +0100 |
parents | 8a8ab47cccde |
children | 1a09814a5b1f |
rev | line source |
---|---|
1089 | 1 # httprepo.py - HTTP repository proxy classes for mercurial |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
2 # |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
3 # Copyright 2005 Matt Mackall <mpm@selenic.com> |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
4 # |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
6 # of the GNU General Public License, incorporated herein by reference. |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
7 |
1089 | 8 from node import * |
9 from remoterepo import * | |
1400
cf9a1233738a
i18n first part: make '_' available for files who need it
Benoit Boissinot <benoit.boissinot@ens-lyon.org
parents:
1377
diff
changeset
|
10 from i18n import gettext as _ |
1251
84cf8834efb5
Fix lots of exception-related problems.
Bryan O'Sullivan <bos@serpentine.com>
parents:
1089
diff
changeset
|
11 from demandload import * |
1377
854775b27d1a
Fixed a bug in my changes to httprepo.py
Eric Hopper <hopper@omnifarious.org>
parents:
1376
diff
changeset
|
12 demandload(globals(), "hg os urllib urllib2 urlparse zlib util") |
926 | 13 |
14 class httprepository(remoterepository): | |
60 | 15 def __init__(self, ui, path): |
765 | 16 # fix missing / after hostname |
17 s = urlparse.urlsplit(path) | |
18 partial = s[2] | |
19 if not partial: partial = "/" | |
20 self.url = urlparse.urlunsplit((s[0], s[1], partial, '', '')) | |
60 | 21 self.ui = ui |
321 | 22 no_list = [ "localhost", "127.0.0.1" ] |
23 host = ui.config("http_proxy", "host") | |
424
9294dce4b633
Allow override of HTTP_PROXY, http_proxy and no_proxy; make no_proxy work.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
385
diff
changeset
|
24 if host is None: |
9294dce4b633
Allow override of HTTP_PROXY, http_proxy and no_proxy; make no_proxy work.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
385
diff
changeset
|
25 host = os.environ.get("http_proxy") |
426
8c90ab5644c9
Allow hgrc's proxy host and $http_proxy env var to start with http://
Thomas Arendsen Hein <thomas@intevation.de>
parents:
424
diff
changeset
|
26 if host and host.startswith('http://'): |
8c90ab5644c9
Allow hgrc's proxy host and $http_proxy env var to start with http://
Thomas Arendsen Hein <thomas@intevation.de>
parents:
424
diff
changeset
|
27 host = host[7:] |
321 | 28 user = ui.config("http_proxy", "user") |
29 passwd = ui.config("http_proxy", "passwd") | |
30 no = ui.config("http_proxy", "no") | |
424
9294dce4b633
Allow override of HTTP_PROXY, http_proxy and no_proxy; make no_proxy work.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
385
diff
changeset
|
31 if no is None: |
9294dce4b633
Allow override of HTTP_PROXY, http_proxy and no_proxy; make no_proxy work.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
385
diff
changeset
|
32 no = os.environ.get("no_proxy") |
321 | 33 if no: |
34 no_list = no_list + no.split(",") | |
515 | 35 |
321 | 36 no_proxy = 0 |
37 for h in no_list: | |
38 if (path.startswith("http://" + h + "/") or | |
39 path.startswith("http://" + h + ":") or | |
40 path == "http://" + h): | |
41 no_proxy = 1 | |
42 | |
43 # Note: urllib2 takes proxy values from the environment and those will | |
44 # take precedence | |
424
9294dce4b633
Allow override of HTTP_PROXY, http_proxy and no_proxy; make no_proxy work.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
385
diff
changeset
|
45 for env in ["HTTP_PROXY", "http_proxy", "no_proxy"]: |
859
6390c377a9e6
Trap OSError when deleting env vars
Edouard Gomez <ed.gomez@free.fr>
parents:
856
diff
changeset
|
46 try: |
6390c377a9e6
Trap OSError when deleting env vars
Edouard Gomez <ed.gomez@free.fr>
parents:
856
diff
changeset
|
47 if os.environ.has_key(env): |
6390c377a9e6
Trap OSError when deleting env vars
Edouard Gomez <ed.gomez@free.fr>
parents:
856
diff
changeset
|
48 del os.environ[env] |
6390c377a9e6
Trap OSError when deleting env vars
Edouard Gomez <ed.gomez@free.fr>
parents:
856
diff
changeset
|
49 except OSError: |
6390c377a9e6
Trap OSError when deleting env vars
Edouard Gomez <ed.gomez@free.fr>
parents:
856
diff
changeset
|
50 pass |
321 | 51 |
52 proxy_handler = urllib2.BaseHandler() | |
53 if host and not no_proxy: | |
54 proxy_handler = urllib2.ProxyHandler({"http" : "http://" + host}) | |
55 | |
56 authinfo = None | |
57 if user and passwd: | |
58 passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm() | |
59 passmgr.add_password(None, host, user, passwd) | |
60 authinfo = urllib2.ProxyBasicAuthHandler(passmgr) | |
61 | |
62 opener = urllib2.build_opener(proxy_handler, authinfo) | |
1359
51ac9a79f3e5
Set the user agent for httprepo communication
Matt Mackall <mpm@selenic.com>
parents:
1251
diff
changeset
|
63 # 1.0 here is the _protocol_ version |
51ac9a79f3e5
Set the user agent for httprepo communication
Matt Mackall <mpm@selenic.com>
parents:
1251
diff
changeset
|
64 opener.addheaders = [('User-agent', 'mercurial/proto-1.0')] |
321 | 65 urllib2.install_opener(opener) |
60 | 66 |
634
da5378d39269
Add a repo method to report repo device
Matt Mackall <mpm@selenic.com>
parents:
627
diff
changeset
|
67 def dev(self): |
da5378d39269
Add a repo method to report repo device
Matt Mackall <mpm@selenic.com>
parents:
627
diff
changeset
|
68 return -1 |
da5378d39269
Add a repo method to report repo device
Matt Mackall <mpm@selenic.com>
parents:
627
diff
changeset
|
69 |
1870
8a8ab47cccde
make push over http print good error message.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1736
diff
changeset
|
70 def lock(self): |
8a8ab47cccde
make push over http print good error message.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1736
diff
changeset
|
71 raise util.Abort(_('operation not supported over http')) |
8a8ab47cccde
make push over http print good error message.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1736
diff
changeset
|
72 |
60 | 73 def do_cmd(self, cmd, **args): |
1402
9d2c2e6b32b5
i18n part2: use '_' for all strings who are part of the user interface
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1400
diff
changeset
|
74 self.ui.debug(_("sending %s command\n") % cmd) |
60 | 75 q = {"cmd": cmd} |
76 q.update(args) | |
77 qs = urllib.urlencode(q) | |
78 cu = "%s?%s" % (self.url, qs) | |
752 | 79 resp = urllib2.urlopen(cu) |
753 | 80 proto = resp.headers['content-type'] |
752 | 81 |
753 | 82 # accept old "text/plain" and "application/hg-changegroup" for now |
83 if not proto.startswith('application/mercurial') and \ | |
84 not proto.startswith('text/plain') and \ | |
85 not proto.startswith('application/hg-changegroup'): | |
1402
9d2c2e6b32b5
i18n part2: use '_' for all strings who are part of the user interface
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1400
diff
changeset
|
86 raise hg.RepoError(_("'%s' does not appear to be an hg repository") % |
1251
84cf8834efb5
Fix lots of exception-related problems.
Bryan O'Sullivan <bos@serpentine.com>
parents:
1089
diff
changeset
|
87 self.url) |
752 | 88 |
753 | 89 if proto.startswith('application/mercurial'): |
90 version = proto[22:] | |
91 if float(version) > 0.1: | |
1402
9d2c2e6b32b5
i18n part2: use '_' for all strings who are part of the user interface
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1400
diff
changeset
|
92 raise hg.RepoError(_("'%s' uses newer protocol %s") % |
1251
84cf8834efb5
Fix lots of exception-related problems.
Bryan O'Sullivan <bos@serpentine.com>
parents:
1089
diff
changeset
|
93 (self.url, version)) |
753 | 94 |
752 | 95 return resp |
60 | 96 |
222 | 97 def heads(self): |
98 d = self.do_cmd("heads").read() | |
99 try: | |
100 return map(bin, d[:-1].split(" ")) | |
101 except: | |
1402
9d2c2e6b32b5
i18n part2: use '_' for all strings who are part of the user interface
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1400
diff
changeset
|
102 self.ui.warn(_("unexpected response:\n") + d[:400] + "\n...\n") |
222 | 103 raise |
104 | |
60 | 105 def branches(self, nodes): |
106 n = " ".join(map(hex, nodes)) | |
752 | 107 d = self.do_cmd("branches", nodes=n).read() |
217 | 108 try: |
109 br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ] | |
110 return br | |
111 except: | |
1402
9d2c2e6b32b5
i18n part2: use '_' for all strings who are part of the user interface
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1400
diff
changeset
|
112 self.ui.warn(_("unexpected response:\n") + d[:400] + "\n...\n") |
217 | 113 raise |
60 | 114 |
115 def between(self, pairs): | |
116 n = "\n".join(["-".join(map(hex, p)) for p in pairs]) | |
752 | 117 d = self.do_cmd("between", pairs=n).read() |
217 | 118 try: |
119 p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ] | |
120 return p | |
121 except: | |
1402
9d2c2e6b32b5
i18n part2: use '_' for all strings who are part of the user interface
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1400
diff
changeset
|
122 self.ui.warn(_("unexpected response:\n") + d[:400] + "\n...\n") |
217 | 123 raise |
60 | 124 |
1736
50de0887bbcd
add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1402
diff
changeset
|
125 def changegroup(self, nodes, kind): |
60 | 126 n = " ".join(map(hex, nodes)) |
752 | 127 f = self.do_cmd("changegroup", roots=n) |
192 | 128 bytes = 0 |
635
85e2209d401c
Protocol switch from using generators to stream-like objects.
Matt Mackall <mpm@selenic.com>
parents:
634
diff
changeset
|
129 |
1376
524ca4a06f70
Fix same performance bug as c3654cfaa77 but for httprepo.py instead.
Eric Hopper <hopper@omnifarious.org>
parents:
1359
diff
changeset
|
130 def zgenerator(f): |
524ca4a06f70
Fix same performance bug as c3654cfaa77 but for httprepo.py instead.
Eric Hopper <hopper@omnifarious.org>
parents:
1359
diff
changeset
|
131 zd = zlib.decompressobj() |
524ca4a06f70
Fix same performance bug as c3654cfaa77 but for httprepo.py instead.
Eric Hopper <hopper@omnifarious.org>
parents:
1359
diff
changeset
|
132 for chnk in f: |
524ca4a06f70
Fix same performance bug as c3654cfaa77 but for httprepo.py instead.
Eric Hopper <hopper@omnifarious.org>
parents:
1359
diff
changeset
|
133 yield zd.decompress(chnk) |
524ca4a06f70
Fix same performance bug as c3654cfaa77 but for httprepo.py instead.
Eric Hopper <hopper@omnifarious.org>
parents:
1359
diff
changeset
|
134 yield zd.flush() |
635
85e2209d401c
Protocol switch from using generators to stream-like objects.
Matt Mackall <mpm@selenic.com>
parents:
634
diff
changeset
|
135 |
1376
524ca4a06f70
Fix same performance bug as c3654cfaa77 but for httprepo.py instead.
Eric Hopper <hopper@omnifarious.org>
parents:
1359
diff
changeset
|
136 return util.chunkbuffer(zgenerator(util.filechunkiter(f))) |
635
85e2209d401c
Protocol switch from using generators to stream-like objects.
Matt Mackall <mpm@selenic.com>
parents:
634
diff
changeset
|
137 |
923 | 138 class httpsrepository(httprepository): |
139 pass |