Fossil

Check-in [6499c93d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:The "fossil grep" command now agrees with the documentation. But there is still a lot of opportunity to make enhancements.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6499c93dbfbabcdf6b36b45a80f6ca97e135d28a48f8dde0525d28dc578c2947
User & Date: drh 2018-06-13 02:18:42
Context
2018-06-14
13:48
Reinstate the timeline arrow foreground color changes that were removed by check-in [7ac88481a69dd], but with fixes to avoid integer overflow. check-in: 57a0143b user: drh tags: trunk
13:43
Reinstate the foreground color changing for timeline arrors based on the background color of the text. This check-in uses the #00aa00 background color intentially for testing purposes. Closed-Leaf check-in: 4f2b2309 user: drh tags: arrow-color-fix
2018-06-13
02:18
The "fossil grep" command now agrees with the documentation. But there is still a lot of opportunity to make enhancements. check-in: 6499c93d user: drh tags: trunk
02:02
Incomplete implementation of the "fossil grep" command. check-in: c5a98aa0 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/regexp.c.

   823    823     }
   824    824     re_free(pRe);
   825    825   }
   826    826   
   827    827   /*
   828    828   ** COMMAND: grep
   829    829   **
   830         -** Usage: %fossil grep [OPTIONS] PATTERN FILENAME|CHECKIN
          830  +** Usage: %fossil grep [OPTIONS] PATTERN FILENAME
   831    831   **
   832         -** Run grep over all historic version of FILENAME or over all files
   833         -** in CHECKIN.
          832  +** Run grep over all historic version of FILENAME
   834    833   **
   835    834   ** Options:
   836    835   **
   837    836   **     -i|--ignore-case         Ignore case
   838    837   **     -l|--files-with-matches  Print only filenames that match
   839    838   **     -v|--verbose             Show each file as it is analyzed
   840    839   */
................................................................................
   848    847   
   849    848     if( find_option("ignore-case","i",0)!=0 ) ignoreCase = 1;
   850    849     if( find_option("files-with-matches","l",0)!=0 ) flags |= GREP_EXISTS;
   851    850     if( find_option("verbose","v",0)!=0 ) bVerbose = 1;
   852    851     db_find_and_open_repository(0, 0);
   853    852     verify_all_options();
   854    853     if( g.argc<3 ){
   855         -    usage("REGEXP FILENAME|CHECKIN");
          854  +    usage("REGEXP FILENAME");
   856    855     }
   857    856     zErr = re_compile(&pRe, g.argv[2], ignoreCase);
   858    857     if( zErr ) fossil_fatal("%s", zErr);
   859    858   
   860    859     if( file_tree_name(g.argv[3], &fullName, 0, 0) ){
   861    860       int fnid = db_int(0, "SELECT fnid FROM filename WHERE name=%Q",
   862    861                         blob_str(&fullName));
   863         -    Stmt q;
   864         -    if( fnid==0 ){
   865         -      fossil_fatal("no such file: \"%s\"", blob_str(&fullName));
          862  +    if( fnid ){
          863  +      Stmt q;
          864  +      add_content_sql_commands(g.db);
          865  +      db_prepare(&q,
          866  +        "SELECT content(ux), substr(ux,1,10) FROM ("
          867  +        "  SELECT blob.uuid AS ux, min(event.mtime) AS mx"
          868  +        "    FROM mlink, blob, event"
          869  +        "   WHERE mlink.mid=event.objid"
          870  +        "     AND mlink.fid=blob.rid"
          871  +        "     AND mlink.fnid=%d"
          872  +        "   GROUP BY blob.uuid"
          873  +        ") ORDER BY mx DESC;",
          874  +        fnid
          875  +      );
          876  +      while( db_step(&q)==SQLITE_ROW ){
          877  +        if( bVerbose ) fossil_print("%s:\n", db_column_text(&q,1));
          878  +        grep_buffer(pRe, db_column_text(&q,1), db_column_text(&q,0), flags);
          879  +      }
          880  +      db_finalize(&q);
   866    881       }
   867         -    add_content_sql_commands(g.db);
   868         -    db_prepare(&q,
   869         -      "SELECT content(uuid), substr(uuid,1,10)"
   870         -      "  FROM mlink, blob, event"
   871         -      " WHERE mlink.mid=event.objid"
   872         -      "   AND mlink.fid=blob.rid"
   873         -      "   AND mlink.fnid=%d"
   874         -      " ORDER BY event.mtime DESC",
   875         -      fnid
   876         -    );
   877         -    while( db_step(&q)==SQLITE_ROW ){
   878         -      grep_buffer(pRe, db_column_text(&q,1), db_column_text(&q,0), flags);
   879         -    }
   880         -    db_finalize(&q);
   881    882     }
   882    883   }