Fossil SCM
Add db_get_versionable_setting() for implementing 'versionable settings', which is like db_get() except will prefer to read the value from .fossil-settings/NAME in the checked out source, rather than the database.
Commit
09e52f0df7bab794159322def51e43c71debf9b7
Parent
3db75c4803c934f…
1 file changed
+36
M
src/db.c
+36
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -1390,10 +1390,46 @@ | ||
| 1390 | 1390 | sqlite3 *dbTemp = g.db; |
| 1391 | 1391 | g.db = g.dbConfig; |
| 1392 | 1392 | g.dbConfig = dbTemp; |
| 1393 | 1393 | } |
| 1394 | 1394 | } |
| 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 | + return dflt; | |
| 1429 | +} | |
| 1430 | + | |
| 1395 | 1431 | |
| 1396 | 1432 | /* |
| 1397 | 1433 | ** Get and set values from the CONFIG, GLOBAL_CONFIG and VVAR table in the |
| 1398 | 1434 | ** repository and local databases. |
| 1399 | 1435 | */ |
| 1400 | 1436 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -1390,10 +1390,46 @@ | |
| 1390 | sqlite3 *dbTemp = g.db; |
| 1391 | g.db = g.dbConfig; |
| 1392 | g.dbConfig = dbTemp; |
| 1393 | } |
| 1394 | } |
| 1395 | |
| 1396 | /* |
| 1397 | ** Get and set values from the CONFIG, GLOBAL_CONFIG and VVAR table in the |
| 1398 | ** repository and local databases. |
| 1399 | */ |
| 1400 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -1390,10 +1390,46 @@ | |
| 1390 | sqlite3 *dbTemp = g.db; |
| 1391 | g.db = g.dbConfig; |
| 1392 | g.dbConfig = dbTemp; |
| 1393 | } |
| 1394 | } |
| 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 | return dflt; |
| 1429 | } |
| 1430 | |
| 1431 | |
| 1432 | /* |
| 1433 | ** Get and set values from the CONFIG, GLOBAL_CONFIG and VVAR table in the |
| 1434 | ** repository and local databases. |
| 1435 | */ |
| 1436 |