Fossil SCM
merge from trunk
Commit
e1d15514fba78718c82831236a01a513ecef459a
Parent
a5cd79272f1287b…
2 files changed
+103
-11
+103
-11
+103
-11
| --- src/manifest.c | ||
| +++ src/manifest.c | ||
| @@ -83,10 +83,22 @@ | ||
| 83 | 83 | char *zValue; /* Value of the field */ |
| 84 | 84 | } *aField; /* One for each J card */ |
| 85 | 85 | }; |
| 86 | 86 | #endif |
| 87 | 87 | |
| 88 | +/* | |
| 89 | +** A cache of parsed manifests. This reduces the number of | |
| 90 | +** calls to manifest_parse() when doing a rebuild. | |
| 91 | +*/ | |
| 92 | +#define MX_MANIFEST_CACHE 4 | |
| 93 | +static struct { | |
| 94 | + int nxAge; | |
| 95 | + int aRid[MX_MANIFEST_CACHE]; | |
| 96 | + int aAge[MX_MANIFEST_CACHE]; | |
| 97 | + Manifest aLine[MX_MANIFEST_CACHE]; | |
| 98 | +} manifestCache; | |
| 99 | + | |
| 88 | 100 | |
| 89 | 101 | /* |
| 90 | 102 | ** Clear the memory allocated in a manifest object |
| 91 | 103 | */ |
| 92 | 104 | void manifest_clear(Manifest *p){ |
| @@ -97,10 +109,69 @@ | ||
| 97 | 109 | free(p->aTag); |
| 98 | 110 | free(p->aField); |
| 99 | 111 | memset(p, 0, sizeof(*p)); |
| 100 | 112 | } |
| 101 | 113 | |
| 114 | +/* | |
| 115 | +** Add an element to the manifest cache using LRU replacement. | |
| 116 | +*/ | |
| 117 | +void manifest_cache_insert(int rid, Manifest *p){ | |
| 118 | + int i; | |
| 119 | + for(i=0; i<MX_MANIFEST_CACHE; i++){ | |
| 120 | + if( manifestCache.aRid[i]==0 ) break; | |
| 121 | + } | |
| 122 | + if( i>=MX_MANIFEST_CACHE ){ | |
| 123 | + int oldest = 0; | |
| 124 | + int oldestAge = manifestCache.aAge[0]; | |
| 125 | + for(i=1; i<MX_MANIFEST_CACHE; i++){ | |
| 126 | + if( manifestCache.aAge[i]<oldestAge ){ | |
| 127 | + oldest = i; | |
| 128 | + oldestAge = manifestCache.aAge[i]; | |
| 129 | + } | |
| 130 | + } | |
| 131 | + manifest_clear(&manifestCache.aLine[oldest]); | |
| 132 | + i = oldest; | |
| 133 | + } | |
| 134 | + manifestCache.aAge[i] = ++manifestCache.nxAge; | |
| 135 | + manifestCache.aRid[i] = rid; | |
| 136 | + manifestCache.aLine[i] = *p; | |
| 137 | +} | |
| 138 | + | |
| 139 | +/* | |
| 140 | +** Try to extract a line from the manifest cache. Return 1 if found. | |
| 141 | +** Return 0 if not found. | |
| 142 | +*/ | |
| 143 | +int manifest_cache_find(int rid, Manifest *p){ | |
| 144 | + int i; | |
| 145 | + for(i=0; i<MX_MANIFEST_CACHE; i++){ | |
| 146 | + if( manifestCache.aRid[i]==rid ){ | |
| 147 | + *p = manifestCache.aLine[i]; | |
| 148 | + manifestCache.aRid[i] = 0; | |
| 149 | + return 1; | |
| 150 | + } | |
| 151 | + } | |
| 152 | + return 0; | |
| 153 | +} | |
| 154 | + | |
| 155 | +/* | |
| 156 | +** Clear the manifest cache. | |
| 157 | +*/ | |
| 158 | +void manifest_cache_clear(void){ | |
| 159 | + int i; | |
| 160 | + for(i=0; i<MX_MANIFEST_CACHE; i++){ | |
| 161 | + if( manifestCache.aRid[i]>0 ){ | |
| 162 | + manifest_clear(&manifestCache.aLine[i]); | |
| 163 | + } | |
| 164 | + } | |
| 165 | + memset(&manifestCache, 0, sizeof(manifestCache)); | |
| 166 | +} | |
| 167 | + | |
| 168 | +#ifdef FOSSIL_DONT_VERIFY_MANIFEST_MD5SUM | |
| 169 | +# define md5sum_init(X) | |
| 170 | +# define md5sum_step_text(X,Y) | |
| 171 | +#endif | |
| 172 | + | |
| 102 | 173 | /* |
| 103 | 174 | ** Parse a blob into a Manifest object. The Manifest object |
| 104 | 175 | ** takes over the input blob and will free it when the |
| 105 | 176 | ** Manifest object is freed. Zeros are inserted into the blob |
| 106 | 177 | ** as string terminators so that blob should not be used again. |
| @@ -569,20 +640,24 @@ | ||
| 569 | 640 | ** This card is required for all control file types except for |
| 570 | 641 | ** Manifest. It is not required for manifest only for historical |
| 571 | 642 | ** compatibility reasons. |
| 572 | 643 | */ |
| 573 | 644 | case 'Z': { |
| 645 | +#ifndef FOSSIL_DONT_VERIFY_MANIFEST_MD5SUM | |
| 574 | 646 | int rc; |
| 575 | 647 | Blob hash; |
| 648 | +#endif | |
| 576 | 649 | if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error; |
| 577 | 650 | if( blob_token(&line, &a2)!=0 ) goto manifest_syntax_error; |
| 578 | 651 | if( blob_size(&a1)!=32 ) goto manifest_syntax_error; |
| 579 | 652 | if( !validate16(blob_buffer(&a1), 32) ) goto manifest_syntax_error; |
| 653 | +#ifndef FOSSIL_DONT_VERIFY_MANIFEST_MD5SUM | |
| 580 | 654 | md5sum_finish(&hash); |
| 581 | 655 | rc = blob_compare(&hash, &a1); |
| 582 | 656 | blob_reset(&hash); |
| 583 | 657 | if( rc!=0 ) goto manifest_syntax_error; |
| 658 | +#endif | |
| 584 | 659 | seenZ = 1; |
| 585 | 660 | break; |
| 586 | 661 | } |
| 587 | 662 | default: { |
| 588 | 663 | goto manifest_syntax_error; |
| @@ -686,24 +761,31 @@ | ||
| 686 | 761 | } |
| 687 | 762 | |
| 688 | 763 | /* |
| 689 | 764 | ** COMMAND: test-parse-manifest |
| 690 | 765 | ** |
| 691 | -** Usage: %fossil test-parse-manifest FILENAME | |
| 766 | +** Usage: %fossil test-parse-manifest FILENAME ?N? | |
| 692 | 767 | ** |
| 693 | 768 | ** Parse the manifest and discarded. Use for testing only. |
| 694 | 769 | */ |
| 695 | 770 | void manifest_test_parse_cmd(void){ |
| 696 | 771 | Manifest m; |
| 697 | 772 | Blob b; |
| 698 | - if( g.argc!=3 ){ | |
| 773 | + int i; | |
| 774 | + int n = 1; | |
| 775 | + if( g.argc!=3 && g.argc!=4 ){ | |
| 699 | 776 | usage("FILENAME"); |
| 700 | 777 | } |
| 701 | 778 | db_must_be_within_tree(); |
| 702 | 779 | blob_read_from_file(&b, g.argv[2]); |
| 703 | - manifest_parse(&m, &b); | |
| 704 | - manifest_clear(&m); | |
| 780 | + if( g.argc>3 ) n = atoi(g.argv[3]); | |
| 781 | + for(i=0; i<n; i++){ | |
| 782 | + Blob b2; | |
| 783 | + blob_copy(&b2, &b); | |
| 784 | + manifest_parse(&m, &b2); | |
| 785 | + manifest_clear(&m); | |
| 786 | + } | |
| 705 | 787 | } |
| 706 | 788 | |
| 707 | 789 | /* |
| 708 | 790 | ** Translate a filename into a filename-id (fnid). Create a new fnid |
| 709 | 791 | ** if no previously exists. |
| @@ -810,25 +892,29 @@ | ||
| 810 | 892 | ** Edited files have both mlink.pid!=0 and mlink.fid!=0 |
| 811 | 893 | */ |
| 812 | 894 | static void add_mlink(int pid, Manifest *pParent, int cid, Manifest *pChild){ |
| 813 | 895 | Manifest other; |
| 814 | 896 | Blob otherContent; |
| 897 | + int otherRid; | |
| 815 | 898 | int i, j; |
| 816 | 899 | |
| 817 | 900 | if( db_exists("SELECT 1 FROM mlink WHERE mid=%d", cid) ){ |
| 818 | 901 | return; |
| 819 | 902 | } |
| 820 | 903 | assert( pParent==0 || pChild==0 ); |
| 821 | 904 | if( pParent==0 ){ |
| 822 | 905 | pParent = &other; |
| 823 | - content_get(pid, &otherContent); | |
| 906 | + otherRid = pid; | |
| 824 | 907 | }else{ |
| 825 | 908 | pChild = &other; |
| 826 | - content_get(cid, &otherContent); | |
| 909 | + otherRid = cid; | |
| 827 | 910 | } |
| 828 | - if( blob_size(&otherContent)==0 ) return; | |
| 829 | - if( manifest_parse(&other, &otherContent)==0 ) return; | |
| 911 | + if( manifest_cache_find(otherRid, &other)==0 ){ | |
| 912 | + content_get(otherRid, &otherContent); | |
| 913 | + if( blob_size(&otherContent)==0 ) return; | |
| 914 | + if( manifest_parse(&other, &otherContent)==0 ) return; | |
| 915 | + } | |
| 830 | 916 | content_deltify(pid, cid, 0); |
| 831 | 917 | |
| 832 | 918 | /* Use the iRename fields to find the cross-linkage between |
| 833 | 919 | ** renamed files. */ |
| 834 | 920 | for(j=0; j<pChild->nFile; j++){ |
| @@ -882,11 +968,11 @@ | ||
| 882 | 968 | }else{ |
| 883 | 969 | add_one_mlink(cid, 0, pChild->aFile[j].zUuid, pChild->aFile[j].zName,0); |
| 884 | 970 | } |
| 885 | 971 | j++; |
| 886 | 972 | } |
| 887 | - manifest_clear(&other); | |
| 973 | + manifest_cache_insert(otherRid, &other); | |
| 888 | 974 | } |
| 889 | 975 | |
| 890 | 976 | /* |
| 891 | 977 | ** True if manifest_crosslink_begin() has been called but |
| 892 | 978 | ** manifest_crosslink_end() is still pending. |
| @@ -1027,11 +1113,13 @@ | ||
| 1027 | 1113 | int i; |
| 1028 | 1114 | Manifest m; |
| 1029 | 1115 | Stmt q; |
| 1030 | 1116 | int parentid = 0; |
| 1031 | 1117 | |
| 1032 | - if( manifest_parse(&m, pContent)==0 ){ | |
| 1118 | + if( manifest_cache_find(rid, &m) ){ | |
| 1119 | + blob_reset(pContent); | |
| 1120 | + }else if( manifest_parse(&m, pContent)==0 ){ | |
| 1033 | 1121 | return 0; |
| 1034 | 1122 | } |
| 1035 | 1123 | if( g.xlinkClusterOnly && m.type!=CFTYPE_CLUSTER ){ |
| 1036 | 1124 | manifest_clear(&m); |
| 1037 | 1125 | return 0; |
| @@ -1263,11 +1351,15 @@ | ||
| 1263 | 1351 | ); |
| 1264 | 1352 | free(zComment); |
| 1265 | 1353 | } |
| 1266 | 1354 | } |
| 1267 | 1355 | db_end_transaction(0); |
| 1268 | - manifest_clear(&m); | |
| 1356 | + if( m.type==CFTYPE_MANIFEST ){ | |
| 1357 | + manifest_cache_insert(rid, &m); | |
| 1358 | + }else{ | |
| 1359 | + manifest_clear(&m); | |
| 1360 | + } | |
| 1269 | 1361 | return 1; |
| 1270 | 1362 | } |
| 1271 | 1363 | |
| 1272 | 1364 | /* |
| 1273 | 1365 | ** Given a checkin name, load and parse the manifest for that checkin. |
| 1274 | 1366 |
| --- src/manifest.c | |
| +++ src/manifest.c | |
| @@ -83,10 +83,22 @@ | |
| 83 | char *zValue; /* Value of the field */ |
| 84 | } *aField; /* One for each J card */ |
| 85 | }; |
| 86 | #endif |
| 87 | |
| 88 | |
| 89 | /* |
| 90 | ** Clear the memory allocated in a manifest object |
| 91 | */ |
| 92 | void manifest_clear(Manifest *p){ |
| @@ -97,10 +109,69 @@ | |
| 97 | free(p->aTag); |
| 98 | free(p->aField); |
| 99 | memset(p, 0, sizeof(*p)); |
| 100 | } |
| 101 | |
| 102 | /* |
| 103 | ** Parse a blob into a Manifest object. The Manifest object |
| 104 | ** takes over the input blob and will free it when the |
| 105 | ** Manifest object is freed. Zeros are inserted into the blob |
| 106 | ** as string terminators so that blob should not be used again. |
| @@ -569,20 +640,24 @@ | |
| 569 | ** This card is required for all control file types except for |
| 570 | ** Manifest. It is not required for manifest only for historical |
| 571 | ** compatibility reasons. |
| 572 | */ |
| 573 | case 'Z': { |
| 574 | int rc; |
| 575 | Blob hash; |
| 576 | if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error; |
| 577 | if( blob_token(&line, &a2)!=0 ) goto manifest_syntax_error; |
| 578 | if( blob_size(&a1)!=32 ) goto manifest_syntax_error; |
| 579 | if( !validate16(blob_buffer(&a1), 32) ) goto manifest_syntax_error; |
| 580 | md5sum_finish(&hash); |
| 581 | rc = blob_compare(&hash, &a1); |
| 582 | blob_reset(&hash); |
| 583 | if( rc!=0 ) goto manifest_syntax_error; |
| 584 | seenZ = 1; |
| 585 | break; |
| 586 | } |
| 587 | default: { |
| 588 | goto manifest_syntax_error; |
| @@ -686,24 +761,31 @@ | |
| 686 | } |
| 687 | |
| 688 | /* |
| 689 | ** COMMAND: test-parse-manifest |
| 690 | ** |
| 691 | ** Usage: %fossil test-parse-manifest FILENAME |
| 692 | ** |
| 693 | ** Parse the manifest and discarded. Use for testing only. |
| 694 | */ |
| 695 | void manifest_test_parse_cmd(void){ |
| 696 | Manifest m; |
| 697 | Blob b; |
| 698 | if( g.argc!=3 ){ |
| 699 | usage("FILENAME"); |
| 700 | } |
| 701 | db_must_be_within_tree(); |
| 702 | blob_read_from_file(&b, g.argv[2]); |
| 703 | manifest_parse(&m, &b); |
| 704 | manifest_clear(&m); |
| 705 | } |
| 706 | |
| 707 | /* |
| 708 | ** Translate a filename into a filename-id (fnid). Create a new fnid |
| 709 | ** if no previously exists. |
| @@ -810,25 +892,29 @@ | |
| 810 | ** Edited files have both mlink.pid!=0 and mlink.fid!=0 |
| 811 | */ |
| 812 | static void add_mlink(int pid, Manifest *pParent, int cid, Manifest *pChild){ |
| 813 | Manifest other; |
| 814 | Blob otherContent; |
| 815 | int i, j; |
| 816 | |
| 817 | if( db_exists("SELECT 1 FROM mlink WHERE mid=%d", cid) ){ |
| 818 | return; |
| 819 | } |
| 820 | assert( pParent==0 || pChild==0 ); |
| 821 | if( pParent==0 ){ |
| 822 | pParent = &other; |
| 823 | content_get(pid, &otherContent); |
| 824 | }else{ |
| 825 | pChild = &other; |
| 826 | content_get(cid, &otherContent); |
| 827 | } |
| 828 | if( blob_size(&otherContent)==0 ) return; |
| 829 | if( manifest_parse(&other, &otherContent)==0 ) return; |
| 830 | content_deltify(pid, cid, 0); |
| 831 | |
| 832 | /* Use the iRename fields to find the cross-linkage between |
| 833 | ** renamed files. */ |
| 834 | for(j=0; j<pChild->nFile; j++){ |
| @@ -882,11 +968,11 @@ | |
| 882 | }else{ |
| 883 | add_one_mlink(cid, 0, pChild->aFile[j].zUuid, pChild->aFile[j].zName,0); |
| 884 | } |
| 885 | j++; |
| 886 | } |
| 887 | manifest_clear(&other); |
| 888 | } |
| 889 | |
| 890 | /* |
| 891 | ** True if manifest_crosslink_begin() has been called but |
| 892 | ** manifest_crosslink_end() is still pending. |
| @@ -1027,11 +1113,13 @@ | |
| 1027 | int i; |
| 1028 | Manifest m; |
| 1029 | Stmt q; |
| 1030 | int parentid = 0; |
| 1031 | |
| 1032 | if( manifest_parse(&m, pContent)==0 ){ |
| 1033 | return 0; |
| 1034 | } |
| 1035 | if( g.xlinkClusterOnly && m.type!=CFTYPE_CLUSTER ){ |
| 1036 | manifest_clear(&m); |
| 1037 | return 0; |
| @@ -1263,11 +1351,15 @@ | |
| 1263 | ); |
| 1264 | free(zComment); |
| 1265 | } |
| 1266 | } |
| 1267 | db_end_transaction(0); |
| 1268 | manifest_clear(&m); |
| 1269 | return 1; |
| 1270 | } |
| 1271 | |
| 1272 | /* |
| 1273 | ** Given a checkin name, load and parse the manifest for that checkin. |
| 1274 |
| --- src/manifest.c | |
| +++ src/manifest.c | |
| @@ -83,10 +83,22 @@ | |
| 83 | char *zValue; /* Value of the field */ |
| 84 | } *aField; /* One for each J card */ |
| 85 | }; |
| 86 | #endif |
| 87 | |
| 88 | /* |
| 89 | ** A cache of parsed manifests. This reduces the number of |
| 90 | ** calls to manifest_parse() when doing a rebuild. |
| 91 | */ |
| 92 | #define MX_MANIFEST_CACHE 4 |
| 93 | static struct { |
| 94 | int nxAge; |
| 95 | int aRid[MX_MANIFEST_CACHE]; |
| 96 | int aAge[MX_MANIFEST_CACHE]; |
| 97 | Manifest aLine[MX_MANIFEST_CACHE]; |
| 98 | } manifestCache; |
| 99 | |
| 100 | |
| 101 | /* |
| 102 | ** Clear the memory allocated in a manifest object |
| 103 | */ |
| 104 | void manifest_clear(Manifest *p){ |
| @@ -97,10 +109,69 @@ | |
| 109 | free(p->aTag); |
| 110 | free(p->aField); |
| 111 | memset(p, 0, sizeof(*p)); |
| 112 | } |
| 113 | |
| 114 | /* |
| 115 | ** Add an element to the manifest cache using LRU replacement. |
| 116 | */ |
| 117 | void manifest_cache_insert(int rid, Manifest *p){ |
| 118 | int i; |
| 119 | for(i=0; i<MX_MANIFEST_CACHE; i++){ |
| 120 | if( manifestCache.aRid[i]==0 ) break; |
| 121 | } |
| 122 | if( i>=MX_MANIFEST_CACHE ){ |
| 123 | int oldest = 0; |
| 124 | int oldestAge = manifestCache.aAge[0]; |
| 125 | for(i=1; i<MX_MANIFEST_CACHE; i++){ |
| 126 | if( manifestCache.aAge[i]<oldestAge ){ |
| 127 | oldest = i; |
| 128 | oldestAge = manifestCache.aAge[i]; |
| 129 | } |
| 130 | } |
| 131 | manifest_clear(&manifestCache.aLine[oldest]); |
| 132 | i = oldest; |
| 133 | } |
| 134 | manifestCache.aAge[i] = ++manifestCache.nxAge; |
| 135 | manifestCache.aRid[i] = rid; |
| 136 | manifestCache.aLine[i] = *p; |
| 137 | } |
| 138 | |
| 139 | /* |
| 140 | ** Try to extract a line from the manifest cache. Return 1 if found. |
| 141 | ** Return 0 if not found. |
| 142 | */ |
| 143 | int manifest_cache_find(int rid, Manifest *p){ |
| 144 | int i; |
| 145 | for(i=0; i<MX_MANIFEST_CACHE; i++){ |
| 146 | if( manifestCache.aRid[i]==rid ){ |
| 147 | *p = manifestCache.aLine[i]; |
| 148 | manifestCache.aRid[i] = 0; |
| 149 | return 1; |
| 150 | } |
| 151 | } |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | /* |
| 156 | ** Clear the manifest cache. |
| 157 | */ |
| 158 | void manifest_cache_clear(void){ |
| 159 | int i; |
| 160 | for(i=0; i<MX_MANIFEST_CACHE; i++){ |
| 161 | if( manifestCache.aRid[i]>0 ){ |
| 162 | manifest_clear(&manifestCache.aLine[i]); |
| 163 | } |
| 164 | } |
| 165 | memset(&manifestCache, 0, sizeof(manifestCache)); |
| 166 | } |
| 167 | |
| 168 | #ifdef FOSSIL_DONT_VERIFY_MANIFEST_MD5SUM |
| 169 | # define md5sum_init(X) |
| 170 | # define md5sum_step_text(X,Y) |
| 171 | #endif |
| 172 | |
| 173 | /* |
| 174 | ** Parse a blob into a Manifest object. The Manifest object |
| 175 | ** takes over the input blob and will free it when the |
| 176 | ** Manifest object is freed. Zeros are inserted into the blob |
| 177 | ** as string terminators so that blob should not be used again. |
| @@ -569,20 +640,24 @@ | |
| 640 | ** This card is required for all control file types except for |
| 641 | ** Manifest. It is not required for manifest only for historical |
| 642 | ** compatibility reasons. |
| 643 | */ |
| 644 | case 'Z': { |
| 645 | #ifndef FOSSIL_DONT_VERIFY_MANIFEST_MD5SUM |
| 646 | int rc; |
| 647 | Blob hash; |
| 648 | #endif |
| 649 | if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error; |
| 650 | if( blob_token(&line, &a2)!=0 ) goto manifest_syntax_error; |
| 651 | if( blob_size(&a1)!=32 ) goto manifest_syntax_error; |
| 652 | if( !validate16(blob_buffer(&a1), 32) ) goto manifest_syntax_error; |
| 653 | #ifndef FOSSIL_DONT_VERIFY_MANIFEST_MD5SUM |
| 654 | md5sum_finish(&hash); |
| 655 | rc = blob_compare(&hash, &a1); |
| 656 | blob_reset(&hash); |
| 657 | if( rc!=0 ) goto manifest_syntax_error; |
| 658 | #endif |
| 659 | seenZ = 1; |
| 660 | break; |
| 661 | } |
| 662 | default: { |
| 663 | goto manifest_syntax_error; |
| @@ -686,24 +761,31 @@ | |
| 761 | } |
| 762 | |
| 763 | /* |
| 764 | ** COMMAND: test-parse-manifest |
| 765 | ** |
| 766 | ** Usage: %fossil test-parse-manifest FILENAME ?N? |
| 767 | ** |
| 768 | ** Parse the manifest and discarded. Use for testing only. |
| 769 | */ |
| 770 | void manifest_test_parse_cmd(void){ |
| 771 | Manifest m; |
| 772 | Blob b; |
| 773 | int i; |
| 774 | int n = 1; |
| 775 | if( g.argc!=3 && g.argc!=4 ){ |
| 776 | usage("FILENAME"); |
| 777 | } |
| 778 | db_must_be_within_tree(); |
| 779 | blob_read_from_file(&b, g.argv[2]); |
| 780 | if( g.argc>3 ) n = atoi(g.argv[3]); |
| 781 | for(i=0; i<n; i++){ |
| 782 | Blob b2; |
| 783 | blob_copy(&b2, &b); |
| 784 | manifest_parse(&m, &b2); |
| 785 | manifest_clear(&m); |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | /* |
| 790 | ** Translate a filename into a filename-id (fnid). Create a new fnid |
| 791 | ** if no previously exists. |
| @@ -810,25 +892,29 @@ | |
| 892 | ** Edited files have both mlink.pid!=0 and mlink.fid!=0 |
| 893 | */ |
| 894 | static void add_mlink(int pid, Manifest *pParent, int cid, Manifest *pChild){ |
| 895 | Manifest other; |
| 896 | Blob otherContent; |
| 897 | int otherRid; |
| 898 | int i, j; |
| 899 | |
| 900 | if( db_exists("SELECT 1 FROM mlink WHERE mid=%d", cid) ){ |
| 901 | return; |
| 902 | } |
| 903 | assert( pParent==0 || pChild==0 ); |
| 904 | if( pParent==0 ){ |
| 905 | pParent = &other; |
| 906 | otherRid = pid; |
| 907 | }else{ |
| 908 | pChild = &other; |
| 909 | otherRid = cid; |
| 910 | } |
| 911 | if( manifest_cache_find(otherRid, &other)==0 ){ |
| 912 | content_get(otherRid, &otherContent); |
| 913 | if( blob_size(&otherContent)==0 ) return; |
| 914 | if( manifest_parse(&other, &otherContent)==0 ) return; |
| 915 | } |
| 916 | content_deltify(pid, cid, 0); |
| 917 | |
| 918 | /* Use the iRename fields to find the cross-linkage between |
| 919 | ** renamed files. */ |
| 920 | for(j=0; j<pChild->nFile; j++){ |
| @@ -882,11 +968,11 @@ | |
| 968 | }else{ |
| 969 | add_one_mlink(cid, 0, pChild->aFile[j].zUuid, pChild->aFile[j].zName,0); |
| 970 | } |
| 971 | j++; |
| 972 | } |
| 973 | manifest_cache_insert(otherRid, &other); |
| 974 | } |
| 975 | |
| 976 | /* |
| 977 | ** True if manifest_crosslink_begin() has been called but |
| 978 | ** manifest_crosslink_end() is still pending. |
| @@ -1027,11 +1113,13 @@ | |
| 1113 | int i; |
| 1114 | Manifest m; |
| 1115 | Stmt q; |
| 1116 | int parentid = 0; |
| 1117 | |
| 1118 | if( manifest_cache_find(rid, &m) ){ |
| 1119 | blob_reset(pContent); |
| 1120 | }else if( manifest_parse(&m, pContent)==0 ){ |
| 1121 | return 0; |
| 1122 | } |
| 1123 | if( g.xlinkClusterOnly && m.type!=CFTYPE_CLUSTER ){ |
| 1124 | manifest_clear(&m); |
| 1125 | return 0; |
| @@ -1263,11 +1351,15 @@ | |
| 1351 | ); |
| 1352 | free(zComment); |
| 1353 | } |
| 1354 | } |
| 1355 | db_end_transaction(0); |
| 1356 | if( m.type==CFTYPE_MANIFEST ){ |
| 1357 | manifest_cache_insert(rid, &m); |
| 1358 | }else{ |
| 1359 | manifest_clear(&m); |
| 1360 | } |
| 1361 | return 1; |
| 1362 | } |
| 1363 | |
| 1364 | /* |
| 1365 | ** Given a checkin name, load and parse the manifest for that checkin. |
| 1366 |
+103
-11
| --- src/manifest.c | ||
| +++ src/manifest.c | ||
| @@ -83,10 +83,22 @@ | ||
| 83 | 83 | char *zValue; /* Value of the field */ |
| 84 | 84 | } *aField; /* One for each J card */ |
| 85 | 85 | }; |
| 86 | 86 | #endif |
| 87 | 87 | |
| 88 | +/* | |
| 89 | +** A cache of parsed manifests. This reduces the number of | |
| 90 | +** calls to manifest_parse() when doing a rebuild. | |
| 91 | +*/ | |
| 92 | +#define MX_MANIFEST_CACHE 4 | |
| 93 | +static struct { | |
| 94 | + int nxAge; | |
| 95 | + int aRid[MX_MANIFEST_CACHE]; | |
| 96 | + int aAge[MX_MANIFEST_CACHE]; | |
| 97 | + Manifest aLine[MX_MANIFEST_CACHE]; | |
| 98 | +} manifestCache; | |
| 99 | + | |
| 88 | 100 | |
| 89 | 101 | /* |
| 90 | 102 | ** Clear the memory allocated in a manifest object |
| 91 | 103 | */ |
| 92 | 104 | void manifest_clear(Manifest *p){ |
| @@ -97,10 +109,69 @@ | ||
| 97 | 109 | free(p->aTag); |
| 98 | 110 | free(p->aField); |
| 99 | 111 | memset(p, 0, sizeof(*p)); |
| 100 | 112 | } |
| 101 | 113 | |
| 114 | +/* | |
| 115 | +** Add an element to the manifest cache using LRU replacement. | |
| 116 | +*/ | |
| 117 | +void manifest_cache_insert(int rid, Manifest *p){ | |
| 118 | + int i; | |
| 119 | + for(i=0; i<MX_MANIFEST_CACHE; i++){ | |
| 120 | + if( manifestCache.aRid[i]==0 ) break; | |
| 121 | + } | |
| 122 | + if( i>=MX_MANIFEST_CACHE ){ | |
| 123 | + int oldest = 0; | |
| 124 | + int oldestAge = manifestCache.aAge[0]; | |
| 125 | + for(i=1; i<MX_MANIFEST_CACHE; i++){ | |
| 126 | + if( manifestCache.aAge[i]<oldestAge ){ | |
| 127 | + oldest = i; | |
| 128 | + oldestAge = manifestCache.aAge[i]; | |
| 129 | + } | |
| 130 | + } | |
| 131 | + manifest_clear(&manifestCache.aLine[oldest]); | |
| 132 | + i = oldest; | |
| 133 | + } | |
| 134 | + manifestCache.aAge[i] = ++manifestCache.nxAge; | |
| 135 | + manifestCache.aRid[i] = rid; | |
| 136 | + manifestCache.aLine[i] = *p; | |
| 137 | +} | |
| 138 | + | |
| 139 | +/* | |
| 140 | +** Try to extract a line from the manifest cache. Return 1 if found. | |
| 141 | +** Return 0 if not found. | |
| 142 | +*/ | |
| 143 | +int manifest_cache_find(int rid, Manifest *p){ | |
| 144 | + int i; | |
| 145 | + for(i=0; i<MX_MANIFEST_CACHE; i++){ | |
| 146 | + if( manifestCache.aRid[i]==rid ){ | |
| 147 | + *p = manifestCache.aLine[i]; | |
| 148 | + manifestCache.aRid[i] = 0; | |
| 149 | + return 1; | |
| 150 | + } | |
| 151 | + } | |
| 152 | + return 0; | |
| 153 | +} | |
| 154 | + | |
| 155 | +/* | |
| 156 | +** Clear the manifest cache. | |
| 157 | +*/ | |
| 158 | +void manifest_cache_clear(void){ | |
| 159 | + int i; | |
| 160 | + for(i=0; i<MX_MANIFEST_CACHE; i++){ | |
| 161 | + if( manifestCache.aRid[i]>0 ){ | |
| 162 | + manifest_clear(&manifestCache.aLine[i]); | |
| 163 | + } | |
| 164 | + } | |
| 165 | + memset(&manifestCache, 0, sizeof(manifestCache)); | |
| 166 | +} | |
| 167 | + | |
| 168 | +#ifdef FOSSIL_DONT_VERIFY_MANIFEST_MD5SUM | |
| 169 | +# define md5sum_init(X) | |
| 170 | +# define md5sum_step_text(X,Y) | |
| 171 | +#endif | |
| 172 | + | |
| 102 | 173 | /* |
| 103 | 174 | ** Parse a blob into a Manifest object. The Manifest object |
| 104 | 175 | ** takes over the input blob and will free it when the |
| 105 | 176 | ** Manifest object is freed. Zeros are inserted into the blob |
| 106 | 177 | ** as string terminators so that blob should not be used again. |
| @@ -569,20 +640,24 @@ | ||
| 569 | 640 | ** This card is required for all control file types except for |
| 570 | 641 | ** Manifest. It is not required for manifest only for historical |
| 571 | 642 | ** compatibility reasons. |
| 572 | 643 | */ |
| 573 | 644 | case 'Z': { |
| 645 | +#ifndef FOSSIL_DONT_VERIFY_MANIFEST_MD5SUM | |
| 574 | 646 | int rc; |
| 575 | 647 | Blob hash; |
| 648 | +#endif | |
| 576 | 649 | if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error; |
| 577 | 650 | if( blob_token(&line, &a2)!=0 ) goto manifest_syntax_error; |
| 578 | 651 | if( blob_size(&a1)!=32 ) goto manifest_syntax_error; |
| 579 | 652 | if( !validate16(blob_buffer(&a1), 32) ) goto manifest_syntax_error; |
| 653 | +#ifndef FOSSIL_DONT_VERIFY_MANIFEST_MD5SUM | |
| 580 | 654 | md5sum_finish(&hash); |
| 581 | 655 | rc = blob_compare(&hash, &a1); |
| 582 | 656 | blob_reset(&hash); |
| 583 | 657 | if( rc!=0 ) goto manifest_syntax_error; |
| 658 | +#endif | |
| 584 | 659 | seenZ = 1; |
| 585 | 660 | break; |
| 586 | 661 | } |
| 587 | 662 | default: { |
| 588 | 663 | goto manifest_syntax_error; |
| @@ -686,24 +761,31 @@ | ||
| 686 | 761 | } |
| 687 | 762 | |
| 688 | 763 | /* |
| 689 | 764 | ** COMMAND: test-parse-manifest |
| 690 | 765 | ** |
| 691 | -** Usage: %fossil test-parse-manifest FILENAME | |
| 766 | +** Usage: %fossil test-parse-manifest FILENAME ?N? | |
| 692 | 767 | ** |
| 693 | 768 | ** Parse the manifest and discarded. Use for testing only. |
| 694 | 769 | */ |
| 695 | 770 | void manifest_test_parse_cmd(void){ |
| 696 | 771 | Manifest m; |
| 697 | 772 | Blob b; |
| 698 | - if( g.argc!=3 ){ | |
| 773 | + int i; | |
| 774 | + int n = 1; | |
| 775 | + if( g.argc!=3 && g.argc!=4 ){ | |
| 699 | 776 | usage("FILENAME"); |
| 700 | 777 | } |
| 701 | 778 | db_must_be_within_tree(); |
| 702 | 779 | blob_read_from_file(&b, g.argv[2]); |
| 703 | - manifest_parse(&m, &b); | |
| 704 | - manifest_clear(&m); | |
| 780 | + if( g.argc>3 ) n = atoi(g.argv[3]); | |
| 781 | + for(i=0; i<n; i++){ | |
| 782 | + Blob b2; | |
| 783 | + blob_copy(&b2, &b); | |
| 784 | + manifest_parse(&m, &b2); | |
| 785 | + manifest_clear(&m); | |
| 786 | + } | |
| 705 | 787 | } |
| 706 | 788 | |
| 707 | 789 | /* |
| 708 | 790 | ** Translate a filename into a filename-id (fnid). Create a new fnid |
| 709 | 791 | ** if no previously exists. |
| @@ -810,25 +892,29 @@ | ||
| 810 | 892 | ** Edited files have both mlink.pid!=0 and mlink.fid!=0 |
| 811 | 893 | */ |
| 812 | 894 | static void add_mlink(int pid, Manifest *pParent, int cid, Manifest *pChild){ |
| 813 | 895 | Manifest other; |
| 814 | 896 | Blob otherContent; |
| 897 | + int otherRid; | |
| 815 | 898 | int i, j; |
| 816 | 899 | |
| 817 | 900 | if( db_exists("SELECT 1 FROM mlink WHERE mid=%d", cid) ){ |
| 818 | 901 | return; |
| 819 | 902 | } |
| 820 | 903 | assert( pParent==0 || pChild==0 ); |
| 821 | 904 | if( pParent==0 ){ |
| 822 | 905 | pParent = &other; |
| 823 | - content_get(pid, &otherContent); | |
| 906 | + otherRid = pid; | |
| 824 | 907 | }else{ |
| 825 | 908 | pChild = &other; |
| 826 | - content_get(cid, &otherContent); | |
| 909 | + otherRid = cid; | |
| 827 | 910 | } |
| 828 | - if( blob_size(&otherContent)==0 ) return; | |
| 829 | - if( manifest_parse(&other, &otherContent)==0 ) return; | |
| 911 | + if( manifest_cache_find(otherRid, &other)==0 ){ | |
| 912 | + content_get(otherRid, &otherContent); | |
| 913 | + if( blob_size(&otherContent)==0 ) return; | |
| 914 | + if( manifest_parse(&other, &otherContent)==0 ) return; | |
| 915 | + } | |
| 830 | 916 | content_deltify(pid, cid, 0); |
| 831 | 917 | |
| 832 | 918 | /* Use the iRename fields to find the cross-linkage between |
| 833 | 919 | ** renamed files. */ |
| 834 | 920 | for(j=0; j<pChild->nFile; j++){ |
| @@ -882,11 +968,11 @@ | ||
| 882 | 968 | }else{ |
| 883 | 969 | add_one_mlink(cid, 0, pChild->aFile[j].zUuid, pChild->aFile[j].zName,0); |
| 884 | 970 | } |
| 885 | 971 | j++; |
| 886 | 972 | } |
| 887 | - manifest_clear(&other); | |
| 973 | + manifest_cache_insert(otherRid, &other); | |
| 888 | 974 | } |
| 889 | 975 | |
| 890 | 976 | /* |
| 891 | 977 | ** True if manifest_crosslink_begin() has been called but |
| 892 | 978 | ** manifest_crosslink_end() is still pending. |
| @@ -1027,11 +1113,13 @@ | ||
| 1027 | 1113 | int i; |
| 1028 | 1114 | Manifest m; |
| 1029 | 1115 | Stmt q; |
| 1030 | 1116 | int parentid = 0; |
| 1031 | 1117 | |
| 1032 | - if( manifest_parse(&m, pContent)==0 ){ | |
| 1118 | + if( manifest_cache_find(rid, &m) ){ | |
| 1119 | + blob_reset(pContent); | |
| 1120 | + }else if( manifest_parse(&m, pContent)==0 ){ | |
| 1033 | 1121 | return 0; |
| 1034 | 1122 | } |
| 1035 | 1123 | if( g.xlinkClusterOnly && m.type!=CFTYPE_CLUSTER ){ |
| 1036 | 1124 | manifest_clear(&m); |
| 1037 | 1125 | return 0; |
| @@ -1263,11 +1351,15 @@ | ||
| 1263 | 1351 | ); |
| 1264 | 1352 | free(zComment); |
| 1265 | 1353 | } |
| 1266 | 1354 | } |
| 1267 | 1355 | db_end_transaction(0); |
| 1268 | - manifest_clear(&m); | |
| 1356 | + if( m.type==CFTYPE_MANIFEST ){ | |
| 1357 | + manifest_cache_insert(rid, &m); | |
| 1358 | + }else{ | |
| 1359 | + manifest_clear(&m); | |
| 1360 | + } | |
| 1269 | 1361 | return 1; |
| 1270 | 1362 | } |
| 1271 | 1363 | |
| 1272 | 1364 | /* |
| 1273 | 1365 | ** Given a checkin name, load and parse the manifest for that checkin. |
| 1274 | 1366 |
| --- src/manifest.c | |
| +++ src/manifest.c | |
| @@ -83,10 +83,22 @@ | |
| 83 | char *zValue; /* Value of the field */ |
| 84 | } *aField; /* One for each J card */ |
| 85 | }; |
| 86 | #endif |
| 87 | |
| 88 | |
| 89 | /* |
| 90 | ** Clear the memory allocated in a manifest object |
| 91 | */ |
| 92 | void manifest_clear(Manifest *p){ |
| @@ -97,10 +109,69 @@ | |
| 97 | free(p->aTag); |
| 98 | free(p->aField); |
| 99 | memset(p, 0, sizeof(*p)); |
| 100 | } |
| 101 | |
| 102 | /* |
| 103 | ** Parse a blob into a Manifest object. The Manifest object |
| 104 | ** takes over the input blob and will free it when the |
| 105 | ** Manifest object is freed. Zeros are inserted into the blob |
| 106 | ** as string terminators so that blob should not be used again. |
| @@ -569,20 +640,24 @@ | |
| 569 | ** This card is required for all control file types except for |
| 570 | ** Manifest. It is not required for manifest only for historical |
| 571 | ** compatibility reasons. |
| 572 | */ |
| 573 | case 'Z': { |
| 574 | int rc; |
| 575 | Blob hash; |
| 576 | if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error; |
| 577 | if( blob_token(&line, &a2)!=0 ) goto manifest_syntax_error; |
| 578 | if( blob_size(&a1)!=32 ) goto manifest_syntax_error; |
| 579 | if( !validate16(blob_buffer(&a1), 32) ) goto manifest_syntax_error; |
| 580 | md5sum_finish(&hash); |
| 581 | rc = blob_compare(&hash, &a1); |
| 582 | blob_reset(&hash); |
| 583 | if( rc!=0 ) goto manifest_syntax_error; |
| 584 | seenZ = 1; |
| 585 | break; |
| 586 | } |
| 587 | default: { |
| 588 | goto manifest_syntax_error; |
| @@ -686,24 +761,31 @@ | |
| 686 | } |
| 687 | |
| 688 | /* |
| 689 | ** COMMAND: test-parse-manifest |
| 690 | ** |
| 691 | ** Usage: %fossil test-parse-manifest FILENAME |
| 692 | ** |
| 693 | ** Parse the manifest and discarded. Use for testing only. |
| 694 | */ |
| 695 | void manifest_test_parse_cmd(void){ |
| 696 | Manifest m; |
| 697 | Blob b; |
| 698 | if( g.argc!=3 ){ |
| 699 | usage("FILENAME"); |
| 700 | } |
| 701 | db_must_be_within_tree(); |
| 702 | blob_read_from_file(&b, g.argv[2]); |
| 703 | manifest_parse(&m, &b); |
| 704 | manifest_clear(&m); |
| 705 | } |
| 706 | |
| 707 | /* |
| 708 | ** Translate a filename into a filename-id (fnid). Create a new fnid |
| 709 | ** if no previously exists. |
| @@ -810,25 +892,29 @@ | |
| 810 | ** Edited files have both mlink.pid!=0 and mlink.fid!=0 |
| 811 | */ |
| 812 | static void add_mlink(int pid, Manifest *pParent, int cid, Manifest *pChild){ |
| 813 | Manifest other; |
| 814 | Blob otherContent; |
| 815 | int i, j; |
| 816 | |
| 817 | if( db_exists("SELECT 1 FROM mlink WHERE mid=%d", cid) ){ |
| 818 | return; |
| 819 | } |
| 820 | assert( pParent==0 || pChild==0 ); |
| 821 | if( pParent==0 ){ |
| 822 | pParent = &other; |
| 823 | content_get(pid, &otherContent); |
| 824 | }else{ |
| 825 | pChild = &other; |
| 826 | content_get(cid, &otherContent); |
| 827 | } |
| 828 | if( blob_size(&otherContent)==0 ) return; |
| 829 | if( manifest_parse(&other, &otherContent)==0 ) return; |
| 830 | content_deltify(pid, cid, 0); |
| 831 | |
| 832 | /* Use the iRename fields to find the cross-linkage between |
| 833 | ** renamed files. */ |
| 834 | for(j=0; j<pChild->nFile; j++){ |
| @@ -882,11 +968,11 @@ | |
| 882 | }else{ |
| 883 | add_one_mlink(cid, 0, pChild->aFile[j].zUuid, pChild->aFile[j].zName,0); |
| 884 | } |
| 885 | j++; |
| 886 | } |
| 887 | manifest_clear(&other); |
| 888 | } |
| 889 | |
| 890 | /* |
| 891 | ** True if manifest_crosslink_begin() has been called but |
| 892 | ** manifest_crosslink_end() is still pending. |
| @@ -1027,11 +1113,13 @@ | |
| 1027 | int i; |
| 1028 | Manifest m; |
| 1029 | Stmt q; |
| 1030 | int parentid = 0; |
| 1031 | |
| 1032 | if( manifest_parse(&m, pContent)==0 ){ |
| 1033 | return 0; |
| 1034 | } |
| 1035 | if( g.xlinkClusterOnly && m.type!=CFTYPE_CLUSTER ){ |
| 1036 | manifest_clear(&m); |
| 1037 | return 0; |
| @@ -1263,11 +1351,15 @@ | |
| 1263 | ); |
| 1264 | free(zComment); |
| 1265 | } |
| 1266 | } |
| 1267 | db_end_transaction(0); |
| 1268 | manifest_clear(&m); |
| 1269 | return 1; |
| 1270 | } |
| 1271 | |
| 1272 | /* |
| 1273 | ** Given a checkin name, load and parse the manifest for that checkin. |
| 1274 |
| --- src/manifest.c | |
| +++ src/manifest.c | |
| @@ -83,10 +83,22 @@ | |
| 83 | char *zValue; /* Value of the field */ |
| 84 | } *aField; /* One for each J card */ |
| 85 | }; |
| 86 | #endif |
| 87 | |
| 88 | /* |
| 89 | ** A cache of parsed manifests. This reduces the number of |
| 90 | ** calls to manifest_parse() when doing a rebuild. |
| 91 | */ |
| 92 | #define MX_MANIFEST_CACHE 4 |
| 93 | static struct { |
| 94 | int nxAge; |
| 95 | int aRid[MX_MANIFEST_CACHE]; |
| 96 | int aAge[MX_MANIFEST_CACHE]; |
| 97 | Manifest aLine[MX_MANIFEST_CACHE]; |
| 98 | } manifestCache; |
| 99 | |
| 100 | |
| 101 | /* |
| 102 | ** Clear the memory allocated in a manifest object |
| 103 | */ |
| 104 | void manifest_clear(Manifest *p){ |
| @@ -97,10 +109,69 @@ | |
| 109 | free(p->aTag); |
| 110 | free(p->aField); |
| 111 | memset(p, 0, sizeof(*p)); |
| 112 | } |
| 113 | |
| 114 | /* |
| 115 | ** Add an element to the manifest cache using LRU replacement. |
| 116 | */ |
| 117 | void manifest_cache_insert(int rid, Manifest *p){ |
| 118 | int i; |
| 119 | for(i=0; i<MX_MANIFEST_CACHE; i++){ |
| 120 | if( manifestCache.aRid[i]==0 ) break; |
| 121 | } |
| 122 | if( i>=MX_MANIFEST_CACHE ){ |
| 123 | int oldest = 0; |
| 124 | int oldestAge = manifestCache.aAge[0]; |
| 125 | for(i=1; i<MX_MANIFEST_CACHE; i++){ |
| 126 | if( manifestCache.aAge[i]<oldestAge ){ |
| 127 | oldest = i; |
| 128 | oldestAge = manifestCache.aAge[i]; |
| 129 | } |
| 130 | } |
| 131 | manifest_clear(&manifestCache.aLine[oldest]); |
| 132 | i = oldest; |
| 133 | } |
| 134 | manifestCache.aAge[i] = ++manifestCache.nxAge; |
| 135 | manifestCache.aRid[i] = rid; |
| 136 | manifestCache.aLine[i] = *p; |
| 137 | } |
| 138 | |
| 139 | /* |
| 140 | ** Try to extract a line from the manifest cache. Return 1 if found. |
| 141 | ** Return 0 if not found. |
| 142 | */ |
| 143 | int manifest_cache_find(int rid, Manifest *p){ |
| 144 | int i; |
| 145 | for(i=0; i<MX_MANIFEST_CACHE; i++){ |
| 146 | if( manifestCache.aRid[i]==rid ){ |
| 147 | *p = manifestCache.aLine[i]; |
| 148 | manifestCache.aRid[i] = 0; |
| 149 | return 1; |
| 150 | } |
| 151 | } |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | /* |
| 156 | ** Clear the manifest cache. |
| 157 | */ |
| 158 | void manifest_cache_clear(void){ |
| 159 | int i; |
| 160 | for(i=0; i<MX_MANIFEST_CACHE; i++){ |
| 161 | if( manifestCache.aRid[i]>0 ){ |
| 162 | manifest_clear(&manifestCache.aLine[i]); |
| 163 | } |
| 164 | } |
| 165 | memset(&manifestCache, 0, sizeof(manifestCache)); |
| 166 | } |
| 167 | |
| 168 | #ifdef FOSSIL_DONT_VERIFY_MANIFEST_MD5SUM |
| 169 | # define md5sum_init(X) |
| 170 | # define md5sum_step_text(X,Y) |
| 171 | #endif |
| 172 | |
| 173 | /* |
| 174 | ** Parse a blob into a Manifest object. The Manifest object |
| 175 | ** takes over the input blob and will free it when the |
| 176 | ** Manifest object is freed. Zeros are inserted into the blob |
| 177 | ** as string terminators so that blob should not be used again. |
| @@ -569,20 +640,24 @@ | |
| 640 | ** This card is required for all control file types except for |
| 641 | ** Manifest. It is not required for manifest only for historical |
| 642 | ** compatibility reasons. |
| 643 | */ |
| 644 | case 'Z': { |
| 645 | #ifndef FOSSIL_DONT_VERIFY_MANIFEST_MD5SUM |
| 646 | int rc; |
| 647 | Blob hash; |
| 648 | #endif |
| 649 | if( blob_token(&line, &a1)==0 ) goto manifest_syntax_error; |
| 650 | if( blob_token(&line, &a2)!=0 ) goto manifest_syntax_error; |
| 651 | if( blob_size(&a1)!=32 ) goto manifest_syntax_error; |
| 652 | if( !validate16(blob_buffer(&a1), 32) ) goto manifest_syntax_error; |
| 653 | #ifndef FOSSIL_DONT_VERIFY_MANIFEST_MD5SUM |
| 654 | md5sum_finish(&hash); |
| 655 | rc = blob_compare(&hash, &a1); |
| 656 | blob_reset(&hash); |
| 657 | if( rc!=0 ) goto manifest_syntax_error; |
| 658 | #endif |
| 659 | seenZ = 1; |
| 660 | break; |
| 661 | } |
| 662 | default: { |
| 663 | goto manifest_syntax_error; |
| @@ -686,24 +761,31 @@ | |
| 761 | } |
| 762 | |
| 763 | /* |
| 764 | ** COMMAND: test-parse-manifest |
| 765 | ** |
| 766 | ** Usage: %fossil test-parse-manifest FILENAME ?N? |
| 767 | ** |
| 768 | ** Parse the manifest and discarded. Use for testing only. |
| 769 | */ |
| 770 | void manifest_test_parse_cmd(void){ |
| 771 | Manifest m; |
| 772 | Blob b; |
| 773 | int i; |
| 774 | int n = 1; |
| 775 | if( g.argc!=3 && g.argc!=4 ){ |
| 776 | usage("FILENAME"); |
| 777 | } |
| 778 | db_must_be_within_tree(); |
| 779 | blob_read_from_file(&b, g.argv[2]); |
| 780 | if( g.argc>3 ) n = atoi(g.argv[3]); |
| 781 | for(i=0; i<n; i++){ |
| 782 | Blob b2; |
| 783 | blob_copy(&b2, &b); |
| 784 | manifest_parse(&m, &b2); |
| 785 | manifest_clear(&m); |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | /* |
| 790 | ** Translate a filename into a filename-id (fnid). Create a new fnid |
| 791 | ** if no previously exists. |
| @@ -810,25 +892,29 @@ | |
| 892 | ** Edited files have both mlink.pid!=0 and mlink.fid!=0 |
| 893 | */ |
| 894 | static void add_mlink(int pid, Manifest *pParent, int cid, Manifest *pChild){ |
| 895 | Manifest other; |
| 896 | Blob otherContent; |
| 897 | int otherRid; |
| 898 | int i, j; |
| 899 | |
| 900 | if( db_exists("SELECT 1 FROM mlink WHERE mid=%d", cid) ){ |
| 901 | return; |
| 902 | } |
| 903 | assert( pParent==0 || pChild==0 ); |
| 904 | if( pParent==0 ){ |
| 905 | pParent = &other; |
| 906 | otherRid = pid; |
| 907 | }else{ |
| 908 | pChild = &other; |
| 909 | otherRid = cid; |
| 910 | } |
| 911 | if( manifest_cache_find(otherRid, &other)==0 ){ |
| 912 | content_get(otherRid, &otherContent); |
| 913 | if( blob_size(&otherContent)==0 ) return; |
| 914 | if( manifest_parse(&other, &otherContent)==0 ) return; |
| 915 | } |
| 916 | content_deltify(pid, cid, 0); |
| 917 | |
| 918 | /* Use the iRename fields to find the cross-linkage between |
| 919 | ** renamed files. */ |
| 920 | for(j=0; j<pChild->nFile; j++){ |
| @@ -882,11 +968,11 @@ | |
| 968 | }else{ |
| 969 | add_one_mlink(cid, 0, pChild->aFile[j].zUuid, pChild->aFile[j].zName,0); |
| 970 | } |
| 971 | j++; |
| 972 | } |
| 973 | manifest_cache_insert(otherRid, &other); |
| 974 | } |
| 975 | |
| 976 | /* |
| 977 | ** True if manifest_crosslink_begin() has been called but |
| 978 | ** manifest_crosslink_end() is still pending. |
| @@ -1027,11 +1113,13 @@ | |
| 1113 | int i; |
| 1114 | Manifest m; |
| 1115 | Stmt q; |
| 1116 | int parentid = 0; |
| 1117 | |
| 1118 | if( manifest_cache_find(rid, &m) ){ |
| 1119 | blob_reset(pContent); |
| 1120 | }else if( manifest_parse(&m, pContent)==0 ){ |
| 1121 | return 0; |
| 1122 | } |
| 1123 | if( g.xlinkClusterOnly && m.type!=CFTYPE_CLUSTER ){ |
| 1124 | manifest_clear(&m); |
| 1125 | return 0; |
| @@ -1263,11 +1351,15 @@ | |
| 1351 | ); |
| 1352 | free(zComment); |
| 1353 | } |
| 1354 | } |
| 1355 | db_end_transaction(0); |
| 1356 | if( m.type==CFTYPE_MANIFEST ){ |
| 1357 | manifest_cache_insert(rid, &m); |
| 1358 | }else{ |
| 1359 | manifest_clear(&m); |
| 1360 | } |
| 1361 | return 1; |
| 1362 | } |
| 1363 | |
| 1364 | /* |
| 1365 | ** Given a checkin name, load and parse the manifest for that checkin. |
| 1366 |