Fossil SCM

If autosync fails, try again to defined maximum with a 1 second sleep between failures.

andybradford 2014-04-21 07:43 trunk
Commit fae1eca8f67e9a8623609d61fdceb47951c9eedb
2 files changed +2 -2 +24 -1
+2 -2
--- src/checkin.c
+++ src/checkin.c
@@ -1547,11 +1547,11 @@
15471547
15481548
/*
15491549
** Autosync if autosync is enabled and this is not a private check-in.
15501550
*/
15511551
if( !g.markPrivate ){
1552
- if( autosync(SYNC_PULL) ){
1552
+ if( autosync_loop(SYNC_PULL) ){
15531553
prompt_user("continue in spite of sync failure (y/N)? ", &ans);
15541554
cReply = blob_str(&ans)[0];
15551555
if( cReply!='y' && cReply!='Y' ){
15561556
fossil_exit(1);
15571557
}
@@ -1932,11 +1932,11 @@
19321932
exit(1);
19331933
}
19341934
db_end_transaction(0);
19351935
19361936
if( !g.markPrivate ){
1937
- autosync(SYNC_PUSH|SYNC_PULL);
1937
+ autosync_loop(SYNC_PUSH|SYNC_PULL);
19381938
}
19391939
if( count_nonbranch_children(vid)>1 ){
19401940
fossil_print("**** warning: a fork has occurred *****\n");
19411941
}
19421942
}
19431943
--- src/checkin.c
+++ src/checkin.c
@@ -1547,11 +1547,11 @@
1547
1548 /*
1549 ** Autosync if autosync is enabled and this is not a private check-in.
1550 */
1551 if( !g.markPrivate ){
1552 if( autosync(SYNC_PULL) ){
1553 prompt_user("continue in spite of sync failure (y/N)? ", &ans);
1554 cReply = blob_str(&ans)[0];
1555 if( cReply!='y' && cReply!='Y' ){
1556 fossil_exit(1);
1557 }
@@ -1932,11 +1932,11 @@
1932 exit(1);
1933 }
1934 db_end_transaction(0);
1935
1936 if( !g.markPrivate ){
1937 autosync(SYNC_PUSH|SYNC_PULL);
1938 }
1939 if( count_nonbranch_children(vid)>1 ){
1940 fossil_print("**** warning: a fork has occurred *****\n");
1941 }
1942 }
1943
--- src/checkin.c
+++ src/checkin.c
@@ -1547,11 +1547,11 @@
1547
1548 /*
1549 ** Autosync if autosync is enabled and this is not a private check-in.
1550 */
1551 if( !g.markPrivate ){
1552 if( autosync_loop(SYNC_PULL) ){
1553 prompt_user("continue in spite of sync failure (y/N)? ", &ans);
1554 cReply = blob_str(&ans)[0];
1555 if( cReply!='y' && cReply!='Y' ){
1556 fossil_exit(1);
1557 }
@@ -1932,11 +1932,11 @@
1932 exit(1);
1933 }
1934 db_end_transaction(0);
1935
1936 if( !g.markPrivate ){
1937 autosync_loop(SYNC_PUSH|SYNC_PULL);
1938 }
1939 if( count_nonbranch_children(vid)>1 ){
1940 fossil_print("**** warning: a fork has occurred *****\n");
1941 }
1942 }
1943
+24 -1
--- src/sync.c
+++ src/sync.c
@@ -19,10 +19,19 @@
1919
*/
2020
#include "config.h"
2121
#include "sync.h"
2222
#include <assert.h>
2323
24
+#if defined(_WIN32)
25
+# include <windows.h> /* for Sleep */
26
+# if defined(__MINGW32__) || defined(_MSC_VER)
27
+# define sleep Sleep /* windows does not have sleep, but Sleep */
28
+# endif
29
+#endif
30
+
31
+#define AUTOSYNC_TRIES 3
32
+
2433
/*
2534
** If the repository is configured for autosyncing, then do an
2635
** autosync. This will be a pull if the argument is true or a push
2736
** if the argument is false.
2837
**
@@ -72,11 +81,25 @@
7281
#endif
7382
if( find_option("verbose","v",0)!=0 ) flags |= SYNC_VERBOSE;
7483
fossil_print("Autosync: %s\n", g.url.canonical);
7584
url_enable_proxy("via proxy: ");
7685
rc = client_sync(flags, configSync, 0);
77
- if( rc ) fossil_warning("Autosync failed");
86
+ return rc;
87
+}
88
+
89
+/*
90
+** This routine will try a number of times to perform autosync with a
91
+** 1 second sleep between attempts; returning the last autosync status.
92
+*/
93
+int autosync_loop(int flags){
94
+ int n = 0;
95
+ int rc = 0;
96
+ while (n++ < AUTOSYNC_TRIES && (rc = autosync(flags))){
97
+ if( rc ) fossil_warning("Autosync failed%s",
98
+ n < AUTOSYNC_TRIES ? ", making another attempt." : ".");
99
+ sleep(1);
100
+ }
78101
return rc;
79102
}
80103
81104
/*
82105
** This routine processes the command-line argument for push, pull,
83106
--- src/sync.c
+++ src/sync.c
@@ -19,10 +19,19 @@
19 */
20 #include "config.h"
21 #include "sync.h"
22 #include <assert.h>
23
 
 
 
 
 
 
 
 
 
24 /*
25 ** If the repository is configured for autosyncing, then do an
26 ** autosync. This will be a pull if the argument is true or a push
27 ** if the argument is false.
28 **
@@ -72,11 +81,25 @@
72 #endif
73 if( find_option("verbose","v",0)!=0 ) flags |= SYNC_VERBOSE;
74 fossil_print("Autosync: %s\n", g.url.canonical);
75 url_enable_proxy("via proxy: ");
76 rc = client_sync(flags, configSync, 0);
77 if( rc ) fossil_warning("Autosync failed");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78 return rc;
79 }
80
81 /*
82 ** This routine processes the command-line argument for push, pull,
83
--- src/sync.c
+++ src/sync.c
@@ -19,10 +19,19 @@
19 */
20 #include "config.h"
21 #include "sync.h"
22 #include <assert.h>
23
24 #if defined(_WIN32)
25 # include <windows.h> /* for Sleep */
26 # if defined(__MINGW32__) || defined(_MSC_VER)
27 # define sleep Sleep /* windows does not have sleep, but Sleep */
28 # endif
29 #endif
30
31 #define AUTOSYNC_TRIES 3
32
33 /*
34 ** If the repository is configured for autosyncing, then do an
35 ** autosync. This will be a pull if the argument is true or a push
36 ** if the argument is false.
37 **
@@ -72,11 +81,25 @@
81 #endif
82 if( find_option("verbose","v",0)!=0 ) flags |= SYNC_VERBOSE;
83 fossil_print("Autosync: %s\n", g.url.canonical);
84 url_enable_proxy("via proxy: ");
85 rc = client_sync(flags, configSync, 0);
86 return rc;
87 }
88
89 /*
90 ** This routine will try a number of times to perform autosync with a
91 ** 1 second sleep between attempts; returning the last autosync status.
92 */
93 int autosync_loop(int flags){
94 int n = 0;
95 int rc = 0;
96 while (n++ < AUTOSYNC_TRIES && (rc = autosync(flags))){
97 if( rc ) fossil_warning("Autosync failed%s",
98 n < AUTOSYNC_TRIES ? ", making another attempt." : ".");
99 sleep(1);
100 }
101 return rc;
102 }
103
104 /*
105 ** This routine processes the command-line argument for push, pull,
106

Keyboard Shortcuts

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