Fossil SCM
Use file_tree_name(), not file_canonical_name(), as in Richard's example [c8253f4066] for "fossil ls|changes|status" too. Advantage: 1) a panic when an out-of-tree filename is given on the command line 2) shortcut when any command line argument is "." (or resolves to the top of the tree in any other way)
Commit
ae0124439685c1102a904ce08d08afc23e062db3
Parent
8db6f9877fec9ae…
1 file changed
+25
-21
+25
-21
| --- src/checkin.c | ||
| +++ src/checkin.c | ||
| @@ -40,25 +40,27 @@ | ||
| 40 | 40 | Stmt q; |
| 41 | 41 | int nPrefix = strlen(zPrefix); |
| 42 | 42 | int nErr = 0; |
| 43 | 43 | Blob rewrittenPathname; |
| 44 | 44 | Blob where; |
| 45 | - const char *zTreeName; | |
| 46 | - int i, nRoot; | |
| 45 | + const char *zName; | |
| 46 | + int i; | |
| 47 | 47 | |
| 48 | 48 | blob_zero(&where); |
| 49 | - nRoot = (int)strlen(g.zLocalRoot); | |
| 50 | - blob_zero(&where); | |
| 51 | 49 | for(i=2; i<g.argc; i++) { |
| 52 | 50 | Blob fname; |
| 53 | - file_canonical_name(g.argv[i], &fname, 0); | |
| 54 | - zTreeName = blob_str(&fname)+nRoot; | |
| 51 | + file_tree_name(g.argv[i], &fname, 1); | |
| 52 | + zName = blob_str(&fname); | |
| 53 | + if( fossil_strcmp(zName, ".")==0 ) { | |
| 54 | + blob_reset(&where); | |
| 55 | + break; | |
| 56 | + } | |
| 55 | 57 | blob_appendf(&where, " %s (pathname=%Q %s) " |
| 56 | 58 | "OR (pathname>'%q/' %s AND pathname<'%q0' %s)", |
| 57 | - (blob_size(&where)>0) ? "OR" : "AND", zTreeName, | |
| 58 | - filename_collation(), zTreeName, filename_collation(), | |
| 59 | - zTreeName, filename_collation()); | |
| 59 | + (blob_size(&where)>0) ? "OR" : "AND", zName, | |
| 60 | + filename_collation(), zName, filename_collation(), | |
| 61 | + zName, filename_collation()); | |
| 60 | 62 | } |
| 61 | 63 | |
| 62 | 64 | db_prepare(&q, |
| 63 | 65 | "SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)" |
| 64 | 66 | " FROM vfile " |
| @@ -258,11 +260,11 @@ | ||
| 258 | 260 | int verboseFlag; |
| 259 | 261 | int showAge; |
| 260 | 262 | char *zOrderBy = "pathname"; |
| 261 | 263 | Blob where; |
| 262 | 264 | int i; |
| 263 | - int nRoot; | |
| 265 | + const char *zName; | |
| 264 | 266 | |
| 265 | 267 | verboseFlag = find_option("verbose","v", 0)!=0; |
| 266 | 268 | if( !verboseFlag ){ |
| 267 | 269 | verboseFlag = find_option("l","l", 0)!=0; /* deprecated */ |
| 268 | 270 | } |
| @@ -276,21 +278,23 @@ | ||
| 276 | 278 | zOrderBy = "mtime DESC"; |
| 277 | 279 | } |
| 278 | 280 | } |
| 279 | 281 | verify_all_options(); |
| 280 | 282 | blob_zero(&where); |
| 281 | - nRoot = (int)strlen(g.zLocalRoot); | |
| 282 | 283 | for(i=2; i<g.argc; i++){ |
| 283 | 284 | Blob fname; |
| 284 | - const char *zTreeName; | |
| 285 | - file_canonical_name(g.argv[i], &fname, 0); | |
| 286 | - zTreeName = blob_str(&fname)+nRoot; | |
| 285 | + file_tree_name(g.argv[i], &fname, 1); | |
| 286 | + zName = blob_str(&fname); | |
| 287 | + if( fossil_strcmp(zName, ".")==0 ) { | |
| 288 | + blob_reset(&where); | |
| 289 | + break; | |
| 290 | + } | |
| 287 | 291 | blob_appendf(&where, " %s (pathname=%Q %s) " |
| 288 | 292 | "OR (pathname>'%q/' %s AND pathname<'%q0' %s)", |
| 289 | - (blob_size(&where)>0) ? "OR" : "WHERE", zTreeName, | |
| 290 | - filename_collation(), zTreeName, filename_collation(), | |
| 291 | - zTreeName, filename_collation()); | |
| 293 | + (blob_size(&where)>0) ? "OR" : "WHERE", zName, | |
| 294 | + filename_collation(), zName, filename_collation(), | |
| 295 | + zName, filename_collation()); | |
| 292 | 296 | } |
| 293 | 297 | vfile_check_signature(vid, 0); |
| 294 | 298 | if( showAge ){ |
| 295 | 299 | db_prepare(&q, |
| 296 | 300 | "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0)," |
| @@ -338,12 +342,12 @@ | ||
| 338 | 342 | } |
| 339 | 343 | db_finalize(&q); |
| 340 | 344 | } |
| 341 | 345 | |
| 342 | 346 | /* |
| 343 | -** Create a TEMP table named SFILE and add all unmanaged files named on the command-line | |
| 344 | -** to that table. If directories are named, then add all unmanged files contained | |
| 347 | +** Create a TEMP table named SFILE and add all unmanaged files named on the command-line | |
| 348 | +** to that table. If directories are named, then add all unmanaged files contained | |
| 345 | 349 | ** underneath those directories. If there are no files or directories named on the |
| 346 | 350 | ** command-line, then add all unmanaged files anywhere in the checkout. |
| 347 | 351 | */ |
| 348 | 352 | static void locate_unmanaged_files( |
| 349 | 353 | int argc, /* Number of command-line arguments to examine */ |
| @@ -371,13 +375,13 @@ | ||
| 371 | 375 | zName = blob_str(&name); |
| 372 | 376 | isDir = file_wd_isdir(zName); |
| 373 | 377 | if( isDir==1 ){ |
| 374 | 378 | vfile_scan(&name, nRoot-1, scanFlags, pIgnore1, pIgnore2); |
| 375 | 379 | }else if( isDir==0 ){ |
| 376 | - fossil_warning("not found: %s", zName); | |
| 380 | + fossil_warning("not found: %s", &zName[nRoot]); | |
| 377 | 381 | }else if( file_access(zName, R_OK) ){ |
| 378 | - fossil_fatal("cannot open %s", zName); | |
| 382 | + fossil_fatal("cannot open %s", &zName[nRoot]); | |
| 379 | 383 | }else{ |
| 380 | 384 | db_multi_exec( |
| 381 | 385 | "INSERT OR IGNORE INTO sfile(x) VALUES(%Q)", |
| 382 | 386 | &zName[nRoot] |
| 383 | 387 | ); |
| 384 | 388 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -40,25 +40,27 @@ | |
| 40 | Stmt q; |
| 41 | int nPrefix = strlen(zPrefix); |
| 42 | int nErr = 0; |
| 43 | Blob rewrittenPathname; |
| 44 | Blob where; |
| 45 | const char *zTreeName; |
| 46 | int i, nRoot; |
| 47 | |
| 48 | blob_zero(&where); |
| 49 | nRoot = (int)strlen(g.zLocalRoot); |
| 50 | blob_zero(&where); |
| 51 | for(i=2; i<g.argc; i++) { |
| 52 | Blob fname; |
| 53 | file_canonical_name(g.argv[i], &fname, 0); |
| 54 | zTreeName = blob_str(&fname)+nRoot; |
| 55 | blob_appendf(&where, " %s (pathname=%Q %s) " |
| 56 | "OR (pathname>'%q/' %s AND pathname<'%q0' %s)", |
| 57 | (blob_size(&where)>0) ? "OR" : "AND", zTreeName, |
| 58 | filename_collation(), zTreeName, filename_collation(), |
| 59 | zTreeName, filename_collation()); |
| 60 | } |
| 61 | |
| 62 | db_prepare(&q, |
| 63 | "SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)" |
| 64 | " FROM vfile " |
| @@ -258,11 +260,11 @@ | |
| 258 | int verboseFlag; |
| 259 | int showAge; |
| 260 | char *zOrderBy = "pathname"; |
| 261 | Blob where; |
| 262 | int i; |
| 263 | int nRoot; |
| 264 | |
| 265 | verboseFlag = find_option("verbose","v", 0)!=0; |
| 266 | if( !verboseFlag ){ |
| 267 | verboseFlag = find_option("l","l", 0)!=0; /* deprecated */ |
| 268 | } |
| @@ -276,21 +278,23 @@ | |
| 276 | zOrderBy = "mtime DESC"; |
| 277 | } |
| 278 | } |
| 279 | verify_all_options(); |
| 280 | blob_zero(&where); |
| 281 | nRoot = (int)strlen(g.zLocalRoot); |
| 282 | for(i=2; i<g.argc; i++){ |
| 283 | Blob fname; |
| 284 | const char *zTreeName; |
| 285 | file_canonical_name(g.argv[i], &fname, 0); |
| 286 | zTreeName = blob_str(&fname)+nRoot; |
| 287 | blob_appendf(&where, " %s (pathname=%Q %s) " |
| 288 | "OR (pathname>'%q/' %s AND pathname<'%q0' %s)", |
| 289 | (blob_size(&where)>0) ? "OR" : "WHERE", zTreeName, |
| 290 | filename_collation(), zTreeName, filename_collation(), |
| 291 | zTreeName, filename_collation()); |
| 292 | } |
| 293 | vfile_check_signature(vid, 0); |
| 294 | if( showAge ){ |
| 295 | db_prepare(&q, |
| 296 | "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0)," |
| @@ -338,12 +342,12 @@ | |
| 338 | } |
| 339 | db_finalize(&q); |
| 340 | } |
| 341 | |
| 342 | /* |
| 343 | ** Create a TEMP table named SFILE and add all unmanaged files named on the command-line |
| 344 | ** to that table. If directories are named, then add all unmanged files contained |
| 345 | ** underneath those directories. If there are no files or directories named on the |
| 346 | ** command-line, then add all unmanaged files anywhere in the checkout. |
| 347 | */ |
| 348 | static void locate_unmanaged_files( |
| 349 | int argc, /* Number of command-line arguments to examine */ |
| @@ -371,13 +375,13 @@ | |
| 371 | zName = blob_str(&name); |
| 372 | isDir = file_wd_isdir(zName); |
| 373 | if( isDir==1 ){ |
| 374 | vfile_scan(&name, nRoot-1, scanFlags, pIgnore1, pIgnore2); |
| 375 | }else if( isDir==0 ){ |
| 376 | fossil_warning("not found: %s", zName); |
| 377 | }else if( file_access(zName, R_OK) ){ |
| 378 | fossil_fatal("cannot open %s", zName); |
| 379 | }else{ |
| 380 | db_multi_exec( |
| 381 | "INSERT OR IGNORE INTO sfile(x) VALUES(%Q)", |
| 382 | &zName[nRoot] |
| 383 | ); |
| 384 |
| --- src/checkin.c | |
| +++ src/checkin.c | |
| @@ -40,25 +40,27 @@ | |
| 40 | Stmt q; |
| 41 | int nPrefix = strlen(zPrefix); |
| 42 | int nErr = 0; |
| 43 | Blob rewrittenPathname; |
| 44 | Blob where; |
| 45 | const char *zName; |
| 46 | int i; |
| 47 | |
| 48 | blob_zero(&where); |
| 49 | for(i=2; i<g.argc; i++) { |
| 50 | Blob fname; |
| 51 | file_tree_name(g.argv[i], &fname, 1); |
| 52 | zName = blob_str(&fname); |
| 53 | if( fossil_strcmp(zName, ".")==0 ) { |
| 54 | blob_reset(&where); |
| 55 | break; |
| 56 | } |
| 57 | blob_appendf(&where, " %s (pathname=%Q %s) " |
| 58 | "OR (pathname>'%q/' %s AND pathname<'%q0' %s)", |
| 59 | (blob_size(&where)>0) ? "OR" : "AND", zName, |
| 60 | filename_collation(), zName, filename_collation(), |
| 61 | zName, filename_collation()); |
| 62 | } |
| 63 | |
| 64 | db_prepare(&q, |
| 65 | "SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)" |
| 66 | " FROM vfile " |
| @@ -258,11 +260,11 @@ | |
| 260 | int verboseFlag; |
| 261 | int showAge; |
| 262 | char *zOrderBy = "pathname"; |
| 263 | Blob where; |
| 264 | int i; |
| 265 | const char *zName; |
| 266 | |
| 267 | verboseFlag = find_option("verbose","v", 0)!=0; |
| 268 | if( !verboseFlag ){ |
| 269 | verboseFlag = find_option("l","l", 0)!=0; /* deprecated */ |
| 270 | } |
| @@ -276,21 +278,23 @@ | |
| 278 | zOrderBy = "mtime DESC"; |
| 279 | } |
| 280 | } |
| 281 | verify_all_options(); |
| 282 | blob_zero(&where); |
| 283 | for(i=2; i<g.argc; i++){ |
| 284 | Blob fname; |
| 285 | file_tree_name(g.argv[i], &fname, 1); |
| 286 | zName = blob_str(&fname); |
| 287 | if( fossil_strcmp(zName, ".")==0 ) { |
| 288 | blob_reset(&where); |
| 289 | break; |
| 290 | } |
| 291 | blob_appendf(&where, " %s (pathname=%Q %s) " |
| 292 | "OR (pathname>'%q/' %s AND pathname<'%q0' %s)", |
| 293 | (blob_size(&where)>0) ? "OR" : "WHERE", zName, |
| 294 | filename_collation(), zName, filename_collation(), |
| 295 | zName, filename_collation()); |
| 296 | } |
| 297 | vfile_check_signature(vid, 0); |
| 298 | if( showAge ){ |
| 299 | db_prepare(&q, |
| 300 | "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0)," |
| @@ -338,12 +342,12 @@ | |
| 342 | } |
| 343 | db_finalize(&q); |
| 344 | } |
| 345 | |
| 346 | /* |
| 347 | ** Create a TEMP table named SFILE and add all unmanaged files named on the command-line |
| 348 | ** to that table. If directories are named, then add all unmanaged files contained |
| 349 | ** underneath those directories. If there are no files or directories named on the |
| 350 | ** command-line, then add all unmanaged files anywhere in the checkout. |
| 351 | */ |
| 352 | static void locate_unmanaged_files( |
| 353 | int argc, /* Number of command-line arguments to examine */ |
| @@ -371,13 +375,13 @@ | |
| 375 | zName = blob_str(&name); |
| 376 | isDir = file_wd_isdir(zName); |
| 377 | if( isDir==1 ){ |
| 378 | vfile_scan(&name, nRoot-1, scanFlags, pIgnore1, pIgnore2); |
| 379 | }else if( isDir==0 ){ |
| 380 | fossil_warning("not found: %s", &zName[nRoot]); |
| 381 | }else if( file_access(zName, R_OK) ){ |
| 382 | fossil_fatal("cannot open %s", &zName[nRoot]); |
| 383 | }else{ |
| 384 | db_multi_exec( |
| 385 | "INSERT OR IGNORE INTO sfile(x) VALUES(%Q)", |
| 386 | &zName[nRoot] |
| 387 | ); |
| 388 |