/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:23:45 UTC
  • Revision ID: jelmer@samba.org-20070715162345-c8a8lq27g1euw83u
Add push item in revision menu, clean up push code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
 
2
# Copyright (C) 2007 by Jelmer Vernooij <jelmer@samba.org>
2
3
#
3
4
# This program is free software; you can redistribute it and/or modify
4
5
# it under the terms of the GNU General Public License as published by
33
34
 
34
35
class PushDialog(gtk.Dialog):
35
36
    """ New implementation of the Push dialog. """
36
 
    def __init__(self, branch, parent=None):
 
37
    def __init__(self, repository, revid, branch=None, parent=None):
37
38
        """ Initialize the Push dialog. """
38
39
        gtk.Dialog.__init__(self, title="Push - Olive",
39
40
                                  parent=parent,
41
42
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
42
43
        
43
44
        # Get arguments
 
45
        self.repository = repository
 
46
        self.revid = revid
44
47
        self.branch = branch
45
48
        
46
49
        # Create the widgets
47
50
        self._label_location = gtk.Label(_("Location:"))
48
51
        self._label_test = gtk.Label(_("(click the Test button to check write access)"))
49
 
        self._check_remember = gtk.CheckButton(_("_Remember as default location"),
50
 
                                               use_underline=True)
51
52
        self._check_prefix = gtk.CheckButton(_("Create the path _leading up to the location"),
52
53
                                             use_underline=True)
53
 
        self._check_overwrite = gtk.CheckButton(_("_Overwrite target if diverged"),
54
 
                                                use_underline=True)
55
54
        self._combo = gtk.ComboBoxEntry()
56
55
        self._button_test = gtk.Button(_("_Test"), use_underline=True)
57
56
        self._button_push = gtk.Button(_("_Push"), use_underline=True)
77
76
        self._hbox_test.pack_start(self._image_test, False, False)
78
77
        self._hbox_test.pack_start(self._label_test, True, True)
79
78
        self.vbox.pack_start(self._hbox_location)
80
 
        self.vbox.pack_start(self._check_remember)
81
79
        self.vbox.pack_start(self._check_prefix)
82
 
        self.vbox.pack_start(self._check_overwrite)
83
80
        self.vbox.pack_start(self._hbox_test)
84
81
        self.action_area.pack_start(self._button_test)
85
82
        self.action_area.pack_end(self._button_push)
99
96
        self._combo.set_model(self._combo_model)
100
97
        self._combo.set_text_column(0)
101
98
        
102
 
        location = self.branch.get_push_location()
103
 
        if location:
104
 
            self._combo.get_child().set_text(location)
 
99
        if self.branch is not None:
 
100
            location = self.branch.get_push_location()
 
101
            if location is not None:
 
102
                self._combo.get_child().set_text(location)
105
103
    
106
104
    def _on_test_clicked(self, widget):
107
105
        """ Test button clicked handler. """
133
131
        """ Push button clicked handler. """
134
132
        location = self._combo.get_child().get_text()
135
133
        revs = 0
 
134
        if self.branch is not None and self.branch.get_push_location() is None:
 
135
            response = question_dialog(_('Set default push location'),
 
136
                                       _('There is no default push location set.\nSet %r as default now?') % location)
 
137
            if response == gtk.REPONSE_OK:
 
138
                self.branch.set_push_location(location)
 
139
 
136
140
        try:
137
141
            revs = do_push(self.branch,
138
142
                           location=location,
139
 
                           overwrite=self._check_overwrite.get_active(),
140
 
                           remember=self._check_remember.get_active(),
 
143
                           overwrite=False,
141
144
                           create_prefix=self._check_prefix.get_active())
142
145
        except errors.DivergedBranches:
143
146
            response = question_dialog(_('Branches have been diverged'),
144
147
                                       _('You cannot push if branches have diverged.\nOverwrite?'))
145
148
            if response == gtk.RESPONSE_OK:
146
 
                revs = do_push(self.branch, overwrite=True)
 
149
                revs = do_push(self.branch, location=location,
 
150
                               overwrite=True,
 
151
                               create_prefix=self._check_prefix.get_active()
 
152
                               )
147
153
            return
148
154
        
149
155
        self._history.add_entry(location)
152
158
        
153
159
        self.response(gtk.RESPONSE_OK)
154
160
 
155
 
def do_push(branch, location=None, remember=False, overwrite=False,
156
 
         create_prefix=False):
 
161
def do_push(branch, location, overwrite, create_prefix):
157
162
    """ Update a mirror of a branch.
158
163
    
159
164
    :param branch: the source branch
160
165
    
161
166
    :param location: the location of the branch that you'd like to update
162
167
    
163
 
    :param remember: if set, the location will be stored
164
 
    
165
168
    :param overwrite: overwrite target location if it diverged
166
169
    
167
170
    :param create_prefix: create the path leading up to the branch if it doesn't exist
171
174
    from bzrlib.bzrdir import BzrDir
172
175
    from bzrlib.transport import get_transport
173
176
        
174
 
    br_from = branch
175
 
    
176
 
    stored_loc = br_from.get_push_location()
177
 
    if location is None:
178
 
        if stored_loc is None:
179
 
            error_dialog(_('Push location is unknown'),
180
 
                         _('Please specify a location manually.'))
181
 
            return
182
 
        else:
183
 
            location = stored_loc
184
 
 
185
177
    transport = get_transport(location)
186
178
    location_url = transport.base
187
179
 
188
 
    if br_from.get_push_location() is None or remember:
189
 
        br_from.set_push_location(location_url)
190
 
 
191
180
    old_rh = []
192
181
 
193
182
    try:
230
219
            tree_to = dir_to.open_workingtree()
231
220
        except errors.NotLocalUrl:
232
221
            # FIXME - what to do here? how should we warn the user?
233
 
            #warning('This transport does not update the working '
234
 
            #        'tree of: %s' % (br_to.base,))
235
222
            count = br_to.pull(br_from, overwrite)
236
223
        except errors.NoWorkingTree:
237
224
            count = br_to.pull(br_from, overwrite)