Fossil SCM

Check for name aliases when committing. Use SHA3 hashes if the version number is 2.1 or higher.

drh 2017-03-01 14:10 UTC fossil-2.0
Commit 104c8d3409b11eb37ec693e640ec74164811fd4b
+9 -2
--- src/content.c
+++ src/content.c
@@ -513,13 +513,21 @@
513513
int isDephantomize = 0;
514514
515515
assert( g.repositoryOpen );
516516
assert( pBlob!=0 );
517517
assert( srcId==0 || zUuid!=0 );
518
+ db_begin_transaction();
518519
if( zUuid==0 ){
519520
assert( nBlob==0 );
520
- sha1sum_blob(pBlob, &hash);
521
+ hname_hash(pBlob, 1, &hash);
522
+ rid = fast_uuid_to_rid(blob_str(&hash));
523
+ blob_reset(&hash);
524
+ if( rid ){
525
+ db_end_transaction(0);
526
+ return rid;
527
+ }
528
+ hname_hash(pBlob, 0, &hash);
521529
}else{
522530
blob_init(&hash, zUuid, -1);
523531
}
524532
if( nBlob ){
525533
size = nBlob;
@@ -527,11 +535,10 @@
527535
size = blob_size(pBlob);
528536
if( srcId ){
529537
size = delta_output_size(blob_buffer(pBlob), size);
530538
}
531539
}
532
- db_begin_transaction();
533540
534541
/* Check to see if the entry already exists and if it does whether
535542
** or not the entry is a phantom
536543
*/
537544
db_prepare(&s1, "SELECT rid, size FROM blob WHERE uuid=%B", &hash);
538545
--- src/content.c
+++ src/content.c
@@ -513,13 +513,21 @@
513 int isDephantomize = 0;
514
515 assert( g.repositoryOpen );
516 assert( pBlob!=0 );
517 assert( srcId==0 || zUuid!=0 );
 
518 if( zUuid==0 ){
519 assert( nBlob==0 );
520 sha1sum_blob(pBlob, &hash);
 
 
 
 
 
 
 
521 }else{
522 blob_init(&hash, zUuid, -1);
523 }
524 if( nBlob ){
525 size = nBlob;
@@ -527,11 +535,10 @@
527 size = blob_size(pBlob);
528 if( srcId ){
529 size = delta_output_size(blob_buffer(pBlob), size);
530 }
531 }
532 db_begin_transaction();
533
534 /* Check to see if the entry already exists and if it does whether
535 ** or not the entry is a phantom
536 */
537 db_prepare(&s1, "SELECT rid, size FROM blob WHERE uuid=%B", &hash);
538
--- src/content.c
+++ src/content.c
@@ -513,13 +513,21 @@
513 int isDephantomize = 0;
514
515 assert( g.repositoryOpen );
516 assert( pBlob!=0 );
517 assert( srcId==0 || zUuid!=0 );
518 db_begin_transaction();
519 if( zUuid==0 ){
520 assert( nBlob==0 );
521 hname_hash(pBlob, 1, &hash);
522 rid = fast_uuid_to_rid(blob_str(&hash));
523 blob_reset(&hash);
524 if( rid ){
525 db_end_transaction(0);
526 return rid;
527 }
528 hname_hash(pBlob, 0, &hash);
529 }else{
530 blob_init(&hash, zUuid, -1);
531 }
532 if( nBlob ){
533 size = nBlob;
@@ -527,11 +535,10 @@
535 size = blob_size(pBlob);
536 if( srcId ){
537 size = delta_output_size(blob_buffer(pBlob), size);
538 }
539 }
 
540
541 /* Check to see if the entry already exists and if it does whether
542 ** or not the entry is a phantom
543 */
544 db_prepare(&s1, "SELECT rid, size FROM blob WHERE uuid=%B", &hash);
545
+31
--- src/hname.c
+++ src/hname.c
@@ -42,10 +42,15 @@
4242
** Hash lengths for the various algorithms
4343
*/
4444
#define HNAME_LEN_SHA1 40
4545
#define HNAME_LEN_K256 64
4646
47
+/*
48
+** The number of distinct hash algorithms:
49
+*/
50
+#define HNAME_COUNT 2 /* Just SHA1 and SHA3-256. Let's keep it that way! */
51
+
4752
#endif /* INTERFACE */
4853
4954
/*
5055
** Return the integer hash algorithm code number (ex: HNAME_K224) for
5156
** the hash string provided. Or return HNAME_ERROR (0) if the input string
@@ -122,5 +127,31 @@
122127
break;
123128
}
124129
}
125130
return id;
126131
}
132
+
133
+/*
134
+** Compute a hash on blob pContent. Write the hash into blob pHashOut.
135
+** This routine assumes that pHashOut is uninitialized.
136
+**
137
+** The preferred hash is used for iHType==0, and various alternative hashes
138
+** are used for iHType>0 && iHType<NHAME_COUNT.
139
+*/
140
+void hname_hash(const Blob *pContent, unsigned int iHType, Blob *pHashOut){
141
+#if RELEASE_VERSION_NUMBER>=20100
142
+ /* For Fossil 2.1 and later, the preferred hash algorithm is SHA3-256 and
143
+ ** SHA1 is the secondary hash algorithm. */
144
+ switch( iHType ){
145
+ case 0: sha3sum_blob(pContent, 256, pHashOut); break;
146
+ case 1: sha1sum_blob(pContent, pHashOut); break;
147
+ }
148
+#else
149
+ /* Prior to Fossil 2.1, the preferred hash algorithm is SHA1 (for backwards
150
+ ** compatibility with Fossil 1.x) and SHA3-256 is the only auxiliary
151
+ ** algorithm */
152
+ switch( iHType ){
153
+ case 0: sha1sum_blob(pContent, pHashOut); break;
154
+ case 1: sha3sum_blob(pContent, 256, pHashOut); break;
155
+ }
156
+#endif
157
+}
127158
--- src/hname.c
+++ src/hname.c
@@ -42,10 +42,15 @@
42 ** Hash lengths for the various algorithms
43 */
44 #define HNAME_LEN_SHA1 40
45 #define HNAME_LEN_K256 64
46
 
 
 
 
 
