##// END OF EJS Templates
help: expand the extensions topic
Cédric Duval -
r8865:37d8a5dd default
parent child Browse files
Show More
@@ -1,559 +1,583 b''
1 1 # help.py - help data for mercurial
2 2 #
3 3 # Copyright 2006 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2, incorporated herein by reference.
7 7
8 8 import os, sys
9 9 from i18n import _, gettext
10 10 import extensions
11 11
12 12
13 13 # borrowed from pydoc
14 14 def pathdirs():
15 15 '''Convert sys.path into a list of absolute, existing, unique paths.'''
16 16 dirs = []
17 17 normdirs = []
18 18 for dir in sys.path:
19 19 dir = os.path.abspath(dir or '.')
20 20 normdir = os.path.normcase(dir)
21 21 if normdir not in normdirs and os.path.isdir(dir):
22 22 dirs.append(dir)
23 23 normdirs.append(normdir)
24 24 return dirs
25 25
26 26 # loosely inspired by pydoc.source_synopsis()
27 27 # rewritten to handle ''' as well as """
28 28 # and to return the whole text instead of just the synopsis
29 29 def moduledoc(file):
30 30 '''Return the top python documentation for the given file'''
31 31 result = []
32 32
33 33 line = file.readline()
34 34 while line[:1] == '#' or not line.strip():
35 35 line = file.readline()
36 36 if not line: break
37 37
38 38 start = line[:3]
39 39 if start == '"""' or start == "'''":
40 40 line = line[3:]
41 41 while line:
42 42 if line.rstrip().endswith(start):
43 43 line = line.split(start)[0]
44 44 if line:
45 45 result.append(line)
46 46 break
47 47 elif not line:
48 48 return None # unmatched delimiter
49 49 result.append(line)
50 50 line = file.readline()
51 51 else:
52 52 return None
53 53
54 54 return ''.join(result)
55 55
56 56 def additionalextensions():
57 57 '''Find the extensions shipped with Mercurial but not enabled
58 58
59 59 Returns extensions names and descriptions, and the max name length
60 60 '''
61 61 exts = {}
62 62 maxlength = 0
63 63
64 64 for dir in filter(os.path.isdir,
65 65 (os.path.join(pd, 'hgext') for pd in pathdirs())):
66 66 for e in os.listdir(dir):
67 67 if e.endswith('.py'):
68 68 name = e.rsplit('.', 1)[0]
69 69 path = os.path.join(dir, e)
70 70 else:
71 71 name = e
72 72 path = os.path.join(dir, e, '__init__.py')
73 73
74 74 if name in exts or name == '__init__' or not os.path.exists(path):
75 75 continue
76 76
77 77 try:
78 78 extensions.find(name)
79 79 except KeyError:
80 80 pass
81 81 else:
82 82 continue # enabled extension
83 83
84 84 try:
85 85 file = open(path)
86 86 except IOError:
87 87 continue
88 88 else:
89 89 doc = moduledoc(file)
90 90 file.close()
91 91
92 92 if doc: # extracting localized synopsis
93 93 exts[name] = gettext(doc).splitlines()[0]
94 94 else:
95 95 exts[name] = _('(no help text available)')
96 96 if len(name) > maxlength:
97 97 maxlength = len(name)
98 98
99 99 return exts, maxlength
100 100
101 101 def enabledextensions():
102 102 '''Return the list of enabled extensions, and max name length'''
103 103 enabled = list(extensions.extensions())
104 104 exts = {}
105 105 maxlength = 0
106 106
107 107 if enabled:
108 108 exthelps = []
109 109 for ename, ext in enabled:
110 110 doc = (gettext(ext.__doc__) or _('(no help text available)'))
111 111 ename = ename.split('.')[-1]
112 112 maxlength = max(len(ename), maxlength)
113 113 exts[ename] = doc.splitlines(0)[0].strip()
114 114
115 115 return exts, maxlength
116 116
117 117 def extensionslisting(header, exts, maxlength):
118 118 '''Return a text listing of the given extensions'''
119 119 result = ''
120 120
121 121 if exts:
122 122 result += '\n%s\n\n' % header
123 123 for name, desc in sorted(exts.iteritems()):
124 124 result += ' %s %s\n' % (name.ljust(maxlength), desc)
125 125
126 126 return result
127 127
128 128 def topicextensions():
129 129 doc = _(r'''
130 Mercurial has an extension mechanism for adding new features.
130 Mercurial has a mechanism for adding new features through the
131 use of extensions. Extensions may bring new commands, or new
132 hooks, or change some behaviors of Mercurial.
131 133
132 To enable an extension "foo" bundled with Mercurial, create an
133 entry for it your hgrc, like this:
134 Extensions are not loaded by default for a variety of reasons,
135 they may be meant for an advanced usage or provide potentially
136 dangerous commands (eg. mq or rebase allow to rewrite history),
137 they might not be yet ready for prime-time, or they may alter
138 some usual behaviors of stock Mercurial. It is thus up to the
139 user to activate the extensions as needed.
140
141 To enable an extension "foo" which is either shipped with
142 Mercurial or in the Python search path, create an entry for
143 it in your hgrc, like this:
134 144
135 145 [extensions]
136 146 foo =
147
148 You may also specify the full path where an extension resides:
149
150 [extensions]
151 myfeature = ~/.hgext/myfeature.py
152
153 To explicitly disable an extension which is enabled in an hgrc
154 of broader scope, prepend its path with !:
155
156 [extensions]
157 # disabling extension bar residing in /ext/path
158 hgext.bar = !/path/to/extension/bar.py
159 # ditto, but no path was supplied for extension baz
160 hgext.baz = !
137 161 ''')
138 162
139 163 exts, maxlength = enabledextensions()
140 164 doc += extensionslisting(_('enabled extensions:'), exts, maxlength)
141 165
142 166 exts, maxlength = additionalextensions()
143 167 doc += extensionslisting(_('non-enabled extensions:'), exts, maxlength)
144 168
145 169 return doc
146 170
147 171 helptable = (
148 172 (["dates"], _("Date Formats"),
149 173 _(r'''
150 174 Some commands allow the user to specify a date, e.g.:
151 175 * backout, commit, import, tag: Specify the commit date.
152 176 * log, revert, update: Select revision(s) by date.
153 177
154 178 Many date formats are valid. Here are some examples:
155 179
156 180 "Wed Dec 6 13:18:29 2006" (local timezone assumed)
157 181 "Dec 6 13:18 -0600" (year assumed, time offset provided)
158 182 "Dec 6 13:18 UTC" (UTC and GMT are aliases for +0000)
159 183 "Dec 6" (midnight)
160 184 "13:18" (today assumed)
161 185 "3:39" (3:39AM assumed)
162 186 "3:39pm" (15:39)
163 187 "2006-12-06 13:18:29" (ISO 8601 format)
164 188 "2006-12-6 13:18"
165 189 "2006-12-6"
166 190 "12-6"
167 191 "12/6"
168 192 "12/6/6" (Dec 6 2006)
169 193
170 194 Lastly, there is Mercurial's internal format:
171 195
172 196 "1165432709 0" (Wed Dec 6 13:18:29 2006 UTC)
173 197
174 198 This is the internal representation format for dates. unixtime is
175 199 the number of seconds since the epoch (1970-01-01 00:00 UTC).
176 200 offset is the offset of the local timezone, in seconds west of UTC
177 201 (negative if the timezone is east of UTC).
178 202
179 203 The log command also accepts date ranges:
180 204
181 205 "<{datetime}" - at or before a given date/time
182 206 ">{datetime}" - on or after a given date/time
183 207 "{datetime} to {datetime}" - a date range, inclusive
184 208 "-{days}" - within a given number of days of today
185 209 ''')),
186 210
187 211 (["patterns"], _("File Name Patterns"),
188 212 _(r'''
189 213 Mercurial accepts several notations for identifying one or more
190 214 files at a time.
191 215
192 216 By default, Mercurial treats filenames as shell-style extended
193 217 glob patterns.
194 218
195 219 Alternate pattern notations must be specified explicitly.
196 220
197 221 To use a plain path name without any pattern matching, start it
198 222 with "path:". These path names must completely match starting at
199 223 the current repository root.
200 224
201 225 To use an extended glob, start a name with "glob:". Globs are
202 226 rooted at the current directory; a glob such as "*.c" will only
203 227 match files in the current directory ending with ".c".
204 228
205 229 The supported glob syntax extensions are "**" to match any string
206 230 across path separators and "{a,b}" to mean "a or b".
207 231
208 232 To use a Perl/Python regular expression, start a name with "re:".
209 233 Regexp pattern matching is anchored at the root of the repository.
210 234
211 235 Plain examples:
212 236
213 237 path:foo/bar a name bar in a directory named foo in the root of
214 238 the repository
215 239 path:path:name a file or directory named "path:name"
216 240
217 241 Glob examples:
218 242
219 243 glob:*.c any name ending in ".c" in the current directory
220 244 *.c any name ending in ".c" in the current directory
221 245 **.c any name ending in ".c" in any subdirectory of the
222 246 current directory including itself.
223 247 foo/*.c any name ending in ".c" in the directory foo
224 248 foo/**.c any name ending in ".c" in any subdirectory of foo
225 249 including itself.
226 250
227 251 Regexp examples:
228 252
229 253 re:.*\.c$ any name ending in ".c", anywhere in the repository
230 254
231 255 ''')),
232 256
233 257 (['environment', 'env'], _('Environment Variables'),
234 258 _(r'''
235 259 HG::
236 260 Path to the 'hg' executable, automatically passed when running
237 261 hooks, extensions or external tools. If unset or empty, this is
238 262 the hg executable's name if it's frozen, or an executable named
239 263 'hg' (with %PATHEXT% [defaulting to COM/EXE/BAT/CMD] extensions on
240 264 Windows) is searched.
241 265
242 266 HGEDITOR::
243 267 This is the name of the editor to run when committing. See EDITOR.
244 268
245 269 (deprecated, use .hgrc)
246 270
247 271 HGENCODING::
248 272 This overrides the default locale setting detected by Mercurial.
249 273 This setting is used to convert data including usernames,
250 274 changeset descriptions, tag names, and branches. This setting can
251 275 be overridden with the --encoding command-line option.
252 276
253 277 HGENCODINGMODE::
254 278 This sets Mercurial's behavior for handling unknown characters
255 279 while transcoding user input. The default is "strict", which
256 280 causes Mercurial to abort if it can't map a character. Other
257 281 settings include "replace", which replaces unknown characters, and
258 282 "ignore", which drops them. This setting can be overridden with
259 283 the --encodingmode command-line option.
260 284
261 285 HGMERGE::
262 286 An executable to use for resolving merge conflicts. The program
263 287 will be executed with three arguments: local file, remote file,
264 288 ancestor file.
265 289
266 290 (deprecated, use .hgrc)
267 291
268 292 HGRCPATH::
269 293 A list of files or directories to search for hgrc files. Item
270 294 separator is ":" on Unix, ";" on Windows. If HGRCPATH is not set,
271 295 platform default search path is used. If empty, only the .hg/hgrc
272 296 from the current repository is read.
273 297
274 298 For each element in HGRCPATH:
275 299 * if it's a directory, all files ending with .rc are added
276 300 * otherwise, the file itself will be added
277 301
278 302 HGUSER::
279 303 This is the string used as the author of a commit. If not set,
280 304 available values will be considered in this order:
281 305
282 306 * HGUSER (deprecated)
283 307 * hgrc files from the HGRCPATH
284 308 * EMAIL
285 309 * interactive prompt
286 310 * LOGNAME (with '@hostname' appended)
287 311
288 312 (deprecated, use .hgrc)
289 313
290 314 EMAIL::
291 315 May be used as the author of a commit; see HGUSER.
292 316
293 317 LOGNAME::
294 318 May be used as the author of a commit; see HGUSER.
295 319
296 320 VISUAL::
297 321 This is the name of the editor to use when committing. See EDITOR.
298 322
299 323 EDITOR::
300 324 Sometimes Mercurial needs to open a text file in an editor for a
301 325 user to modify, for example when writing commit messages. The
302 326 editor it uses is determined by looking at the environment
303 327 variables HGEDITOR, VISUAL and EDITOR, in that order. The first
304 328 non-empty one is chosen. If all of them are empty, the editor
305 329 defaults to 'vi'.
306 330
307 331 PYTHONPATH::
308 332 This is used by Python to find imported modules and may need to be
309 333 set appropriately if this Mercurial is not installed system-wide.
310 334 ''')),
311 335
312 336 (['revs', 'revisions'], _('Specifying Single Revisions'),
313 337 _(r'''
314 338 Mercurial supports several ways to specify individual revisions.
315 339
316 340 A plain integer is treated as a revision number. Negative integers
317 341 are treated as topological offsets from the tip, with -1 denoting
318 342 the tip. As such, negative numbers are only useful if you've
319 343 memorized your local tree numbers and want to save typing a single
320 344 digit. This editor suggests copy and paste.
321 345
322 346 A 40-digit hexadecimal string is treated as a unique revision
323 347 identifier.
324 348
325 349 A hexadecimal string less than 40 characters long is treated as a
326 350 unique revision identifier, and referred to as a short-form
327 351 identifier. A short-form identifier is only valid if it is the
328 352 prefix of exactly one full-length identifier.
329 353
330 354 Any other string is treated as a tag name, which is a symbolic
331 355 name associated with a revision identifier. Tag names may not
332 356 contain the ":" character.
333 357
334 358 The reserved name "tip" is a special tag that always identifies
335 359 the most recent revision.
336 360
337 361 The reserved name "null" indicates the null revision. This is the
338 362 revision of an empty repository, and the parent of revision 0.
339 363
340 364 The reserved name "." indicates the working directory parent. If
341 365 no working directory is checked out, it is equivalent to null. If
342 366 an uncommitted merge is in progress, "." is the revision of the
343 367 first parent.
344 368 ''')),
345 369
346 370 (['mrevs', 'multirevs'], _('Specifying Multiple Revisions'),
347 371 _(r'''
348 372 When Mercurial accepts more than one revision, they may be
349 373 specified individually, or provided as a topologically continuous
350 374 range, separated by the ":" character.
351 375
352 376 The syntax of range notation is [BEGIN]:[END], where BEGIN and END
353 377 are revision identifiers. Both BEGIN and END are optional. If
354 378 BEGIN is not specified, it defaults to revision number 0. If END
355 379 is not specified, it defaults to the tip. The range ":" thus means
356 380 "all revisions".
357 381
358 382 If BEGIN is greater than END, revisions are treated in reverse
359 383 order.
360 384
361 385 A range acts as a closed interval. This means that a range of 3:5
362 386 gives 3, 4 and 5. Similarly, a range of 9:6 gives 9, 8, 7, and 6.
363 387 ''')),
364 388
365 389 (['diffs'], _('Diff Formats'),
366 390 _(r'''
367 391 Mercurial's default format for showing changes between two
368 392 versions of a file is compatible with the unified format of GNU
369 393 diff, which can be used by GNU patch and many other standard
370 394 tools.
371 395
372 396 While this standard format is often enough, it does not encode the
373 397 following information:
374 398
375 399 - executable status and other permission bits
376 400 - copy or rename information
377 401 - changes in binary files
378 402 - creation or deletion of empty files
379 403
380 404 Mercurial also supports the extended diff format from the git VCS
381 405 which addresses these limitations. The git diff format is not
382 406 produced by default because a few widespread tools still do not
383 407 understand this format.
384 408
385 409 This means that when generating diffs from a Mercurial repository
386 410 (e.g. with "hg export"), you should be careful about things like
387 411 file copies and renames or other things mentioned above, because
388 412 when applying a standard diff to a different repository, this
389 413 extra information is lost. Mercurial's internal operations (like
390 414 push and pull) are not affected by this, because they use an
391 415 internal binary format for communicating changes.
392 416
393 417 To make Mercurial produce the git extended diff format, use the
394 418 --git option available for many commands, or set 'git = True' in
395 419 the [diff] section of your hgrc. You do not need to set this
396 420 option when importing diffs in this format or using them in the mq
397 421 extension.
398 422 ''')),
399 423 (['templating'], _('Template Usage'),
400 424 _(r'''
401 425 Mercurial allows you to customize output of commands through
402 426 templates. You can either pass in a template from the command
403 427 line, via the --template option, or select an existing
404 428 template-style (--style).
405 429
406 430 You can customize output for any "log-like" command: log,
407 431 outgoing, incoming, tip, parents, heads and glog.
408 432
409 433 Three styles are packaged with Mercurial: default (the style used
410 434 when no explicit preference is passed), compact and changelog.
411 435 Usage:
412 436
413 437 $ hg log -r1 --style changelog
414 438
415 439 A template is a piece of text, with markup to invoke variable
416 440 expansion:
417 441
418 442 $ hg log -r1 --template "{node}\n"
419 443 b56ce7b07c52de7d5fd79fb89701ea538af65746
420 444
421 445 Strings in curly braces are called keywords. The availability of
422 446 keywords depends on the exact context of the templater. These
423 447 keywords are usually available for templating a log-like command:
424 448
425 449 - author: String. The unmodified author of the changeset.
426 450 - branches: String. The name of the branch on which the changeset
427 451 was committed. Will be empty if the branch name was default.
428 452 - date: Date information. The date when the changeset was committed.
429 453 - desc: String. The text of the changeset description.
430 454 - diffstat: String. Statistics of changes with the following
431 455 format: "modified files: +added/-removed lines"
432 456 - files: List of strings. All files modified, added, or removed by
433 457 this changeset.
434 458 - file_adds: List of strings. Files added by this changeset.
435 459 - file_mods: List of strings. Files modified by this changeset.
436 460 - file_dels: List of strings. Files removed by this changeset.
437 461 - node: String. The changeset identification hash, as a
438 462 40-character hexadecimal string.
439 463 - parents: List of strings. The parents of the changeset.
440 464 - rev: Integer. The repository-local changeset revision number.
441 465 - tags: List of strings. Any tags associated with the changeset.
442 466
443 467 The "date" keyword does not produce human-readable output. If you
444 468 want to use a date in your output, you can use a filter to process
445 469 it. Filters are functions which return a string based on the input
446 470 variable. You can also use a chain of filters to get the desired
447 471 output:
448 472
449 473 $ hg tip --template "{date|isodate}\n"
450 474 2008-08-21 18:22 +0000
451 475
452 476 List of filters:
453 477
454 478 - addbreaks: Any text. Add an XHTML "<br />" tag before the end of
455 479 every line except the last.
456 480 - age: Date. Returns a human-readable date/time difference between
457 481 the given date/time and the current date/time.
458 482 - basename: Any text. Treats the text as a path, and returns the
459 483 last component of the path after splitting by the path
460 484 separator (ignoring trailing separators). For example,
461 485 "foo/bar/baz" becomes "baz" and "foo/bar//" becomes "bar".
462 486 - stripdir: Treat the text as path and strip a directory level, if
463 487 possible. For example, "foo" and "foo/bar" becomes "foo".
464 488 - date: Date. Returns a date in a Unix date format, including
465 489 the timezone: "Mon Sep 04 15:13:13 2006 0700".
466 490 - domain: Any text. Finds the first string that looks like an
467 491 email address, and extracts just the domain component.
468 492 Example: 'User <user@example.com>' becomes 'example.com'.
469 493 - email: Any text. Extracts the first string that looks like an
470 494 email address. Example: 'User <user@example.com>' becomes
471 495 'user@example.com'.
472 496 - escape: Any text. Replaces the special XML/XHTML characters "&",
473 497 "<" and ">" with XML entities.
474 498 - fill68: Any text. Wraps the text to fit in 68 columns.
475 499 - fill76: Any text. Wraps the text to fit in 76 columns.
476 500 - firstline: Any text. Returns the first line of text.
477 501 - nonempty: Any text. Returns '(none)' if the string is empty.
478 502 - hgdate: Date. Returns the date as a pair of numbers:
479 503 "1157407993 25200" (Unix timestamp, timezone offset).
480 504 - isodate: Date. Returns the date in ISO 8601 format.
481 505 - localdate: Date. Converts a date to local date.
482 506 - obfuscate: Any text. Returns the input text rendered as a
483 507 sequence of XML entities.
484 508 - person: Any text. Returns the text before an email address.
485 509 - rfc822date: Date. Returns a date using the same format used
486 510 in email headers.
487 511 - short: Changeset hash. Returns the short form of a changeset
488 512 hash, i.e. a 12-byte hexadecimal string.
489 513 - shortdate: Date. Returns a date like "2006-09-18".
490 514 - strip: Any text. Strips all leading and trailing whitespace.
491 515 - tabindent: Any text. Returns the text, with every line except
492 516 the first starting with a tab character.
493 517 - urlescape: Any text. Escapes all "special" characters. For
494 518 example, "foo bar" becomes "foo%20bar".
495 519 - user: Any text. Returns the user portion of an email address.
496 520 ''')),
497 521
498 522 (['urls'], _('URL Paths'),
499 523 _(r'''
500 524 Valid URLs are of the form:
501 525
502 526 local/filesystem/path (or file://local/filesystem/path)
503 527 http://[user[:pass]@]host[:port]/[path]
504 528 https://[user[:pass]@]host[:port]/[path]
505 529 ssh://[user[:pass]@]host[:port]/[path]
506 530
507 531 Paths in the local filesystem can either point to Mercurial
508 532 repositories or to bundle files (as created by 'hg bundle' or
509 533 'hg incoming --bundle').
510 534
511 535 An optional identifier after # indicates a particular branch, tag,
512 536 or changeset to use from the remote repository.
513 537
514 538 Some features, such as pushing to http:// and https:// URLs are
515 539 only possible if the feature is explicitly enabled on the remote
516 540 Mercurial server.
517 541
518 542 Some notes about using SSH with Mercurial:
519 543 - SSH requires an accessible shell account on the destination
520 544 machine and a copy of hg in the remote path or specified with as
521 545 remotecmd.
522 546 - path is relative to the remote user's home directory by default.
523 547 Use an extra slash at the start of a path to specify an absolute path:
524 548 ssh://example.com//tmp/repository
525 549 - Mercurial doesn't use its own compression via SSH; the right
526 550 thing to do is to configure it in your ~/.ssh/config, e.g.:
527 551 Host *.mylocalnetwork.example.com
528 552 Compression no
529 553 Host *
530 554 Compression yes
531 555 Alternatively specify "ssh -C" as your ssh command in your hgrc
532 556 or with the --ssh command line option.
533 557
534 558 These URLs can all be stored in your hgrc with path aliases under
535 559 the [paths] section like so:
536 560 [paths]
537 561 alias1 = URL1
538 562 alias2 = URL2
539 563 ...
540 564
541 565 You can then use the alias for any command that uses a URL (for
542 566 example 'hg pull alias1' would pull from the 'alias1' path).
543 567
544 568 Two path aliases are special because they are used as defaults
545 569 when you do not provide the URL to a command:
546 570
547 571 default:
548 572 When you create a repository with hg clone, the clone command
549 573 saves the location of the source repository as the new
550 574 repository's 'default' path. This is then used when you omit
551 575 path from push- and pull-like commands (including incoming and
552 576 outgoing).
553 577
554 578 default-push:
555 579 The push command will look for a path named 'default-push', and
556 580 prefer it over 'default' if both are defined.
557 581 ''')),
558 582 (["extensions"], _("Using additional features"), topicextensions),
559 583 )
General Comments 0
You need to be logged in to leave comments. Login now