Changeset 97a7505a2b54…
Parent 25a749a2c8fb…
by
Changes to 4 files · Browse files at 97a7505a2b54 Showing diff from parent 25a749a2c8fb Diff from another changeset...
|
|
@@ -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,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,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):
"""
|
@@ -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
|
Loading...