/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/info.py

  • Committer: Aaron Bentley
  • Date: 2007-07-06 18:30:50 UTC
  • mto: (1551.19.24 Aaron's mergeable stuff)
  • mto: This revision was merged to the branch mainline in revision 2600.
  • Revision ID: abentley@panoramicfeedback.com-20070706183050-2folzf1brc3syc3a
Make info provide more related brances, and format all branches nicely

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
__all__ = ['show_bzrdir_info']
18
18
 
 
19
import os
19
20
import time
20
21
 
21
22
 
22
23
from bzrlib import (
23
24
    bzrdir,
24
25
    diff,
 
26
    errors,
25
27
    osutils,
26
28
    urlutils,
27
29
    )
41
43
        return 's'
42
44
 
43
45
 
44
 
def _repo_rel_url(repo_url, inner_url):
45
 
    """Return path with common prefix of repository path removed.
46
 
 
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
49
 
    returned.
50
 
    Otherwise, a relative path is returned, with trailing '/' stripped.
51
 
    """
52
 
    inner_url = urlutils.normalize_url(inner_url)
53
 
    repo_url = urlutils.normalize_url(repo_url)
54
 
    if inner_url == repo_url:
55
 
        return '.'
56
 
    result = urlutils.relative_url(repo_url, inner_url)
57
 
    if result != inner_url:
58
 
        result = result.rstrip('/')
59
 
    return result
60
 
 
61
 
class _UrlList(object):
62
 
 
63
 
    def __init__(self):
 
46
class LocationList(object):
 
47
 
 
48
    def __init__(self, base_path):
64
49
        self.urls = []
65
 
 
66
 
    def add_url(self, label, url):
67
 
        self.add_path(label, urlutils.unescape_for_display(url, 'ascii'))
68
 
 
69
 
    def add_url(self, label, url):
70
 
        self.add_path(label, url)
 
50
        self.base_path = base_path
 
51
 
 
52
    def add_url(self, label, url):
 
53
        if url is None:
 
54
            return
 
55
        path = urlutils.unescape_for_display(url, 'ascii')
 
56
        if path != url:
 
57
            self.add_path(label, path)
 
58
        else:
 
59
            self.urls.append((label, url))
71
60
 
72
61
    def add_path(self, label, path):
 
62
        try:
 
63
            path = osutils.relpath(self.base_path, path)
 
64
        except errors.PathNotChild:
 
65
            pass
 
66
        else:
 
67
            if path == '':
 
68
                path = '.'
 
69
        if path != '/':
 
70
            path = path.rstrip('/')
73
71
        self.urls.append((label, path))
74
72
 
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,
105
 
                branch_path)
 
102
            locs['repository branch'] = branch_path
106
103
        elif branch_path is not None:
107
104
            # standalone
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,
115
 
                                                          branch_path)
 
111
                locs['repository branch'] = branch_path
116
112
        elif branch_path is not None:
117
113
            # standalone
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()
140
136
 
 
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())
 
143
    return locs
141
144
 
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:
145
149
        print
146
150
        print 'Related branches:'
147
 
        if branch.get_parent():
148
 
            if branch.get_push_location():
149
 
                print '      parent branch: %s' % branch.get_parent()
150
 
            else:
151
 
                print '  parent branch: %s' % branch.get_parent()
152
 
        if branch.get_push_location():
153
 
            print '  publish to branch: %s' % branch.get_push_location()
 
151
        locs.print_lines()
154
152
 
155
153
 
156
154
def _show_format_info(control=None, repository=None, branch=None, working=None):