Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Minor refactoring and general cleanup of the "fossil setting" logic. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA1: |
32f8da0ce785b63ad8a53fa851b5416b |
| User & Date: | drh 2015-02-01 21:21:40.395 |
References
|
2015-02-02
| ||
| 22:01 | proxy setting test adj for new [32f8da0ce785b63] "fossil setting" logic per ticket [5e35dd60cf7410af64d41] Closed-Leaf check-in: f201cb61a0 user: bch tags: fsl_setting_proxy | |
| 21:26 | • New ticket [5e35dd60cf] http_proxy env variable not honoured. artifact: 76a42d4c1c user: bharder | |
Context
|
2015-02-02
| ||
| 00:17 | Added the /srchsetup page for configuring the /search screen. check-in: ca833ff86f user: drh tags: trunk | |
|
2015-02-01
| ||
| 21:21 | Minor refactoring and general cleanup of the "fossil setting" logic. check-in: 32f8da0ce7 user: drh tags: trunk | |
| 18:37 | Add the /mimetype_list page for use by documentation. check-in: 51751b00a9 user: drh tags: trunk | |
Changes
Changes to src/db.c.
| ︙ | ︙ | |||
1518 1519 1520 1521 1522 1523 1524 |
const char *db_setting_inop_rhs(){
Blob x;
int i;
const char *zSep = "";
blob_zero(&x);
blob_append_sql(&x, "(");
| | | | 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 |
const char *db_setting_inop_rhs(){
Blob x;
int i;
const char *zSep = "";
blob_zero(&x);
blob_append_sql(&x, "(");
for(i=0; aSetting[i].name; i++){
blob_append_sql(&x, "%s%Q", zSep/*safe-for-%s*/, aSetting[i].name);
zSep = ",";
}
blob_append_sql(&x, ")");
return blob_sql_text(&x);
}
/*
|
| ︙ | ︙ | |||
1916 1917 1918 1919 1920 1921 1922 |
g.zMainDbType = g.zConfigDbType;
g.dbConfig = dbTemp;
g.zConfigDbType = zTempDbType;
}
}
/*
| < | > > > > > | | > | | 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 |
g.zMainDbType = g.zConfigDbType;
g.dbConfig = dbTemp;
g.zConfigDbType = zTempDbType;
}
}
/*
** Try to read a versioned setting string from .fossil-settings/<name>.
**
** Return the text of the string if it is found. Return NULL if not
** found.
**
** If the zNonVersionedSetting parameter is not NULL then it holds the
** non-versioned value for this setting. If both a versioned and ad
** non-versioned value exist and are not equal, then a warning message
** might be generated.
*/
char *db_get_versioned(const char *zName, char *zNonVersionedSetting){
char *zVersionedSetting = 0;
int noWarn = 0;
struct _cacheEntry {
struct _cacheEntry *next;
const char *zName, *zValue;
} *cacheEntry = 0;
static struct _cacheEntry *cache = 0;
|
| ︙ | ︙ | |||
1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 |
return ( zVersionedSetting!=0 ) ? zVersionedSetting : zNonVersionedSetting;
}
/*
** Get and set values from the CONFIG, GLOBAL_CONFIG and VVAR table in the
** repository and local databases.
*/
char *db_get(const char *zName, char *zDefault){
char *z = 0;
| > > > > > < < < < < | < < < | | > > > | > | 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 |
return ( zVersionedSetting!=0 ) ? zVersionedSetting : zNonVersionedSetting;
}
/*
** Get and set values from the CONFIG, GLOBAL_CONFIG and VVAR table in the
** repository and local databases.
**
** If no such variable exists, return zDefault. Or, if zName is the name
** of a setting, then the zDefault is ignored and the default value of the
** setting is returned instead. If zName is a versioned setting, then
** versioned value takes priority.
*/
char *db_get(const char *zName, char *zDefault){
char *z = 0;
const Setting *pSetting = db_find_setting(zName, 0);
if( g.repositoryOpen ){
z = db_text(0, "SELECT value FROM config WHERE name=%Q", zName);
}
if( z==0 && g.zConfigDbName ){
db_swap_connections();
z = db_text(0, "SELECT value FROM global_config WHERE name=%Q", zName);
db_swap_connections();
}
if( pSetting!=0 && pSetting->versionable ){
/* This is a versionable setting, try and get the info from a
** checked out file */
z = db_get_versioned(zName, z);
}
if( z==0 ){
if( zDefault==0 && pSetting && pSetting->def[0] ){
z = fossil_strdup(pSetting->def);
}else{
z = zDefault;
}
}
return z;
}
char *db_get_mtime(const char *zName, char *zFormat, char *zDefault){
char *z = 0;
if( g.repositoryOpen ){
z = db_text(0, "SELECT mtime FROM config WHERE name=%Q", zName);
|
| ︙ | ︙ | |||
2288 2289 2290 2291 2292 2293 2294 |
checkout_cmd();
}
g.argc = 2;
info_cmd();
}
/*
| | > | < < < | | | | | | | > | > > | > > < | | > < > | 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 |
checkout_cmd();
}
g.argc = 2;
info_cmd();
}
/*
** Print the current value of a setting identified by the pSetting
** pointer.
*/
static void print_setting(const Setting *pSetting){
Stmt q;
if( g.repositoryOpen ){
db_prepare(&q,
"SELECT '(local)', value FROM config WHERE name=%Q"
" UNION ALL "
"SELECT '(global)', value FROM global_config WHERE name=%Q",
pSetting->name, pSetting->name
);
}else{
db_prepare(&q,
"SELECT '(global)', value FROM global_config WHERE name=%Q",
pSetting->name
);
}
if( db_step(&q)==SQLITE_ROW ){
fossil_print("%-20s %-8s %s\n", pSetting->name, db_column_text(&q, 0),
db_column_text(&q, 1));
}else{
fossil_print("%-20s\n", pSetting->name);
}
if( pSetting->versionable && g.localOpen ){
/* Check to see if this is overridden by a versionable settings file */
Blob versionedPathname;
blob_zero(&versionedPathname);
blob_appendf(&versionedPathname, "%s/.fossil-settings/%s",
g.zLocalRoot, pSetting->name);
if( file_size(blob_str(&versionedPathname))>=0 ){
fossil_print(" (overridden by contents of file .fossil-settings/%s)\n",
pSetting->name);
}
}
db_finalize(&q);
}
#if INTERFACE
/*
** Define all settings, which can be controlled via the set/unset
** command.
**
** var is the name of the internal configuration name for db_(un)set.
** If var is 0, the settings name is used.
**
** width is the length for the edit field on the behavior page, 0
** is used for on/off checkboxes.
**
** The behaviour page doesn't use a special layout. It lists all
** set-commands and displays the 'set'-help as info.
*/
struct Setting {
const char *name; /* Name of the setting */
const char *var; /* Internal variable name used by db_set() */
int width; /* Width of display. 0 for boolean values. */
int versionable; /* Is this setting versionable? */
int forceTextArea; /* Force using a text area for display? */
const char *def; /* Default value */
};
#endif /* INTERFACE */
const Setting aSetting[] = {
{ "access-log", 0, 0, 0, 0, "off" },
{ "admin-log", 0, 0, 0, 0, "off" },
{ "allow-symlinks", 0, 0, 1, 0, "off" },
{ "auto-captcha", "autocaptcha", 0, 0, 0, "on" },
{ "auto-hyperlink", 0, 0, 0, 0, "on", },
{ "auto-shun", 0, 0, 0, 0, "on" },
{ "autosync", 0, 0, 0, 0, "on" },
{ "autosync-tries", 0, 16, 0, 0, "1" },
{ "binary-glob", 0, 40, 1, 0, "" },
#if defined(_WIN32) || defined(__CYGWIN__) || defined(__DARWIN__) || \
defined(__APPLE__)
{ "case-sensitive", 0, 0, 0, 0, "off" },
#else
{ "case-sensitive", 0, 0, 0, 0, "on" },
#endif
{ "clean-glob", 0, 40, 1, 0, "" },
{ "clearsign", 0, 0, 0, 0, "off" },
{ "crnl-glob", 0, 40, 1, 0, "" },
{ "default-perms", 0, 16, 0, 0, "u" },
{ "diff-binary", 0, 0, 0, 0, "on" },
{ "diff-command", 0, 40, 0, 0, "" },
{ "dont-push", 0, 0, 0, 0, "off" },
{ "editor", 0, 32, 0, 0, "" },
{ "empty-dirs", 0, 40, 1, 0, "" },
|
| ︙ | ︙ | |||
2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 |
#endif
{ "th1-setup", 0, 40, 1, 1, "" },
{ "th1-uri-regexp", 0, 40, 1, 0, "" },
{ "web-browser", 0, 32, 0, 0, "" },
{ "white-foreground", 0, 0, 0, 0, "off" },
{ 0,0,0,0,0,0 }
};
/*
** COMMAND: settings
** COMMAND: unset*
**
** %fossil settings ?PROPERTY? ?VALUE? ?OPTIONS?
** %fossil unset PROPERTY ?OPTIONS?
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 |
#endif
{ "th1-setup", 0, 40, 1, 1, "" },
{ "th1-uri-regexp", 0, 40, 1, 0, "" },
{ "web-browser", 0, 32, 0, 0, "" },
{ "white-foreground", 0, 0, 0, 0, "off" },
{ 0,0,0,0,0,0 }
};
/*
** Look up a control setting by its name. Return a pointer to the Setting
** object, or NULL if there is no such setting.
**
** If allowPrefix is true, then the Setting returned is the first one for
** which zName is a prefix of the Setting name.
*/
const Setting *db_find_setting(const char *zName, int allowPrefix){
int lwr, mid, upr, c;
int n = (int)strlen(zName) + !allowPrefix;
lwr = 0;
upr = ArraySize(aSetting)-2;
while( upr>=lwr ){
mid = (upr+lwr)/2;
c = fossil_strncmp(zName, aSetting[mid].name, n);
if( c<0 ){
upr = mid - 1;
}else if( c>0 ){
lwr = mid + 1;
}else{
if( allowPrefix ){
while( mid>lwr && fossil_strncmp(zName, aSetting[mid-1].name, n)==0 ){
mid--;
}
}
return &aSetting[mid];
}
}
return 0;
}
/*
** COMMAND: settings
** COMMAND: unset*
**
** %fossil settings ?PROPERTY? ?VALUE? ?OPTIONS?
** %fossil unset PROPERTY ?OPTIONS?
|
| ︙ | ︙ | |||
2661 2662 2663 2664 2665 2666 2667 2668 |
}
if( !g.repositoryOpen ){
globalFlag = 1;
}
if( unsetFlag && g.argc!=3 ){
usage("PROPERTY ?-global?");
}
if( g.argc==2 ){
| > > > > > > > > > > > > < | | < | | < < | | < | | > | < < | | | < | < | > > > | > | | | | | > > < | < < | | < < < | 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 |
}
if( !g.repositoryOpen ){
globalFlag = 1;
}
if( unsetFlag && g.argc!=3 ){
usage("PROPERTY ?-global?");
}
/* Verify that the aSetting[] entries are in sorted order. This is
** necessary for the binary search in db_find_setting() to work correctly.
*/
for(i=1; aSetting[i].name; i++){
if( fossil_strcmp(aSetting[i-1].name, aSetting[i].name)>=0 ){
fossil_panic("Internal Error: aSetting[] entries for \"%s\""
" and \"%s\" are out of order.",
aSetting[i-1].name, aSetting[i].name);
}
}
if( g.argc==2 ){
for(i=0; aSetting[i].name; i++){
print_setting(&aSetting[i]);
}
}else if( g.argc==3 || g.argc==4 ){
const char *zName = g.argv[2];
int n = (int)strlen(zName);
const Setting *pSetting = db_find_setting(zName, 1);
if( pSetting==0 ){
fossil_fatal("no such setting: %s", zName);
}
if( globalFlag && fossil_strcmp(pSetting->name, "manifest")==0 ){
fossil_fatal("cannot set 'manifest' globally");
}
if( unsetFlag || g.argc==4 ){
int isManifest = fossil_strcmp(pSetting->name, "manifest")==0;
if( pSetting[1].name && fossil_strncmp(pSetting[1].name, zName, n)==0 ){
Blob x;
int i;
blob_init(&x,0,0);
for(i=0; pSetting[i].name; i++){
if( fossil_strncmp(pSetting[i].name,zName,n)!=0 ) break;
blob_appendf(&x, " %s", pSetting[i].name);
}
fossil_fatal("ambiguous setting \"%s\" - might be:%s",
zName, blob_str(&x));
}
if( globalFlag && isManifest ){
fossil_fatal("cannot set 'manifest' globally");
}
if( unsetFlag ){
db_unset(pSetting->name, globalFlag);
}else{
db_set(pSetting->name, g.argv[3], globalFlag);
}
if( isManifest && g.localOpen ){
manifest_to_disk(db_lget_int("checkout", 0));
}
}else{
while( pSetting->name && fossil_strncmp(pSetting->name,zName,n)==0 ){
print_setting(pSetting);
pSetting++;
}
}
}else{
usage("?PROPERTY? ?VALUE? ?-global?");
}
}
/*
|
| ︙ | ︙ |
Changes to src/setup.c.
| ︙ | ︙ | |||
1352 1353 1354 1355 1356 1357 1358 |
style_footer();
}
/*
** WEBPAGE: setup_settings
*/
void setup_settings(void){
| | | | | | | | | 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 |
style_footer();
}
/*
** WEBPAGE: setup_settings
*/
void setup_settings(void){
Setting const *pSet;
login_check_credentials();
if( !g.perm.Setup ){
login_needed();
}
(void) aCmdHelp; /* NOTE: Silence compiler warning. */
style_header("Settings");
if(!g.repositoryOpen){
/* Provide read-only access to versioned settings,
but only if no repo file was explicitly provided. */
db_open_local(0);
}
db_begin_transaction();
@ <p>This page provides a simple interface to the "fossil setting" command.
@ See the "fossil help setting" output below for further information on
@ the meaning of each setting.</p><hr />
@ <form action="%s(g.zTop)/setup_settings" method="post"><div>
@ <table border="0"><tr><td valign="top">
login_insert_csrf_secret();
for(pSet=aSetting; pSet->name!=0; pSet++){
if( pSet->width==0 ){
int hasVersionableValue = pSet->versionable &&
(db_get_versioned(pSet->name, NULL)!=0);
onoff_attribute(pSet->name, pSet->name,
pSet->var!=0 ? pSet->var : pSet->name,
is_truth(pSet->def), hasVersionableValue);
if( pSet->versionable ){
@ (v)<br />
} else {
@ <br />
}
}
}
@ <br /><input type="submit" name="submit" value="Apply Changes" />
@ </td><td style="width:50px;"></td><td valign="top">
for(pSet=aSetting; pSet->name!=0; pSet++){
if( pSet->width!=0 && !pSet->versionable && !pSet->forceTextArea ){
entry_attribute(pSet->name, /*pSet->width*/ 25, pSet->name,
pSet->var!=0 ? pSet->var : pSet->name,
(char*)pSet->def, 0);
@ <br />
}
}
for(pSet=aSetting; pSet->name!=0; pSet++){
if( pSet->width!=0 && !pSet->versionable && pSet->forceTextArea ){
@<b>%s(pSet->name)</b><br />
textarea_attribute("", /*rows*/ 3, /*cols*/ 50, pSet->name,
pSet->var!=0 ? pSet->var : pSet->name,
(char*)pSet->def, 0);
@ <br />
}
}
@ </td><td style="width:50px;"></td><td valign="top">
for(pSet=aSetting; pSet->name!=0; pSet++){
if( pSet->width!=0 && pSet->versionable ){
int hasVersionableValue = db_get_versioned(pSet->name, NULL)!=0;
@<b>%s(pSet->name)</b> (v)<br />
textarea_attribute("", /*rows*/ 3, /*cols*/ 20, pSet->name,
pSet->var!=0 ? pSet->var : pSet->name,
(char*)pSet->def, hasVersionableValue);
@<br />
}
}
|
| ︙ | ︙ |