/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to olive/info_helper.py

  • Committer: Jelmer Vernooij
  • Date: 2006-09-30 10:21:43 UTC
  • Revision ID: jelmer@samba.org-20060930102143-c0ef64d6ca860c21
Merge some files from Olive and bzr-gtk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
 
19
19
import time
20
 
import sys
21
20
 
22
21
import bzrlib
23
22
 
24
 
from bzrlib import (
25
 
    bzrdir,
26
 
    diff,
27
 
    errors,
28
 
    osutils,
29
 
    urlutils,
30
 
    )
 
23
import bzrlib.osutils as osutils
31
24
 
32
 
from bzrlib.diff import show_diff_trees
 
25
from bzrlib.info import _repo_relpath
33
26
from bzrlib.missing import find_unmerged
34
 
    
35
 
def _repo_rel_url(repo_url, inner_url):
36
 
    """Return path with common prefix of repository path removed.
37
 
 
38
 
    If path is not part of the repository, the original path is returned.
39
 
    If path is equal to the repository, the current directory marker '.' is
40
 
    returned.
41
 
    Otherwise, a relative path is returned, with trailing '/' stripped.
42
 
    """
43
 
    inner_url = urlutils.normalize_url(inner_url)
44
 
    repo_url = urlutils.normalize_url(repo_url)
45
 
    if inner_url == repo_url:
46
 
        return '.'
47
 
    result = urlutils.relative_url(repo_url, inner_url)
48
 
    if result != inner_url:
49
 
        result = result.rstrip('/')
50
 
    return result
51
27
 
52
28
def get_location_info(repository, branch=None, working=None):
53
29
    """ Get known locations for working, branch and repository.
65
41
            if repository.is_shared():
66
42
                # lightweight checkout of branch in shared repository
67
43
                ret['sharedrepo'] = repository_path
68
 
                ret['repobranch'] = _repo_rel_url(repository_path, branch_path)
 
44
                ret['repobranch'] = _repo_relpath(repository_path, branch_path)
69
45
            else:
70
46
                # lightweight checkout of standalone branch
71
47
                ret['cobranch'] = branch_path
72
48
        elif repository.is_shared():
73
49
            # branch with tree inside shared repository
74
50
            ret['sharedrepo'] = repository_path
75
 
            ret['repoco'] = _repo_rel_url(repository_path, branch_path)
 
51
            ret['repoco'] = _repo_relpath(repository_path, branch_path)
76
52
        elif branch.get_bound_location():
77
53
            # normal checkout
78
54
            ret['coroot'] = working_path
85
61
        if repository.is_shared():
86
62
            # branch is part of shared repository
87
63
            ret['sharedrepo'] = repository_path
88
 
            ret['repobranch'] = _repo_rel_url(repository_path, branch_path)
 
64
            ret['repobranch'] = _repo_relpath(repository_path, branch_path)
89
65
        else:
90
66
            # standalone branch
91
67
            ret['branchroot'] = branch_path
187
163
    ret = {}
188
164
    branch = working.branch
189
165
    basis = working.basis_tree()
190
 
 
 
166
    work_inv = working.inventory
 
167
    
191
168
    if (bzrlib.version_info[0] == 0) and (bzrlib.version_info[1] < 9):
192
169
        delta = compare_trees(basis, working, want_unchanged=True)
193
170
    else:
215
192
    
216
193
    ret = {}
217
194
    basis = working.basis_tree()
218
 
 
 
195
    work_inv = working.inventory
 
196
    
219
197
    if (bzrlib.version_info[0] == 0) and (bzrlib.version_info[1] < 9):
220
198
        delta = compare_trees(basis, working, want_unchanged=True)
221
199
    else:
237
215
    ret['ignored'] = ignore_cnt
238
216
 
239
217
    dir_cnt = 0
240
 
    for path, ie in working.iter_entries_by_dir():
241
 
        if ie.kind == 'directory':
 
218
    for file_id in work_inv:
 
219
        if work_inv.get_file_kind(file_id) == 'directory':
242
220
            dir_cnt += 1
243
221
    ret['subdirs'] = dir_cnt
244
222
 
262
240
    if revno > 0:
263
241
        firstrev = repository.get_revision(history[0])
264
242
        age = int((time.time() - firstrev.timestamp) / 3600 / 24)
265
 
        ret['age'] = '%d days'%age
 
243
        ret['age'] = age
266
244
        ret['firstrev'] = osutils.format_date(firstrev.timestamp,
267
245
                                              firstrev.timezone)
268
246
 
281
259
    if repository.bzrdir.root_transport.listable():
282
260
        c, t = repository._revision_store.total_size(repository.get_transaction())
283
261
        ret['revisions'] = c
284
 
        ret['size'] = '%d KiB'%t
 
262
        ret['size'] = t
285
263
 
286
264
    return ret
287
265
 
300
278
 
301
279
    :param new_revision_spec:  if None, use working tree as new revision, otherwise use the tree for the specified revision.
302
280
    """
 
281
    import sys
 
282
    
 
283
    from bzrlib.diff import show_diff_trees
303
284
    
304
285
    if output == None:
305
286
        output = sys.stdout
306
287
    
 
288
    def spec_tree(spec):
 
289
        revision_id = spec.in_store(tree.branch).rev_id
 
290
        return tree.branch.repository.revision_tree(revision_id)
 
291
    
307
292
    if old_revision_spec is None:
308
293
        old_tree = tree.basis_tree()
309
294
    else:
317
302
    return show_diff_trees(old_tree, new_tree, output, specific_files,
318
303
                           external_diff_options,
319
304
                           old_label=old_label, new_label=new_label)
320
 
 
321
 
def spec_tree(spec):
322
 
        revision_id = spec.in_store(tree.branch).rev_id
323
 
        return tree.branch.repository.revision_tree(revision_id)