Fossil SCM
Add -width option to the search command.
Commit
e4a6159ba38c085c5ecfb5048dceec6413cae44c
Parent
5dc60b1faffeeb6…
1 file changed
+16
-4
+16
-4
| --- src/search.c | ||
| +++ src/search.c | ||
| @@ -167,21 +167,23 @@ | ||
| 167 | 167 | |
| 168 | 168 | /* |
| 169 | 169 | ** Testing the search function. |
| 170 | 170 | ** |
| 171 | 171 | ** COMMAND: search* |
| 172 | -** %fossil search [-all|-a] [-limit|-n #] pattern... | |
| 172 | +** %fossil search [-all|-a] [-limit|-n #] [-width|-W #] pattern... | |
| 173 | 173 | ** |
| 174 | 174 | ** Search for timeline entries matching all words |
| 175 | 175 | ** provided on the command line. Whole-word matches |
| 176 | 176 | ** scope more highly than partial matches. |
| 177 | 177 | ** |
| 178 | 178 | ** Outputs, by default, some top-N fraction of the |
| 179 | 179 | ** results. The -all option can be used to output |
| 180 | 180 | ** all matches, regardless of their search score. |
| 181 | -** -limit can be used to limit the number of entries | |
| 182 | -** returned. | |
| 181 | +** The -limit option can be used to limit the number | |
| 182 | +** of entries returned. The -width option can be | |
| 183 | +** used to set the output width used when printing | |
| 184 | +** matches. | |
| 183 | 185 | */ |
| 184 | 186 | void search_cmd(void){ |
| 185 | 187 | Search *p; |
| 186 | 188 | Blob pattern; |
| 187 | 189 | int i; |
| @@ -190,12 +192,22 @@ | ||
| 190 | 192 | int iBest; |
| 191 | 193 | char fAll = NULL != find_option("all", "a", 0); /* If set, do not lop |
| 192 | 194 | off the end of the |
| 193 | 195 | results. */ |
| 194 | 196 | char const * zLimit = find_option("limit","n",1); |
| 197 | + const char *zWidth = find_option("width","W",1); | |
| 195 | 198 | int nLimit = zLimit ? atoi(zLimit) : -1000; /* Max number of matching |
| 196 | 199 | lines/entries to list */ |
| 200 | + int width; | |
| 201 | + if( zWidth ){ | |
| 202 | + width = atoi(zWidth); | |
| 203 | + if( (width!=0) && (width<=20) ){ | |
| 204 | + fossil_fatal("--width|-W value must be >20 or 0"); | |
| 205 | + } | |
| 206 | + }else{ | |
| 207 | + width = 79; | |
| 208 | + } | |
| 197 | 209 | |
| 198 | 210 | db_must_be_within_tree(); |
| 199 | 211 | if( g.argc<2 ) return; |
| 200 | 212 | blob_init(&pattern, g.argv[2], -1); |
| 201 | 213 | for(i=3; i<g.argc; i++){ |
| @@ -224,8 +236,8 @@ | ||
| 224 | 236 | blob_appendf(&sql,"AND x>%d ", iBest/3); |
| 225 | 237 | } |
| 226 | 238 | blob_append(&sql, "ORDER BY x DESC, date DESC ", -1); |
| 227 | 239 | db_prepare(&q, blob_str(&sql)); |
| 228 | 240 | blob_reset(&sql); |
| 229 | - print_timeline(&q, nLimit, 79, 0); | |
| 241 | + print_timeline(&q, nLimit, width, 0); | |
| 230 | 242 | db_finalize(&q); |
| 231 | 243 | } |
| 232 | 244 |
| --- src/search.c | |
| +++ src/search.c | |
| @@ -167,21 +167,23 @@ | |
| 167 | |
| 168 | /* |
| 169 | ** Testing the search function. |
| 170 | ** |
| 171 | ** COMMAND: search* |
| 172 | ** %fossil search [-all|-a] [-limit|-n #] pattern... |
| 173 | ** |
| 174 | ** Search for timeline entries matching all words |
| 175 | ** provided on the command line. Whole-word matches |
| 176 | ** scope more highly than partial matches. |
| 177 | ** |
| 178 | ** Outputs, by default, some top-N fraction of the |
| 179 | ** results. The -all option can be used to output |
| 180 | ** all matches, regardless of their search score. |
| 181 | ** -limit can be used to limit the number of entries |
| 182 | ** returned. |
| 183 | */ |
| 184 | void search_cmd(void){ |
| 185 | Search *p; |
| 186 | Blob pattern; |
| 187 | int i; |
| @@ -190,12 +192,22 @@ | |
| 190 | int iBest; |
| 191 | char fAll = NULL != find_option("all", "a", 0); /* If set, do not lop |
| 192 | off the end of the |
| 193 | results. */ |
| 194 | char const * zLimit = find_option("limit","n",1); |
| 195 | int nLimit = zLimit ? atoi(zLimit) : -1000; /* Max number of matching |
| 196 | lines/entries to list */ |
| 197 | |
| 198 | db_must_be_within_tree(); |
| 199 | if( g.argc<2 ) return; |
| 200 | blob_init(&pattern, g.argv[2], -1); |
| 201 | for(i=3; i<g.argc; i++){ |
| @@ -224,8 +236,8 @@ | |
| 224 | blob_appendf(&sql,"AND x>%d ", iBest/3); |
| 225 | } |
| 226 | blob_append(&sql, "ORDER BY x DESC, date DESC ", -1); |
| 227 | db_prepare(&q, blob_str(&sql)); |
| 228 | blob_reset(&sql); |
| 229 | print_timeline(&q, nLimit, 79, 0); |
| 230 | db_finalize(&q); |
| 231 | } |
| 232 |
| --- src/search.c | |
| +++ src/search.c | |
| @@ -167,21 +167,23 @@ | |
| 167 | |
| 168 | /* |
| 169 | ** Testing the search function. |
| 170 | ** |
| 171 | ** COMMAND: search* |
| 172 | ** %fossil search [-all|-a] [-limit|-n #] [-width|-W #] pattern... |
| 173 | ** |
| 174 | ** Search for timeline entries matching all words |
| 175 | ** provided on the command line. Whole-word matches |
| 176 | ** scope more highly than partial matches. |
| 177 | ** |
| 178 | ** Outputs, by default, some top-N fraction of the |
| 179 | ** results. The -all option can be used to output |
| 180 | ** all matches, regardless of their search score. |
| 181 | ** The -limit option can be used to limit the number |
| 182 | ** of entries returned. The -width option can be |
| 183 | ** used to set the output width used when printing |
| 184 | ** matches. |
| 185 | */ |
| 186 | void search_cmd(void){ |
| 187 | Search *p; |
| 188 | Blob pattern; |
| 189 | int i; |
| @@ -190,12 +192,22 @@ | |
| 192 | int iBest; |
| 193 | char fAll = NULL != find_option("all", "a", 0); /* If set, do not lop |
| 194 | off the end of the |
| 195 | results. */ |
| 196 | char const * zLimit = find_option("limit","n",1); |
| 197 | const char *zWidth = find_option("width","W",1); |
| 198 | int nLimit = zLimit ? atoi(zLimit) : -1000; /* Max number of matching |
| 199 | lines/entries to list */ |
| 200 | int width; |
| 201 | if( zWidth ){ |
| 202 | width = atoi(zWidth); |
| 203 | if( (width!=0) && (width<=20) ){ |
| 204 | fossil_fatal("--width|-W value must be >20 or 0"); |
| 205 | } |
| 206 | }else{ |
| 207 | width = 79; |
| 208 | } |
| 209 | |
| 210 | db_must_be_within_tree(); |
| 211 | if( g.argc<2 ) return; |
| 212 | blob_init(&pattern, g.argv[2], -1); |
| 213 | for(i=3; i<g.argc; i++){ |
| @@ -224,8 +236,8 @@ | |
| 236 | blob_appendf(&sql,"AND x>%d ", iBest/3); |
| 237 | } |
| 238 | blob_append(&sql, "ORDER BY x DESC, date DESC ", -1); |
| 239 | db_prepare(&q, blob_str(&sql)); |
| 240 | blob_reset(&sql); |
| 241 | print_timeline(&q, nLimit, width, 0); |
| 242 | db_finalize(&q); |
| 243 | } |
| 244 |