Fossil

Check-in [8dbee6731d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
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.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 8dbee6731d9b779a2e47b873467584f55370255b
User & Date: drh 2007-07-31 01:34:45.000
Context
2007-07-31
10:10
Remove one to-do item. Add another. check-in: 7fe1e734e9 user: drh tags: trunk
01:34
The push, pull, and sync commands remember the last server and reuse it if the URL argument is omitted. Sync via network only now. check-in: 8dbee6731d user: drh tags: trunk
00:06
More additions to the todo.txt list. check-in: 9c28ba4956 user: drh tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/clone.c.
45
46
47
48
49
50
51



52
53
54
55
56
57
58
  }
  url_parse(g.argv[2]);
  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);



  db_multi_exec(
    "INSERT INTO config(name,value) VALUES('server-code', hex(randomblob(20)));"
  );
   if( g.urlIsFile ){
    Stmt q;
    db_multi_exec("ATTACH DATABASE %Q AS orig", g.urlName);
    db_begin_transaction();







>
>
>







45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  }
  url_parse(g.argv[2]);
  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;
    db_multi_exec("ATTACH DATABASE %Q AS orig", g.urlName);
    db_begin_transaction();
Changes to src/db.c.
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
** Try to find the repository and open it.  If we are in a local
** tree, then use the repository of the local tree.  Otherwise,
** 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);
  if( zRep==0 ){
    if( db_open_local()==0 ){
      goto rep_not_found;
    }
    zRep = db_lget("repository", 0);
    if( zRep==0 ){
      goto rep_not_found;







|







584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
** Try to find the repository and open it.  If we are in a local
** tree, then use the repository of the local tree.  Otherwise,
** fall back to the -R or --repository option.
**
** Error out if the repository cannot be opened.
*/
void db_find_and_open_repository(void){
  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);
    if( zRep==0 ){
      goto rep_not_found;
Changes to src/sync.c.
22
23
24
25
26
27
28

























29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
*******************************************************************************
**
** This file contains code used to push, pull, and sync a repository
*/
#include "config.h"
#include "sync.h"
#include <assert.h>


























/*
** 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);
  }
}

/*
** 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);
  }
}


/*
** 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);
  }
}







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
|
<








<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
|
<









<
<
<
<
<
|
<
<
<
<
|
<

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60




















61











62

63
64
65
66
67
68
69
70


















71



72

73
74
75
76
77
78
79
80
81





82




83

84
*******************************************************************************
**
** This file contains code used to push, pull, and sync a repository
*/
#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){




















  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){


















  process_sync_args();



  client_sync(1,0,0);

}


/*
** COMMAND: sync
**
** Synchronize the local repository with a remote repository
*/
void sync_cmd(void){





  process_sync_args();




  client_sync(1,1,0);

}