327
327
"""Return the kind and naming details."""
329
329
kind = self.kind()
331
'this_location': None,
332
'master_location': None,
334
335
shared_tree_repo_found = False
336
def format_location(location):
337
return self.url_for_display(strip_trailing_slash(location))
335
338
if kind == CHECKOUT_KIND:
337
co_str = os.path.basename(self.url_for_display(co_base))
339
br_base = strip_trailing_slash(self.branch.base)
340
br_str = os.path.basename(self.url_for_display(br_base))
339
locations['this_location'] = format_location(self._root)
340
locations['master_location'] = format_location(self.branch.base)
341
elif kind == BOUND_BRANCH_KIND:
342
locations['this_location'] = format_location(self.branch.base)
343
locations['master_location'] = format_location(self.branch.get_bound_location())
344
elif kind == BRANCH_KIND:
345
locations['this_location'] = format_location(self.branch.base)
341
346
if self.repository:
342
repo_base = strip_trailing_slash(
343
self.repository.bzrdir.root_transport.external_url())
344
if br_base is not None and repo_base == br_base:
345
loc_str = self.location
346
if loc_str.endswith(br_str):
347
loc_str = os.path.basename(loc_str[:-(len(br_str) + 1)])
348
repo_str = '(%s)' % (loc_str,)
347
repository_location = format_location(self.repository.bzrdir.root_transport.external_url())
348
if repository_location != locations['this_location']:
349
locations['repository'] = repository_location
350
if os.path.basename(locations['repository']) == '.bzrbranches':
351
locations['repository'] = os.path.split(locations['repository'])[0]
352
shared_tree_repo_found = True
353
elif locations['repository'].endswith('/.bzr/branches'):
354
locations['repository'] = locations['repository'][:-len('/.bzr/branches')]
355
shared_tree_repo_found = True
356
for key in locations.keys():
357
if locations[key] is not None:
358
locations[key + '_base'] = os.path.basename(locations[key])
350
repo_path = self.url_for_display(repo_base)
351
repo_str = os.path.basename(repo_path)
352
# If this is a nested shared repo inside a checkout
353
# (as happens in the 'colocated-branches' model), use the
354
# checkout name as the label.
355
if repo_str == '.bzrbranches':
356
repo_str = repo_path.split("/")[-2]
357
shared_tree_repo_found = True
358
elif repo_path.endswith("/.bzr/branches"):
359
repo_str = repo_path.split("/")[-3]
360
shared_tree_repo_found = True
361
if kind != REPOSITORY_KIND:
362
repo_str = '[%s]' % (repo_str,)
367
'relpath': self.relpath,
368
'pathsep': os.path.sep,
370
return kind, template, shared_tree_repo_found
360
locations[key + '_base'] = None
361
return kind, locations, shared_tree_repo_found
372
363
def display_name(self):
373
364
"""Return a name suitable for displaying in a tab or title bar.
382
373
checkout -> branch [repository]
384
kind, template, shared_tree_repo_found = self._get_name_details()
385
if kind in [BRANCH_KIND, BOUND_BRANCH_KIND]:
387
format = "%(br)s %(repo)s"
375
kind, locations, shared_tree_repo_found = self._get_name_details()
376
if kind == BRANCH_KIND:
377
if locations['repository'] is not None:
378
format = "%(this_location_base)s [%(repository_base)s]"
380
format = "%(this_location_base)s"
390
381
elif kind == CHECKOUT_KIND:
391
if template['br'] == 'trunk':
394
format = "%(co)s -> %(br)s"
395
if self.repository and not shared_tree_repo_found:
396
format += " %(repo)s"
382
format = "%(this_location_base)s -> %(master_location_base)s"
383
if locations['repository'] is not None and not shared_tree_repo_found:
384
format += " %(repository)s"
385
elif kind == BOUND_BRANCH_KIND:
386
format = "%(this_location_base)s -> %(master_location_base)s"
397
387
elif kind == REPOSITORY_KIND:
388
format = "[%(repository_base)s]"
401
return format % template
391
return format % locations
403
393
def display_local_name(self):
404
394
"""Return a name to display - context is implied. """
405
kind, template, _ = self._get_name_details()
406
if kind in [BRANCH_KIND, BOUND_BRANCH_KIND]:
408
elif kind == CHECKOUT_KIND:
409
if template['br'] == 'trunk':
412
format = "%(co)s -> %(br)s"
395
kind, locations, _ = self._get_name_details()
396
if kind == BRANCH_KIND:
397
format = "%(this_location_base)s"
398
elif kind in [CHECKOUT_KIND, BOUND_BRANCH_KIND]:
399
format = "%(this_location_base)s -> %(master_location_base)s"
413
400
elif kind == REPOSITORY_KIND:
414
401
# Just the icon would do but it looks too plain if that's
415
402
# the only object open. If the space could be better used
418
405
format = gettext("Repository")
421
return format % template
408
return format % locations
410
def display_tooltip(self):
411
kind, locations, shared_tree_repo_found = self._get_name_details()
413
if kind == BRANCH_KIND:
414
format += "%(this_location)s"
415
if locations['repository'] is not None:
416
format += "\n" + gettext("in repository") + " %(repository)s"
417
elif kind == CHECKOUT_KIND:
418
format += "%(this_location)s\n-> %(master_location)s"
419
if locations['repository'] is not None and not shared_tree_repo_found:
420
format += "\n" + gettext("in repository") + " %(repository)s"
421
elif kind == BOUND_BRANCH_KIND:
422
format += "%(this_location)s\n-> %(master_location)s"
423
elif kind == REPOSITORY_KIND:
424
format += "%(this_location)s"
426
return format % locations
423
428
def display_diagnostics(self):
424
429
"""Return diagnostic information as a string.