Fossil SCM
If a command is "fossil ABC" and "ABC" is not a valid command name or prefix but "ABC" is the name of a repository file, then change the command to be "fossil ui ABC".
Commit
aad4c2485b706595be986bee1fc010a5bcddeb53db1a9526daf543d818fc7fc6
Parent
525e93dd5711f5d…
2 files changed
+41
+26
-1
+41
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -347,10 +347,50 @@ | ||
| 347 | 347 | } |
| 348 | 348 | free(zFN); |
| 349 | 349 | return rc; |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | +/* | |
| 353 | +** Return true (1) if zFilename seems like it seems like a valid | |
| 354 | +** repository database. | |
| 355 | +*/ | |
| 356 | +int file_is_repository(const char *zFilename){ | |
| 357 | + i64 sz; | |
| 358 | + sqlite3 *db = 0; | |
| 359 | + sqlite3_stmt *pStmt = 0; | |
| 360 | + int rc; | |
| 361 | + int i; | |
| 362 | + static const char *azReqTab[] = { | |
| 363 | + "blob", "delta", "rcvfrom", "user", "config" | |
| 364 | + }; | |
| 365 | + if( !file_isfile(zFilename, ExtFILE) ) return 0; | |
| 366 | + sz = file_size(zFilename, ExtFILE); | |
| 367 | + if( sz<35328 ) return 0; | |
| 368 | + if( sz%512!=0 ) return 0; | |
| 369 | + rc = sqlite3_open_v2(zFilename, &db, | |
| 370 | + SQLITE_OPEN_READWRITE, 0); | |
| 371 | + if( rc!=0 ) goto not_a_repo; | |
| 372 | + for(i=0; i<count(azReqTab); i++){ | |
| 373 | + if( sqlite3_table_column_metadata(db, "main", azReqTab[i],0,0,0,0,0,0) ){ | |
| 374 | + goto not_a_repo; | |
| 375 | + } | |
| 376 | + } | |
| 377 | + rc = sqlite3_prepare_v2(db, "SELECT 1 FROM config WHERE name='project-code'", | |
| 378 | + -1, &pStmt, 0); | |
| 379 | + if( rc ) goto not_a_repo; | |
| 380 | + rc = sqlite3_step(pStmt); | |
| 381 | + if( rc!=SQLITE_ROW ) goto not_a_repo; | |
| 382 | + sqlite3_finalize(pStmt); | |
| 383 | + sqlite3_close(db); | |
| 384 | + return 1; | |
| 385 | + | |
| 386 | +not_a_repo: | |
| 387 | + sqlite3_finalize(pStmt); | |
| 388 | + sqlite3_close(db); | |
| 389 | + return 0; | |
| 390 | +} | |
| 391 | + | |
| 352 | 392 | |
| 353 | 393 | /* |
| 354 | 394 | ** Wrapper around the access() system call. |
| 355 | 395 | */ |
| 356 | 396 | int file_access(const char *zFilename, int flags){ |
| @@ -1167,10 +1207,11 @@ | ||
| 1167 | 1207 | fossil_print(" file_isfile(RepoFILE) = %d\n", file_isfile(zPath,RepoFILE)); |
| 1168 | 1208 | fossil_print(" file_isfile_or_link = %d\n", file_isfile_or_link(zPath)); |
| 1169 | 1209 | fossil_print(" file_islink = %d\n", file_islink(zPath)); |
| 1170 | 1210 | fossil_print(" file_isexe(RepoFILE) = %d\n", file_isexe(zPath,RepoFILE)); |
| 1171 | 1211 | fossil_print(" file_isdir(RepoFILE) = %d\n", file_isdir(zPath,RepoFILE)); |
| 1212 | + fossil_print(" file_is_repository = %d\n", file_is_repository(zPath)); | |
| 1172 | 1213 | if( reset ) resetStat(); |
| 1173 | 1214 | } |
| 1174 | 1215 | |
| 1175 | 1216 | /* |
| 1176 | 1217 | ** COMMAND: test-file-environment |
| 1177 | 1218 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -347,10 +347,50 @@ | |
| 347 | } |
| 348 | free(zFN); |
| 349 | return rc; |
| 350 | } |
| 351 | |
| 352 | |
| 353 | /* |
| 354 | ** Wrapper around the access() system call. |
| 355 | */ |
| 356 | int file_access(const char *zFilename, int flags){ |
| @@ -1167,10 +1207,11 @@ | |
| 1167 | fossil_print(" file_isfile(RepoFILE) = %d\n", file_isfile(zPath,RepoFILE)); |
| 1168 | fossil_print(" file_isfile_or_link = %d\n", file_isfile_or_link(zPath)); |
| 1169 | fossil_print(" file_islink = %d\n", file_islink(zPath)); |
| 1170 | fossil_print(" file_isexe(RepoFILE) = %d\n", file_isexe(zPath,RepoFILE)); |
| 1171 | fossil_print(" file_isdir(RepoFILE) = %d\n", file_isdir(zPath,RepoFILE)); |
| 1172 | if( reset ) resetStat(); |
| 1173 | } |
| 1174 | |
| 1175 | /* |
| 1176 | ** COMMAND: test-file-environment |
| 1177 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -347,10 +347,50 @@ | |
| 347 | } |
| 348 | free(zFN); |
| 349 | return rc; |
| 350 | } |
| 351 | |
| 352 | /* |
| 353 | ** Return true (1) if zFilename seems like it seems like a valid |
| 354 | ** repository database. |
| 355 | */ |
| 356 | int file_is_repository(const char *zFilename){ |
| 357 | i64 sz; |
| 358 | sqlite3 *db = 0; |
| 359 | sqlite3_stmt *pStmt = 0; |
| 360 | int rc; |
| 361 | int i; |
| 362 | static const char *azReqTab[] = { |
| 363 | "blob", "delta", "rcvfrom", "user", "config" |
| 364 | }; |
| 365 | if( !file_isfile(zFilename, ExtFILE) ) return 0; |
| 366 | sz = file_size(zFilename, ExtFILE); |
| 367 | if( sz<35328 ) return 0; |
| 368 | if( sz%512!=0 ) return 0; |
| 369 | rc = sqlite3_open_v2(zFilename, &db, |
| 370 | SQLITE_OPEN_READWRITE, 0); |
| 371 | if( rc!=0 ) goto not_a_repo; |
| 372 | for(i=0; i<count(azReqTab); i++){ |
| 373 | if( sqlite3_table_column_metadata(db, "main", azReqTab[i],0,0,0,0,0,0) ){ |
| 374 | goto not_a_repo; |
| 375 | } |
| 376 | } |
| 377 | rc = sqlite3_prepare_v2(db, "SELECT 1 FROM config WHERE name='project-code'", |
| 378 | -1, &pStmt, 0); |
| 379 | if( rc ) goto not_a_repo; |
| 380 | rc = sqlite3_step(pStmt); |
| 381 | if( rc!=SQLITE_ROW ) goto not_a_repo; |
| 382 | sqlite3_finalize(pStmt); |
| 383 | sqlite3_close(db); |
| 384 | return 1; |
| 385 | |
| 386 | not_a_repo: |
| 387 | sqlite3_finalize(pStmt); |
| 388 | sqlite3_close(db); |
| 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | |
| 393 | /* |
| 394 | ** Wrapper around the access() system call. |
| 395 | */ |
| 396 | int file_access(const char *zFilename, int flags){ |
| @@ -1167,10 +1207,11 @@ | |
| 1207 | fossil_print(" file_isfile(RepoFILE) = %d\n", file_isfile(zPath,RepoFILE)); |
| 1208 | fossil_print(" file_isfile_or_link = %d\n", file_isfile_or_link(zPath)); |
| 1209 | fossil_print(" file_islink = %d\n", file_islink(zPath)); |
| 1210 | fossil_print(" file_isexe(RepoFILE) = %d\n", file_isexe(zPath,RepoFILE)); |
| 1211 | fossil_print(" file_isdir(RepoFILE) = %d\n", file_isdir(zPath,RepoFILE)); |
| 1212 | fossil_print(" file_is_repository = %d\n", file_is_repository(zPath)); |
| 1213 | if( reset ) resetStat(); |
| 1214 | } |
| 1215 | |
| 1216 | /* |
| 1217 | ** COMMAND: test-file-environment |
| 1218 |
+26
-1
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -782,11 +782,21 @@ | ||
| 782 | 782 | nNewArgc = g.argc+1; |
| 783 | 783 | zNewArgv[i+1] = 0; |
| 784 | 784 | } |
| 785 | 785 | g.argc = nNewArgc; |
| 786 | 786 | g.argv = zNewArgv; |
| 787 | - } | |
| 787 | +#if 0 | |
| 788 | + }else if( g.argc==2 && file_is_repository(g.argv[1]) ){ | |
| 789 | + char **zNewArgv = fossil_malloc( sizeof(char*)*4 ); | |
| 790 | + zNewArgv[0] = g.argv[0]; | |
| 791 | + zNewArgv[1] = "ui"; | |
| 792 | + zNewArgv[2] = g.argv[1]; | |
| 793 | + zNewArgv[3] = 0; | |
| 794 | + g.argc = 3; | |
| 795 | + g.argv = zNewArgv; | |
| 796 | +#endif | |
| 797 | + } | |
| 788 | 798 | zCmdName = g.argv[1]; |
| 789 | 799 | } |
| 790 | 800 | #ifndef _WIN32 |
| 791 | 801 | /* There is a bug in stunnel4 in which it sometimes starts up client |
| 792 | 802 | ** processes without first opening file descriptor 2 (standard error). |
| @@ -812,10 +822,25 @@ | ||
| 812 | 822 | } |
| 813 | 823 | } |
| 814 | 824 | #endif |
| 815 | 825 | g.zCmdName = zCmdName; |
| 816 | 826 | rc = dispatch_name_search(zCmdName, CMDFLAG_COMMAND|CMDFLAG_PREFIX, &pCmd); |
| 827 | + if( rc==1 && g.argc==2 && file_is_repository(g.argv[1]) ){ | |
| 828 | + /* If the command-line is "fossil ABC" and "ABC" is no a valid command, | |
| 829 | + ** but "ABC" is the name of a repository file, make the command be | |
| 830 | + ** "fossil ui ABC" instead. | |
| 831 | + */ | |
| 832 | + char **zNewArgv = fossil_malloc( sizeof(char*)*4 ); | |
| 833 | + zNewArgv[0] = g.argv[0]; | |
| 834 | + zNewArgv[1] = "ui"; | |
| 835 | + zNewArgv[2] = g.argv[1]; | |
| 836 | + zNewArgv[3] = 0; | |
| 837 | + g.argc = 3; | |
| 838 | + g.argv = zNewArgv; | |
| 839 | + g.zCmdName = zCmdName = "ui"; | |
| 840 | + rc = dispatch_name_search(zCmdName, CMDFLAG_COMMAND|CMDFLAG_PREFIX, &pCmd); | |
| 841 | + } | |
| 817 | 842 | if( rc==1 ){ |
| 818 | 843 | #ifdef FOSSIL_ENABLE_TH1_HOOKS |
| 819 | 844 | if( !g.isHTTP && !g.fNoThHook ){ |
| 820 | 845 | rc = Th_CommandHook(zCmdName, 0); |
| 821 | 846 | }else{ |
| 822 | 847 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -782,11 +782,21 @@ | |
| 782 | nNewArgc = g.argc+1; |
| 783 | zNewArgv[i+1] = 0; |
| 784 | } |
| 785 | g.argc = nNewArgc; |
| 786 | g.argv = zNewArgv; |
| 787 | } |
| 788 | zCmdName = g.argv[1]; |
| 789 | } |
| 790 | #ifndef _WIN32 |
| 791 | /* There is a bug in stunnel4 in which it sometimes starts up client |
| 792 | ** processes without first opening file descriptor 2 (standard error). |
| @@ -812,10 +822,25 @@ | |
| 812 | } |
| 813 | } |
| 814 | #endif |
| 815 | g.zCmdName = zCmdName; |
| 816 | rc = dispatch_name_search(zCmdName, CMDFLAG_COMMAND|CMDFLAG_PREFIX, &pCmd); |
| 817 | if( rc==1 ){ |
| 818 | #ifdef FOSSIL_ENABLE_TH1_HOOKS |
| 819 | if( !g.isHTTP && !g.fNoThHook ){ |
| 820 | rc = Th_CommandHook(zCmdName, 0); |
| 821 | }else{ |
| 822 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -782,11 +782,21 @@ | |
| 782 | nNewArgc = g.argc+1; |
| 783 | zNewArgv[i+1] = 0; |
| 784 | } |
| 785 | g.argc = nNewArgc; |
| 786 | g.argv = zNewArgv; |
| 787 | #if 0 |
| 788 | }else if( g.argc==2 && file_is_repository(g.argv[1]) ){ |
| 789 | char **zNewArgv = fossil_malloc( sizeof(char*)*4 ); |
| 790 | zNewArgv[0] = g.argv[0]; |
| 791 | zNewArgv[1] = "ui"; |
| 792 | zNewArgv[2] = g.argv[1]; |
| 793 | zNewArgv[3] = 0; |
| 794 | g.argc = 3; |
| 795 | g.argv = zNewArgv; |
| 796 | #endif |
| 797 | } |
| 798 | zCmdName = g.argv[1]; |
| 799 | } |
| 800 | #ifndef _WIN32 |
| 801 | /* There is a bug in stunnel4 in which it sometimes starts up client |
| 802 | ** processes without first opening file descriptor 2 (standard error). |
| @@ -812,10 +822,25 @@ | |
| 822 | } |
| 823 | } |
| 824 | #endif |
| 825 | g.zCmdName = zCmdName; |
| 826 | rc = dispatch_name_search(zCmdName, CMDFLAG_COMMAND|CMDFLAG_PREFIX, &pCmd); |
| 827 | if( rc==1 && g.argc==2 && file_is_repository(g.argv[1]) ){ |
| 828 | /* If the command-line is "fossil ABC" and "ABC" is no a valid command, |
| 829 | ** but "ABC" is the name of a repository file, make the command be |
| 830 | ** "fossil ui ABC" instead. |
| 831 | */ |
| 832 | char **zNewArgv = fossil_malloc( sizeof(char*)*4 ); |
| 833 | zNewArgv[0] = g.argv[0]; |
| 834 | zNewArgv[1] = "ui"; |
| 835 | zNewArgv[2] = g.argv[1]; |
| 836 | zNewArgv[3] = 0; |
| 837 | g.argc = 3; |
| 838 | g.argv = zNewArgv; |
| 839 | g.zCmdName = zCmdName = "ui"; |
| 840 | rc = dispatch_name_search(zCmdName, CMDFLAG_COMMAND|CMDFLAG_PREFIX, &pCmd); |
| 841 | } |
| 842 | if( rc==1 ){ |
| 843 | #ifdef FOSSIL_ENABLE_TH1_HOOKS |
| 844 | if( !g.isHTTP && !g.fNoThHook ){ |
| 845 | rc = Th_CommandHook(zCmdName, 0); |
| 846 | }else{ |
| 847 |