/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
227 by Jelmer Vernooij
Add push item in revision menu, clean up push code.
2
# Copyright (C) 2007 by Jelmer Vernooij <jelmer@samba.org>
0.8.46 by Szilveszter Farkas (Phanatic)
Modified OliveDialog class interface; huge cleanups.
3
#
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
0.8.46 by Szilveszter Farkas (Phanatic)
Modified OliveDialog class interface; huge cleanups.
8
#
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
0.8.46 by Szilveszter Farkas (Phanatic)
Modified OliveDialog class interface; huge cleanups.
13
#
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
try:
19
    import pygtk
20
    pygtk.require("2.0")
21
except:
22
    pass
724 by Jelmer Vernooij
Fix formatting, imports.
23
0.13.10 by Jelmer Vernooij
Don't pass around gladefile all the time.
24
import gtk
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
25
26
from errors import show_bzr_error
27
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
28
import bzrlib.errors as errors
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
29
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
30
from bzrlib.plugins.gtk import _i18n
724 by Jelmer Vernooij
Fix formatting, imports.
31
from bzrlib.plugins.gtk.dialog import (
32
    info_dialog,
33
    question_dialog,
34
    )
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
35
724 by Jelmer Vernooij
Fix formatting, imports.
36
from bzrlib.plugins.gtk.history import UrlHistory
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
37
38
class PushDialog(gtk.Dialog):
39
    """ New implementation of the Push dialog. """
