Fossil SCM
Fix db_open_local() fonction so it find the local checkout database on "/". It was working inconsistently depending what was the current directory. ** Even if fossil is not the right tool to version files on the root of the system, I found it very usefull to track what file change on my system Tested on Linux only for now..
Commit
be993c47d5dd6d319d6317f917446f6691106d63
Parent
927cacb3530c67e…
1 file changed
+13
-4
M
src/db.c
+13
-4
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -934,40 +934,49 @@ | ||
| 934 | 934 | ** |
| 935 | 935 | ** This routine always opens the user database regardless of whether or |
| 936 | 936 | ** not the repository database is found. If the _FOSSIL_ or .fslckout file |
| 937 | 937 | ** is found, it is attached to the open database connection too. |
| 938 | 938 | */ |
| 939 | +/* #define DBG_CHECKOUT_ON_ROOT_FIX 1 */ | |
| 939 | 940 | int db_open_local(const char *zDbName){ |
| 940 | 941 | int i, n; |
| 941 | 942 | char zPwd[2000]; |
| 942 | 943 | static const char aDbName[][10] = { "_FOSSIL_", ".fslckout", ".fos" }; |
| 943 | 944 | |
| 944 | 945 | if( g.localOpen) return 1; |
| 945 | 946 | file_getcwd(zPwd, sizeof(zPwd)-20); |
| 946 | 947 | n = strlen(zPwd); |
| 947 | - if( n==1 && zPwd[0]=='/' ) zPwd[0] = '.'; | |
| 948 | +#ifdef DBG_CHECKOUT_ON_ROOT_FIX | |
| 949 | + fossil_trace("---> DEBUG: zPwd: %s, n: %d\n", zPwd, n); | |
| 950 | +#endif | |
| 948 | 951 | while( n>0 ){ |
| 949 | 952 | for(i=0; i<count(aDbName); i++){ |
| 950 | 953 | sqlite3_snprintf(sizeof(zPwd)-n, &zPwd[n], "/%s", aDbName[i]); |
| 951 | 954 | if( isValidLocalDb(zPwd) ){ |
| 952 | 955 | /* Found a valid checkout database file */ |
| 953 | 956 | zPwd[n] = 0; |
| 954 | - while( n>1 && zPwd[n-1]=='/' ){ | |
| 957 | + while( n>0 && zPwd[n-1]=='/' ){ | |
| 955 | 958 | n--; |
| 956 | 959 | zPwd[n] = 0; |
| 957 | 960 | } |
| 958 | 961 | g.zLocalRoot = mprintf("%s/", zPwd); |
| 962 | +#ifdef DBG_CHECKOUT_ON_ROOT_FIX | |
| 963 | + fossil_trace("---> DEBUG: g.zLocalRoot: %s\n", g.zLocalRoot); | |
| 964 | +#endif | |
| 959 | 965 | g.localOpen = 1; |
| 960 | 966 | db_open_config(0); |
| 961 | 967 | db_open_repository(zDbName); |
| 962 | 968 | return 1; |
| 963 | 969 | } |
| 964 | 970 | } |
| 965 | 971 | n--; |
| 966 | - while( n>0 && zPwd[n]!='/' ){ n--; } | |
| 967 | - while( n>0 && zPwd[n-1]=='/' ){ n--; } | |
| 972 | + while( n>1 && zPwd[n]!='/' ){ n--; } | |
| 973 | + while( n>1 && zPwd[n-1]=='/' ){ n--; } | |
| 968 | 974 | zPwd[n] = 0; |
| 975 | +#ifdef DBG_CHECKOUT_ON_ROOT_FIX | |
| 976 | + fossil_trace("---> DEBUG: next zPwd: %s, n: %d\n", zPwd, n); | |
| 977 | +#endif | |
| 969 | 978 | } |
| 970 | 979 | |
| 971 | 980 | /* A checkout database file could not be found */ |
| 972 | 981 | return 0; |
| 973 | 982 | } |
| 974 | 983 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -934,40 +934,49 @@ | |
| 934 | ** |
| 935 | ** This routine always opens the user database regardless of whether or |
| 936 | ** not the repository database is found. If the _FOSSIL_ or .fslckout file |
| 937 | ** is found, it is attached to the open database connection too. |
| 938 | */ |
| 939 | int db_open_local(const char *zDbName){ |
| 940 | int i, n; |
| 941 | char zPwd[2000]; |
| 942 | static const char aDbName[][10] = { "_FOSSIL_", ".fslckout", ".fos" }; |
| 943 | |
| 944 | if( g.localOpen) return 1; |
| 945 | file_getcwd(zPwd, sizeof(zPwd)-20); |
| 946 | n = strlen(zPwd); |
| 947 | if( n==1 && zPwd[0]=='/' ) zPwd[0] = '.'; |
| 948 | while( n>0 ){ |
| 949 | for(i=0; i<count(aDbName); i++){ |
| 950 | sqlite3_snprintf(sizeof(zPwd)-n, &zPwd[n], "/%s", aDbName[i]); |
| 951 | if( isValidLocalDb(zPwd) ){ |
| 952 | /* Found a valid checkout database file */ |
| 953 | zPwd[n] = 0; |
| 954 | while( n>1 && zPwd[n-1]=='/' ){ |
| 955 | n--; |
| 956 | zPwd[n] = 0; |
| 957 | } |
| 958 | g.zLocalRoot = mprintf("%s/", zPwd); |
| 959 | g.localOpen = 1; |
| 960 | db_open_config(0); |
| 961 | db_open_repository(zDbName); |
| 962 | return 1; |
| 963 | } |
| 964 | } |
| 965 | n--; |
| 966 | while( n>0 && zPwd[n]!='/' ){ n--; } |
| 967 | while( n>0 && zPwd[n-1]=='/' ){ n--; } |
| 968 | zPwd[n] = 0; |
| 969 | } |
| 970 | |
| 971 | /* A checkout database file could not be found */ |
| 972 | return 0; |
| 973 | } |
| 974 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -934,40 +934,49 @@ | |
| 934 | ** |
| 935 | ** This routine always opens the user database regardless of whether or |
| 936 | ** not the repository database is found. If the _FOSSIL_ or .fslckout file |
| 937 | ** is found, it is attached to the open database connection too. |
| 938 | */ |
| 939 | /* #define DBG_CHECKOUT_ON_ROOT_FIX 1 */ |
| 940 | int db_open_local(const char *zDbName){ |
| 941 | int i, n; |
| 942 | char zPwd[2000]; |
| 943 | static const char aDbName[][10] = { "_FOSSIL_", ".fslckout", ".fos" }; |
| 944 | |
| 945 | if( g.localOpen) return 1; |
| 946 | file_getcwd(zPwd, sizeof(zPwd)-20); |
| 947 | n = strlen(zPwd); |
| 948 | #ifdef DBG_CHECKOUT_ON_ROOT_FIX |
| 949 | fossil_trace("---> DEBUG: zPwd: %s, n: %d\n", zPwd, n); |
| 950 | #endif |
| 951 | while( n>0 ){ |
| 952 | for(i=0; i<count(aDbName); i++){ |
| 953 | sqlite3_snprintf(sizeof(zPwd)-n, &zPwd[n], "/%s", aDbName[i]); |
| 954 | if( isValidLocalDb(zPwd) ){ |
| 955 | /* Found a valid checkout database file */ |
| 956 | zPwd[n] = 0; |
| 957 | while( n>0 && zPwd[n-1]=='/' ){ |
| 958 | n--; |
| 959 | zPwd[n] = 0; |
| 960 | } |
| 961 | g.zLocalRoot = mprintf("%s/", zPwd); |
| 962 | #ifdef DBG_CHECKOUT_ON_ROOT_FIX |
| 963 | fossil_trace("---> DEBUG: g.zLocalRoot: %s\n", g.zLocalRoot); |
| 964 | #endif |
| 965 | g.localOpen = 1; |
| 966 | db_open_config(0); |
| 967 | db_open_repository(zDbName); |
| 968 | return 1; |
| 969 | } |
| 970 | } |
| 971 | n--; |
| 972 | while( n>1 && zPwd[n]!='/' ){ n--; } |
| 973 | while( n>1 && zPwd[n-1]=='/' ){ n--; } |
| 974 | zPwd[n] = 0; |
| 975 | #ifdef DBG_CHECKOUT_ON_ROOT_FIX |
| 976 | fossil_trace("---> DEBUG: next zPwd: %s, n: %d\n", zPwd, n); |
| 977 | #endif |
| 978 | } |
| 979 | |
| 980 | /* A checkout database file could not be found */ |
| 981 | return 0; |
| 982 | } |
| 983 |