##// END OF EJS Templates
allow http authentication information to be specified in the configuration
Sune Foldager -
r8333:89c80c3d default
parent child Browse files
Show More
@@ -0,0 +1,61 b''
1 from mercurial import demandimport; demandimport.enable()
2 from mercurial import ui
3 from mercurial import url
4 from mercurial.error import Abort
5
6 class myui(ui.ui):
7 def interactive(self):
8 return False
9
10 origui = myui()
11
12 def writeauth(items):
13 ui = origui.copy()
14 for name, value in items.iteritems():
15 ui.setconfig('auth', name, value)
16 return ui
17
18 def dumpdict(dict):
19 return '{' + ', '.join(['%s: %s' % (k, dict[k]) for k in sorted(dict.iterkeys())]) + '}'
20
21 def test(auth):
22 print 'CFG:', dumpdict(auth)
23 prefixes = set()
24 for k in auth:
25 prefixes.add(k.split('.', 1)[0])
26 for p in prefixes:
27 auth.update({p + '.username': p, p + '.password': p})
28
29 ui = writeauth(auth)
30
31 def _test(uri):
32 print 'URI:', uri
33 try:
34 pm = url.passwordmgr(ui)
35 print ' ', pm.find_user_password('test', uri)
36 except Abort, e:
37 print 'abort'
38
39 _test('http://example.org/foo')
40 _test('http://example.org/foo/bar')
41 _test('http://example.org/bar')
42 _test('https://example.org/foo')
43 _test('https://example.org/foo/bar')
44 _test('https://example.org/bar')
45
46
47 print '\n*** Test in-uri schemes\n'
48 test({'x.prefix': 'http://example.org'})
49 test({'x.prefix': 'https://example.org'})
50 test({'x.prefix': 'http://example.org', 'x.schemes': 'https'})
51 test({'x.prefix': 'https://example.org', 'x.schemes': 'http'})
52
53 print '\n*** Test separately configured schemes\n'
54 test({'x.prefix': 'example.org', 'x.schemes': 'http'})
55 test({'x.prefix': 'example.org', 'x.schemes': 'https'})
56 test({'x.prefix': 'example.org', 'x.schemes': 'http https'})
57
58 print '\n*** Test prefix matching\n'
59 test({'x.prefix': 'http://example.org/foo', 'y.prefix': 'http://example.org/bar'})
60 test({'x.prefix': 'http://example.org/foo', 'y.prefix': 'http://example.org/foo/bar'})
61 test({'x.prefix': '*', 'y.prefix': 'https://example.org/bar'})
@@ -0,0 +1,139 b''
1
2 *** Test in-uri schemes
3
4 CFG: {x.prefix: http://example.org}
5 URI: http://example.org/foo
6 ('x', 'x')
7 URI: http://example.org/foo/bar
8 ('x', 'x')
9 URI: http://example.org/bar
10 ('x', 'x')
11 URI: https://example.org/foo
12 abort
13 URI: https://example.org/foo/bar
14 abort
15 URI: https://example.org/bar
16 abort
17 CFG: {x.prefix: https://example.org}
18 URI: http://example.org/foo
19 abort
20 URI: http://example.org/foo/bar
21 abort
22 URI: http://example.org/bar
23 abort
24 URI: https://example.org/foo
25 ('x', 'x')
26 URI: https://example.org/foo/bar
27 ('x', 'x')
28 URI: https://example.org/bar
29 ('x', 'x')
30 CFG: {x.prefix: http://example.org, x.schemes: https}
31 URI: http://example.org/foo
32 ('x', 'x')
33 URI: http://example.org/foo/bar
34 ('x', 'x')
35 URI: http://example.org/bar
36 ('x', 'x')
37 URI: https://example.org/foo
38 abort
39 URI: https://example.org/foo/bar
40 abort
41 URI: https://example.org/bar
42 abort
43 CFG: {x.prefix: https://example.org, x.schemes: http}
44 URI: http://example.org/foo
45 abort
46 URI: http://example.org/foo/bar
47 abort
48 URI: http://example.org/bar
49 abort
50 URI: https://example.org/foo
51 ('x', 'x')
52 URI: https://example.org/foo/bar
53 ('x', 'x')
54 URI: https://example.org/bar
55 ('x', 'x')
56
57 *** Test separately configured schemes
58
59 CFG: {x.prefix: example.org, x.schemes: http}
60 URI: http://example.org/foo
61 ('x', 'x')
62 URI: http://example.org/foo/bar
63 ('x', 'x')
64 URI: http://example.org/bar
65 ('x', 'x')
66 URI: https://example.org/foo
67 abort
68 URI: https://example.org/foo/bar
69 abort
70 URI: https://example.org/bar
71 abort
72 CFG: {x.prefix: example.org, x.schemes: https}
73 URI: http://example.org/foo
74 abort
75 URI: http://example.org/foo/bar
76 abort
77 URI: http://example.org/bar
78 abort
79 URI: https://example.org/foo
80 ('x', 'x')
81 URI: https://example.org/foo/bar
82 ('x', 'x')
83 URI: https://example.org/bar
84 ('x', 'x')
85 CFG: {x.prefix: example.org, x.schemes: http https}
86 URI: http://example.org/foo
87 ('x', 'x')
88 URI: http://example.org/foo/bar
89 ('x', 'x')
90 URI: http://example.org/bar
91 ('x', 'x')
92 URI: https://example.org/foo
93 ('x', 'x')
94 URI: https://example.org/foo/bar
95 ('x', 'x')
96 URI: https://example.org/bar
97 ('x', 'x')
98
99 *** Test prefix matching
100
101 CFG: {x.prefix: http://example.org/foo, y.prefix: http://example.org/bar}
102 URI: http://example.org/foo
103 ('x', 'x')
104 URI: http://example.org/foo/bar
105 ('x', 'x')
106 URI: http://example.org/bar
107 ('y', 'y')
108 URI: https://example.org/foo
109 abort
110 URI: https://example.org/foo/bar
111 abort
112 URI: https://example.org/bar
113 abort
114 CFG: {x.prefix: http://example.org/foo, y.prefix: http://example.org/foo/bar}
115 URI: http://example.org/foo
116 ('x', 'x')
117 URI: http://example.org/foo/bar
118 ('y', 'y')
119 URI: http://example.org/bar
120 abort
121 URI: https://example.org/foo
122 abort
123 URI: https://example.org/foo/bar
124 abort
125 URI: https://example.org/bar
126 abort
127 CFG: {x.prefix: *, y.prefix: https://example.org/bar}
128 URI: http://example.org/foo
129 abort
130 URI: http://example.org/foo/bar
131 abort
132 URI: http://example.org/bar
133 abort
134 URI: https://example.org/foo
135 ('x', 'x')
136 URI: https://example.org/foo/bar
137 ('x', 'x')
138 URI: https://example.org/bar
139 ('y', 'y')
@@ -1,797 +1,836 b''
1 HGRC(5)
1 HGRC(5)
2 =======
2 =======
3 Bryan O'Sullivan <bos@serpentine.com>
3 Bryan O'Sullivan <bos@serpentine.com>
4
4
5 NAME
5 NAME
6 ----
6 ----
7 hgrc - configuration files for Mercurial
7 hgrc - configuration files for Mercurial
8
8
9 SYNOPSIS
9 SYNOPSIS
10 --------
10 --------
11
11
12 The Mercurial system uses a set of configuration files to control
12 The Mercurial system uses a set of configuration files to control
13 aspects of its behaviour.
13 aspects of its behaviour.
14
14
15 FILES
15 FILES
16 -----
16 -----
17
17
18 Mercurial reads configuration data from several files, if they exist.
18 Mercurial reads configuration data from several files, if they exist.
19 The names of these files depend on the system on which Mercurial is
19 The names of these files depend on the system on which Mercurial is
20 installed. *.rc files from a single directory are read in
20 installed. *.rc files from a single directory are read in
21 alphabetical order, later ones overriding earlier ones. Where
21 alphabetical order, later ones overriding earlier ones. Where
22 multiple paths are given below, settings from later paths override
22 multiple paths are given below, settings from later paths override
23 earlier ones.
23 earlier ones.
24
24
25 (Unix) <install-root>/etc/mercurial/hgrc.d/*.rc::
25 (Unix) <install-root>/etc/mercurial/hgrc.d/*.rc::
26 (Unix) <install-root>/etc/mercurial/hgrc::
26 (Unix) <install-root>/etc/mercurial/hgrc::
27 Per-installation configuration files, searched for in the
27 Per-installation configuration files, searched for in the
28 directory where Mercurial is installed. <install-root> is the
28 directory where Mercurial is installed. <install-root> is the
29 parent directory of the hg executable (or symlink) being run.
29 parent directory of the hg executable (or symlink) being run.
30 For example, if installed in /shared/tools/bin/hg, Mercurial will
30 For example, if installed in /shared/tools/bin/hg, Mercurial will
31 look in /shared/tools/etc/mercurial/hgrc. Options in these files
31 look in /shared/tools/etc/mercurial/hgrc. Options in these files
32 apply to all Mercurial commands executed by any user in any
32 apply to all Mercurial commands executed by any user in any
33 directory.
33 directory.
34
34
35 (Unix) /etc/mercurial/hgrc.d/*.rc::
35 (Unix) /etc/mercurial/hgrc.d/*.rc::
36 (Unix) /etc/mercurial/hgrc::
36 (Unix) /etc/mercurial/hgrc::
37 Per-system configuration files, for the system on which Mercurial
37 Per-system configuration files, for the system on which Mercurial
38 is running. Options in these files apply to all Mercurial
38 is running. Options in these files apply to all Mercurial
39 commands executed by any user in any directory. Options in these
39 commands executed by any user in any directory. Options in these
40 files override per-installation options.
40 files override per-installation options.
41
41
42 (Windows) <install-dir>\Mercurial.ini::
42 (Windows) <install-dir>\Mercurial.ini::
43 or else::
43 or else::
44 (Windows) HKEY_LOCAL_MACHINE\SOFTWARE\Mercurial::
44 (Windows) HKEY_LOCAL_MACHINE\SOFTWARE\Mercurial::
45 or else::
45 or else::
46 (Windows) C:\Mercurial\Mercurial.ini::
46 (Windows) C:\Mercurial\Mercurial.ini::
47 Per-installation/system configuration files, for the system on
47 Per-installation/system configuration files, for the system on
48 which Mercurial is running. Options in these files apply to all
48 which Mercurial is running. Options in these files apply to all
49 Mercurial commands executed by any user in any directory.
49 Mercurial commands executed by any user in any directory.
50 Registry keys contain PATH-like strings, every part of which must
50 Registry keys contain PATH-like strings, every part of which must
51 reference a Mercurial.ini file or be a directory where *.rc files
51 reference a Mercurial.ini file or be a directory where *.rc files
52 will be read.
52 will be read.
53
53
54 (Unix) $HOME/.hgrc::
54 (Unix) $HOME/.hgrc::
55 (Windows) %HOME%\Mercurial.ini::
55 (Windows) %HOME%\Mercurial.ini::
56 (Windows) %HOME%\.hgrc::
56 (Windows) %HOME%\.hgrc::
57 (Windows) %USERPROFILE%\Mercurial.ini::
57 (Windows) %USERPROFILE%\Mercurial.ini::
58 (Windows) %USERPROFILE%\.hgrc::
58 (Windows) %USERPROFILE%\.hgrc::
59 Per-user configuration file(s), for the user running Mercurial.
59 Per-user configuration file(s), for the user running Mercurial.
60 On Windows 9x, %HOME% is replaced by %APPDATA%.
60 On Windows 9x, %HOME% is replaced by %APPDATA%.
61 Options in these files apply to all Mercurial commands executed
61 Options in these files apply to all Mercurial commands executed
62 by this user in any directory. Options in thes files override
62 by this user in any directory. Options in thes files override
63 per-installation and per-system options.
63 per-installation and per-system options.
64
64
65 (Unix, Windows) <repo>/.hg/hgrc::
65 (Unix, Windows) <repo>/.hg/hgrc::
66 Per-repository configuration options that only apply in a
66 Per-repository configuration options that only apply in a
67 particular repository. This file is not version-controlled, and
67 particular repository. This file is not version-controlled, and
68 will not get transferred during a "clone" operation. Options in
68 will not get transferred during a "clone" operation. Options in
69 this file override options in all other configuration files.
69 this file override options in all other configuration files.
70 On Unix, most of this file will be ignored if it doesn't belong
70 On Unix, most of this file will be ignored if it doesn't belong
71 to a trusted user or to a trusted group. See the documentation
71 to a trusted user or to a trusted group. See the documentation
72 for the trusted section below for more details.
72 for the trusted section below for more details.
73
73
74 SYNTAX
74 SYNTAX
75 ------
75 ------
76
76
77 A configuration file consists of sections, led by a "[section]" header
77 A configuration file consists of sections, led by a "[section]" header
78 and followed by "name: value" entries; "name=value" is also accepted.
78 and followed by "name: value" entries; "name=value" is also accepted.
79
79
80 [spam]
80 [spam]
81 eggs=ham
81 eggs=ham
82 green=
82 green=
83 eggs
83 eggs
84
84
85 Each line contains one entry. If the lines that follow are indented,
85 Each line contains one entry. If the lines that follow are indented,
86 they are treated as continuations of that entry.
86 they are treated as continuations of that entry.
87
87
88 Leading whitespace is removed from values. Empty lines are skipped.
88 Leading whitespace is removed from values. Empty lines are skipped.
89
89
90 The optional values can contain format strings which refer to other
90 The optional values can contain format strings which refer to other
91 values in the same section, or values in a special DEFAULT section.
91 values in the same section, or values in a special DEFAULT section.
92
92
93 Lines beginning with "#" or ";" are ignored and may be used to provide
93 Lines beginning with "#" or ";" are ignored and may be used to provide
94 comments.
94 comments.
95
95
96 SECTIONS
96 SECTIONS
97 --------
97 --------
98
98
99 This section describes the different sections that may appear in a
99 This section describes the different sections that may appear in a
100 Mercurial "hgrc" file, the purpose of each section, its possible
100 Mercurial "hgrc" file, the purpose of each section, its possible
101 keys, and their possible values.
101 keys, and their possible values.
102
102
103 [[auth]]
104 auth:
105 Authentication credentials for HTTP authentication.
106 Each line has the following format:
107
108 <name>.<argument> = <value>
109
110 where <name> is used to group arguments into authentication entries.
111 Example:
112
113 foo.prefix = hg.intevation.org/mercurial
114 foo.username = foo
115 foo.password = bar
116 foo.schemes = http https
117
118 Supported arguments:
119
120 prefix;;
121 Either '*' or a URI prefix with or without the scheme part. The
122 authentication entry with the longest matching prefix is used
123 (where '*' matches everything and counts as a match of length 1).
124 If the prefix doesn't include a scheme, the match is performed against
125 the URI with its scheme stripped as well, and the schemes argument,
126 q.v., is then subsequently consulted.
127 username;;
128 Username to authenticate with.
129 password;;
130 Optional. Password to authenticate with. If not given the user will be
131 prompted for it.
132 schemes;;
133 Optional. Space separated list of URI schemes to use this authentication
134 entry with. Only used if the prefix doesn't include a scheme. Supported
135 schemes are http and https. They will match static-http and static-https
136 respectively, as well.
137 Default: https.
138
139 If no suitable authentication entry is found, the user is prompted for
140 credentials as usual if required by the remote.
141
103 [[decode]]
142 [[decode]]
104 decode/encode::
143 decode/encode::
105 Filters for transforming files on checkout/checkin. This would
144 Filters for transforming files on checkout/checkin. This would
106 typically be used for newline processing or other
145 typically be used for newline processing or other
107 localization/canonicalization of files.
146 localization/canonicalization of files.
108
147
109 Filters consist of a filter pattern followed by a filter command.
148 Filters consist of a filter pattern followed by a filter command.
110 Filter patterns are globs by default, rooted at the repository
149 Filter patterns are globs by default, rooted at the repository
111 root. For example, to match any file ending in ".txt" in the root
150 root. For example, to match any file ending in ".txt" in the root
112 directory only, use the pattern "*.txt". To match any file ending
151 directory only, use the pattern "*.txt". To match any file ending
113 in ".c" anywhere in the repository, use the pattern "**.c".
152 in ".c" anywhere in the repository, use the pattern "**.c".
114
153
115 The filter command can start with a specifier, either "pipe:" or
154 The filter command can start with a specifier, either "pipe:" or
116 "tempfile:". If no specifier is given, "pipe:" is used by default.
155 "tempfile:". If no specifier is given, "pipe:" is used by default.
117
156
118 A "pipe:" command must accept data on stdin and return the
157 A "pipe:" command must accept data on stdin and return the
119 transformed data on stdout.
158 transformed data on stdout.
120
159
121 Pipe example:
160 Pipe example:
122
161
123 [encode]
162 [encode]
124 # uncompress gzip files on checkin to improve delta compression
163 # uncompress gzip files on checkin to improve delta compression
125 # note: not necessarily a good idea, just an example
164 # note: not necessarily a good idea, just an example
126 *.gz = pipe: gunzip
165 *.gz = pipe: gunzip
127
166
128 [decode]
167 [decode]
129 # recompress gzip files when writing them to the working dir (we
168 # recompress gzip files when writing them to the working dir (we
130 # can safely omit "pipe:", because it's the default)
169 # can safely omit "pipe:", because it's the default)
131 *.gz = gzip
170 *.gz = gzip
132
171
133 A "tempfile:" command is a template. The string INFILE is replaced
172 A "tempfile:" command is a template. The string INFILE is replaced
134 with the name of a temporary file that contains the data to be
173 with the name of a temporary file that contains the data to be
135 filtered by the command. The string OUTFILE is replaced with the
174 filtered by the command. The string OUTFILE is replaced with the
136 name of an empty temporary file, where the filtered data must be
175 name of an empty temporary file, where the filtered data must be
137 written by the command.
176 written by the command.
138
177
139 NOTE: the tempfile mechanism is recommended for Windows systems,
178 NOTE: the tempfile mechanism is recommended for Windows systems,
140 where the standard shell I/O redirection operators often have
179 where the standard shell I/O redirection operators often have
141 strange effects and may corrupt the contents of your files.
180 strange effects and may corrupt the contents of your files.
142
181
143 The most common usage is for LF <-> CRLF translation on Windows.
182 The most common usage is for LF <-> CRLF translation on Windows.
144 For this, use the "smart" convertors which check for binary files:
183 For this, use the "smart" convertors which check for binary files:
145
184
146 [extensions]
185 [extensions]
147 hgext.win32text =
186 hgext.win32text =
148 [encode]
187 [encode]
149 ** = cleverencode:
188 ** = cleverencode:
150 [decode]
189 [decode]
151 ** = cleverdecode:
190 ** = cleverdecode:
152
191
153 or if you only want to translate certain files:
192 or if you only want to translate certain files:
154
193
155 [extensions]
194 [extensions]
156 hgext.win32text =
195 hgext.win32text =
157 [encode]
196 [encode]
158 **.txt = dumbencode:
197 **.txt = dumbencode:
159 [decode]
198 [decode]
160 **.txt = dumbdecode:
199 **.txt = dumbdecode:
161
200
162 [[defaults]]
201 [[defaults]]
163 defaults::
202 defaults::
164 Use the [defaults] section to define command defaults, i.e. the
203 Use the [defaults] section to define command defaults, i.e. the
165 default options/arguments to pass to the specified commands.
204 default options/arguments to pass to the specified commands.
166
205
167 The following example makes 'hg log' run in verbose mode, and
206 The following example makes 'hg log' run in verbose mode, and
168 'hg status' show only the modified files, by default.
207 'hg status' show only the modified files, by default.
169
208
170 [defaults]
209 [defaults]
171 log = -v
210 log = -v
172 status = -m
211 status = -m
173
212
174 The actual commands, instead of their aliases, must be used when
213 The actual commands, instead of their aliases, must be used when
175 defining command defaults. The command defaults will also be
214 defining command defaults. The command defaults will also be
176 applied to the aliases of the commands defined.
215 applied to the aliases of the commands defined.
177
216
178 [[diff]]
217 [[diff]]
179 diff::
218 diff::
180 Settings used when displaying diffs. They are all boolean and
219 Settings used when displaying diffs. They are all boolean and
181 defaults to False.
220 defaults to False.
182 git;;
221 git;;
183 Use git extended diff format.
222 Use git extended diff format.
184 nodates;;
223 nodates;;
185 Don't include dates in diff headers.
224 Don't include dates in diff headers.
186 showfunc;;
225 showfunc;;
187 Show which function each change is in.
226 Show which function each change is in.
188 ignorews;;
227 ignorews;;
189 Ignore white space when comparing lines.
228 Ignore white space when comparing lines.
190 ignorewsamount;;
229 ignorewsamount;;
191 Ignore changes in the amount of white space.
230 Ignore changes in the amount of white space.
192 ignoreblanklines;;
231 ignoreblanklines;;
193 Ignore changes whose lines are all blank.
232 Ignore changes whose lines are all blank.
194
233
195 [[email]]
234 [[email]]
196 email::
235 email::
197 Settings for extensions that send email messages.
236 Settings for extensions that send email messages.
198 from;;
237 from;;
199 Optional. Email address to use in "From" header and SMTP envelope
238 Optional. Email address to use in "From" header and SMTP envelope
200 of outgoing messages.
239 of outgoing messages.
201 to;;
240 to;;
202 Optional. Comma-separated list of recipients' email addresses.
241 Optional. Comma-separated list of recipients' email addresses.
203 cc;;
242 cc;;
204 Optional. Comma-separated list of carbon copy recipients'
243 Optional. Comma-separated list of carbon copy recipients'
205 email addresses.
244 email addresses.
206 bcc;;
245 bcc;;
207 Optional. Comma-separated list of blind carbon copy
246 Optional. Comma-separated list of blind carbon copy
208 recipients' email addresses. Cannot be set interactively.
247 recipients' email addresses. Cannot be set interactively.
209 method;;
248 method;;
210 Optional. Method to use to send email messages. If value is
249 Optional. Method to use to send email messages. If value is
211 "smtp" (default), use SMTP (see section "[smtp]" for
250 "smtp" (default), use SMTP (see section "[smtp]" for
212 configuration). Otherwise, use as name of program to run that
251 configuration). Otherwise, use as name of program to run that
213 acts like sendmail (takes "-f" option for sender, list of
252 acts like sendmail (takes "-f" option for sender, list of
214 recipients on command line, message on stdin). Normally, setting
253 recipients on command line, message on stdin). Normally, setting
215 this to "sendmail" or "/usr/sbin/sendmail" is enough to use
254 this to "sendmail" or "/usr/sbin/sendmail" is enough to use
216 sendmail to send messages.
255 sendmail to send messages.
217 charsets;;
256 charsets;;
218 Optional. Comma-separated list of charsets considered
257 Optional. Comma-separated list of charsets considered
219 convenient for recipients. Addresses, headers, and parts not
258 convenient for recipients. Addresses, headers, and parts not
220 containing patches of outgoing messages will be encoded in
259 containing patches of outgoing messages will be encoded in
221 the first charset to which conversion from local encoding
260 the first charset to which conversion from local encoding
222 ($HGENCODING, ui.fallbackencoding) succeeds. If correct
261 ($HGENCODING, ui.fallbackencoding) succeeds. If correct
223 conversion fails, the text in question is sent as is.
262 conversion fails, the text in question is sent as is.
224 Defaults to empty (explicit) list.
263 Defaults to empty (explicit) list.
225
264
226 Order of outgoing email charsets:
265 Order of outgoing email charsets:
227
266
228 us-ascii always first, regardless of settings
267 us-ascii always first, regardless of settings
229 email.charsets in order given by user
268 email.charsets in order given by user
230 ui.fallbackencoding if not in email.charsets
269 ui.fallbackencoding if not in email.charsets
231 $HGENCODING if not in email.charsets
270 $HGENCODING if not in email.charsets
232 utf-8 always last, regardless of settings
271 utf-8 always last, regardless of settings
233
272
234 Email example:
273 Email example:
235
274
236 [email]
275 [email]
237 from = Joseph User <joe.user@example.com>
276 from = Joseph User <joe.user@example.com>
238 method = /usr/sbin/sendmail
277 method = /usr/sbin/sendmail
239 # charsets for western europeans
278 # charsets for western europeans
240 # us-ascii, utf-8 omitted, as they are tried first and last
279 # us-ascii, utf-8 omitted, as they are tried first and last
241 charsets = iso-8859-1, iso-8859-15, windows-1252
280 charsets = iso-8859-1, iso-8859-15, windows-1252
242
281
243 [[extensions]]
282 [[extensions]]
244 extensions::
283 extensions::
245 Mercurial has an extension mechanism for adding new features. To
284 Mercurial has an extension mechanism for adding new features. To
246 enable an extension, create an entry for it in this section.
285 enable an extension, create an entry for it in this section.
247
286
248 If you know that the extension is already in Python's search path,
287 If you know that the extension is already in Python's search path,
249 you can give the name of the module, followed by "=", with nothing
288 you can give the name of the module, followed by "=", with nothing
250 after the "=".
289 after the "=".
251
290
252 Otherwise, give a name that you choose, followed by "=", followed by
291 Otherwise, give a name that you choose, followed by "=", followed by
253 the path to the ".py" file (including the file name extension) that
292 the path to the ".py" file (including the file name extension) that
254 defines the extension.
293 defines the extension.
255
294
256 To explicitly disable an extension that is enabled in an hgrc of
295 To explicitly disable an extension that is enabled in an hgrc of
257 broader scope, prepend its path with '!', as in
296 broader scope, prepend its path with '!', as in
258 'hgext.foo = !/ext/path' or 'hgext.foo = !' when no path is supplied.
297 'hgext.foo = !/ext/path' or 'hgext.foo = !' when no path is supplied.
259
298
260 Example for ~/.hgrc:
299 Example for ~/.hgrc:
261
300
262 [extensions]
301 [extensions]
263 # (the mq extension will get loaded from mercurial's path)
302 # (the mq extension will get loaded from mercurial's path)
264 hgext.mq =
303 hgext.mq =
265 # (this extension will get loaded from the file specified)
304 # (this extension will get loaded from the file specified)
266 myfeature = ~/.hgext/myfeature.py
305 myfeature = ~/.hgext/myfeature.py
267
306
268 [[format]]
307 [[format]]
269 format::
308 format::
270
309
271 usestore;;
310 usestore;;
272 Enable or disable the "store" repository format which improves
311 Enable or disable the "store" repository format which improves
273 compatibility with systems that fold case or otherwise mangle
312 compatibility with systems that fold case or otherwise mangle
274 filenames. Enabled by default. Disabling this option will allow
313 filenames. Enabled by default. Disabling this option will allow
275 you to store longer filenames in some situations at the expense of
314 you to store longer filenames in some situations at the expense of
276 compatibility and ensures that the on-disk format of newly created
315 compatibility and ensures that the on-disk format of newly created
277 repositories will be compatible with Mercurial before version 0.9.4.
316 repositories will be compatible with Mercurial before version 0.9.4.
278
317
279 usefncache;;
318 usefncache;;
280 Enable or disable the "fncache" repository format which enhances
319 Enable or disable the "fncache" repository format which enhances
281 the "store" repository format (which has to be enabled to use
320 the "store" repository format (which has to be enabled to use
282 fncache) to allow longer filenames and avoids using Windows reserved
321 fncache) to allow longer filenames and avoids using Windows reserved
283 names, e.g. "nul". Enabled by default. Disabling this option ensures
322 names, e.g. "nul". Enabled by default. Disabling this option ensures
284 that the on-disk format of newly created repositories will be
323 that the on-disk format of newly created repositories will be
285 compatible with Mercurial before version 1.1.
324 compatible with Mercurial before version 1.1.
286
325
287 [[merge-patterns]]
326 [[merge-patterns]]
288 merge-patterns::
327 merge-patterns::
289 This section specifies merge tools to associate with particular file
328 This section specifies merge tools to associate with particular file
290 patterns. Tools matched here will take precedence over the default
329 patterns. Tools matched here will take precedence over the default
291 merge tool. Patterns are globs by default, rooted at the repository root.
330 merge tool. Patterns are globs by default, rooted at the repository root.
292
331
293 Example:
332 Example:
294
333
295 [merge-patterns]
334 [merge-patterns]
296 **.c = kdiff3
335 **.c = kdiff3
297 **.jpg = myimgmerge
336 **.jpg = myimgmerge
298
337
299 [[merge-tools]]
338 [[merge-tools]]
300 merge-tools::
339 merge-tools::
301 This section configures external merge tools to use for file-level
340 This section configures external merge tools to use for file-level
302 merges.
341 merges.
303
342
304 Example ~/.hgrc:
343 Example ~/.hgrc:
305
344
306 [merge-tools]
345 [merge-tools]
307 # Override stock tool location
346 # Override stock tool location
308 kdiff3.executable = ~/bin/kdiff3
347 kdiff3.executable = ~/bin/kdiff3
309 # Specify command line
348 # Specify command line
310 kdiff3.args = $base $local $other -o $output
349 kdiff3.args = $base $local $other -o $output
311 # Give higher priority
350 # Give higher priority
312 kdiff3.priority = 1
351 kdiff3.priority = 1
313
352
314 # Define new tool
353 # Define new tool
315 myHtmlTool.args = -m $local $other $base $output
354 myHtmlTool.args = -m $local $other $base $output
316 myHtmlTool.regkey = Software\FooSoftware\HtmlMerge
355 myHtmlTool.regkey = Software\FooSoftware\HtmlMerge
317 myHtmlTool.priority = 1
356 myHtmlTool.priority = 1
318
357
319 Supported arguments:
358 Supported arguments:
320
359
321 priority;;
360 priority;;
322 The priority in which to evaluate this tool.
361 The priority in which to evaluate this tool.
323 Default: 0.
362 Default: 0.
324 executable;;
363 executable;;
325 Either just the name of the executable or its pathname.
364 Either just the name of the executable or its pathname.
326 Default: the tool name.
365 Default: the tool name.
327 args;;
366 args;;
328 The arguments to pass to the tool executable. You can refer to the files
367 The arguments to pass to the tool executable. You can refer to the files
329 being merged as well as the output file through these variables: $base,
368 being merged as well as the output file through these variables: $base,
330 $local, $other, $output.
369 $local, $other, $output.
331 Default: $local $base $other
370 Default: $local $base $other
332 premerge;;
371 premerge;;
333 Attempt to run internal non-interactive 3-way merge tool before
372 Attempt to run internal non-interactive 3-way merge tool before
334 launching external tool.
373 launching external tool.
335 Default: True
374 Default: True
336 binary;;
375 binary;;
337 This tool can merge binary files. Defaults to False, unless tool
376 This tool can merge binary files. Defaults to False, unless tool
338 was selected by file pattern match.
377 was selected by file pattern match.
339 symlink;;
378 symlink;;
340 This tool can merge symlinks. Defaults to False, even if tool was
379 This tool can merge symlinks. Defaults to False, even if tool was
341 selected by file pattern match.
380 selected by file pattern match.
342 checkconflicts;;
381 checkconflicts;;
343 Check whether there are conflicts even though the tool reported
382 Check whether there are conflicts even though the tool reported
344 success.
383 success.
345 Default: False
384 Default: False
346 checkchanged;;
385 checkchanged;;
347 Check whether outputs were written even though the tool reported
386 Check whether outputs were written even though the tool reported
348 success.
387 success.
349 Default: False
388 Default: False
350 fixeol;;
389 fixeol;;
351 Attempt to fix up EOL changes caused by the merge tool.
390 Attempt to fix up EOL changes caused by the merge tool.
352 Default: False
391 Default: False
353 gui;;
392 gui;;
354 This tool requires a graphical interface to run. Default: False
393 This tool requires a graphical interface to run. Default: False
355 regkey;;
394 regkey;;
356 Windows registry key which describes install location of this tool.
395 Windows registry key which describes install location of this tool.
357 Mercurial will search for this key first under HKEY_CURRENT_USER and
396 Mercurial will search for this key first under HKEY_CURRENT_USER and
358 then under HKEY_LOCAL_MACHINE. Default: None
397 then under HKEY_LOCAL_MACHINE. Default: None
359 regname;;
398 regname;;
360 Name of value to read from specified registry key. Defaults to the
399 Name of value to read from specified registry key. Defaults to the
361 unnamed (default) value.
400 unnamed (default) value.
362 regappend;;
401 regappend;;
363 String to append to the value read from the registry, typically the
402 String to append to the value read from the registry, typically the
364 executable name of the tool. Default: None
403 executable name of the tool. Default: None
365
404
366 [[hooks]]
405 [[hooks]]
367 hooks::
406 hooks::
368 Commands or Python functions that get automatically executed by
407 Commands or Python functions that get automatically executed by
369 various actions such as starting or finishing a commit. Multiple
408 various actions such as starting or finishing a commit. Multiple
370 hooks can be run for the same action by appending a suffix to the
409 hooks can be run for the same action by appending a suffix to the
371 action. Overriding a site-wide hook can be done by changing its
410 action. Overriding a site-wide hook can be done by changing its
372 value or setting it to an empty string.
411 value or setting it to an empty string.
373
412
374 Example .hg/hgrc:
413 Example .hg/hgrc:
375
414
376 [hooks]
415 [hooks]
377 # do not use the site-wide hook
416 # do not use the site-wide hook
378 incoming =
417 incoming =
379 incoming.email = /my/email/hook
418 incoming.email = /my/email/hook
380 incoming.autobuild = /my/build/hook
419 incoming.autobuild = /my/build/hook
381
420
382 Most hooks are run with environment variables set that give added
421 Most hooks are run with environment variables set that give added
383 useful information. For each hook below, the environment variables
422 useful information. For each hook below, the environment variables
384 it is passed are listed with names of the form "$HG_foo".
423 it is passed are listed with names of the form "$HG_foo".
385
424
386 changegroup;;
425 changegroup;;
387 Run after a changegroup has been added via push, pull or
426 Run after a changegroup has been added via push, pull or
388 unbundle. ID of the first new changeset is in $HG_NODE. URL from
427 unbundle. ID of the first new changeset is in $HG_NODE. URL from
389 which changes came is in $HG_URL.
428 which changes came is in $HG_URL.
390 commit;;
429 commit;;
391 Run after a changeset has been created in the local repository.
430 Run after a changeset has been created in the local repository.
392 ID of the newly created changeset is in $HG_NODE. Parent
431 ID of the newly created changeset is in $HG_NODE. Parent
393 changeset IDs are in $HG_PARENT1 and $HG_PARENT2.
432 changeset IDs are in $HG_PARENT1 and $HG_PARENT2.
394 incoming;;
433 incoming;;
395 Run after a changeset has been pulled, pushed, or unbundled into
434 Run after a changeset has been pulled, pushed, or unbundled into
396 the local repository. The ID of the newly arrived changeset is in
435 the local repository. The ID of the newly arrived changeset is in
397 $HG_NODE. URL that was source of changes came is in $HG_URL.
436 $HG_NODE. URL that was source of changes came is in $HG_URL.
398 outgoing;;
437 outgoing;;
399 Run after sending changes from local repository to another. ID of
438 Run after sending changes from local repository to another. ID of
400 first changeset sent is in $HG_NODE. Source of operation is in
439 first changeset sent is in $HG_NODE. Source of operation is in
401 $HG_SOURCE; see "preoutgoing" hook for description.
440 $HG_SOURCE; see "preoutgoing" hook for description.
402 post-<command>;;
441 post-<command>;;
403 Run after successful invocations of the associated command. The
442 Run after successful invocations of the associated command. The
404 contents of the command line are passed as $HG_ARGS and the result
443 contents of the command line are passed as $HG_ARGS and the result
405 code in $HG_RESULT. Hook failure is ignored.
444 code in $HG_RESULT. Hook failure is ignored.
406 pre-<command>;;
445 pre-<command>;;
407 Run before executing the associated command. The contents of the
446 Run before executing the associated command. The contents of the
408 command line are passed as $HG_ARGS. If the hook returns failure,
447 command line are passed as $HG_ARGS. If the hook returns failure,
409 the command doesn't execute and Mercurial returns the failure code.
448 the command doesn't execute and Mercurial returns the failure code.
410 prechangegroup;;
449 prechangegroup;;
411 Run before a changegroup is added via push, pull or unbundle.
450 Run before a changegroup is added via push, pull or unbundle.
412 Exit status 0 allows the changegroup to proceed. Non-zero status
451 Exit status 0 allows the changegroup to proceed. Non-zero status
413 will cause the push, pull or unbundle to fail. URL from which
452 will cause the push, pull or unbundle to fail. URL from which
414 changes will come is in $HG_URL.
453 changes will come is in $HG_URL.
415 precommit;;
454 precommit;;
416 Run before starting a local commit. Exit status 0 allows the
455 Run before starting a local commit. Exit status 0 allows the
417 commit to proceed. Non-zero status will cause the commit to fail.
456 commit to proceed. Non-zero status will cause the commit to fail.
418 Parent changeset IDs are in $HG_PARENT1 and $HG_PARENT2.
457 Parent changeset IDs are in $HG_PARENT1 and $HG_PARENT2.
419 preoutgoing;;
458 preoutgoing;;
420 Run before collecting changes to send from the local repository to
459 Run before collecting changes to send from the local repository to
421 another. Non-zero status will cause failure. This lets you
460 another. Non-zero status will cause failure. This lets you
422 prevent pull over http or ssh. Also prevents against local pull,
461 prevent pull over http or ssh. Also prevents against local pull,
423 push (outbound) or bundle commands, but not effective, since you
462 push (outbound) or bundle commands, but not effective, since you
424 can just copy files instead then. Source of operation is in
463 can just copy files instead then. Source of operation is in
425 $HG_SOURCE. If "serve", operation is happening on behalf of
464 $HG_SOURCE. If "serve", operation is happening on behalf of
426 remote ssh or http repository. If "push", "pull" or "bundle",
465 remote ssh or http repository. If "push", "pull" or "bundle",
427 operation is happening on behalf of repository on same system.
466 operation is happening on behalf of repository on same system.
428 pretag;;
467 pretag;;
429 Run before creating a tag. Exit status 0 allows the tag to be
468 Run before creating a tag. Exit status 0 allows the tag to be
430 created. Non-zero status will cause the tag to fail. ID of
469 created. Non-zero status will cause the tag to fail. ID of
431 changeset to tag is in $HG_NODE. Name of tag is in $HG_TAG. Tag
470 changeset to tag is in $HG_NODE. Name of tag is in $HG_TAG. Tag
432 is local if $HG_LOCAL=1, in repo if $HG_LOCAL=0.
471 is local if $HG_LOCAL=1, in repo if $HG_LOCAL=0.
433 pretxnchangegroup;;
472 pretxnchangegroup;;
434 Run after a changegroup has been added via push, pull or unbundle,
473 Run after a changegroup has been added via push, pull or unbundle,
435 but before the transaction has been committed. Changegroup is
474 but before the transaction has been committed. Changegroup is
436 visible to hook program. This lets you validate incoming changes
475 visible to hook program. This lets you validate incoming changes
437 before accepting them. Passed the ID of the first new changeset
476 before accepting them. Passed the ID of the first new changeset
438 in $HG_NODE. Exit status 0 allows the transaction to commit.
477 in $HG_NODE. Exit status 0 allows the transaction to commit.
439 Non-zero status will cause the transaction to be rolled back and
478 Non-zero status will cause the transaction to be rolled back and
440 the push, pull or unbundle will fail. URL that was source of
479 the push, pull or unbundle will fail. URL that was source of
441 changes is in $HG_URL.
480 changes is in $HG_URL.
442 pretxncommit;;
481 pretxncommit;;
443 Run after a changeset has been created but the transaction not yet
482 Run after a changeset has been created but the transaction not yet
444 committed. Changeset is visible to hook program. This lets you
483 committed. Changeset is visible to hook program. This lets you
445 validate commit message and changes. Exit status 0 allows the
484 validate commit message and changes. Exit status 0 allows the
446 commit to proceed. Non-zero status will cause the transaction to
485 commit to proceed. Non-zero status will cause the transaction to
447 be rolled back. ID of changeset is in $HG_NODE. Parent changeset
486 be rolled back. ID of changeset is in $HG_NODE. Parent changeset
448 IDs are in $HG_PARENT1 and $HG_PARENT2.
487 IDs are in $HG_PARENT1 and $HG_PARENT2.
449 preupdate;;
488 preupdate;;
450 Run before updating the working directory. Exit status 0 allows
489 Run before updating the working directory. Exit status 0 allows
451 the update to proceed. Non-zero status will prevent the update.
490 the update to proceed. Non-zero status will prevent the update.
452 Changeset ID of first new parent is in $HG_PARENT1. If merge, ID
491 Changeset ID of first new parent is in $HG_PARENT1. If merge, ID
453 of second new parent is in $HG_PARENT2.
492 of second new parent is in $HG_PARENT2.
454 tag;;
493 tag;;
455 Run after a tag is created. ID of tagged changeset is in
494 Run after a tag is created. ID of tagged changeset is in
456 $HG_NODE. Name of tag is in $HG_TAG. Tag is local if
495 $HG_NODE. Name of tag is in $HG_TAG. Tag is local if
457 $HG_LOCAL=1, in repo if $HG_LOCAL=0.
496 $HG_LOCAL=1, in repo if $HG_LOCAL=0.
458 update;;
497 update;;
459 Run after updating the working directory. Changeset ID of first
498 Run after updating the working directory. Changeset ID of first
460 new parent is in $HG_PARENT1. If merge, ID of second new parent
499 new parent is in $HG_PARENT1. If merge, ID of second new parent
461 is in $HG_PARENT2. If update succeeded, $HG_ERROR=0. If update
500 is in $HG_PARENT2. If update succeeded, $HG_ERROR=0. If update
462 failed (e.g. because conflicts not resolved), $HG_ERROR=1.
501 failed (e.g. because conflicts not resolved), $HG_ERROR=1.
463
502
464 Note: it is generally better to use standard hooks rather than the
503 Note: it is generally better to use standard hooks rather than the
465 generic pre- and post- command hooks as they are guaranteed to be
504 generic pre- and post- command hooks as they are guaranteed to be
466 called in the appropriate contexts for influencing transactions.
505 called in the appropriate contexts for influencing transactions.
467 Also, hooks like "commit" will be called in all contexts that
506 Also, hooks like "commit" will be called in all contexts that
468 generate a commit (eg. tag) and not just the commit command.
507 generate a commit (eg. tag) and not just the commit command.
469
508
470 Note2: Environment variables with empty values may not be passed to
509 Note2: Environment variables with empty values may not be passed to
471 hooks on platforms like Windows. For instance, $HG_PARENT2 will
510 hooks on platforms like Windows. For instance, $HG_PARENT2 will
472 not be available under Windows for non-merge changesets while being
511 not be available under Windows for non-merge changesets while being
473 set to an empty value under Unix-like systems.
512 set to an empty value under Unix-like systems.
474
513
475 The syntax for Python hooks is as follows:
514 The syntax for Python hooks is as follows:
476
515
477 hookname = python:modulename.submodule.callable
516 hookname = python:modulename.submodule.callable
478 hookname = python:/path/to/python/module.py:callable
517 hookname = python:/path/to/python/module.py:callable
479
518
480 Python hooks are run within the Mercurial process. Each hook is
519 Python hooks are run within the Mercurial process. Each hook is
481 called with at least three keyword arguments: a ui object (keyword
520 called with at least three keyword arguments: a ui object (keyword
482 "ui"), a repository object (keyword "repo"), and a "hooktype"
521 "ui"), a repository object (keyword "repo"), and a "hooktype"
483 keyword that tells what kind of hook is used. Arguments listed as
522 keyword that tells what kind of hook is used. Arguments listed as
484 environment variables above are passed as keyword arguments, with no
523 environment variables above are passed as keyword arguments, with no
485 "HG_" prefix, and names in lower case.
524 "HG_" prefix, and names in lower case.
486
525
487 If a Python hook returns a "true" value or raises an exception, this
526 If a Python hook returns a "true" value or raises an exception, this
488 is treated as failure of the hook.
527 is treated as failure of the hook.
489
528
490 [[http_proxy]]
529 [[http_proxy]]
491 http_proxy::
530 http_proxy::
492 Used to access web-based Mercurial repositories through a HTTP
531 Used to access web-based Mercurial repositories through a HTTP
493 proxy.
532 proxy.
494 host;;
533 host;;
495 Host name and (optional) port of the proxy server, for example
534 Host name and (optional) port of the proxy server, for example
496 "myproxy:8000".
535 "myproxy:8000".
497 no;;
536 no;;
498 Optional. Comma-separated list of host names that should bypass
537 Optional. Comma-separated list of host names that should bypass
499 the proxy.
538 the proxy.
500 passwd;;
539 passwd;;
501 Optional. Password to authenticate with at the proxy server.
540 Optional. Password to authenticate with at the proxy server.
502 user;;
541 user;;
503 Optional. User name to authenticate with at the proxy server.
542 Optional. User name to authenticate with at the proxy server.
504
543
505 [[smtp]]
544 [[smtp]]
506 smtp::
545 smtp::
507 Configuration for extensions that need to send email messages.
546 Configuration for extensions that need to send email messages.
508 host;;
547 host;;
509 Host name of mail server, e.g. "mail.example.com".
548 Host name of mail server, e.g. "mail.example.com".
510 port;;
549 port;;
511 Optional. Port to connect to on mail server. Default: 25.
550 Optional. Port to connect to on mail server. Default: 25.
512 tls;;
551 tls;;
513 Optional. Whether to connect to mail server using TLS. True or
552 Optional. Whether to connect to mail server using TLS. True or
514 False. Default: False.
553 False. Default: False.
515 username;;
554 username;;
516 Optional. User name to authenticate to SMTP server with.
555 Optional. User name to authenticate to SMTP server with.
517 If username is specified, password must also be specified.
556 If username is specified, password must also be specified.
518 Default: none.
557 Default: none.
519 password;;
558 password;;
520 Optional. Password to authenticate to SMTP server with.
559 Optional. Password to authenticate to SMTP server with.
521 If username is specified, password must also be specified.
560 If username is specified, password must also be specified.
522 Default: none.
561 Default: none.
523 local_hostname;;
562 local_hostname;;
524 Optional. It's the hostname that the sender can use to identify itself
563 Optional. It's the hostname that the sender can use to identify itself
525 to the MTA.
564 to the MTA.
526
565
527 [[paths]]
566 [[paths]]
528 paths::
567 paths::
529 Assigns symbolic names to repositories. The left side is the
568 Assigns symbolic names to repositories. The left side is the
530 symbolic name, and the right gives the directory or URL that is the
569 symbolic name, and the right gives the directory or URL that is the
531 location of the repository. Default paths can be declared by
570 location of the repository. Default paths can be declared by
532 setting the following entries.
571 setting the following entries.
533 default;;
572 default;;
534 Directory or URL to use when pulling if no source is specified.
573 Directory or URL to use when pulling if no source is specified.
535 Default is set to repository from which the current repository
574 Default is set to repository from which the current repository
536 was cloned.
575 was cloned.
537 default-push;;
576 default-push;;
538 Optional. Directory or URL to use when pushing if no destination
577 Optional. Directory or URL to use when pushing if no destination
539 is specified.
578 is specified.
540
579
541 [[profiling]]
580 [[profiling]]
542 profiling::
581 profiling::
543 Specifies profiling format and file output.
582 Specifies profiling format and file output.
544 In this section description, 'profiling data' stands for the raw data
583 In this section description, 'profiling data' stands for the raw data
545 collected during profiling, while 'profiling report' stands for a
584 collected during profiling, while 'profiling report' stands for a
546 statistical text report generated from the profiling data.
585 statistical text report generated from the profiling data.
547 The profiling is done using lsprof.
586 The profiling is done using lsprof.
548 format;;
587 format;;
549 Profiling format.
588 Profiling format.
550 Default: text.
589 Default: text.
551 text;;
590 text;;
552 Generate a profiling report.
591 Generate a profiling report.
553 When saving to a file, it should be noted that only the report is saved,
592 When saving to a file, it should be noted that only the report is saved,
554 and the profiling data is not kept.
593 and the profiling data is not kept.
555 kcachegrind;;
594 kcachegrind;;
556 Format profiling data for kcachegrind use:
595 Format profiling data for kcachegrind use:
557 when saving to a file, the generated file can directly be loaded
596 when saving to a file, the generated file can directly be loaded
558 into kcachegrind.
597 into kcachegrind.
559 output;;
598 output;;
560 File path where profiling data or report should be saved.
599 File path where profiling data or report should be saved.
561 If the file exists, it is replaced.
600 If the file exists, it is replaced.
562 Default: None, data is printed on stderr
601 Default: None, data is printed on stderr
563
602
564 [[server]]
603 [[server]]
565 server::
604 server::
566 Controls generic server settings.
605 Controls generic server settings.
567 uncompressed;;
606 uncompressed;;
568 Whether to allow clients to clone a repo using the uncompressed
607 Whether to allow clients to clone a repo using the uncompressed
569 streaming protocol. This transfers about 40% more data than a
608 streaming protocol. This transfers about 40% more data than a
570 regular clone, but uses less memory and CPU on both server and
609 regular clone, but uses less memory and CPU on both server and
571 client. Over a LAN (100Mbps or better) or a very fast WAN, an
610 client. Over a LAN (100Mbps or better) or a very fast WAN, an
572 uncompressed streaming clone is a lot faster (~10x) than a regular
611 uncompressed streaming clone is a lot faster (~10x) than a regular
573 clone. Over most WAN connections (anything slower than about
612 clone. Over most WAN connections (anything slower than about
574 6Mbps), uncompressed streaming is slower, because of the extra
613 6Mbps), uncompressed streaming is slower, because of the extra
575 data transfer overhead. Default is False.
614 data transfer overhead. Default is False.
576
615
577 [[trusted]]
616 [[trusted]]
578 trusted::
617 trusted::
579 For security reasons, Mercurial will not use the settings in
618 For security reasons, Mercurial will not use the settings in
580 the .hg/hgrc file from a repository if it doesn't belong to a
619 the .hg/hgrc file from a repository if it doesn't belong to a
581 trusted user or to a trusted group. The main exception is the
620 trusted user or to a trusted group. The main exception is the
582 web interface, which automatically uses some safe settings, since
621 web interface, which automatically uses some safe settings, since
583 it's common to serve repositories from different users.
622 it's common to serve repositories from different users.
584
623
585 This section specifies what users and groups are trusted. The
624 This section specifies what users and groups are trusted. The
586 current user is always trusted. To trust everybody, list a user
625 current user is always trusted. To trust everybody, list a user
587 or a group with name "*".
626 or a group with name "*".
588
627
589 users;;
628 users;;
590 Comma-separated list of trusted users.
629 Comma-separated list of trusted users.
591 groups;;
630 groups;;
592 Comma-separated list of trusted groups.
631 Comma-separated list of trusted groups.
593
632
594 [[ui]]
633 [[ui]]
595 ui::
634 ui::
596 User interface controls.
635 User interface controls.
597 archivemeta;;
636 archivemeta;;
598 Whether to include the .hg_archival.txt file containing metadata
637 Whether to include the .hg_archival.txt file containing metadata
599 (hashes for the repository base and for tip) in archives created by
638 (hashes for the repository base and for tip) in archives created by
600 the hg archive command or downloaded via hgweb.
639 the hg archive command or downloaded via hgweb.
601 Default is true.
640 Default is true.
602 askusername;;
641 askusername;;
603 Whether to prompt for a username when committing. If True, and
642 Whether to prompt for a username when committing. If True, and
604 neither $HGUSER nor $EMAIL has been specified, then the user will
643 neither $HGUSER nor $EMAIL has been specified, then the user will
605 be prompted to enter a username. If no username is entered, the
644 be prompted to enter a username. If no username is entered, the
606 default USER@HOST is used instead.
645 default USER@HOST is used instead.
607 Default is False.
646 Default is False.
608 debug;;
647 debug;;
609 Print debugging information. True or False. Default is False.
648 Print debugging information. True or False. Default is False.
610 editor;;
649 editor;;
611 The editor to use during a commit. Default is $EDITOR or "vi".
650 The editor to use during a commit. Default is $EDITOR or "vi".
612 fallbackencoding;;
651 fallbackencoding;;
613 Encoding to try if it's not possible to decode the changelog using
652 Encoding to try if it's not possible to decode the changelog using
614 UTF-8. Default is ISO-8859-1.
653 UTF-8. Default is ISO-8859-1.
615 ignore;;
654 ignore;;
616 A file to read per-user ignore patterns from. This file should be in
655 A file to read per-user ignore patterns from. This file should be in
617 the same format as a repository-wide .hgignore file. This option
656 the same format as a repository-wide .hgignore file. This option
618 supports hook syntax, so if you want to specify multiple ignore
657 supports hook syntax, so if you want to specify multiple ignore
619 files, you can do so by setting something like
658 files, you can do so by setting something like
620 "ignore.other = ~/.hgignore2". For details of the ignore file
659 "ignore.other = ~/.hgignore2". For details of the ignore file
621 format, see the hgignore(5) man page.
660 format, see the hgignore(5) man page.
622 interactive;;
661 interactive;;
623 Allow to prompt the user. True or False. Default is True.
662 Allow to prompt the user. True or False. Default is True.
624 logtemplate;;
663 logtemplate;;
625 Template string for commands that print changesets.
664 Template string for commands that print changesets.
626 merge;;
665 merge;;
627 The conflict resolution program to use during a manual merge.
666 The conflict resolution program to use during a manual merge.
628 There are some internal tools available:
667 There are some internal tools available:
629
668
630 internal:local;;
669 internal:local;;
631 keep the local version
670 keep the local version
632 internal:other;;
671 internal:other;;
633 use the other version
672 use the other version
634 internal:merge;;
673 internal:merge;;
635 use the internal non-interactive merge tool
674 use the internal non-interactive merge tool
636 internal:fail;;
675 internal:fail;;
637 fail to merge
676 fail to merge
638
677
639 See the merge-tools section for more information on configuring tools.
678 See the merge-tools section for more information on configuring tools.
640
679
641 patch;;
680 patch;;
642 command to use to apply patches. Look for 'gpatch' or 'patch' in PATH if
681 command to use to apply patches. Look for 'gpatch' or 'patch' in PATH if
643 unset.
682 unset.
644 quiet;;
683 quiet;;
645 Reduce the amount of output printed. True or False. Default is False.
684 Reduce the amount of output printed. True or False. Default is False.
646 remotecmd;;
685 remotecmd;;
647 remote command to use for clone/push/pull operations. Default is 'hg'.
686 remote command to use for clone/push/pull operations. Default is 'hg'.
648 report_untrusted;;
687 report_untrusted;;
649 Warn if a .hg/hgrc file is ignored due to not being owned by a
688 Warn if a .hg/hgrc file is ignored due to not being owned by a
650 trusted user or group. True or False. Default is True.
689 trusted user or group. True or False. Default is True.
651 slash;;
690 slash;;
652 Display paths using a slash ("/") as the path separator. This only
691 Display paths using a slash ("/") as the path separator. This only
653 makes a difference on systems where the default path separator is not
692 makes a difference on systems where the default path separator is not
654 the slash character (e.g. Windows uses the backslash character ("\")).
693 the slash character (e.g. Windows uses the backslash character ("\")).
655 Default is False.
694 Default is False.
656 ssh;;
695 ssh;;
657 command to use for SSH connections. Default is 'ssh'.
696 command to use for SSH connections. Default is 'ssh'.
658 strict;;
697 strict;;
659 Require exact command names, instead of allowing unambiguous
698 Require exact command names, instead of allowing unambiguous
660 abbreviations. True or False. Default is False.
699 abbreviations. True or False. Default is False.
661 style;;
700 style;;
662 Name of style to use for command output.
701 Name of style to use for command output.
663 timeout;;
702 timeout;;
664 The timeout used when a lock is held (in seconds), a negative value
703 The timeout used when a lock is held (in seconds), a negative value
665 means no timeout. Default is 600.
704 means no timeout. Default is 600.
666 username;;
705 username;;
667 The committer of a changeset created when running "commit".
706 The committer of a changeset created when running "commit".
668 Typically a person's name and email address, e.g. "Fred Widget
707 Typically a person's name and email address, e.g. "Fred Widget
669 <fred@example.com>". Default is $EMAIL or username@hostname.
708 <fred@example.com>". Default is $EMAIL or username@hostname.
670 If the username in hgrc is empty, it has to be specified manually or
709 If the username in hgrc is empty, it has to be specified manually or
671 in a different hgrc file (e.g. $HOME/.hgrc, if the admin set "username ="
710 in a different hgrc file (e.g. $HOME/.hgrc, if the admin set "username ="
672 in the system hgrc).
711 in the system hgrc).
673 verbose;;
712 verbose;;
674 Increase the amount of output printed. True or False. Default is False.
713 Increase the amount of output printed. True or False. Default is False.
675
714
676
715
677 [[web]]
716 [[web]]
678 web::
717 web::
679 Web interface configuration.
718 Web interface configuration.
680 accesslog;;
719 accesslog;;
681 Where to output the access log. Default is stdout.
720 Where to output the access log. Default is stdout.
682 address;;
721 address;;
683 Interface address to bind to. Default is all.
722 Interface address to bind to. Default is all.
684 allow_archive;;
723 allow_archive;;
685 List of archive format (bz2, gz, zip) allowed for downloading.
724 List of archive format (bz2, gz, zip) allowed for downloading.
686 Default is empty.
725 Default is empty.
687 allowbz2;;
726 allowbz2;;
688 (DEPRECATED) Whether to allow .tar.bz2 downloading of repo revisions.
727 (DEPRECATED) Whether to allow .tar.bz2 downloading of repo revisions.
689 Default is false.
728 Default is false.
690 allowgz;;
729 allowgz;;
691 (DEPRECATED) Whether to allow .tar.gz downloading of repo revisions.
730 (DEPRECATED) Whether to allow .tar.gz downloading of repo revisions.
692 Default is false.
731 Default is false.
693 allowpull;;
732 allowpull;;
694 Whether to allow pulling from the repository. Default is true.
733 Whether to allow pulling from the repository. Default is true.
695 allow_push;;
734 allow_push;;
696 Whether to allow pushing to the repository. If empty or not set,
735 Whether to allow pushing to the repository. If empty or not set,
697 push is not allowed. If the special value "*", any remote user
736 push is not allowed. If the special value "*", any remote user
698 can push, including unauthenticated users. Otherwise, the remote
737 can push, including unauthenticated users. Otherwise, the remote
699 user must have been authenticated, and the authenticated user name
738 user must have been authenticated, and the authenticated user name
700 must be present in this list (separated by whitespace or ",").
739 must be present in this list (separated by whitespace or ",").
701 The contents of the allow_push list are examined after the
740 The contents of the allow_push list are examined after the
702 deny_push list.
741 deny_push list.
703 allow_read;;
742 allow_read;;
704 If the user has not already been denied repository access due to the
743 If the user has not already been denied repository access due to the
705 contents of deny_read, this list determines whether to grant repository
744 contents of deny_read, this list determines whether to grant repository
706 access to the user. If this list is not empty, and the user is
745 access to the user. If this list is not empty, and the user is
707 unauthenticated or not present in the list (separated by whitespace or ","),
746 unauthenticated or not present in the list (separated by whitespace or ","),
708 then access is denied for the user. If the list is empty or not set, then
747 then access is denied for the user. If the list is empty or not set, then
709 access is permitted to all users by default. Setting allow_read to the
748 access is permitted to all users by default. Setting allow_read to the
710 special value "*" is equivalent to it not being set (i.e. access is
749 special value "*" is equivalent to it not being set (i.e. access is
711 permitted to all users). The contents of the allow_read list are examined
750 permitted to all users). The contents of the allow_read list are examined
712 after the deny_read list.
751 after the deny_read list.
713 allowzip;;
752 allowzip;;
714 (DEPRECATED) Whether to allow .zip downloading of repo revisions.
753 (DEPRECATED) Whether to allow .zip downloading of repo revisions.
715 Default is false. This feature creates temporary files.
754 Default is false. This feature creates temporary files.
716 baseurl;;
755 baseurl;;
717 Base URL to use when publishing URLs in other locations, so
756 Base URL to use when publishing URLs in other locations, so
718 third-party tools like email notification hooks can construct URLs.
757 third-party tools like email notification hooks can construct URLs.
719 Example: "http://hgserver/repos/"
758 Example: "http://hgserver/repos/"
720 contact;;
759 contact;;
721 Name or email address of the person in charge of the repository.
760 Name or email address of the person in charge of the repository.
722 Defaults to ui.username or $EMAIL or "unknown" if unset or empty.
761 Defaults to ui.username or $EMAIL or "unknown" if unset or empty.
723 deny_push;;
762 deny_push;;
724 Whether to deny pushing to the repository. If empty or not set,
763 Whether to deny pushing to the repository. If empty or not set,
725 push is not denied. If the special value "*", all remote users
764 push is not denied. If the special value "*", all remote users
726 are denied push. Otherwise, unauthenticated users are all denied,
765 are denied push. Otherwise, unauthenticated users are all denied,
727 and any authenticated user name present in this list (separated by
766 and any authenticated user name present in this list (separated by
728 whitespace or ",") is also denied. The contents of the deny_push
767 whitespace or ",") is also denied. The contents of the deny_push
729 list are examined before the allow_push list.
768 list are examined before the allow_push list.
730 deny_read;;
769 deny_read;;
731 Whether to deny reading/viewing of the repository. If this list is not
770 Whether to deny reading/viewing of the repository. If this list is not
732 empty, unauthenticated users are all denied, and any authenticated user name
771 empty, unauthenticated users are all denied, and any authenticated user name
733 present in this list (separated by whitespace or ",") is also denied access
772 present in this list (separated by whitespace or ",") is also denied access
734 to the repository. If set to the special value "*", all remote users are
773 to the repository. If set to the special value "*", all remote users are
735 denied access (rarely needed ;). If deny_read is empty or not set, the
774 denied access (rarely needed ;). If deny_read is empty or not set, the
736 determination of repository access depends on the presence and content of
775 determination of repository access depends on the presence and content of
737 the allow_read list (see description). If both deny_read and allow_read are
776 the allow_read list (see description). If both deny_read and allow_read are
738 empty or not set, then access is permitted to all users by default. If the
777 empty or not set, then access is permitted to all users by default. If the
739 repository is being served via hgwebdir, denied users will not be able to
778 repository is being served via hgwebdir, denied users will not be able to
740 see it in the list of repositories. The contents of the deny_read list have
779 see it in the list of repositories. The contents of the deny_read list have
741 priority over (are examined before) the contents of the allow_read list.
780 priority over (are examined before) the contents of the allow_read list.
742 description;;
781 description;;
743 Textual description of the repository's purpose or contents.
782 Textual description of the repository's purpose or contents.
744 Default is "unknown".
783 Default is "unknown".
745 encoding;;
784 encoding;;
746 Character encoding name.
785 Character encoding name.
747 Example: "UTF-8"
786 Example: "UTF-8"
748 errorlog;;
787 errorlog;;
749 Where to output the error log. Default is stderr.
788 Where to output the error log. Default is stderr.
750 hidden;;
789 hidden;;
751 Whether to hide the repository in the hgwebdir index. Default is false.
790 Whether to hide the repository in the hgwebdir index. Default is false.
752 ipv6;;
791 ipv6;;
753 Whether to use IPv6. Default is false.
792 Whether to use IPv6. Default is false.
754 name;;
793 name;;
755 Repository name to use in the web interface. Default is current
794 Repository name to use in the web interface. Default is current
756 working directory.
795 working directory.
757 maxchanges;;
796 maxchanges;;
758 Maximum number of changes to list on the changelog. Default is 10.
797 Maximum number of changes to list on the changelog. Default is 10.
759 maxfiles;;
798 maxfiles;;
760 Maximum number of files to list per changeset. Default is 10.
799 Maximum number of files to list per changeset. Default is 10.
761 port;;
800 port;;
762 Port to listen on. Default is 8000.
801 Port to listen on. Default is 8000.
763 prefix;;
802 prefix;;
764 Prefix path to serve from. Default is '' (server root).
803 Prefix path to serve from. Default is '' (server root).
765 push_ssl;;
804 push_ssl;;
766 Whether to require that inbound pushes be transported over SSL to
805 Whether to require that inbound pushes be transported over SSL to
767 prevent password sniffing. Default is true.
806 prevent password sniffing. Default is true.
768 staticurl;;
807 staticurl;;
769 Base URL to use for static files. If unset, static files (e.g.
808 Base URL to use for static files. If unset, static files (e.g.
770 the hgicon.png favicon) will be served by the CGI script itself.
809 the hgicon.png favicon) will be served by the CGI script itself.
771 Use this setting to serve them directly with the HTTP server.
810 Use this setting to serve them directly with the HTTP server.
772 Example: "http://hgserver/static/"
811 Example: "http://hgserver/static/"
773 stripes;;
812 stripes;;
774 How many lines a "zebra stripe" should span in multiline output.
813 How many lines a "zebra stripe" should span in multiline output.
775 Default is 1; set to 0 to disable.
814 Default is 1; set to 0 to disable.
776 style;;
815 style;;
777 Which template map style to use.
816 Which template map style to use.
778 templates;;
817 templates;;
779 Where to find the HTML templates. Default is install path.
818 Where to find the HTML templates. Default is install path.
780
819
781
820
782 AUTHOR
821 AUTHOR
783 ------
822 ------
784 Bryan O'Sullivan <bos@serpentine.com>.
823 Bryan O'Sullivan <bos@serpentine.com>.
785
824
786 Mercurial was written by Matt Mackall <mpm@selenic.com>.
825 Mercurial was written by Matt Mackall <mpm@selenic.com>.
787
826
788 SEE ALSO
827 SEE ALSO
789 --------
828 --------
790 hg(1), hgignore(5)
829 hg(1), hgignore(5)
791
830
792 COPYING
831 COPYING
793 -------
832 -------
794 This manual page is copyright 2005 Bryan O'Sullivan.
833 This manual page is copyright 2005 Bryan O'Sullivan.
795 Mercurial is copyright 2005-2007 Matt Mackall.
834 Mercurial is copyright 2005-2007 Matt Mackall.
796 Free use of this software is granted under the terms of the GNU General
835 Free use of this software is granted under the terms of the GNU General
797 Public License (GPL).
836 Public License (GPL).
@@ -1,314 +1,348 b''
1 # url.py - HTTP handling for mercurial
1 # url.py - HTTP handling for mercurial
2 #
2 #
3 # Copyright 2005, 2006, 2007, 2008 Matt Mackall <mpm@selenic.com>
3 # Copyright 2005, 2006, 2007, 2008 Matt Mackall <mpm@selenic.com>
4 # Copyright 2006, 2007 Alexis S. L. Carvalho <alexis@cecm.usp.br>
4 # Copyright 2006, 2007 Alexis S. L. Carvalho <alexis@cecm.usp.br>
5 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
5 # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
6 #
6 #
7 # This software may be used and distributed according to the terms of the
7 # This software may be used and distributed according to the terms of the
8 # GNU General Public License version 2, incorporated herein by reference.
8 # GNU General Public License version 2, incorporated herein by reference.
9
9
10 import urllib, urllib2, urlparse, httplib, os, re
10 import urllib, urllib2, urlparse, httplib, os, re
11 from i18n import _
11 from i18n import _
12 import keepalive, util
12 import keepalive, util
13
13
14 def hidepassword(url):
14 def hidepassword(url):
15 '''hide user credential in a url string'''
15 '''hide user credential in a url string'''
16 scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
16 scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
17 netloc = re.sub('([^:]*):([^@]*)@(.*)', r'\1:***@\3', netloc)
17 netloc = re.sub('([^:]*):([^@]*)@(.*)', r'\1:***@\3', netloc)
18 return urlparse.urlunparse((scheme, netloc, path, params, query, fragment))
18 return urlparse.urlunparse((scheme, netloc, path, params, query, fragment))
19
19
20 def removeauth(url):
20 def removeauth(url):
21 '''remove all authentication information from a url string'''
21 '''remove all authentication information from a url string'''
22 scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
22 scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
23 netloc = netloc[netloc.find('@')+1:]
23 netloc = netloc[netloc.find('@')+1:]
24 return urlparse.urlunparse((scheme, netloc, path, params, query, fragment))
24 return urlparse.urlunparse((scheme, netloc, path, params, query, fragment))
25
25
26 def netlocsplit(netloc):
26 def netlocsplit(netloc):
27 '''split [user[:passwd]@]host[:port] into 4-tuple.'''
27 '''split [user[:passwd]@]host[:port] into 4-tuple.'''
28
28
29 a = netloc.find('@')
29 a = netloc.find('@')
30 if a == -1:
30 if a == -1:
31 user, passwd = None, None
31 user, passwd = None, None
32 else:
32 else:
33 userpass, netloc = netloc[:a], netloc[a+1:]
33 userpass, netloc = netloc[:a], netloc[a+1:]
34 c = userpass.find(':')
34 c = userpass.find(':')
35 if c == -1:
35 if c == -1:
36 user, passwd = urllib.unquote(userpass), None
36 user, passwd = urllib.unquote(userpass), None
37 else:
37 else:
38 user = urllib.unquote(userpass[:c])
38 user = urllib.unquote(userpass[:c])
39 passwd = urllib.unquote(userpass[c+1:])
39 passwd = urllib.unquote(userpass[c+1:])
40 c = netloc.find(':')
40 c = netloc.find(':')
41 if c == -1:
41 if c == -1:
42 host, port = netloc, None
42 host, port = netloc, None
43 else:
43 else:
44 host, port = netloc[:c], netloc[c+1:]
44 host, port = netloc[:c], netloc[c+1:]
45 return host, port, user, passwd
45 return host, port, user, passwd
46
46
47 def netlocunsplit(host, port, user=None, passwd=None):
47 def netlocunsplit(host, port, user=None, passwd=None):
48 '''turn host, port, user, passwd into [user[:passwd]@]host[:port].'''
48 '''turn host, port, user, passwd into [user[:passwd]@]host[:port].'''
49 if port:
49 if port:
50 hostport = host + ':' + port
50 hostport = host + ':' + port
51 else:
51 else:
52 hostport = host
52 hostport = host
53 if user:
53 if user:
54 if passwd:
54 if passwd:
55 userpass = urllib.quote(user) + ':' + urllib.quote(passwd)
55 userpass = urllib.quote(user) + ':' + urllib.quote(passwd)
56 else:
56 else:
57 userpass = urllib.quote(user)
57 userpass = urllib.quote(user)
58 return userpass + '@' + hostport
58 return userpass + '@' + hostport
59 return hostport
59 return hostport
60
60
61 _safe = ('abcdefghijklmnopqrstuvwxyz'
61 _safe = ('abcdefghijklmnopqrstuvwxyz'
62 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
62 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
63 '0123456789' '_.-/')
63 '0123456789' '_.-/')
64 _safeset = None
64 _safeset = None
65 _hex = None
65 _hex = None
66 def quotepath(path):
66 def quotepath(path):
67 '''quote the path part of a URL
67 '''quote the path part of a URL
68
68
69 This is similar to urllib.quote, but it also tries to avoid
69 This is similar to urllib.quote, but it also tries to avoid
70 quoting things twice (inspired by wget):
70 quoting things twice (inspired by wget):
71
71
72 >>> quotepath('abc def')
72 >>> quotepath('abc def')
73 'abc%20def'
73 'abc%20def'
74 >>> quotepath('abc%20def')
74 >>> quotepath('abc%20def')
75 'abc%20def'
75 'abc%20def'
76 >>> quotepath('abc%20 def')
76 >>> quotepath('abc%20 def')
77 'abc%20%20def'
77 'abc%20%20def'
78 >>> quotepath('abc def%20')
78 >>> quotepath('abc def%20')
79 'abc%20def%20'
79 'abc%20def%20'
80 >>> quotepath('abc def%2')
80 >>> quotepath('abc def%2')
81 'abc%20def%252'
81 'abc%20def%252'
82 >>> quotepath('abc def%')
82 >>> quotepath('abc def%')
83 'abc%20def%25'
83 'abc%20def%25'
84 '''
84 '''
85 global _safeset, _hex
85 global _safeset, _hex
86 if _safeset is None:
86 if _safeset is None:
87 _safeset = set(_safe)
87 _safeset = set(_safe)
88 _hex = set('abcdefABCDEF0123456789')
88 _hex = set('abcdefABCDEF0123456789')
89 l = list(path)
89 l = list(path)
90 for i in xrange(len(l)):
90 for i in xrange(len(l)):
91 c = l[i]
91 c = l[i]
92 if c == '%' and i + 2 < len(l) and (l[i+1] in _hex and l[i+2] in _hex):
92 if c == '%' and i + 2 < len(l) and (l[i+1] in _hex and l[i+2] in _hex):
93 pass
93 pass
94 elif c not in _safeset:
94 elif c not in _safeset:
95 l[i] = '%%%02X' % ord(c)
95 l[i] = '%%%02X' % ord(c)
96 return ''.join(l)
96 return ''.join(l)
97
97
98 class passwordmgr(urllib2.HTTPPasswordMgrWithDefaultRealm):
98 class passwordmgr(urllib2.HTTPPasswordMgrWithDefaultRealm):
99 def __init__(self, ui):
99 def __init__(self, ui):
100 urllib2.HTTPPasswordMgrWithDefaultRealm.__init__(self)
100 urllib2.HTTPPasswordMgrWithDefaultRealm.__init__(self)
101 self.ui = ui
101 self.ui = ui
102
102
103 def find_user_password(self, realm, authuri):
103 def find_user_password(self, realm, authuri):
104 authinfo = urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password(
104 authinfo = urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password(
105 self, realm, authuri)
105 self, realm, authuri)
106 user, passwd = authinfo
106 user, passwd = authinfo
107 if user and passwd:
107 if user and passwd:
108 self._writedebug(user, passwd)
108 return (user, passwd)
109 return (user, passwd)
109
110
110 if not self.ui.interactive():
111 user, passwd = self._readauthtoken(authuri)
111 raise util.Abort(_('http authorization required'))
112 if not user or not passwd:
113 if not self.ui.interactive():
114 raise util.Abort(_('http authorization required'))
112
115
113 self.ui.write(_("http authorization required\n"))
116 self.ui.write(_("http authorization required\n"))
114 self.ui.status(_("realm: %s\n") % realm)
117 self.ui.status(_("realm: %s\n") % realm)
115 if user:
118 if user:
116 self.ui.status(_("user: %s\n") % user)
119 self.ui.status(_("user: %s\n") % user)
117 else:
120 else:
118 user = self.ui.prompt(_("user:"), default=None)
121 user = self.ui.prompt(_("user:"), default=None)
119
122
120 if not passwd:
123 if not passwd:
121 passwd = self.ui.getpass()
124 passwd = self.ui.getpass()
122
125
123 self.add_password(realm, authuri, user, passwd)
126 self.add_password(realm, authuri, user, passwd)
127 self._writedebug(user, passwd)
124 return (user, passwd)
128 return (user, passwd)
125
129
130 def _writedebug(self, user, passwd):
131 msg = _('http auth: user %s, password %s\n')
132 self.ui.debug(msg % (user, passwd and '*' * len(passwd) or 'not set'))
133
134 def _readauthtoken(self, uri):
135 # Read configuration
136 config = dict()
137 for key, val in self.ui.configitems('auth'):
138 group, setting = key.split('.', 1)
139 gdict = config.setdefault(group, dict())
140 gdict[setting] = val
141
142 # Find the best match
143 scheme, hostpath = uri.split('://', 1)
144 bestlen = 0
145 bestauth = None, None
146 for auth in config.itervalues():
147 prefix = auth.get('prefix')
148 if not prefix: continue
149 p = prefix.split('://', 1)
150 if len(p) > 1:
151 schemes, prefix = [p[0]], p[1]
152 else:
153 schemes = (auth.get('schemes') or 'https').split()
154 if (prefix == '*' or hostpath.startswith(prefix)) and \
155 len(prefix) > bestlen and scheme in schemes:
156 bestlen = len(prefix)
157 bestauth = auth.get('username'), auth.get('password')
158 return bestauth
159
126 class proxyhandler(urllib2.ProxyHandler):
160 class proxyhandler(urllib2.ProxyHandler):
127 def __init__(self, ui):
161 def __init__(self, ui):
128 proxyurl = ui.config("http_proxy", "host") or os.getenv('http_proxy')
162 proxyurl = ui.config("http_proxy", "host") or os.getenv('http_proxy')
129 # XXX proxyauthinfo = None
163 # XXX proxyauthinfo = None
130
164
131 if proxyurl:
165 if proxyurl:
132 # proxy can be proper url or host[:port]
166 # proxy can be proper url or host[:port]
133 if not (proxyurl.startswith('http:') or
167 if not (proxyurl.startswith('http:') or
134 proxyurl.startswith('https:')):
168 proxyurl.startswith('https:')):
135 proxyurl = 'http://' + proxyurl + '/'
169 proxyurl = 'http://' + proxyurl + '/'
136 snpqf = urlparse.urlsplit(proxyurl)
170 snpqf = urlparse.urlsplit(proxyurl)
137 proxyscheme, proxynetloc, proxypath, proxyquery, proxyfrag = snpqf
171 proxyscheme, proxynetloc, proxypath, proxyquery, proxyfrag = snpqf
138 hpup = netlocsplit(proxynetloc)
172 hpup = netlocsplit(proxynetloc)
139
173
140 proxyhost, proxyport, proxyuser, proxypasswd = hpup
174 proxyhost, proxyport, proxyuser, proxypasswd = hpup
141 if not proxyuser:
175 if not proxyuser:
142 proxyuser = ui.config("http_proxy", "user")
176 proxyuser = ui.config("http_proxy", "user")
143 proxypasswd = ui.config("http_proxy", "passwd")
177 proxypasswd = ui.config("http_proxy", "passwd")
144
178
145 # see if we should use a proxy for this url
179 # see if we should use a proxy for this url
146 no_list = [ "localhost", "127.0.0.1" ]
180 no_list = [ "localhost", "127.0.0.1" ]
147 no_list.extend([p.lower() for
181 no_list.extend([p.lower() for
148 p in ui.configlist("http_proxy", "no")])
182 p in ui.configlist("http_proxy", "no")])
149 no_list.extend([p.strip().lower() for
183 no_list.extend([p.strip().lower() for
150 p in os.getenv("no_proxy", '').split(',')
184 p in os.getenv("no_proxy", '').split(',')
151 if p.strip()])
185 if p.strip()])
152 # "http_proxy.always" config is for running tests on localhost
186 # "http_proxy.always" config is for running tests on localhost
153 if ui.configbool("http_proxy", "always"):
187 if ui.configbool("http_proxy", "always"):
154 self.no_list = []
188 self.no_list = []
155 else:
189 else:
156 self.no_list = no_list
190 self.no_list = no_list
157
191
158 proxyurl = urlparse.urlunsplit((
192 proxyurl = urlparse.urlunsplit((
159 proxyscheme, netlocunsplit(proxyhost, proxyport,
193 proxyscheme, netlocunsplit(proxyhost, proxyport,
160 proxyuser, proxypasswd or ''),
194 proxyuser, proxypasswd or ''),
161 proxypath, proxyquery, proxyfrag))
195 proxypath, proxyquery, proxyfrag))
162 proxies = {'http': proxyurl, 'https': proxyurl}
196 proxies = {'http': proxyurl, 'https': proxyurl}
163 ui.debug(_('proxying through http://%s:%s\n') %
197 ui.debug(_('proxying through http://%s:%s\n') %
164 (proxyhost, proxyport))
198 (proxyhost, proxyport))
165 else:
199 else:
166 proxies = {}
200 proxies = {}
167
201
168 # urllib2 takes proxy values from the environment and those
202 # urllib2 takes proxy values from the environment and those
169 # will take precedence if found, so drop them
203 # will take precedence if found, so drop them
170 for env in ["HTTP_PROXY", "http_proxy", "no_proxy"]:
204 for env in ["HTTP_PROXY", "http_proxy", "no_proxy"]:
171 try:
205 try:
172 if env in os.environ:
206 if env in os.environ:
173 del os.environ[env]
207 del os.environ[env]
174 except OSError:
208 except OSError:
175 pass
209 pass
176
210
177 urllib2.ProxyHandler.__init__(self, proxies)
211 urllib2.ProxyHandler.__init__(self, proxies)
178 self.ui = ui
212 self.ui = ui
179
213
180 def proxy_open(self, req, proxy, type_):
214 def proxy_open(self, req, proxy, type_):
181 host = req.get_host().split(':')[0]
215 host = req.get_host().split(':')[0]
182 if host in self.no_list:
216 if host in self.no_list:
183 return None
217 return None
184
218
185 # work around a bug in Python < 2.4.2
219 # work around a bug in Python < 2.4.2
186 # (it leaves a "\n" at the end of Proxy-authorization headers)
220 # (it leaves a "\n" at the end of Proxy-authorization headers)
187 baseclass = req.__class__
221 baseclass = req.__class__
188 class _request(baseclass):
222 class _request(baseclass):
189 def add_header(self, key, val):
223 def add_header(self, key, val):
190 if key.lower() == 'proxy-authorization':
224 if key.lower() == 'proxy-authorization':
191 val = val.strip()
225 val = val.strip()
192 return baseclass.add_header(self, key, val)
226 return baseclass.add_header(self, key, val)
193 req.__class__ = _request
227 req.__class__ = _request
194
228
195 return urllib2.ProxyHandler.proxy_open(self, req, proxy, type_)
229 return urllib2.ProxyHandler.proxy_open(self, req, proxy, type_)
196
230
197 class httpsendfile(file):
231 class httpsendfile(file):
198 def __len__(self):
232 def __len__(self):
199 return os.fstat(self.fileno()).st_size
233 return os.fstat(self.fileno()).st_size
200
234
201 def _gen_sendfile(connection):
235 def _gen_sendfile(connection):
202 def _sendfile(self, data):
236 def _sendfile(self, data):
203 # send a file
237 # send a file
204 if isinstance(data, httpsendfile):
238 if isinstance(data, httpsendfile):
205 # if auth required, some data sent twice, so rewind here
239 # if auth required, some data sent twice, so rewind here
206 data.seek(0)
240 data.seek(0)
207 for chunk in util.filechunkiter(data):
241 for chunk in util.filechunkiter(data):
208 connection.send(self, chunk)
242 connection.send(self, chunk)
209 else:
243 else:
210 connection.send(self, data)
244 connection.send(self, data)
211 return _sendfile
245 return _sendfile
212
246
213 class httpconnection(keepalive.HTTPConnection):
247 class httpconnection(keepalive.HTTPConnection):
214 # must be able to send big bundle as stream.
248 # must be able to send big bundle as stream.
215 send = _gen_sendfile(keepalive.HTTPConnection)
249 send = _gen_sendfile(keepalive.HTTPConnection)
216
250
217 class httphandler(keepalive.HTTPHandler):
251 class httphandler(keepalive.HTTPHandler):
218 def http_open(self, req):
252 def http_open(self, req):
219 return self.do_open(httpconnection, req)
253 return self.do_open(httpconnection, req)
220
254
221 def __del__(self):
255 def __del__(self):
222 self.close_all()
256 self.close_all()
223
257
224 has_https = hasattr(urllib2, 'HTTPSHandler')
258 has_https = hasattr(urllib2, 'HTTPSHandler')
225 if has_https:
259 if has_https:
226 class httpsconnection(httplib.HTTPSConnection):
260 class httpsconnection(httplib.HTTPSConnection):
227 response_class = keepalive.HTTPResponse
261 response_class = keepalive.HTTPResponse
228 # must be able to send big bundle as stream.
262 # must be able to send big bundle as stream.
229 send = _gen_sendfile(httplib.HTTPSConnection)
263 send = _gen_sendfile(httplib.HTTPSConnection)
230
264
231 class httpshandler(keepalive.KeepAliveHandler, urllib2.HTTPSHandler):
265 class httpshandler(keepalive.KeepAliveHandler, urllib2.HTTPSHandler):
232 def https_open(self, req):
266 def https_open(self, req):
233 return self.do_open(httpsconnection, req)
267 return self.do_open(httpsconnection, req)
234
268
235 # In python < 2.5 AbstractDigestAuthHandler raises a ValueError if
269 # In python < 2.5 AbstractDigestAuthHandler raises a ValueError if
236 # it doesn't know about the auth type requested. This can happen if
270 # it doesn't know about the auth type requested. This can happen if
237 # somebody is using BasicAuth and types a bad password.
271 # somebody is using BasicAuth and types a bad password.
238 class httpdigestauthhandler(urllib2.HTTPDigestAuthHandler):
272 class httpdigestauthhandler(urllib2.HTTPDigestAuthHandler):
239 def http_error_auth_reqed(self, auth_header, host, req, headers):
273 def http_error_auth_reqed(self, auth_header, host, req, headers):
240 try:
274 try:
241 return urllib2.HTTPDigestAuthHandler.http_error_auth_reqed(
275 return urllib2.HTTPDigestAuthHandler.http_error_auth_reqed(
242 self, auth_header, host, req, headers)
276 self, auth_header, host, req, headers)
243 except ValueError, inst:
277 except ValueError, inst:
244 arg = inst.args[0]
278 arg = inst.args[0]
245 if arg.startswith("AbstractDigestAuthHandler doesn't know "):
279 if arg.startswith("AbstractDigestAuthHandler doesn't know "):
246 return
280 return
247 raise
281 raise
248
282
249 def getauthinfo(path):
283 def getauthinfo(path):
250 scheme, netloc, urlpath, query, frag = urlparse.urlsplit(path)
284 scheme, netloc, urlpath, query, frag = urlparse.urlsplit(path)
251 if not urlpath:
285 if not urlpath:
252 urlpath = '/'
286 urlpath = '/'
253 if scheme != 'file':
287 if scheme != 'file':
254 # XXX: why are we quoting the path again with some smart
288 # XXX: why are we quoting the path again with some smart
255 # heuristic here? Anyway, it cannot be done with file://
289 # heuristic here? Anyway, it cannot be done with file://
256 # urls since path encoding is os/fs dependent (see
290 # urls since path encoding is os/fs dependent (see
257 # urllib.pathname2url() for details).
291 # urllib.pathname2url() for details).
258 urlpath = quotepath(urlpath)
292 urlpath = quotepath(urlpath)
259 host, port, user, passwd = netlocsplit(netloc)
293 host, port, user, passwd = netlocsplit(netloc)
260
294
261 # urllib cannot handle URLs with embedded user or passwd
295 # urllib cannot handle URLs with embedded user or passwd
262 url = urlparse.urlunsplit((scheme, netlocunsplit(host, port),
296 url = urlparse.urlunsplit((scheme, netlocunsplit(host, port),
263 urlpath, query, frag))
297 urlpath, query, frag))
264 if user:
298 if user:
265 netloc = host
299 netloc = host
266 if port:
300 if port:
267 netloc += ':' + port
301 netloc += ':' + port
268 # Python < 2.4.3 uses only the netloc to search for a password
302 # Python < 2.4.3 uses only the netloc to search for a password
269 authinfo = (None, (url, netloc), user, passwd or '')
303 authinfo = (None, (url, netloc), user, passwd or '')
270 else:
304 else:
271 authinfo = None
305 authinfo = None
272 return url, authinfo
306 return url, authinfo
273
307
274 def opener(ui, authinfo=None):
308 def opener(ui, authinfo=None):
275 '''
309 '''
276 construct an opener suitable for urllib2
310 construct an opener suitable for urllib2
277 authinfo will be added to the password manager
311 authinfo will be added to the password manager
278 '''
312 '''
279 handlers = [httphandler()]
313 handlers = [httphandler()]
280 if has_https:
314 if has_https:
281 handlers.append(httpshandler())
315 handlers.append(httpshandler())
282
316
283 handlers.append(proxyhandler(ui))
317 handlers.append(proxyhandler(ui))
284
318
285 passmgr = passwordmgr(ui)
319 passmgr = passwordmgr(ui)
286 if authinfo is not None:
320 if authinfo is not None:
287 passmgr.add_password(*authinfo)
321 passmgr.add_password(*authinfo)
288 user, passwd = authinfo[2:4]
322 user, passwd = authinfo[2:4]
289 ui.debug(_('http auth: user %s, password %s\n') %
323 ui.debug(_('http auth: user %s, password %s\n') %
290 (user, passwd and '*' * len(passwd) or 'not set'))
324 (user, passwd and '*' * len(passwd) or 'not set'))
291
325
292 handlers.extend((urllib2.HTTPBasicAuthHandler(passmgr),
326 handlers.extend((urllib2.HTTPBasicAuthHandler(passmgr),
293 httpdigestauthhandler(passmgr)))
327 httpdigestauthhandler(passmgr)))
294 opener = urllib2.build_opener(*handlers)
328 opener = urllib2.build_opener(*handlers)
295
329
296 # 1.0 here is the _protocol_ version
330 # 1.0 here is the _protocol_ version
297 opener.addheaders = [('User-agent', 'mercurial/proto-1.0')]
331 opener.addheaders = [('User-agent', 'mercurial/proto-1.0')]
298 opener.addheaders.append(('Accept', 'application/mercurial-0.1'))
332 opener.addheaders.append(('Accept', 'application/mercurial-0.1'))
299 return opener
333 return opener
300
334
301 scheme_re = re.compile(r'^([a-zA-Z0-9+-.]+)://')
335 scheme_re = re.compile(r'^([a-zA-Z0-9+-.]+)://')
302
336
303 def open(ui, url, data=None):
337 def open(ui, url, data=None):
304 scheme = None
338 scheme = None
305 m = scheme_re.search(url)
339 m = scheme_re.search(url)
306 if m:
340 if m:
307 scheme = m.group(1).lower()
341 scheme = m.group(1).lower()
308 if not scheme:
342 if not scheme:
309 path = util.normpath(os.path.abspath(url))
343 path = util.normpath(os.path.abspath(url))
310 url = 'file://' + urllib.pathname2url(path)
344 url = 'file://' + urllib.pathname2url(path)
311 authinfo = None
345 authinfo = None
312 else:
346 else:
313 url, authinfo = getauthinfo(url)
347 url, authinfo = getauthinfo(url)
314 return opener(ui, authinfo).open(url, data)
348 return opener(ui, authinfo).open(url, data)
General Comments 0
You need to be logged in to leave comments. Login now