/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 olive/commit.py

  • Committer: Szilveszter Farkas (Phanatic)
  • Date: 2006-12-10 20:16:18 UTC
  • Revision ID: szilveszter.farkas@gmail.com-20061210201618-hhaij79cvzalo9sg
Rename put into context menu (Fixed: #73774).

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
import sys
18
 
 
19
17
try:
20
18
    import pygtk
21
19
    pygtk.require("2.0")
22
20
except:
23
21
    pass
24
 
try:
25
 
    import gtk
26
 
    import gtk.glade
27
 
    import gobject
28
 
    import pango
29
 
except:
30
 
    sys.exit(1)
31
 
 
32
 
from bzrlib import version_info
33
 
 
34
 
if version_info < (0, 9):
35
 
    # function deprecated after 0.9
36
 
    from bzrlib.delta import compare_trees
 
22
 
 
23
import gtk
 
24
import gtk.glade
 
25
import gobject
 
26
import pango
37
27
 
38
28
import bzrlib.errors as errors
39
 
from bzrlib.workingtree import WorkingTree
40
 
 
41
 
class OliveCommit:
 
29
from bzrlib import osutils
 
30
 
 
31
from dialog import error_dialog, question_dialog
 
32
from guifiles import GLADEFILENAME
 
33
 
 
34
 
 
35
class CommitDialog:
42
36
    """ Display Commit dialog and perform the needed actions. """
43
 
    def __init__(self, gladefile, comm, dialog):
44
 
        """ Initialize the Commit dialog. """
45
 
        self.gladefile = gladefile
46
 
        self.glade = gtk.glade.XML(self.gladefile, 'window_commit', 'olive-gtk')
47
 
        
48
 
        # Communication object
49
 
        self.comm = comm
50
 
        # Dialog object
51
 
        self.dialog = dialog
52
 
        
 
37
    def __init__(self, wt, wtpath, notbranch):
 
38
        """ Initialize the Commit dialog.
 
39
        :param  wt:         bzr working tree object
 
40
        :param  wtpath:     path to working tree root
 
41
        :param  notbranch:  flag that path is not a brach
 
42
        :type   notbranch:  bool
 
43
        """
 
44
        self.glade = gtk.glade.XML(GLADEFILENAME, 'window_commit', 'olive-gtk')
 
45
        
 
46
        self.wt = wt
 
47
        self.wtpath = wtpath
 
48
        self.notbranch = notbranch
 
49
 
53
50
        # Get some important widgets
54
51
        self.window = self.glade.get_widget('window_commit')
55
52
        self.checkbutton_local = self.glade.get_widget('checkbutton_commit_local')
56
53
        self.textview = self.glade.get_widget('textview_commit')
 
54
        self.file_expander = self.glade.get_widget('expander_commit_select')
57
55
        self.file_view = self.glade.get_widget('treeview_commit_select')
58
 
 
59
 
        # Check if current location is a branch
60
 
        try:
61
 
            (self.wt, path) = WorkingTree.open_containing(self.comm.get_path())
62
 
            branch = self.wt.branch
63
 
        except errors.NotBranchError:
64
 
            self.notbranch = True
65
 
            return
66
 
        except:
67
 
            raise
68
 
 
69
 
        file_id = self.wt.path2id(path)
70
 
 
71
 
        self.notbranch = False
72
 
        if file_id is None:
73
 
            self.notbranch = True
 
56
        self.pending_expander = self.glade.get_widget('expander_commit_pending')
 
57
        self.pending_label = self.glade.get_widget('label_commit_pending')
 
58
        self.pending_view = self.glade.get_widget('treeview_commit_pending')
 
59
 
 
60
        if wt is None or notbranch:
74
61
            return
75
62
        
76
63
        # Set the delta
77
64
        self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
78
 
        if version_info < (0, 9):
79
 
            self.delta = compare_trees(self.old_tree, self.wt)
80
 
        else:
81
 
            self.delta = self.wt.changes_from(self.old_tree)
 
65
        self.delta = self.wt.changes_from(self.old_tree)
 
66
        
 
67
        # Get pending merges
 
68
        self.pending = self._pending_merges(self.wt)
82
69
        
83
70
        # Dictionary for signal_autoconnect
84
71
        dic = { "on_button_commit_commit_clicked": self.commit,
85
72
                "on_button_commit_cancel_clicked": self.close }
86
 
        
 
73
 
87
74
        # Connect the signals to the handlers
88
75
        self.glade.signal_autoconnect(dic)
89
76
        
90
77
        # Create the file list
91
78
        self._create_file_view()
 
79
        # Create the pending merges
 
80
        self._create_pending_merges()
92
81
    
93
82
    def display(self):
94
 
        """ Display the Push dialog. """
 
83
        """ Display the Push dialog.
 
84
        @return:    True if dialog is shown.
 
85
        """
 
86
        if self.wt is None and not self.notbranch:
 
87
            error_dialog(_('Directory does not have a working tree'),
 
88
                         _('Operation aborted.'))
 
89
            self.close()
 
90
            dialog_shown = False
95
91
        if self.notbranch:
96
 
            self.dialog.error_dialog(_('Directory is not a branch'),
97
 
                                     _('You can perform this action only in a branch.'))
 
92
            error_dialog(_('Directory is not a branch'),
 
93
                         _('You can perform this action only in a branch.'))
98
94
            self.close()
 
95
            dialog_shown = False
99
96
        else:
100
 
            from olive.backend.info import is_checkout
101
 
            if is_checkout(self.comm.get_path()):
 
97
            if self.wt.branch.get_bound_location() is not None:
102
98
                # we have a checkout, so the local commit checkbox must appear
103
99
                self.checkbutton_local.show()
104
100
            
 
101
            if self.pending:
 
102
                # There are pending merges, file selection not supported
 
103
                self.file_expander.set_expanded(False)
 
104
                self.file_view.set_sensitive(False)
 
105
            else:
 
106
                # No pending merges
 
107
                self.pending_expander.hide()
 
108
            
105
109
            self.textview.modify_font(pango.FontDescription("Monospace"))
106
110
            self.window.show()
107
 
            
 
111
            dialog_shown = True
 
112
        if dialog_shown:
 
113
            # Gives the focus to the commit message area
 
114
            self.textview.grab_focus()
 
115
        return dialog_shown
108
116
    
109
 
    # This code is from Jelmer Vernooij's bzr-gtk branch
110
117
    def _create_file_view(self):
111
 
        self.file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,
112
 
                                        gobject.TYPE_STRING,
113
 
                                        gobject.TYPE_STRING)
 
