/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: Jelmer Vernooij
  • Date: 2006-09-30 10:21:43 UTC
  • Revision ID: jelmer@samba.org-20060930102143-c0ef64d6ca860c21
Merge some files from Olive and bzr-gtk.

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
 
17
19
try:
18
20
    import pygtk
19
21
    pygtk.require("2.0")
20
22
except:
21
23
    pass
22
 
 
23
24
import gtk
24
25
import gtk.glade
25
26
import gobject
26
27
import pango
27
28
 
 
29
from bzrlib import version_info
 
30
 
28
31
import bzrlib.errors as errors
 
32
from bzrlib.workingtree import WorkingTree
29
33
 
30
34
from dialog import error_dialog
31
35
from olive import gladefile
32
36
 
33
 
class CommitDialog:
 
37
class OliveCommit:
34
38
    """ Display Commit dialog and perform the needed actions. """
35
39
    def __init__(self, wt, wtpath):
36
40
        """ Initialize the Commit dialog. """
44
48
        self.checkbutton_local = self.glade.get_widget('checkbutton_commit_local')
45
49
        self.textview = self.glade.get_widget('textview_commit')
46
50
        self.file_view = self.glade.get_widget('treeview_commit_select')
47
 
        self.pending_label = self.glade.get_widget('label_commit_pending')
48
 
        self.pending_view = self.glade.get_widget('treeview_commit_pending')
49
51
 
50
52
        file_id = self.wt.path2id(wtpath)
51
53
 
58
60
        self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
59
61
        self.delta = self.wt.changes_from(self.old_tree)
60
62
        
61
 
        # Get pending merges
62
 
        self.pending = self._pending_merges(self.wt)
63
 
        
64
63
        # Dictionary for signal_autoconnect
65
64
        dic = { "on_button_commit_commit_clicked": self.commit,
66
65
                "on_button_commit_cancel_clicked": self.close }
70
69
        
71
70
        # Create the file list
72
71
        self._create_file_view()
73
 
        # Create the pending merges
74
 
        self._create_pending_merges()
75
72
    
76
73
    def display(self):
77
74
        """ Display the Push dialog. """
78
75
        if self.notbranch:
79
76
            error_dialog(_('Directory is not a branch'),
80
 
                         _('You can perform this action only in a branch.'))
 
77
                                     _('You can perform this action only in a branch.'))
81
78
            self.close()
82
79
        else:
83
80
            if self.wt.branch.get_bound_location() is not None:
84
81
                # we have a checkout, so the local commit checkbox must appear
85
82
                self.checkbutton_local.show()
86
83
            
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
 
            
94
84
            self.textview.modify_font(pango.FontDescription("Monospace"))
95
85
            self.window.show()
96
86
            
122
112
        for path, id, kind, text_modified, meta_modified in self.delta.modified:
123
113
            self.file_store.append([ True, path, _('modified') ])
124
114
    
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
 
    
146
115
    def _get_specific_files(self):
147
116
        ret = []
148
117
        it = self.file_store.get_iter_first()
157
126
        model[path][0] = not model[path][0]
158
127
        return
159
128
    
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
 
 
224
129
    def commit(self, widget):
225
130
        textbuffer = self.textview.get_buffer()
226
131
        start, end = textbuffer.get_bounds()
229
134
        checkbutton_strict = self.glade.get_widget('checkbutton_commit_strict')
230
135
        checkbutton_force = self.glade.get_widget('checkbutton_commit_force')
231
136
        
232
 
        if not self.pending:
233
 
            specific_files = self._get_specific_files()
234
 
        else:
235
 
            specific_files = None
 
137
        specific_files = self._get_specific_files()
236
138
        
237
139
        try:
238
140
            self.wt.commit(message, 
242
144
                           specific_files=specific_files)
243
145
        except errors.NotBranchError:
244
146
            error_dialog(_('Directory is not a branch'),
245
 
                         _('You can perform this action only in a branch.'))
 
147
                                     _('You can perform this action only in a branch.'))
246
148
            return
247
149
        except errors.LocalRequiresBoundBranch:
248
150
            error_dialog(_('Directory is not a checkout'),
249
 
                         _('You can perform local commit only on checkouts.'))
 
151
                                     _('You can perform local commit only on checkouts.'))
250
152
            return
251
153
        except errors.PointlessCommit:
252
154
            error_dialog(_('No changes to commit'),
253
 
                         _('Try force commit if you want to commit anyway.'))
 
155
                                     _('Try force commit if you want to commit anyway.'))
254
156
            return
255
157
        except errors.ConflictsInTree:
256
158
            error_dialog(_('Conflicts in tree'),
257
 
                         _('You need to resolve the conflicts before committing.'))
 
159
                                     _('You need to resolve the conflicts before committing.'))
258
160
            return
259
161
        except errors.StrictCommitFailed:
260
162
            error_dialog(_('Strict commit failed'),
261
 
                         _('There are unknown files in the working tree.\nPlease add or delete them.'))
 
163
                                     _('There are unknown files in the working tree.\nPlease add or delete them.'))
262
164
            return
263
165
        except errors.BoundBranchOutOfDate, errmsg:
264
166
            error_dialog(_('Bound branch is out of date'),
265
 
                         _('%s') % errmsg)
 
167
                                     _('%s') % errmsg)
266
168
            return
267
169
        except errors.BzrError, msg:
268
170
            error_dialog(_('Unknown bzr error'), str(msg))