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

merge with Adrian

Changeset ceb5521c0ab2

Parents 25ae007cf4b8

Parents d4bb3d7c4d60

by Steve Borho

Changes to 5 files · Browse files at ceb5521c0ab2 Showing diff from parent 25ae007cf4b8 d4bb3d7c4d60 Diff from another changeset...

Change 1 of 1 Show Entire File thgtaskbar.py Stacked
 
317
318
319
 
320
321
322
 
 
 
 
 
 
 
323
324
325
 
317
318
319
320
321
 
 
322
323
324
325
326
327
328
329
330
331
@@ -317,9 +317,15 @@
  roots, notifypaths = getrepos([path])   if roots:   for r in sorted(roots): + tfn = os.path.join(r, '.hg', 'thgstatus')   try: - os.remove(os.path.join(r, '.hg', 'thgstatus')) - except OSError: + f = open(tfn, 'rb') + e = f.readline() + f.close() + if not e.startswith('@@noicons'): + os.remove(tfn) + except (IOError, OSError): + print "IOError or OSError while trying to remove %s" % tfn   pass   if notifypaths:   shlib.shell_notify(list(notifypaths))
Change 1 of 1 Show Changes Only thgutil/​shlib.py Stacked
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
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
 """  shlib.py - TortoiseHg shell utilities   Copyright (C) 2007 TK Soh <teekaysoh@gmail.com>    This software may be used and distributed according to the terms  of the GNU General Public License, incorporated herein by reference.  """    import os  import sys  import time  from mercurial.i18n import _  from mercurial import hg    def get_system_times():   t = os.times()   if t[4] == 0.0: # Windows leaves this as zero, so use time.clock()   t = (t[0], t[1], t[2], t[3], time.clock())   return t    def version():   try:   import __version__   return __version__.version   except ImportError:   return _('unknown')    if os.name == 'nt':   def shell_notify(paths):   try:   from win32com.shell import shell, shellcon   import pywintypes   except ImportError:   return   dirs = set()   for path in paths:   abspath = os.path.abspath(path)   if not os.path.isdir(abspath):   abspath = os.path.dirname(abspath)   dirs.add(abspath)   # send notifications to deepest directories first   for dir in sorted(dirs, key=len, reverse=True):   try:   pidl, ignore = shell.SHILCreateFromPath(dir, 0)   except pywintypes.com_error:   return   if pidl is None:   continue   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 = repostate[:4]     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 + deleted:   dirstatus[dirname(fn)] = 'r'     update = False   f = None   try:   try:   f = repo.opener('thgstatus', 'rb')   for dn in sorted(dirstatus):   s = dirstatus[dn]   e = f.readline() + if e.startswith('@@noicons'): + break   if e == '' or e[0] != s or e[1:-1] != dn:   update = True   break   if f.readline() != '':   # extra line in f, needs update   update = True   except IOError:   update = True   finally:   if f != None:   f.close()     if update:   f = repo.opener('thgstatus', 'wb', atomictemp=True)   for dn in sorted(dirstatus):   s = dirstatus[dn]   f.write(s + dn + '\n')   ui.note("%s %s\n" % (s, dn))   f.rename()    else:   def shell_notify(paths):   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()     def update_thgstatus(*args, **kws):   pass
 
59
60
61
 
62
63
64
 
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
 
59
60
61
62
63
64
65
 
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
@@ -59,6 +59,7 @@
 int DirectoryStatus::read(const std::string& hgroot, const std::string& cwd)  {   v_.clear(); + noicons_ = false;     std::string p = hgroot + "\\.hg\\thgstatus";   @@ -71,37 +72,65 @@
  return 0;   }   - char state; - std::vector<char> path(MAX_PATH); -   DirectoryStatus::E e;   - while (fread(&state, sizeof(state), 1, f) == 1) + int res = 1; + const std::string noicons = "@@noicons"; + + std::vector<char> vline(200); + + for (;;)   { - e.status_ = state; + vline.clear(); + char t;   - path.clear(); - char t; - while (fread(&t, sizeof(t), 1, f) == 1 && t != '\n') + for (;;)   { - path.push_back(t); - if (path.size() > 1000) - return 0; + if (fread(&t, sizeof(t), 1, f) != 1) + goto close; + if (t == '\n') + break; + vline.push_back(t); + if (vline.size() > 1000) + { + res = 0; + goto close; + } + } + vline.push_back(0); + + std::string line = &vline[0]; + + if (line.substr(0, noicons.size()) == noicons) + { + noicons_ = true; + goto close; + } + + if (line.empty()) + goto close; + + e.status_ = line[0]; + + std::string path; + if (line.size() > 1) + { + path = line.c_str() + 1;   }   path.push_back('/'); - path.push_back(0);   - e.path_ = &path[0]; + e.path_ = path;     v_.push_back(e);   }   +close:   fclose(f);     TDEBUG_TRACE("DirectoryStatus::read(" << hgroot << "): done. " - << v_.size() << " entries read"); + << v_.size() << " entries read. noicons_ = " << noicons_ );   - return 1; + return res;  }    
 
30
31
32
 
33
34
 
 
35
36
37
 
38
39
40
 
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
@@ -30,11 +30,15 @@
    typedef std::vector<E> V;   V v_; + bool noicons_;    public: + DirectoryStatus(): noicons_(false) {} +   static DirectoryStatus* get(   const std::string& hgroot, const std::string& cwd);   char status(const std::string& relpath) const; + bool noicons() const { return noicons_; }    private:   int read(const std::string& hgroot, const std::string& cwd);
 
175
176
177
 
 
 
 
 
 
 
178
179
180
181
182
183
 
 
184
 
185
186
187
188
 
189
190
191
 
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
@@ -175,17 +175,26 @@
  relpath[i] = '/';   }   + DirectoryStatus* pdirsta = DirectoryStatus::get(cur.hgroot, cur.basedir); + if (pdirsta && pdirsta->noicons()) + { + last = cur; + return 0; + } +   if (cur.isdir)   {   if (!relpath.empty())   {   Dirstate* pds2 = Dirstatecache::get(cur.hgroot, cur.basedir);   if (pds2 && !pds2->root().getdir(relpath)) + { + last = cur;   return 0; // unknown dir -> no icon + }   }   - DirectoryStatus* pds = DirectoryStatus::get(cur.hgroot, cur.basedir); - outStatus = (pds ? pds->status(relpath) : '?'); + outStatus = (pdirsta ? pdirsta->status(relpath) : '?');   }   else   {