/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
0.8.9 by Szilveszter Farkas (Phanatic)
2006-07-08 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
0.8.2 by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented
2
# Some parts of the code are:
3
# Copyright (C) 2005, 2006 by Canonical Ltd
4
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU General Public License for more details.
14
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
19
import bzrlib
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
20
from bzrlib.errors import NoSuchFile
0.8.2 by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented
21
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
22
from errors import ( LocalRequiresBoundBranch, NotBranchError, NonExistingParent,
0.8.7 by Szilveszter Farkas (Phanatic)
2006-06-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
23
                    PathPrefixNotCreated, NoLocationKnown,
0.8.3 by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet
24
                    DivergedBranchesError)
0.8.2 by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented
25
0.8.3 by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet
26
def push(branch, location=None, remember=False, overwrite=False,
27
         create_prefix=False):
28
    """ Update a mirror of a branch.
29
    
30
    :param branch: the source branch
31
    
32
    :param location: the location of the branch that you'd like to update
33
    
34
    :param remember: if set, the location will be stored
35
    
36
    :param overwrite: overwrite target location if it diverged
37
    
38
    :param create_prefix: create the path leading up to the branch if it doesn't exist
39
    
40
    :return: number of revisions pushed
41
    """
42
    from bzrlib.branch import Branch
43
    from bzrlib.transport import get_transport
44
        
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
45
    br_from = Branch.open_containing(branch)[0]
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
46
    
0.8.3 by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet
47
    stored_loc = br_from.get_push_location()
48
    if location is None:
49
        if stored_loc is None:
0.8.7 by Szilveszter Farkas (Phanatic)
2006-06-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
50
            raise NoLocationKnown
0.8.3 by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet
51
        else:
52
            location = stored_loc
53
54
    transport = get_transport(location)
55
    location_url = transport.base
56
57
    if br_from.get_push_location() is None or remember:
58
        br_from.set_push_location(location_url)
59
60
    old_rh = []
61
62
    try:
63
        dir_to = bzrlib.bzrdir.BzrDir.open(location_url)
64
        br_to = dir_to.open_branch()
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
65
    except NotBranchError:
0.8.3 by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet
66
        # create a branch.
67
        transport = transport.clone('..')
68
        if not create_prefix:
69
            try:
70
                relurl = transport.relpath(location_url)
71
                transport.mkdir(relurl)
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
72
            except NoSuchFile:
0.8.3 by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet
73
                raise NonExistingParent(location)
74
        else:
75
            current = transport.base
76
            needed = [(transport, transport.relpath(location_url))]
77
            while needed:
78
                try:
79
                    transport, relpath = needed[-1]
80
                    transport.mkdir(relpath)
81
                    needed.pop()
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
82
                except NoSuchFile:
0.8.3 by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet
83
                    new_transport = transport.clone('..')
84
                    needed.append((new_transport,
85
                                   new_transport.relpath(transport.base)))
86
                    if new_transport.base == transport.base:
87
                        raise PathPrefixNotCreated
88
        dir_to = br_from.bzrdir.clone(location_url,
89
            revision_id=br_from.last_revision())
90
        br_to = dir_to.open_branch()
91
        count = len(br_to.revision_history())
92
    else:
93
        old_rh = br_to.revision_history()
94
        try:
95
            try:
96
                tree_to = dir_to.open_workingtree()
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
97
            except NotLocalUrl:
0.8.3 by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet
98
                # FIXME - what to do here? how should we warn the user?
99
                #warning('This transport does not update the working '
100
                #        'tree of: %s' % (br_to.base,))
101
                count = br_to.pull(br_from, overwrite)
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
102
            except NoWorkingTree:
0.8.3 by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet
103
                count = br_to.pull(br_from, overwrite)
104
            else:
105
                count = tree_to.pull(br_from, overwrite)
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
106
        except DivergedBranches:
0.8.3 by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet
107
            raise DivergedBranchesError
108
    
109
    return count