Fossil SCM

First cut at the "bundle export" command. Enhancements to "bundle ls".

drh 2014-11-25 23:15 UTC DBP-workflow
Commit a2f04d81735d49b67d68480551aaff4751a3098b
1 file changed +58 -8
+58 -8
--- src/bundle.c
+++ src/bundle.c
@@ -60,18 +60,27 @@
6060
/*
6161
** fossil bundle ls BUNDLE ?OPTIONS?
6262
**
6363
** Display the content of a bundle in human-readable form.
6464
*/
65
-static void bundle_ls(void){
65
+static void bundle_ls_cmd(void){
6666
Stmt q;
6767
sqlite3_int64 sumSz = 0;
6868
sqlite3_int64 sumLen = 0;
6969
bundle_attach_file(g.argv[3], "b1", 0);
70
+ db_prepare(&q,
71
+ "SELECT bcname, bcvalue FROM bconfig"
72
+ " WHERE typeof(bcvalue)='text'"
73
+ " AND bcvalue NOT GLOB char(0x2a,0x0a,0x2a);"
74
+ );
75
+ while( db_step(&q)==SQLITE_ROW ){
76
+ fossil_print("%s: %s\n", db_column_text(&q,0), db_column_text(&q,1));
77
+ }
78
+ db_finalize(&q);
7079
db_prepare(&q,
7180
"SELECT blobid, substr(uuid,1,16), coalesce(substr(delta,1,16),''),"
72
- " sz, length(data)"
81
+ " sz, length(data)"
7382
" FROM bblob"
7483
);
7584
while( db_step(&q)==SQLITE_ROW ){
7685
fossil_print("%4d %16s %16s %10d %10d\n",
7786
db_column_int(&q,0),
@@ -81,19 +90,19 @@
8190
db_column_int(&q,4));
8291
sumSz += db_column_int(&q,3);
8392
sumLen += db_column_int(&q,4);
8493
}
8594
db_finalize(&q);
86
- fossil_print("%38s %10lld %10lld\n", "Total:", sumSz, sumLen);
95
+ fossil_print("%39s %10lld %10lld\n", "Total:", sumSz, sumLen);
8796
}
8897
8998
/*
9099
** Implement the "fossil bundle append BUNDLE FILE..." command. Add
91100
** the named files into the BUNDLE. Create the BUNDLE if it does not
92101
** alraedy exist.
93102
*/
94
-static void bundle_append(void){
103
+static void bundle_append_cmd(void){
95104
char *zFilename;
96105
Blob content, hash;
97106
int i;
98107
Stmt q;
99108
@@ -181,11 +190,11 @@
181190
}
182191
if( zBr ){
183192
blob_appendf(&sql,
184193
" AND EXISTS(SELECT 1 FROM tagxref"
185194
" WHERE tagid=%d AND tagtype>0"
186
- " AND value=%Q and rid=plink.cid))",
195
+ " AND value=%Q and rid=plink.cid)",
187196
TAG_BRANCH, zBr);
188197
}
189198
blob_appendf(&sql, ") INSERT OR IGNORE INTO \"%w\" SELECT rid FROM child;",
190199
zTab);
191200
db_multi_exec("%s", blob_str(&sql)/*safe-for-%s*/);
@@ -228,10 +237,51 @@
228237
db_column_text(&q, 1));
229238
}
230239
db_finalize(&q);
231240
db_end_transaction(1);
232241
}
242
+
243
+/* fossil bundle export BUNDLE ?OPTIONS?
244
+**
245
+** OPTIONS:
246
+** --branch BRANCH
247
+** --from TAG
248
+** --to TAG
249
+** --checkin TAG
250
+*/
251
+static void bundle_export_cmd(void){
252
+ db_multi_exec("CREATE TEMP TABLE tobundle(rid INTEGER PRIMARY KEY);");
253
+ subtree_from_arguments("tobundle");
254
+ verify_all_options();
255
+ bundle_attach_file(g.argv[3], "b1", 1);
256
+ find_checkin_associates("tobundle");
257
+ db_begin_transaction();
258
+ db_multi_exec(
259
+ "REPLACE INTO bblob(blobid,uuid,sz,delta,data) "
260
+ " SELECT"
261
+ " tobundle.rid,"
262
+ " b1.uuid,"
263
+ " b1.size,"
264
+ " CASE WHEN delta.srcid NOT IN tobundle"
265
+ " THEN (SELECT uuid FROM blob WHERE rid=delta.srcid)"
266
+ " ELSE delta.srcid END,"
267
+ " b1.content"
268
+ " FROM tobundle"
269
+ " JOIN blob AS b1 ON b1.rid=tobundle.rid"
270
+ " LEFT JOIN delta ON delta.rid=tobundle.rid"
271
+ );
272
+ db_multi_exec(
273
+ "INSERT INTO bconfig(bcname,bcvalue)"
274
+ " VALUES('mtime',datetime('now'));"
275
+ );
276
+ db_multi_exec(
277
+ "INSERT INTO bconfig(bcname,bcvalue)"
278
+ " SELECT name, value FROM config"
279
+ " WHERE name IN ('project-code');"
280
+ );
281
+ db_end_transaction(0);
282
+}
233283
234284
/*
235285
** COMMAND: bundle
236286
**
237287
** Usage: %fossil bundle SUBCOMMAND ARGS...
@@ -287,18 +337,18 @@
287337
if( g.argc<4 ) usage("SUBCOMMAND BUNDLE ?ARGUMENTS?");
288338
zSubcmd = g.argv[2];
289339
db_find_and_open_repository(0,0);
290340
n = (int)strlen(zSubcmd);
291341
if( strncmp(zSubcmd, "export", n)==0 ){
292
- fossil_print("Not yet implemented...\n");
342
+ bundle_export_cmd();
293343
}else if( strncmp(zSubcmd, "import", n)==0 ){
294344
fossil_print("Not yet implemented...\n");
295345
}else if( strncmp(zSubcmd, "ls", n)==0 ){
296
- bundle_ls();
346
+ bundle_ls_cmd();
297347
}else if( strncmp(zSubcmd, "append", n)==0 ){
298
- bundle_append();
348
+ bundle_append_cmd();
299349
}else if( strncmp(zSubcmd, "extract", n)==0 ){
300350
fossil_print("Not yet implemented...\n");
301351
}else{
302352
fossil_fatal("unknown subcommand for bundle: %s", zSubcmd);
303353
}
304354
}
305355
--- src/bundle.c
+++ src/bundle.c
@@ -60,18 +60,27 @@
60 /*
61 ** fossil bundle ls BUNDLE ?OPTIONS?
62 **
63 ** Display the content of a bundle in human-readable form.
64 */
65 static void bundle_ls(void){
66 Stmt q;
67 sqlite3_int64 sumSz = 0;
68 sqlite3_int64 sumLen = 0;
69 bundle_attach_file(g.argv[3], "b1", 0);
 
 
 
 
 
 
 
 
 
70 db_prepare(&q,
71 "SELECT blobid, substr(uuid,1,16), coalesce(substr(delta,1,16),''),"
72 " sz, length(data)"
73 " FROM bblob"
74 );
75 while( db_step(&q)==SQLITE_ROW ){
76 fossil_print("%4d %16s %16s %10d %10d\n",
77 db_column_int(&q,0),
@@ -81,19 +90,19 @@
81 db_column_int(&q,4));
82 sumSz += db_column_int(&q,3);
83 sumLen += db_column_int(&q,4);
84 }
85 db_finalize(&q);
86 fossil_print("%38s %10lld %10lld\n", "Total:", sumSz, sumLen);
87 }
88
89 /*
90 ** Implement the "fossil bundle append BUNDLE FILE..." command. Add
91 ** the named files into the BUNDLE. Create the BUNDLE if it does not
92 ** alraedy exist.
93 */
94 static void bundle_append(void){
95 char *zFilename;
96 Blob content, hash;
97 int i;
98 Stmt q;
99
@@ -181,11 +190,11 @@
181 }
182 if( zBr ){
183 blob_appendf(&sql,
184 " AND EXISTS(SELECT 1 FROM tagxref"
185 " WHERE tagid=%d AND tagtype>0"
186 " AND value=%Q and rid=plink.cid))",
187 TAG_BRANCH, zBr);
188 }
189 blob_appendf(&sql, ") INSERT OR IGNORE INTO \"%w\" SELECT rid FROM child;",
190 zTab);
191 db_multi_exec("%s", blob_str(&sql)/*safe-for-%s*/);
@@ -228,10 +237,51 @@
228 db_column_text(&q, 1));
229 }
230 db_finalize(&q);
231 db_end_transaction(1);
232 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
234 /*
235 ** COMMAND: bundle
236 **
237 ** Usage: %fossil bundle SUBCOMMAND ARGS...
@@ -287,18 +337,18 @@
287 if( g.argc<4 ) usage("SUBCOMMAND BUNDLE ?ARGUMENTS?");
288 zSubcmd = g.argv[2];
289 db_find_and_open_repository(0,0);
290 n = (int)strlen(zSubcmd);
291 if( strncmp(zSubcmd, "export", n)==0 ){
292 fossil_print("Not yet implemented...\n");
293 }else if( strncmp(zSubcmd, "import", n)==0 ){
294 fossil_print("Not yet implemented...\n");
295 }else if( strncmp(zSubcmd, "ls", n)==0 ){
296 bundle_ls();
297 }else if( strncmp(zSubcmd, "append", n)==0 ){
298 bundle_append();
299 }else if( strncmp(zSubcmd, "extract", n)==0 ){
300 fossil_print("Not yet implemented...\n");
301 }else{
302 fossil_fatal("unknown subcommand for bundle: %s", zSubcmd);
303 }
304 }
305
--- src/bundle.c
+++ src/bundle.c
@@ -60,18 +60,27 @@
60 /*
61 ** fossil bundle ls BUNDLE ?OPTIONS?
62 **
63 ** Display the content of a bundle in human-readable form.
64 */
65 static void bundle_ls_cmd(void){
66 Stmt q;
67 sqlite3_int64 sumSz = 0;
68 sqlite3_int64 sumLen = 0;
69 bundle_attach_file(g.argv[3], "b1", 0);
70 db_prepare(&q,
71 "SELECT bcname, bcvalue FROM bconfig"
72 " WHERE typeof(bcvalue)='text'"
73 " AND bcvalue NOT GLOB char(0x2a,0x0a,0x2a);"
74 );
75 while( db_step(&q)==SQLITE_ROW ){
76 fossil_print("%s: %s\n", db_column_text(&q,0), db_column_text(&q,1));
77 }
78 db_finalize(&q);
79 db_prepare(&q,
80 "SELECT blobid, substr(uuid,1,16), coalesce(substr(delta,1,16),''),"
81 " sz, length(data)"
82 " FROM bblob"
83 );
84 while( db_step(&q)==SQLITE_ROW ){
85 fossil_print("%4d %16s %16s %10d %10d\n",
86 db_column_int(&q,0),
@@ -81,19 +90,19 @@
90 db_column_int(&q,4));
91 sumSz += db_column_int(&q,3);
92 sumLen += db_column_int(&q,4);
93 }
94 db_finalize(&q);
95 fossil_print("%39s %10lld %10lld\n", "Total:", sumSz, sumLen);
96 }
97
98 /*
99 ** Implement the "fossil bundle append BUNDLE FILE..." command. Add
100 ** the named files into the BUNDLE. Create the BUNDLE if it does not
101 ** alraedy exist.
102 */
103 static void bundle_append_cmd(void){
104 char *zFilename;
105 Blob content, hash;
106 int i;
107 Stmt q;
108
@@ -181,11 +190,11 @@
190 }
191 if( zBr ){
192 blob_appendf(&sql,
193 " AND EXISTS(SELECT 1 FROM tagxref"
194 " WHERE tagid=%d AND tagtype>0"
195 " AND value=%Q and rid=plink.cid)",
196 TAG_BRANCH, zBr);
197 }
198 blob_appendf(&sql, ") INSERT OR IGNORE INTO \"%w\" SELECT rid FROM child;",
199 zTab);
200 db_multi_exec("%s", blob_str(&sql)/*safe-for-%s*/);
@@ -228,10 +237,51 @@
237 db_column_text(&q, 1));
238 }
239 db_finalize(&q);
240 db_end_transaction(1);
241 }
242
243 /* fossil bundle export BUNDLE ?OPTIONS?
244 **
245 ** OPTIONS:
246 ** --branch BRANCH
247 ** --from TAG
248 ** --to TAG
249 ** --checkin TAG
250 */
251 static void bundle_export_cmd(void){
252 db_multi_exec("CREATE TEMP TABLE tobundle(rid INTEGER PRIMARY KEY);");
253 subtree_from_arguments("tobundle");
254 verify_all_options();
255 bundle_attach_file(g.argv[3], "b1", 1);
256 find_checkin_associates("tobundle");
257 db_begin_transaction();
258 db_multi_exec(
259 "REPLACE INTO bblob(blobid,uuid,sz,delta,data) "
260 " SELECT"
261 " tobundle.rid,"
262 " b1.uuid,"
263 " b1.size,"
264 " CASE WHEN delta.srcid NOT IN tobundle"
265 " THEN (SELECT uuid FROM blob WHERE rid=delta.srcid)"
266 " ELSE delta.srcid END,"
267 " b1.content"
268 " FROM tobundle"
269 " JOIN blob AS b1 ON b1.rid=tobundle.rid"
270 " LEFT JOIN delta ON delta.rid=tobundle.rid"
271 );
272 db_multi_exec(
273 "INSERT INTO bconfig(bcname,bcvalue)"
274 " VALUES('mtime',datetime('now'));"
275 );
276 db_multi_exec(
277 "INSERT INTO bconfig(bcname,bcvalue)"
278 " SELECT name, value FROM config"
279 " WHERE name IN ('project-code');"
280 );
281 db_end_transaction(0);
282 }
283
284 /*
285 ** COMMAND: bundle
286 **
287 ** Usage: %fossil bundle SUBCOMMAND ARGS...
@@ -287,18 +337,18 @@
337 if( g.argc<4 ) usage("SUBCOMMAND BUNDLE ?ARGUMENTS?");
338 zSubcmd = g.argv[2];
339 db_find_and_open_repository(0,0);
340 n = (int)strlen(zSubcmd);
341 if( strncmp(zSubcmd, "export", n)==0 ){
342 bundle_export_cmd();
343 }else if( strncmp(zSubcmd, "import", n)==0 ){
344 fossil_print("Not yet implemented...\n");
345 }else if( strncmp(zSubcmd, "ls", n)==0 ){
346 bundle_ls_cmd();
347 }else if( strncmp(zSubcmd, "append", n)==0 ){
348 bundle_append_cmd();
349 }else if( strncmp(zSubcmd, "extract", n)==0 ){
350 fossil_print("Not yet implemented...\n");
351 }else{
352 fossil_fatal("unknown subcommand for bundle: %s", zSubcmd);
353 }
354 }
355

Keyboard Shortcuts

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