Fossil SCM
Use the files_of_checkin virtual table to generate the file listings on the /dir page, instead of a bunch of C code that was written before files_of_checkin was invented.
Commit
15d9d5b097ab4e72eef9c81984550ff1baaf86117ba7eec4aaa1b83c036909ed
Parent
dedae5a1239eed6…
1 file changed
+48
-43
+48
-43
| --- src/browse.c | ||
| +++ src/browse.c | ||
| @@ -271,54 +271,42 @@ | ||
| 271 | 271 | */ |
| 272 | 272 | db_multi_exec( |
| 273 | 273 | "CREATE TEMP TABLE localfiles(x UNIQUE NOT NULL, u);" |
| 274 | 274 | ); |
| 275 | 275 | if( zCI ){ |
| 276 | - Stmt ins; | |
| 277 | - ManifestFile *pFile; | |
| 278 | - ManifestFile *pPrev = 0; | |
| 279 | - int nPrev = 0; | |
| 280 | - int c; | |
| 281 | - | |
| 282 | - db_prepare(&ins, | |
| 283 | - "INSERT OR IGNORE INTO localfiles VALUES(pathelement(:x,0), :u)" | |
| 284 | - ); | |
| 285 | - manifest_file_rewind(pM); | |
| 286 | - while( (pFile = manifest_file_next(pM,0))!=0 ){ | |
| 287 | - if( nD>0 | |
| 288 | - && (fossil_strncmp(pFile->zName, zD, nD-1)!=0 | |
| 289 | - || pFile->zName[nD-1]!='/') | |
| 290 | - ){ | |
| 291 | - continue; | |
| 292 | - } | |
| 293 | - if( pPrev | |
| 294 | - && fossil_strncmp(&pFile->zName[nD],&pPrev->zName[nD],nPrev)==0 | |
| 295 | - && (pFile->zName[nD+nPrev]==0 || pFile->zName[nD+nPrev]=='/') | |
| 296 | - ){ | |
| 297 | - continue; | |
| 298 | - } | |
| 299 | - db_bind_text(&ins, ":x", &pFile->zName[nD]); | |
| 300 | - db_bind_text(&ins, ":u", pFile->zUuid); | |
| 301 | - db_step(&ins); | |
| 302 | - db_reset(&ins); | |
| 303 | - pPrev = pFile; | |
| 304 | - for(nPrev=0; (c=pPrev->zName[nD+nPrev]) && c!='/'; nPrev++){} | |
| 305 | - if( c=='/' ) nPrev++; | |
| 306 | - } | |
| 307 | - db_finalize(&ins); | |
| 308 | - }else if( zD ){ | |
| 309 | - db_multi_exec( | |
| 310 | - "INSERT OR IGNORE INTO localfiles" | |
| 311 | - " SELECT pathelement(name,%d), NULL FROM filename" | |
| 312 | - " WHERE name GLOB '%q/*'", | |
| 313 | - nD, zD | |
| 314 | - ); | |
| 276 | + /* Files in the specific checked given by zCI */ | |
| 277 | + if( zD ){ | |
| 278 | + db_multi_exec( | |
| 279 | + "INSERT OR IGNORE INTO localfiles" | |
| 280 | + " SELECT pathelement(filename,%d), uuid" | |
| 281 | + " FROM files_of_checkin(%Q)" | |
| 282 | + " WHERE filename GLOB '%q/*'", | |
| 283 | + nD, zCI, zD | |
| 284 | + ); | |
| 285 | + }else{ | |
| 286 | + db_multi_exec( | |
| 287 | + "INSERT OR IGNORE INTO localfiles" | |
| 288 | + " SELECT pathelement(filename,%d), uuid" | |
| 289 | + " FROM files_of_checkin(%Q)", | |
| 290 | + nD, zCI | |
| 291 | + ); | |
| 292 | + } | |
| 315 | 293 | }else{ |
| 316 | - db_multi_exec( | |
| 317 | - "INSERT OR IGNORE INTO localfiles" | |
| 318 | - " SELECT pathelement(name,0), NULL FROM filename" | |
| 319 | - ); | |
| 294 | + /* All files across all check-ins */ | |
| 295 | + if( zD ){ | |
| 296 | + db_multi_exec( | |
| 297 | + "INSERT OR IGNORE INTO localfiles" | |
| 298 | + " SELECT pathelement(name,%d), NULL FROM filename" | |
| 299 | + " WHERE name GLOB '%q/*'", | |
| 300 | + nD, zD | |
| 301 | + ); | |
| 302 | + }else{ | |
| 303 | + db_multi_exec( | |
| 304 | + "INSERT OR IGNORE INTO localfiles" | |
| 305 | + " SELECT pathelement(name,0), NULL FROM filename" | |
| 306 | + ); | |
| 307 | + } | |
| 320 | 308 | } |
| 321 | 309 | |
| 322 | 310 | /* If the re=REGEXP query parameter is present, filter out names that |
| 323 | 311 | ** do not match the pattern */ |
| 324 | 312 | if( zRegexp ){ |
| @@ -1220,5 +1208,22 @@ | ||
| 1220 | 1208 | @ </table></div> |
| 1221 | 1209 | db_finalize(&q1); |
| 1222 | 1210 | db_finalize(&q2); |
| 1223 | 1211 | style_finish_page(); |
| 1224 | 1212 | } |
| 1213 | + | |
| 1214 | +/* | |
| 1215 | +** WEBPAGE: files | |
| 1216 | +** | |
| 1217 | +** Show files as a flat table. If the ci=LABEL query parameter is provided, | |
| 1218 | +** then show all the files in the specified check-in. Without the ci= query | |
| 1219 | +** parameter show all files across all check-ins. | |
| 1220 | +** | |
| 1221 | +** Query parameters: | |
| 1222 | +** | |
| 1223 | +** name=PATH Directory to display. Optional | |
| 1224 | +** ci=LABEL Show only files in this check-in. Optional. | |
| 1225 | +** re=REGEXP Show only files matching REGEXP. Optional. | |
| 1226 | +*/ | |
| 1227 | +void files_page(void){ | |
| 1228 | + return; | |
| 1229 | +} | |
| 1225 | 1230 |
| --- src/browse.c | |
| +++ src/browse.c | |
| @@ -271,54 +271,42 @@ | |
| 271 | */ |
| 272 | db_multi_exec( |
| 273 | "CREATE TEMP TABLE localfiles(x UNIQUE NOT NULL, u);" |
| 274 | ); |
| 275 | if( zCI ){ |
| 276 | Stmt ins; |
| 277 | ManifestFile *pFile; |
| 278 | ManifestFile *pPrev = 0; |
| 279 | int nPrev = 0; |
| 280 | int c; |
| 281 | |
| 282 | db_prepare(&ins, |
| 283 | "INSERT OR IGNORE INTO localfiles VALUES(pathelement(:x,0), :u)" |
| 284 | ); |
| 285 | manifest_file_rewind(pM); |
| 286 | while( (pFile = manifest_file_next(pM,0))!=0 ){ |
| 287 | if( nD>0 |
| 288 | && (fossil_strncmp(pFile->zName, zD, nD-1)!=0 |
| 289 | || pFile->zName[nD-1]!='/') |
| 290 | ){ |
| 291 | continue; |
| 292 | } |
| 293 | if( pPrev |
| 294 | && fossil_strncmp(&pFile->zName[nD],&pPrev->zName[nD],nPrev)==0 |
| 295 | && (pFile->zName[nD+nPrev]==0 || pFile->zName[nD+nPrev]=='/') |
| 296 | ){ |
| 297 | continue; |
| 298 | } |
| 299 | db_bind_text(&ins, ":x", &pFile->zName[nD]); |
| 300 | db_bind_text(&ins, ":u", pFile->zUuid); |
| 301 | db_step(&ins); |
| 302 | db_reset(&ins); |
| 303 | pPrev = pFile; |
| 304 | for(nPrev=0; (c=pPrev->zName[nD+nPrev]) && c!='/'; nPrev++){} |
| 305 | if( c=='/' ) nPrev++; |
| 306 | } |
| 307 | db_finalize(&ins); |
| 308 | }else if( zD ){ |
| 309 | db_multi_exec( |
| 310 | "INSERT OR IGNORE INTO localfiles" |
| 311 | " SELECT pathelement(name,%d), NULL FROM filename" |
| 312 | " WHERE name GLOB '%q/*'", |
| 313 | nD, zD |
| 314 | ); |
| 315 | }else{ |
| 316 | db_multi_exec( |
| 317 | "INSERT OR IGNORE INTO localfiles" |
| 318 | " SELECT pathelement(name,0), NULL FROM filename" |
| 319 | ); |
| 320 | } |
| 321 | |
| 322 | /* If the re=REGEXP query parameter is present, filter out names that |
| 323 | ** do not match the pattern */ |
| 324 | if( zRegexp ){ |
| @@ -1220,5 +1208,22 @@ | |
| 1220 | @ </table></div> |
| 1221 | db_finalize(&q1); |
| 1222 | db_finalize(&q2); |
| 1223 | style_finish_page(); |
| 1224 | } |
| 1225 |
| --- src/browse.c | |
| +++ src/browse.c | |
| @@ -271,54 +271,42 @@ | |
| 271 | */ |
| 272 | db_multi_exec( |
| 273 | "CREATE TEMP TABLE localfiles(x UNIQUE NOT NULL, u);" |
| 274 | ); |
| 275 | if( zCI ){ |
| 276 | /* Files in the specific checked given by zCI */ |
| 277 | if( zD ){ |
| 278 | db_multi_exec( |
| 279 | "INSERT OR IGNORE INTO localfiles" |
| 280 | " SELECT pathelement(filename,%d), uuid" |
| 281 | " FROM files_of_checkin(%Q)" |
| 282 | " WHERE filename GLOB '%q/*'", |
| 283 | nD, zCI, zD |
| 284 | ); |
| 285 | }else{ |
| 286 | db_multi_exec( |
| 287 | "INSERT OR IGNORE INTO localfiles" |
| 288 | " SELECT pathelement(filename,%d), uuid" |
| 289 | " FROM files_of_checkin(%Q)", |
| 290 | nD, zCI |
| 291 | ); |
| 292 | } |
| 293 | }else{ |
| 294 | /* All files across all check-ins */ |
| 295 | if( zD ){ |
| 296 | db_multi_exec( |
| 297 | "INSERT OR IGNORE INTO localfiles" |
| 298 | " SELECT pathelement(name,%d), NULL FROM filename" |
| 299 | " WHERE name GLOB '%q/*'", |
| 300 | nD, zD |
| 301 | ); |
| 302 | }else{ |
| 303 | db_multi_exec( |
| 304 | "INSERT OR IGNORE INTO localfiles" |
| 305 | " SELECT pathelement(name,0), NULL FROM filename" |
| 306 | ); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | /* If the re=REGEXP query parameter is present, filter out names that |
| 311 | ** do not match the pattern */ |
| 312 | if( zRegexp ){ |
| @@ -1220,5 +1208,22 @@ | |
| 1208 | @ </table></div> |
| 1209 | db_finalize(&q1); |
| 1210 | db_finalize(&q2); |
| 1211 | style_finish_page(); |
| 1212 | } |
| 1213 | |
| 1214 | /* |
| 1215 | ** WEBPAGE: files |
| 1216 | ** |
| 1217 | ** Show files as a flat table. If the ci=LABEL query parameter is provided, |
| 1218 | ** then show all the files in the specified check-in. Without the ci= query |
| 1219 | ** parameter show all files across all check-ins. |
| 1220 | ** |
| 1221 | ** Query parameters: |
| 1222 | ** |
| 1223 | ** name=PATH Directory to display. Optional |
| 1224 | ** ci=LABEL Show only files in this check-in. Optional. |
| 1225 | ** re=REGEXP Show only files matching REGEXP. Optional. |
| 1226 | */ |
| 1227 | void files_page(void){ |
| 1228 | return; |
| 1229 | } |
| 1230 |