/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: 2006-11-21 15:30:44 UTC
  • mto: (66.6.5 gtk)
  • mto: This revision was merged to the branch mainline in revision 112.
  • Revision ID: abentley@panoramicfeedback.com-20061121153044-58onrnqijuwxr8jd
force long revnos to 'merge'

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