Changeset 581ea099d9d7…
Parent 3fc3518ce7db…
by
Changes to one file · Browse files at 581ea099d9d7 Showing diff from parent 3fc3518ce7db Diff from another changeset...
|
|
@@ -20,6 +20,7 @@ UNKNOWN = "unknown"
IGNORED = "ignored"
NOT_IN_REPO = "n/a"
+ROOT = "root"
# file status cache
overlay_cache = {}
@@ -30,6 +31,8 @@
def add_dirs(list):
dirs = set()
+ if list:
+ dirs.add('')
for f in list:
pdir = os.path.dirname(f)
if pdir in dirs:
@@ -44,6 +47,13 @@ """
Get the state of a given path in source control.
"""
+ return get_states(upath, repo)[-1]
+
+
+def get_states(upath, repo=None):
+ """
+ Get the states of a given path in source control.
+ """
global overlay_cache, cache_tick_count
global cache_root, cache_pdir
@@ -61,34 +71,43 @@ if tc - cache_tick_count < CACHE_TIMEOUT:
status = overlay_cache.get(path)
if not status:
- status = overlay_cache.get(pdir, NOT_IN_REPO)
+ if os.path.isdir(os.path.join(path, '.hg')):
+ add(path, ROOT)
+ status = ROOT,
+ else:
+ status = overlay_cache.get(pdir, [NOT_IN_REPO])
print "%s: %s (cached)" % (path, status)
return status
else:
- print "Timed out!!"
+ print "Timed out!! ",
overlay_cache.clear()
cache_tick_count = GetTickCount()
# path is a drive
if path.endswith(":\\"):
- overlay_cache[path] = NOT_IN_REPO
- return NOT_IN_REPO
+ add(path, NOT_IN_REPO)
+ return [NOT_IN_REPO]
# open repo
if cache_pdir == pdir:
root = cache_root
else:
- print "find new root"
+ print "find new root ",
+ root = thgutil.find_root(path)
+ if root == path:
+ add(path, ROOT)
+ return [ROOT]
+ cache_root = root
cache_pdir = pdir
- cache_root = root = thgutil.find_root(pdir)
+
print "_get_state: root = ", root
if root is None:
print "_get_state: not in repo"
overlay_cache = {None: None}
cache_tick_count = GetTickCount()
- return NOT_IN_REPO
+ return [NOT_IN_REPO]
hgdir = os.path.join(root, '.hg', '')
if pdir == hgdir[:-1] or pdir.startswith(hgdir):
- overlay_cache[pdir] = NOT_IN_REPO
- return NOT_IN_REPO
+ add(pdir, NOT_IN_REPO)
+ return [NOT_IN_REPO]
try:
tc1 = GetTickCount()
if not repo or (repo.root != root and repo.root != os.path.realpath(root)):
@@ -103,17 +122,17 @@ print "%s: overlayicons disabled" % path
overlay_cache = {None: None}
cache_tick_count = GetTickCount()
- return NOT_IN_REPO
+ return [NOT_IN_REPO]
except RepoError:
# We aren't in a working tree
print "%s: not in repo" % pdir
- overlay_cache[pdir] = IGNORED
- return IGNORED
+ add(pdir, IGNORED)
+ return [IGNORED]
except StandardError, e:
print "error while handling %s:" % pdir
print e
- overlay_cache[pdir] = UNKNOWN
- return UNKNOWN
+ add(pdir, UNKNOWN)
+ return [UNKNOWN]
# get file status
tc1 = GetTickCount()
@@ -121,13 +140,10 @@ matcher = cmdutil.match(repo, [pdir])
repostate = repo.status(match=matcher, ignored=True,
clean=True, unknown=True)
- # add directory status to list
- for grp in repostate:
- add_dirs(grp)
except util.Abort, inst:
print "abort: %s" % inst
print "treat as unknown : %s" % path
- return UNKNOWN
+ return [UNKNOWN]
print "status() took %g ticks" % (GetTickCount() - tc1)
modified, added, removed, deleted, unknown, ignored, clean = repostate
@@ -142,10 +158,17 @@ (removed, MODIFIED),
(deleted, MODIFIED),
(modified, MODIFIED)):
+ add_dirs(grp)
for f in grp:
fpath = os.path.join(root, os.path.normpath(f))
- overlay_cache[fpath] = st
- status = overlay_cache.get(path, UNKNOWN)
- print "%s: %s" % (path, status)
+ add(fpath, st)
+ add(root, ROOT)
+ status = overlay_cache.get(path, [UNKNOWN])
+ print "\n%s: %s" % (path, status)
cache_tick_count = GetTickCount()
return status
+
+
+def add(path, state):
+ c = overlay_cache.setdefault(path, [])
+ c.append(state)
|
Loading...