118
        self.file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,   # [0] checkbox
 
119
                                        gobject.TYPE_STRING,    # [1] path to display
 
120
                                        gobject.TYPE_STRING,    # [2] changes type
 
121
                                        gobject.TYPE_STRING)    # [3] real path
114
122
        self.file_view.set_model(self.file_store)
115
123
        crt = gtk.CellRendererToggle()
116
124
        crt.set_property("activatable", True)
123
131
                                     gtk.CellRendererText(), text=2))
124
132
 
125
133
        for path, id, kind in self.delta.added:
126
 
            self.file_store.append([ True, path, _('added') ])
 
134
            marker = osutils.kind_marker(kind)
 
135
            self.file_store.append([ True, path+marker, _('added'), path ])
127
136
 
128
137
        for path, id, kind in self.delta.removed:
129
 
            self.file_store.append([ True, path, _('removed') ])
 
138
            marker = osutils.kind_marker(kind)
 
139
            self.file_store.append([ True, path+marker, _('removed'), path ])
130
140
 
131
141
        for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
132
 
            self.file_store.append([ True, oldpath, _('renamed') ])
 
142
            marker = osutils.kind_marker(kind)
 
143
            if text_modified or meta_modified:
 
144
                changes = _('renamed and modified')
 
145
            else:
 
146
                changes = _('renamed')
 
147
            self.file_store.append([ True,
 
148
                                     oldpath+marker + '  =>  ' + newpath+marker,
 
149
                                     changes,
 
150
                                     newpath
 
151
                                   ])
133
152
 
134
153
        for path, id, kind, text_modified, meta_modified in self.delta.modified:
135
 
            self.file_store.append([ True, path, _('modified') ])
 
154
            marker = osutils.kind_marker(kind)
 
155
            self.file_store.append([ True, path+marker, _('modified'), path ])
 
156
    
 
157
    def _create_pending_merges(self):
 
