Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.9, 0.9.1, and 0.9.1.1

update: cleanup UI codes #2

Changeset f8277a149004

Parent bba95a137eb2

by Yuki KODAMA

Changes to one file · Browse files at f8277a149004 Showing diff from parent bba95a137eb2 Diff from another changeset...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
 
93
94
95
96
97
 
 
98
99
100
101
 
102
103
104
105
106
107
108
109
 
 
 
110
111
112
 
 
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
 
206
207
208
 
209
210
211
212
213
 
214
215
216
 
217
218
219
 
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
 
 
 
90
91
92
 
 
 
93
94
95
96
 
 
97
98
99
100
101
 
 
 
 
102
103
104
105
 
 
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
 
200
201
202
 
203
204
205
206
207
 
208
209
210
 
211
212
213
 
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
 # update.py - TortoiseHg's dialog for updating repo  #  # Copyright 2007 TK Soh <teekaysoh@gmail.com>  # Copyright 2007 Steve Borho <steve@borho.org>  #  # This software may be used and distributed according to the terms of the  # GNU General Public License version 2, incorporated herein by reference.    import os  import gtk  import gobject    from mercurial import hg, ui    from tortoisehg.util.i18n import _  from tortoisehg.util import hglib, paths  from tortoisehg.util.hglib import LookupError, RepoLookupError, RepoError    from tortoisehg.hgtk import hgcmd, gtklib, gdialog    MODE_NORMAL = 'normal'  MODE_WORKING = 'working'    class UpdateDialog(gtk.Dialog):   """ Dialog to update Mercurial repo """   def __init__(self, rev=None):   """ Initialize the Dialog """   gtk.Dialog.__init__(self)   gtklib.set_tortoise_icon(self, 'menucheckout.ico')   gtklib.set_tortoise_keys(self)   self.set_resizable(False)   self.set_size_request(450, -1)   self.set_has_separator(False)   self.connect('response', self.dialog_response)     try:   repo = hg.repository(ui.ui(), path=paths.find_root())   except hglib.RepoError:   gtklib.idle_add_single_call(self.destroy)   return   self.repo = repo   self.set_title(_('Update - %s') % hglib.get_reponame(repo))     # add dialog buttons   self.updatebtn = self.add_button(_('Update'), gtk.RESPONSE_OK)   self.closebtn = self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CLOSE)     # layout table for fixed items   table = gtklib.LayoutTable()   self.vbox.pack_start(table, True, True, 2)   self.table = table     ## revision label & combobox   self.revcombo = combo = gtk.combo_box_entry_new_text()   entry = combo.child   entry.set_width_chars(38)   entry.connect('activate', lambda b: self.response(gtk.RESPONSE_OK))   table.add_row(_('Update to:'), combo, padding=False)     ## update method   btn = gtk.CheckButton(_('Discard local changes, no backup (-C/--clean)'))   self.opt_clean = btn   table.add_row(None, btn)     ## fill list of combo   if rev != None:   combo.append_text(str(rev))   else:   combo.append_text(repo.dirstate.branch())   combo.set_active(0)     dblist = repo.ui.config('tortoisehg', 'deadbranch', '')   deadbranches = [ x.strip() for x in dblist.split(',') ]   for name in repo.branchtags().keys():   if name not in deadbranches:   combo.append_text(name)     tags = list(repo.tags())   tags.sort()   tags.reverse()   for t in tags:   combo.append_text(t)     ## changeset summaries   def new_label():   label = gtk.Label('-')   label.set_selectable(True)   label.set_line_wrap(True)   label.set_size_request(350, -1) - hb = gtk.HBox() - hb.pack_start(label, False, False) - return hb, label + return label     ## summary of target revision - hb, label = new_label() - table.add_row(_('Target:'), hb) - self.new_rev_label = label + self.target_label = new_label() + table.add_row(_('Target:'), self.target_label)     ## summary of parent 1 revision - hb, label = new_label() - self.current_rev_label1 = label + self.parent1_label = new_label()     ## summary of parent 2 revision if needs   self.ctxs = self.repo[None].parents()   if len(self.ctxs) == 2: - table.add_row(_('Parent 1:'), hb) - hb, label = new_label() - table.add_row(_('Parent 2:'), hb) - self.current_rev_label2 = label + table.add_row(_('Parent 1:'), self.parent1_label) + self.parent2_label = new_label() + table.add_row(_('Parent 2:'), self.parent2_label)   else: - table.add_row(_('Parent:'), hb) - self.current_rev_label2 = None + table.add_row(_('Parent:'), self.parent1_label) + self.parent2_label = None     # signal handlers   self.revcombo.connect('changed', lambda b: self.update_summaries())   self.opt_clean.connect('toggled', lambda b: self.update_summaries())     # prepare to show   self.update_summaries()   self.updatebtn.grab_focus()   gtklib.idle_add_single_call(self.after_init)     def after_init(self):   # CmdWidget   self.cmd = hgcmd.CmdWidget()   self.cmd.show_all()   self.cmd.hide()   self.vbox.pack_start(self.cmd, True, True, 6)     # abort button   self.abortbtn = self.add_button(_('Abort'), gtk.RESPONSE_CANCEL)   self.abortbtn.hide()     def abort(self):   self.cmd.stop()   self.cmd.show_log()   self.switch_to(MODE_NORMAL, cmd=False)     def dialog_response(self, dialog, response_id):   # Update button   if response_id == gtk.RESPONSE_OK:   self.update()   # Close button or dialog closing by the user   elif response_id in (gtk.RESPONSE_CLOSE, gtk.RESPONSE_DELETE_EVENT):   if self.cmd.is_alive():   ret = gdialog.Confirm(_('Confirm Abort'), [], self,   _('Do you want to abort?')).run()   if ret == gtk.RESPONSE_YES:   self.abort()   else:   self.destroy()   return # close dialog   # Abort button   elif response_id == gtk.RESPONSE_CANCEL:   self.abort()   else:   raise _('unexpected response id: %s') % response_id     self.run() # don't close dialog     def switch_to(self, mode, cmd=True):   if mode == MODE_NORMAL:   normal = True   self.closebtn.grab_focus()   elif mode == MODE_WORKING:   normal = False   self.abortbtn.grab_focus()   else:   raise _('unknown mode name: %s') % mode   working = not normal     self.table.set_sensitive(normal)   self.updatebtn.set_property('visible', normal)   self.closebtn.set_property('visible', normal)   if cmd:   self.cmd.set_property('visible', working)   self.abortbtn.set_property('visible', working)     def update_summaries(self):   def setlabel(label, ctx):   revision = str(ctx.rev())   hash = str(ctx)   summary = gtklib.markup_escape_text(hglib.toutf(   ctx.description().split('\n')[0]))   face = 'monospace'   size = '9000'     format = '<span face="%s" size="%s">%s (%s)\n</span>'   t = format % (face, size, revision, hash)     branch = ctx.branch()   if branch != 'default':   format = '<span color="%s" background="%s"> %s </span> '   t += format % ('black', '#aaffaa', branch)     tags = self.repo.nodetags(ctx.node())   format = '<span color="%s" background="%s"> %s </span> '   for tag in tags:   t += format % ('black', '#ffffaa', tag)     t += summary   label.set_markup(t)     ctxs = self.ctxs - setlabel(self.current_rev_label1, ctxs[0]) + setlabel(self.parent1_label, ctxs[0])   merge = len(ctxs) == 2   if merge: - setlabel(self.current_rev_label2, ctxs[1]) + setlabel(self.parent2_label, ctxs[1])   newrev = self.revcombo.get_active_text()   try:   new_ctx = self.repo[newrev]   if not merge and new_ctx.rev() == ctxs[0].rev(): - self.new_rev_label.set_label(_('(same as parent)')) + self.target_label.set_label(_('(same as parent)'))   self.updatebtn.set_sensitive(self.opt_clean.get_active())   else: - setlabel(self.new_rev_label, self.repo[newrev]) + setlabel(self.target_label, self.repo[newrev])   self.updatebtn.set_sensitive(True)   except (LookupError, RepoLookupError, RepoError): - self.new_rev_label.set_label(_('unknown revision!')) + self.target_label.set_label(_('unknown revision!'))   self.updatebtn.set_sensitive(False)     def update(self):   cmdline = ['hg', 'update', '--verbose']   rev = self.revcombo.get_active_text()   cmdline.append('--rev')   cmdline.append(rev)     if self.opt_clean.get_active():   cmdline.append('--clean')   else:   cur = self.repo['.']   node = self.repo[rev]   def isclean():   '''whether WD is changed'''   wc = self.repo[None]   return not (wc.modified() or wc.added() or wc.removed())   def ismergedchange():   '''whether the local changes are merged (have 2 parents)'''   wc = self.repo[None]   return len(wc.parents()) == 2   def iscrossbranch(p1, p2):   '''whether p1 -> p2 crosses branch'''   pa = p1.ancestor(p2)   return p1.branch() != p2.branch() or (p1 != pa and p2 != pa)   def islocalmerge(p1, p2, clean=None):   if clean is None:   clean = isclean()   pa = p1.ancestor(p2)   return not clean and p1.branch() == p2.branch() and \   (p1 == pa or p2 == pa)   def confirmupdate(clean=None):   if clean is None:   clean = isclean()     msg = _('Detected uncommitted local changes in working tree.\n'   'Please select to continue:\n\n')   data = {'discard': (_('&Discard'),   _('Discard - discard local changes, no backup')),   'shelve': (_('&Shelve'),   _('Shelve - launch Shelve tool and continue')),   'merge': (_('&Merge'),   _('Merge - allow to merge with local changes')),   'cancel': (_('&Cancel'), None)}     opts = [data['discard']]   if not ismergedchange():   opts.append(data['shelve'])   if islocalmerge(cur, node, clean):   opts.append(data['merge'])   opts.append(data['cancel'])     msg += '\n'.join([ desc for label, desc in opts if desc ])   buttons = [ label for label, desc in opts ]   cancel = len(opts) - 1   retcode = gdialog.CustomPrompt(_('Confirm Update'), msg, self,   buttons, default=cancel, esc=cancel).run()   retlabel = buttons[retcode]   retid = [ id for id, (label, desc) in data.items() \   if label == retlabel ][0]   return dict([(id, id == retid) for id in data.keys()])   clean = isclean()   if clean:   cmdline.append('--check')   else:   ret = confirmupdate(clean)   if ret['discard']:   cmdline.append('--clean')   elif ret['shelve']:   from tortoisehg.hgtk import thgshelve   dlg = thgshelve.run(ui.ui())   dlg.set_transient_for(self)   dlg.set_modal(True)   dlg.display()   dlg.connect('destroy', lambda w: self.update())   return # retry later, no need to destroy   elif ret['merge']:   pass # no args   elif ret['cancel']:   self.cmd.log.append(_('[user canceled]\n'), error=True)   self.switch_to(MODE_WORKING)   self.abort()   return   else:   raise _('invalid dialog result: %s') % ret     def cmd_done(returncode, useraborted):   self.switch_to(MODE_NORMAL, cmd=False)   if hasattr(self, 'notify_func'):   self.notify_func(self.notify_args)   if returncode == 0:   if not self.cmd.is_show_log():   self.response(gtk.RESPONSE_CLOSE)   self.cmd.set_result(_('Updated successfully'), style='ok')   elif useraborted:   self.cmd.set_result(_('Canceled updating'), style='error')   else:   self.cmd.set_result(_('Failed to update'), style='error')   self.switch_to(MODE_WORKING)   self.cmd.execute(cmdline, cmd_done)     def set_notify_func(self, func, *args):   self.notify_func = func   self.notify_args = args    def run(ui, *pats, **opts):   return UpdateDialog(opts.get('rev'))