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

tortoise: make debugging load-time selectable

HKEY_CURRENT_USER\Software\TortoiseHg\OverlayDebug - enables overlay tracelog
HKEY_CURRENT_USER\Software\TortoiseHg\ContextMenuDebug - enables cmenu tracelog

Options are read when the shell extensions are loaded, so restarting explorer.exe
or launching as /separate will use new registry values. Key values of '1' or 'True'
enable logging. Thgconfig will be able to set these shortly.

Changeset 97a7505a2b54

Parent 25a749a2c8fb

by Steve Borho

Changes to 4 files · Browse files at 97a7505a2b54 Showing diff from parent 25a749a2c8fb Diff from another changeset...

 
7
8
9
 
 
10
11
12
 
 
 
 
 
 
 
 
 
 
13
14
15
16
 
 
 
 
 
 
 
 
 
17
18
19
 
57
58
59
60
 
61
62
63
 
76
77
78
79
 
80
81
82
 
83
84
85
 
90
91
92
93
 
94
95
96
 
98
99
100
101
102
103
 
104
105
106
 
107
108
109
 
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
 
141
142
143
144
145
 
 
146
147
148
 
149
150
151
 
164
165
166
167
 
168
169
170
 
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
 
78
79
80
 
81
82
83
84
 
97
98
99
 
100
101
102
 
103
104
105
106
 
111
112
113
 
114
115
116
117
 
119
120
121
 
122
 
123
124
125
126
127
128
129
130
 
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
 
162
163
164
 
 
165
166
167
168
 
169
170
171
172
 
185
186
187
 
188
189
190
191
@@ -7,13 +7,34 @@
 except ImportError:   from mercurial.repo import RepoError   +debugging = False +  try:   from win32api import GetTickCount   CACHE_TIMEOUT = 5000 + import _winreg + try: + hkey = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, + r"Software\TortoiseHg", 0, + _winreg.KEY_ALL_ACCESS) + val = QueryValueEx(hkey, 'OverlayDebug')[0] + if val in ('1', 'True'): + debugging = True + except EnvironmentError: + pass  except ImportError:   from time import time as GetTickCount   CACHE_TIMEOUT = 5.0   +if debugging: + import win32traceutil + def debugf(str, args=None): + if args: print str % args + else: print str +else: + def debugf(str, args=None): + pass +  UNCHANGED = "unchanged"  ADDED = "added"  MODIFIED = "modified" @@ -57,7 +78,7 @@
  global overlay_cache, cache_tick_count   global cache_root, cache_pdir   - #print "called: _get_state(%s)" % path + #debugf("called: _get_state(%s)", path)   tc = GetTickCount()     try: @@ -76,10 +97,10 @@
  status = ROOT,   else:   status = overlay_cache.get(pdir, [NOT_IN_REPO]) - print "%s: %s (cached)" % (path, status) + debugf("%s: %s (cached)", (path, status))   return status   else: - print "Timed out!! ", + debugf("Timed out!!")   overlay_cache.clear()   cache_tick_count = GetTickCount()   # path is a drive @@ -90,7 +111,7 @@
  if cache_pdir == pdir:   root = cache_root   else: - print "find new root ", + debugf("find new root")   root = thgutil.find_root(path)   if root == path:   add(path, ROOT) @@ -98,12 +119,12 @@
  cache_root = root   cache_pdir = pdir   - print "_get_state: root = ", root   if root is None: - print "_get_state: not in repo" + debugf("_get_state: not in repo")   overlay_cache = {None: None}   cache_tick_count = GetTickCount()   return [NOT_IN_REPO] + debugf("_get_state: root = " + root)   hgdir = os.path.join(root, '.hg', '')   if pdir == hgdir[:-1] or pdir.startswith(hgdir):   add(pdir, NOT_IN_REPO) @@ -112,25 +133,25 @@
  tc1 = GetTickCount()   if not repo or (repo.root != root and repo.root != os.path.realpath(root)):   repo = hg.repository(ui.ui(), path=root) - print "hg.repository() took %g ticks" % (GetTickCount() - tc1) + debugf("hg.repository() took %g ticks", (GetTickCount() - tc1))   # check if to display overlay icons in this repo   overlayopt = repo.ui.config('tortoisehg', 'overlayicons', ' ').lower() - print "%s: repo overlayicons = " % path, overlayopt + debugf("%s: repo overlayicons = ", (path, overlayopt))   if overlayopt == 'localdisk':   overlayopt = bool(thgutil.netdrive_status(path))   if not overlayopt or overlayopt in 'false off no'.split(): - print "%s: overlayicons disabled" % path + debugf("%s: overlayicons disabled", path)   overlay_cache = {None: None}   cache_tick_count = GetTickCount()   return [NOT_IN_REPO]   except RepoError:   # We aren't in a working tree - print "%s: not in repo" % pdir + debugf("%s: not in repo", pdir)   add(pdir, IGNORED)   return [IGNORED]   except StandardError, e: - print "error while handling %s:" % pdir - print e + debugf("error while handling %s:", pdir) + debugf(e)   add(pdir, UNKNOWN)   return [UNKNOWN]   # get file status @@ -141,11 +162,11 @@
  repostate = repo.status(match=matcher, ignored=True,   clean=True, unknown=True)   except util.Abort, inst: - print "abort: %s" % inst - print "treat as unknown : %s" % path + debugf("abort: %s", inst) + debugf("treat as unknown : %s", path)   return [UNKNOWN]   - print "status() took %g ticks" % (GetTickCount() - tc1) + debugf("status() took %g ticks", (GetTickCount() - tc1))   modified, added, removed, deleted, unknown, ignored, clean = repostate   # cached file info   tc = GetTickCount() @@ -164,7 +185,7 @@
  add(fpath, st)   add(root, ROOT)   status = overlay_cache.get(path, [UNKNOWN]) - print "\n%s: %s" % (path, status) + debugf("\n%s: %s", (path, status))   cache_tick_count = GetTickCount()   return status  
 