47 #endif /* INTERFACE */
48
49 /*
50 ** Return the integer hash algorithm code number (ex: HNAME_K224) for
51 ** the hash string provided. Or return HNAME_ERROR (0) if the input string
@@ -122,5 +127,31 @@
122 break;
123 }
124 }
125 return id;
126 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
--- src/hname.c
+++ src/hname.c
@@ -42,10 +42,15 @@
42 ** Hash lengths for the various algorithms
43 */
44 #define HNAME_LEN_SHA1 40
45 #define HNAME_LEN_K256 64
46
47 /*
48 ** The number of distinct hash algorithms:
49 */
50 #define HNAME_COUNT 2 /* Just SHA1 and SHA3-256. Let's keep it that way! */
51
52 #endif /* INTERFACE */
53
54 /*
55 ** Return the integer hash algorithm code number (ex: HNAME_K224) for
56 ** the hash string provided. Or return HNAME_ERROR (0) if the input string
@@ -122,5 +127,31 @@
127 break;
128 }
129 }
130 return id;
131 }
132
133 /*
134 ** Compute a hash on blob pContent. Write the hash into blob pHashOut.
135 ** This routine assumes that pHashOut is uninitialized.
136 **
137 ** The preferred hash is used for iHType==0, and various alternative hashes
138 ** are used for iHType>0 && iHType<NHAME_COUNT.
139 */
140 void hname_hash(const Blob *pContent, unsigned int iHType, Blob *pHashOut){
141 #if RELEASE_VERSION_NUMBER>=20100
142 /* For Fossil 2.1 and later, the preferred hash algorithm is SHA3-256 and
143 ** SHA1 is the secondary hash algorithm. */
144 switch( iHType ){
145 case 0: sha3sum_blob(pContent, 256, pHashOut); break;
146 case 1: sha1sum_blob(pContent, pHashOut); break;
147 }
148 #else
149 /* Prior to Fossil 2.1, the preferred hash algorithm is SHA1 (for backwards
150 ** compatibility with Fossil 1.x) and SHA3-256 is the only auxiliary
151 ** algorithm */
152 switch( iHType ){
153 case 0: sha1sum_blob(pContent, pHashOut); break;
154 case 1: sha3sum_blob(pContent, 256, pHashOut); break;
155 }
156 #endif
157 }
158
+1 -1
--- src/sha3.c
+++ src/sha3.c
@@ -417,11 +417,11 @@
417417
unsigned int nData
418418
){
419419
unsigned int i = 0;
420420
#if SHA3_BYTEORDER==1234
421421
if( (p->nLoaded % 8)==0 && ((aData - (const unsigned char*)0)&7)==0 ){
422
- for(; i<nData-7; i+=8){
422
+ for(; i+7<nData; i+=8){
423423
p->u.s[p->nLoaded/8] ^= *(u64*)&aData[i];
424424
p->nLoaded += 8;
425425
if( p->nLoaded>=p->nRate ){
426426
KeccakF1600Step(p);
427427
p->nLoaded = 0;
428428
--- src/sha3.c
+++ src/sha3.c
@@ -417,11 +417,11 @@
417 unsigned int nData
418 ){
419 unsigned int i = 0;
420 #if SHA3_BYTEORDER==1234
421 if( (p->nLoaded % 8)==0 && ((aData - (const unsigned char*)0)&7)==0 ){
422 for(; i<nData-7; i+=8){
423 p->u.s[p->nLoaded/8] ^= *(u64*)&aData[i];
424 p->nLoaded += 8;
425 if( p->nLoaded>=p->nRate ){
426 KeccakF1600Step(p);
427 p->nLoaded = 0;
428
--- src/sha3.c
+++ src/sha3.c
@@ -417,11 +417,11 @@
417 unsigned int nData
418 ){
419 unsigned int i = 0;
420 #if SHA3_BYTEORDER==1234
421 if( (p->nLoaded % 8)==0 && ((aData - (const unsigned char*)0)&7)==0 ){
422 for(; i+7<nData; i+=8){
423 p->u.s[p->nLoaded/8] ^= *(u64*)&aData[i];
424 p->nLoaded += 8;
425 if( p->nLoaded>=p->nRate ){
426 KeccakF1600Step(p);
427 p->nLoaded = 0;
428

Keyboard Shortcuts

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