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 Unified Diffs Ignore Whitespace Patch

Changes to src/regexp.c.

823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
...
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862

863
864
865
866
867
868
869

870
871
872
873

874
875
876
877

878
879
880
881
882

  }
  re_free(pRe);
}

/*
** COMMAND: grep
**
** Usage: %fossil grep [OPTIONS] PATTERN FILENAME|CHECKIN
**
** Run grep over all historic version of FILENAME or over all files
** in CHECKIN.
**
** Options:
**
**     -i|--ignore-case         Ignore case
**     -l|--files-with-matches  Print only filenames that match
**     -v|--verbose             Show each file as it is analyzed
*/
................................................................................

  if( find_option("ignore-case","i",0)!=0 ) ignoreCase = 1;
  if( find_option("files-with-matches","l",0)!=0 ) flags |= GREP_EXISTS;
  if( find_option("verbose","v",0)!=0 ) bVerbose = 1;
  db_find_and_open_repository(0, 0);
  verify_all_options();
  if( g.argc<3 ){
    usage("REGEXP FILENAME|CHECKIN");
  }
  zErr = re_compile(&pRe, g.argv[2], ignoreCase);
  if( zErr ) fossil_fatal("%s", zErr);

  if( file_tree_name(g.argv[3], &fullName, 0, 0) ){
    int fnid = db_int(0, "SELECT fnid FROM filename WHERE name=%Q",
                      blob_str(&fullName));

    Stmt q;
    if( fnid==0 ){
      fossil_fatal("no such file: \"%s\"", blob_str(&fullName));
    }
    add_content_sql_commands(g.db);
    db_prepare(&q,
      "SELECT content(uuid), substr(uuid,1,10)"

      "  FROM mlink, blob, event"
      " WHERE mlink.mid=event.objid"
      "   AND mlink.fid=blob.rid"
      "   AND mlink.fnid=%d"

      " ORDER BY event.mtime DESC",
      fnid
    );
    while( db_step(&q)==SQLITE_ROW ){

      grep_buffer(pRe, db_column_text(&q,1), db_column_text(&q,0), flags);
    }
    db_finalize(&q);
  }
}








|

|
<







 







|







>
|
<
<
<
|
|
|
>
|
|
|
|
>
|
|
|
|
>
|
|
|
|
|
>
823
824
825
826
827
828
829
830
831
832

833
834
835
836
837
838
839
...
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863



864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
  }
  re_free(pRe);
}

/*
** COMMAND: grep
**
** Usage: %fossil grep [OPTIONS] PATTERN FILENAME
**
** Run grep over all historic version of FILENAME

**
** Options:
**
**     -i|--ignore-case         Ignore case
**     -l|--files-with-matches  Print only filenames that match
**     -v|--verbose             Show each file as it is analyzed
*/
................................................................................

  if( find_option("ignore-case","i",0)!=0 ) ignoreCase = 1;
  if( find_option("files-with-matches","l",0)!=0 ) flags |= GREP_EXISTS;
  if( find_option("verbose","v",0)!=0 ) bVerbose = 1;
  db_find_and_open_repository(0, 0);
  verify_all_options();
  if( g.argc<3 ){
    usage("REGEXP FILENAME");
  }
  zErr = re_compile(&pRe, g.argv[2], ignoreCase);
  if( zErr ) fossil_fatal("%s", zErr);

  if( file_tree_name(g.argv[3], &fullName, 0, 0) ){
    int fnid = db_int(0, "SELECT fnid FROM filename WHERE name=%Q",
                      blob_str(&fullName));
    if( fnid ){
      Stmt q;



      add_content_sql_commands(g.db);
      db_prepare(&q,
        "SELECT content(ux), substr(ux,1,10) FROM ("
        "  SELECT blob.uuid AS ux, min(event.mtime) AS mx"
        "    FROM mlink, blob, event"
        "   WHERE mlink.mid=event.objid"
        "     AND mlink.fid=blob.rid"
        "     AND mlink.fnid=%d"
        "   GROUP BY blob.uuid"
        ") ORDER BY mx DESC;",
        fnid
      );
      while( db_step(&q)==SQLITE_ROW ){
        if( bVerbose ) fossil_print("%s:\n", db_column_text(&q,1));
        grep_buffer(pRe, db_column_text(&q,1), db_column_text(&q,0), flags);
      }
      db_finalize(&q);
    }
  }
}