158
        liststore = gtk.ListStore(gobject.TYPE_STRING,
 
159
                                  gobject.TYPE_STRING,
 
160
                                  gobject.TYPE_STRING)
 
161
        self.pending_view.set_model(liststore)
 
162
        
 
163
        self.pending_view.append_column(gtk.TreeViewColumn(_('Date'),
 
164
                                        gtk.CellRendererText(), text=0))
 
165
        self.pending_view.append_column(gtk.TreeViewColumn(_('Committer'),
 
166
                                        gtk.CellRendererText(), text=1))
 
167
        self.pending_view.append_column(gtk.TreeViewColumn(_('Summary'),
 
168
                                        gtk.CellRendererText(), text=2))
 
169
        
 
170
        if not self.pending:
 
171
            return
 
172
        
 
173
        for item in self.pending:
 
174
            liststore.append([ item['date'],
 
175
                               item['committer'],
 
176
                               item['summary'] ])
136
177
    
137
178
    def _get_specific_files(self):
138
179
        ret = []
139
180
        it = self.file_store.get_iter_first()
140
181
        while it:
141
182
            if self.file_store.get_value(it, 0):
142
 
                ret.append(self.file_store.get_value(it, 1))
 
183
                # get real path from hidden column 3
 
184
                ret.append(self.file_store.get_value(it, 3))
143
185
            it = self.file_store.iter_next(it)
144
186
 
145
187
        return ret
146
 
    # end of bzr-gtk code
147
188
    
148
189
    def _toggle_commit(self, cell, path, model):
149
190
        model[path][0] = not model[path][0]
150
191
        return
151
192
    
 
193
    def _pending_merges(self, wt):
 
194
        """ Return a list of pending merges or None if there are none of them. """
 
195
        parents = wt.get_parent_ids()
 
196
        if len(parents) < 2:
 
197
            return None
 
198
        
 
199
        import re
 
200
        from bzrlib.osutils import format_date
 
201
        
 
202
        pending = parents[1:]
 
203
        branch = wt.branch
 
204
        last_revision = parents[0]
 
205
        
 
206
        if last_revision is not None:
 
207
            try:
 
208
                ignore = set(branch.repository.get_ancestry(last_revision))
 
209
            except errors.NoSuchRevision:
 
210
                # the last revision is a ghost : assume everything is new 
 
211
                # except for it
 
212
                ignore = set([None, last_revision])
 
213
        else:
 
214
            ignore = set([None])
 
215
        
 
216
        pm = []
 
217
        for merge in pending:
 
218
            ignore.add(merge)
 
219
            try:
 
220
                m_revision = branch.repository.get_revision(merge)
 
221
                
 
222
                rev = {}
 
223
                rev['committer'] = re.sub('<.*@.*>', '', m_revision.committer).strip(' ')
 
224
                rev['summary'] = m_revision.get_summary()
 
225
                rev['date'] = format_date(m_revision.timestamp,
 
226
                                          m_revision.timezone or 0, 
 
227
                                          'original', date_fmt="%Y-%m-%d",
 
228
                                          show_offset=False)
 
229
                
 
230
                pm.append(rev)
 
231
                
 
232
                inner_merges = branch.repository.get_ancestry(merge)
 
233
                assert inner_merges[0] is None
 
234
                inner_merges.pop(0)
 
235
                inner_merges.reverse()
 
236
                for mmerge in inner_merges:
 
237
                    if mmerge in ignore:
 
238
                        continue
 
239
                    mm_revision = branch.repository.get_revision(mmerge)
 
240
                    
 
241
                    rev = {}
 
242
                    rev['committer'] = re.sub('<.*@.*>', '', mm_revision.committer).strip(' ')
 
243
                    rev['summary'] = mm_revision.get_summary()
 
244
                    rev['date'] = format_date(mm_revision.timestamp,
 
245
                                              mm_revision.timezone or 0, 
 
246
                                              'original', date_fmt="%Y-%m-%d",
 
247
                                              show_offset=False)
 
248
                
 
249
                    pm.append(rev)
 
250
                    
 
251
                    ignore.add(mmerge)
 
252
            except errors.NoSuchRevision:
 
253
                print "DEBUG: NoSuchRevision:", merge
 
254
        
 
255
        return pm
 
256
 
152
257
    def commit(self, widget):
153
258
        textbuffer = self.textview.get_buffer()
