hgext/directaccess.py
changeset 1714 4565b046b850
parent 1552 ebebff25b891
equal deleted inserted replaced
1713:00612a019547 1714:4565b046b850
   130 
   130 
   131 hashre = util.re.compile('[0-9a-fA-F]{1,40}')
   131 hashre = util.re.compile('[0-9a-fA-F]{1,40}')
   132 
   132 
   133 _listtuple = ('symbol', '_list')
   133 _listtuple = ('symbol', '_list')
   134 
   134 
       
   135 def _ishashsymbol(symbol, maxrev):
       
   136     # Returns true if symbol looks like a hash
       
   137     try:
       
   138         n = int(symbol)
       
   139         if n <= maxrev:
       
   140             # It's a rev number
       
   141             return False
       
   142     except ValueError:
       
   143         pass
       
   144     return hashre.match(symbol)
       
   145 
   135 def gethashsymbols(tree, maxrev):
   146 def gethashsymbols(tree, maxrev):
   136     # Returns the list of symbols of the tree that look like hashes
   147     # Returns the list of symbols of the tree that look like hashes
   137     # for example for the revset 3::abe3ff it will return ('abe3ff')
   148     # for example for the revset 3::abe3ff it will return ('abe3ff')
   138     if not tree:
   149     if not tree:
   139         return []
   150         return []
   140 
   151 
       
   152     results = []
   141     if len(tree) == 2 and tree[0] == "symbol":
   153     if len(tree) == 2 and tree[0] == "symbol":
   142         try:
   154         results.append(tree[1])
   143             n = int(tree[1])
       
   144             # This isn't necessarily a rev number, could be a hash prefix
       
   145             if n > maxrev:
       
   146                 return [tree[1]]
       
   147             else:
       
   148                 return []
       
   149         except ValueError as e:
       
   150             if hashre.match(tree[1]):
       
   151                 return [tree[1]]
       
   152             return []
       
   153     elif tree[0] == "func" and tree[1] == _listtuple:
   155     elif tree[0] == "func" and tree[1] == _listtuple:
   154         # the optimiser will group sequence of hash request
   156         # the optimiser will group sequence of hash request
   155         result = []
   157         results += tree[2][1].split('\0')
   156         for entry in tree[2][1].split('\0'):
       
   157             if hashre.match(entry):
       
   158                 result.append(entry)
       
   159         return result
       
   160     elif len(tree) >= 3:
   158     elif len(tree) >= 3:
   161         results = []
       
   162         for subtree in tree[1:]:
   159         for subtree in tree[1:]:
   163             results += gethashsymbols(subtree, maxrev)
   160             results += gethashsymbols(subtree, maxrev)
       
   161         # return directly, we don't need to filter symbols again
   164         return results
   162         return results
   165     else:
   163     return [s for s in results if _ishashsymbol(s, maxrev)]
   166         return []
       
   167 
   164 
   168 def _posttreebuilthook(orig, tree, repo):
   165 def _posttreebuilthook(orig, tree, repo):
   169     # This is use to enabled direct hash access
   166     # This is use to enabled direct hash access
   170     # We extract the symbols that look like hashes and add them to the
   167     # We extract the symbols that look like hashes and add them to the
   171     # explicitaccess set
   168     # explicitaccess set