/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: Aaron Bentley
  • Date: 2007-01-17 06:42:55 UTC
  • mto: This revision was merged to the branch mainline in revision 129.
  • Revision ID: aaron.bentley@utoronto.ca-20070117064255-x4gznz5e0lyjq3gk
Remove usused span selector

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