15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
from gi.repository import Gtk
20
26
from errors import show_bzr_error
28
# FIXME: This needs to be public JRV 20070714
29
from bzrlib.builtins import _create_prefix
30
from bzrlib.config import LocationConfig
22
31
import bzrlib.errors as errors
24
from bzrlib.plugins.gtk.dialog import (
29
from bzrlib.plugins.gtk.history import UrlHistory
30
from bzrlib.plugins.gtk.i18n import _i18n
33
class PushDialog(Gtk.Dialog):
34
"""New implementation of the Push dialog."""
33
from dialog import error_dialog, info_dialog, question_dialog
35
from history import UrlHistory
37
class PushDialog(gtk.Dialog):
38
""" New implementation of the Push dialog. """
36
39
def __init__(self, repository, revid, branch=None, parent=None):
37
"""Initialize the Push dialog. """
38
GObject.GObject.__init__(self, title="Push",
40
""" Initialize the Push dialog. """
41
gtk.Dialog.__init__(self, title="Push - Olive",
41
buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
44
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
44
47
self.repository = repository
46
49
self.branch = branch
48
51
# Create the widgets
49
self._label_location = Gtk.Label(label=_i18n("Location:"))
50
self._combo = Gtk.ComboBoxEntry()
51
self._button_push = Gtk.Button(_i18n("_Push"), use_underline=True)
52
self._hbox_location = Gtk.HBox()
52
self._label_location = gtk.Label(_("Location:"))
53
self._combo = gtk.ComboBoxEntry()
54
self._button_push = gtk.Button(_("_Push"), use_underline=True)
55
self._hbox_location = gtk.HBox()
55
58
self._button_push.connect('clicked', self._on_push_clicked)
58
61
self._label_location.set_alignment(0, 0.5)
59
62
self._hbox_location.set_spacing(3)
60
63
self.vbox.set_spacing(3)
63
66
self._hbox_location.pack_start(self._label_location, False, False)
64
67
self._hbox_location.pack_start(self._combo, True, True)
65
self.vbox.pack_start(self._hbox_location, True, True, 0)
68
self.vbox.pack_start(self._hbox_location)
66
69
self.action_area.pack_end(self._button_push)
69
72
self.vbox.show_all()
71
74
# Build location history
72
75
self._history = UrlHistory(self.branch.get_config(), 'push_history')
73
76
self._build_history()
75
78
def _build_history(self):
76
"""Build up the location history. """
77
self._combo_model = Gtk.ListStore(str)
79
""" Build up the location history. """
80
self._combo_model = gtk.ListStore(str)
78
81
for item in self._history.get_entries():
79
82
self._combo_model.append([ item ])
80
83
self._combo.set_model(self._combo_model)
81
84
self._combo.set_text_column(0)
83
86
if self.branch is not None:
84
87
location = self.branch.get_push_location()
85
88
if location is not None:
86
89
self._combo.get_child().set_text(location)
89
92
def _on_push_clicked(self, widget):
90
"""Push button clicked handler. """
93
""" Push button clicked handler. """
91
94
location = self._combo.get_child().get_text()
96
if self.branch is not None and self.branch.get_push_location() is None:
97
response = question_dialog(_('Set default push location'),
98
_('There is no default push location set.\nSet %r as default now?') % location)
99
if response == gtk.RESPONSE_OK:
100
self.branch.set_push_location(location)
95
103
revs = do_push(self.branch, location=location, overwrite=False)
96
104
except errors.DivergedBranches:
97
response = question_dialog(_i18n('Branches have been diverged'),
98
_i18n('You cannot push if branches have diverged.\nOverwrite?'))
99
if response == Gtk.ResponseType.YES:
105
response = question_dialog(_('Branches have been diverged'),
106
_('You cannot push if branches have diverged.\nOverwrite?'))
107
if response == gtk.RESPONSE_YES:
100
108
revs = do_push(self.branch, location=location, overwrite=True)
102
if self.branch is not None and self.branch.get_push_location() is None:
103
self.branch.set_push_location(location)
105
110
self._history.add_entry(location)
106
info_dialog(_i18n('Push successful'),
107
_i18n("%d revision(s) pushed.") % revs)
109
self.response(Gtk.ResponseType.OK)
111
info_dialog(_('Push successful'),
112
_("%d revision(s) pushed.") % revs)
114
self.response(gtk.RESPONSE_OK)
112
116
def do_push(br_from, location, overwrite):
113
"""Update a mirror of a branch.
117
""" Update a mirror of a branch.
115
119
:param br_from: the source branch
116
121
:param location: the location of the branch that you'd like to update
117
123
:param overwrite: overwrite target location if it diverged
118
125
:return: number of revisions pushed
120
127
from bzrlib.bzrdir import BzrDir
121
128
from bzrlib.transport import get_transport
123
130
transport = get_transport(location)
124
131
location_url = transport.base