/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: Alexander Belchenko
  • Date: 2006-10-26 13:16:07 UTC
  • mto: (91.1.8 trunk) (66.2.10 trunk)
  • mto: This revision was merged to the branch mainline in revision 107.
  • Revision ID: bialix@ukr.net-20061026131607-fa48887c5a4869a5
olive-gtk: use olive ui factory

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