Fossil SCM

Updates to the autosync logic. Add the "setting" command.

drh 2007-09-25 20:23 trunk
Commit fff234b77cc774ca649f8279cd50585a9d44ac4b
+2 -6
--- src/branch.c
+++ src/branch.c
@@ -157,16 +157,12 @@
157157
undo_reset();
158158
159159
/* Commit */
160160
db_end_transaction(0);
161161
162
- /* Autosync and do a push? */
163
- if( do_autosync() ){
164
- g.argc=2;
165
- g.argv[1]="push";
166
- push_cmd();
167
- }
162
+ /* Do an autosync push, if requested */
163
+ autosync(0);
168164
}
169165
170166
/*
171167
** COMMAND: branch
172168
**
173169
--- src/branch.c
+++ src/branch.c
@@ -157,16 +157,12 @@
157 undo_reset();
158
159 /* Commit */
160 db_end_transaction(0);
161
162 /* Autosync and do a push? */
163 if( do_autosync() ){
164 g.argc=2;
165 g.argv[1]="push";
166 push_cmd();
167 }
168 }
169
170 /*
171 ** COMMAND: branch
172 **
173
--- src/branch.c
+++ src/branch.c
@@ -157,16 +157,12 @@
157 undo_reset();
158
159 /* Commit */
160 db_end_transaction(0);
161
162 /* Do an autosync push, if requested */
163 autosync(0);
 
 
 
 
164 }
165
166 /*
167 ** COMMAND: branch
168 **
169
+14 -8
--- src/checkin.c
+++ src/checkin.c
@@ -323,23 +323,30 @@
323323
Stmt q;
324324
Stmt q2;
325325
char *zUuid, *zDate;
326326
int noSign = 0; /* True to omit signing the manifest using GPG */
327327
int isAMerge = 0; /* True if checking in a merge */
328
+ int forceFlag = 0; /* Force a fork */
328329
char *zManifestFile; /* Name of the manifest file */
329330
Blob manifest;
330331
Blob muuid; /* Manifest uuid */
331332
Blob mcksum; /* Self-checksum on the manifest */
332333
Blob cksum1, cksum2; /* Before and after commit checksums */
333334
Blob cksum1b; /* Checksum recorded in the manifest */
334335
335336
noSign = find_option("nosign","",0)!=0;
336337
zComment = find_option("comment","m",1);
338
+ forceFlag = find_option("force", "r", 0)!=0;
337339
db_must_be_within_tree();
338340
noSign = db_get_int("omit-ci-sig", 0)|noSign;
339341
verify_all_options();
340
-
342
+
343
+ /*
344
+ ** Autosync if requested.
345
+ */
346
+ autosync(1);
347
+
341348
/* There are two ways this command may be executed. If there are
342349
** no arguments following the word "commit", then all modified files
343350
** in the checked out directory are committed. If one or more arguments
344351
** follows "commit", then only those files are committed.
345352
**
@@ -355,11 +362,11 @@
355362
}
356363
357364
user_select();
358365
db_begin_transaction();
359366
rc = unsaved_changes();
360
- if( rc==0 && !isAMerge ){
367
+ if( rc==0 && !isAMerge && !forceFlag ){
361368
fossil_panic("nothing has changed");
362369
}
363370
364371
/* If one or more files that were named on the command line have not
365372
** been modified, bail out now.
@@ -375,10 +382,13 @@
375382
fossil_panic("file %s has not changed", blob_str(&unmodified));
376383
}
377384
}
378385
379386
vid = db_lget_int("checkout", 0);
387
+ if( !forceFlag && db_exists("SELECT 1 FROM plink WHERE pid=%d", vid) ){
388
+ fossil_fatal("would fork. use -f or --force");
389
+ }
380390
vfile_aggregate_checksum_disk(vid, &cksum1);
381391
if( zComment ){
382392
blob_zero(&comment);
383393
blob_append(&comment, zComment, -1);
384394
}else{
@@ -524,12 +534,8 @@
524534
undo_reset();
525535
526536
/* Commit */
527537
db_end_transaction(0);
528538
529
- /* Autosync and do a push? */
530
- if( do_autosync() ){
531
- g.argc=2;
532
- g.argv[1]="push";
533
- push_cmd();
534
- }
539
+ /* Do an autosync push if requested */
540
+ autosync(0);
535541
}
536542
--- src/checkin.c
+++ src/checkin.c
@@ -323,23 +323,30 @@
323 Stmt q;
324 Stmt q2;
325 char *zUuid, *zDate;
326 int noSign = 0; /* True to omit signing the manifest using GPG */
327 int isAMerge = 0; /* True if checking in a merge */
 
