/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: 2012-03-05 14:02:16 UTC
  • Revision ID: jelmer@samba.org-20120305140216-kin6qx701t4205ej
Only show annotate option for files in nautilus-bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
 
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic)
 
2
#                       <szilveszter.farkas@gmail.com>
2
3
# Copyright (C) 2007 by Jelmer Vernooij <jelmer@samba.org>
3
4
#
4
5
# This program is free software; you can redistribute it and/or modify
19
20
 
20
21
from errors import show_bzr_error
21
22
 
22
 
import bzrlib.errors as errors
 
23
from bzrlib import (
 
24
    errors,
 
25
    ui,
 
26
    )
 
27
from bzrlib.bzrdir import BzrDir
 
28
from bzrlib.transport import get_transport
23
29
 
24
30
from bzrlib.plugins.gtk.dialog import (
25
 
    info_dialog,
26
31
    question_dialog,
27
32
    )
28
 
 
29
33
from bzrlib.plugins.gtk.history import UrlHistory
30
34
from bzrlib.plugins.gtk.i18n import _i18n
 
35
from bzrlib.plugins.gtk.ui import ProgressPanel
31
36
 
32
37
 
33
38
class PushDialog(Gtk.Dialog):
34
39
    """New implementation of the Push dialog."""
35
40
 
36
 
    def __init__(self, repository, revid, branch=None, parent=None):
 
41
    def __init__(self, repository=None, revid=None, branch=None, parent=None):
37
42
        """Initialize the Push dialog. """
