Fossil SCM
The "fossil grep" command now agrees with the documentation. But there is still a lot of opportunity to make enhancements.
Commit
6499c93dbfbabcdf6b36b45a80f6ca97e135d28a48f8dde0525d28dc578c2947
Parent
c5a98aa0ba0692d…
1 file changed
+23
-22
+23
-22
| --- src/regexp.c | ||
| +++ src/regexp.c | ||
| @@ -825,14 +825,13 @@ | ||
| 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 |
| @@ -850,33 +849,35 @@ | ||
| 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)); | |
| 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 | + } | |
| 881 | 882 | } |
| 882 | 883 | } |
| 883 | 884 |
| --- 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 |