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.

ben 2011-05-28 09:15 versionable-settings
Commit 761a98a1ee390b928c7691793a7cac5b6f849ef9
1 file changed +19 -8
+19 -8
--- src/db.c
+++ src/db.c
@@ -1395,33 +1395,44 @@
13951395
13961396
/*
13971397
** Get a potentially versioned setting - either from .fossil-settings/<name>
13981398
*/
13991399
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;
14011403
if( db_open_local() ){
1402
- /* See if there's a versioned setting */
14031404
Blob versionedPathname;
14041405
blob_zero(&versionedPathname);
14051406
blob_appendf(&versionedPathname, "%s/.fossil-settings/%s", g.zLocalRoot, zName);
14061407
char *zVersionedPathname = blob_str(&versionedPathname);
1407
- if( file_size(zVersionedPathname) >= 0 ){
1408
+ if( file_size(zVersionedPathname)>=0 ){
14081409
/* File exists, and contains the value for this setting. Load from the file. */
14091410
Blob setting;
14101411
blob_zero(&setting);
14111412
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));
14131415
}
14141416
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
+ }
14151422
}
14161423
blob_reset(&versionedPathname);
14171424
}
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);
14201431
}
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;
14231434
}
14241435
int db_get_versionable_setting_boolean(const char *zName, int dflt){
14251436
char *zVal = db_get_versionable_setting(zName, dflt ? "on" : "off");
14261437
if( is_truth(zVal) ) return 1;
14271438
if( is_false(zVal) ) return 0;
14281439
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button