/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 push.py

  • Committer: Jelmer Vernooij
  • Date: 2007-07-15 16:33:48 UTC
  • Revision ID: jelmer@samba.org-20070715163348-taiailweuoc5a9jf
Remove unused code, prefer questions to check boxes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
from errors import show_bzr_error
27
27
 
 
28
# FIXME: This needs to be public JRV 20070714
 
29
from bzrlib.builtins import _create_prefix
28
30
from bzrlib.config import LocationConfig
29
31
import bzrlib.errors as errors
30
32
 
49
51
        # Create the widgets
50
52
        self._label_location = gtk.Label(_("Location:"))
51
53
        self._label_test = gtk.Label(_("(click the Test button to check write access)"))
52
 
        self._check_prefix = gtk.CheckButton(_("Create the path _leading up to the location"),
53
 
                                             use_underline=True)
54
54
        self._combo = gtk.ComboBoxEntry()
55
55
        self._button_test = gtk.Button(_("_Test"), use_underline=True)
56
56
        self._button_push = gtk.Button(_("_Push"), use_underline=True)
76
76
        self._hbox_test.pack_start(self._image_test, False, False)
77
77
        self._hbox_test.pack_start(self._label_test, True, True)
78
78
        self.vbox.pack_start(self._hbox_location)
79
 
        self.vbox.pack_start(self._check_prefix)
80
79
        self.vbox.pack_start(self._hbox_test)
81
80
        self.action_area.pack_start(self._button_test)
82
81
        self.action_area.pack_end(self._button_push)
138
137
                self.branch.set_push_location(location)
139
138
 
140
139
        try:
141
 
            revs = do_push(self.branch,
142
 
                           location=location,
143
 
                           overwrite=False,
144
 
                           create_prefix=self._check_prefix.get_active())
 
140
            revs = do_push(self.branch, location=location, overwrite=False)
145
141
        except errors.DivergedBranches:
146
142
            response = question_dialog(_('Branches have been diverged'),
147
143
                                       _('You cannot push if branches have diverged.\nOverwrite?'))
148
144
            if response == gtk.RESPONSE_OK:
149
 
                revs = do_push(self.branch, location=location,
150
 
                               overwrite=True,
151
 
                               create_prefix=self._check_prefix.get_active()
152
 
                               )
 
145
                revs = do_push(self.branch, location=location, overwrite=True)
153
146
            return
154
147
        
155
148
        self._history.add_entry(location)
158
151
        
159
152
        self.response(gtk.RESPONSE_OK)
160
153
 
161
 
def do_push(branch, location, overwrite, create_prefix):
 
154
def do_push(br_from, location, overwrite):
162
155
    """ Update a mirror of a branch.
163
156
    
164
 
    :param branch: the source branch
 
157
    :param br_from: the source branch
165
158
    
166
159
    :param location: the location of the branch that you'd like to update
167
160
    
168
161
    :param overwrite: overwrite target location if it diverged
169
162
    
170
 
    :param create_prefix: create the path leading up to the branch if it doesn't exist
171
 
    
172
163
    :return: number of revisions pushed
173
164
    """
174
165
    from bzrlib.bzrdir import BzrDir
185
176
    except errors.NotBranchError:
186
177
        # create a branch.
187
178
        transport = transport.clone('..')
188
 
        if not create_prefix:
189
 
            try:
190
 
                relurl = transport.relpath(location_url)
191
 
                transport.mkdir(relurl)
192
 
            except errors.NoSuchFile:
193
 
                error_dialog(_('Non existing parent directory'),
194
 
                             _("The parent directory (%s)\ndoesn't exist.") % location)
 
179
        try:
 
180
            relurl = transport.relpath(location_url)
 
181
            transport.mkdir(relurl)
 
182
        except errors.NoSuchFile:
 
183
            response = question_dialog(_('Non existing parent directory'),
 
184
                         _("The parent directory (%s)\ndoesn't exist. Create?") % location)
 
185
            if response == gtk.RESPONSE_OK:
 
186
                _create_prefix(transport)
 
187
            else:
195
188
                return
196
 
        else:
197
 
            current = transport.base
198
 
            needed = [(transport, transport.relpath(location_url))]
199
 
            while needed:
200
 
                try:
201
 
                    transport, relpath = needed[-1]
202
 
                    transport.mkdir(relpath)
203
 
                    needed.pop()
204
 
                except errors.NoSuchFile:
205
 
                    new_transport = transport.clone('..')
206
 
                    needed.append((new_transport,
207
 
                                   new_transport.relpath(transport.base)))
208
 
                    if new_transport.base == transport.base:
209
 
                        error_dialog(_('Path prefix not created'),
210
 
                                     _("The path leading up to the specified location couldn't\nbe created."))
211
 
                        return
212
189
        dir_to = br_from.bzrdir.clone(location_url,
213
190
            revision_id=br_from.last_revision())
214
191
        br_to = dir_to.open_branch()