Check-in [8dbee6731d]
Not logged in
Overview

SHA1 Hash:8dbee6731d9b779a2e47b873467584f55370255b
Date: 2007-07-31 01:34:45
User: drh
Comment:The push, pull, and sync commands remember the last server and reuse it if the URL argument is omitted. Sync via network only now.
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/clone.c from [163dfdc48c] to [3302dbc338].

@@ -47,10 +47,13 @@
   db_create_repository(g.argv[3]);
   db_open_repository(g.argv[3]);
   user_select();
   db_set("content-schema", CONTENT_SCHEMA);
   db_set("aux-schema", AUX_SCHEMA);
+  if( !g.urlIsFile ){
+    db_set("last-sync-url", g.argv[2]);
+  }
   db_multi_exec(
     "INSERT INTO config(name,value) VALUES('server-code', hex(randomblob(20)));"
   );
    if( g.urlIsFile ){
     Stmt q;

Modified src/db.c from [44658ef357] to [904ab46ad3].

@@ -586,11 +586,11 @@
 ** fall back to the -R or --repository option.
 **
 ** Error out if the repository cannot be opened.
 */
 void db_find_and_open_repository(void){
-  char *zRep = find_option("repository", "R", 1);
+  const char *zRep = find_option("repository", "R", 1);
   if( zRep==0 ){
     if( db_open_local()==0 ){
       goto rep_not_found;
     }
     zRep = db_lget("repository", 0);

Modified src/sync.c from [36ca951c1c] to [53257d834f].

@@ -26,98 +26,59 @@
 #include "config.h"
 #include "sync.h"
 #include <assert.h>
 
 /*
+** This routine processes the command-line argument for push, pull,
+** and sync.  If a command-line argument is given, that is the URL
+** of a server to sync against.  If no argument is given, use the
+** most recently synced URL.  Remember the current URL for next time.
+*/
+static void process_sync_args(void){
+  const char *zUrl = 0;
+  db_find_and_open_repository();
+  if( g.argc==2 ){
+    zUrl = db_get("last-sync-url", 0);
+  }else if( g.argc==3 ){
+    zUrl = g.argv[2];
+  }
+  if( zUrl==0 ){
+    usage("URL");
+  }
+  url_parse(zUrl);
+  if( g.urlIsFile ){
+    fossil_fatal("network sync only");
+  }
+  db_set("last-sync-url", zUrl);
+  user_select();
+}
+
+/*
 ** COMMAND: pull
 **
 ** Pull changes in a remote repository into the local repository
 */
 void pull_cmd(void){
-  if( g.argc!=3 ){
-    usage("FILE-OR-URL");
-  }
-  url_parse(g.argv[2]);
-  db_must_be_within_tree();
-  user_select();
-  if( g.urlIsFile ){
-    Stmt q;
-    char *zRemote = g.urlName;
-    if( !file_isfile(zRemote) ){
-      zRemote = mprintf("%s/_FOSSIL_");
-    }
-    if( !file_isfile(zRemote) ){
-      fossil_panic("no such repository: %s", zRemote);
-    }
-    db_multi_exec("ATTACH DATABASE %Q AS other", zRemote);
-    db_begin_transaction();
-    db_prepare(&q,
-      "SELECT rid FROM other.blob WHERE NOT EXISTS"
-      " (SELECT 1 FROM blob WHERE uuid=other.blob.uuid)"
-    );
-    while( db_step(&q)==SQLITE_ROW ){
-      int nrid;
-      int rid = db_column_int(&q, 0);
-      Blob rec;
-      content_get_from_db(rid, &rec, "other");
-      nrid = content_put(&rec, 0);
-      manifest_crosslink(nrid, &rec);
-    }
-    db_finalize(&q);
-    db_end_transaction(0);
-  }else{
-    client_sync(0,1,0);
-  }
+  process_sync_args();
+  client_sync(0,1,0);
 }
 
 /*
 ** COMMAND: push
 **
 ** Push changes in the local repository over into a remote repository
 */
 void push_cmd(void){
-  if( g.argc!=3 ){
-    usage("FILE-OR-URL");
-  }
-  url_parse(g.argv[2]);
-  db_must_be_within_tree();
-  if( g.urlIsFile ){
-    Blob remote;
-    char *zRemote;
-    file_canonical_name(g.urlName, &remote);
-    zRemote = blob_str(&remote);
-    if( file_isdir(zRemote)!=1 ){
-      int i = strlen(zRemote);
-      while( i>0 && zRemote[i]!='/' ){ i--; }
-      zRemote[i] = 0;
-    }
-    if( chdir(zRemote) ){
-      fossil_panic("unable to change the working directory to %s", zRemote);
-    }
-    db_close();
-    g.argv[2] = g.zLocalRoot;
-    pull_cmd();
-  }else{
-    client_sync(1,0,0);
-  }
+  process_sync_args();
+  client_sync(1,0,0);
 }
 
 
 /*
 ** COMMAND: sync
 **
 ** Synchronize the local repository with a remote repository
 */
 void sync_cmd(void){
-  if( g.argc!=3 ){
-    usage("FILE-OR-URL");
-  }
-  url_parse(g.argv[2]);
-  if( g.urlIsFile ){
-    pull_cmd();
-    db_close();
-    push_cmd();
-  }else{
-    db_must_be_within_tree();
-    client_sync(1,1,0);
-  }
+  process_sync_args();
+  client_sync(1,1,0);
 }