154
259
        start, end = textbuffer.get_bounds()
155
 
        message = textbuffer.get_text(start, end)
 
260
        message = textbuffer.get_text(start, end).decode('utf-8')
156
261
        
157
262
        checkbutton_strict = self.glade.get_widget('checkbutton_commit_strict')
158
263
        checkbutton_force = self.glade.get_widget('checkbutton_commit_force')
159
264
        
160
 
        specific_files = self._get_specific_files()
161
 
        
162
 
        self.comm.set_busy(self.window)
163
 
        # merged from Jelmer Vernooij's olive integration branch
 
265
        if not self.pending:
 
266
            specific_files = self._get_specific_files()
 
267
        else:
 
268
            specific_files = None
 
269
 
 
270
        if message == '':
 
271
            response = question_dialog('Commit with an empty message ?',
 
272
                                       'You can describe your commit intent'
 
273
                                       +' in the message')
 
274
            if response == gtk.RESPONSE_NO:
 
275
                # Kindly give focus to message area
 
276
                self.textview.grab_focus()
 
277
                return
 
278
 
164
279
        try:
165
 
            self.wt.commit(message, 
 
280
            self.wt.commit(message,
166
281
                           allow_pointless=checkbutton_force.get_active(),
167
282
                           strict=checkbutton_strict.get_active(),
168
283
                           local=self.checkbutton_local.get_active(),
169
284
                           specific_files=specific_files)
170
285
        except errors.NotBranchError:
171
 
            self.dialog.error_dialog(_('Directory is not a branch'),
172
 
                                     _('You can perform this action only in a branch.'))
173
 
            self.comm.set_busy(self.window, False)
 
286
            error_dialog(_('Directory is not a branch'),
 
287
                         _('You can perform this action only in a branch.'))
174
288
            return
175
289
        except errors.LocalRequiresBoundBranch:
176
 
            self.dialog.error_dialog(_('Directory is not a checkout'),
177
 
                                     _('You can perform local commit only on checkouts.'))
178
 
            self.comm.set_busy(self.window, False)
 
290
            error_dialog(_('Directory is not a checkout'),
 
291
                         _('You can perform local commit only on checkouts.'))
179
292
            return
180
293
        except errors.PointlessCommit:
181
 
            self.dialog.error_dialog(_('No changes to commit'),
182
 
                                     _('Try force commit if you want to commit anyway.'))
183
 
            self.comm.set_busy(self.window, False)
 
294
            error_dialog(_('No changes to commit'),
 
295
                         _('Try force commit if you want to commit anyway.'))
184
296
            return
185
297
        except errors.ConflictsInTree:
186
 
            self.dialog.error_dialog(_('Conflicts in tree'),
187
 
                                     _('You need to resolve the conflicts before committing.'))
188
 
            self.comm.set_busy(self.window, False)
 
298
            error_dialog(_('Conflicts in tree'),
 
299
                         _('You need to resolve the conflicts before committing.'))
189
300
            return
190
301
        except errors.StrictCommitFailed:
191
 
            self.dialog.error_dialog(_('Strict commit failed'),
192
 
                                     _('There are unknown files in the working tree.\nPlease add or delete them.'))
193
 
            self.comm.set_busy(self.window, False)
 
302
            error_dialog(_('Strict commit failed'),
 
303
                         _('There are unknown files in the working tree.\nPlease add or delete them.'))
194
304
            return
195
305
        except errors.BoundBranchOutOfDate, errmsg:
196
 
            self.dialog.error_dialog(_('Bound branch is out of date'),
197
 
                                     _('%s') % errmsg)
198
 
            self.comm.set_busy(self.window, False)
199
 
            return
200
 
        except:
201
 
            raise
202
 
        
 
306
            error_dialog(_('Bound branch is out of date'),
 
307
                         _('%s') % errmsg)
 
308
            return
 
309
        except errors.BzrError, msg:
 
310
            error_dialog(_('Unknown bzr error'), str(msg))
 
311
            return
 
312
        except Exception, msg:
 
313
            error_dialog(_('Unknown error'), str(msg))
 
314
            return
 
315
 
203
316
        self.close()
204
 
        self.comm.refresh_right()
205
 
        
 
317
 
206
318
    def close(self, widget=None):
207
319
        self.window.destroy()