1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
|
# Copyright (C) 2006 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""A collection of extra help information for using bzr.
Help topics are meant to be help for items that aren't commands, but will
help bzr become fully learnable without referring to a tutorial.
Limited formatting of help text is permitted to make the text useful
both within the reference manual (reStructuredText) and on the screen.
The help text should be reStructuredText with formatting kept to a
minimum and, in particular, no headings. The onscreen renderer applies
the following simple rules before rendering the text:
1. A '::' appearing on the end of a line is replaced with ':'.
2. Lines starting with a ':' have it stripped.
These rules mean that literal blocks and field lists respectively can
be used in the help text, producing sensible input to a manual while
rendering on the screen naturally.
"""
from bzrlib import registry
# Section identifiers (map topics to the right place in the manual)
SECT_COMMAND = "command"
SECT_CONCEPT = "concept"
SECT_HIDDEN = "hidden"
SECT_LIST = "list"
SECT_PLUGIN = "plugin"
class HelpTopicRegistry(registry.Registry):
"""A Registry customized for handling help topics."""
def register(self, topic, detail, summary, section=SECT_LIST):
"""Register a new help topic.
:param topic: Name of documentation entry
:param detail: Function or string object providing detailed
documentation for topic. Function interface is detail(topic).
This should return a text string of the detailed information.
See the module documentation for details on help text formatting.
:param summary: String providing single-line documentation for topic.
:param section: Section in reference manual - see SECT_* identifiers.
"""
# The detail is stored as the 'object' and the metadata as the info
info=(summary,section)
super(HelpTopicRegistry, self).register(topic, detail, info=info)
def register_lazy(self, topic, module_name, member_name, summary,
section=SECT_LIST):
"""Register a new help topic, and import the details on demand.
:param topic: Name of documentation entry
:param module_name: The module to find the detailed help.
:param member_name: The member of the module to use for detailed help.
:param summary: String providing single-line documentation for topic.
:param section: Section in reference manual - see SECT_* identifiers.
"""
# The detail is stored as the 'object' and the metadata as the info
info=(summary,section)
super(HelpTopicRegistry, self).register_lazy(topic, module_name,
member_name, info=info)
def get_detail(self, topic):
"""Get the detailed help on a given topic."""
obj = self.get(topic)
if callable(obj):
return obj(topic)
else:
return obj
def get_summary(self, topic):
"""Get the single line summary for the topic."""
info = self.get_info(topic)
if info is None:
return None
else:
return info[0]
def get_section(self, topic):
"""Get the section for the topic."""
info = self.get_info(topic)
if info is None:
return None
else:
return info[1]
def get_topics_for_section(self, section):
"""Get the set of topics in a section."""
result = set()
for topic in self.keys():
if section == self.get_section(topic):
result.add(topic)
return result
topic_registry = HelpTopicRegistry()
#----------------------------------------------------
def _help_on_topics(dummy):
"""Write out the help for topics to outfile"""
topics = topic_registry.keys()
lmax = max(len(topic) for topic in topics)
out = []
for topic in topics:
summary = topic_registry.get_summary(topic)
out.append("%-*s %s\n" % (lmax, topic, summary))
return ''.join(out)
def _help_on_revisionspec(name):
"""Generate the help for revision specs."""
import re
import bzrlib.revisionspec
out = []
out.append("Revision Identifiers\n")
out.append("A revision, or a range bound, can be one of the following.\n")
details = []
details.append("\nFurther details are given below.\n")
# The help text is indented 4 spaces - this re cleans that up below
indent_re = re.compile(r'^ ', re.MULTILINE)
for i in bzrlib.revisionspec.SPEC_TYPES:
doc = i.help_txt
if doc == bzrlib.revisionspec.RevisionSpec.help_txt:
summary = "N/A"
doc = summary + "\n"
else:
# Extract out the top line summary from the body and
# clean-up the unwanted whitespace
summary,doc = doc.split("\n", 1)
#doc = indent_re.sub('', doc)
while (doc[-2:] == '\n\n' or doc[-1:] == ' '):
doc = doc[:-1]
# Note: The leading : here are HACKs to get reStructuredText
# 'field' formatting - we know that the prefix ends in a ':'.
out.append(":%s\n\t%s" % (i.prefix, summary))
details.append(":%s\n%s" % (i.prefix, doc))
return '\n'.join(out + details)
def _help_on_transport(name):
from bzrlib.transport import (
transport_list_registry,
)
import textwrap
def add_string(proto, help, maxl, prefix_width=20):
help_lines = textwrap.wrap(help, maxl - prefix_width)
line_with_indent = '\n' + ' ' * prefix_width
help_text = line_with_indent.join(help_lines)
return "%-20s%s\n" % (proto, help_text)
def sort_func(a,b):
a1 = a[:a.rfind("://")]
b1 = b[:b.rfind("://")]
if a1>b1:
return +1
elif a1<b1:
return -1
else:
return 0
protl = []
decl = []
protos = transport_list_registry.keys( )
protos.sort(sort_func)
for proto in protos:
shorthelp = transport_list_registry.get_help(proto)
if not shorthelp:
continue
if proto.endswith("://"):
protl.append(add_string(proto, shorthelp, 79))
else:
decl.append(add_string(proto, shorthelp, 79))
out = "URL Identifiers\n\n" + \
"Supported URL prefixes::\n\n " + \
' '.join(protl)
if len(decl):
out += "\nSupported modifiers::\n\n " + \
' '.join(decl)
return out
_basic_help = \
"""Bazaar -- a free distributed version-control tool
http://bazaar-vcs.org/
Basic commands:
bzr init makes this directory a versioned branch
bzr branch make a copy of another branch
bzr add make files or directories versioned
bzr ignore ignore a file or pattern
bzr mv move or rename a versioned file
bzr status summarize changes in working copy
bzr diff show detailed diffs
bzr merge pull in changes from another branch
bzr commit save some or all changes
bzr log show history of changes
bzr check validate storage
bzr help init more help on e.g. init command
bzr help commands list all commands
bzr help topics list all help topics
"""
_global_options = \
"""Global Options
These options may be used with any command, and may appear in front of any
command. (e.g. "bzr --profile help").
--version Print the version number. Must be supplied before the command.
--no-aliases Do not process command aliases when running this command.
--builtin Use the built-in version of a command, not the plugin version.
This does not suppress other plugin effects.
--no-plugins Do not process any plugins.
--profile Profile execution using the hotshot profiler.
--lsprof Profile execution using the lsprof profiler.
--lsprof-file Profile execution using the lsprof profiler, and write the
results to a specified file. If the filename ends with ".txt",
text format will be used. If the filename either starts with
"callgrind.out" or end with ".callgrind", the output will be
formatted for use with KCacheGrind. Otherwise, the output
will be a pickle.
See doc/developers/profiling.txt for more information on profiling.
A number of debug flags are also available to assist troubleshooting and
development.
-Dauth Trace authentication sections used.
-Derror Instead of normal error handling, always print a traceback on
error.
-Devil Capture call sites that do expensive or badly-scaling
operations.
-Dhashcache Log every time a working file is read to determine its hash.
-Dhooks Trace hook execution.
-Dhttp Trace http connections, requests and responses
-Dhpss Trace smart protocol requests and responses.
-Dindex Trace major index operations.
-Dlock Trace when lockdir locks are taken or released.
-Dmerge Emit information for debugging merges.
"""
_standard_options = \
"""Standard Options
Standard options are legal for all commands.
--help, -h Show help message.
--verbose, -v Display more information.
--quiet, -q Only display errors and warnings.
Unlike global options, standard options can be used in aliases.
"""
_checkouts = \
"""Checkouts
Checkouts are source trees that are connected to a branch, so that when
you commit in the source tree, the commit goes into that branch. They
allow you to use a simpler, more centralized workflow, ignoring some of
Bazaar's decentralized features until you want them. Using checkouts
with shared repositories is very similar to working with SVN or CVS, but
doesn't have the same restrictions. And using checkouts still allows
others working on the project to use whatever workflow they like.
A checkout is created with the bzr checkout command (see "help checkout").
You pass it a reference to another branch, and it will create a local copy
for you that still contains a reference to the branch you created the
checkout from (the master branch). Then if you make any commits they will be
made on the other branch first. This creates an instant mirror of your work, or
facilitates lockstep development, where each developer is working together,
continuously integrating the changes of others.
However the checkout is still a first class branch in Bazaar terms, so that
you have the full history locally. As you have a first class branch you can
also commit locally if you want, for instance due to the temporary loss af a
network connection. Use the --local option to commit to do this. All the local
commits will then be made on the master branch the next time you do a non-local
commit.
If you are using a checkout from a shared branch you will periodically want to
pull in all the changes made by others. This is done using the "update"
command. The changes need to be applied before any non-local commit, but
Bazaar will tell you if there are any changes and suggest that you use this
command when needed.
It is also possible to create a "lightweight" checkout by passing the
--lightweight flag to checkout. A lightweight checkout is even closer to an
SVN checkout in that it is not a first class branch, it mainly consists of the
working tree. This means that any history operations must query the master
branch, which could be slow if a network connection is involved. Also, as you
don't have a local branch, then you cannot commit locally.
Lightweight checkouts work best when you have fast reliable access to the
master branch. This means that if the master branch is on the same disk or LAN
a lightweight checkout will be faster than a heavyweight one for any commands
that modify the revision history (as only one copy branch needs to be updated).
Heavyweight checkouts will generally be faster for any command that uses the
history but does not change it, but if the master branch is on the same disk
then there wont be a noticeable difference.
Another possible use for a checkout is to use it with a treeless repository
containing your branches, where you maintain only one working tree by
switching the master branch that the checkout points to when you want to
work on a different branch.
Obviously to commit on a checkout you need to be able to write to the master
branch. This means that the master branch must be accessible over a writeable
protocol , such as sftp://, and that you have write permissions at the other
end. Checkouts also work on the local file system, so that all that matters is
file permissions.
You can change the master of a checkout by using the "bind" command (see "help
bind"). This will change the location that the commits are sent to. The bind
command can also be used to turn a branch into a heavy checkout. If you
would like to convert your heavy checkout into a normal branch so that every
commit is local, you can use the "unbind" command.
Related commands::
checkout Create a checkout. Pass --lightweight to get a lightweight
checkout
update Pull any changes in the master branch in to your checkout
commit Make a commit that is sent to the master branch. If you have
a heavy checkout then the --local option will commit to the
checkout without sending the commit to the master
bind Change the master branch that the commits in the checkout will
be sent to
unbind Turn a heavy checkout into a standalone branch so that any
commits are only made locally
"""
_repositories = \
"""Repositories
Repositories in Bazaar are where committed information is stored. There is
a repository associated with every branch.
Repositories are a form of database. Bzr will usually maintain this for
good performance automatically, but in some situations (e.g. when doing
very many commits in a short time period) you may want to ask bzr to
optimise the database indices. This can be done by the 'bzr pack' command.
By default just running 'bzr init' will create a repository within the new
branch but it is possible to create a shared repository which allows multiple
branches to share their information in the same location. When a new branch is
created it will first look to see if there is a containing shared repository it
can use.
When two branches of the same project share a repository, there is
generally a large space saving. For some operations (e.g. branching
within the repository) this translates in to a large time saving.
To create a shared repository use the init-repository command (or the alias
init-repo). This command takes the location of the repository to create. This
means that 'bzr init-repository repo' will create a directory named 'repo',
which contains a shared repository. Any new branches that are created in this
directory will then use it for storage.
It is a good idea to create a repository whenever you might create more
than one branch of a project. This is true for both working areas where you
are doing the development, and any server areas that you use for hosting
projects. In the latter case, it is common to want branches without working
trees. Since the files in the branch will not be edited directly there is no
need to use up disk space for a working tree. To create a repository in which
the branches will not have working trees pass the '--no-trees' option to
'init-repository'.
Related commands::
init-repository Create a shared repository. Use --no-trees to create one
in which new branches won't get a working tree.
"""
_working_trees = \
"""Working Trees
A working tree is the contents of a branch placed on disk so that you can
see the files and edit them. The working tree is where you make changes to a
branch, and when you commit the current state of the working tree is the
snapshot that is recorded in the commit.
When you push a branch to a remote system, a working tree will not be
created. If one is already present the files will not be updated. The
branch information will be updated and the working tree will be marked
as out-of-date. Updating a working tree remotely is difficult, as there
may be uncommitted changes or the update may cause content conflicts that are
difficult to deal with remotely.
If you have a branch with no working tree you can use the 'checkout' command
to create a working tree. If you run 'bzr checkout .' from the branch it will
create the working tree. If the branch is updated remotely, you can update the
working tree by running 'bzr update' in that directory.
If you have a branch with a working tree that you do not want the 'remove-tree'
command will remove the tree if it is safe. This can be done to avoid the
warning about the remote working tree not being updated when pushing to the
branch. It can also be useful when working with a '--no-trees' repository
(see 'bzr help repositories').
If you want to have a working tree on a remote machine that you push to you
can either run 'bzr update' in the remote branch after each push, or use some
other method to update the tree during the push. There is an 'rspush' plugin
that will update the working tree using rsync as well as doing a push. There
is also a 'push-and-update' plugin that automates running 'bzr update' via SSH
after each push.
Useful commands::
checkout Create a working tree when a branch does not have one.
remove-tree Removes the working tree from a branch when it is safe to do so.
update When a working tree is out of sync with it's associated branch
this will update the tree to match the branch.
"""
_branches = \
"""Branches
A branch consists of the state of a project, including all of its
history. All branches have a repository associated (which is where the
branch history is stored), but multiple branches may share the same
repository (a shared repository). Branches can be copied and merged.
Related commands::
init Make a directory into a versioned branch.
branch Create a new copy of a branch.
merge Perform a three-way merge.
"""
_standalone_trees = \
"""Standalone Trees
A standalone tree is a working tree with an associated repository. It
is an independently usable branch, with no dependencies on any other.
Creating a standalone tree (via bzr init) is the quickest way to put
an existing project under version control.
Related Commands::
init Make a directory into a versioned branch.
"""
_status_flags = \
"""Status Flags
Status flags are used to summarise changes to the working tree in a concise
manner. They are in the form::
xxx <filename>
where the columns' meanings are as follows.
Column 1 - versioning/renames::
+ File versioned
- File unversioned
R File renamed
? File unknown
C File has conflicts
P Entry for a pending merge (not a file)
Column 2 - contents::
N File created
D File deleted
K File kind changed
M File modified
Column 3 - execute::
* The execute bit was changed
"""
_env_variables = \
"""Environment Variables
================ =================================================================
BZRPATH Path where bzr is to look for shell plugin external commands.
BZR_EMAIL E-Mail address of the user. Overrides EMAIL.
EMAIL E-Mail address of the user.
BZR_EDITOR Editor for editing commit messages. Overrides EDITOR.
EDITOR Editor for editing commit messages.
BZR_PLUGIN_PATH Paths where bzr should look for plugins.
BZR_HOME Directory holding .bazaar config dir. Overrides HOME.
BZR_HOME (Win32) Directory holding bazaar config dir. Overrides APPDATA and HOME.
BZR_REMOTE_PATH Full name of remote 'bzr' command (for bzr+ssh:// URLs).
================ =================================================================
"""
_files = \
r"""Files
:On Linux: ~/.bazaar/bazaar.conf
:On Windows: C:\\Documents and Settings\\username\\Application Data\\bazaar\\2.0\\bazaar.conf
Contains the user's default configuration. The section ``[DEFAULT]`` is
used to define general configuration that will be applied everywhere.
The section ``[ALIASES]`` can be used to create command aliases for
commonly used options.
A typical config file might look something like::
[DEFAULT]
email=John Doe <jdoe@isp.com>
[ALIASES]
commit = commit --strict
log10 = log --short -r -10..-1
"""
_criss_cross = \
"""
A criss-cross in the branch history can cause the default merge technique
to emit more conflicts than would normally be expected.
If you encounter criss-crosses, you can use merge --weave instead, which
should provide a much better result.
Criss-crosses occur in a branch's history if two branches merge the same thing
and then merge one another, or if two branches merge one another at the same
time. They can be avoided by having each branch only merge from or into a
designated central branch (a "star topology").
Criss-crosses cause problems because of the way merge works. Bazaar's default
merge is a three-way merger; in order to merge OTHER into THIS, it must
find a basis for comparison, BASE. Using BASE, it can determine whether
differences between THIS and OTHER are due to one side adding lines, or
from another side removing lines.
Criss-crosses mean there is no good choice for a base. Selecting the recent
merge points could cause one side's changes to be silently discarded.
Selecting older merge points (which Bazaar does) mean that extra conflicts
are emitted.
The ``weave`` merge type is not affected by this problem because it uses
line-origin detection instead of a basis revision to determine the cause of
differences."""
# Register help topics
topic_registry.register("revisionspec", _help_on_revisionspec,
"Explain how to use --revision")
topic_registry.register('basic', _basic_help, "Basic commands", SECT_HIDDEN)
topic_registry.register('topics', _help_on_topics, "Topics list", SECT_HIDDEN)
def get_format_topic(topic):
from bzrlib import bzrdir
return "Storage Formats\n\n" + bzrdir.format_registry.help_topic(topic)
topic_registry.register('formats', get_format_topic, 'Directory formats')
topic_registry.register('standard-options', _standard_options,
'Options that can be used with any command')
topic_registry.register('global-options', _global_options,
'Options that control how Bazaar runs')
topic_registry.register('urlspec', _help_on_transport,
"Supported transport protocols")
topic_registry.register('status-flags', _status_flags,
"Help on status flags")
def get_bugs_topic(topic):
from bzrlib import bugtracker
return "Bug Trackers\n\n" + bugtracker.tracker_registry.help_topic(topic)
topic_registry.register('bugs', get_bugs_topic, 'Bug tracker support')
topic_registry.register('env-variables', _env_variables,
'Environment variable names and values')
topic_registry.register('files', _files,
'Information on configuration and log files')
# Register concept topics.
# Note that we might choose to remove these from the online help in the
# future or implement them via loading content from files. In the meantime,
# please keep them concise.
topic_registry.register('branches', _branches,
'Information on what a branch is', SECT_CONCEPT)
topic_registry.register('checkouts', _checkouts,
'Information on what a checkout is', SECT_CONCEPT)
topic_registry.register('repositories', _repositories,
'Basic information on shared repositories.',
SECT_CONCEPT)
topic_registry.register('standalone-trees', _standalone_trees,
'Information on what a standalone tree is',
SECT_CONCEPT)
topic_registry.register('working-trees', _working_trees,
'Information on working trees', SECT_CONCEPT)
topic_registry.register('criss-cross', _criss_cross,
'Information on criss-cross merging', SECT_CONCEPT)
class HelpTopicIndex(object):
"""A index for bzr help that returns topics."""
def __init__(self):
self.prefix = ''
def get_topics(self, topic):
"""Search for topic in the HelpTopicRegistry.
:param topic: A topic to search for. None is treated as 'basic'.
:return: A list which is either empty or contains a single
RegisteredTopic entry.
"""
if topic is None:
topic = 'basic'
if topic in topic_registry:
return [RegisteredTopic(topic)]
else:
return []
class RegisteredTopic(object):
"""A help topic which has been registered in the HelpTopicRegistry.
These topics consist of nothing more than the name of the topic - all
data is retrieved on demand from the registry.
"""
def __init__(self, topic):
"""Constructor.
:param topic: The name of the topic that this represents.
"""
self.topic = topic
def get_help_text(self, additional_see_also=None, plain=True):
"""Return a string with the help for this topic.
:param additional_see_also: Additional help topics to be
cross-referenced.
:param plain: if False, raw help (reStructuredText) is
returned instead of plain text.
"""
result = topic_registry.get_detail(self.topic)
# there is code duplicated here and in bzrlib/plugin.py's
# matching Topic code. This should probably be factored in
# to a helper function and a common base class.
if additional_see_also is not None:
see_also = sorted(set(additional_see_also))
else:
see_also = None
if see_also:
result += '\n:See also: '
result += ', '.join(see_also)
result += '\n'
if plain:
result = help_as_plain_text(result)
return result
def get_help_topic(self):
"""Return the help topic this can be found under."""
return self.topic
def help_as_plain_text(text):
"""Minimal converter of reStructuredText to plain text."""
lines = text.splitlines()
result = []
for line in lines:
if line.startswith(':'):
line = line[1:]
elif line.endswith('::'):
line = line[:-1]
result.append(line)
return "\n".join(result) + "\n"
|