##// END OF EJS Templates
Adapted behaviour of ui.username() to documentation and mention it explicitly:...
Thomas Arendsen Hein -
r1985:c5776890 default
parent child Browse files
Show More
@@ -1,317 +1,319 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 Per-user configuration file, for the user running Mercurial.
41 41 Options in this file apply to all Mercurial commands executed by
42 42 any user in any directory. Options in this file override
43 43 per-installation and per-system options.
44 44
45 45 (Unix, Windows) <repo>/.hg/hgrc::
46 46 Per-repository configuration options that only apply in a
47 47 particular repository. This file is not version-controlled, and
48 48 will not get transferred during a "clone" operation. Options in
49 49 this file override options in all other configuration files.
50 50
51 51 SYNTAX
52 52 ------
53 53
54 54 A configuration file consists of sections, led by a "[section]" header
55 55 and followed by "name: value" entries; "name=value" is also accepted.
56 56
57 57 [spam]
58 58 eggs=ham
59 59 green=
60 60 eggs
61 61
62 62 Each line contains one entry. If the lines that follow are indented,
63 63 they are treated as continuations of that entry.
64 64
65 65 Leading whitespace is removed from values. Empty lines are skipped.
66 66
67 67 The optional values can contain format strings which refer to other
68 68 values in the same section, or values in a special DEFAULT section.
69 69
70 70 Lines beginning with "#" or ";" are ignored and may be used to provide
71 71 comments.
72 72
73 73 SECTIONS
74 74 --------
75 75
76 76 This section describes the different sections that may appear in a
77 77 Mercurial "hgrc" file, the purpose of each section, its possible
78 78 keys, and their possible values.
79 79
80 80 decode/encode::
81 81 Filters for transforming files on checkout/checkin. This would
82 82 typically be used for newline processing or other
83 83 localization/canonicalization of files.
84 84
85 85 Filters consist of a filter pattern followed by a filter command.
86 86 Filter patterns are globs by default, rooted at the repository
87 87 root. For example, to match any file ending in ".txt" in the root
88 88 directory only, use the pattern "*.txt". To match any file ending
89 89 in ".c" anywhere in the repository, use the pattern "**.c".
90 90
91 91 The filter command can start with a specifier, either "pipe:" or
92 92 "tempfile:". If no specifier is given, "pipe:" is used by default.
93 93
94 94 A "pipe:" command must accept data on stdin and return the
95 95 transformed data on stdout.
96 96
97 97 Pipe example:
98 98
99 99 [encode]
100 100 # uncompress gzip files on checkin to improve delta compression
101 101 # note: not necessarily a good idea, just an example
102 102 *.gz = pipe: gunzip
103 103
104 104 [decode]
105 105 # recompress gzip files when writing them to the working dir (we
106 106 # can safely omit "pipe:", because it's the default)
107 107 *.gz = gzip
108 108
109 109 A "tempfile:" command is a template. The string INFILE is replaced
110 110 with the name of a temporary file that contains the data to be
111 111 filtered by the command. The string OUTFILE is replaced with the
112 112 name of an empty temporary file, where the filtered data must be
113 113 written by the command.
114 114
115 115 NOTE: the tempfile mechanism is recommended for Windows systems,
116 116 where the standard shell I/O redirection operators often have
117 117 strange effects. In particular, if you are doing line ending
118 118 conversion on Windows using the popular dos2unix and unix2dos
119 119 programs, you *must* use the tempfile mechanism, as using pipes will
120 120 corrupt the contents of your files.
121 121
122 122 Tempfile example:
123 123
124 124 [encode]
125 125 # convert files to unix line ending conventions on checkin
126 126 **.txt = tempfile: dos2unix -n INFILE OUTFILE
127 127
128 128 [decode]
129 129 # convert files to windows line ending conventions when writing
130 130 # them to the working dir
131 131 **.txt = tempfile: unix2dos -n INFILE OUTFILE
132 132
133 133 hooks::
134 134 Commands that get automatically executed by various actions such as
135 135 starting or finishing a commit. Multiple commands can be run for
136 136 the same action by appending a suffix to the action. Overriding a
137 137 site-wide hook can be done by changing its value or setting it to
138 138 an empty string.
139 139
140 140 Example .hg/hgrc:
141 141
142 142 [hooks]
143 143 # do not use the site-wide hook
144 144 incoming =
145 145 incoming.email = /my/email/hook
146 146 incoming.autobuild = /my/build/hook
147 147
148 148 Most hooks are run with environment variables set that give added
149 149 useful information. For each hook below, the environment variables
150 150 it is passed are listed with names of the form "$HG_foo".
151 151
152 152 changegroup;;
153 153 Run after a changegroup has been added via push, pull or
154 154 unbundle. ID of the first new changeset is in $HG_NODE.
155 155 commit;;
156 156 Run after a changeset has been created in the local repository.
157 157 ID of the newly created changeset is in $HG_NODE. Parent
158 158 changeset IDs are in $HG_PARENT1 and $HG_PARENT2.
159 159 incoming;;
160 160 Run after a changeset has been pulled, pushed, or unbundled into
161 161 the local repository. The ID of the newly arrived changeset is in
162 162 $HG_NODE.
163 163 outgoing;;
164 164 Run after sending changes from local repository to another. ID of
165 165 first changeset sent is in $HG_NODE. Source of operation is in
166 166 $HG_SOURCE; see "preoutgoing" hook for description.
167 167 prechangegroup;;
168 168 Run before a changegroup is added via push, pull or unbundle.
169 169 Exit status 0 allows the changegroup to proceed. Non-zero status
170 170 will cause the push, pull or unbundle to fail.
171 171 precommit;;
172 172 Run before starting a local commit. Exit status 0 allows the
173 173 commit to proceed. Non-zero status will cause the commit to fail.
174 174 Parent changeset IDs are in $HG_PARENT1 and $HG_PARENT2.
175 175 preoutgoing;;
176 176 Run before computing changes to send from the local repository to
177 177 another. Non-zero status will cause failure. This lets you
178 178 prevent pull over http or ssh. Also prevents against local pull,
179 179 push (outbound) or bundle commands, but not effective, since you
180 180 can just copy files instead then. Source of operation is in
181 181 $HG_SOURCE. If "serve", operation is happening on behalf of
182 182 remote ssh or http repository. If "push", "pull" or "bundle",
183 183 operation is happening on behalf of repository on same system.
184 184 pretag;;
185 185 Run before creating a tag. Exit status 0 allows the tag to be
186 186 created. Non-zero status will cause the tag to fail. ID of
187 187 changeset to tag is in $HG_NODE. Name of tag is in $HG_TAG. Tag
188 188 is local if $HG_LOCAL=1, in repo if $HG_LOCAL=0.
189 189 pretxnchangegroup;;
190 190 Run after a changegroup has been added via push, pull or unbundle,
191 191 but before the transaction has been committed. Changegroup is
192 192 visible to hook program. This lets you validate incoming changes
193 193 before accepting them. Passed the ID of the first new changeset
194 194 in $HG_NODE. Exit status 0 allows the transaction to commit.
195 195 Non-zero status will cause the transaction to be rolled back and
196 196 the push, pull or unbundle will fail.
197 197 pretxncommit;;
198 198 Run after a changeset has been created but the transaction not yet
199 199 committed. Changeset is visible to hook program. This lets you
200 200 validate commit message and changes. Exit status 0 allows the
201 201 commit to proceed. Non-zero status will cause the transaction to
202 202 be rolled back. ID of changeset is in $HG_NODE. Parent changeset
203 203 IDs are in $HG_PARENT1 and $HG_PARENT2.
204 204 tag;;
205 205 Run after a tag is created. ID of tagged changeset is in
206 206 $HG_NODE. Name of tag is in $HG_TAG. Tag is local if
207 207 $HG_LOCAL=1, in repo if $HG_LOCAL=0.
208 208
209 209 In earlier releases, the names of hook environment variables did not
210 210 have a "HG_" prefix. These unprefixed names are still provided in
211 211 the environment for backwards compatibility, but their use is
212 212 deprecated, and they will be removed in a future release.
213 213
214 214 http_proxy::
215 215 Used to access web-based Mercurial repositories through a HTTP
216 216 proxy.
217 217 host;;
218 218 Host name and (optional) port of the proxy server, for example
219 219 "myproxy:8000".
220 220 no;;
221 221 Optional. Comma-separated list of host names that should bypass
222 222 the proxy.
223 223 passwd;;
224 224 Optional. Password to authenticate with at the proxy server.
225 225 user;;
226 226 Optional. User name to authenticate with at the proxy server.
227 227
228 228 paths::
229 229 Assigns symbolic names to repositories. The left side is the
230 230 symbolic name, and the right gives the directory or URL that is the
231 231 location of the repository.
232 232
233 233 ui::
234 234 User interface controls.
235 235 debug;;
236 236 Print debugging information. True or False. Default is False.
237 237 editor;;
238 238 The editor to use during a commit. Default is $EDITOR or "vi".
239 239 interactive;;
240 240 Allow to prompt the user. True or False. Default is True.
241 241 logtemplate;;
242 242 Template string for commands that print changesets.
243 243 style;;
244 244 Name of style to use for command output.
245 245 merge;;
246 246 The conflict resolution program to use during a manual merge.
247 247 Default is "hgmerge".
248 248 quiet;;
249 249 Reduce the amount of output printed. True or False. Default is False.
250 250 remotecmd;;
251 251 remote command to use for clone/push/pull operations. Default is 'hg'.
252 252 ssh;;
253 253 command to use for SSH connections. Default is 'ssh'.
254 254 timeout;;
255 255 The timeout used when a lock is held (in seconds), a negative value
256 256 means no timeout. Default is 600.
257 257 username;;
258 258 The committer of a changeset created when running "commit".
259 259 Typically a person's name and email address, e.g. "Fred Widget
260 <fred@example.com>". Default is $EMAIL or username@hostname.
260 <fred@example.com>". Default is $EMAIL or username@hostname, unless
261 username is set to an empty string, which enforces specifying the
262 username manually.
261 263 verbose;;
262 264 Increase the amount of output printed. True or False. Default is False.
263 265
264 266
265 267 web::
266 268 Web interface configuration.
267 269 accesslog;;
268 270 Where to output the access log. Default is stdout.
269 271 address;;
270 272 Interface address to bind to. Default is all.
271 273 allowbz2;;
272 274 Whether to allow .tar.bz2 downloading of repo revisions. Default is false.
273 275 allowgz;;
274 276 Whether to allow .tar.gz downloading of repo revisions. Default is false.
275 277 allowpull;;
276 278 Whether to allow pulling from the repository. Default is true.
277 279 allowzip;;
278 280 Whether to allow .zip downloading of repo revisions. Default is false.
279 281 This feature creates temporary files.
280 282 description;;
281 283 Textual description of the repository's purpose or contents.
282 284 Default is "unknown".
283 285 errorlog;;
284 286 Where to output the error log. Default is stderr.
285 287 ipv6;;
286 288 Whether to use IPv6. Default is false.
287 289 name;;
288 290 Repository name to use in the web interface. Default is current
289 291 working directory.
290 292 maxchanges;;
291 293 Maximum number of changes to list on the changelog. Default is 10.
292 294 maxfiles;;
293 295 Maximum number of files to list per changeset. Default is 10.
294 296 port;;
295 297 Port to listen on. Default is 8000.
296 298 style;;
297 299 Which template map style to use.
298 300 templates;;
299 301 Where to find the HTML templates. Default is install path.
300 302
301 303
302 304 AUTHOR
303 305 ------
304 306 Bryan O'Sullivan <bos@serpentine.com>.
305 307
306 308 Mercurial was written by Matt Mackall <mpm@selenic.com>.
307 309
308 310 SEE ALSO
309 311 --------
310 312 hg(1)
311 313
312 314 COPYING
313 315 -------
314 316 This manual page is copyright 2005 Bryan O'Sullivan.
315 317 Mercurial is copyright 2005 Matt Mackall.
316 318 Free use of this software is granted under the terms of the GNU General
317 319 Public License (GPL).
@@ -1,219 +1,233 b''
1 1 # ui.py - user interface bits for mercurial
2 2 #
3 3 # Copyright 2005 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 import ConfigParser
9 9 from i18n import gettext as _
10 10 from demandload import *
11 11 demandload(globals(), "os re socket sys util tempfile")
12 12
13 13 class ui(object):
14 14 def __init__(self, verbose=False, debug=False, quiet=False,
15 15 interactive=True, parentui=None):
16 16 self.overlay = {}
17 17 if parentui is None:
18 18 # this is the parent of all ui children
19 19 self.parentui = None
20 20 self.cdata = ConfigParser.SafeConfigParser()
21 21 self.readconfig(util.rcpath())
22 22
23 23 self.quiet = self.configbool("ui", "quiet")
24 24 self.verbose = self.configbool("ui", "verbose")
25 25 self.debugflag = self.configbool("ui", "debug")
26 26 self.interactive = self.configbool("ui", "interactive", True)
27 27
28 28 self.updateopts(verbose, debug, quiet, interactive)
29 29 self.diffcache = None
30 30 else:
31 31 # parentui may point to an ui object which is already a child
32 32 self.parentui = parentui.parentui or parentui
33 33 parent_cdata = self.parentui.cdata
34 34 self.cdata = ConfigParser.SafeConfigParser(parent_cdata.defaults())
35 35 # make interpolation work
36 36 for section in parent_cdata.sections():
37 37 self.cdata.add_section(section)
38 38 for name, value in parent_cdata.items(section, raw=True):
39 39 self.cdata.set(section, name, value)
40 40
41 41 def __getattr__(self, key):
42 42 return getattr(self.parentui, key)
43 43
44 44 def updateopts(self, verbose=False, debug=False, quiet=False,
45 45 interactive=True):
46 46 self.quiet = (self.quiet or quiet) and not verbose and not debug
47 47 self.verbose = (self.verbose or verbose) or debug
48 48 self.debugflag = (self.debugflag or debug)
49 49 self.interactive = (self.interactive and interactive)
50 50
51 51 def readconfig(self, fn, root=None):
52 52 if isinstance(fn, basestring):
53 53 fn = [fn]
54 54 for f in fn:
55 55 try:
56 56 self.cdata.read(f)
57 57 except ConfigParser.ParsingError, inst:
58 58 raise util.Abort(_("Failed to parse %s\n%s") % (f, inst))
59 59 # translate paths relative to root (or home) into absolute paths
60 60 if root is None:
61 61 root = os.path.expanduser('~')
62 62 for name, path in self.configitems("paths"):
63 63 if path and path.find("://") == -1 and not os.path.isabs(path):
64 64 self.cdata.set("paths", name, os.path.join(root, path))
65 65
66 66 def setconfig(self, section, name, val):
67 67 self.overlay[(section, name)] = val
68 68
69 69 def config(self, section, name, default=None):
70 70 if self.overlay.has_key((section, name)):
71 71 return self.overlay[(section, name)]
72 72 if self.cdata.has_option(section, name):
73 73 try:
74 74 return self.cdata.get(section, name)
75 75 except ConfigParser.InterpolationError, inst:
76 76 raise util.Abort(_("Error in configuration:\n%s") % inst)
77 77 if self.parentui is None:
78 78 return default
79 79 else:
80 80 return self.parentui.config(section, name, default)
81 81
82 82 def configbool(self, section, name, default=False):
83 83 if self.overlay.has_key((section, name)):
84 84 return self.overlay[(section, name)]
85 85 if self.cdata.has_option(section, name):
86 86 try:
87 87 return self.cdata.getboolean(section, name)
88 88 except ConfigParser.InterpolationError, inst:
89 89 raise util.Abort(_("Error in configuration:\n%s") % inst)
90 90 if self.parentui is None:
91 91 return default
92 92 else:
93 93 return self.parentui.configbool(section, name, default)
94 94
95 95 def configitems(self, section):
96 96 items = {}
97 97 if self.parentui is not None:
98 98 items = dict(self.parentui.configitems(section))
99 99 if self.cdata.has_section(section):
100 100 try:
101 101 items.update(dict(self.cdata.items(section)))
102 102 except ConfigParser.InterpolationError, inst:
103 103 raise util.Abort(_("Error in configuration:\n%s") % inst)
104 104 x = items.items()
105 105 x.sort()
106 106 return x
107 107
108 108 def walkconfig(self, seen=None):
109 109 if seen is None:
110 110 seen = {}
111 111 for (section, name), value in self.overlay.iteritems():
112 112 yield section, name, value
113 113 seen[section, name] = 1
114 114 for section in self.cdata.sections():
115 115 for name, value in self.cdata.items(section):
116 116 if (section, name) in seen: continue
117 117 yield section, name, value.replace('\n', '\\n')
118 118 seen[section, name] = 1
119 119 if self.parentui is not None:
120 120 for parent in self.parentui.walkconfig(seen):
121 121 yield parent
122 122
123 123 def extensions(self):
124 124 return self.configitems("extensions")
125 125
126 126 def diffopts(self):
127 127 if self.diffcache:
128 128 return self.diffcache
129 129 ret = { 'showfunc' : True, 'ignorews' : False}
130 130 for x in self.configitems("diff"):
131 131 k = x[0].lower()
132 132 v = x[1]
133 133 if v:
134 134 v = v.lower()
135 135 if v == 'true':
136 136 value = True
137 137 else:
138 138 value = False
139 139 ret[k] = value
140 140 self.diffcache = ret
141 141 return ret
142 142
143 143 def username(self):
144 return (os.environ.get("HGUSER") or
145 self.config("ui", "username") or
146 os.environ.get("EMAIL") or
147 (os.environ.get("LOGNAME",
148 os.environ.get("USERNAME", "unknown"))
149 + '@' + socket.getfqdn()))
144 """Return default username to be used in commits.
145
146 Searched in this order: $HGUSER, [ui] section of hgrcs, $EMAIL
147 and stop searching if one of these is set.
148 Abort if found username is an empty string to force specifying
149 the commit user elsewhere, e.g. with line option or repo hgrc.
150 If not found, use $LOGNAME or $USERNAME +"@full.hostname".
151 """
152 user = os.environ.get("HGUSER")
153 if user is None:
154 user = self.config("ui", "username")
155 if user is None:
156 user = os.environ.get("EMAIL")
157 if user is None:
158 user = os.environ.get("LOGNAME") or os.environ.get("USERNAME")
159 if user:
160 user = "%s@%s" % (user, socket.getfqdn())
161 if not user:
162 raise util.Abort(_("Please specify a username."))
163 return user
150 164
151 165 def shortuser(self, user):
152 166 """Return a short representation of a user name or email address."""
153 167 if not self.verbose: user = util.shortuser(user)
154 168 return user
155 169
156 170 def expandpath(self, loc):
157 171 """Return repository location relative to cwd or from [paths]"""
158 172 if loc.find("://") != -1 or os.path.exists(loc):
159 173 return loc
160 174
161 175 return self.config("paths", loc, loc)
162 176
163 177 def write(self, *args):
164 178 for a in args:
165 179 sys.stdout.write(str(a))
166 180
167 181 def write_err(self, *args):
168 182 if not sys.stdout.closed: sys.stdout.flush()
169 183 for a in args:
170 184 sys.stderr.write(str(a))
171 185
172 186 def flush(self):
173 187 try:
174 188 sys.stdout.flush()
175 189 finally:
176 190 sys.stderr.flush()
177 191
178 192 def readline(self):
179 193 return sys.stdin.readline()[:-1]
180 194 def prompt(self, msg, pat, default="y"):
181 195 if not self.interactive: return default
182 196 while 1:
183 197 self.write(msg, " ")
184 198 r = self.readline()
185 199 if re.match(pat, r):
186 200 return r
187 201 else:
188 202 self.write(_("unrecognized response\n"))
189 203 def status(self, *msg):
190 204 if not self.quiet: self.write(*msg)
191 205 def warn(self, *msg):
192 206 self.write_err(*msg)
193 207 def note(self, *msg):
194 208 if self.verbose: self.write(*msg)
195 209 def debug(self, *msg):
196 210 if self.debugflag: self.write(*msg)
197 211 def edit(self, text, user):
198 212 (fd, name) = tempfile.mkstemp(prefix="hg-editor-", suffix=".txt")
199 213 try:
200 214 f = os.fdopen(fd, "w")
201 215 f.write(text)
202 216 f.close()
203 217
204 218 editor = (os.environ.get("HGEDITOR") or
205 219 self.config("ui", "editor") or
206 220 os.environ.get("EDITOR", "vi"))
207 221
208 222 util.system("%s \"%s\"" % (editor, name),
209 223 environ={'HGUSER': user},
210 224 onerr=util.Abort, errprefix=_("edit failed"))
211 225
212 226 f = open(name)
213 227 t = f.read()
214 228 f.close()
215 229 t = re.sub("(?m)^HG:.*\n", "", t)
216 230 finally:
217 231 os.unlink(name)
218 232
219 233 return t
General Comments 0
You need to be logged in to leave comments. Login now