Fossil SCM

The "fossil grep" command now agrees with the documentation. But there is still a lot of opportunity to make enhancements.

drh 2018-06-13 02:18 trunk
Commit 6499c93dbfbabcdf6b36b45a80f6ca97e135d28a48f8dde0525d28dc578c2947
1 file changed +23 -22
+23 -22
--- src/regexp.c
+++ src/regexp.c
@@ -825,14 +825,13 @@
825825
}
826826
827827
/*
828828
** COMMAND: grep
829829
**
830
-** Usage: %fossil grep [OPTIONS] PATTERN FILENAME|CHECKIN
830
+** Usage: %fossil grep [OPTIONS] PATTERN FILENAME
831831
**
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
834833
**
835834
** Options:
836835
**
837836
** -i|--ignore-case Ignore case
838837
** -l|--files-with-matches Print only filenames that match
@@ -850,33 +849,35 @@
850849
if( find_option("files-with-matches","l",0)!=0 ) flags |= GREP_EXISTS;
851850
if( find_option("verbose","v",0)!=0 ) bVerbose = 1;
852851
db_find_and_open_repository(0, 0);
853852
verify_all_options();
854853
if( g.argc<3 ){
855
- usage("REGEXP FILENAME|CHECKIN");
854
+ usage("REGEXP FILENAME");
856855
}
857856
zErr = re_compile(&pRe, g.argv[2], ignoreCase);
858857
if( zErr ) fossil_fatal("%s", zErr);
859858
860859
if( file_tree_name(g.argv[3], &fullName, 0, 0) ){
861860
int fnid = db_int(0, "SELECT fnid FROM filename WHERE name=%Q",
862861
blob_str(&fullName));
863
- Stmt q;
864
- if( fnid==0 ){
865
- fossil_fatal("no such file: \"%s\"", blob_str(&fullName));
866
- }
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);
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);
881
+ }
881882
}
882883
}
883884
--- src/regexp.c
+++ src/regexp.c
@@ -825,14 +825,13 @@
825 }
826
827 /*
828 ** COMMAND: grep
829 **
830 ** Usage: %fossil grep [OPTIONS] PATTERN FILENAME|CHECKIN
831 **
832 ** Run grep over all historic version of FILENAME or over all files
833 ** in CHECKIN.
834 **
835 ** Options:
836 **
837 ** -i|--ignore-case Ignore case
838 ** -l|--files-with-matches Print only filenames that match
@@ -850,33 +849,35 @@
850 if( find_option("files-with-matches","l",0)!=0 ) flags |= GREP_EXISTS;
851 if( find_option("verbose","v",0)!=0 ) bVerbose = 1;
852 db_find_and_open_repository(0, 0);
853 verify_all_options();
854 if( g.argc<3 ){
855 usage("REGEXP FILENAME|CHECKIN");
856 }
857 zErr = re_compile(&pRe, g.argv[2], ignoreCase);
858 if( zErr ) fossil_fatal("%s", zErr);
859
860 if( file_tree_name(g.argv[3], &fullName, 0, 0) ){
861 int fnid = db_int(0, "SELECT fnid FROM filename WHERE name=%Q",
862 blob_str(&fullName));
863 Stmt q;
864 if( fnid==0 ){
865 fossil_fatal("no such file: \"%s\"", blob_str(&fullName));
866 }
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 }
883
--- src/regexp.c
+++ src/regexp.c
@@ -825,14 +825,13 @@
825 }
826
827 /*
828 ** COMMAND: grep
829 **
830 ** Usage: %fossil grep [OPTIONS] PATTERN FILENAME
831 **
832 ** Run grep over all historic version of FILENAME
 
833 **
834 ** Options:
835 **
836 ** -i|--ignore-case Ignore case
837 ** -l|--files-with-matches Print only filenames that match
@@ -850,33 +849,35 @@
849 if( find_option("files-with-matches","l",0)!=0 ) flags |= GREP_EXISTS;
850 if( find_option("verbose","v",0)!=0 ) bVerbose = 1;
851 db_find_and_open_repository(0, 0);
852 verify_all_options();
853 if( g.argc<3 ){
854 usage("REGEXP FILENAME");
855 }
856 zErr = re_compile(&pRe, g.argv[2], ignoreCase);
857 if( zErr ) fossil_fatal("%s", zErr);
858
859 if( file_tree_name(g.argv[3], &fullName, 0, 0) ){
860 int fnid = db_int(0, "SELECT fnid FROM filename WHERE name=%Q",
861 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);
881 }
882 }
883 }
884

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button