Fossil SCM
Warn when there's a versioned and non-versioned value for a setting, and allow this warning to be silenced. Trim whitespace from settings loaded from files.
Commit
761a98a1ee390b928c7691793a7cac5b6f849ef9
Parent
9c915adb0a3d84c…
1 file changed
+19
-8
M
src/db.c
+19
-8
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -1395,33 +1395,44 @@ | ||
| 1395 | 1395 | |
| 1396 | 1396 | /* |
| 1397 | 1397 | ** Get a potentially versioned setting - either from .fossil-settings/<name> |
| 1398 | 1398 | */ |
| 1399 | 1399 | char *db_get_versionable_setting(const char *zName, char *zDefault){ |
| 1400 | - char *s = 0; | |
| 1400 | + /* Attempt to load the versioned setting from a checked out file */ | |
| 1401 | + char *zVersionedSetting = 0; | |
| 1402 | + int noWarn = 0; | |
| 1401 | 1403 | if( db_open_local() ){ |
| 1402 | - /* See if there's a versioned setting */ | |
| 1403 | 1404 | Blob versionedPathname; |
| 1404 | 1405 | blob_zero(&versionedPathname); |
| 1405 | 1406 | blob_appendf(&versionedPathname, "%s/.fossil-settings/%s", g.zLocalRoot, zName); |
| 1406 | 1407 | char *zVersionedPathname = blob_str(&versionedPathname); |
| 1407 | - if( file_size(zVersionedPathname) >= 0 ){ | |
| 1408 | + if( file_size(zVersionedPathname)>=0 ){ | |
| 1408 | 1409 | /* File exists, and contains the value for this setting. Load from the file. */ |
| 1409 | 1410 | Blob setting; |
| 1410 | 1411 | blob_zero(&setting); |
| 1411 | 1412 | if( blob_read_from_file(&setting, zVersionedPathname) >= 0 ){ |
| 1412 | - s = strdup(blob_str(&setting)); | |
| 1413 | + blob_trim(&setting); /* Avoid non-obvious problems with line endings on boolean properties */ | |
| 1414 | + zVersionedSetting = strdup(blob_str(&setting)); | |
| 1413 | 1415 | } |
| 1414 | 1416 | blob_reset(&setting); |
| 1417 | + /* See if there's a no-warn flag */ | |
| 1418 | + blob_append(&versionedPathname, ".no-warn", -1); | |
| 1419 | + if( file_size(blob_str(&versionedPathname))>=0 ){ | |
| 1420 | + noWarn = 1; | |
| 1421 | + } | |
| 1415 | 1422 | } |
| 1416 | 1423 | blob_reset(&versionedPathname); |
| 1417 | 1424 | } |
| 1418 | - if( s != 0 ){ | |
| 1419 | - return s; | |
| 1425 | + /* Load the normal, non-versioned setting */ | |
| 1426 | + char *zSetting = db_get(zName, zDefault); | |
| 1427 | + /* Display a warning? */ | |
| 1428 | + if( zVersionedSetting!=0 && zSetting!=0 && zSetting[0]!='\0' && zSetting!=zDefault && !noWarn ){ | |
| 1429 | + /* There's a versioned setting, and a non-versioned setting. Tell the user about the conflict */ | |
| 1430 | + fossil_warning("Setting %s has both versioned and non-versioned values: using versioned value from file .fossil-settings/%s (To silence this warning, either create an empty file named .fossil-settings/%s.no-warn or delete the non-versioned setting with \"fossil unset %s\")", zName, zName, zName, zName); | |
| 1420 | 1431 | } |
| 1421 | - /* Fall back to settings in the database */ | |
| 1422 | - return db_get(zName, zDefault); | |
| 1432 | + /* Prefer the versioned setting */ | |
| 1433 | + return ( zVersionedSetting!=0 ) ? zVersionedSetting : zSetting; | |
| 1423 | 1434 | } |
| 1424 | 1435 | int db_get_versionable_setting_boolean(const char *zName, int dflt){ |
| 1425 | 1436 | char *zVal = db_get_versionable_setting(zName, dflt ? "on" : "off"); |
| 1426 | 1437 | if( is_truth(zVal) ) return 1; |
| 1427 | 1438 | if( is_false(zVal) ) return 0; |
| 1428 | 1439 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -1395,33 +1395,44 @@ | |
| 1395 | |
| 1396 | /* |
| 1397 | ** Get a potentially versioned setting - either from .fossil-settings/<name> |
| 1398 | */ |
| 1399 | char *db_get_versionable_setting(const char *zName, char *zDefault){ |
| 1400 | char *s = 0; |
| 1401 | if( db_open_local() ){ |
| 1402 | /* See if there's a versioned setting */ |
| 1403 | Blob versionedPathname; |
| 1404 | blob_zero(&versionedPathname); |
| 1405 | blob_appendf(&versionedPathname, "%s/.fossil-settings/%s", g.zLocalRoot, zName); |
| 1406 | char *zVersionedPathname = blob_str(&versionedPathname); |
| 1407 | if( file_size(zVersionedPathname) >= 0 ){ |
| 1408 | /* File exists, and contains the value for this setting. Load from the file. */ |
| 1409 | Blob setting; |
| 1410 | blob_zero(&setting); |
| 1411 | if( blob_read_from_file(&setting, zVersionedPathname) >= 0 ){ |
| 1412 | s = strdup(blob_str(&setting)); |
| 1413 | } |
| 1414 | blob_reset(&setting); |
| 1415 | } |
| 1416 | blob_reset(&versionedPathname); |
| 1417 | } |
| 1418 | if( s != 0 ){ |
| 1419 | return s; |
| 1420 | } |
| 1421 | /* Fall back to settings in the database */ |
| 1422 | return db_get(zName, zDefault); |
| 1423 | } |
| 1424 | int db_get_versionable_setting_boolean(const char *zName, int dflt){ |
| 1425 | char *zVal = db_get_versionable_setting(zName, dflt ? "on" : "off"); |
| 1426 | if( is_truth(zVal) ) return 1; |
| 1427 | if( is_false(zVal) ) return 0; |
| 1428 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -1395,33 +1395,44 @@ | |
| 1395 | |
| 1396 | /* |
| 1397 | ** Get a potentially versioned setting - either from .fossil-settings/<name> |
| 1398 | */ |
| 1399 | char *db_get_versionable_setting(const char *zName, char *zDefault){ |
| 1400 | /* Attempt to load the versioned setting from a checked out file */ |
| 1401 | char *zVersionedSetting = 0; |
| 1402 | int noWarn = 0; |
| 1403 | if( db_open_local() ){ |
| 1404 | Blob versionedPathname; |
| 1405 | blob_zero(&versionedPathname); |
| 1406 | blob_appendf(&versionedPathname, "%s/.fossil-settings/%s", g.zLocalRoot, zName); |
| 1407 | char *zVersionedPathname = blob_str(&versionedPathname); |
| 1408 | if( file_size(zVersionedPathname)>=0 ){ |
| 1409 | /* File exists, and contains the value for this setting. Load from the file. */ |
| 1410 | Blob setting; |
| 1411 | blob_zero(&setting); |
| 1412 | if( blob_read_from_file(&setting, zVersionedPathname) >= 0 ){ |
| 1413 | blob_trim(&setting); /* Avoid non-obvious problems with line endings on boolean properties */ |
| 1414 | zVersionedSetting = strdup(blob_str(&setting)); |
| 1415 | } |
| 1416 | blob_reset(&setting); |
| 1417 | /* See if there's a no-warn flag */ |
| 1418 | blob_append(&versionedPathname, ".no-warn", -1); |
| 1419 | if( file_size(blob_str(&versionedPathname))>=0 ){ |
| 1420 | noWarn = 1; |
| 1421 | } |
| 1422 | } |
| 1423 | blob_reset(&versionedPathname); |
| 1424 | } |
| 1425 | /* Load the normal, non-versioned setting */ |
| 1426 | char *zSetting = db_get(zName, zDefault); |
| 1427 | /* Display a warning? */ |
| 1428 | if( zVersionedSetting!=0 && zSetting!=0 && zSetting[0]!='\0' && zSetting!=zDefault && !noWarn ){ |
| 1429 | /* There's a versioned setting, and a non-versioned setting. Tell the user about the conflict */ |
| 1430 | fossil_warning("Setting %s has both versioned and non-versioned values: using versioned value from file .fossil-settings/%s (To silence this warning, either create an empty file named .fossil-settings/%s.no-warn or delete the non-versioned setting with \"fossil unset %s\")", zName, zName, zName, zName); |
| 1431 | } |
| 1432 | /* Prefer the versioned setting */ |
| 1433 | return ( zVersionedSetting!=0 ) ? zVersionedSetting : zSetting; |
| 1434 | } |
| 1435 | int db_get_versionable_setting_boolean(const char *zName, int dflt){ |
| 1436 | char *zVal = db_get_versionable_setting(zName, dflt ? "on" : "off"); |
| 1437 | if( is_truth(zVal) ) return 1; |
| 1438 | if( is_false(zVal) ) return 0; |
| 1439 |