Check-in [418207989a]
Not logged in
Overview

SHA1 Hash:418207989a55779c3226021079c046f8f296919b
Date: 2008-05-10 17:22:07
User: drh
Comment:Add the "unset" command for clearing settings.
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/db.c from [5e79625a72] to [c776b3bd01].

@@ -942,10 +942,19 @@
   if( globalFlag && g.repositoryOpen ){
     db_multi_exec("DELETE FROM config WHERE name=%Q", zName);
   }
   db_end_transaction(0);
 }
+void db_unset(const char *zName, int globalFlag){
+  db_begin_transaction();
+  db_multi_exec("DELETE FROM %sconfig WHERE name=%Q",
+                 globalFlag ? "global_" : "", zName);
+  if( globalFlag && g.repositoryOpen ){
+    db_multi_exec("DELETE FROM config WHERE name=%Q", zName);
+  }
+  db_end_transaction(0);
+}
 int db_is_global(const char *zName){
   if( g.configOpen ){
     return db_exists("SELECT 1 FROM global_config WHERE name=%Q", zName);
   }else{
     return 0;
@@ -1063,15 +1072,19 @@
 }
 
 
 /*
 ** COMMAND: settings
+** COMMAND: unset
 ** %fossil setting ?PROPERTY? ?VALUE? ?-global?
-**
-** With no arguments, list all properties and their values.  With just
-** a property name, show the value of that property.  With a value
-** argument, change the property for the current repository.
+** %fossil unset PROPERTY ?-global?
+**
+** The "setting" command with no arguments lists all properties and their
+** values.  With just a property name it shows the value of that property.
+** With a value argument it changes the property for the current repository.
+**
+** The "unset" command clears a property setting.
 **
 **    autosync         If enabled, automatically pull prior to
 **                     commit or update and automatically push
 **                     after commit or tag or branch creation.
 **
@@ -1110,14 +1123,18 @@
     "diff-command",
     "gdiff-command",
   };
   int i;
   int globalFlag = find_option("global","g",0)!=0;
+  int unsetFlag = g.argv[1][0]=='u';
   db_find_and_open_repository(0);
   if( !g.repositoryOpen ){
     db_open_config();
     globalFlag = 1;
+  }
+  if( unsetFlag && g.argc!=3 ){
+    usage("PROPERTY ?-global?");
   }
   if( g.argc==2 ){
     for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
       print_setting(azName[i]);
     }
@@ -1128,11 +1145,13 @@
       if( strncmp(azName[i], zName, n)==0 ) break;
     }
     if( i>=sizeof(azName)/sizeof(azName[0]) ){
       fossil_fatal("no such setting: %s", zName);
     }
-    if( g.argc==4 ){
+    if( unsetFlag ){
+      db_unset(azName[i], globalFlag);
+    }else if( g.argc==4 ){
       db_set(azName[i], g.argv[3], globalFlag);
     }else{
       print_setting(azName[i]);
     }
   }else{