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

  • Committer: Szilveszter Farkas (Phanatic)
  • Date: 2006-06-12 23:18:08 UTC
  • mto: (0.14.1 main) (93.1.1 win32.bialix)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: Szilveszter.Farkas@gmail.com-20060612231808-cb80db10cf0beaf1
* backend/init.py: checkout() implemented - not tested yet
* backend/commit.py: push() implemented - not tested yet
* backend/error.py: another bunch of exceptions added

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
from errors import (EmptyMessageError, NoMessageNoFileError,
25
25
                    NoChangesToCommitError, ConflictsInTreeError,
26
26
                    StrictCommitError, BoundBranchOutOfDate,
27
 
                    LocalRequiresBoundBranch, NotBranchError)
 
27
                    LocalRequiresBoundBranch, NotBranchError, NonExistingParent,
 
28
                    PathPrefixNotCreated, NoPushLocationKnown,
 
29
                    DivergedBranchesError)
28
30
 
29
31
def commit(selected_list, message=None, file=None, unchanged=False,
30
32
           strict=False, local=False):
79
81
    except errors.BoundBranchOutOfDate, e:
80
82
        raise BoundBranchOutOfDate(str(e))
81
83
 
 
84
# FIXME - not tested yet
 
85
def push(branch, location=None, remember=False, overwrite=False,
 
86
         create_prefix=False):
 
87
    """ Update a mirror of a branch.
 
88
    
 
89
    :param branch: the source branch
 
90
    
 
91
    :param location: the location of the branch that you'd like to update
 
92
    
 
93
    :param remember: if set, the location will be stored
 
94
    
 
95
    :param overwrite: overwrite target location if it diverged
 
96
    
 
97
    :param create_prefix: create the path leading up to the branch if it doesn't exist
 
98
    
 
99
    :return: number of revisions pushed
 
100
    """
 
101
    from bzrlib.branch import Branch
 
102
    from bzrlib.transport import get_transport
 
103
        
 
104
    br_from = Branch.open_containing(branch)[0]
 
105
    stored_loc = br_from.get_push_location()
 
106
    if location is None:
 
107
        if stored_loc is None:
 
108
            raise NoPushLocationKnown
 
109
        else:
 
110
            location = stored_loc
 
111
 
 
112
    transport = get_transport(location)
 
113
    location_url = transport.base
 
114
 
 
115
    if br_from.get_push_location() is None or remember:
 
116
        br_from.set_push_location(location_url)
 
117
 
 
118
    old_rh = []
 
119
 
 
120
    try:
 
121
        dir_to = bzrlib.bzrdir.BzrDir.open(location_url)
 
122
        br_to = dir_to.open_branch()
 
123
    except NotBranchError:
 
124
        # create a branch.
 
125
        transport = transport.clone('..')
 
126
        if not create_prefix:
 
127
            try:
 
128
                relurl = transport.relpath(location_url)
 
129
                transport.mkdir(relurl)
 
130
            except errors.NoSuchFile:
 
131
                raise NonExistingParent(location)
 
132
        else:
 
133
            current = transport.base
 
134
            needed = [(transport, transport.relpath(location_url))]
 
135
            while needed:
 
136
                try:
 
137
                    transport, relpath = needed[-1]
 
138
                    transport.mkdir(relpath)
 
139
                    needed.pop()
 
140
                except errors.NoSuchFile:
 
141
                    new_transport = transport.clone('..')
 
142
                    needed.append((new_transport,
 
143
                                   new_transport.relpath(transport.base)))
 
144
                    if new_transport.base == transport.base:
 
145
                        raise PathPrefixNotCreated
 
146
        dir_to = br_from.bzrdir.clone(location_url,
 
147
            revision_id=br_from.last_revision())
 
148
        br_to = dir_to.open_branch()
 
149
        count = len(br_to.revision_history())
 
150
    else:
 
151
        old_rh = br_to.revision_history()
 
152
        try:
 
153
            try:
 
154
                tree_to = dir_to.open_workingtree()
 
155
            except errors.NotLocalUrl:
 
156
                # FIXME - what to do here? how should we warn the user?
 
157
                #warning('This transport does not update the working '
 
158
                #        'tree of: %s' % (br_to.base,))
 
159
                count = br_to.pull(br_from, overwrite)
 
160
            except errors.NoWorkingTree:
 
161
                count = br_to.pull(br_from, overwrite)
 
162
            else:
 
163
                count = tree_to.pull(br_from, overwrite)
 
164
        except errors.DivergedBranches:
 
165
            raise DivergedBranchesError
 
166
    
 
167
    return count