328 char *zManifestFile; /* Name of the manifest file */
329 Blob manifest;
330 Blob muuid; /* Manifest uuid */
331 Blob mcksum; /* Self-checksum on the manifest */
332 Blob cksum1, cksum2; /* Before and after commit checksums */
333 Blob cksum1b; /* Checksum recorded in the manifest */
334
335 noSign = find_option("nosign","",0)!=0;
336 zComment = find_option("comment","m",1);
 
337 db_must_be_within_tree();
338 noSign = db_get_int("omit-ci-sig", 0)|noSign;
339 verify_all_options();
340
 
 
 
 
 
341 /* There are two ways this command may be executed. If there are
342 ** no arguments following the word "commit", then all modified files
343 ** in the checked out directory are committed. If one or more arguments
344 ** follows "commit", then only those files are committed.
345 **
@@ -355,11 +362,11 @@
355 }
356
357 user_select();
358 db_begin_transaction();
359 rc = unsaved_changes();
360 if( rc==0 && !isAMerge ){
361 fossil_panic("nothing has changed");
362 }
363
364 /* If one or more files that were named on the command line have not
365 ** been modified, bail out now.
@@ -375,10 +382,13 @@
375 fossil_panic("file %s has not changed", blob_str(&unmodified));
376 }
377 }
378
379 vid = db_lget_int("checkout", 0);
 
 
 
380 vfile_aggregate_checksum_disk(vid, &cksum1);
381 if( zComment ){
382 blob_zero(&comment);
383 blob_append(&comment, zComment, -1);
384 }else{
@@ -524,12 +534,8 @@
524 undo_reset();
525
526 /* Commit */
527 db_end_transaction(0);
528
529 /* Autosync and do a push? */
530 if( do_autosync() ){
531 g.argc=2;
532 g.argv[1]="push";
533 push_cmd();
534 }
535 }
536
--- src/checkin.c
+++ src/checkin.c
@@ -323,23 +323,30 @@
323 Stmt q;
324 Stmt q2;
325 char *zUuid, *zDate;
326 int noSign = 0; /* True to omit signing the manifest using GPG */
327 int isAMerge = 0; /* True if checking in a merge */
328 int forceFlag = 0; /* Force a fork */
329 char *zManifestFile; /* Name of the manifest file */
330 Blob manifest;
331 Blob muuid; /* Manifest uuid */
332 Blob mcksum; /* Self-checksum on the manifest */
333 Blob cksum1, cksum2; /* Before and after commit checksums */
334 Blob cksum1b; /* Checksum recorded in the manifest */
335
336 noSign = find_option("nosign","",0)!=0;
337 zComment = find_option("comment","m",1);
338 forceFlag = find_option("force", "r", 0)!=0;
339 db_must_be_within_tree();
340 noSign = db_get_int("omit-ci-sig", 0)|noSign;
341 verify_all_options();
342
343 /*
344 ** Autosync if requested.
345 */
346 autosync(1);
347
348 /* There are two ways this command may be executed. If there are
349 ** no arguments following the word "commit", then all modified files
350 ** in the checked out directory are committed. If one or more arguments
351 ** follows "commit", then only those files are committed.
352 **
@@ -355,11 +362,11 @@
362 }
363
364 user_select();
365 db_begin_transaction();
366 rc = unsaved_changes();
367 if( rc==0 && !isAMerge && !forceFlag ){
368 fossil_panic("nothing has changed");
369 }
370
371 /* If one or more files that were named on the command line have not
372 ** been modified, bail out now.
@@ -375,10 +382,13 @@
382 fossil_panic("file %s has not changed", blob_str(&unmodified));
383 }
384 }
385
386 vid = db_lget_int("checkout", 0);
387 if( !forceFlag && db_exists("SELECT 1 FROM plink WHERE pid=%d", vid) ){
388 fossil_fatal("would fork. use -f or --force");
389 }
390 vfile_aggregate_checksum_disk(vid, &cksum1);
391 if( zComment ){
392 blob_zero(&comment);
393 blob_append(&comment, zComment, -1);
394 }else{
@@ -524,12 +534,8 @@
534 undo_reset();
535
536 /* Commit */
537 db_end_transaction(0);
538
539 /* Do an autosync push if requested */
540 autosync(0);
 
 
 
 
541 }
542
+38
--- src/db.c
+++ src/db.c
@@ -956,5 +956,43 @@
956956
printf("%s=%s\n", db_column_text(&q, 0), db_column_text(&q, 1));
957957
}
958958
db_finalize(&q);
959959
}
960960
}
961
+
962
+/*
963
+** COMMAND: setting
964
+** %fossil setting ?PROPERTY? ?VALUE?
965
+**
966
+** With no arguments, list all properties and their values. With just
967
+** a property name, show the value of that property. With a value
968
+** arugment, change the property for the current repository.
969
+*/
970
+void setting_cmd(void){
971
+ static const char *azName[] = {
972
+ "autosync",
973
+ "safemerge"
974
+ };
975
+ int i;
976
+ db_find_and_open_repository();
977
+ if( g.argc==2 ){
978
+ for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
979
+ printf("%-20s %d\n", azName[i], db_get_int(azName[i], 0));
980
+ }
981
+ }else if( g.argc==3 || g.argc==4 ){
982
+ const char *zName = g.argv[2];
983
+ int n = strlen(zName);
984
+ for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
985
+ if( strncmp(azName[i], zName, n)==0 ) break;
986
+ }
987
+ if( i>=sizeof(azName)/sizeof(azName[0]) ){
988
+ fossil_fatal("no such setting: %s", zName);
989
+ }
990
+ if( g.argc==4 ){
991
+ db_set(azName[i], g.argv[3]);
992
+ }else{
993
+ printf("%-20s %d\n", azName[i], db_get_int(azName[i], 0));
994
+ }
995
+ }else{
996
+ usage("?PROPERTY? ?VALUE?");
997
+ }
998
+}
961999
--- src/db.c
+++ src/db.c
@@ -956,5 +956,43 @@
956 printf("%s=%s\n", db_column_text(&q, 0), db_column_text(&q, 1));
957 }
958 db_finalize(&q);
959 }
960 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
961
--- src/db.c
+++ src/db.c
@@ -956,5 +956,43 @@
956 printf("%s=%s\n", db_column_text(&q, 0), db_column_text(&q, 1));
957 }
958 db_finalize(&q);
959 }
960 }
961
962 /*
963 ** COMMAND: setting
964 ** %fossil setting ?PROPERTY? ?VALUE?
965 **
966 ** With no arguments, list all properties and their values. With just
967 ** a property name, show the value of that property. With a value
968 ** arugment, change the property for the current repository.
969 */
970 void setting_cmd(void){
971 static const char *azName[] = {
972 "autosync",
973 "safemerge"
974 };
975 int i;
976 db_find_and_open_repository();
977 if( g.argc==2 ){
978 for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
979 printf("%-20s %d\n", azName[i], db_get_int(azName[i], 0));
980 }
981 }else if( g.argc==3 || g.argc==4 ){
982 const char *zName = g.argv[2];
983 int n = strlen(zName);
984 for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
985 if( strncmp(azName[i], zName, n)==0 ) break;
986 }
987 if( i>=sizeof(azName)/sizeof(azName[0]) ){
988 fossil_fatal("no such setting: %s", zName);
989 }
990 if( g.argc==4 ){
991 db_set(azName[i], g.argv[3]);
992 }else{
993 printf("%-20s %d\n", azName[i], db_get_int(azName[i], 0));
994 }
995 }else{
996 usage("?PROPERTY? ?VALUE?");
997 }
998 }
999
+22 -10
--- src/sync.c
+++ src/sync.c
@@ -26,23 +26,35 @@
2626
#include "config.h"
2727
#include "sync.h"
2828
#include <assert.h>
2929
3030
/*
31
-** Determine if an autosync should be done or not. The config setting,
32
-** autosync must start with 1, y or Y. The last-sync-url must also be
33
-** defined.
31
+** If the respository is configured for autosyncing, then do an
32
+** autosync. This will be a pull if the argument is true or a push
33
+** if the argument is false. Return true if the autosync is done
34
+** and false if autosync is not requested for the current repository.
3435
*/
35
-int do_autosync(void){
36
- const char *zAutoSync = db_global_get("autosync", 0);
37
- if( zAutoSync != 0
38
- && (zAutoSync[0]=='1' || zAutoSync[0]=='y' || zAutoSync=='Y')
39
- && db_get("last-sync-url", 0)!=0 ){
40
- return 1;
41
- }else{
36
+int autosync(int pullFlag){
37
+ const char *zUrl;
38
+ if( db_get_int("autosync", 0)==0 ){
4239
return 0;
4340
}
41
+ zUrl = db_get("last-sync-url", 0);
42
+ if( zUrl ){
43
+ return 0; /* No default server */
44
+ }
45
+ url_parse(zUrl);
46
+ if( g.urlIsFile ){
47
+ return 0; /* Network sync only */
48
+ }
49
+ if( g.urlPort!=80 ){
50
+ printf("Autosync: http://%s:%d%s\n", g.urlName, g.urlPort, g.urlPath);
51
+ }else{
52
+ printf("Autosync: http://%s%s\n", g.urlName, g.urlPath);
53
+ }
54
+ client_sync(!pullFlag, pullFlag, 0);
55
+ return 1;
4456
}
4557
4658
/*
4759
** This routine processes the command-line argument for push, pull,
4860
** and sync. If a command-line argument is given, that is the URL
4961
--- src/sync.c
+++ src/sync.c
@@ -26,23 +26,35 @@
26 #include "config.h"
27 #include "sync.h"
28 #include <assert.h>
29
30 /*
31 ** Determine if an autosync should be done or not. The config setting,
32 ** autosync must start with 1, y or Y. The last-sync-url must also be
33 ** defined.
 
34 */
35 int do_autosync(void){
36 const char *zAutoSync = db_global_get("autosync", 0);
37 if( zAutoSync != 0
38 && (zAutoSync[0]=='1' || zAutoSync[0]=='y' || zAutoSync=='Y')
39 && db_get("last-sync-url", 0)!=0 ){
40 return 1;
41 }else{
42 return 0;
43 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44 }
45
46 /*
47 ** This routine processes the command-line argument for push, pull,
48 ** and sync. If a command-line argument is given, that is the URL
49
--- src/sync.c
+++ src/sync.c
@@ -26,23 +26,35 @@
26 #include "config.h"
27 #include "sync.h"
28 #include <assert.h>
29
30 /*
31 ** If the respository is configured for autosyncing, then do an
32 ** autosync. This will be a pull if the argument is true or a push
33 ** if the argument is false. Return true if the autosync is done
34 ** and false if autosync is not requested for the current repository.
35 */
36 int autosync(int pullFlag){
37 const char *zUrl;
38 if( db_get_int("autosync", 0)==0 ){
 
 
 
 
39 return 0;
40 }
41 zUrl = db_get("last-sync-url", 0);
42 if( zUrl ){
43 return 0; /* No default server */
44 }
45 url_parse(zUrl);
46 if( g.urlIsFile ){
47 return 0; /* Network sync only */
48 }
49 if( g.urlPort!=80 ){
50 printf("Autosync: http://%s:%d%s\n", g.urlName, g.urlPort, g.urlPath);
51 }else{
52 printf("Autosync: http://%s%s\n", g.urlName, g.urlPath);
53 }
54 client_sync(!pullFlag, pullFlag, 0);
55 return 1;
56 }
57
58 /*
59 ** This routine processes the command-line argument for push, pull,
60 ** and sync. If a command-line argument is given, that is the URL
61
+2 -6
--- src/tag.c
+++ src/tag.c
@@ -290,16 +290,12 @@
290290
db_begin_transaction();
291291
nrid = content_put(&ctrl, 0, 0);
292292
manifest_crosslink(nrid, &ctrl);
293293
db_end_transaction(0);
294294
295
- /* Autosync and do a push? */
296
- if( do_autosync() ){
297
- g.argc=2;
298
- g.argv[1]="push";
299
- push_cmd();
300
- }
295
+ /* Do an autosync push if requested */
296
+ autosync(0);
301297
}
302298
303299
/*
304300
** COMMAND: tag
305301
** Usage: %fossil tag SUBCOMMAND ...
306302
--- src/tag.c
+++ src/tag.c
@@ -290,16 +290,12 @@
290 db_begin_transaction();
291 nrid = content_put(&ctrl, 0, 0);
292 manifest_crosslink(nrid, &ctrl);
293 db_end_transaction(0);
294
295 /* Autosync and do a push? */
296 if( do_autosync() ){
297 g.argc=2;
298 g.argv[1]="push";
299 push_cmd();
300 }
301 }
302
303 /*
304 ** COMMAND: tag
305 ** Usage: %fossil tag SUBCOMMAND ...
306
--- src/tag.c
+++ src/tag.c
@@ -290,16 +290,12 @@
290 db_begin_transaction();
291 nrid = content_put(&ctrl, 0, 0);
292 manifest_crosslink(nrid, &ctrl);
293 db_end_transaction(0);
294
295 /* Do an autosync push if requested */
296 autosync(0);
 
 
 
 
297 }
298
299 /*
300 ** COMMAND: tag
301 ** Usage: %fossil tag SUBCOMMAND ...
302
+2 -5
--- src/update.c
+++ src/update.c
@@ -76,15 +76,12 @@
7676
if( !is_a_version(tid) ){
7777
fossil_fatal("not a version: %s", g.argv[2]);
7878
}
7979
}
8080
81
- if( do_autosync() ){
82
- g.argc=2;
83
- g.argv[1]="pull";
84
- pull_cmd();
85
- }
81
+ /* Do an autosync pull prior to the update, if autosync is on */
82
+ autosync(1);
8683
8784
if( tid==0 ){
8885
compute_leaves(vid);
8986
if( !latestFlag && db_int(0, "SELECT count(*) FROM leaves")>1 ){
9087
db_prepare(&q,
9188
--- src/update.c
+++ src/update.c
@@ -76,15 +76,12 @@
76 if( !is_a_version(tid) ){
77 fossil_fatal("not a version: %s", g.argv[2]);
78 }
79 }
80
81 if( do_autosync() ){
82 g.argc=2;
83 g.argv[1]="pull";
84 pull_cmd();
85 }
86
87 if( tid==0 ){
88 compute_leaves(vid);
89 if( !latestFlag && db_int(0, "SELECT count(*) FROM leaves")>1 ){
90 db_prepare(&q,
91
--- src/update.c
+++ src/update.c
@@ -76,15 +76,12 @@
76 if( !is_a_version(tid) ){
77 fossil_fatal("not a version: %s", g.argv[2]);
78 }
79 }
80
81 /* Do an autosync pull prior to the update, if autosync is on */
82 autosync(1);
 
 
 
83
84 if( tid==0 ){
85 compute_leaves(vid);
86 if( !latestFlag && db_int(0, "SELECT count(*) FROM leaves")>1 ){
87 db_prepare(&q,
88

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button