##// END OF EJS Templates
Commit username: Better error message, abort on empty name, fix documentation.
Thomas Arendsen Hein -
r3489:c3345b0f default
parent child Browse files
Show More
@@ -1,495 +1,495 b''
1 1 HGRC(5)
2 2 =======
3 3 Bryan O'Sullivan <bos@serpentine.com>
4 4
5 5 NAME
6 6 ----
7 7 hgrc - configuration files for Mercurial
8 8
9 9 SYNOPSIS
10 10 --------
11 11
12 12 The Mercurial system uses a set of configuration files to control
13 13 aspects of its behaviour.
14 14
15 15 FILES
16 16 -----
17 17
18 18 Mercurial reads configuration data from several files, if they exist.
19 19 The names of these files depend on the system on which Mercurial is
20 20 installed.
21 21
22 22 (Unix) <install-root>/etc/mercurial/hgrc.d/*.rc::
23 23 (Unix) <install-root>/etc/mercurial/hgrc::
24 24 Per-installation configuration files, searched for in the
25 25 directory where Mercurial is installed. For example, if installed
26 26 in /shared/tools, Mercurial will look in
27 27 /shared/tools/etc/mercurial/hgrc. Options in these files apply to
28 28 all Mercurial commands executed by any user in any directory.
29 29
30 30 (Unix) /etc/mercurial/hgrc.d/*.rc::
31 31 (Unix) /etc/mercurial/hgrc::
32 32 (Windows) C:\Mercurial\Mercurial.ini::
33 33 Per-system configuration files, for the system on which Mercurial
34 34 is running. Options in these files apply to all Mercurial
35 35 commands executed by any user in any directory. Options in these
36 36 files override per-installation options.
37 37
38 38 (Unix) $HOME/.hgrc::
39 39 (Windows) C:\Documents and Settings\USERNAME\Mercurial.ini::
40 40 (Windows) $HOME\Mercurial.ini::
41 41 Per-user configuration file, for the user running Mercurial.
42 42 Options in this file apply to all Mercurial commands executed by
43 43 any user in any directory. Options in this file override
44 44 per-installation and per-system options.
45 45 On Windows system, one of these is chosen exclusively according
46 46 to definition of HOME environment variable.
47 47
48 48 (Unix, Windows) <repo>/.hg/hgrc::
49 49 Per-repository configuration options that only apply in a
50 50 particular repository. This file is not version-controlled, and
51 51 will not get transferred during a "clone" operation. Options in
52 52 this file override options in all other configuration files.
53 53
54 54 SYNTAX
55 55 ------
56 56
57 57 A configuration file consists of sections, led by a "[section]" header
58 58 and followed by "name: value" entries; "name=value" is also accepted.
59 59
60 60 [spam]
61 61 eggs=ham
62 62 green=
63 63 eggs
64 64
65 65 Each line contains one entry. If the lines that follow are indented,
66 66 they are treated as continuations of that entry.
67 67
68 68 Leading whitespace is removed from values. Empty lines are skipped.
69 69
70 70 The optional values can contain format strings which refer to other
71 71 values in the same section, or values in a special DEFAULT section.
72 72
73 73 Lines beginning with "#" or ";" are ignored and may be used to provide
74 74 comments.
75 75
76 76 SECTIONS
77 77 --------
78 78
79 79 This section describes the different sections that may appear in a
80 80 Mercurial "hgrc" file, the purpose of each section, its possible
81 81 keys, and their possible values.
82 82
83 83 decode/encode::
84 84 Filters for transforming files on checkout/checkin. This would
85 85 typically be used for newline processing or other
86 86 localization/canonicalization of files.
87 87
88 88 Filters consist of a filter pattern followed by a filter command.
89 89 Filter patterns are globs by default, rooted at the repository
90 90 root. For example, to match any file ending in ".txt" in the root
91 91 directory only, use the pattern "*.txt". To match any file ending
92 92 in ".c" anywhere in the repository, use the pattern "**.c".
93 93
94 94 The filter command can start with a specifier, either "pipe:" or
95 95 "tempfile:". If no specifier is given, "pipe:" is used by default.
96 96
97 97 A "pipe:" command must accept data on stdin and return the
98 98 transformed data on stdout.
99 99
100 100 Pipe example:
101 101
102 102 [encode]
103 103 # uncompress gzip files on checkin to improve delta compression
104 104 # note: not necessarily a good idea, just an example
105 105 *.gz = pipe: gunzip
106 106
107 107 [decode]
108 108 # recompress gzip files when writing them to the working dir (we
109 109 # can safely omit "pipe:", because it's the default)
110 110 *.gz = gzip
111 111
112 112 A "tempfile:" command is a template. The string INFILE is replaced
113 113 with the name of a temporary file that contains the data to be
114 114 filtered by the command. The string OUTFILE is replaced with the
115 115 name of an empty temporary file, where the filtered data must be
116 116 written by the command.
117 117
118 118 NOTE: the tempfile mechanism is recommended for Windows systems,
119 119 where the standard shell I/O redirection operators often have
120 120 strange effects. In particular, if you are doing line ending
121 121 conversion on Windows using the popular dos2unix and unix2dos
122 122 programs, you *must* use the tempfile mechanism, as using pipes will
123 123 corrupt the contents of your files.
124 124
125 125 Tempfile example:
126 126
127 127 [encode]
128 128 # convert files to unix line ending conventions on checkin
129 129 **.txt = tempfile: dos2unix -n INFILE OUTFILE
130 130
131 131 [decode]
132 132 # convert files to windows line ending conventions when writing
133 133 # them to the working dir
134 134 **.txt = tempfile: unix2dos -n INFILE OUTFILE
135 135
136 136 defaults::
137 137 Use the [defaults] section to define command defaults, i.e. the
138 138 default options/arguments to pass to the specified commands.
139 139
140 140 The following example makes 'hg log' run in verbose mode, and
141 141 'hg status' show only the modified files, by default.
142 142
143 143 [defaults]
144 144 log = -v
145 145 status = -m
146 146
147 147 The actual commands, instead of their aliases, must be used when
148 148 defining command defaults. The command defaults will also be
149 149 applied to the aliases of the commands defined.
150 150
151 151 email::
152 152 Settings for extensions that send email messages.
153 153 from;;
154 154 Optional. Email address to use in "From" header and SMTP envelope
155 155 of outgoing messages.
156 156 to;;
157 157 Optional. Comma-separated list of recipients' email addresses.
158 158 cc;;
159 159 Optional. Comma-separated list of carbon copy recipients'
160 160 email addresses.
161 161 bcc;;
162 162 Optional. Comma-separated list of blind carbon copy
163 163 recipients' email addresses. Cannot be set interactively.
164 164 method;;
165 165 Optional. Method to use to send email messages. If value is
166 166 "smtp" (default), use SMTP (see section "[smtp]" for
167 167 configuration). Otherwise, use as name of program to run that
168 168 acts like sendmail (takes "-f" option for sender, list of
169 169 recipients on command line, message on stdin). Normally, setting
170 170 this to "sendmail" or "/usr/sbin/sendmail" is enough to use
171 171 sendmail to send messages.
172 172
173 173 Email example:
174 174
175 175 [email]
176 176 from = Joseph User <joe.user@example.com>
177 177 method = /usr/sbin/sendmail
178 178
179 179 extensions::
180 180 Mercurial has an extension mechanism for adding new features. To
181 181 enable an extension, create an entry for it in this section.
182 182
183 183 If you know that the extension is already in Python's search path,
184 184 you can give the name of the module, followed by "=", with nothing
185 185 after the "=".
186 186
187 187 Otherwise, give a name that you choose, followed by "=", followed by
188 188 the path to the ".py" file (including the file name extension) that
189 189 defines the extension.
190 190
191 191 Example for ~/.hgrc:
192 192
193 193 [extensions]
194 194 # (the mq extension will get loaded from mercurial's path)
195 195 hgext.mq =
196 196 # (this extension will get loaded from the file specified)
197 197 myfeature = ~/.hgext/myfeature.py
198 198
199 199 hooks::
200 200 Commands or Python functions that get automatically executed by
201 201 various actions such as starting or finishing a commit. Multiple
202 202 hooks can be run for the same action by appending a suffix to the
203 203 action. Overriding a site-wide hook can be done by changing its
204 204 value or setting it to an empty string.
205 205
206 206 Example .hg/hgrc:
207 207
208 208 [hooks]
209 209 # do not use the site-wide hook
210 210 incoming =
211 211 incoming.email = /my/email/hook
212 212 incoming.autobuild = /my/build/hook
213 213
214 214 Most hooks are run with environment variables set that give added
215 215 useful information. For each hook below, the environment variables
216 216 it is passed are listed with names of the form "$HG_foo".
217 217
218 218 changegroup;;
219 219 Run after a changegroup has been added via push, pull or
220 220 unbundle. ID of the first new changeset is in $HG_NODE. URL from
221 221 which changes came is in $HG_URL.
222 222 commit;;
223 223 Run after a changeset has been created in the local repository.
224 224 ID of the newly created changeset is in $HG_NODE. Parent
225 225 changeset IDs are in $HG_PARENT1 and $HG_PARENT2.
226 226 incoming;;
227 227 Run after a changeset has been pulled, pushed, or unbundled into
228 228 the local repository. The ID of the newly arrived changeset is in
229 229 $HG_NODE. URL that was source of changes came is in $HG_URL.
230 230 outgoing;;
231 231 Run after sending changes from local repository to another. ID of
232 232 first changeset sent is in $HG_NODE. Source of operation is in
233 233 $HG_SOURCE; see "preoutgoing" hook for description.
234 234 prechangegroup;;
235 235 Run before a changegroup is added via push, pull or unbundle.
236 236 Exit status 0 allows the changegroup to proceed. Non-zero status
237 237 will cause the push, pull or unbundle to fail. URL from which
238 238 changes will come is in $HG_URL.
239 239 precommit;;
240 240 Run before starting a local commit. Exit status 0 allows the
241 241 commit to proceed. Non-zero status will cause the commit to fail.
242 242 Parent changeset IDs are in $HG_PARENT1 and $HG_PARENT2.
243 243 preoutgoing;;
244 244 Run before computing changes to send from the local repository to
245 245 another. Non-zero status will cause failure. This lets you
246 246 prevent pull over http or ssh. Also prevents against local pull,
247 247 push (outbound) or bundle commands, but not effective, since you
248 248 can just copy files instead then. Source of operation is in
249 249 $HG_SOURCE. If "serve", operation is happening on behalf of
250 250 remote ssh or http repository. If "push", "pull" or "bundle",
251 251 operation is happening on behalf of repository on same system.
252 252 pretag;;
253 253 Run before creating a tag. Exit status 0 allows the tag to be
254 254 created. Non-zero status will cause the tag to fail. ID of
255 255 changeset to tag is in $HG_NODE. Name of tag is in $HG_TAG. Tag
256 256 is local if $HG_LOCAL=1, in repo if $HG_LOCAL=0.
257 257 pretxnchangegroup;;
258 258 Run after a changegroup has been added via push, pull or unbundle,
259 259 but before the transaction has been committed. Changegroup is
260 260 visible to hook program. This lets you validate incoming changes
261 261 before accepting them. Passed the ID of the first new changeset
262 262 in $HG_NODE. Exit status 0 allows the transaction to commit.
263 263 Non-zero status will cause the transaction to be rolled back and
264 264 the push, pull or unbundle will fail. URL that was source of
265 265 changes is in $HG_URL.
266 266 pretxncommit;;
267 267 Run after a changeset has been created but the transaction not yet
268 268 committed. Changeset is visible to hook program. This lets you
269 269 validate commit message and changes. Exit status 0 allows the
270 270 commit to proceed. Non-zero status will cause the transaction to
271 271 be rolled back. ID of changeset is in $HG_NODE. Parent changeset
272 272 IDs are in $HG_PARENT1 and $HG_PARENT2.
273 273 preupdate;;
274 274 Run before updating the working directory. Exit status 0 allows
275 275 the update to proceed. Non-zero status will prevent the update.
276 276 Changeset ID of first new parent is in $HG_PARENT1. If merge, ID
277 277 of second new parent is in $HG_PARENT2.
278 278 tag;;
279 279 Run after a tag is created. ID of tagged changeset is in
280 280 $HG_NODE. Name of tag is in $HG_TAG. Tag is local if
281 281 $HG_LOCAL=1, in repo if $HG_LOCAL=0.
282 282 update;;
283 283 Run after updating the working directory. Changeset ID of first
284 284 new parent is in $HG_PARENT1. If merge, ID of second new parent
285 285 is in $HG_PARENT2. If update succeeded, $HG_ERROR=0. If update
286 286 failed (e.g. because conflicts not resolved), $HG_ERROR=1.
287 287
288 288 Note: In earlier releases, the names of hook environment variables
289 289 did not have a "HG_" prefix. The old unprefixed names are no longer
290 290 provided in the environment.
291 291
292 292 The syntax for Python hooks is as follows:
293 293
294 294 hookname = python:modulename.submodule.callable
295 295
296 296 Python hooks are run within the Mercurial process. Each hook is
297 297 called with at least three keyword arguments: a ui object (keyword
298 298 "ui"), a repository object (keyword "repo"), and a "hooktype"
299 299 keyword that tells what kind of hook is used. Arguments listed as
300 300 environment variables above are passed as keyword arguments, with no
301 301 "HG_" prefix, and names in lower case.
302 302
303 303 A Python hook must return a "true" value to succeed. Returning a
304 304 "false" value or raising an exception is treated as failure of the
305 305 hook.
306 306
307 307 http_proxy::
308 308 Used to access web-based Mercurial repositories through a HTTP
309 309 proxy.
310 310 host;;
311 311 Host name and (optional) port of the proxy server, for example
312 312 "myproxy:8000".
313 313 no;;
314 314 Optional. Comma-separated list of host names that should bypass
315 315 the proxy.
316 316 passwd;;
317 317 Optional. Password to authenticate with at the proxy server.
318 318 user;;
319 319 Optional. User name to authenticate with at the proxy server.
320 320
321 321 smtp::
322 322 Configuration for extensions that need to send email messages.
323 323 host;;
324 324 Host name of mail server, e.g. "mail.example.com".
325 325 port;;
326 326 Optional. Port to connect to on mail server. Default: 25.
327 327 tls;;
328 328 Optional. Whether to connect to mail server using TLS. True or
329 329 False. Default: False.
330 330 username;;
331 331 Optional. User name to authenticate to SMTP server with.
332 332 If username is specified, password must also be specified.
333 333 Default: none.
334 334 password;;
335 335 Optional. Password to authenticate to SMTP server with.
336 336 If username is specified, password must also be specified.
337 337 Default: none.
338 338 local_hostname;;
339 339 Optional. It's the hostname that the sender can use to identify itself
340 340 to the MTA.
341 341
342 342 paths::
343 343 Assigns symbolic names to repositories. The left side is the
344 344 symbolic name, and the right gives the directory or URL that is the
345 345 location of the repository. Default paths can be declared by
346 346 setting the following entries.
347 347 default;;
348 348 Directory or URL to use when pulling if no source is specified.
349 349 Default is set to repository from which the current repository
350 350 was cloned.
351 351 default-push;;
352 352 Optional. Directory or URL to use when pushing if no destination
353 353 is specified.
354 354
355 355 server::
356 356 Controls generic server settings.
357 357 uncompressed;;
358 358 Whether to allow clients to clone a repo using the uncompressed
359 359 streaming protocol. This transfers about 40% more data than a
360 360 regular clone, but uses less memory and CPU on both server and
361 361 client. Over a LAN (100Mbps or better) or a very fast WAN, an
362 362 uncompressed streaming clone is a lot faster (~10x) than a regular
363 363 clone. Over most WAN connections (anything slower than about
364 364 6Mbps), uncompressed streaming is slower, because of the extra
365 365 data transfer overhead. Default is False.
366 366
367 367 ui::
368 368 User interface controls.
369 369 debug;;
370 370 Print debugging information. True or False. Default is False.
371 371 editor;;
372 372 The editor to use during a commit. Default is $EDITOR or "vi".
373 373 ignore;;
374 374 A file to read per-user ignore patterns from. This file should be in
375 375 the same format as a repository-wide .hgignore file. This option
376 376 supports hook syntax, so if you want to specify multiple ignore
377 377 files, you can do so by setting something like
378 378 "ignore.other = ~/.hgignore2". For details of the ignore file
379 379 format, see the hgignore(5) man page.
380 380 interactive;;
381 381 Allow to prompt the user. True or False. Default is True.
382 382 logtemplate;;
383 383 Template string for commands that print changesets.
384 384 style;;
385 385 Name of style to use for command output.
386 386 merge;;
387 387 The conflict resolution program to use during a manual merge.
388 388 Default is "hgmerge".
389 389 quiet;;
390 390 Reduce the amount of output printed. True or False. Default is False.
391 391 remotecmd;;
392 392 remote command to use for clone/push/pull operations. Default is 'hg'.
393 393 ssh;;
394 394 command to use for SSH connections. Default is 'ssh'.
395 395 strict;;
396 396 Require exact command names, instead of allowing unambiguous
397 397 abbreviations. True or False. Default is False.
398 398 timeout;;
399 399 The timeout used when a lock is held (in seconds), a negative value
400 400 means no timeout. Default is 600.
401 401 username;;
402 402 The committer of a changeset created when running "commit".
403 403 Typically a person's name and email address, e.g. "Fred Widget
404 <fred@example.com>". Default is $EMAIL. If no default is found,
405 the username have to be specified manually.
404 <fred@example.com>". Default is $EMAIL. If no default is found, or the
405 configured username is empty, it has to be specified manually.
406 406 verbose;;
407 407 Increase the amount of output printed. True or False. Default is False.
408 408
409 409
410 410 web::
411 411 Web interface configuration.
412 412 accesslog;;
413 413 Where to output the access log. Default is stdout.
414 414 address;;
415 415 Interface address to bind to. Default is all.
416 416 allow_archive;;
417 417 List of archive format (bz2, gz, zip) allowed for downloading.
418 418 Default is empty.
419 419 allowbz2;;
420 420 (DEPRECATED) Whether to allow .tar.bz2 downloading of repo revisions.
421 421 Default is false.
422 422 allowgz;;
423 423 (DEPRECATED) Whether to allow .tar.gz downloading of repo revisions.
424 424 Default is false.
425 425 allowpull;;
426 426 Whether to allow pulling from the repository. Default is true.
427 427 allow_push;;
428 428 Whether to allow pushing to the repository. If empty or not set,
429 429 push is not allowed. If the special value "*", any remote user
430 430 can push, including unauthenticated users. Otherwise, the remote
431 431 user must have been authenticated, and the authenticated user name
432 432 must be present in this list (separated by whitespace or ",").
433 433 The contents of the allow_push list are examined after the
434 434 deny_push list.
435 435 allowzip;;
436 436 (DEPRECATED) Whether to allow .zip downloading of repo revisions.
437 437 Default is false. This feature creates temporary files.
438 438 baseurl;;
439 439 Base URL to use when publishing URLs in other locations, so
440 440 third-party tools like email notification hooks can construct URLs.
441 441 Example: "http://hgserver/repos/"
442 442 contact;;
443 443 Name or email address of the person in charge of the repository.
444 444 Default is "unknown".
445 445 deny_push;;
446 446 Whether to deny pushing to the repository. If empty or not set,
447 447 push is not denied. If the special value "*", all remote users
448 448 are denied push. Otherwise, unauthenticated users are all denied,
449 449 and any authenticated user name present in this list (separated by
450 450 whitespace or ",") is also denied. The contents of the deny_push
451 451 list are examined before the allow_push list.
452 452 description;;
453 453 Textual description of the repository's purpose or contents.
454 454 Default is "unknown".
455 455 errorlog;;
456 456 Where to output the error log. Default is stderr.
457 457 ipv6;;
458 458 Whether to use IPv6. Default is false.
459 459 name;;
460 460 Repository name to use in the web interface. Default is current
461 461 working directory.
462 462 maxchanges;;
463 463 Maximum number of changes to list on the changelog. Default is 10.
464 464 maxfiles;;
465 465 Maximum number of files to list per changeset. Default is 10.
466 466 port;;
467 467 Port to listen on. Default is 8000.
468 468 push_ssl;;
469 469 Whether to require that inbound pushes be transported over SSL to
470 470 prevent password sniffing. Default is true.
471 471 stripes;;
472 472 How many lines a "zebra stripe" should span in multiline output.
473 473 Default is 1; set to 0 to disable.
474 474 style;;
475 475 Which template map style to use.
476 476 templates;;
477 477 Where to find the HTML templates. Default is install path.
478 478
479 479
480 480 AUTHOR
481 481 ------
482 482 Bryan O'Sullivan <bos@serpentine.com>.
483 483
484 484 Mercurial was written by Matt Mackall <mpm@selenic.com>.
485 485
486 486 SEE ALSO
487 487 --------
488 488 hg(1), hgignore(5)
489 489
490 490 COPYING
491 491 -------
492 492 This manual page is copyright 2005 Bryan O'Sullivan.
493 493 Mercurial is copyright 2005, 2006 Matt Mackall.
494 494 Free use of this software is granted under the terms of the GNU General
495 495 Public License (GPL).
@@ -1,338 +1,343 b''
1 1 # ui.py - user interface bits for mercurial
2 2 #
3 3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms
6 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 8 from i18n import gettext as _
9 9 from demandload import *
10 10 demandload(globals(), "errno getpass os re socket sys tempfile")
11 11 demandload(globals(), "ConfigParser traceback util")
12 12
13 13 def dupconfig(orig):
14 14 new = util.configparser(orig.defaults())
15 15 updateconfig(orig, new)
16 16 return new
17 17
18 18 def updateconfig(source, dest, sections=None):
19 19 if not sections:
20 20 sections = source.sections()
21 21 for section in sections:
22 22 if not dest.has_section(section):
23 23 dest.add_section(section)
24 24 for name, value in source.items(section, raw=True):
25 25 dest.set(section, name, value)
26 26
27 27 class ui(object):
28 28 def __init__(self, verbose=False, debug=False, quiet=False,
29 29 interactive=True, traceback=False, parentui=None):
30 30 self.overlay = None
31 31 self.header = []
32 32 self.prev_header = []
33 33 if parentui is None:
34 34 # this is the parent of all ui children
35 35 self.parentui = None
36 36 self.readhooks = []
37 37 self.quiet = quiet
38 38 self.verbose = verbose
39 39 self.debugflag = debug
40 40 self.interactive = interactive
41 41 self.traceback = traceback
42 42 self.cdata = util.configparser()
43 43 self.readconfig(util.rcpath())
44 44 self.updateopts(verbose, debug, quiet, interactive)
45 45 else:
46 46 # parentui may point to an ui object which is already a child
47 47 self.parentui = parentui.parentui or parentui
48 48 self.readhooks = self.parentui.readhooks[:]
49 49 self.cdata = dupconfig(self.parentui.cdata)
50 50 if self.parentui.overlay:
51 51 self.overlay = dupconfig(self.parentui.overlay)
52 52
53 53 def __getattr__(self, key):
54 54 return getattr(self.parentui, key)
55 55
56 56 def updateopts(self, verbose=False, debug=False, quiet=False,
57 57 interactive=True, traceback=False, config=[]):
58 58 for section, name, value in config:
59 59 self.setconfig(section, name, value)
60 60
61 61 if quiet or verbose or debug:
62 62 self.setconfig('ui', 'quiet', str(bool(quiet)))
63 63 self.setconfig('ui', 'verbose', str(bool(verbose)))
64 64 self.setconfig('ui', 'debug', str(bool(debug)))
65 65
66 66 self.verbosity_constraints()
67 67
68 68 if not interactive:
69 69 self.setconfig('ui', 'interactive', 'False')
70 70 self.interactive = False
71 71
72 72 self.traceback = self.traceback or traceback
73 73
74 74 def verbosity_constraints(self):
75 75 self.quiet = self.configbool('ui', 'quiet')
76 76 self.verbose = self.configbool('ui', 'verbose')
77 77 self.debugflag = self.configbool('ui', 'debug')
78 78
79 79 if self.debugflag:
80 80 self.verbose = True
81 81 self.quiet = False
82 82 elif self.verbose and self.quiet:
83 83 self.quiet = self.verbose = False
84 84
85 85 def readconfig(self, fn, root=None):
86 86 if isinstance(fn, basestring):
87 87 fn = [fn]
88 88 for f in fn:
89 89 try:
90 90 self.cdata.read(f)
91 91 except ConfigParser.ParsingError, inst:
92 92 raise util.Abort(_("Failed to parse %s\n%s") % (f, inst))
93 93 # override data from config files with data set with ui.setconfig
94 94 if self.overlay:
95 95 updateconfig(self.overlay, self.cdata)
96 96 if root is None:
97 97 root = os.path.expanduser('~')
98 98 self.fixconfig(root=root)
99 99 for hook in self.readhooks:
100 100 hook(self)
101 101
102 102 def addreadhook(self, hook):
103 103 self.readhooks.append(hook)
104 104
105 105 def readsections(self, filename, *sections):
106 106 "read filename and add only the specified sections to the config data"
107 107 if not sections:
108 108 return
109 109
110 110 cdata = util.configparser()
111 111 try:
112 112 cdata.read(filename)
113 113 except ConfigParser.ParsingError, inst:
114 114 raise util.Abort(_("failed to parse %s\n%s") % (filename,
115 115 inst))
116 116
117 117 for section in sections:
118 118 if not cdata.has_section(section):
119 119 cdata.add_section(section)
120 120
121 121 updateconfig(cdata, self.cdata, sections)
122 122
123 123 def fixconfig(self, section=None, name=None, value=None, root=None):
124 124 # translate paths relative to root (or home) into absolute paths
125 125 if section is None or section == 'paths':
126 126 if root is None:
127 127 root = os.getcwd()
128 128 items = section and [(name, value)] or []
129 129 for cdata in self.cdata, self.overlay:
130 130 if not cdata: continue
131 131 if not items and cdata.has_section('paths'):
132 132 pathsitems = cdata.items('paths')
133 133 else:
134 134 pathsitems = items
135 135 for n, path in pathsitems:
136 136 if path and "://" not in path and not os.path.isabs(path):
137 137 cdata.set("paths", n, os.path.join(root, path))
138 138
139 139 # update quiet/verbose/debug and interactive status
140 140 if section is None or section == 'ui':
141 141 if name is None or name in ('quiet', 'verbose', 'debug'):
142 142 self.verbosity_constraints()
143 143
144 144 if name is None or name == 'interactive':
145 145 self.interactive = self.configbool("ui", "interactive", True)
146 146
147 147 def setconfig(self, section, name, value):
148 148 if not self.overlay:
149 149 self.overlay = util.configparser()
150 150 for cdata in (self.overlay, self.cdata):
151 151 if not cdata.has_section(section):
152 152 cdata.add_section(section)
153 153 cdata.set(section, name, value)
154 154 self.fixconfig(section, name, value)
155 155
156 156 def _config(self, section, name, default, funcname):
157 157 if self.cdata.has_option(section, name):
158 158 try:
159 159 func = getattr(self.cdata, funcname)
160 160 return func(section, name)
161 161 except ConfigParser.InterpolationError, inst:
162 162 raise util.Abort(_("Error in configuration section [%s] "
163 163 "parameter '%s':\n%s")
164 164 % (section, name, inst))
165 165 return default
166 166
167 167 def config(self, section, name, default=None):
168 168 return self._config(section, name, default, 'get')
169 169
170 170 def configbool(self, section, name, default=False):
171 171 return self._config(section, name, default, 'getboolean')
172 172
173 173 def configlist(self, section, name, default=None):
174 174 """Return a list of comma/space separated strings"""
175 175 result = self.config(section, name)
176 176 if result is None:
177 177 result = default or []
178 178 if isinstance(result, basestring):
179 179 result = result.replace(",", " ").split()
180 180 return result
181 181
182 182 def has_config(self, section):
183 183 '''tell whether section exists in config.'''
184 184 return self.cdata.has_section(section)
185 185
186 186 def configitems(self, section):
187 187 items = {}
188 188 if self.cdata.has_section(section):
189 189 try:
190 190 items.update(dict(self.cdata.items(section)))
191 191 except ConfigParser.InterpolationError, inst:
192 192 raise util.Abort(_("Error in configuration section [%s]:\n%s")
193 193 % (section, inst))
194 194 x = items.items()
195 195 x.sort()
196 196 return x
197 197
198 198 def walkconfig(self):
199 199 sections = self.cdata.sections()
200 200 sections.sort()
201 201 for section in sections:
202 202 for name, value in self.configitems(section):
203 203 yield section, name, value.replace('\n', '\\n')
204 204
205 205 def extensions(self):
206 206 result = self.configitems("extensions")
207 207 for i, (key, value) in enumerate(result):
208 208 if value:
209 209 result[i] = (key, os.path.expanduser(value))
210 210 return result
211 211
212 212 def hgignorefiles(self):
213 213 result = []
214 214 for key, value in self.configitems("ui"):
215 215 if key == 'ignore' or key.startswith('ignore.'):
216 216 result.append(os.path.expanduser(value))
217 217 return result
218 218
219 219 def configrevlog(self):
220 220 result = {}
221 221 for key, value in self.configitems("revlog"):
222 222 result[key.lower()] = value
223 223 return result
224 224
225 225 def username(self):
226 226 """Return default username to be used in commits.
227 227
228 228 Searched in this order: $HGUSER, [ui] section of hgrcs, $EMAIL
229 229 and stop searching if one of these is set.
230 230 Abort if no username is found, to force specifying the commit user
231 231 with line option or repo hgrc.
232 232 """
233 233 user = os.environ.get("HGUSER")
234 234 if user is None:
235 235 user = self.config("ui", "username")
236 236 if user is None:
237 237 user = os.environ.get("EMAIL")
238 if user is None:
239 raise util.Abort(_("No default username available, use -u"))
238 if not user:
239 self.status(_("Please choose a commit username to be recorded "
240 "in the changelog via\ncommand line option "
241 '(-u "First Last <email@example.com>"), in the\n'
242 "configuration files (hgrc), or by setting the "
243 "EMAIL environment variable.\n\n"))
244 raise util.Abort(_("No commit username specified!"))
240 245 return user
241 246
242 247 def shortuser(self, user):
243 248 """Return a short representation of a user name or email address."""
244 249 if not self.verbose: user = util.shortuser(user)
245 250 return user
246 251
247 252 def expandpath(self, loc, default=None):
248 253 """Return repository location relative to cwd or from [paths]"""
249 254 if "://" in loc or os.path.isdir(loc):
250 255 return loc
251 256
252 257 path = self.config("paths", loc)
253 258 if not path and default is not None:
254 259 path = self.config("paths", default)
255 260 return path or loc
256 261
257 262 def write(self, *args):
258 263 if self.header:
259 264 if self.header != self.prev_header:
260 265 self.prev_header = self.header
261 266 self.write(*self.header)
262 267 self.header = []
263 268 for a in args:
264 269 sys.stdout.write(str(a))
265 270
266 271 def write_header(self, *args):
267 272 for a in args:
268 273 self.header.append(str(a))
269 274
270 275 def write_err(self, *args):
271 276 try:
272 277 if not sys.stdout.closed: sys.stdout.flush()
273 278 for a in args:
274 279 sys.stderr.write(str(a))
275 280 except IOError, inst:
276 281 if inst.errno != errno.EPIPE:
277 282 raise
278 283
279 284 def flush(self):
280 285 try: sys.stdout.flush()
281 286 except: pass
282 287 try: sys.stderr.flush()
283 288 except: pass
284 289
285 290 def readline(self):
286 291 return sys.stdin.readline()[:-1]
287 292 def prompt(self, msg, pat=None, default="y"):
288 293 if not self.interactive: return default
289 294 while 1:
290 295 self.write(msg, " ")
291 296 r = self.readline()
292 297 if not pat or re.match(pat, r):
293 298 return r
294 299 else:
295 300 self.write(_("unrecognized response\n"))
296 301 def getpass(self, prompt=None, default=None):
297 302 if not self.interactive: return default
298 303 return getpass.getpass(prompt or _('password: '))
299 304 def status(self, *msg):
300 305 if not self.quiet: self.write(*msg)
301 306 def warn(self, *msg):
302 307 self.write_err(*msg)
303 308 def note(self, *msg):
304 309 if self.verbose: self.write(*msg)
305 310 def debug(self, *msg):
306 311 if self.debugflag: self.write(*msg)
307 312 def edit(self, text, user):
308 313 (fd, name) = tempfile.mkstemp(prefix="hg-editor-", suffix=".txt",
309 314 text=True)
310 315 try:
311 316 f = os.fdopen(fd, "w")
312 317 f.write(text)
313 318 f.close()
314 319
315 320 editor = (os.environ.get("HGEDITOR") or
316 321 self.config("ui", "editor") or
317 322 os.environ.get("EDITOR", "vi"))
318 323
319 324 util.system("%s \"%s\"" % (editor, name),
320 325 environ={'HGUSER': user},
321 326 onerr=util.Abort, errprefix=_("edit failed"))
322 327
323 328 f = open(name)
324 329 t = f.read()
325 330 f.close()
326 331 t = re.sub("(?m)^HG:.*\n", "", t)
327 332 finally:
328 333 os.unlink(name)
329 334
330 335 return t
331 336
332 337 def print_exc(self):
333 338 '''print exception traceback if traceback printing enabled.
334 339 only to call in exception handler. returns true if traceback
335 340 printed.'''
336 341 if self.traceback:
337 342 traceback.print_exc()
338 343 return self.traceback
@@ -1,27 +1,31 b''
1 1 changeset: 0:9426b370c206
2 2 tag: tip
3 3 user: My Name <myname@example.com>
4 4 date: Mon Jan 12 13:46:40 1970 +0000
5 5 summary: commit-1
6 6
7 abort: No default username available, use -u
7 Please choose a commit username to be recorded in the changelog via
8 command line option (-u "First Last <email@example.com>"), in the
9 configuration files (hgrc), or by setting the EMAIL environment variable.
10
11 abort: No commit username specified!
8 12 transaction abort!
9 13 rollback completed
10 14 changeset: 1:2becd0bae6e6
11 15 tag: tip
12 16 user: foo@bar.com
13 17 date: Mon Jan 12 13:46:40 1970 +0000
14 18 summary: commit-1
15 19
16 20 changeset: 2:7a0176714f78
17 21 tag: tip
18 22 user: foobar <foo@bar.com>
19 23 date: Mon Jan 12 13:46:40 1970 +0000
20 24 summary: commit-1
21 25
22 26 changeset: 3:f9b58c5a6352
23 27 tag: tip
24 28 user: foo@bar.com
25 29 date: Mon Jan 12 13:46:40 1970 +0000
26 30 summary: commit-1
27 31
General Comments 0
You need to be logged in to leave comments. Login now