/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/backend/commit.py

  • Committer: Jelmer Vernooij
  • Date: 2008-06-28 16:59:50 UTC
  • mto: This revision was merged to the branch mainline in revision 516.
  • Revision ID: jelmer@samba.org-20080628165950-18kv7bdykgf1f1jf
Fix import in olive.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
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
22
 
from bzrlib.errors import NoSuchFile
23
 
 
24
 
from errors import ( LocalRequiresBoundBranch, NotBranchError, NonExistingParent,
25
 
                    PathPrefixNotCreated, NoLocationKnown,
26
 
                    DivergedBranchesError)
27
 
 
28
 
def commit(selected_list, message=None, unchanged=False,
29
 
           strict=False, local=False):
30
 
    """ Command to commit changes into the branch.
31
 
    
32
 
    :param selected_list: list of files you want to commit (at least the top working directory has to be specified)
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
 
 
47
 
    tree, selected_list = tree_files(selected_list)
48
 
    
49
 
    if local and not tree.branch.get_bound_location():
50
 
        raise LocalRequiresBoundBranch
51
 
 
52
 
    assert message is not None and len(message) > 0
53
 
 
54
 
    # FIXME: This should be a GtkCommitReporter!
55
 
    reporter = NullCommitReporter()
56
 
 
57
 
    tree.commit(message, specific_files=selected_list,
58
 
                    allow_pointless=unchanged, strict=strict, local=local,
59
 
                    reporter=reporter)
60
 
 
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
 
        
80
 
    br_from = Branch.open_containing(branch)[0]
81
 
    
82
 
    stored_loc = br_from.get_push_location()
83
 
    if location is None:
84
 
        if stored_loc is None:
85
 
            raise NoLocationKnown
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()
100
 
    except NotBranchError:
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)
107
 
            except NoSuchFile:
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()
117
 
                except NoSuchFile:
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()
132
 
            except NotLocalUrl:
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)
137
 
            except NoWorkingTree:
138
 
                count = br_to.pull(br_from, overwrite)
139
 
            else:
140
 
                count = tree_to.pull(br_from, overwrite)
141
 
        except DivergedBranches:
142
 
            raise DivergedBranchesError
143
 
    
144
 
    return count