Fossil SCM

Change the bundle on-disk format slightly. Add the "bundle ls" command.

drh 2014-11-25 22:43 UTC DBP-workflow
Commit b2a56a76d55c99860a1ed4dba0440f939fd2b178
1 file changed +35 -6
+35 -6
--- src/bundle.c
+++ src/bundle.c
@@ -21,10 +21,16 @@
2121
#include "bundle.h"
2222
#include <assert.h>
2323
2424
/*
2525
** SQL code used to initialize the schema of a bundle.
26
+**
27
+** The bblob.delta field can be an integer, a text string, or NULL.
28
+** If an integer, then the corresponding blobid is the delta basis.
29
+** If a text string, then that string is a SHA1 hash for the delta
30
+** basis, which is presumably in the master repository. If NULL, then
31
+** data contains contain without delta compression.
2632
*/
2733
static const char zBundleInit[] =
2834
@ CREATE TABLE IF NOT EXISTS "%w".bconfig(
2935
@ bcname TEXT,
3036
@ bcvalue ANY
@@ -31,11 +37,11 @@
3137
@ );
3238
@ CREATE TABLE IF NOT EXISTS "%w".bblob(
3339
@ blobid INTEGER PRIMARY KEY, -- Blob ID
3440
@ uuid TEXT NOT NULL, -- SHA1 hash of expanded blob
3541
@ sz INT NOT NULL, -- Size of blob after expansion
36
-@ delta INT REFERENCES bblob, -- Delta compression basis, or NULL
42
+@ delta ANY, -- Delta compression basis, or NULL
3743
@ data BLOB -- compressed content
3844
@ );
3945
;
4046
4147
/*
@@ -50,26 +56,51 @@
5056
db_multi_exec("ATTACH %Q AS %Q;", zFile, zBName);
5157
db_multi_exec(zBundleInit /*works-like:"%w%w"*/, zBName, zBName);
5258
}
5359
5460
/*
55
-** List the content of a bundle
61
+** fossil bundle ls BUNDLE ?OPTIONS?
62
+**
63
+** Display the content of a bundle in human-readable form.
5664
*/
5765
static void bundle_ls(void){
58
-
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),
78
+ db_column_text(&q,1),
79
+ db_column_text(&q,2),
80
+ db_column_int(&q,3),
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);
5987
}
6088
6189
/*
62
-** Implement the "fossil bundle append BUNDLE FILE..." command.
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.
6393
*/
6494
static void bundle_append(void){
6595
char *zFilename;
6696
Blob content, hash;
6797
int i;
6898
Stmt q;
6999
70100
verify_all_options();
101
+ bundle_attach_file(g.argv[3], "b1", 1);
71102
db_prepare(&q,
72103
"INSERT INTO bblob(blobid, uuid, sz, delta, data) "
73104
"VALUES(NULL, $uuid, $sz, NULL, $data)");
74105
db_begin_transaction();
75106
for(i=4; i<g.argc; i++){
@@ -254,12 +285,10 @@
254285
const char *zBundleFile;
255286
int n;
256287
if( g.argc<4 ) usage("SUBCOMMAND BUNDLE ?ARGUMENTS?");
257288
zSubcmd = g.argv[2];
258289
db_find_and_open_repository(0,0);
259
- zBundleFile = g.argv[3];
260
- bundle_attach_file(zBundleFile, "b1", 1);
261290
n = (int)strlen(zSubcmd);
262291
if( strncmp(zSubcmd, "export", n)==0 ){
263292
fossil_print("Not yet implemented...\n");
264293
}else if( strncmp(zSubcmd, "import", n)==0 ){
265294
fossil_print("Not yet implemented...\n");
266295
--- src/bundle.c
+++ src/bundle.c
@@ -21,10 +21,16 @@
21 #include "bundle.h"
22 #include <assert.h>
23
24 /*
25 ** SQL code used to initialize the schema of a bundle.
 
 
 
 
 
 
26 */
27 static const char zBundleInit[] =
28 @ CREATE TABLE IF NOT EXISTS "%w".bconfig(
29 @ bcname TEXT,
30 @ bcvalue ANY
@@ -31,11 +37,11 @@
31 @ );
32 @ CREATE TABLE IF NOT EXISTS "%w".bblob(
33 @ blobid INTEGER PRIMARY KEY, -- Blob ID
34 @ uuid TEXT NOT NULL, -- SHA1 hash of expanded blob
35 @ sz INT NOT NULL, -- Size of blob after expansion
36 @ delta INT REFERENCES bblob, -- Delta compression basis, or NULL
37 @ data BLOB -- compressed content
38 @ );
39 ;
40
41 /*
@@ -50,26 +56,51 @@
50 db_multi_exec("ATTACH %Q AS %Q;", zFile, zBName);
51 db_multi_exec(zBundleInit /*works-like:"%w%w"*/, zBName, zBName);
52 }
53
54 /*
55 ** List the content of a bundle
 
 
56 */
57 static void bundle_ls(void){
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59 }
60
61 /*
62 ** Implement the "fossil bundle append BUNDLE FILE..." command.
 
 
63 */
64 static void bundle_append(void){
65 char *zFilename;
66 Blob content, hash;
67 int i;
68 Stmt q;
69
70 verify_all_options();
 
71 db_prepare(&q,
72 "INSERT INTO bblob(blobid, uuid, sz, delta, data) "
73 "VALUES(NULL, $uuid, $sz, NULL, $data)");
74 db_begin_transaction();
75 for(i=4; i<g.argc; i++){
@@ -254,12 +285,10 @@
254 const char *zBundleFile;
255 int n;
256 if( g.argc<4 ) usage("SUBCOMMAND BUNDLE ?ARGUMENTS?");
257 zSubcmd = g.argv[2];
258 db_find_and_open_repository(0,0);
259 zBundleFile = g.argv[3];
260 bundle_attach_file(zBundleFile, "b1", 1);
261 n = (int)strlen(zSubcmd);
262 if( strncmp(zSubcmd, "export", n)==0 ){
263 fossil_print("Not yet implemented...\n");
264 }else if( strncmp(zSubcmd, "import", n)==0 ){
265 fossil_print("Not yet implemented...\n");
266
--- src/bundle.c
+++ src/bundle.c
@@ -21,10 +21,16 @@
21 #include "bundle.h"
22 #include <assert.h>
23
24 /*
25 ** SQL code used to initialize the schema of a bundle.
26 **
27 ** The bblob.delta field can be an integer, a text string, or NULL.
28 ** If an integer, then the corresponding blobid is the delta basis.
29 ** If a text string, then that string is a SHA1 hash for the delta
30 ** basis, which is presumably in the master repository. If NULL, then
31 ** data contains contain without delta compression.
32 */
33 static const char zBundleInit[] =
34 @ CREATE TABLE IF NOT EXISTS "%w".bconfig(
35 @ bcname TEXT,
36 @ bcvalue ANY
@@ -31,11 +37,11 @@
37 @ );
38 @ CREATE TABLE IF NOT EXISTS "%w".bblob(
39 @ blobid INTEGER PRIMARY KEY, -- Blob ID
40 @ uuid TEXT NOT NULL, -- SHA1 hash of expanded blob
41 @ sz INT NOT NULL, -- Size of blob after expansion
42 @ delta ANY, -- Delta compression basis, or NULL
43 @ data BLOB -- compressed content
44 @ );
45 ;
46
47 /*
@@ -50,26 +56,51 @@
56 db_multi_exec("ATTACH %Q AS %Q;", zFile, zBName);
57 db_multi_exec(zBundleInit /*works-like:"%w%w"*/, zBName, zBName);
58 }
59
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),
78 db_column_text(&q,1),
79 db_column_text(&q,2),
80 db_column_int(&q,3),
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
100 verify_all_options();
101 bundle_attach_file(g.argv[3], "b1", 1);
102 db_prepare(&q,
103 "INSERT INTO bblob(blobid, uuid, sz, delta, data) "
104 "VALUES(NULL, $uuid, $sz, NULL, $data)");
105 db_begin_transaction();
106 for(i=4; i<g.argc; i++){
@@ -254,12 +285,10 @@
285 const char *zBundleFile;
286 int n;
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

Keyboard Shortcuts

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