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

nautilus: notify from hggtk dialogs

hgtk writes the names of the changed files to ~/.tortoisehg/notify
nautilus-thg monitors this file, reads the data and truncates the file
the icons of the files and of their parent directories are invalidated

Changeset 84d9de782a48

Parent 84d4048505a0

by Simon Heimberg

Changes to 2 files · Browse files at 84d9de782a48 Showing diff from parent 84d4048505a0 Diff from another changeset...

 
12
13
14
 
15
16
17
 
64
65
66
 
 
67
68
69
70
 
 
 
 
 
 
 
 
 
 
71
72
73
74
75
76
 
 
77
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
80
81
 
239
240
241
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
243
244
 
12
13
14
15
16
17
18
 
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
 
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
@@ -12,6 +12,7 @@
 import gtk  import gobject  import nautilus +import gnomevfs    try:   from mercurial import demandimport @@ -64,18 +65,43 @@
  self.cacherepo = None   self.cacheroot = None   self.scanStack = [] + self.allvfs = {} + self.inv_dirs = set()     from thgutil import menuthg   self.hgtk = paths.find_in_path('hgtk')   self.menu = menuthg.menuThg() + self.notify = os.path.expanduser('~/.tortoisehg/notify') + try: + f = open(self.notify, 'w') + f.close() + ds_uri = gnomevfs.get_uri_from_local_path(self.notify) + self.gmon = gnomevfs.monitor_add(ds_uri, + gnomevfs.MONITOR_FILE, self.notified) + except (gnomevfs.NotSupportedError, IOError), e: + debugf('no notification because of %s', e) + self.notify = ''     def icon(self, iname):   return paths.get_tortoise_icon(iname)   - def get_path_for_vfs_file(self, vfs_file): - if vfs_file.is_gone() or vfs_file.get_uri_scheme() != 'file': + def get_path_for_vfs_file(self, vfs_file, store=True): + if vfs_file.get_uri_scheme() != 'file':   return None - return urllib.unquote(vfs_file.get_uri()[7:]) + path = urllib.unquote(vfs_file.get_uri()[7:]) + if vfs_file.is_gone(): + self.allvfs.pop(path, '') + return None + if store: + self.allvfs[path] = vfs_file + return path + + def get_vfs(self, path): + vfs = self.allvfs.get(path, None) + if vfs and vfs.is_gone(): + del self.allvfs[path] + return None + return vfs     def get_repo_for_path(self, path):   ''' @@ -239,6 +265,50 @@
  vfs_file.add_string_attribute('hg_status', status)   return True   + def notified(self, mon_uri=None, event_uri=None, event=None): + debugf('notified from hgtk, %s', event, level='n') + f = open(self.notify, 'a+') + files = None + try: + files = [line[:-1] for line in f if line] + if files: + f.truncate(0) + finally: + f.close() + if not files: + return + root = os.path.commonprefix(files) + root = paths.find_root(root) + self.invalidate(files, root) + + def invalidate(self, paths, root = ''): + from tortoise import cachethg + started = bool(self.inv_dirs) + if cachethg.cache_pdir == root and root not in self.inv_dirs: + cachethg.overlay_cache.clear() + self.inv_dirs.update([os.path.dirname(root), '/', '']) + for path in paths: + path = os.path.join(root, path) + while path not in self.inv_dirs: + self.inv_dirs.add(path) + path = os.path.dirname(path) + if cachethg.cache_pdir == path: + cachethg.overlay_cache.clear() + if started: + return + if len(paths) > 1: + self._invalidate_dirs() + else: + #group invalidation of directories + gobject.timeout_add(200, self._invalidate_dirs) + + def _invalidate_dirs(self): + for path in self.inv_dirs: + vfs = self.get_vfs(path) + if vfs: + vfs.invalidate_extension_info() + self.inv_dirs.clear() +   # property page borrowed from http://www.gnome.org/~gpoo/hg/nautilus-hg/   def __add_row(self, row, label_item, label_value):   label = gtk.Label(label_item)
Change 1 of 1 Show Entire File thgutil/​shlib.py Stacked
 
178
179
180
181
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
179
180
 
181
182
183
184
185
186
187
188
189
190
191
192
193
194
@@ -178,4 +178,17 @@
  pidl, None)  else:   def shell_notify(paths): - pass + if not paths: + return + notify = os.environ.get('THG_NOTIFY', '.tortoisehg/notify') + if not os.path.isabs(notify): + notify = os.path.join(os.path.expanduser('~'), notify) + os.environ['THG_NOTIFY'] = notify + if not os.path.isfile(notify): + return + f_notify = open(notify, 'w') + try: + f_notify.write('\n'.join([os.path.abspath(path) for path in paths])) + finally: + f_notify.close() +