724 by Jelmer Vernooij
Fix formatting, imports.
40
227 by Jelmer Vernooij
Add push item in revision menu, clean up push code.
41
    def __init__(self, repository, revid, branch=None, parent=None):
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
42
        """ Initialize the Push dialog. """
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
43
        gtk.Dialog.__init__(self, title="Push - Olive",
44
                                  parent=parent,
45
                                  flags=0,
46
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
724 by Jelmer Vernooij
Fix formatting, imports.
47
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
48
        # Get arguments
227 by Jelmer Vernooij
Add push item in revision menu, clean up push code.
49
        self.repository = repository
50
        self.revid = revid
0.13.13 by Jelmer Vernooij
Update TODO
51
        self.branch = branch
724 by Jelmer Vernooij
Fix formatting, imports.
52
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
53
        # Create the widgets
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
54
        self._label_location = gtk.Label(_i18n("Location:"))
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
55
        self._combo = gtk.ComboBoxEntry()
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
56
        self._button_push = gtk.Button(_i18n("_Push"), use_underline=True)
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
57
        self._hbox_location = gtk.HBox()
724 by Jelmer Vernooij
Fix formatting, imports.
58
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
59
        # Set callbacks
60
        self._button_push.connect('clicked', self._on_push_clicked)
724 by Jelmer Vernooij
Fix formatting, imports.
61
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
62
        # Set properties
63
        self._label_location.set_alignment(0, 0.5)
64
        self._hbox_location.set_spacing(3)
65
        self.vbox.set_spacing(3)
724 by Jelmer Vernooij
Fix formatting, imports.
66
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
67
        # Pack widgets
68
        self._hbox_location.pack_start(self._label_location, False, False)
69
        self._hbox_location.pack_start(self._combo, True, True)
70
        self.vbox.pack_start(self._hbox_location)
71
        self.action_area.pack_end(self._button_push)
724 by Jelmer Vernooij
Fix formatting, imports.
72
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
73
        # Show the dialog
74
        self.vbox.show_all()
724 by Jelmer Vernooij
Fix formatting, imports.
75
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
76
        # Build location history
154 by Jelmer Vernooij
Add trivial generic class for storing URL history.
77
        self._history = UrlHistory(self.branch.get_config(), 'push_history')
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
78
        self._build_history()
724 by Jelmer Vernooij
Fix formatting, imports.
79
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
80
    def _build_history(self):
81
        """ Build up the location history. """
154 by Jelmer Vernooij
Add trivial generic class for storing URL history.
82
        self._combo_model = gtk.ListStore(str)
83
        for item in self._history.get_entries():
84
            self._combo_model.append([ item ])
85
        self._combo.set_model(self._combo_model)
86
        self._combo.set_text_column(0)
724 by Jelmer Vernooij
Fix formatting, imports.
87
227 by Jelmer Vernooij
Add push item in revision menu, clean up push code.
88
        if self.branch is not None:
89
            location = self.branch.get_push_location()
90
            if location is not None:
91
                self._combo.get_child().set_text(location)
724 by Jelmer Vernooij
Fix formatting, imports.
92
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
93
    @show_bzr_error
94
    def _on_push_clicked(self, widget):
95
        """ Push button clicked handler. """
96
        location = self._combo.get_child().get_text()
97
        revs = 0
724 by Jelmer Vernooij
Fix formatting, imports.
98
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
99
        try:
228 by Jelmer Vernooij
Remove unused code, prefer questions to check boxes.
100
            revs = do_push(self.branch, location=location, overwrite=False)
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
101
        except errors.DivergedBranches:
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
102
            response = question_dialog(_i18n('Branches have been diverged'),
103
                                       _i18n('You cannot push if branches have diverged.\nOverwrite?'))
276 by Mateusz Korniak
Bugfix: Fixed push (with overwite) behavior when branches are diverged.
104
            if response == gtk.RESPONSE_YES:
228 by Jelmer Vernooij
Remove unused code, prefer questions to check boxes.
105
                revs = do_push(self.branch, location=location, overwrite=True)
724 by Jelmer Vernooij
Fix formatting, imports.
106
562 by Jasper Groenewegen
Merge removal of question to set default push location
107
        if self.branch is not None and self.branch.get_push_location() is None:
108
            self.branch.set_push_location(location)
724 by Jelmer Vernooij
Fix formatting, imports.
109
154 by Jelmer Vernooij
Add trivial generic class for storing URL history.
110
        self._history.add_entry(location)
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
111
        info_dialog(_i18n('Push successful'),
112
                    _i18n("%d revision(s) pushed.") % revs)
724 by Jelmer Vernooij
Fix formatting, imports.
113
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
114
        self.response(gtk.RESPONSE_OK)
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
115
724 by Jelmer Vernooij
Fix formatting, imports.
116
228 by Jelmer Vernooij
Remove unused code, prefer questions to check boxes.
117
def do_push(br_from, location, overwrite):
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
118
    """ Update a mirror of a branch.
724 by Jelmer Vernooij
Fix formatting, imports.
119
228 by Jelmer Vernooij
Remove unused code, prefer questions to check boxes.
120
    :param br_from: the source branch
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
121
    :param location: the location of the branch that you'd like to update
122
    :param overwrite: overwrite target location if it diverged
123
    :return: number of revisions pushed
124
    """
0.8.85 by Szilveszter Farkas (Phanatic)
Fix Push functionality.
125
    from bzrlib.bzrdir import BzrDir
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
126
    from bzrlib.transport import get_transport
724 by Jelmer Vernooij
Fix formatting, imports.
127
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
128
    transport = get_transport(location)
129
    location_url = transport.base
130
131
    old_rh = []
132
133
    try:
0.8.85 by Szilveszter Farkas (Phanatic)
Fix Push functionality.
134
        dir_to = BzrDir.open(location_url)
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
135
        br_to = dir_to.open_branch()
0.8.85 by Szilveszter Farkas (Phanatic)
Fix Push functionality.
136
    except errors.NotBranchError:
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
137
        # create a branch.
138
        transport = transport.clone('..')
228 by Jelmer Vernooij
Remove unused code, prefer questions to check boxes.
139
        try:
140
            relurl = transport.relpath(location_url)
141
            transport.mkdir(relurl)
142
        except errors.NoSuchFile:
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
143
            response = question_dialog(_i18n('Non existing parent directory'),
144
                         _i18n("The parent directory (%s)\ndoesn't exist. Create?") % location)
228 by Jelmer Vernooij
Remove unused code, prefer questions to check boxes.
145
            if response == gtk.RESPONSE_OK:
629 by Jelmer Vernooij
Use new transport.create_prefix.
146
                transport.create_prefix()
228 by Jelmer Vernooij
Remove unused code, prefer questions to check boxes.
147
            else:
0.8.85 by Szilveszter Farkas (Phanatic)
Fix Push functionality.
148
                return
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
149
        dir_to = br_from.bzrdir.clone(location_url,
150
            revision_id=br_from.last_revision())
151
        br_to = dir_to.open_branch()
152
        count = len(br_to.revision_history())
153
    else:
154
        old_rh = br_to.revision_history()
155
        try:
0.13.13 by Jelmer Vernooij
Update TODO
156
            tree_to = dir_to.open_workingtree()
157
        except errors.NotLocalUrl:
158
            # FIXME - what to do here? how should we warn the user?
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
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
165
    return count