Changeset 1385

Show
Ignore:
Timestamp:
10/15/06 17:18:31 (2 years ago)
Author:
coderanger
Message:

FilenameSearchPlugin:

  • Add config options to control "wrong" matches
  • Allow for globbing against each component if the term doesn't contain '/'
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • filenamesearchplugin/0.10/filenamesearch/web_ui.py

    r1384 r1385  
    33from trac.Search import ISearchSource 
    44from trac.perm import IPermissionRequestor 
     5from trac.config import BoolOption 
    56 
    67from fnmatch import fnmatchcase 
     
    89class FilenameSearchModule(Component): 
    910    """Search source for filenames in the repository.""" 
     11 
     12    check_gone = BoolOption('filenamesearch', 'check_gone', default=True, 
     13                            doc='Check if files are present in the youngest rev before returning.')     
     14    show_gone = BoolOption('filenamesearch', 'show_gone', default=True, 
     15                           doc='Show files that are in the DB, but not in the youngest rev. (These may indicate moved files)') 
    1016     
    1117    implements(ISearchSource, IPermissionRequestor) 
     
    2228        cursor = db.cursor() 
    2329        repo = self.env.get_repository(req.authname) 
    24         #youngest_rev = repo.get_youngest_rev()         
     30        youngest_rev = repo.get_youngest_rev()         
    2531 
    2632        cursor.execute("""SELECT max("""+db.cast('rev','int')+"""), path FROM node_change 
     
    3339        for term in terms: 
    3440            for rev, path in all_files: 
    35                 if fnmatchcase(path, term): 
     41                match = None 
     42                if '/' in term: 
     43                    match = fnmatchcase(path, term.lstrip('/')) 
     44                else: 
     45                    match = sum([fnmatchcase(x, term) for x in path.split('/')]) 
     46                if match: 
    3647                    cset = cset_cache.setdefault(rev, repo.get_changeset(rev)) 
    37                     yield (req.href.browser(path, rev=rev), path, cset.date, cset.author, '') 
     48                    msg = '' 
     49                    if self.check_gone and not repo.has_node(path, youngest_rev): 
     50                        if self.show_gone: 
     51                            msg = 'Not in the youngest revision, file has possibly been moved.' 
     52                        else: 
     53                            continue 
     54                    yield (req.href.browser(path, rev=rev), path, cset.date, cset.author, msg) 
    3855         
    3956    # IPermissionRequestor methods