bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4763.2.4
by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry. |
1 |
# Copyright (C) 2005-2010 Canonical Ltd
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
2 |
#
|
77
by mbp at sourcefrog
- split info command out into separate file |
3 |
# This program is free software; you can redistribute it and/or modify
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
2052.3.1
by John Arbash Meinel
Add tests to cleanup the copyright of all source files |
7 |
#
|
77
by mbp at sourcefrog
- split info command out into separate file |
8 |
# This program is distributed in the hope that it will be useful,
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
2052.3.1
by John Arbash Meinel
Add tests to cleanup the copyright of all source files |
12 |
#
|
77
by mbp at sourcefrog
- split info command out into separate file |
13 |
# You should have received a copy of the GNU General Public License
|
14 |
# along with this program; if not, write to the Free Software
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
77
by mbp at sourcefrog
- split info command out into separate file |
16 |
|
6379.6.3
by Jelmer Vernooij
Use absolute_import. |
17 |
from __future__ import absolute_import |
18 |
||
1534.5.1
by Robert Collins
Give info some reasonable output and tests. |
19 |
__all__ = ['show_bzrdir_info'] |
20 |
||
6963.2.18
by Jelmer Vernooij
Add bees to some of bp.weave_fmt. |
21 |
from io import StringIO |
77
by mbp at sourcefrog
- split info command out into separate file |
22 |
import time |
1551.15.43
by Aaron Bentley
Provide ways of getting at unicode-clean output |
23 |
import sys |
1534.5.1
by Robert Collins
Give info some reasonable output and tests. |
24 |
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
25 |
from . import ( |
6734.1.11
by Jelmer Vernooij
Move UnstackableBranchFormat. |
26 |
branch as _mod_branch, |
6207.3.3
by jelmer at samba
Fix tests and the like. |
27 |
controldir, |
1551.15.41
by Aaron Bentley
Make info provide more related brances, and format all branches nicely |
28 |
errors, |
4307.3.1
by Jelmer Vernooij
Allow registering hooks that extend the Repository section in 'bzr info -v'. |
29 |
hooks as _mod_hooks, |
1551.9.22
by Aaron Bentley
Use urlutils for info. Fixes bug #76229 |
30 |
osutils, |
31 |
urlutils, |
|
32 |
)
|
|
6670.4.1
by Jelmer Vernooij
Update imports. |
33 |
from .bzr import ( |
34 |
bzrdir, |
|
35 |
)
|
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
36 |
from .errors import (NoWorkingTree, NotBranchError, |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
37 |
NoRepositoryPresent, NotLocalUrl) |
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
38 |
from .missing import find_unmerged |
77
by mbp at sourcefrog
- split info command out into separate file |
39 |
|
462
by Martin Pool
- New form 'file_id in tree' to check if the file is present |
40 |
|
6985
by Jelmer Vernooij
Merge lp:~jelmer/brz/python3-weave-fmt. |
41 |
def plural(n, base=u'', pl=None): |
1563.2.28
by Robert Collins
Add total_size to the revision_store api. |
42 |
if n == 1: |
43 |
return base |
|
1963.2.6
by Robey Pointer
pychecker is on crack; go back to using 'is None'. |
44 |
elif pl is not None: |
1563.2.28
by Robert Collins
Add total_size to the revision_store api. |
45 |
return pl |
46 |
else: |
|
6985
by Jelmer Vernooij
Merge lp:~jelmer/brz/python3-weave-fmt. |
47 |
return u's' |
1563.2.28
by Robert Collins
Add total_size to the revision_store api. |
48 |
|
49 |
||
1551.15.41
by Aaron Bentley
Make info provide more related brances, and format all branches nicely |
50 |
class LocationList(object): |
51 |
||
52 |
def __init__(self, base_path): |
|
1551.15.43
by Aaron Bentley
Provide ways of getting at unicode-clean output |
53 |
self.locs = [] |
1551.15.41
by Aaron Bentley
Make info provide more related brances, and format all branches nicely |
54 |
self.base_path = base_path |
55 |
||
56 |
def add_url(self, label, url): |
|
1551.15.43
by Aaron Bentley
Provide ways of getting at unicode-clean output |
57 |
"""Add a URL to the list, converting it to a path if possible""" |
1551.15.41
by Aaron Bentley
Make info provide more related brances, and format all branches nicely |
58 |
if url is None: |
59 |
return
|
|
1551.15.43
by Aaron Bentley
Provide ways of getting at unicode-clean output |
60 |
try: |
61 |
path = urlutils.local_path_from_url(url) |
|
6729.6.1
by Jelmer Vernooij
Move urlutils errors. |
62 |
except urlutils.InvalidURL: |
1551.15.43
by Aaron Bentley
Provide ways of getting at unicode-clean output |
63 |
self.locs.append((label, url)) |
64 |
else: |
|
1551.15.41
by Aaron Bentley
Make info provide more related brances, and format all branches nicely |
65 |
self.add_path(label, path) |
2363.5.18
by Aaron Bentley
Get all tests passing |
66 |
|
67 |
def add_path(self, label, path): |
|
1551.15.43
by Aaron Bentley
Provide ways of getting at unicode-clean output |
68 |
"""Add a path, converting it to a relative path if possible""" |
1551.15.41
by Aaron Bentley
Make info provide more related brances, and format all branches nicely |
69 |
try: |
70 |
path = osutils.relpath(self.base_path, path) |
|
71 |
except errors.PathNotChild: |
|
72 |
pass
|
|
73 |
else: |
|
74 |
if path == '': |
|
75 |
path = '.' |
|
76 |
if path != '/': |
|
77 |
path = path.rstrip('/') |
|
1551.15.43
by Aaron Bentley
Provide ways of getting at unicode-clean output |
78 |
self.locs.append((label, path)) |
2363.5.18
by Aaron Bentley
Get all tests passing |
79 |
|
1551.15.43
by Aaron Bentley
Provide ways of getting at unicode-clean output |
80 |
def get_lines(self): |
81 |
max_len = max(len(l) for l, u in self.locs) |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
82 |
return [" %*s: %s\n" % (max_len, l, u) for l, u in self.locs] |
2363.5.18
by Aaron Bentley
Get all tests passing |
83 |
|
84 |
||
6241.4.1
by Jelmer Vernooij
Make gather_location_info understand control directories. |
85 |
def gather_location_info(repository=None, branch=None, working=None, |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
86 |
control=None): |
2363.5.18
by Aaron Bentley
Get all tests passing |
87 |
locs = {} |
88 |
if branch is not None: |
|
5158.6.6
by Martin Pool
Change info code to use user_url etc |
89 |
branch_path = branch.user_url |
2363.5.18
by Aaron Bentley
Get all tests passing |
90 |
master_path = branch.get_bound_location() |
91 |
if master_path is None: |
|
92 |
master_path = branch_path |
|
93 |
else: |
|
94 |
branch_path = None |
|
95 |
master_path = None |
|
6241.4.3
by Jelmer Vernooij
Add test for dangling tree references. |
96 |
try: |
97 |
if control is not None and control.get_branch_reference(): |
|
98 |
locs['checkout of branch'] = control.get_branch_reference() |
|
99 |
except NotBranchError: |
|
100 |
pass
|
|
2363.5.18
by Aaron Bentley
Get all tests passing |
101 |
if working: |
5158.6.6
by Martin Pool
Change info code to use user_url etc |
102 |
working_path = working.user_url |
1694.2.6
by Martin Pool
[merge] bzr.dev |
103 |
if working_path != branch_path: |
2363.5.18
by Aaron Bentley
Get all tests passing |
104 |
locs['light checkout root'] = working_path |
105 |
if master_path != branch_path: |
|
1694.2.6
by Martin Pool
[merge] bzr.dev |
106 |
if repository.is_shared(): |
2363.5.18
by Aaron Bentley
Get all tests passing |
107 |
locs['repository checkout root'] = branch_path |
1694.2.6
by Martin Pool
[merge] bzr.dev |
108 |
else: |
2363.5.18
by Aaron Bentley
Get all tests passing |
109 |
locs['checkout root'] = branch_path |
110 |
if working_path != master_path: |
|
7211.9.1
by Jelmer Vernooij
Report colocated branch name in 'brz info'. |
111 |
(master_path_base, params) = urlutils.split_segment_parameters( |
112 |
master_path) |
|
113 |
if working_path == master_path_base: |
|
114 |
locs['checkout of co-located branch'] = params['branch'] |
|
115 |
elif 'branch' in params: |
|
116 |
locs['checkout of branch'] = "%s, branch %s" ( |
|
117 |
master_path_base, params['branch']) |
|
118 |
else: |
|
119 |
locs['checkout of branch'] = master_path |
|
1694.2.6
by Martin Pool
[merge] bzr.dev |
120 |
elif repository.is_shared(): |
1551.15.41
by Aaron Bentley
Make info provide more related brances, and format all branches nicely |
121 |
locs['repository branch'] = branch_path |
2363.5.18
by Aaron Bentley
Get all tests passing |
122 |
elif branch_path is not None: |
1694.2.6
by Martin Pool
[merge] bzr.dev |
123 |
# standalone
|
2363.5.18
by Aaron Bentley
Get all tests passing |
124 |
locs['branch root'] = branch_path |
125 |
else: |
|
126 |
working_path = None |
|
6241.4.1
by Jelmer Vernooij
Make gather_location_info understand control directories. |
127 |
if repository is not None and repository.is_shared(): |
2363.5.18
by Aaron Bentley
Get all tests passing |
128 |
# lightweight checkout of branch in shared repository
|
129 |
if branch_path is not None: |
|
1551.15.41
by Aaron Bentley
Make info provide more related brances, and format all branches nicely |
130 |
locs['repository branch'] = branch_path |
2363.5.18
by Aaron Bentley
Get all tests passing |
131 |
elif branch_path is not None: |
132 |
# standalone
|
|
133 |
locs['branch root'] = branch_path |
|
6241.4.1
by Jelmer Vernooij
Make gather_location_info understand control directories. |
134 |
elif repository is not None: |
135 |
locs['repository'] = repository.user_url |
|
136 |
elif control is not None: |
|
137 |
locs['control directory'] = control.user_url |
|
1624.3.48
by Olaf Conradi
Add info on standalone branches without a working tree. |
138 |
else: |
6241.4.1
by Jelmer Vernooij
Make gather_location_info understand control directories. |
139 |
# Really, at least a control directory should be
|
140 |
# passed in for this method to be useful.
|
|
141 |
pass
|
|
6241.2.1
by Jelmer Vernooij
bzr info now shows the bound location too for local branches without tree. |
142 |
if master_path != branch_path: |
143 |
locs['bound to branch'] = master_path |
|
6241.4.1
by Jelmer Vernooij
Make gather_location_info understand control directories. |
144 |
if repository is not None and repository.is_shared(): |
2363.5.18
by Aaron Bentley
Get all tests passing |
145 |
# lightweight checkout of branch in shared repository
|
6241.4.1
by Jelmer Vernooij
Make gather_location_info understand control directories. |
146 |
locs['shared repository'] = repository.user_url |
147 |
order = ['control directory', 'light checkout root', |
|
148 |
'repository checkout root', 'checkout root', |
|
7211.9.1
by Jelmer Vernooij
Report colocated branch name in 'brz info'. |
149 |
'checkout of branch', 'checkout of co-located branch', |
150 |
'shared repository', 'repository', 'repository branch', |
|
151 |
'branch root', 'bound to branch'] |
|
2363.5.23
by Aaron Bentley
Output 2-tuples from gather_locations |
152 |
return [(n, locs[n]) for n in order if n in locs] |
2363.5.18
by Aaron Bentley
Get all tests passing |
153 |
|
154 |
||
2904.3.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info``. |
155 |
def _show_location_info(locs, outfile): |
2363.5.18
by Aaron Bentley
Get all tests passing |
156 |
"""Show known locations for working, branch and repository.""" |
2968.2.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info`` |
157 |
outfile.write('Location:\n') |
2804.4.3
by Alexander Belchenko
fix for test_info-tests: using osutils.getcwd instead of os.getcwd (sigh) |
158 |
path_list = LocationList(osutils.getcwd()) |
2363.5.23
by Aaron Bentley
Output 2-tuples from gather_locations |
159 |
for name, loc in locs: |
160 |
path_list.add_url(name, loc) |
|
2904.3.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info``. |
161 |
outfile.writelines(path_list.get_lines()) |
162 |
||
1694.2.6
by Martin Pool
[merge] bzr.dev |
163 |
|
1551.15.41
by Aaron Bentley
Make info provide more related brances, and format all branches nicely |
164 |
def _gather_related_branches(branch): |
2804.4.3
by Alexander Belchenko
fix for test_info-tests: using osutils.getcwd instead of os.getcwd (sigh) |
165 |
locs = LocationList(osutils.getcwd()) |
1551.15.41
by Aaron Bentley
Make info provide more related brances, and format all branches nicely |
166 |
locs.add_url('public branch', branch.get_public_branch()) |
167 |
locs.add_url('push branch', branch.get_push_location()) |
|
168 |
locs.add_url('parent branch', branch.get_parent()) |
|
169 |
locs.add_url('submit branch', branch.get_submit_branch()) |
|
3221.11.21
by Robert Collins
Have info report on stacked branches. |
170 |
try: |
3537.3.1
by Martin Pool
Rename branch.get_stacked_on to get_stacked_on_url |
171 |
locs.add_url('stacked on', branch.get_stacked_on_url()) |
6734.1.11
by Jelmer Vernooij
Move UnstackableBranchFormat. |
172 |
except (_mod_branch.UnstackableBranchFormat, errors.UnstackableRepositoryFormat, |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
173 |
errors.NotStacked): |
3221.11.21
by Robert Collins
Have info report on stacked branches. |
174 |
pass
|
1551.15.41
by Aaron Bentley
Make info provide more related brances, and format all branches nicely |
175 |
return locs |
1694.2.6
by Martin Pool
[merge] bzr.dev |
176 |
|
2904.3.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info``. |
177 |
|
1551.15.43
by Aaron Bentley
Provide ways of getting at unicode-clean output |
178 |
def _show_related_info(branch, outfile): |
1694.2.6
by Martin Pool
[merge] bzr.dev |
179 |
"""Show parent and push location of branch.""" |
1551.15.41
by Aaron Bentley
Make info provide more related brances, and format all branches nicely |
180 |
locs = _gather_related_branches(branch) |
1551.15.43
by Aaron Bentley
Provide ways of getting at unicode-clean output |
181 |
if len(locs.locs) > 0: |
2911.6.1
by Blake Winton
Change 'print >> f,'s to 'f.write('s. |
182 |
outfile.write('\n') |
183 |
outfile.write('Related branches:\n') |
|
1551.15.43
by Aaron Bentley
Provide ways of getting at unicode-clean output |
184 |
outfile.writelines(locs.get_lines()) |
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
185 |
|
186 |
||
6240.1.1
by Jelmer Vernooij
Show the number of colocated branches in 'bzr info -v'. |
187 |
def _show_control_dir_info(control, outfile): |
188 |
"""Show control dir information.""" |
|
189 |
if control._format.colocated_branches: |
|
190 |
outfile.write('\n') |
|
191 |
outfile.write('Control directory:\n') |
|
192 |
outfile.write(' %d branches\n' % len(control.list_branches())) |
|
193 |
||
194 |
||
2904.3.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info``. |
195 |
def _show_format_info(control=None, repository=None, branch=None, |
196 |
working=None, outfile=None): |
|
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
197 |
"""Show known formats for control, working, branch and repository.""" |
2968.2.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info`` |
198 |
outfile.write('\n') |
199 |
outfile.write('Format:\n') |
|
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
200 |
if control: |
2968.2.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info`` |
201 |
outfile.write(' control: %s\n' % |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
202 |
control._format.get_format_description()) |
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
203 |
if working: |
2968.2.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info`` |
204 |
outfile.write(' working tree: %s\n' % |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
205 |
working._format.get_format_description()) |
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
206 |
if branch: |
2968.2.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info`` |
207 |
outfile.write(' branch: %s\n' % |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
208 |
branch._format.get_format_description()) |
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
209 |
if repository: |
2968.2.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info`` |
210 |
outfile.write(' repository: %s\n' % |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
211 |
repository._format.get_format_description()) |
2904.3.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info``. |
212 |
|
213 |
||
6437.33.2
by Jelmer Vernooij
Cope with repository being missing in 'bzr info'. |
214 |
def _show_locking_info(repository=None, branch=None, working=None, |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
215 |
outfile=None): |
1694.2.6
by Martin Pool
[merge] bzr.dev |
216 |
"""Show locking status of working, branch and repository.""" |
6437.33.2
by Jelmer Vernooij
Cope with repository being missing in 'bzr info'. |
217 |
if (repository and repository.get_physical_lock_status() or |
1694.2.6
by Martin Pool
[merge] bzr.dev |
218 |
(branch and branch.get_physical_lock_status()) or |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
219 |
(working and working.get_physical_lock_status())): |
2968.2.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info`` |
220 |
outfile.write('\n') |
221 |
outfile.write('Lock status:\n') |
|
1694.2.6
by Martin Pool
[merge] bzr.dev |
222 |
if working: |
223 |
if working.get_physical_lock_status(): |
|
224 |
status = 'locked' |
|
225 |
else: |
|
226 |
status = 'unlocked' |
|
2968.2.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info`` |
227 |
outfile.write(' working tree: %s\n' % status) |
1694.2.6
by Martin Pool
[merge] bzr.dev |
228 |
if branch: |
229 |
if branch.get_physical_lock_status(): |
|
230 |
status = 'locked' |
|
231 |
else: |
|
232 |
status = 'unlocked' |
|
2968.2.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info`` |
233 |
outfile.write(' branch: %s\n' % status) |
1694.2.6
by Martin Pool
[merge] bzr.dev |
234 |
if repository: |
235 |
if repository.get_physical_lock_status(): |
|
236 |
status = 'locked' |
|
237 |
else: |
|
238 |
status = 'unlocked' |
|
2968.2.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info`` |
239 |
outfile.write(' repository: %s\n' % status) |
2904.3.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info``. |
240 |
|
241 |
||
242 |
def _show_missing_revisions_branch(branch, outfile): |
|
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
243 |
"""Show missing master revisions in branch.""" |
1587.1.14
by Robert Collins
Make bound branch creation happen via 'checkout' |
244 |
# Try with inaccessible branch ?
|
1624.3.2
by Olaf Conradi
Implemented table of constructs from BzrInfo specification. |
245 |
master = branch.get_master_branch() |
1587.1.14
by Robert Collins
Make bound branch creation happen via 'checkout' |
246 |
if master: |
1624.3.2
by Olaf Conradi
Implemented table of constructs from BzrInfo specification. |
247 |
local_extra, remote_extra = find_unmerged(branch, master) |
1587.1.14
by Robert Collins
Make bound branch creation happen via 'checkout' |
248 |
if remote_extra: |
2968.2.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info`` |
249 |
outfile.write('\n') |
250 |
outfile.write(('Branch is out of date: missing %d ' |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
251 |
'revision%s.\n') % (len(remote_extra), |
252 |
plural(len(remote_extra)))) |
|
2904.3.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info``. |
253 |
|
254 |
||
255 |
def _show_missing_revisions_working(working, outfile): |
|
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
256 |
"""Show missing revisions in working tree.""" |
257 |
branch = working.branch |
|
6181.1.1
by Jelmer Vernooij
If the branch doesn't support last_revision_info, don't display |
258 |
try: |
259 |
branch_revno, branch_last_revision = branch.last_revision_info() |
|
260 |
except errors.UnsupportedOperation: |
|
261 |
return
|
|
1908.7.6
by Robert Collins
Deprecate WorkingTree.last_revision. |
262 |
try: |
263 |
tree_last_id = working.get_parent_ids()[0] |
|
264 |
except IndexError: |
|
265 |
tree_last_id = None |
|
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
266 |
|
2249.4.2
by Wouter van Heyst
Convert callers of Branch.revision_history() to Branch.last_revision_info() where sensible. |
267 |
if branch_revno and tree_last_id != branch_last_revision: |
1624.3.11
by Olaf Conradi
Test cases exposed a bug in missing revisions count of working tree. It |
268 |
tree_last_revno = branch.revision_id_to_revno(tree_last_id) |
2249.4.2
by Wouter van Heyst
Convert callers of Branch.revision_history() to Branch.last_revision_info() where sensible. |
269 |
missing_count = branch_revno - tree_last_revno |
2968.2.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info`` |
270 |
outfile.write('\n') |
271 |
outfile.write(('Working tree is out of date: missing %d ' |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
272 |
'revision%s.\n') % (missing_count, plural(missing_count))) |
2904.3.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info``. |
273 |
|
274 |
||
275 |
def _show_working_stats(working, outfile): |
|
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
276 |
"""Show statistics about a working tree.""" |
277 |
basis = working.basis_tree() |
|
1852.10.3
by Robert Collins
Remove all uses of compare_trees and replace with Tree.changes_from throughout bzrlib. |
278 |
delta = working.changes_from(basis, want_unchanged=True) |
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
279 |
|
2968.2.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info`` |
280 |
outfile.write('\n') |
281 |
outfile.write('In the working tree:\n') |
|
282 |
outfile.write(' %8s unchanged\n' % len(delta.unchanged)) |
|
283 |
outfile.write(' %8d modified\n' % len(delta.modified)) |
|
284 |
outfile.write(' %8d added\n' % len(delta.added)) |
|
285 |
outfile.write(' %8d removed\n' % len(delta.removed)) |
|
286 |
outfile.write(' %8d renamed\n' % len(delta.renamed)) |
|
462
by Martin Pool
- New form 'file_id in tree' to check if the file is present |
287 |
|
288 |
ignore_cnt = unknown_cnt = 0 |
|
289 |
for path in working.extras(): |
|
290 |
if working.is_ignored(path): |
|
291 |
ignore_cnt += 1 |
|
292 |
else: |
|
293 |
unknown_cnt += 1 |
|
2968.2.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info`` |
294 |
outfile.write(' %8d unknown\n' % unknown_cnt) |
295 |
outfile.write(' %8d ignored\n' % ignore_cnt) |
|
462
by Martin Pool
- New form 'file_id in tree' to check if the file is present |
296 |
|
297 |
dir_cnt = 0 |
|
5777.5.5
by Jelmer Vernooij
Use working.iter_entries_by_dir. |
298 |
for path, entry in working.iter_entries_by_dir(): |
6913.3.2
by Jelmer Vernooij
Avoid file id usage. |
299 |
if entry.kind == 'directory' and path != '': |
1731.1.39
by Aaron Bentley
Reject removing is_root |
300 |
dir_cnt += 1 |
2968.2.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info`` |
301 |
outfile.write(' %8d versioned %s\n' % (dir_cnt, |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
302 |
plural(dir_cnt, 'subdirectory', 'subdirectories'))) |
77
by mbp at sourcefrog
- split info command out into separate file |
303 |
|
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
304 |
|
2904.3.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info``. |
305 |
def _show_branch_stats(branch, verbose, outfile): |
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
306 |
"""Show statistics about a branch.""" |
6181.1.1
by Jelmer Vernooij
If the branch doesn't support last_revision_info, don't display |
307 |
try: |
308 |
revno, head = branch.last_revision_info() |
|
309 |
except errors.UnsupportedOperation: |
|
310 |
return {} |
|
2968.2.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info`` |
311 |
outfile.write('\n') |
312 |
outfile.write('Branch history:\n') |
|
313 |
outfile.write(' %8d revision%s\n' % (revno, plural(revno))) |
|
2258.1.1
by Robert Collins
Move info branch statistics gathering into the repository to allow smart server optimisation (Robert Collins). |
314 |
stats = branch.repository.gather_stats(head, committers=verbose) |
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
315 |
if verbose: |
2258.1.1
by Robert Collins
Move info branch statistics gathering into the repository to allow smart server optimisation (Robert Collins). |
316 |
committers = stats['committers'] |
2968.2.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info`` |
317 |
outfile.write(' %8d committer%s\n' % (committers, |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
318 |
plural(committers))) |
2258.1.1
by Robert Collins
Move info branch statistics gathering into the repository to allow smart server optimisation (Robert Collins). |
319 |
if revno: |
320 |
timestamp, timezone = stats['firstrev'] |
|
321 |
age = int((time.time() - timestamp) / 3600 / 24) |
|
2968.2.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info`` |
322 |
outfile.write(' %8d day%s old\n' % (age, plural(age))) |
323 |
outfile.write(' first revision: %s\n' % |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
324 |
osutils.format_date(timestamp, timezone)) |
2258.1.1
by Robert Collins
Move info branch statistics gathering into the repository to allow smart server optimisation (Robert Collins). |
325 |
timestamp, timezone = stats['latestrev'] |
2968.2.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info`` |
326 |
outfile.write(' latest revision: %s\n' % |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
327 |
osutils.format_date(timestamp, timezone)) |
2258.1.2
by Robert Collins
New version of gather_stats which gathers aggregate data too. |
328 |
return stats |
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
329 |
|
330 |
||
2904.3.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info``. |
331 |
def _show_repository_info(repository, outfile): |
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
332 |
"""Show settings of a repository.""" |
333 |
if repository.make_working_trees(): |
|
2968.2.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info`` |
334 |
outfile.write('\n') |
335 |
outfile.write('Create working tree for new branches inside ' |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
336 |
'the repository.\n') |
2904.3.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info``. |
337 |
|
338 |
||
4307.3.3
by Jelmer Vernooij
Add repository argument to 'repository' info hook, per Roberts review. |
339 |
def _show_repository_stats(repository, stats, outfile): |
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
340 |
"""Show statistics about a repository.""" |
6963.2.18
by Jelmer Vernooij
Add bees to some of bp.weave_fmt. |
341 |
f = StringIO() |
2258.1.2
by Robert Collins
New version of gather_stats which gathers aggregate data too. |
342 |
if 'revisions' in stats: |
343 |
revisions = stats['revisions'] |
|
4307.3.1
by Jelmer Vernooij
Allow registering hooks that extend the Repository section in 'bzr info -v'. |
344 |
f.write(' %8d revision%s\n' % (revisions, plural(revisions))) |
2258.1.2
by Robert Collins
New version of gather_stats which gathers aggregate data too. |
345 |
if 'size' in stats: |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
346 |
f.write(' %8d KiB\n' % (stats['size'] / 1024)) |
4307.3.1
by Jelmer Vernooij
Allow registering hooks that extend the Repository section in 'bzr info -v'. |
347 |
for hook in hooks['repository']: |
4307.3.3
by Jelmer Vernooij
Add repository argument to 'repository' info hook, per Roberts review. |
348 |
hook(repository, stats, f) |
7045.3.1
by Jelmer Vernooij
Fix another ~500 tests. |
349 |
if f.getvalue() != "": |
4307.3.1
by Jelmer Vernooij
Allow registering hooks that extend the Repository section in 'bzr info -v'. |
350 |
outfile.write('\n') |
351 |
outfile.write('Repository:\n') |
|
352 |
outfile.write(f.getvalue()) |
|
2968.2.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info`` |
353 |
|
1624.3.21
by Olaf Conradi
Make bzr info command work on both local and remote locations. Support |
354 |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
355 |
def show_bzrdir_info(a_controldir, verbose=False, outfile=None): |
356 |
"""Output to stdout the 'info' for a_controldir.""" |
|
2904.3.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info``. |
357 |
if outfile is None: |
358 |
outfile = sys.stdout |
|
2363.5.1
by Aaron Bentley
Unify info display into show_component_info |
359 |
try: |
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
360 |
tree = a_controldir.open_workingtree( |
2363.5.9
by Aaron Bentley
Merge from bzr.dev |
361 |
recommend_upgrade=False) |
6241.4.3
by Jelmer Vernooij
Add test for dangling tree references. |
362 |
except (NoWorkingTree, NotLocalUrl, NotBranchError): |
2363.5.1
by Aaron Bentley
Unify info display into show_component_info |
363 |
tree = None |
364 |
try: |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
365 |
branch = a_controldir.open_branch(name="") |
2363.5.1
by Aaron Bentley
Unify info display into show_component_info |
366 |
except NotBranchError: |
367 |
branch = None |
|
368 |
try: |
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
369 |
repository = a_controldir.open_repository() |
2363.5.1
by Aaron Bentley
Unify info display into show_component_info |
370 |
except NoRepositoryPresent: |
6241.4.2
by Jelmer Vernooij
No longer show empty output when only control directory is present. |
371 |
lockable = None |
372 |
repository = None |
|
2363.5.1
by Aaron Bentley
Unify info display into show_component_info |
373 |
else: |
374 |
lockable = repository |
|
375 |
else: |
|
376 |
repository = branch.repository |
|
377 |
lockable = branch |
|
378 |
else: |
|
379 |
branch = tree.branch |
|
380 |
repository = branch.repository |
|
381 |
lockable = tree |
|
382 |
||
6241.4.2
by Jelmer Vernooij
No longer show empty output when only control directory is present. |
383 |
if lockable is not None: |
384 |
lockable.lock_read() |
|
2363.5.1
by Aaron Bentley
Unify info display into show_component_info |
385 |
try: |
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
386 |
show_component_info(a_controldir, repository, branch, tree, verbose, |
2904.3.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info``. |
387 |
outfile) |
2363.5.1
by Aaron Bentley
Unify info display into show_component_info |
388 |
finally: |
6241.4.2
by Jelmer Vernooij
No longer show empty output when only control directory is present. |
389 |
if lockable is not None: |
390 |
lockable.unlock() |
|
2363.5.1
by Aaron Bentley
Unify info display into show_component_info |
391 |
|
392 |
||
393 |
def show_component_info(control, repository, branch=None, working=None, |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
394 |
verbose=1, outfile=None): |
2363.5.1
by Aaron Bentley
Unify info display into show_component_info |
395 |
"""Write info about all bzrdir components to stdout""" |
2904.3.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info``. |
396 |
if outfile is None: |
397 |
outfile = sys.stdout |
|
2363.5.7
by Aaron Bentley
Make verbose mean what I want |
398 |
if verbose is False: |
399 |
verbose = 1 |
|
400 |
if verbose is True: |
|
401 |
verbose = 2 |
|
6241.4.3
by Jelmer Vernooij
Add test for dangling tree references. |
402 |
layout = describe_layout(repository, branch, working, control) |
2363.5.6
by Aaron Bentley
Add short format description |
403 |
format = describe_format(control, repository, branch, working) |
2968.2.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info`` |
404 |
outfile.write("%s (format: %s)\n" % (layout, format)) |
6241.4.1
by Jelmer Vernooij
Make gather_location_info understand control directories. |
405 |
_show_location_info( |
406 |
gather_location_info(control=control, repository=repository, |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
407 |
branch=branch, working=working), |
6241.4.1
by Jelmer Vernooij
Make gather_location_info understand control directories. |
408 |
outfile) |
2584.2.1
by Adeodato Simó
Make `bzr info` show related branches in non-verbose mode. |
409 |
if branch is not None: |
2904.3.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info``. |
410 |
_show_related_info(branch, outfile) |
2363.5.7
by Aaron Bentley
Make verbose mean what I want |
411 |
if verbose == 0: |
412 |
return
|
|
2904.3.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info``. |
413 |
_show_format_info(control, repository, branch, working, outfile) |
414 |
_show_locking_info(repository, branch, working, outfile) |
|
6240.1.1
by Jelmer Vernooij
Show the number of colocated branches in 'bzr info -v'. |
415 |
_show_control_dir_info(control, outfile) |
2363.5.1
by Aaron Bentley
Unify info display into show_component_info |
416 |
if branch is not None: |
2904.3.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info``. |
417 |
_show_missing_revisions_branch(branch, outfile) |
2363.5.1
by Aaron Bentley
Unify info display into show_component_info |
418 |
if working is not None: |
2904.3.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info``. |
419 |
_show_missing_revisions_working(working, outfile) |
420 |
_show_working_stats(working, outfile) |
|
2363.5.1
by Aaron Bentley
Unify info display into show_component_info |
421 |
elif branch is not None: |
2904.3.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info``. |
422 |
_show_missing_revisions_branch(branch, outfile) |
2363.5.1
by Aaron Bentley
Unify info display into show_component_info |
423 |
if branch is not None: |
4032.2.1
by Ian Clatworthy
omit branch committers from info -v (now requires -vv) |
424 |
show_committers = verbose >= 2 |
425 |
stats = _show_branch_stats(branch, show_committers, outfile) |
|
6437.33.3
by Jelmer Vernooij
Cope with repository being missing in more cases. |
426 |
elif repository is not None: |
2363.5.1
by Aaron Bentley
Unify info display into show_component_info |
427 |
stats = repository.gather_stats() |
6437.33.3
by Jelmer Vernooij
Cope with repository being missing in more cases. |
428 |
if branch is None and working is None and repository is not None: |
2904.3.1
by Lukáš Lalinský
Unicode-safe output from ``bzr info``. |
429 |
_show_repository_info(repository, outfile) |
6437.33.3
by Jelmer Vernooij
Cope with repository being missing in more cases. |
430 |
if repository is not None: |
431 |
_show_repository_stats(repository, stats, outfile) |
|
2363.5.1
by Aaron Bentley
Unify info display into show_component_info |
432 |
|
433 |
||
6241.4.3
by Jelmer Vernooij
Add test for dangling tree references. |
434 |
def describe_layout(repository=None, branch=None, tree=None, control=None): |
2363.5.2
by Aaron Bentley
Implement layout description |
435 |
"""Convert a control directory layout into a user-understandable term |
436 |
||
437 |
Common outputs include "Standalone tree", "Repository branch" and
|
|
438 |
"Checkout". Uncommon outputs include "Unshared repository with trees"
|
|
439 |
and "Empty control directory"
|
|
440 |
"""
|
|
6241.4.3
by Jelmer Vernooij
Add test for dangling tree references. |
441 |
if branch is None and control is not None: |
442 |
try: |
|
443 |
branch_reference = control.get_branch_reference() |
|
444 |
except NotBranchError: |
|
445 |
pass
|
|
446 |
else: |
|
447 |
if branch_reference is not None: |
|
448 |
return "Dangling branch reference" |
|
2363.5.2
by Aaron Bentley
Implement layout description |
449 |
if repository is None: |
450 |
return 'Empty control directory' |
|
451 |
if branch is None and tree is None: |
|
452 |
if repository.is_shared(): |
|
453 |
phrase = 'Shared repository' |
|
454 |
else: |
|
455 |
phrase = 'Unshared repository' |
|
6437.9.1
by Jelmer Vernooij
Report present but unused colocated branches in `bzr info`. |
456 |
extra = [] |
2363.5.2
by Aaron Bentley
Implement layout description |
457 |
if repository.make_working_trees(): |
6437.9.1
by Jelmer Vernooij
Report present but unused colocated branches in `bzr info`. |
458 |
extra.append('trees') |
459 |
if len(control.get_branches()) > 0: |
|
460 |
extra.append('colocated branches') |
|
461 |
if extra: |
|
462 |
phrase += ' with ' + " and ".join(extra) |
|
2363.5.2
by Aaron Bentley
Implement layout description |
463 |
return phrase |
464 |
else: |
|
465 |
if repository.is_shared(): |
|
466 |
independence = "Repository " |
|
467 |
else: |
|
468 |
independence = "Standalone " |
|
469 |
if tree is not None: |
|
470 |
phrase = "tree" |
|
471 |
else: |
|
472 |
phrase = "branch" |
|
473 |
if branch is None and tree is not None: |
|
474 |
phrase = "branchless tree" |
|
475 |
else: |
|
6874.1.2
by Jelmer Vernooij
Consistently use Branch.user_url. |
476 |
if (tree is not None and tree.controldir.control_url != |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
477 |
branch.controldir.control_url): |
2363.5.4
by Aaron Bentley
Eliminate the concept of a 'repository lightweight checkout' |
478 |
independence = '' |
2363.5.2
by Aaron Bentley
Implement layout description |
479 |
phrase = "Lightweight checkout" |
480 |
elif branch.get_bound_location() is not None: |
|
481 |
if independence == 'Standalone ': |
|
482 |
independence = '' |
|
483 |
if tree is None: |
|
484 |
phrase = "Bound branch" |
|
485 |
else: |
|
486 |
phrase = "Checkout" |
|
487 |
if independence != "": |
|
488 |
phrase = phrase.lower() |
|
489 |
return "%s%s" % (independence, phrase) |
|
490 |
||
491 |
||
2363.5.5
by Aaron Bentley
add info.describe_format |
492 |
def describe_format(control, repository, branch, tree): |
493 |
"""Determine the format of an existing control directory |
|
494 |
||
495 |
Several candidates may be found. If so, the names are returned as a
|
|
2363.5.17
by Aaron Bentley
Change separator from '/' to 'or' |
496 |
single string, separated by ' or '.
|
2363.5.5
by Aaron Bentley
add info.describe_format |
497 |
|
498 |
If no matching candidate is found, "unnamed" is returned.
|
|
499 |
"""
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
500 |
candidates = [] |
2363.5.6
by Aaron Bentley
Add short format description |
501 |
if (branch is not None and tree is not None and |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
502 |
branch.user_url != tree.user_url): |
2363.5.6
by Aaron Bentley
Add short format description |
503 |
branch = None |
504 |
repository = None |
|
6207.3.3
by jelmer at samba
Fix tests and the like. |
505 |
non_aliases = set(controldir.format_registry.keys()) |
506 |
non_aliases.difference_update(controldir.format_registry.aliases()) |
|
3152.2.2
by Robert Collins
The bzrdir format registry now accepts an ``alias`` keyword to |
507 |
for key in non_aliases: |
6653.6.5
by Jelmer Vernooij
Rename make_bzrdir to make_controldir. |
508 |
format = controldir.format_registry.make_controldir(key) |
2363.5.5
by Aaron Bentley
add info.describe_format |
509 |
if isinstance(format, bzrdir.BzrDirMetaFormat1): |
510 |
if (tree and format.workingtree_format != |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
511 |
tree._format): |
2363.5.5
by Aaron Bentley
add info.describe_format |
512 |
continue
|
513 |
if (branch and format.get_branch_format() != |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
514 |
branch._format): |
2363.5.5
by Aaron Bentley
add info.describe_format |
515 |
continue
|
516 |
if (repository and format.repository_format != |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
517 |
repository._format): |
2363.5.5
by Aaron Bentley
add info.describe_format |
518 |
continue
|
519 |
if format.__class__ is not control._format.__class__: |
|
520 |
continue
|
|
521 |
candidates.append(key) |
|
522 |
if len(candidates) == 0: |
|
523 |
return 'unnamed' |
|
3152.2.2
by Robert Collins
The bzrdir format registry now accepts an ``alias`` keyword to |
524 |
candidates.sort() |
2363.5.6
by Aaron Bentley
Add short format description |
525 |
new_candidates = [c for c in candidates if not |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
526 |
controldir.format_registry.get_info(c).hidden] |
2363.5.6
by Aaron Bentley
Add short format description |
527 |
if len(new_candidates) > 0: |
3152.2.2
by Robert Collins
The bzrdir format registry now accepts an ``alias`` keyword to |
528 |
# If there are any non-hidden formats that match, only return those to
|
529 |
# avoid listing hidden formats except when only a hidden format will
|
|
530 |
# do.
|
|
2363.5.6
by Aaron Bentley
Add short format description |
531 |
candidates = new_candidates |
2363.5.17
by Aaron Bentley
Change separator from '/' to 'or' |
532 |
return ' or '.join(candidates) |
4307.3.1
by Jelmer Vernooij
Allow registering hooks that extend the Repository section in 'bzr info -v'. |
533 |
|
534 |
||
535 |
class InfoHooks(_mod_hooks.Hooks): |
|
536 |
"""Hooks for the info command.""" |
|
537 |
||
5622.3.10
by Jelmer Vernooij
Don't require arguments to hooks. |
538 |
def __init__(self): |
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
539 |
super(InfoHooks, self).__init__("breezy.info", "hooks") |
7143.15.5
by Jelmer Vernooij
More PEP8 fixes. |
540 |
self.add_hook( |
541 |
'repository', |
|
542 |
"Invoked when displaying the statistics for a repository. "
|
|
543 |
"repository is called with a statistics dictionary as returned "
|
|
544 |
"by the repository and a file-like object to write to.", (1, 15)) |
|
5622.3.2
by Jelmer Vernooij
Add more lazily usable hook points. |
545 |
|
546 |
||
5622.3.10
by Jelmer Vernooij
Don't require arguments to hooks. |
547 |
hooks = InfoHooks() |