/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-10-20 11:18:37 UTC
  • Revision ID: Szilveszter.Farkas@gmail.com-20061020111837-e2a99e1d4db9f0f7
Removed completed TODO items.

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