/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 codecs
20
21
import bzrlib
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
22
from bzrlib.errors import NoSuchFile
0.8.2 by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented
23
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
24
from errors import ( LocalRequiresBoundBranch, NotBranchError, NonExistingParent,
0.8.7 by Szilveszter Farkas (Phanatic)
2006-06-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
25
                    PathPrefixNotCreated, NoLocationKnown,
0.8.3 by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet
26
                    DivergedBranchesError)
0.8.2 by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented
27
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
28
def commit(selected_list, message=None, unchanged=False,
0.8.2 by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented
29
           strict=False, local=False):
30
    """ Command to commit changes into the branch.
31
    
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
32
    :param selected_list: list of files you want to commit (at least the top working directory has to be specified)
0.8.2 by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented
33
    
34
    :param message: commit message
35
    
36
    :param file: the file which contains the commit message
37
    
38
    :param unchanged: force commit if nothing has changed since the last commit
39
    
40
    :param strict: refuse to commit if there are unknown files in the working tree
41
    
42
    :param local: perform a local only commit in a bound branch
43
    """
44
    from bzrlib.builtins import tree_files
45
    from bzrlib.commit import NullCommitReporter
46
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
47
    tree, selected_list = tree_files(selected_list)
0.8.2 by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented
48
    
49
    if local and not tree.branch.get_bound_location():
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
50
        raise LocalRequiresBoundBranch
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
51
52
    assert message is not None and len(message) > 0
53
54
    # FIXME: This should be a GtkCommitReporter!
0.8.2 by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented
55
    reporter = NullCommitReporter()
56
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
57
    tree.commit(message, specific_files=selected_list,
0.8.2 by Szilveszter Farkas (Phanatic)
* backend/commit.py: commit() implemented
58
                    allow_pointless=unchanged, strict=strict, local=local,
59
                    reporter=reporter)
60
0.8.3 by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet
61
def push(branch, location=None, remember=False, overwrite=False,
62
         create_prefix=False):
63
    """ Update a mirror of a branch.
64
    
65
    :param branch: the source branch
66
    
67
    :param location: the location of the branch that you'd like to update
68
    
69
    :param remember: if set, the location will be stored
70
    
71
    :param overwrite: overwrite target location if it diverged
72
    
73
    :param create_prefix: create the path leading up to the branch if it doesn't exist
74
    
75
    :return: number of revisions pushed
76
    """
77
    from bzrlib.branch import Branch
78
    from bzrlib.transport import get_transport
79
        
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
80
    br_from = Branch.open_containing(branch)[0]
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
81
    
0.8.3 by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet
82
    stored_loc = br_from.get_push_location()
83
    if location is None:
84
        if stored_loc is None:
0.8.7 by Szilveszter Farkas (Phanatic)
2006-06-20 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
85
            raise NoLocationKnown
0.8.3 by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet
86
        else:
87
            location = stored_loc
88
89
    transport = get_transport(location)
90
    location_url = transport.base
91
92
    if br_from.get_push_location() is None or remember:
93
        br_from.set_push_location(location_url)
94
95
    old_rh = []
96
97
    try:
98
        dir_to = bzrlib.bzrdir.BzrDir.open(location_url)
99
        br_to = dir_to.open_branch()
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
100
    except NotBranchError:
0.8.3 by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet
101
        # create a branch.
102
        transport = transport.clone('..')
103
        if not create_prefix:
104
            try:
105
                relurl = transport.relpath(location_url)
106
                transport.mkdir(relurl)
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
107
            except NoSuchFile:
0.8.3 by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet
108
                raise NonExistingParent(location)
109
        else:
110
            current = transport.base
111
            needed = [(transport, transport.relpath(location_url))]
112
            while needed:
113
                try:
114
                    transport, relpath = needed[-1]
115
                    transport.mkdir(relpath)
116
                    needed.pop()
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
117
                except NoSuchFile:
0.8.3 by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet
118
                    new_transport = transport.clone('..')
119
                    needed.append((new_transport,
120
                                   new_transport.relpath(transport.base)))
121
                    if new_transport.base == transport.base:
122
                        raise PathPrefixNotCreated
123
        dir_to = br_from.bzrdir.clone(location_url,
124
            revision_id=br_from.last_revision())
125
        br_to = dir_to.open_branch()
126
        count = len(br_to.revision_history())
127
    else:
128
        old_rh = br_to.revision_history()
129
        try:
130
            try:
131
                tree_to = dir_to.open_workingtree()
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
132
            except NotLocalUrl:
0.8.3 by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet
133
                # FIXME - what to do here? how should we warn the user?
134
                #warning('This transport does not update the working '
135
                #        'tree of: %s' % (br_to.base,))
136
                count = br_to.pull(br_from, overwrite)
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
137
            except NoWorkingTree:
0.8.3 by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet
138
                count = br_to.pull(br_from, overwrite)
139
            else:
140
                count = tree_to.pull(br_from, overwrite)
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
141
        except DivergedBranches:
0.8.3 by Szilveszter Farkas (Phanatic)
* backend/init.py: checkout() implemented - not tested yet
142
            raise DivergedBranchesError
143
    
144
    return count