26
27
28
29
30
31
32
33
34
35
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
38
39
 
26
27
28
 
 
 
 
 
 
 
 
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
@@ -26,14 +26,24 @@
 except ImportError:   from mercurial.repo import RepoError   -# FIXME: quick workaround traceback caused by missing "closed" -# attribute in win32trace. -import sys -from mercurial import ui -def write_err(self, *args): - for a in args: - sys.stderr.write(str(a)) -ui.ui.write_err = write_err +debugging = False + +try: + import _winreg + try: + hkey = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, + r"Software\TortoiseHg", 0, + _winreg.KEY_ALL_ACCESS) + val = QueryValueEx(hkey, 'ContextMenuDebug')[0] + if val in ('1', 'True'): + debugging = True + except EnvironmentError: + pass +except ImportError: + pass + +if debugging: + import win32traceutil    S_OK = 0  S_FALSE = 1
 
11
12
13
 
 
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
71
72
73
74
75
 
 
76
77
78
 
11
12
13
14
15
16
17
18
19
20
21
 
 
 
 
 
 
 
 
 
 
22
23
24
 
63
64
65
 
 
66
67
68
69
70
@@ -11,22 +11,14 @@
 import thgutil  import sys  import threading +import cachethg +from cachethg import debugf    try:   from mercurial.error import RepoError  except ImportError:   from mercurial.repo import RepoError   -# FIXME: quick workaround traceback caused by missing "closed" -# attribute in win32trace. -from mercurial import ui -def write_err(self, *args): - for a in args: - sys.stderr.write(str(a)) -ui.ui.write_err = write_err - -import cachethg -  cache_lock = threading.Semaphore()    # some misc constants @@ -71,8 +63,8 @@
  return S_FALSE   finally:   cache_lock.release() - print "IsMemberOf(%s): _get_state() took %d ticks" % \ - (self.state, win32api.GetTickCount() - tc) + debugf("IsMemberOf(%s): _get_state() took %d ticks", + (self.state, win32api.GetTickCount() - tc))    def make_icon_overlay(name, icon_type, state, clsid):   """
Change 1 of 1 Show Entire File tortoisehg.py Stacked
 
15
16
17
18
19
20
21
22
23
 
15
16
17
 
 
 
18
19
20
@@ -15,9 +15,6 @@
 import sys  import _winreg   -if hasattr(sys, "frozen") and sys.frozen == 'dll': - import win32traceutil -  # shell extension classes  from tortoise.contextmenu import ContextMenuExtension  from tortoise.iconoverlay import ChangedOverlay, AddedOverlay, UnchangedOverlay