Fossil SCM
First cut at the "bundle export" command. Enhancements to "bundle ls".
Commit
a2f04d81735d49b67d68480551aaff4751a3098b
Parent
b2a56a76d55c998…
1 file changed
+58
-8
+58
-8
| --- src/bundle.c | ||
| +++ src/bundle.c | ||
| @@ -60,18 +60,27 @@ | ||
| 60 | 60 | /* |
| 61 | 61 | ** fossil bundle ls BUNDLE ?OPTIONS? |
| 62 | 62 | ** |
| 63 | 63 | ** Display the content of a bundle in human-readable form. |
| 64 | 64 | */ |
| 65 | -static void bundle_ls(void){ | |
| 65 | +static void bundle_ls_cmd(void){ | |
| 66 | 66 | Stmt q; |
| 67 | 67 | sqlite3_int64 sumSz = 0; |
| 68 | 68 | sqlite3_int64 sumLen = 0; |
| 69 | 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); | |
| 70 | 79 | db_prepare(&q, |
| 71 | 80 | "SELECT blobid, substr(uuid,1,16), coalesce(substr(delta,1,16),'')," |
| 72 | - " sz, length(data)" | |
| 81 | + " sz, length(data)" | |
| 73 | 82 | " FROM bblob" |
| 74 | 83 | ); |
| 75 | 84 | while( db_step(&q)==SQLITE_ROW ){ |
| 76 | 85 | fossil_print("%4d %16s %16s %10d %10d\n", |
| 77 | 86 | db_column_int(&q,0), |
| @@ -81,19 +90,19 @@ | ||
| 81 | 90 | db_column_int(&q,4)); |
| 82 | 91 | sumSz += db_column_int(&q,3); |
| 83 | 92 | sumLen += db_column_int(&q,4); |
| 84 | 93 | } |
| 85 | 94 | db_finalize(&q); |
| 86 | - fossil_print("%38s %10lld %10lld\n", "Total:", sumSz, sumLen); | |
| 95 | + fossil_print("%39s %10lld %10lld\n", "Total:", sumSz, sumLen); | |
| 87 | 96 | } |
| 88 | 97 | |
| 89 | 98 | /* |
| 90 | 99 | ** Implement the "fossil bundle append BUNDLE FILE..." command. Add |
| 91 | 100 | ** the named files into the BUNDLE. Create the BUNDLE if it does not |
| 92 | 101 | ** alraedy exist. |
| 93 | 102 | */ |
| 94 | -static void bundle_append(void){ | |
| 103 | +static void bundle_append_cmd(void){ | |
| 95 | 104 | char *zFilename; |
| 96 | 105 | Blob content, hash; |
| 97 | 106 | int i; |
| 98 | 107 | Stmt q; |
| 99 | 108 | |
| @@ -181,11 +190,11 @@ | ||
| 181 | 190 | } |
| 182 | 191 | if( zBr ){ |
| 183 | 192 | blob_appendf(&sql, |
| 184 | 193 | " AND EXISTS(SELECT 1 FROM tagxref" |
| 185 | 194 | " WHERE tagid=%d AND tagtype>0" |
| 186 | - " AND value=%Q and rid=plink.cid))", | |
| 195 | + " AND value=%Q and rid=plink.cid)", | |
| 187 | 196 | TAG_BRANCH, zBr); |
| 188 | 197 | } |
| 189 | 198 | blob_appendf(&sql, ") INSERT OR IGNORE INTO \"%w\" SELECT rid FROM child;", |
| 190 | 199 | zTab); |
| 191 | 200 | db_multi_exec("%s", blob_str(&sql)/*safe-for-%s*/); |
| @@ -228,10 +237,51 @@ | ||
| 228 | 237 | db_column_text(&q, 1)); |
| 229 | 238 | } |
| 230 | 239 | db_finalize(&q); |
| 231 | 240 | db_end_transaction(1); |
| 232 | 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 | +} | |
| 233 | 283 | |
| 234 | 284 | /* |
| 235 | 285 | ** COMMAND: bundle |
| 236 | 286 | ** |
| 237 | 287 | ** Usage: %fossil bundle SUBCOMMAND ARGS... |
| @@ -287,18 +337,18 @@ | ||
| 287 | 337 | if( g.argc<4 ) usage("SUBCOMMAND BUNDLE ?ARGUMENTS?"); |
| 288 | 338 | zSubcmd = g.argv[2]; |
| 289 | 339 | db_find_and_open_repository(0,0); |
| 290 | 340 | n = (int)strlen(zSubcmd); |
| 291 | 341 | if( strncmp(zSubcmd, "export", n)==0 ){ |
| 292 | - fossil_print("Not yet implemented...\n"); | |
| 342 | + bundle_export_cmd(); | |
| 293 | 343 | }else if( strncmp(zSubcmd, "import", n)==0 ){ |
| 294 | 344 | fossil_print("Not yet implemented...\n"); |
| 295 | 345 | }else if( strncmp(zSubcmd, "ls", n)==0 ){ |
| 296 | - bundle_ls(); | |
| 346 | + bundle_ls_cmd(); | |
| 297 | 347 | }else if( strncmp(zSubcmd, "append", n)==0 ){ |
| 298 | - bundle_append(); | |
| 348 | + bundle_append_cmd(); | |
| 299 | 349 | }else if( strncmp(zSubcmd, "extract", n)==0 ){ |
| 300 | 350 | fossil_print("Not yet implemented...\n"); |
| 301 | 351 | }else{ |
| 302 | 352 | fossil_fatal("unknown subcommand for bundle: %s", zSubcmd); |
| 303 | 353 | } |
| 304 | 354 | } |
| 305 | 355 |
| --- 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 |