Fossil SCM

Incremental check-in. (Saving my place in order to go work on other things.) Changes are untested.

drh 2016-08-05 08:30 unversioned-files
Commit a9463a7157129ee3cb6ecd1ca681c3b6f5a256a1
2 files changed +15 -8 +54 -2
+15 -8
--- src/content.c
+++ src/content.c
@@ -452,10 +452,24 @@
452452
** Turn dephantomization processing on or off.
453453
*/
454454
void content_enable_dephantomize(int onoff){
455455
ignoreDephantomizations = !onoff;
456456
}
457
+
458
+/*
459
+** Make sure the g.rcvid global variable has been initialized.
460
+*/
461
+void content_rcvid_init(void){
462
+ if( g.rcvid==0 ){
463
+ db_multi_exec(
464
+ "INSERT INTO rcvfrom(uid, mtime, nonce, ipaddr)"
465
+ "VALUES(%d, julianday('now'), %Q, %Q)",
466
+ g.userUid, g.zNonce, g.zIpAddr
467
+ );
468
+ g.rcvid = db_last_insert_rowid();
469
+ }
470
+}
457471
458472
/*
459473
** Write content into the database. Return the record ID. If the
460474
** content is already in the database, just return the record ID.
461475
**
@@ -530,18 +544,11 @@
530544
markAsUnclustered = 1;
531545
}
532546
db_finalize(&s1);
533547
534548
/* Construct a received-from ID if we do not already have one */
535
- if( g.rcvid==0 ){
536
- db_multi_exec(
537
- "INSERT INTO rcvfrom(uid, mtime, nonce, ipaddr)"
538
- "VALUES(%d, julianday('now'), %Q, %Q)",
539
- g.userUid, g.zNonce, g.zIpAddr
540
- );
541
- g.rcvid = db_last_insert_rowid();
542
- }
549
+ content_rcvid_init();
543550
544551
if( nBlob ){
545552
cmpr = pBlob[0];
546553
}else{
547554
blob_compress(pBlob, &cmpr);
548555
--- src/content.c
+++ src/content.c
@@ -452,10 +452,24 @@
452 ** Turn dephantomization processing on or off.
453 */
454 void content_enable_dephantomize(int onoff){
455 ignoreDephantomizations = !onoff;
456 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
457
458 /*
459 ** Write content into the database. Return the record ID. If the
460 ** content is already in the database, just return the record ID.
461 **
@@ -530,18 +544,11 @@
530 markAsUnclustered = 1;
531 }
532 db_finalize(&s1);
533
534 /* Construct a received-from ID if we do not already have one */
535 if( g.rcvid==0 ){
536 db_multi_exec(
537 "INSERT INTO rcvfrom(uid, mtime, nonce, ipaddr)"
538 "VALUES(%d, julianday('now'), %Q, %Q)",
539 g.userUid, g.zNonce, g.zIpAddr
540 );
541 g.rcvid = db_last_insert_rowid();
542 }
543
544 if( nBlob ){
545 cmpr = pBlob[0];
546 }else{
547 blob_compress(pBlob, &cmpr);
548
--- src/content.c
+++ src/content.c
@@ -452,10 +452,24 @@
452 ** Turn dephantomization processing on or off.
453 */
454 void content_enable_dephantomize(int onoff){
455 ignoreDephantomizations = !onoff;
456 }
457
458 /*
459 ** Make sure the g.rcvid global variable has been initialized.
460 */
461 void content_rcvid_init(void){
462 if( g.rcvid==0 ){
463 db_multi_exec(
464 "INSERT INTO rcvfrom(uid, mtime, nonce, ipaddr)"
465 "VALUES(%d, julianday('now'), %Q, %Q)",
466 g.userUid, g.zNonce, g.zIpAddr
467 );
468 g.rcvid = db_last_insert_rowid();
469 }
470 }
471
472 /*
473 ** Write content into the database. Return the record ID. If the
474 ** content is already in the database, just return the record ID.
475 **
@@ -530,18 +544,11 @@
544 markAsUnclustered = 1;
545 }
546 db_finalize(&s1);
547
548 /* Construct a received-from ID if we do not already have one */
549 content_rcvid_init();
 
 
 
 
 
 
 
550
551 if( nBlob ){
552 cmpr = pBlob[0];
553 }else{
554 blob_compress(pBlob, &cmpr);
555
--- src/unversioned.c
+++ src/unversioned.c
@@ -27,11 +27,11 @@
2727
#endif
2828
#include "unversioned.h"
2929
#include <time.h>
3030
3131
/*
32
-** SQL code to implement the tables needed by the unverioned.
32
+** SQL code to implement the tables needed by the unversioned.
3333
*/
3434
static const char zUnversionedInit[] =
3535
@ CREATE TABLE IF NOT EXISTS "%w".unversioned(
3636
@ name TEXT PRIMARY KEY, -- Name of the uv file
3737
@ rcvid INTEGER, -- Where received from
@@ -104,12 +104,64 @@
104104
}else{
105105
mtime = db_int(0, "SELECT strftime('%%s',%Q)", zMtime);
106106
if( mtime<=0 ) fossil_fatal("bad timestamp: %Q", zMtime);
107107
}
108108
if( memcmp(zCmd, "add", nCmd)==0 ){
109
+ const char *zFile;
110
+ const char *zIn;
111
+ Blob file;
112
+ Blob hash;
113
+ Blob compressed;
114
+ Stmt ins;
115
+ if( g.argc!=4 && g.argc!=5 ) usage("add FILE ?INPUT?");
116
+ zFile = g.argv[3];
117
+ if( !file_is_simple_pathname(zFile,1) ){
118
+ fossil_fatal("'%Q' is not an acceptable filename", zFile);
119
+ }
120
+ zIn = g.argc==5 ? g.argv[4] : "-";
121
+ blob_init(&file,0,0);
122
+ blob_read_from_file(&file, zIn);
123
+ sha1sum_blob(&file, &hash);
124
+ blob_compress(&file, &compressed);
125
+ db_begin_transaction();
126
+ content_rcvid_init();
127
+ db_prepare(&ins,
128
+ "REPLACE INTO unversioned(name,rcvid,mtime,hash,sz,content)"
129
+ " VALUES(:name,:rcvid,:mtime,:hash,:sz,:content)"
130
+ );
131
+ db_bind_text(&ins, ":name", zFile);
132
+ db_bind_int(&ins, ":rcvid", g.rcvid);
133
+ db_bind_int64(&ins, ":mtime", mtime);
134
+ db_bind_text(&ins, ":hash", blob_str(&hash));
135
+ db_bind_int(&ins, ":sz", blob_size(&file));
136
+ db_bind_blob(&ins, ":content", &compressed);
137
+ db_step(&ins);
138
+ db_finalize(&ins);
139
+ blob_reset(&compressed);
140
+ blob_reset(&hash);
141
+ blob_reset(&file);
142
+ /* Clear the uvhash cache */
143
+ db_end_transaction(0);
109144
}else if( memcmp(zCmd, "cat", nCmd)==0 ){
110145
}else if( memcmp(zCmd, "list", nCmd)==0 || memcmp(zCmd, "ls", nCmd)==0 ){
146
+ Stmt q;
147
+ db_prepare(&q,
148
+ "SELECT hash, datetime(mtime,'unixepoch'), sz, name, content IS NULL"
149
+ " FROM unversioned"
150
+ " WHERE hash IS NOT NULL"
151
+ " ORDER BY name;"
152
+ );
153
+ while( db_step(&q)==SQLITE_ROW ){
154
+ fossil_print("%12.12s %s %8d %s%s\n",
155
+ db_column_text(&q,0),
156
+ db_column_text(&q,1),
157
+ db_column_int(&q,2),
158
+ db_column_text(&q,3),
159
+ db_column_int(&q,4) ? " ** no content ** ": ""
160
+ );
161
+ }
162
+ db_finalize(&q);
111163
}else if( memcmp(zCmd, "revert", nCmd)==0 || memcmp(zCmd,"sync",nCmd)==0 ){
112164
fossil_fatal("not yet implemented...");
113165
}else if( memcmp(zCmd, "rm", nCmd)==0 ){
114166
}else{
115167
usage("add|cat|ls|revert|rm|sync");
@@ -152,11 +204,11 @@
152204
153205
The client sends uvgimme if
154206
155207
(a) it does not possess NAME or
156208
(b) if the NAME it holds has an earlier timestamp than TIMESTAMP or
157
- (c) if the NAME it holds has the exact timestamp TIMESATMP but a
209
+ (c) if the NAME it holds has the exact timestamp TIMESTAMP but a
158210
lexicographically earliers HASH.
159211
160212
Otherwise the client sends a uvfile. The client also sends uvfile
161213
cards for each unversioned file it holds which was not named by any
162214
uvigot card.
163215
--- src/unversioned.c
+++ src/unversioned.c
@@ -27,11 +27,11 @@
27 #endif
28 #include "unversioned.h"
29 #include <time.h>
30
31 /*
32 ** SQL code to implement the tables needed by the unverioned.
33 */
34 static const char zUnversionedInit[] =
35 @ CREATE TABLE IF NOT EXISTS "%w".unversioned(
36 @ name TEXT PRIMARY KEY, -- Name of the uv file
37 @ rcvid INTEGER, -- Where received from
@@ -104,12 +104,64 @@
104 }else{
105 mtime = db_int(0, "SELECT strftime('%%s',%Q)", zMtime);
106 if( mtime<=0 ) fossil_fatal("bad timestamp: %Q", zMtime);
107 }
108 if( memcmp(zCmd, "add", nCmd)==0 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109 }else if( memcmp(zCmd, "cat", nCmd)==0 ){
110 }else if( memcmp(zCmd, "list", nCmd)==0 || memcmp(zCmd, "ls", nCmd)==0 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111 }else if( memcmp(zCmd, "revert", nCmd)==0 || memcmp(zCmd,"sync",nCmd)==0 ){
112 fossil_fatal("not yet implemented...");
113 }else if( memcmp(zCmd, "rm", nCmd)==0 ){
114 }else{
115 usage("add|cat|ls|revert|rm|sync");
@@ -152,11 +204,11 @@
152
153 The client sends uvgimme if
154
155 (a) it does not possess NAME or
156 (b) if the NAME it holds has an earlier timestamp than TIMESTAMP or
157 (c) if the NAME it holds has the exact timestamp TIMESATMP but a
158 lexicographically earliers HASH.
159
160 Otherwise the client sends a uvfile. The client also sends uvfile
161 cards for each unversioned file it holds which was not named by any
162 uvigot card.
163
--- src/unversioned.c
+++ src/unversioned.c
@@ -27,11 +27,11 @@
27 #endif
28 #include "unversioned.h"
29 #include <time.h>
30
31 /*
32 ** SQL code to implement the tables needed by the unversioned.
33 */
34 static const char zUnversionedInit[] =
35 @ CREATE TABLE IF NOT EXISTS "%w".unversioned(
36 @ name TEXT PRIMARY KEY, -- Name of the uv file
37 @ rcvid INTEGER, -- Where received from
@@ -104,12 +104,64 @@
104 }else{
105 mtime = db_int(0, "SELECT strftime('%%s',%Q)", zMtime);
106 if( mtime<=0 ) fossil_fatal("bad timestamp: %Q", zMtime);
107 }
108 if( memcmp(zCmd, "add", nCmd)==0 ){
109 const char *zFile;
110 const char *zIn;
111 Blob file;
112 Blob hash;
113 Blob compressed;
114 Stmt ins;
115 if( g.argc!=4 && g.argc!=5 ) usage("add FILE ?INPUT?");
116 zFile = g.argv[3];
117 if( !file_is_simple_pathname(zFile,1) ){
118 fossil_fatal("'%Q' is not an acceptable filename", zFile);
119 }
120 zIn = g.argc==5 ? g.argv[4] : "-";
121 blob_init(&file,0,0);
122 blob_read_from_file(&file, zIn);
123 sha1sum_blob(&file, &hash);
124 blob_compress(&file, &compressed);
125 db_begin_transaction();
126 content_rcvid_init();
127 db_prepare(&ins,
128 "REPLACE INTO unversioned(name,rcvid,mtime,hash,sz,content)"
129 " VALUES(:name,:rcvid,:mtime,:hash,:sz,:content)"
130 );
131 db_bind_text(&ins, ":name", zFile);
132 db_bind_int(&ins, ":rcvid", g.rcvid);
133 db_bind_int64(&ins, ":mtime", mtime);
134 db_bind_text(&ins, ":hash", blob_str(&hash));
135 db_bind_int(&ins, ":sz", blob_size(&file));
136 db_bind_blob(&ins, ":content", &compressed);
137 db_step(&ins);
138 db_finalize(&ins);
139 blob_reset(&compressed);
140 blob_reset(&hash);
141 blob_reset(&file);
142 /* Clear the uvhash cache */
143 db_end_transaction(0);
144 }else if( memcmp(zCmd, "cat", nCmd)==0 ){
145 }else if( memcmp(zCmd, "list", nCmd)==0 || memcmp(zCmd, "ls", nCmd)==0 ){
146 Stmt q;
147 db_prepare(&q,
148 "SELECT hash, datetime(mtime,'unixepoch'), sz, name, content IS NULL"
149 " FROM unversioned"
150 " WHERE hash IS NOT NULL"
151 " ORDER BY name;"
152 );
153 while( db_step(&q)==SQLITE_ROW ){
154 fossil_print("%12.12s %s %8d %s%s\n",
155 db_column_text(&q,0),
156 db_column_text(&q,1),
157 db_column_int(&q,2),
158 db_column_text(&q,3),
159 db_column_int(&q,4) ? " ** no content ** ": ""
160 );
161 }
162 db_finalize(&q);
163 }else if( memcmp(zCmd, "revert", nCmd)==0 || memcmp(zCmd,"sync",nCmd)==0 ){
164 fossil_fatal("not yet implemented...");
165 }else if( memcmp(zCmd, "rm", nCmd)==0 ){
166 }else{
167 usage("add|cat|ls|revert|rm|sync");
@@ -152,11 +204,11 @@
204
205 The client sends uvgimme if
206
207 (a) it does not possess NAME or
208 (b) if the NAME it holds has an earlier timestamp than TIMESTAMP or
209 (c) if the NAME it holds has the exact timestamp TIMESTAMP but a
210 lexicographically earliers HASH.
211
212 Otherwise the client sends a uvfile. The client also sends uvfile
213 cards for each unversioned file it holds which was not named by any
214 uvigot card.
215

Keyboard Shortcuts

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