Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.8, 0.8.1, and 0.8.2

menuthg: catch more errors

example: IOError when .hg/store is not readable

Changeset a1592c02c80b

Parent 5c6d9cbe3bc8

by Simon Heimberg

Changes to one file · Browse files at a1592c02c80b Showing diff from parent 5c6d9cbe3bc8 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
327
328
329
330
331
332
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
327
328
329
330
331
332
333
334
335
 # Published under the GNU GPL, v2 or later.  # Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>  # Copyright (C) 2007 Henry Ludemann <misc@hl.id.au>  # Copyright (C) 2007 TK Soh <teekaysoh@gmail.com>    import os  from mercurial import hg  from thgutil import *  import cachethg  from mercurial import ui  from mercurial.i18n import _    try:   from mercurial.error import RepoError  except ImportError:   from mercurial.repo import RepoError      class TortoiseMenu(object):     def __init__(self, menutext, helptext, hgcmd, icon=None, state=True):   self.menutext = menutext   self.helptext = helptext   self.hgcmd = hgcmd   self.state = state   self.icon = icon     def isSubmenu(self):   return False     def isSep(self):   return False      class TortoiseSubmenu(TortoiseMenu):     def __init__(self, menutext, helptext, menus=[], icon=None):   TortoiseMenu.__init__(self, menutext, helptext, None, icon)   self.menus = menus[:]     def add_menu(self, menutext, helptext, hgcmd, icon=None, state=True):   self.menus.append(TortoiseMenu(menutext, helptext,   hgcmd, icon, state))     def add_sep(self):   self.menus.append(TortoiseMenuSep())     def get_menus(self):   return self.menus     def append(self, entry):   self.menus.append(entry)     def isSubmenu(self):   return True      class TortoiseMenuSep(object):     def isSubmenu(self):   return False     def isSep(self):   return True      class thg_menu(object):     def __init__(self, ui, name = "TortoiseHG"):   self.menus = [[]]   self.ui = ui   self.name = name   self.sep = [False]     def add_menu(self, menutext, helptext, hgcmd, icon=None, state=True):   pos = self.ui.config('tortoisehg_menu', hgcmd)   if pos:   if pos.isdigit():   pos = int(pos)   else:   pos = pos[0].lower() not in 'nfm' # no, false, main menu   elif hgcmd == 'commit':   pos = 0   else:   pos = 1   if pos < 0:   return   while len(self.menus) <= pos: #add Submenu   self.menus.append([])   self.sep.append(False)   if self.sep[pos]:   self.sep[pos] = False   self.menus[pos].append(TortoiseMenuSep())   self.menus[pos].append(TortoiseMenu(   menutext, helptext, hgcmd, icon, state))     def add_sep(self):   for s in self.sep:   s = True     def get(self):   menu = self.menus[0]   for submenu in menus[1:]:   menu.add(TortoiseSubmenu(self.name, 'Mercurial', submenu, "hg.ico"))   menu.add(TortoseMenuSep())   return menu     def __iter__(self):   return iter(self.get())      def open_repo(path):   root = find_root(path)   if root:   try:   repo = hg.repository(ui.ui(), path=root)   return repo   except RepoError:   pass + except StandardError, e: + print "error while opening repo %s:" % path + print e     return None      class menuThg:   """shell extension that adds context menu items"""     def __init__(self):   self.name = "TortoiseHG"     def get_commands_dragdrop(self, srcfiles, destfolder):   """   Get a list of commands valid for the current selection.     Commands are instances of TortoiseMenu, TortoiseMenuSep or TortoiseMenu   """     # we can only accept dropping one item   if len(srcfiles) > 1:   return []     # open repo   drag_repo = None   drop_repo = None     drag_path = self.srcfiles[0]   drag_repo = open_repo(drag_path)   if not drag_repo:   return []   if drag_repo and drag_repo.root != drag_path:   return [] # dragged item must be a hg repo root directory     drop_repo = open_repo(self._folder)     menu = thg_menu(drag_repo.ui, self.name)   menu.add_menu(_("Create Clone"),   _("Create clone here from source"),   'clone', icon="menuclone.ico")     if drop_repo:   menu.add_menu(_("Synchronize"),   _("Synchronize with dragged repository"),   'synch', icon="menusynch.py")   return menu     def get_norepo_commands(self, cwd, files):   menu = thg_menu(ui.ui(), self.name)   menu.add_menu(_("Clone a Repository"),   _("clone a repository"),   'clone', icon="menuclone.ico")   menu.add_menu(_("Create Repository Here"),   _("create a new repository in this directory"),   'init', icon="menucreaterepos.ico")   menu.add_menu(_("Global Settings"),   _("Configure user wide settings"),   'userconfig', icon="settings_user.ico")   menu.add_sep()   menu.add_menu(_("About"), _("About TortoiseHg"),   'about', icon="menuabout.ico")   menu.add_sep()   return menu     def get_commands(self, repo, cwd, files):   """   Get a list of commands valid for the current selection.     Commands are instances of TortoiseMenu, TortoiseMenuSep or TortoiseMenu   """   states = set()   onlyfiles = len(files) > 0   hashgignore = False   for f in files:   if not os.path.isfile(f):   onlyfiles = False   if f.endswith('.hgignore'):   hashgignore = True   states.add(cachethg.get_state(f, repo))   if not files:   if repo.root == os.path.realpath(cwd):   inroot = True   #cache does not return state for root   if not cachethg.overlay_cache:   cachethg.get_state(os.path.join(cwd,'.hg'))   states = set(cachethg.overlay_cache.values())   else:   states.add(cachethg.get_state(cwd))     changed = bool(states & set([cachethg.ADDED, cachethg.MODIFIED]))   modified = cachethg.MODIFIED in states   tracked = changed or cachethg.MODIFIED in states   new = bool(states & set([cachethg.UNKNOWN, cachethg.IGNORED]))     menu = thg_menu(repo.ui, self.name)   if changed or cachethg.UNKNOWN in states:   menu.add_menu(_("HG Commit..."),   _("Commit changes in repository"),   'commit', icon="menucommit.ico")     if hashgignore or new and len(states) == 1:   menu.add_menu(_("Edit Ignore Filter"),   _("Edit repository ignore filter"),   'hgignore', icon="ignore.ico")     if changed or cachethg.UNKNOWN in states:   menu.add_menu(_("View File Status"),   _("Repository status"),   'status', icon="menushowchanged.ico")     if modified:   menu.add_menu(_("Shelve Changes"),   _("Shelve or unshelve repository changes"),   'shelve', icon="shelve.ico")     # Visual Diff (any extdiff command)   has_vdiff = repo.ui.config('tortoisehg', 'vdiff', '') != ''   if has_vdiff and modified:   menu.add_menu(_("Visual Diff"),   _("View changes using GUI diff tool"),   'vdiff', icon="TortoiseMerge.ico")     if len(files) == 0 and cachethg.UNKNOWN in states:   menu.add_menu(_("Guess Renames"),   _("Detect renames and copies"),   'guess', icon="detect_rename.ico")   elif len(files) == 1 and tracked: # needs ico   menu.add_menu(_("Rename File"),   _("Rename file or directory"),   'rename', icon="general.ico")     if files and new:   menu.add_menu(_("Add Files"),   _("Add files to Hg repository"),   'add', icon="menuadd.ico")   if files and tracked:   menu.add_menu(_("Remove Files"),   _("Remove selected files on the next commit"),   'remove', icon="menudelete.ico")   if files and changed:   menu.add_menu(_("Undo Changes"),   _("Revert selected files"),   'revert', icon="menurevert.ico")     # we can only annotate file but not directories   if onlyfiles and tracked:   menu.add_menu(_("Annotate Files"),   _("show changeset information per file line"),   'datamine', icon="menublame.ico")     menu.add_sep()   menu.add_menu(_("Update To Revision"),   _("update working directory"),   'update', icon="menucheckout.ico")     if len(repo.changectx(None).parents()) < 2:   menu.add_menu(_("Merge Revisions"),   _("merge working directory with another revision"),   'merge', icon="menumerge.ico")     inmerge = len(repo.changectx(None).parents()) > 1   if inmerge:   menu.add_menu(_("Undo Merge"),   _("Undo merge by updating to revision"),   'merge', icon="menuunmerge.ico")     menu.add_sep()     if tracked:   menu.add_menu(_("View Changelog"),   _("View revision history"),   'history', icon="menulog.ico")     if len(files) == 0:   menu.add_menu(_("Search Repository"),   _("Search revisions of files for a text pattern"),   'datamine', icon="menurepobrowse.ico")     menu.add_sep()     menu.add_menu(_("Synchronize..."),   _("Synchronize with remote repository"),   'synch', icon="menusynch.ico")   menu.add_menu(_("Recovery..."),   _("General repair and recovery of repository"),   'recovery', icon="general.ico")   menu.add_menu(_("Web Server"),   _("start web server for this repository"),   'serve', icon="proxy.ico")     menu.add_sep()   menu.add_menu(_("Create Clone"),   _("Clone a repository here"),   'clone', icon="menuclone.ico")   if repo.root != cwd:   menu.add_menu(_("Create Repository Here"),   _("create a new repository in this directory"),   'init', icon="menucreaterepos.ico")     # config settings menu   menu.add_sep()   menu.add_menu(_("Global"),   _("Configure user wide settings"),   'userconfig', icon="settings_user.ico")   menu.add_menu(_("Repository"),   _("Configure settings local to this repository"),   'repoconfig', icon="settings_repo.ico")     # add common menu items   menu.add_sep()   menu.add_menu(_("About"), _("About TortoiseHg"),   'about', icon="menuabout.ico")     menu.add_sep()   return menu