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

thgutil/shlib: add function update_thgstatus

Changeset 28af0c485cf4

Parent 9de5a3d6d776

by Adrian Buehlmann

Changes to one file · Browse files at 28af0c485cf4 Showing diff from parent 9de5a3d6d776 Diff from another changeset...

Change 1 of 3 Show Entire File thgutil/​shlib.py Stacked
 
13
14
15
 
16
17
18
 
176
177
178
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
180
181
 
192
193
194
 
 
 
 
13
14
15
16
17
18
19
 
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
 
241
242
243
244
245
246
@@ -13,6 +13,7 @@
 import time  from mercurial.i18n import _  from mercurial import util +from mercurial import hg    class SimpleMRUList(object):   def __init__(self, size=10, reflist=[], compact=True): @@ -176,6 +177,54 @@
  shell.SHChangeNotify(shellcon.SHCNE_UPDATEITEM,   shellcon.SHCNF_IDLIST | shellcon.SHCNF_FLUSH,   pidl, None) + + def update_thgstatus(ui, root, wait=False): + '''Rewrite the file .hg/thgstatus + + Caches the information provided by repo.status() in the file + .hg/thgstatus, which can then be read by the overlay shell extension + to display overlay icons for directories. + + The file .hg/thgstatus contains one line for each directory that has + removed, modified or added files (in that order of preference). Each + line consists of one char for the status of the directory (r, m or a), + followed by the relative path of the directory in the repo. If the + file .hg/thgstatus is empty, then the repo's working directory is + clean. + + Specify wait=True to wait until the system clock ticks to the next + second before accessing Mercurial's dirstate. This is useful when + Mercurial's .hg/dirstate contains unset entries (in output of + "hg debugstate"). unset entries happen if .hg/dirstate was updated + within the same second as Mercurial updated the respective file in + the working tree. This happens with a high probability for example + when cloning a repo. The overlay shell extension will display unset + dirstate entries as (potentially false) modified. Specifying wait=True + ensures that there are no unset entries left in .hg/dirstate when this + function exits. + ''' + if wait: + tref = time.time() + tdelta = float(int(tref)) + 1.0 - tref + if (tdelta > 0.0): + time.sleep(tdelta) + repo = hg.repository(ui, root) # a fresh repo object is needed + repostate = repo.status() # will update .hg/dirstate as a side effect + modified, added, removed, deleted, unknown, ignored, clean = repostate + dirstatus = {} + def dirname(f): + return '/'.join(f.split('/')[:-1]) + for fn in added: + dirstatus[dirname(fn)] = 'a' + for fn in modified: + dirstatus[dirname(fn)] = 'm' + for fn in removed: + dirstatus[dirname(fn)] = 'r' + f = open(repo.root + "\\.hg\\thgstatus", 'wb') + for dn in sorted(dirstatus): + f.write(dirstatus[dn] + dn + '\n') + f.close() +  else:   def shell_notify(paths):   if not paths: @@ -192,3 +241,6 @@
  finally:   f_notify.close()   + def update_thgstatus(): + pass +