Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.0, 1.0.1, and 1.0.2

bookmarks: fixes invalidaterepo check if repo._bookmarks is a property

also provides hglib.is_descriptor, which might be useful for other things

Changeset 67a74dbcb9b4

Parent 4d75e31662d4

by Paul Molodowitch

Changes to one file · Browse files at 67a74dbcb9b4 Showing diff from parent 4d75e31662d4 Diff from another changeset...

 
9
10
11
 
12
13
14
 
147
148
149
150
151
 
152
153
154
 
381
382
383
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
10
11
12
13
14
15
 
148
149
150
 
 
151
152
153
154
 
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
@@ -9,6 +9,7 @@
 import sys  import shlex  import time +import inspect    from mercurial import ui, util, extensions, match, bundlerepo, url  from mercurial import dispatch, encoding, templatefilters, filemerge @@ -147,8 +148,7 @@
  # from 1.4 to 1.5...   for cachedAttr in ('_bookmarks', '_bookmarkcurrent'):   # Check if it's a property or normal value... - classAttr = getattr(repo.__class__, cachedAttr, None) - if hasattr(classAttr, '__get__'): + if is_descriptor(repo, cachedAttr):   # The very act of calling hasattr would   # re-cache the property, so just assume it's   # already cached, and catch the error if it wasn't. @@ -381,3 +381,18 @@
  return False     return rev == parents[0].node() + +def is_descriptor(obj, attr): + """ + Returns True if obj.attr is a descriptor - ie, accessing + the attribute will actually invoke the '__get__' method of + some object. + + Returns False if obj.attr exists, but is not a descriptor, + and None if obj.attr was not found at all. + """ + for cls in inspect.getmro(obj.__class__): + if attr in cls.__dict__: + return hasattr(cls.__dict__[attr], '__get__') + return None +