##// END OF EJS Templates
Add unique boolean argument to history search
Takafumi Arakaki -
Show More
@@ -307,7 +307,7 b' class HistoryAccessor(Configurable):'
307
307
308 @catch_corrupt_db
308 @catch_corrupt_db
309 def search(self, pattern="*", raw=True, search_raw=True,
309 def search(self, pattern="*", raw=True, search_raw=True,
310 output=False, n=None):
310 output=False, n=None, unique=False):
311 """Search the database using unix glob-style matching (wildcards
311 """Search the database using unix glob-style matching (wildcards
312 * and ?).
312 * and ?).
313
313
@@ -322,6 +322,8 b' class HistoryAccessor(Configurable):'
322 n : None or int
322 n : None or int
323 If an integer is given, it defines the limit of
323 If an integer is given, it defines the limit of
324 returned entries.
324 returned entries.
325 unique : bool
326 When it is true, return only unique entries.
325
327
326 Returns
328 Returns
327 -------
329 -------
@@ -333,9 +335,13 b' class HistoryAccessor(Configurable):'
333 self.writeout_cache()
335 self.writeout_cache()
334 sqlform = "WHERE %s GLOB ?" % tosearch
336 sqlform = "WHERE %s GLOB ?" % tosearch
335 params = (pattern,)
337 params = (pattern,)
338 if unique:
339 sqlform += ' GROUP BY {0}'.format(tosearch)
336 if n is not None:
340 if n is not None:
337 sqlform += " ORDER BY session DESC, line DESC LIMIT ?"
341 sqlform += " ORDER BY session DESC, line DESC LIMIT ?"
338 params += (n,)
342 params += (n,)
343 elif unique:
344 sqlform += " ORDER BY session, line"
339 cur = self._run_sql(sqlform, params, raw=raw, output=output)
345 cur = self._run_sql(sqlform, params, raw=raw, output=output)
340 if n is not None:
346 if n is not None:
341 return reversed(list(cur))
347 return reversed(list(cur))
General Comments 0
You need to be logged in to leave comments. Login now