/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: 2006-09-05 01:37:16 UTC
  • mto: (0.8.83 merge)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: jelmer@samba.org-20060905013716-ed1ce9389829a5a1
Integrate olive.backend.fileops

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 bzrlib
 
20
from bzrlib.errors import NoSuchFile
 
21
 
 
22
from errors import ( LocalRequiresBoundBranch, NotBranchError, NonExistingParent,
 
23
                    PathPrefixNotCreated, NoLocationKnown,
 
24
                    DivergedBranchesError)
 
25
 
 
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
        
 
45
    br_from = Branch.open_containing(branch)[0]
 
46
    
 
47
    stored_loc = br_from.get_push_location()
 
48
    if location is None:
 
49
        if stored_loc is None:
 
50
            raise NoLocationKnown
 
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()
 
65
    except NotBranchError:
 
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)
 
72
            except NoSuchFile:
 
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()
 
82
                except NoSuchFile:
 
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()
 
97
            except NotLocalUrl:
 
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)
 
102
            except NoWorkingTree:
 
103
                count = br_to.pull(br_from, overwrite)
 
104
            else:
 
105
                count = tree_to.pull(br_from, overwrite)
 
106
        except DivergedBranches:
 
107
            raise DivergedBranchesError
 
108
    
 
109
    return count