Fossil SCM
Use a new pragma requested only in the first clone cycle to track the rebuilt time on the remote server to be able to error out if the rids are rebuilt before resuming a clone. This is currently just a fossilized string but it could instead by a hash of the components to make it more like a "code". Requesting the pragma only at the beginning does not account for the possibility that a rebuild will happen after the clone begins. I find that scenario highly unlikely, but grant that it might be possible.
Commit
7f116a437ccfd18853a9f52e8f04196eda662fb069f74ad70123d5d734bbcfd1
Parent
15b166df9badce1…
1 file changed
+36
-3
+36
-3
| --- src/xfer.c | ||
| +++ src/xfer.c | ||
| @@ -1762,10 +1762,24 @@ | ||
| 1762 | 1762 | ** The client sends this message to the server to ask the server |
| 1763 | 1763 | ** to tell it about alternative repositories in the reply. |
| 1764 | 1764 | */ |
| 1765 | 1765 | if( blob_eq(&xfer.aToken[1], "req-links") ){ |
| 1766 | 1766 | bSendLinks = 1; |
| 1767 | + }else | |
| 1768 | + | |
| 1769 | + /* pragma send-rebuilt | |
| 1770 | + ** | |
| 1771 | + ** The client sends this message to the server to ask the server | |
| 1772 | + ** for the last time its database was rebuilt | |
| 1773 | + */ | |
| 1774 | + if( blob_eq(&xfer.aToken[1], "send-rebuilt") ){ | |
| 1775 | + Blob rcode; | |
| 1776 | + blob_zero(&rcode); | |
| 1777 | + blob_appendf(&rcode, "%s-%s", db_get("server-code",0), | |
| 1778 | + db_get("rebuilt",0)); | |
| 1779 | + @ pragma rebuilt %F(blob_str(&rcode)) | |
| 1780 | + blob_reset(&rcode); | |
| 1767 | 1781 | } |
| 1768 | 1782 | |
| 1769 | 1783 | }else |
| 1770 | 1784 | |
| 1771 | 1785 | /* Unknown message |
| @@ -2114,10 +2128,14 @@ | ||
| 2114 | 2128 | MANIFEST_NUMERIC_TIME); |
| 2115 | 2129 | if( syncFlags & SYNC_CLONE ){ |
| 2116 | 2130 | #if !defined(_WIN32) |
| 2117 | 2131 | signal(SIGINT, sync_sigint_handler); |
| 2118 | 2132 | #endif |
| 2133 | + if( nCycle<2 ){ | |
| 2134 | + /* Only request this at the beginning of the clone */ | |
| 2135 | + blob_appendf(&send, "pragma send-rebuilt\n"); | |
| 2136 | + } | |
| 2119 | 2137 | blob_appendf(&send, "clone 3 %d\n", cloneSeqno); |
| 2120 | 2138 | syncFlags &= ~(SYNC_PUSH|SYNC_PULL); |
| 2121 | 2139 | nCardSent++; |
| 2122 | 2140 | /* TBD: Request all transferable configuration values */ |
| 2123 | 2141 | content_enable_dephantomize(0); |
| @@ -2581,13 +2599,15 @@ | ||
| 2581 | 2599 | ){ |
| 2582 | 2600 | if( zPCode==0 ){ |
| 2583 | 2601 | zPCode = mprintf("%b", &xfer.aToken[2]); |
| 2584 | 2602 | db_set("project-code", zPCode, 0); |
| 2585 | 2603 | } |
| 2586 | - if( zCCode==0 && blob_is_hname(&xfer.aToken[1]) ){ | |
| 2587 | - zCCode = mprintf("%b", &xfer.aToken[1]); | |
| 2588 | - db_set("aux-clone-code", zCCode, 0); | |
| 2604 | + if( zCCode==0 ){ | |
| 2605 | + if( blob_is_hname(&xfer.aToken[1]) ){ | |
| 2606 | + zCCode = mprintf("%b", &xfer.aToken[1]); | |
| 2607 | + db_set("aux-clone-code", zCCode, 0); | |
| 2608 | + } | |
| 2589 | 2609 | } |
| 2590 | 2610 | if( cloneSeqno>0 ) blob_appendf(&send, "clone 3 %d\n", cloneSeqno); |
| 2591 | 2611 | nCardSent++; |
| 2592 | 2612 | }else |
| 2593 | 2613 | |
| @@ -2773,10 +2793,23 @@ | ||
| 2773 | 2793 | ); |
| 2774 | 2794 | db_protect_pop(); |
| 2775 | 2795 | } |
| 2776 | 2796 | url_unparse(&x); |
| 2777 | 2797 | } |
| 2798 | + | |
| 2799 | + /* pragma rebuilt FOSSILISZESTRING | |
| 2800 | + ** | |
| 2801 | + ** The server generates this message in response to a client request | |
| 2802 | + ** that is trying to resume. | |
| 2803 | + */ | |
| 2804 | + else if( blob_eq(&xfer.aToken[1], "rebuilt") | |
| 2805 | + && xfer.nToken==3 | |
| 2806 | + && (syncFlags & SYNC_CLONE)!=0 | |
| 2807 | + ){ | |
| 2808 | + zCCode = mprintf("%b", &xfer.aToken[2]); | |
| 2809 | + db_set("aux-clone-code", zCCode, 0); | |
| 2810 | + } | |
| 2778 | 2811 | |
| 2779 | 2812 | }else |
| 2780 | 2813 | |
| 2781 | 2814 | /* error MESSAGE |
| 2782 | 2815 | ** |
| 2783 | 2816 |
| --- src/xfer.c | |
| +++ src/xfer.c | |
| @@ -1762,10 +1762,24 @@ | |
| 1762 | ** The client sends this message to the server to ask the server |
| 1763 | ** to tell it about alternative repositories in the reply. |
| 1764 | */ |
| 1765 | if( blob_eq(&xfer.aToken[1], "req-links") ){ |
| 1766 | bSendLinks = 1; |
| 1767 | } |
| 1768 | |
| 1769 | }else |
| 1770 | |
| 1771 | /* Unknown message |
| @@ -2114,10 +2128,14 @@ | |
| 2114 | MANIFEST_NUMERIC_TIME); |
| 2115 | if( syncFlags & SYNC_CLONE ){ |
| 2116 | #if !defined(_WIN32) |
| 2117 | signal(SIGINT, sync_sigint_handler); |
| 2118 | #endif |
| 2119 | blob_appendf(&send, "clone 3 %d\n", cloneSeqno); |
| 2120 | syncFlags &= ~(SYNC_PUSH|SYNC_PULL); |
| 2121 | nCardSent++; |
| 2122 | /* TBD: Request all transferable configuration values */ |
| 2123 | content_enable_dephantomize(0); |
| @@ -2581,13 +2599,15 @@ | |
| 2581 | ){ |
| 2582 | if( zPCode==0 ){ |
| 2583 | zPCode = mprintf("%b", &xfer.aToken[2]); |
| 2584 | db_set("project-code", zPCode, 0); |
| 2585 | } |
| 2586 | if( zCCode==0 && blob_is_hname(&xfer.aToken[1]) ){ |
| 2587 | zCCode = mprintf("%b", &xfer.aToken[1]); |
| 2588 | db_set("aux-clone-code", zCCode, 0); |
| 2589 | } |
| 2590 | if( cloneSeqno>0 ) blob_appendf(&send, "clone 3 %d\n", cloneSeqno); |
| 2591 | nCardSent++; |
| 2592 | }else |
| 2593 | |
| @@ -2773,10 +2793,23 @@ | |
| 2773 | ); |
| 2774 | db_protect_pop(); |
| 2775 | } |
| 2776 | url_unparse(&x); |
| 2777 | } |
| 2778 | |
| 2779 | }else |
| 2780 | |
| 2781 | /* error MESSAGE |
| 2782 | ** |
| 2783 |
| --- src/xfer.c | |
| +++ src/xfer.c | |
| @@ -1762,10 +1762,24 @@ | |
| 1762 | ** The client sends this message to the server to ask the server |
| 1763 | ** to tell it about alternative repositories in the reply. |
| 1764 | */ |
| 1765 | if( blob_eq(&xfer.aToken[1], "req-links") ){ |
| 1766 | bSendLinks = 1; |
| 1767 | }else |
| 1768 | |
| 1769 | /* pragma send-rebuilt |
| 1770 | ** |
| 1771 | ** The client sends this message to the server to ask the server |
| 1772 | ** for the last time its database was rebuilt |
| 1773 | */ |
| 1774 | if( blob_eq(&xfer.aToken[1], "send-rebuilt") ){ |
| 1775 | Blob rcode; |
| 1776 | blob_zero(&rcode); |
| 1777 | blob_appendf(&rcode, "%s-%s", db_get("server-code",0), |
| 1778 | db_get("rebuilt",0)); |
| 1779 | @ pragma rebuilt %F(blob_str(&rcode)) |
| 1780 | blob_reset(&rcode); |
| 1781 | } |
| 1782 | |
| 1783 | }else |
| 1784 | |
| 1785 | /* Unknown message |
| @@ -2114,10 +2128,14 @@ | |
| 2128 | MANIFEST_NUMERIC_TIME); |
| 2129 | if( syncFlags & SYNC_CLONE ){ |
| 2130 | #if !defined(_WIN32) |
| 2131 | signal(SIGINT, sync_sigint_handler); |
| 2132 | #endif |
| 2133 | if( nCycle<2 ){ |
| 2134 | /* Only request this at the beginning of the clone */ |
| 2135 | blob_appendf(&send, "pragma send-rebuilt\n"); |
| 2136 | } |
| 2137 | blob_appendf(&send, "clone 3 %d\n", cloneSeqno); |
| 2138 | syncFlags &= ~(SYNC_PUSH|SYNC_PULL); |
| 2139 | nCardSent++; |
| 2140 | /* TBD: Request all transferable configuration values */ |
| 2141 | content_enable_dephantomize(0); |
| @@ -2581,13 +2599,15 @@ | |
| 2599 | ){ |
| 2600 | if( zPCode==0 ){ |
| 2601 | zPCode = mprintf("%b", &xfer.aToken[2]); |
| 2602 | db_set("project-code", zPCode, 0); |
| 2603 | } |
| 2604 | if( zCCode==0 ){ |
| 2605 | if( blob_is_hname(&xfer.aToken[1]) ){ |
| 2606 | zCCode = mprintf("%b", &xfer.aToken[1]); |
| 2607 | db_set("aux-clone-code", zCCode, 0); |
| 2608 | } |
| 2609 | } |
| 2610 | if( cloneSeqno>0 ) blob_appendf(&send, "clone 3 %d\n", cloneSeqno); |
| 2611 | nCardSent++; |
| 2612 | }else |
| 2613 | |
| @@ -2773,10 +2793,23 @@ | |
| 2793 | ); |
| 2794 | db_protect_pop(); |
| 2795 | } |
| 2796 | url_unparse(&x); |
| 2797 | } |
| 2798 | |
| 2799 | /* pragma rebuilt FOSSILISZESTRING |
| 2800 | ** |
| 2801 | ** The server generates this message in response to a client request |
| 2802 | ** that is trying to resume. |
| 2803 | */ |
| 2804 | else if( blob_eq(&xfer.aToken[1], "rebuilt") |
| 2805 | && xfer.nToken==3 |
| 2806 | && (syncFlags & SYNC_CLONE)!=0 |
| 2807 | ){ |
| 2808 | zCCode = mprintf("%b", &xfer.aToken[2]); |
| 2809 | db_set("aux-clone-code", zCCode, 0); |
| 2810 | } |
| 2811 | |
| 2812 | }else |
| 2813 | |
| 2814 | /* error MESSAGE |
| 2815 | ** |
| 2816 |