/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-25 09:21:13 UTC
  • mto: (91.1.8 trunk) (66.2.10 trunk)
  • mto: This revision was merged to the branch mainline in revision 106.
  • Revision ID: bialix@ukr.net-20061025092113-4837c5f6fffb2a35
Fix absolute import in gdiff command.

Only gdiff use absolute import from bzrlib.plugins.gtk... 
And this cause error when bzr-gtk not installed as plugin with 'gtk' name 

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