38
 
        GObject.GObject.__init__(self, title="Push",
39
 
                                  parent=parent,
40
 
                                  flags=0,
41
 
                                  buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
 
43
        super(PushDialog, self).__init__(
 
44
            title="Push", parent=parent, flags=0, border_width=6,
 
45
            buttons=(Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE))
 
46
        if repository is None:
 
47
            repository = branch.repository
 
48
        self.branch = branch
42
49
 
43
 
        # Get arguments
 
50
        # Unused arguments
44
51
        self.repository = repository
 
52
        if revid is None:
 
53
            revid = branch.last_revision()
45
54
        self.revid = revid
46
 
        self.branch = branch
47
55
 
48
56
        # Create the widgets
49
57
        self._label_location = Gtk.Label(label=_i18n("Location:"))
50
 
        self._combo = Gtk.ComboBoxEntry()
 
58
        self._combo = Gtk.ComboBox.new_with_entry()
51
59
        self._button_push = Gtk.Button(_i18n("_Push"), use_underline=True)
52
 
        self._hbox_location = Gtk.HBox()
 
60
        self._hbox_location = Gtk.Box(Gtk.Orientation.HORIZONTAL, 6)
 
61
        self._push_message = Gtk.Label(xalign=0)
 
62
        self._progress_widget = ProgressPanel()
53
63
 
54
64
        # Set callbacks
 
65
        ui.ui_factory.set_progress_bar_widget(self._progress_widget)
 
66
        self.connect('close', self._on_close_clicked)
55
67
        self._button_push.connect('clicked', self._on_push_clicked)
56
68
 
57
69
        # Set properties
58
 
        self._label_location.set_alignment(0, 0.5)
59
 
        self._hbox_location.set_spacing(3)
60
 
        self.vbox.set_spacing(3)
 
70
        content_area = self.get_content_area()
 
71
        content_area.set_spacing(6)
61
72
 
62
73
        # Pack widgets
63
 
        self._hbox_location.pack_start(self._label_location, False, False)
64
 
        self._hbox_location.pack_start(self._combo, True, True)
65
 
        self.vbox.pack_start(self._hbox_location, True, True, 0)
66
 
        self.action_area.pack_end(self._button_push)
 
74
        self._hbox_location.pack_start(self._label_location, False, False, 0)
 
75
        self._hbox_location.pack_start(self._combo, False, False, 0)
 
76
        content_area.pack_start(self._hbox_location, True, True, 0)
 
77
        content_area.pack_start(self._progress_widget, True, True, 0)
 
78
        content_area.pack_start(self._push_message, True, True, 0)
 
79
        self.get_action_area().pack_end(self._button_push, True, True, 0)
67
80
 
68
81
        # Show the dialog
69
 
        self.vbox.show_all()
 
82
        content_area.show_all()
 
83
        self._progress_widget.hide()
 
84
        self._push_message.hide()
70
85
 
71
86
        # Build location history
72
87
        self._history = UrlHistory(self.branch.get_config(), 'push_history')
76
91
        """Build up the location history. """
77
92
        self._combo_model = Gtk.ListStore(str)
78
93
        for item in self._history.get_entries():
79
 
            self._combo_model.append([ item ])
 
94
            self._combo_model.append([item])
80
95
        self._combo.set_model(self._combo_model)
81
 
        self._combo.set_text_column(0)
 
96
        self._combo.set_entry_text_column(0)
82
97
 
83
98
        if self.branch is not None:
84
99
            location = self.branch.get_push_location()
85
100
            if location is not None:
86
101
                self._combo.get_child().set_text(location)
87
102
 
 
103
    def _on_close_clicked(self, widget):
 
104
        """Close dialog handler."""
 
105
        ui.ui_factory.set_progress_bar_widget(None)
 
106
 
88
107
    @show_bzr_error
89
108
    def _on_push_clicked(self, widget):
90
109
        """Push button clicked handler. """
 
110
        self._push_message.hide()
 
111
        self._progress_widget.tick()
91
112
        location = self._combo.get_child().get_text()
92
 
        revs = 0
93
113
 
94
114
        try:
95
 
            revs = do_push(self.branch, location=location, overwrite=False)
 
115
            message = do_push(self.branch, location, overwrite=False)
96
116
        except errors.DivergedBranches:
97
 
            response = question_dialog(_i18n('Branches have been diverged'),
98
 
                                       _i18n('You cannot push if branches have diverged.\nOverwrite?'))
 
117
            response = question_dialog(
 
118
                _i18n('Branches have been diverged'),
 
119
                _i18n('You cannot push if branches have diverged.\n'
 
120
                      'Overwrite?'))
99
121
            if response == Gtk.ResponseType.YES:
100
 
                revs = do_push(self.branch, location=location, overwrite=True)
101
 
 
102
 
        if self.branch is not None and self.branch.get_push_location() is None:
 
122
                message = do_push(self.branch, location, overwrite=True)
 
123
            else:
 
124
                return
 
125
        self._history.add_entry(location)
 
126
        if (self.branch is not None
 
127
            and self.branch.get_push_location() is None):
103
128
            self.branch.set_push_location(location)
104
 
 
105
 
        self._history.add_entry(location)
106
 
        info_dialog(_i18n('Push successful'),
107
 
                    _i18n("%d revision(s) pushed.") % revs)
108
 
 
109
 
        self.response(Gtk.ResponseType.OK)
 
129
        if message:
 
130
            self._progress_widget.finished()
 
131
            self._push_message.props.label = message
 
132
            self._push_message.show()
110
133
 
111
134
 
112
135
def do_push(br_from, location, overwrite):
117
140
    :param overwrite: overwrite target location if it diverged
118
141
    :return: number of revisions pushed
119
142
    """
120
 
    from bzrlib.bzrdir import BzrDir
121
 
    from bzrlib.transport import get_transport
122
 
 
123
143
    transport = get_transport(location)
124
144
    location_url = transport.base
125
145
 
126
 
    old_rh = []
127
 
 
128
146
    try:
129
147
        dir_to = BzrDir.open(location_url)
130
148
        br_to = dir_to.open_branch()
135
153
            relurl = transport.relpath(location_url)
136
154
            transport.mkdir(relurl)
137
155
        except errors.NoSuchFile:
138
 
            response = question_dialog(_i18n('Non existing parent directory'),
139
 
                         _i18n("The parent directory (%s)\ndoesn't exist. Create?") % location)
 
156
            response = question_dialog(
 
157
                _i18n('Non existing parent directory'),
 
158
                _i18n("The parent directory (%s)\ndoesn't exist. Create?") %
 
159
                location)
140
160
            if response == Gtk.ResponseType.OK:
141
161
                transport.create_prefix()
142
162
            else:
146
166
        br_to = dir_to.open_branch()
147
167
        count = len(br_to.revision_history())
148
168
    else:
149
 
        old_rh = br_to.revision_history()
 
169
        br_to.revision_history()
150
170
        try:
151
171
            tree_to = dir_to.open_workingtree()
152
172
        except errors.NotLocalUrl:
157
177
        else:
158
178
            count = tree_to.pull(br_from, overwrite)
159
179
 
160
 
    return count
 
180
    # The count var is either an int or a PushResult. PushResult is being
 
181
    # coerced into an int, but the method is deprecated.
 
182
    return _i18n("%d revision(s) pushed.") % int(count)