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):
46
class LocationList(object):
48
def __init__(self, base_path):
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)
50
self.base_path = base_path
52
def add_url(self, label, url):
55
path = urlutils.unescape_for_display(url, 'ascii')
57
self.add_path(label, path)
59
self.urls.append((label, url))
72
61
def add_path(self, label, path):
63
path = osutils.relpath(self.base_path, path)
64
except errors.PathNotChild:
70
path = path.rstrip('/')
73
71
self.urls.append((label, path))
75
73
def print_lines(self):
101
99
if working_path != master_path:
102
100
locs['checkout of branch'] = master_path
103
101
elif repository.is_shared():
104
locs['repository branch'] = _repo_rel_url(repository_path,
102
locs['repository branch'] = branch_path
106
103
elif branch_path is not None:
108
105
locs['branch root'] = branch_path
111
108
if repository.is_shared():
112
109
# lightweight checkout of branch in shared repository
113
110
if branch_path is not None:
114
locs['repository branch'] = _repo_rel_url(repository_path,
111
locs['repository branch'] = branch_path
116
112
elif branch_path is not None:
118
114
locs['branch root'] = branch_path
133
129
def _show_location_info(locs):
134
130
"""Show known locations for working, branch and repository."""
135
131
print 'Location:'
136
path_list = _UrlList()
132
path_list = LocationList(os.getcwd())
137
133
for name, loc in locs:
138
134
path_list.add_url(name, loc)
139
135
path_list.print_lines()
137
def _gather_related_branches(branch):
138
locs = LocationList(os.getcwd())
139
locs.add_url('public branch', branch.get_public_branch())
140
locs.add_url('push branch', branch.get_push_location())
141
locs.add_url('parent branch', branch.get_parent())
142
locs.add_url('submit branch', branch.get_submit_branch())
142
145
def _show_related_info(branch):
143
146
"""Show parent and push location of branch."""
144
if branch.get_parent() or branch.get_push_location():
147
locs = _gather_related_branches(branch)
148
if len(locs.urls) > 0:
146
150
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()
156
154
def _show_format_info(control=None, repository=None, branch=None, working=None):