Check-in [fff234b77c]
Not logged in
Overview

SHA1 Hash:fff234b77cc774ca649f8279cd50585a9d44ac4b
Date: 2007-09-25 20:23:52
User: drh
Comment:Updates to the autosync logic. Add the "setting" command.
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/branch.c from [1d4c15b285] to [6f4b5c89ef].

@@ -157,16 +157,12 @@
   undo_reset();
 
   /* Commit */
   db_end_transaction(0);
 
-  /* Autosync and do a push? */
-  if( do_autosync() ){
-    g.argc=2;
-    g.argv[1]="push";
-    push_cmd();
-  }
+  /* Do an autosync push, if requested */
+  autosync(0);
 }
 
 /*
 ** COMMAND: branch
 **

Modified src/checkin.c from [45c26e70ac] to [55cded4432].

@@ -323,22 +323,29 @@
   Stmt q;
   Stmt q2;
   char *zUuid, *zDate;
   int noSign = 0;        /* True to omit signing the manifest using GPG */
   int isAMerge = 0;      /* True if checking in a merge */
+  int forceFlag = 0;     /* Force a fork */
   char *zManifestFile;   /* Name of the manifest file */
   Blob manifest;
   Blob muuid;            /* Manifest uuid */
   Blob mcksum;           /* Self-checksum on the manifest */
   Blob cksum1, cksum2;   /* Before and after commit checksums */
   Blob cksum1b;          /* Checksum recorded in the manifest */
 
   noSign = find_option("nosign","",0)!=0;
   zComment = find_option("comment","m",1);
+  forceFlag = find_option("force", "r", 0)!=0;
   db_must_be_within_tree();
   noSign = db_get_int("omit-ci-sig", 0)|noSign;
   verify_all_options();
+
+  /*
+  ** Autosync if requested.
+  */
+  autosync(1);
 
   /* There are two ways this command may be executed. If there are
   ** no arguments following the word "commit", then all modified files
   ** in the checked out directory are committed. If one or more arguments
   ** follows "commit", then only those files are committed.
@@ -355,11 +362,11 @@
   }
 
   user_select();
   db_begin_transaction();
   rc = unsaved_changes();
-  if( rc==0 && !isAMerge ){
+  if( rc==0 && !isAMerge && !forceFlag ){
     fossil_panic("nothing has changed");
   }
 
   /* If one or more files that were named on the command line have not
   ** been modified, bail out now.
@@ -375,10 +382,13 @@
       fossil_panic("file %s has not changed", blob_str(&unmodified));
     }
   }
 
   vid = db_lget_int("checkout", 0);
+  if( !forceFlag && db_exists("SELECT 1 FROM plink WHERE pid=%d", vid) ){
+    fossil_fatal("would fork.  use -f or --force");
+  }
   vfile_aggregate_checksum_disk(vid, &cksum1);
   if( zComment ){
     blob_zero(&comment);
     blob_append(&comment, zComment, -1);
   }else{
@@ -524,12 +534,8 @@
   undo_reset();
 
   /* Commit */
   db_end_transaction(0);
 
-  /* Autosync and do a push? */
-  if( do_autosync() ){
-    g.argc=2;
-    g.argv[1]="push";
-    push_cmd();
-  }
+  /* Do an autosync push if requested */
+  autosync(0);
 }

Modified src/db.c from [65cc9f7698] to [df88f7f101].

@@ -954,7 +954,45 @@
     db_prepare(&q, "SELECT name, value FROM global_config ORDER BY name");
     while( db_step(&q)==SQLITE_ROW ){
       printf("%s=%s\n", db_column_text(&q, 0), db_column_text(&q, 1));
     }
     db_finalize(&q);
+  }
+}
+
+/*
+** COMMAND: setting
+** %fossil setting ?PROPERTY? ?VALUE?
+**
+** With no arguments, list all properties and their values.  With just
+** a property name, show the value of that property.  With a value
+** arugment, change the property for the current repository.
+*/
+void setting_cmd(void){
+  static const char *azName[] = {
+    "autosync",
+    "safemerge"
+  };
+  int i;
+  db_find_and_open_repository();
+  if( g.argc==2 ){
+    for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
+      printf("%-20s %d\n", azName[i], db_get_int(azName[i], 0));
+    }
+  }else if( g.argc==3 || g.argc==4 ){
+    const char *zName = g.argv[2];
+    int n = strlen(zName);
+    for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
+      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 ){
+      db_set(azName[i], g.argv[3]);
+    }else{
+      printf("%-20s %d\n", azName[i], db_get_int(azName[i], 0));
+    }
+  }else{
+    usage("?PROPERTY? ?VALUE?");
   }
 }

Modified src/sync.c from [49100c83b1] to [6c1dfe7a9d].

@@ -26,23 +26,35 @@
 #include "config.h"
 #include "sync.h"
 #include <assert.h>
 
 /*
-** Determine if an autosync should be done or not. The config setting,
-** autosync must start with 1, y or Y. The last-sync-url must also be
-** defined.
+** If the respository is configured for autosyncing, then do an
+** autosync.  This will be a pull if the argument is true or a push
+** if the argument is false.  Return true if the autosync is done
+** and false if autosync is not requested for the current repository.
 */
-int do_autosync(void){
-  const char *zAutoSync = db_global_get("autosync", 0);
-  if( zAutoSync != 0
-      && (zAutoSync[0]=='1' || zAutoSync[0]=='y' || zAutoSync=='Y')
-      && db_get("last-sync-url", 0)!=0 ){
-    return 1;
-  }else{
+int autosync(int pullFlag){
+  const char *zUrl;
+  if( db_get_int("autosync", 0)==0 ){
     return 0;
   }
+  zUrl = db_get("last-sync-url", 0);
+  if( zUrl ){
+    return 0;  /* No default server */
+  }
+  url_parse(zUrl);
+  if( g.urlIsFile ){
+    return 0;  /* Network sync only */
+  }
+  if( g.urlPort!=80 ){
+    printf("Autosync:  http://%s:%d%s\n", g.urlName, g.urlPort, g.urlPath);
+  }else{
+    printf("Autosync:  http://%s%s\n", g.urlName, g.urlPath);
+  }
+  client_sync(!pullFlag, pullFlag, 0);
+  return 1;
 }
 
 /*
 ** This routine processes the command-line argument for push, pull,
 ** and sync.  If a command-line argument is given, that is the URL

Modified src/tag.c from [53f340db14] to [1b7c8db1b9].

@@ -290,16 +290,12 @@
   db_begin_transaction();
   nrid = content_put(&ctrl, 0, 0);
   manifest_crosslink(nrid, &ctrl);
   db_end_transaction(0);
 
-  /* Autosync and do a push? */
-  if( do_autosync() ){
-    g.argc=2;
-    g.argv[1]="push";
-    push_cmd();
-  }
+  /* Do an autosync push if requested */
+  autosync(0);
 }
 
 /*
 ** COMMAND: tag
 ** Usage: %fossil tag SUBCOMMAND ...

Modified src/update.c from [ee3b58703f] to [38dd8e9b10].

@@ -76,15 +76,12 @@
     if( !is_a_version(tid) ){
       fossil_fatal("not a version: %s", g.argv[2]);
     }
   }
 
-  if( do_autosync() ){
-    g.argc=2;
-    g.argv[1]="pull";
-    pull_cmd();
-  }
+  /* Do an autosync pull prior to the update, if autosync is on */
+  autosync(1);
 
   if( tid==0 ){
     compute_leaves(vid);
     if( !latestFlag && db_int(0, "SELECT count(*) FROM leaves")>1 ){
       db_prepare(&q,