Fossil SCM

Use stable marks derived from the rid in preparation for optional incremental exports.

joerg 2011-07-21 17:37 trunk
Commit 22d414e517b5846de1a0849f69f385ea015d3c6f
1 file changed +11 -11
+11 -11
--- src/export.c
+++ src/export.c
@@ -78,10 +78,12 @@
7878
free(zName);
7979
free(zEmail);
8080
db_reset(&q);
8181
}
8282
83
+#define BLOBMARK(rid) ((rid) * 2)
84
+#define COMMITMARK(rid) ((rid) * 2 + 1)
8385
8486
/*
8587
** COMMAND: export
8688
**
8789
** Usage: %fossil export --git ?REPOSITORY?
@@ -99,11 +101,10 @@
99101
** or wiki or events or attachments, so none of those are exported.
100102
*/
101103
void export_cmd(void){
102104
Stmt q;
103105
int i;
104
- int firstCkin; /* Integer offset to check-in marks */
105106
Bag blobs, vers;
106107
bag_init(&blobs);
107108
bag_init(&vers);
108109
109110
find_option("git", 0, 0); /* Ignore the --git option for now */
@@ -118,21 +119,20 @@
118119
db_prepare(&q, "SELECT DISTINCT fid FROM mlink WHERE fid>0");
119120
while( db_step(&q)==SQLITE_ROW ){
120121
int rid = db_column_int(&q, 0);
121122
Blob content;
122123
content_get(rid, &content);
123
- printf("blob\nmark :%d\ndata %d\n", rid, blob_size(&content));
124
+ printf("blob\nmark :%d\ndata %d\n", BLOBMARK(rid), blob_size(&content));
124125
bag_insert(&blobs, rid);
125126
fwrite(blob_buffer(&content), 1, blob_size(&content), stdout);
126127
printf("\n");
127128
blob_reset(&content);
128129
}
129130
db_finalize(&q);
130131
131132
/* Output the commit records.
132133
*/
133
- firstCkin = db_int(0, "SELECT max(rid) FROM blob")+1;
134134
db_prepare(&q,
135135
"SELECT strftime('%%s',mtime), objid, coalesce(comment,ecomment),"
136136
" coalesce(user,euser),"
137137
" (SELECT value FROM tagxref WHERE rid=objid AND tagid=%d)"
138138
" FROM event"
@@ -153,11 +153,11 @@
153153
if( zBranch==0 ) zBranch = "trunk";
154154
zBr = mprintf("%s", zBranch);
155155
for(i=0; zBr[i]; i++){
156156
if( !fossil_isalnum(zBr[i]) ) zBr[i] = '_';
157157
}
158
- printf("commit refs/heads/%s\nmark :%d\n", zBr, ckinId+firstCkin);
158
+ printf("commit refs/heads/%s\nmark :%d\n", zBr, COMMITMARK(ckinId));
159159
free(zBr);
160160
printf("committer");
161161
print_person(zUser);
162162
printf(" %s +0000\n", zSecondsSince1970);
163163
if( zComment==0 ) zComment = "null comment";
@@ -171,11 +171,11 @@
171171
zFromType = "from";
172172
p = manifest_get(ckinId, CFTYPE_ANY);
173173
for(i=0; i<p->nParent; i++){
174174
int pid = fast_uuid_to_rid(p->azParent[i]);
175175
if( pid==0 || !bag_find(&vers, pid) ) continue;
176
- printf("%s :%d\n", zFromType, fast_uuid_to_rid(p->azParent[i])+firstCkin);
176
+ printf("%s :%d\n", zFromType, COMMITMARK(fast_uuid_to_rid(p->azParent[i])));
177177
zFromType = "merge";
178178
}
179179
printf("deleteall\n");
180180
manifest_file_rewind(p);
181181
while( (pFile=manifest_file_next(p, 0))!=0 ){
@@ -182,27 +182,27 @@
182182
int fid = fast_uuid_to_rid(pFile->zUuid);
183183
const char *zPerm = "100644";
184184
if( fid==0 ) continue;
185185
if( pFile->zPerm && strstr(pFile->zPerm,"x") ) zPerm = "100755";
186186
if( !bag_find(&blobs, fid) ) continue;
187
- printf("M %s :%d %s\n", zPerm, fid, pFile->zName);
187
+ printf("M %s :%d %s\n", zPerm, BLOBMARK(fid), pFile->zName);
188188
}
189189
manifest_cache_insert(p);
190190
}else{
191191
Stmt q3;
192192
int parent;
193193
194194
parent = db_column_int(&q2, 0);
195
- printf("from :%d\n", parent+firstCkin);
195
+ printf("from :%d\n", COMMITMARK(parent));
196196
db_prepare(&q3,
197197
"SELECT pid FROM plink"
198198
" WHERE cid=%d AND NOT isprim"
199199
" AND NOT EXISTS(SELECT 1 FROM phantom WHERE rid=pid)"
200200
" ORDER BY pid",
201201
ckinId);
202202
while( db_step(&q3)==SQLITE_ROW ){
203
- printf("merge :%d\n", db_column_int(&q3,0)+firstCkin);
203
+ printf("merge :%d\n", COMMITMARK(db_column_int(&q3,0)));
204204
}
205205
db_finalize(&q3);
206206
207207
db_prepare(&q3,
208208
"SELECT filename.name, mlink.fid, mlink.mperm FROM mlink"
@@ -214,12 +214,12 @@
214214
const char *zName = db_column_text(&q3,0);
215215
int zNew = db_column_int(&q3,1);
216216
int mPerm = db_column_int(&q3,2);
217217
if( zNew==0)
218218
printf("D %s\n", zName);
219
- else
220
- printf("M %s :%d %s\n", mPerm ? "100755" : "100644", zNew, zName);
219
+ else if( bag_find(&blobs, zNew) )
220
+ printf("M %s :%d %s\n", mPerm ? "100755" : "100644", BLOBMARK(zNew), zName);
221221
}
222222
db_finalize(&q3);
223223
}
224224
db_finalize(&q2);
225225
printf("\n");
@@ -246,13 +246,13 @@
246246
zEncoded = mprintf("%s", zTagname);
247247
for(i=0; zEncoded[i]; i++){
248248
if( !fossil_isalnum(zEncoded[i]) ) zEncoded[i] = '_';
249249
}
250250
printf("tag %s\n", zEncoded);
251
- printf("from :%d\n", rid+firstCkin);
251
+ printf("from :%d\n", COMMITMARK(rid));
252252
printf("tagger <tagger> %s +0000\n", zSecSince1970);
253253
printf("data 0\n");
254254
fossil_free(zEncoded);
255255
}
256256
db_finalize(&q);
257257
bag_clear(&vers);
258258
}
259259
--- src/export.c
+++ src/export.c
@@ -78,10 +78,12 @@
78 free(zName);
79 free(zEmail);
80 db_reset(&q);
81 }
82
 
 
83
84 /*
85 ** COMMAND: export
86 **
87 ** Usage: %fossil export --git ?REPOSITORY?
@@ -99,11 +101,10 @@
99 ** or wiki or events or attachments, so none of those are exported.
100 */
101 void export_cmd(void){
102 Stmt q;
103 int i;
104 int firstCkin; /* Integer offset to check-in marks */
105 Bag blobs, vers;
106 bag_init(&blobs);
107 bag_init(&vers);
108
109 find_option("git", 0, 0); /* Ignore the --git option for now */
@@ -118,21 +119,20 @@
118 db_prepare(&q, "SELECT DISTINCT fid FROM mlink WHERE fid>0");
119 while( db_step(&q)==SQLITE_ROW ){
120 int rid = db_column_int(&q, 0);
121 Blob content;
122 content_get(rid, &content);
123 printf("blob\nmark :%d\ndata %d\n", rid, blob_size(&content));
124 bag_insert(&blobs, rid);
125 fwrite(blob_buffer(&content), 1, blob_size(&content), stdout);
126 printf("\n");
127 blob_reset(&content);
128 }
129 db_finalize(&q);
130
131 /* Output the commit records.
132 */
133 firstCkin = db_int(0, "SELECT max(rid) FROM blob")+1;
134 db_prepare(&q,
135 "SELECT strftime('%%s',mtime), objid, coalesce(comment,ecomment),"
136 " coalesce(user,euser),"
137 " (SELECT value FROM tagxref WHERE rid=objid AND tagid=%d)"
138 " FROM event"
@@ -153,11 +153,11 @@
153 if( zBranch==0 ) zBranch = "trunk";
154 zBr = mprintf("%s", zBranch);
155 for(i=0; zBr[i]; i++){
156 if( !fossil_isalnum(zBr[i]) ) zBr[i] = '_';
157 }
158 printf("commit refs/heads/%s\nmark :%d\n", zBr, ckinId+firstCkin);
159 free(zBr);
160 printf("committer");
161 print_person(zUser);
162 printf(" %s +0000\n", zSecondsSince1970);
163 if( zComment==0 ) zComment = "null comment";
@@ -171,11 +171,11 @@
171 zFromType = "from";
172 p = manifest_get(ckinId, CFTYPE_ANY);
173 for(i=0; i<p->nParent; i++){
174 int pid = fast_uuid_to_rid(p->azParent[i]);
175 if( pid==0 || !bag_find(&vers, pid) ) continue;
176 printf("%s :%d\n", zFromType, fast_uuid_to_rid(p->azParent[i])+firstCkin);
177 zFromType = "merge";
178 }
179 printf("deleteall\n");
180 manifest_file_rewind(p);
181 while( (pFile=manifest_file_next(p, 0))!=0 ){
@@ -182,27 +182,27 @@
182 int fid = fast_uuid_to_rid(pFile->zUuid);
183 const char *zPerm = "100644";
184 if( fid==0 ) continue;
185 if( pFile->zPerm && strstr(pFile->zPerm,"x") ) zPerm = "100755";
186 if( !bag_find(&blobs, fid) ) continue;
187 printf("M %s :%d %s\n", zPerm, fid, pFile->zName);
188 }
189 manifest_cache_insert(p);
190 }else{
191 Stmt q3;
192 int parent;
193
194 parent = db_column_int(&q2, 0);
195 printf("from :%d\n", parent+firstCkin);
196 db_prepare(&q3,
197 "SELECT pid FROM plink"
198 " WHERE cid=%d AND NOT isprim"
199 " AND NOT EXISTS(SELECT 1 FROM phantom WHERE rid=pid)"
200 " ORDER BY pid",
201 ckinId);
202 while( db_step(&q3)==SQLITE_ROW ){
203 printf("merge :%d\n", db_column_int(&q3,0)+firstCkin);
204 }
205 db_finalize(&q3);
206
207 db_prepare(&q3,
208 "SELECT filename.name, mlink.fid, mlink.mperm FROM mlink"
@@ -214,12 +214,12 @@
214 const char *zName = db_column_text(&q3,0);
215 int zNew = db_column_int(&q3,1);
216 int mPerm = db_column_int(&q3,2);
217 if( zNew==0)
218 printf("D %s\n", zName);
219 else
220 printf("M %s :%d %s\n", mPerm ? "100755" : "100644", zNew, zName);
221 }
222 db_finalize(&q3);
223 }
224 db_finalize(&q2);
225 printf("\n");
@@ -246,13 +246,13 @@
246 zEncoded = mprintf("%s", zTagname);
247 for(i=0; zEncoded[i]; i++){
248 if( !fossil_isalnum(zEncoded[i]) ) zEncoded[i] = '_';
249 }
250 printf("tag %s\n", zEncoded);
251 printf("from :%d\n", rid+firstCkin);
252 printf("tagger <tagger> %s +0000\n", zSecSince1970);
253 printf("data 0\n");
254 fossil_free(zEncoded);
255 }
256 db_finalize(&q);
257 bag_clear(&vers);
258 }
259
--- src/export.c
+++ src/export.c
@@ -78,10 +78,12 @@
78 free(zName);
79 free(zEmail);
80 db_reset(&q);
81 }
82
83 #define BLOBMARK(rid) ((rid) * 2)
84 #define COMMITMARK(rid) ((rid) * 2 + 1)
85
86 /*
87 ** COMMAND: export
88 **
89 ** Usage: %fossil export --git ?REPOSITORY?
@@ -99,11 +101,10 @@
101 ** or wiki or events or attachments, so none of those are exported.
102 */
103 void export_cmd(void){
104 Stmt q;
105 int i;
 
106 Bag blobs, vers;
107 bag_init(&blobs);
108 bag_init(&vers);
109
110 find_option("git", 0, 0); /* Ignore the --git option for now */
@@ -118,21 +119,20 @@
119 db_prepare(&q, "SELECT DISTINCT fid FROM mlink WHERE fid>0");
120 while( db_step(&q)==SQLITE_ROW ){
121 int rid = db_column_int(&q, 0);
122 Blob content;
123 content_get(rid, &content);
124 printf("blob\nmark :%d\ndata %d\n", BLOBMARK(rid), blob_size(&content));
125 bag_insert(&blobs, rid);
126 fwrite(blob_buffer(&content), 1, blob_size(&content), stdout);
127 printf("\n");
128 blob_reset(&content);
129 }
130 db_finalize(&q);
131
132 /* Output the commit records.
133 */
 
134 db_prepare(&q,
135 "SELECT strftime('%%s',mtime), objid, coalesce(comment,ecomment),"
136 " coalesce(user,euser),"
137 " (SELECT value FROM tagxref WHERE rid=objid AND tagid=%d)"
138 " FROM event"
@@ -153,11 +153,11 @@
153 if( zBranch==0 ) zBranch = "trunk";
154 zBr = mprintf("%s", zBranch);
155 for(i=0; zBr[i]; i++){
156 if( !fossil_isalnum(zBr[i]) ) zBr[i] = '_';
157 }
158 printf("commit refs/heads/%s\nmark :%d\n", zBr, COMMITMARK(ckinId));
159 free(zBr);
160 printf("committer");
161 print_person(zUser);
162 printf(" %s +0000\n", zSecondsSince1970);
163 if( zComment==0 ) zComment = "null comment";
@@ -171,11 +171,11 @@
171 zFromType = "from";
172 p = manifest_get(ckinId, CFTYPE_ANY);
173 for(i=0; i<p->nParent; i++){
174 int pid = fast_uuid_to_rid(p->azParent[i]);
175 if( pid==0 || !bag_find(&vers, pid) ) continue;
176 printf("%s :%d\n", zFromType, COMMITMARK(fast_uuid_to_rid(p->azParent[i])));
177 zFromType = "merge";
178 }
179 printf("deleteall\n");
180 manifest_file_rewind(p);
181 while( (pFile=manifest_file_next(p, 0))!=0 ){
@@ -182,27 +182,27 @@
182 int fid = fast_uuid_to_rid(pFile->zUuid);
183 const char *zPerm = "100644";
184 if( fid==0 ) continue;
185 if( pFile->zPerm && strstr(pFile->zPerm,"x") ) zPerm = "100755";
186 if( !bag_find(&blobs, fid) ) continue;
187 printf("M %s :%d %s\n", zPerm, BLOBMARK(fid), pFile->zName);
188 }
189 manifest_cache_insert(p);
190 }else{
191 Stmt q3;
192 int parent;
193
194 parent = db_column_int(&q2, 0);
195 printf("from :%d\n", COMMITMARK(parent));
196 db_prepare(&q3,
197 "SELECT pid FROM plink"
198 " WHERE cid=%d AND NOT isprim"
199 " AND NOT EXISTS(SELECT 1 FROM phantom WHERE rid=pid)"
200 " ORDER BY pid",
201 ckinId);
202 while( db_step(&q3)==SQLITE_ROW ){
203 printf("merge :%d\n", COMMITMARK(db_column_int(&q3,0)));
204 }
205 db_finalize(&q3);
206
207 db_prepare(&q3,
208 "SELECT filename.name, mlink.fid, mlink.mperm FROM mlink"
@@ -214,12 +214,12 @@
214 const char *zName = db_column_text(&q3,0);
215 int zNew = db_column_int(&q3,1);
216 int mPerm = db_column_int(&q3,2);
217 if( zNew==0)
218 printf("D %s\n", zName);
219 else if( bag_find(&blobs, zNew) )
220 printf("M %s :%d %s\n", mPerm ? "100755" : "100644", BLOBMARK(zNew), zName);
221 }
222 db_finalize(&q3);
223 }
224 db_finalize(&q2);
225 printf("\n");
@@ -246,13 +246,13 @@
246 zEncoded = mprintf("%s", zTagname);
247 for(i=0; zEncoded[i]; i++){
248 if( !fossil_isalnum(zEncoded[i]) ) zEncoded[i] = '_';
249 }
250 printf("tag %s\n", zEncoded);
251 printf("from :%d\n", COMMITMARK(rid));
252 printf("tagger <tagger> %s +0000\n", zSecSince1970);
253 printf("data 0\n");
254 fossil_free(zEncoded);
255 }
256 db_finalize(&q);
257 bag_clear(&vers);
258 }
259

Keyboard Shortcuts

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