Fossil SCM

When creating manifest files as part of a "fossil import" command, ensure that "T" cards are added in sorted order, and that there are no duplicates.

dan 2011-06-10 15:14 trunk
Commit 6ed7ceb1dee5b273d02aca78a2b313e443e9f98f
1 file changed +30 -6
+30 -6
--- src/import.c
+++ src/import.c
@@ -207,10 +207,19 @@
207207
static int mfile_cmp(const void *pLeft, const void *pRight){
208208
const ImportFile *pA = (const ImportFile*)pLeft;
209209
const ImportFile *pB = (const ImportFile*)pRight;
210210
return fossil_strcmp(pA->zName, pB->zName);
211211
}
212
+
213
+/*
214
+** Compare two strings for sorting.
215
+*/
216
+static int string_cmp(const void *pLeft, const void *pRight){
217
+ const char *zLeft = *(char const **)pLeft;
218
+ const char *zRight = *(char const **)pRight;
219
+ return fossil_strcmp(zLeft, zRight);
220
+}
212221
213222
/* Forward reference */
214223
static void import_prior_files(void);
215224
216225
/*
@@ -218,11 +227,14 @@
218227
** manifest artifact to the BLOB table.
219228
*/
220229
static void finish_commit(void){
221230
int i;
222231
char *zFromBranch;
232
+ char *aTCard[4]; /* Array of T cards for manifest */
233
+ int nTCard = 0; /* Entries used in aTCard[] */
223234
Blob record, cksum;
235
+
224236
import_prior_files();
225237
qsort(gg.aFile, gg.nFile, sizeof(gg.aFile[0]), mfile_cmp);
226238
blob_zero(&record);
227239
blob_appendf(&record, "C %F\n", gg.zComment);
228240
blob_appendf(&record, "D %s\n", gg.zDate);
@@ -245,21 +257,33 @@
245257
zFromBranch = db_text(0, "SELECT brnm FROM xbranch WHERE tname=%Q",
246258
gg.zFromMark);
247259
}else{
248260
zFromBranch = 0;
249261
}
262
+
263
+ /* Add the required "T" cards to the manifest. Make sure they are added
264
+ ** in sorted order and without any duplicates. Otherwise, fossil will not
265
+ ** recognize the document as a valid manifest. */
250266
if( !gg.tagCommit && fossil_strcmp(zFromBranch, gg.zBranch)!=0 ){
251
- blob_appendf(&record, "T *branch * %F\n", gg.zBranch);
252
- blob_appendf(&record, "T *sym-%F *\n", gg.zBranch);
267
+ aTCard[nTCard++] = mprintf("T *branch * %F\n", gg.zBranch);
268
+ aTCard[nTCard++] = mprintf("T *sym-%F *\n", gg.zBranch);
253269
if( zFromBranch ){
254
- blob_appendf(&record, "T -sym-%F *\n", zFromBranch);
270
+ aTCard[nTCard++] = mprintf("T -sym-%F *\n", zFromBranch);
271
+ }
272
+ }
273
+ if( gg.zFrom==0 ){
274
+ aTCard[nTCard++] = mprintf("T *sym-trunk *\n");
275
+ }
276
+ qsort(aTCard, nTCard, sizeof(char *), string_cmp);
277
+ for(i=0; i<nTCard; i++){
278
+ if( i==0 || fossil_strcmp(aTCard[i-1], aTCard[i]) ){
279
+ blob_appendf(&record, "%s", aTCard[i]);
255280
}
256281
}
282
+ for(i=0; i<nTCard; i++) free(aTCard[i]);
283
+
257284
free(zFromBranch);
258
- if( gg.zFrom==0 ){
259
- blob_appendf(&record, "T *sym-trunk *\n");
260
- }
261285
db_multi_exec("INSERT INTO xbranch(tname, brnm) VALUES(%Q,%Q)",
262286
gg.zMark, gg.zBranch);
263287
blob_appendf(&record, "U %F\n", gg.zUser);
264288
md5sum_blob(&record, &cksum);
265289
blob_appendf(&record, "Z %b\n", &cksum);
266290
--- src/import.c
+++ src/import.c
@@ -207,10 +207,19 @@
207 static int mfile_cmp(const void *pLeft, const void *pRight){
208 const ImportFile *pA = (const ImportFile*)pLeft;
209 const ImportFile *pB = (const ImportFile*)pRight;
210 return fossil_strcmp(pA->zName, pB->zName);
211 }
 
 
 
 
 
 
 
 
 
212
213 /* Forward reference */
214 static void import_prior_files(void);
215
216 /*
@@ -218,11 +227,14 @@
218 ** manifest artifact to the BLOB table.
219 */
220 static void finish_commit(void){
221 int i;
222 char *zFromBranch;
 
 
223 Blob record, cksum;
 
224 import_prior_files();
225 qsort(gg.aFile, gg.nFile, sizeof(gg.aFile[0]), mfile_cmp);
226 blob_zero(&record);
227 blob_appendf(&record, "C %F\n", gg.zComment);
228 blob_appendf(&record, "D %s\n", gg.zDate);
@@ -245,21 +257,33 @@
245 zFromBranch = db_text(0, "SELECT brnm FROM xbranch WHERE tname=%Q",
246 gg.zFromMark);
247 }else{
248 zFromBranch = 0;
249 }
 
 
 
 
250 if( !gg.tagCommit && fossil_strcmp(zFromBranch, gg.zBranch)!=0 ){
251 blob_appendf(&record, "T *branch * %F\n", gg.zBranch);
252 blob_appendf(&record, "T *sym-%F *\n", gg.zBranch);
253 if( zFromBranch ){
254 blob_appendf(&record, "T -sym-%F *\n", zFromBranch);
 
 
 
 
 
 
 
 
 
255 }
256 }
 
 
257 free(zFromBranch);
258 if( gg.zFrom==0 ){
259 blob_appendf(&record, "T *sym-trunk *\n");
260 }
261 db_multi_exec("INSERT INTO xbranch(tname, brnm) VALUES(%Q,%Q)",
262 gg.zMark, gg.zBranch);
263 blob_appendf(&record, "U %F\n", gg.zUser);
264 md5sum_blob(&record, &cksum);
265 blob_appendf(&record, "Z %b\n", &cksum);
266
--- src/import.c
+++ src/import.c
@@ -207,10 +207,19 @@
207 static int mfile_cmp(const void *pLeft, const void *pRight){
208 const ImportFile *pA = (const ImportFile*)pLeft;
209 const ImportFile *pB = (const ImportFile*)pRight;
210 return fossil_strcmp(pA->zName, pB->zName);
211 }
212
213 /*
214 ** Compare two strings for sorting.
215 */
216 static int string_cmp(const void *pLeft, const void *pRight){
217 const char *zLeft = *(char const **)pLeft;
218 const char *zRight = *(char const **)pRight;
219 return fossil_strcmp(zLeft, zRight);
220 }
221
222 /* Forward reference */
223 static void import_prior_files(void);
224
225 /*
@@ -218,11 +227,14 @@
227 ** manifest artifact to the BLOB table.
228 */
229 static void finish_commit(void){
230 int i;
231 char *zFromBranch;
232 char *aTCard[4]; /* Array of T cards for manifest */
233 int nTCard = 0; /* Entries used in aTCard[] */
234 Blob record, cksum;
235
236 import_prior_files();
237 qsort(gg.aFile, gg.nFile, sizeof(gg.aFile[0]), mfile_cmp);
238 blob_zero(&record);
239 blob_appendf(&record, "C %F\n", gg.zComment);
240 blob_appendf(&record, "D %s\n", gg.zDate);
@@ -245,21 +257,33 @@
257 zFromBranch = db_text(0, "SELECT brnm FROM xbranch WHERE tname=%Q",
258 gg.zFromMark);
259 }else{
260 zFromBranch = 0;
261 }
262
263 /* Add the required "T" cards to the manifest. Make sure they are added
264 ** in sorted order and without any duplicates. Otherwise, fossil will not
265 ** recognize the document as a valid manifest. */
266 if( !gg.tagCommit && fossil_strcmp(zFromBranch, gg.zBranch)!=0 ){
267 aTCard[nTCard++] = mprintf("T *branch * %F\n", gg.zBranch);
268 aTCard[nTCard++] = mprintf("T *sym-%F *\n", gg.zBranch);
269 if( zFromBranch ){
270 aTCard[nTCard++] = mprintf("T -sym-%F *\n", zFromBranch);
271 }
272 }
273 if( gg.zFrom==0 ){
274 aTCard[nTCard++] = mprintf("T *sym-trunk *\n");
275 }
276 qsort(aTCard, nTCard, sizeof(char *), string_cmp);
277 for(i=0; i<nTCard; i++){
278 if( i==0 || fossil_strcmp(aTCard[i-1], aTCard[i]) ){
279 blob_appendf(&record, "%s", aTCard[i]);
280 }
281 }
282 for(i=0; i<nTCard; i++) free(aTCard[i]);
283
284 free(zFromBranch);
 
 
 
285 db_multi_exec("INSERT INTO xbranch(tname, brnm) VALUES(%Q,%Q)",
286 gg.zMark, gg.zBranch);
287 blob_appendf(&record, "U %F\n", gg.zUser);
288 md5sum_blob(&record, &cksum);
289 blob_appendf(&record, "Z %b\n", &cksum);
290

Keyboard Shortcuts

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