~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to branches.py

  • Committer: Aaron Bentley
  • Date: 2007-12-22 00:52:23 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20071222005223-05qb47i4jxil7n2j
Update branches to new find_branches API

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from bzrlib import errors
 
2
from bzrlib.bzrdir import BzrDir
1
3
from bzrlib.transport import get_transport
2
 
from bzrtools import iter_branches, apache_ls
 
4
from bzrtools import apache_ls
 
5
 
 
6
 
 
7
 
 
8
def list_branches(t):
 
9
    def is_inside(branch):
 
10
        return bool(branch.base.startswith(t.base))
 
11
 
 
12
    if t.base.startswith('http://'):
 
13
        def evaluate(bzrdir):
 
14
            try:
 
15
                branch = bzrdir.open_branch()
 
16
                if is_inside(branch):
 
17
                    return True, branch
 
18
                else:
 
19
                    return True, None
 
20
            except errors.NotBranchError:
 
21
                return True, None
 
22
        return [b for b in BzrDir.find_bzrdirs(t, list_current=apache_ls,
 
23
                evaluate=evaluate) if b is not None]
 
24
    elif not t.listable():
 
25
        raise BzrCommandError("Can't list this type of location.")
 
26
    return [b for b in BzrDir.find_branches(t) if is_inside(b)]
 
27
 
3
28
 
4
29
def branches(location=None):
5
30
    if location is None:
6
31
        location = '.'
7
32
    t = get_transport(location)
8
 
    if location.startswith('http://'):
9
 
        lister = apache_ls
10
 
    elif not t.listable():
11
 
        print "Can't list this type of location."
12
 
        return 3
13
 
    else:
14
 
        lister = None
15
 
    for branch in iter_branches(t, lister):
 
33
    for branch in list_branches(t):
 
34
        if branch is None:
 
35
            continue
16
36
        print branch.base[len(t.base):].rstrip('/')