44
def _repo_rel_url(repo_url, inner_url):
45
"""Return path with common prefix of repository path removed.
47
If path is not part of the repository, the original path is returned.
48
If path is equal to the repository, the current directory marker '.' is
50
Otherwise, a relative path is returned, with trailing '/' stripped.
52
inner_url = urlutils.normalize_url(inner_url)
53
repo_url = urlutils.normalize_url(repo_url)
54
if inner_url == repo_url:
56
result = urlutils.relative_url(repo_url, inner_url)
57
if result != inner_url:
58
result = result.rstrip('/')
61
class _UrlList(object):
66
def add_url(self, label, url):
67
self.add_path(label, urlutils.unescape_for_display(url, 'ascii'))
69
def add_url(self, label, url):
70
self.add_path(label, url)
46
class LocationList(object):
48
def __init__(self, base_path):
50
self.base_path = base_path
52
def add_url(self, label, url):
53
"""Add a URL to the list, converting it to a path if possible"""
57
path = urlutils.local_path_from_url(url)
58
except errors.InvalidURL:
59
self.locs.append((label, url))
61
self.add_path(label, path)
72
63
def add_path(self, label, path):
73
self.urls.append((label, path))
64
"""Add a path, converting it to a relative path if possible"""
66
path = osutils.relpath(self.base_path, path)
67
except errors.PathNotChild:
73
path = path.rstrip('/')
74
self.locs.append((label, path))
75
def print_lines(self):
76
max_len = max(len(l) for l, u in self.urls)
77
for label, url in self.urls:
78
print " %*s: %s" % (max_len, label, url)
77
max_len = max(len(l) for l, u in self.locs)
78
return [" %*s: %s\n" % (max_len, l, u) for l, u in self.locs ]
81
81
def gather_location_info(repository, branch=None, working=None):
101
101
if working_path != master_path:
102
102
locs['checkout of branch'] = master_path
103
103
elif repository.is_shared():
104
locs['repository branch'] = _repo_rel_url(repository_path,
104
locs['repository branch'] = branch_path
106
105
elif branch_path is not None:
108
107
locs['branch root'] = branch_path
111
110
if repository.is_shared():
112
111
# lightweight checkout of branch in shared repository
113
112
if branch_path is not None:
114
locs['repository branch'] = _repo_rel_url(repository_path,
113
locs['repository branch'] = branch_path
116
114
elif branch_path is not None:
118
116
locs['branch root'] = branch_path
133
131
def _show_location_info(locs):
134
132
"""Show known locations for working, branch and repository."""
135
133
print 'Location:'
136
path_list = _UrlList()
134
path_list = LocationList(os.getcwd())
137
135
for name, loc in locs:
138
136
path_list.add_url(name, loc)
139
path_list.print_lines()
142
def _show_related_info(branch):
137
sys.stdout.writelines(path_list.get_lines())
139
def _gather_related_branches(branch):
140
locs = LocationList(os.getcwd())
141
locs.add_url('public branch', branch.get_public_branch())
142
locs.add_url('push branch', branch.get_push_location())
143
locs.add_url('parent branch', branch.get_parent())
144
locs.add_url('submit branch', branch.get_submit_branch())
147
def _show_related_info(branch, outfile):
143
148
"""Show parent and push location of branch."""
144
if branch.get_parent() or branch.get_push_location():
146
print 'Related branches:'
147
if branch.get_parent():
148
if branch.get_push_location():
149
print ' parent branch: %s' % branch.get_parent()
151
print ' parent branch: %s' % branch.get_parent()
152
if branch.get_push_location():
153
print ' publish to branch: %s' % branch.get_push_location()
149
locs = _gather_related_branches(branch)
150
if len(locs.locs) > 0:
152
print >> outfile, 'Related branches:'
153
outfile.writelines(locs.get_lines())
156
156
def _show_format_info(control=None, repository=None, branch=None, working=None):
343
343
format = describe_format(control, repository, branch, working)
344
344
print "%s (format: %s)" % (layout, format)
345
345
_show_location_info(gather_location_info(repository, branch, working))
346
if branch is not None:
347
_show_related_info(branch, sys.stdout)
348
if branch is not None:
349
_show_related_info(branch)
350
350
_show_format_info(control, repository, branch, working)
351
351
_show_locking_info(repository, branch, working)
352
352
if branch is not None: