Fossil SCM

Not really take over schema change, just don't bark when the repository has a future schema.

jan.nijtmans 2015-01-27 03:24 sqlite3-compat
Commit aca8b6d32a6bf54f16a22e7d72cdf5d75b8ad770
3 files changed +1 -1 +53 -64 +7 -30
+1 -1
--- src/db.c
+++ src/db.c
@@ -1254,11 +1254,11 @@
12541254
/*
12551255
** Return TRUE if the schema is out-of-date
12561256
*/
12571257
int db_schema_is_outofdate(void){
12581258
return strcmp(g.zAuxSchema,AUX_SCHEMA_MIN)<0
1259
- || strcmp(g.zAuxSchema,AUX_SCHEMA_MAX)>0;
1259
+ || strcmp(g.zAuxSchema,"2015-01-24")>0;
12601260
}
12611261
12621262
/*
12631263
** Return true if the database is writeable
12641264
*/
12651265
--- src/db.c
+++ src/db.c
@@ -1254,11 +1254,11 @@
1254 /*
1255 ** Return TRUE if the schema is out-of-date
1256 */
1257 int db_schema_is_outofdate(void){
1258 return strcmp(g.zAuxSchema,AUX_SCHEMA_MIN)<0
1259 || strcmp(g.zAuxSchema,AUX_SCHEMA_MAX)>0;
1260 }
1261
1262 /*
1263 ** Return true if the database is writeable
1264 */
1265
--- src/db.c
+++ src/db.c
@@ -1254,11 +1254,11 @@
1254 /*
1255 ** Return TRUE if the schema is out-of-date
1256 */
1257 int db_schema_is_outofdate(void){
1258 return strcmp(g.zAuxSchema,AUX_SCHEMA_MIN)<0
1259 || strcmp(g.zAuxSchema,"2015-01-24")>0;
1260 }
1261
1262 /*
1263 ** Return true if the database is writeable
1264 */
1265
+53 -64
--- src/manifest.c
+++ src/manifest.c
@@ -1187,18 +1187,16 @@
11871187
/*
11881188
** Add a single entry to the mlink table. Also add the filename to
11891189
** the filename table if it is not there already.
11901190
*/
11911191
static void add_one_mlink(
1192
- int pmid, /* The parent manifest */
1193
- const char *zFromUuid, /* UUID for content in parent */
11941192
int mid, /* The record ID of the manifest */
1195
- const char *zToUuid, /* UUID for content in child */
1193
+ const char *zFromUuid, /* UUID for the mlink.pid. "" to add file */
1194
+ const char *zToUuid, /* UUID for the mlink.fid. "" to delete */
11961195
const char *zFilename, /* Filename */
11971196
const char *zPrior, /* Previous filename. NULL if unchanged */
11981197
int isPublic, /* True if mid is not a private manifest */
1199
- int isPrimary, /* pmid is the primary parent of mid */
12001198
int mperm /* 1: exec, 2: symlink */
12011199
){
12021200
int fnid, pfnid, pid, fid;
12031201
static Stmt s1;
12041202
@@ -1218,21 +1216,19 @@
12181216
}else{
12191217
fid = uuid_to_rid(zToUuid, 1);
12201218
if( isPublic ) content_make_public(fid);
12211219
}
12221220
db_static_prepare(&s1,
1223
- "INSERT INTO mlink(mid,fid,pmid,pid,fnid,pfnid,mperm,isaux)"
1224
- "VALUES(:m,:f,:pm,:p,:n,:pfn,:mp,:isaux)"
1221
+ "INSERT INTO mlink(mid,pid,fid,fnid,pfnid,mperm)"
1222
+ "VALUES(:m,:p,:f,:n,:pfn,:mp)"
12251223
);
12261224
db_bind_int(&s1, ":m", mid);
1227
- db_bind_int(&s1, ":f", fid);
1228
- db_bind_int(&s1, ":pm", pmid);
12291225
db_bind_int(&s1, ":p", pid);
1226
+ db_bind_int(&s1, ":f", fid);
12301227
db_bind_int(&s1, ":n", fnid);
12311228
db_bind_int(&s1, ":pfn", pfnid);
12321229
db_bind_int(&s1, ":mp", mperm);
1233
- db_bind_int(&s1, ":isaux", isPrimary==0);
12341230
db_exec(&s1);
12351231
if( pid && fid ){
12361232
content_deltify(pid, fid, 0);
12371233
}
12381234
}
@@ -1346,29 +1342,24 @@
13461342
**
13471343
** Deleted files have mlink.fid=0.
13481344
** Added files have mlink.pid=0.
13491345
** Edited files have both mlink.pid!=0 and mlink.fid!=0
13501346
*/
1351
-static void add_mlink(
1352
- int pmid, Manifest *pParent, /* Parent check-in */
1353
- int mid, Manifest *pChild, /* The child check-in */
1354
- int isPrim /* TRUE if pmid is the primary parent of mid */
1355
-){
1347
+static void add_mlink(int pid, Manifest *pParent, int cid, Manifest *pChild){
13561348
Blob otherContent;
13571349
int otherRid;
13581350
int i, rc;
13591351
ManifestFile *pChildFile, *pParentFile;
13601352
Manifest **ppOther;
13611353
static Stmt eq;
13621354
int isPublic; /* True if pChild is non-private */
13631355
1364
- /* If mlink table entires are already exist for the pmid-to-mid transition,
1365
- ** then abort early doing no work.
1356
+ /* If mlink table entires are already set for cid, then abort early
1357
+ ** doing no work.
13661358
*/
1367
- db_static_prepare(&eq, "SELECT 1 FROM mlink WHERE mid=:mid AND pmid=:pmid");
1368
- db_bind_int(&eq, ":mid", mid);
1369
- db_bind_int(&eq, ":pmid", pmid);
1359
+ db_static_prepare(&eq, "SELECT 1 FROM mlink WHERE mid=:mid");
1360
+ db_bind_int(&eq, ":mid", cid);
13701361
rc = db_step(&eq);
13711362
db_reset(&eq);
13721363
if( rc==SQLITE_ROW ) return;
13731364
13741365
/* Compute the value of the missing pParent or pChild parameter.
@@ -1375,14 +1366,14 @@
13751366
** Fetch the baseline checkins for both.
13761367
*/
13771368
assert( pParent==0 || pChild==0 );
13781369
if( pParent==0 ){
13791370
ppOther = &pParent;
1380
- otherRid = pmid;
1371
+ otherRid = pid;
13811372
}else{
13821373
ppOther = &pChild;
1383
- otherRid = mid;
1374
+ otherRid = cid;
13841375
}
13851376
if( (*ppOther = manifest_cache_find(otherRid))==0 ){
13861377
content_get(otherRid, &otherContent);
13871378
if( blob_size(&otherContent)==0 ) return;
13881379
*ppOther = manifest_parse(&otherContent, otherRid, 0);
@@ -1390,20 +1381,20 @@
13901381
}
13911382
if( fetch_baseline(pParent, 0) || fetch_baseline(pChild, 0) ){
13921383
manifest_destroy(*ppOther);
13931384
return;
13941385
}
1395
- isPublic = !content_is_private(mid);
1386
+ isPublic = !content_is_private(cid);
13961387
13971388
/* Try to make the parent manifest a delta from the child, if that
13981389
** is an appropriate thing to do. For a new baseline, make the
13991390
** previous baseline a delta from the current baseline.
14001391
*/
14011392
if( (pParent->zBaseline==0)==(pChild->zBaseline==0) ){
1402
- content_deltify(pmid, mid, 0);
1393
+ content_deltify(pid, cid, 0);
14031394
}else if( pChild->zBaseline==0 && pParent->zBaseline!=0 ){
1404
- content_deltify(pParent->pBaseline->rid, mid, 0);
1395
+ content_deltify(pParent->pBaseline->rid, cid, 0);
14051396
}
14061397
14071398
/* Remember all children less than a few seconds younger than their parent,
14081399
** as we might want to fudge the times for those children.
14091400
*/
@@ -1423,32 +1414,31 @@
14231414
int mperm = manifest_file_mperm(pChildFile);
14241415
if( pChildFile->zPrior ){
14251416
pParentFile = manifest_file_seek(pParent, pChildFile->zPrior, 0);
14261417
if( pParentFile ){
14271418
/* File with name change */
1428
- add_one_mlink(pmid, pParentFile->zUuid, mid, pChildFile->zUuid,
1429
- pChildFile->zName, pChildFile->zPrior,
1430
- isPublic, isPrim, mperm);
1419
+ add_one_mlink(cid, pParentFile->zUuid, pChildFile->zUuid,
1420
+ pChildFile->zName, pChildFile->zPrior, isPublic, mperm);
14311421
}else{
14321422
/* File name changed, but the old name is not found in the parent!
14331423
** Treat this like a new file. */
1434
- add_one_mlink(pmid, 0, mid, pChildFile->zUuid, pChildFile->zName, 0,
1435
- isPublic, isPrim, mperm);
1424
+ add_one_mlink(cid, 0, pChildFile->zUuid, pChildFile->zName, 0,
1425
+ isPublic, mperm);
14361426
}
14371427
}else{
14381428
pParentFile = manifest_file_seek(pParent, pChildFile->zName, 0);
14391429
if( pParentFile==0 ){
14401430
if( pChildFile->zUuid ){
14411431
/* A new file */
1442
- add_one_mlink(pmid, 0, mid, pChildFile->zUuid, pChildFile->zName, 0,
1443
- isPublic, isPrim, mperm);
1432
+ add_one_mlink(cid, 0, pChildFile->zUuid, pChildFile->zName, 0,
1433
+ isPublic, mperm);
14441434
}
14451435
}else if( fossil_strcmp(pChildFile->zUuid, pParentFile->zUuid)!=0
14461436
|| manifest_file_mperm(pParentFile)!=mperm ){
14471437
/* Changes in file content or permissions */
1448
- add_one_mlink(pmid, pParentFile->zUuid, mid, pChildFile->zUuid,
1449
- pChildFile->zName, 0, isPublic, isPrim, mperm);
1438
+ add_one_mlink(cid, pParentFile->zUuid, pChildFile->zUuid,
1439
+ pChildFile->zName, 0, isPublic, mperm);
14501440
}
14511441
}
14521442
}
14531443
if( pParent->zBaseline && pChild->zBaseline ){
14541444
/* Both parent and child are delta manifests. Look for files that
@@ -1460,22 +1450,22 @@
14601450
pChildFile = manifest_file_seek_base(pChild, pParentFile->zName, 0);
14611451
if( pChildFile==0 ){
14621452
/* The child file reverts to baseline. Show this as a change */
14631453
pChildFile = manifest_file_seek(pChild, pParentFile->zName, 0);
14641454
if( pChildFile ){
1465
- add_one_mlink(pmid, pParentFile->zUuid, mid, pChildFile->zUuid,
1466
- pChildFile->zName, 0, isPublic, isPrim,
1455
+ add_one_mlink(cid, pParentFile->zUuid, pChildFile->zUuid,
1456
+ pChildFile->zName, 0, isPublic,
14671457
manifest_file_mperm(pChildFile));
14681458
}
14691459
}
14701460
}else{
14711461
pChildFile = manifest_file_seek(pChild, pParentFile->zName, 0);
14721462
if( pChildFile ){
14731463
/* File resurrected in the child after having been deleted in
14741464
** the parent. Show this as an added file. */
1475
- add_one_mlink(pmid, 0, mid, pChildFile->zUuid, pChildFile->zName, 0,
1476
- isPublic, isPrim, manifest_file_mperm(pChildFile));
1465
+ add_one_mlink(cid, 0, pChildFile->zUuid, pChildFile->zName, 0,
1466
+ isPublic, manifest_file_mperm(pChildFile));
14771467
}
14781468
}
14791469
}
14801470
}else if( pChild->zBaseline==0 ){
14811471
/* pChild is a baseline. Look for files that are present in pParent
@@ -1482,12 +1472,12 @@
14821472
** but are missing from pChild and mark them as having been deleted. */
14831473
manifest_file_rewind(pParent);
14841474
while( (pParentFile = manifest_file_next(pParent,0))!=0 ){
14851475
pChildFile = manifest_file_seek(pChild, pParentFile->zName, 0);
14861476
if( pChildFile==0 && pParentFile->zUuid!=0 ){
1487
- add_one_mlink(pmid, pParentFile->zUuid, mid, 0, pParentFile->zName, 0,
1488
- isPublic, isPrim, 0);
1477
+ add_one_mlink(cid, pParentFile->zUuid, 0, pParentFile->zName, 0,
1478
+ isPublic, 0);
14891479
}
14901480
}
14911481
}
14921482
manifest_cache_insert(*ppOther);
14931483
}
@@ -1791,46 +1781,45 @@
17911781
sqlite3_snprintf(sizeof(zBaseId), zBaseId, "%d",
17921782
uuid_to_rid(p->zBaseline,1));
17931783
}else{
17941784
sqlite3_snprintf(sizeof(zBaseId), zBaseId, "NULL");
17951785
}
1786
+ (void)db_schema_is_outofdate(); /* Make sure g.zAuxSchema is initialized */
17961787
for(i=0; i<p->nParent; i++){
17971788
int pid = uuid_to_rid(p->azParent[i], 1);
1798
- db_multi_exec(
1799
- "INSERT OR IGNORE INTO plink(pid, cid, isprim, mtime, baseid)"
1800
- "VALUES(%d, %d, %d, %.17g, %s)",
1801
- pid, rid, i==0, p->rDate, zBaseId/*safe-for-%s*/);
1802
- add_mlink(pid, 0, rid, p, i==0);
1803
- if( i==0 ) parentid = pid;
1804
- }
1805
- if( p->nParent>1 ){
1806
- /* Remove incorrect MLINK create-file entries that arise when a
1807
- ** file is added by merge. */
1808
- db_multi_exec(
1809
- "DELETE FROM mlink"
1810
- " WHERE mid=%d"
1811
- " AND pid=0"
1812
- " AND fnid IN "
1813
- " (SELECT fnid FROM mlink WHERE mid=%d GROUP BY fnid"
1814
- " HAVING count(*)<%d)",
1815
- rid, rid, p->nParent
1816
- );
1817
- }
1818
- db_prepare(&q, "SELECT cid, isprim FROM plink WHERE pid=%d", rid);
1789
+ if( strcmp(g.zAuxSchema,"2014-11-24 20:35")>=0 ){
1790
+ /* Support for PLINK.BASEID added on 2014-11-24 */
1791
+ db_multi_exec(
1792
+ "INSERT OR IGNORE INTO plink(pid, cid, isprim, mtime, baseid)"
1793
+ "VALUES(%d, %d, %d, %.17g, %s)",
1794
+ pid, rid, i==0, p->rDate, zBaseId/*safe-for-%s*/);
1795
+ }else{
1796
+ /* Continue to work with older schema to avoid an unnecessary
1797
+ ** rebuild */
1798
+ db_multi_exec(
1799
+ "INSERT OR IGNORE INTO plink(pid, cid, isprim, mtime)"
1800
+ "VALUES(%d, %d, %d, %.17g)",
1801
+ pid, rid, i==0, p->rDate);
1802
+ }
1803
+ if( i==0 ){
1804
+ add_mlink(pid, 0, rid, p);
1805
+ parentid = pid;
1806
+ }
1807
+ }
1808
+ db_prepare(&q, "SELECT cid FROM plink WHERE pid=%d AND isprim", rid);
18191809
while( db_step(&q)==SQLITE_ROW ){
18201810
int cid = db_column_int(&q, 0);
1821
- int isprim = db_column_int(&q, 1);
1822
- add_mlink(rid, p, cid, 0, isprim);
1811
+ add_mlink(rid, p, cid, 0);
18231812
}
18241813
db_finalize(&q);
18251814
if( p->nParent==0 ){
18261815
/* For root files (files without parents) add mlink entries
18271816
** showing all content as new. */
18281817
int isPublic = !content_is_private(rid);
18291818
for(i=0; i<p->nFile; i++){
1830
- add_one_mlink(0, 0, rid, p->aFile[i].zUuid, p->aFile[i].zName, 0,
1831
- isPublic, 1, manifest_file_mperm(&p->aFile[i]));
1819
+ add_one_mlink(rid, 0, p->aFile[i].zUuid, p->aFile[i].zName, 0,
1820
+ isPublic, manifest_file_mperm(&p->aFile[i]));
18321821
}
18331822
}
18341823
db_multi_exec(
18351824
"REPLACE INTO event(type,mtime,objid,user,comment,"
18361825
"bgcolor,euser,ecomment,omtime)"
18371826
--- src/manifest.c
+++ src/manifest.c
@@ -1187,18 +1187,16 @@
1187 /*
1188 ** Add a single entry to the mlink table. Also add the filename to
1189 ** the filename table if it is not there already.
1190 */
1191 static void add_one_mlink(
1192 int pmid, /* The parent manifest */
1193 const char *zFromUuid, /* UUID for content in parent */
1194 int mid, /* The record ID of the manifest */
1195 const char *zToUuid, /* UUID for content in child */
 
1196 const char *zFilename, /* Filename */
1197 const char *zPrior, /* Previous filename. NULL if unchanged */
1198 int isPublic, /* True if mid is not a private manifest */
1199 int isPrimary, /* pmid is the primary parent of mid */
1200 int mperm /* 1: exec, 2: symlink */
1201 ){
1202 int fnid, pfnid, pid, fid;
1203 static Stmt s1;
1204
@@ -1218,21 +1216,19 @@
1218 }else{
1219 fid = uuid_to_rid(zToUuid, 1);
1220 if( isPublic ) content_make_public(fid);
1221 }
1222 db_static_prepare(&s1,
1223 "INSERT INTO mlink(mid,fid,pmid,pid,fnid,pfnid,mperm,isaux)"
1224 "VALUES(:m,:f,:pm,:p,:n,:pfn,:mp,:isaux)"
1225 );
1226 db_bind_int(&s1, ":m", mid);
1227 db_bind_int(&s1, ":f", fid);
1228 db_bind_int(&s1, ":pm", pmid);
1229 db_bind_int(&s1, ":p", pid);
 
1230 db_bind_int(&s1, ":n", fnid);
1231 db_bind_int(&s1, ":pfn", pfnid);
1232 db_bind_int(&s1, ":mp", mperm);
1233 db_bind_int(&s1, ":isaux", isPrimary==0);
1234 db_exec(&s1);
1235 if( pid && fid ){
1236 content_deltify(pid, fid, 0);
1237 }
1238 }
@@ -1346,29 +1342,24 @@
1346 **
1347 ** Deleted files have mlink.fid=0.
1348 ** Added files have mlink.pid=0.
1349 ** Edited files have both mlink.pid!=0 and mlink.fid!=0
1350 */
1351 static void add_mlink(
1352 int pmid, Manifest *pParent, /* Parent check-in */
1353 int mid, Manifest *pChild, /* The child check-in */
1354 int isPrim /* TRUE if pmid is the primary parent of mid */
1355 ){
1356 Blob otherContent;
1357 int otherRid;
1358 int i, rc;
1359 ManifestFile *pChildFile, *pParentFile;
1360 Manifest **ppOther;
1361 static Stmt eq;
1362 int isPublic; /* True if pChild is non-private */
1363
1364 /* If mlink table entires are already exist for the pmid-to-mid transition,
1365 ** then abort early doing no work.
1366 */
1367 db_static_prepare(&eq, "SELECT 1 FROM mlink WHERE mid=:mid AND pmid=:pmid");
1368 db_bind_int(&eq, ":mid", mid);
1369 db_bind_int(&eq, ":pmid", pmid);
1370 rc = db_step(&eq);
1371 db_reset(&eq);
1372 if( rc==SQLITE_ROW ) return;
1373
1374 /* Compute the value of the missing pParent or pChild parameter.
@@ -1375,14 +1366,14 @@
1375 ** Fetch the baseline checkins for both.
1376 */
1377 assert( pParent==0 || pChild==0 );
1378 if( pParent==0 ){
1379 ppOther = &pParent;
1380 otherRid = pmid;
1381 }else{
1382 ppOther = &pChild;
1383 otherRid = mid;
1384 }
1385 if( (*ppOther = manifest_cache_find(otherRid))==0 ){
1386 content_get(otherRid, &otherContent);
1387 if( blob_size(&otherContent)==0 ) return;
1388 *ppOther = manifest_parse(&otherContent, otherRid, 0);
@@ -1390,20 +1381,20 @@
1390 }
1391 if( fetch_baseline(pParent, 0) || fetch_baseline(pChild, 0) ){
1392 manifest_destroy(*ppOther);
1393 return;
1394 }
1395 isPublic = !content_is_private(mid);
1396
1397 /* Try to make the parent manifest a delta from the child, if that
1398 ** is an appropriate thing to do. For a new baseline, make the
1399 ** previous baseline a delta from the current baseline.
1400 */
1401 if( (pParent->zBaseline==0)==(pChild->zBaseline==0) ){
1402 content_deltify(pmid, mid, 0);
1403 }else if( pChild->zBaseline==0 && pParent->zBaseline!=0 ){
1404 content_deltify(pParent->pBaseline->rid, mid, 0);
1405 }
1406
1407 /* Remember all children less than a few seconds younger than their parent,
1408 ** as we might want to fudge the times for those children.
1409 */
@@ -1423,32 +1414,31 @@
1423 int mperm = manifest_file_mperm(pChildFile);
1424 if( pChildFile->zPrior ){
1425 pParentFile = manifest_file_seek(pParent, pChildFile->zPrior, 0);
1426 if( pParentFile ){
1427 /* File with name change */
1428 add_one_mlink(pmid, pParentFile->zUuid, mid, pChildFile->zUuid,
1429 pChildFile->zName, pChildFile->zPrior,
1430 isPublic, isPrim, mperm);
1431 }else{
1432 /* File name changed, but the old name is not found in the parent!
1433 ** Treat this like a new file. */
1434 add_one_mlink(pmid, 0, mid, pChildFile->zUuid, pChildFile->zName, 0,
1435 isPublic, isPrim, mperm);
1436 }
1437 }else{
1438 pParentFile = manifest_file_seek(pParent, pChildFile->zName, 0);
1439 if( pParentFile==0 ){
1440 if( pChildFile->zUuid ){
1441 /* A new file */
1442 add_one_mlink(pmid, 0, mid, pChildFile->zUuid, pChildFile->zName, 0,
1443 isPublic, isPrim, mperm);
1444 }
1445 }else if( fossil_strcmp(pChildFile->zUuid, pParentFile->zUuid)!=0
1446 || manifest_file_mperm(pParentFile)!=mperm ){
1447 /* Changes in file content or permissions */
1448 add_one_mlink(pmid, pParentFile->zUuid, mid, pChildFile->zUuid,
1449 pChildFile->zName, 0, isPublic, isPrim, mperm);
1450 }
1451 }
1452 }
1453 if( pParent->zBaseline && pChild->zBaseline ){
1454 /* Both parent and child are delta manifests. Look for files that
@@ -1460,22 +1450,22 @@
1460 pChildFile = manifest_file_seek_base(pChild, pParentFile->zName, 0);
1461 if( pChildFile==0 ){
1462 /* The child file reverts to baseline. Show this as a change */
1463 pChildFile = manifest_file_seek(pChild, pParentFile->zName, 0);
1464 if( pChildFile ){
1465 add_one_mlink(pmid, pParentFile->zUuid, mid, pChildFile->zUuid,
1466 pChildFile->zName, 0, isPublic, isPrim,
1467 manifest_file_mperm(pChildFile));
1468 }
1469 }
1470 }else{
1471 pChildFile = manifest_file_seek(pChild, pParentFile->zName, 0);
1472 if( pChildFile ){
1473 /* File resurrected in the child after having been deleted in
1474 ** the parent. Show this as an added file. */
1475 add_one_mlink(pmid, 0, mid, pChildFile->zUuid, pChildFile->zName, 0,
1476 isPublic, isPrim, manifest_file_mperm(pChildFile));
1477 }
1478 }
1479 }
1480 }else if( pChild->zBaseline==0 ){
1481 /* pChild is a baseline. Look for files that are present in pParent
@@ -1482,12 +1472,12 @@
1482 ** but are missing from pChild and mark them as having been deleted. */
1483 manifest_file_rewind(pParent);
1484 while( (pParentFile = manifest_file_next(pParent,0))!=0 ){
1485 pChildFile = manifest_file_seek(pChild, pParentFile->zName, 0);
1486 if( pChildFile==0 && pParentFile->zUuid!=0 ){
1487 add_one_mlink(pmid, pParentFile->zUuid, mid, 0, pParentFile->zName, 0,
1488 isPublic, isPrim, 0);
1489 }
1490 }
1491 }
1492 manifest_cache_insert(*ppOther);
1493 }
@@ -1791,46 +1781,45 @@
1791 sqlite3_snprintf(sizeof(zBaseId), zBaseId, "%d",
1792 uuid_to_rid(p->zBaseline,1));
1793 }else{
1794 sqlite3_snprintf(sizeof(zBaseId), zBaseId, "NULL");
1795 }
 
1796 for(i=0; i<p->nParent; i++){
1797 int pid = uuid_to_rid(p->azParent[i], 1);
1798 db_multi_exec(
1799 "INSERT OR IGNORE INTO plink(pid, cid, isprim, mtime, baseid)"
1800 "VALUES(%d, %d, %d, %.17g, %s)",
1801 pid, rid, i==0, p->rDate, zBaseId/*safe-for-%s*/);
1802 add_mlink(pid, 0, rid, p, i==0);
1803 if( i==0 ) parentid = pid;
1804 }
1805 if( p->nParent>1 ){
1806 /* Remove incorrect MLINK create-file entries that arise when a
1807 ** file is added by merge. */
1808 db_multi_exec(
1809 "DELETE FROM mlink"
1810 " WHERE mid=%d"
1811 " AND pid=0"
1812 " AND fnid IN "
1813 " (SELECT fnid FROM mlink WHERE mid=%d GROUP BY fnid"
1814 " HAVING count(*)<%d)",
1815 rid, rid, p->nParent
1816 );
1817 }
1818 db_prepare(&q, "SELECT cid, isprim FROM plink WHERE pid=%d", rid);
1819 while( db_step(&q)==SQLITE_ROW ){
1820 int cid = db_column_int(&q, 0);
1821 int isprim = db_column_int(&q, 1);
1822 add_mlink(rid, p, cid, 0, isprim);
1823 }
1824 db_finalize(&q);
1825 if( p->nParent==0 ){
1826 /* For root files (files without parents) add mlink entries
1827 ** showing all content as new. */
1828 int isPublic = !content_is_private(rid);
1829 for(i=0; i<p->nFile; i++){
1830 add_one_mlink(0, 0, rid, p->aFile[i].zUuid, p->aFile[i].zName, 0,
1831 isPublic, 1, manifest_file_mperm(&p->aFile[i]));
1832 }
1833 }
1834 db_multi_exec(
1835 "REPLACE INTO event(type,mtime,objid,user,comment,"
1836 "bgcolor,euser,ecomment,omtime)"
1837
--- src/manifest.c
+++ src/manifest.c
@@ -1187,18 +1187,16 @@
1187 /*
1188 ** Add a single entry to the mlink table. Also add the filename to
1189 ** the filename table if it is not there already.
1190 */
1191 static void add_one_mlink(
 
 
1192 int mid, /* The record ID of the manifest */
1193 const char *zFromUuid, /* UUID for the mlink.pid. "" to add file */
1194 const char *zToUuid, /* UUID for the mlink.fid. "" to delete */
1195 const char *zFilename, /* Filename */
1196 const char *zPrior, /* Previous filename. NULL if unchanged */
1197 int isPublic, /* True if mid is not a private manifest */
 
1198 int mperm /* 1: exec, 2: symlink */
1199 ){
1200 int fnid, pfnid, pid, fid;
1201 static Stmt s1;
1202
@@ -1218,21 +1216,19 @@
1216 }else{
1217 fid = uuid_to_rid(zToUuid, 1);
1218 if( isPublic ) content_make_public(fid);
1219 }
1220 db_static_prepare(&s1,
1221 "INSERT INTO mlink(mid,pid,fid,fnid,pfnid,mperm)"
1222 "VALUES(:m,:p,:f,:n,:pfn,:mp)"
1223 );
1224 db_bind_int(&s1, ":m", mid);
 
 
1225 db_bind_int(&s1, ":p", pid);
1226 db_bind_int(&s1, ":f", fid);
1227 db_bind_int(&s1, ":n", fnid);
1228 db_bind_int(&s1, ":pfn", pfnid);
1229 db_bind_int(&s1, ":mp", mperm);
 
1230 db_exec(&s1);
1231 if( pid && fid ){
1232 content_deltify(pid, fid, 0);
1233 }
1234 }
@@ -1346,29 +1342,24 @@
1342 **
1343 ** Deleted files have mlink.fid=0.
1344 ** Added files have mlink.pid=0.
1345 ** Edited files have both mlink.pid!=0 and mlink.fid!=0
1346 */
1347 static void add_mlink(int pid, Manifest *pParent, int cid, Manifest *pChild){
 
 
 
 
1348 Blob otherContent;
1349 int otherRid;
1350 int i, rc;
1351 ManifestFile *pChildFile, *pParentFile;
1352 Manifest **ppOther;
1353 static Stmt eq;
1354 int isPublic; /* True if pChild is non-private */
1355
1356 /* If mlink table entires are already set for cid, then abort early
1357 ** doing no work.
1358 */
1359 db_static_prepare(&eq, "SELECT 1 FROM mlink WHERE mid=:mid");
1360 db_bind_int(&eq, ":mid", cid);
 
1361 rc = db_step(&eq);
1362 db_reset(&eq);
1363 if( rc==SQLITE_ROW ) return;
1364
1365 /* Compute the value of the missing pParent or pChild parameter.
@@ -1375,14 +1366,14 @@
1366 ** Fetch the baseline checkins for both.
1367 */
1368 assert( pParent==0 || pChild==0 );
1369 if( pParent==0 ){
1370 ppOther = &pParent;
1371 otherRid = pid;
1372 }else{
1373 ppOther = &pChild;
1374 otherRid = cid;
1375 }
1376 if( (*ppOther = manifest_cache_find(otherRid))==0 ){
1377 content_get(otherRid, &otherContent);
1378 if( blob_size(&otherContent)==0 ) return;
1379 *ppOther = manifest_parse(&otherContent, otherRid, 0);
@@ -1390,20 +1381,20 @@
1381 }
1382 if( fetch_baseline(pParent, 0) || fetch_baseline(pChild, 0) ){
1383 manifest_destroy(*ppOther);
1384 return;
1385 }
1386 isPublic = !content_is_private(cid);
1387
1388 /* Try to make the parent manifest a delta from the child, if that
1389 ** is an appropriate thing to do. For a new baseline, make the
1390 ** previous baseline a delta from the current baseline.
1391 */
1392 if( (pParent->zBaseline==0)==(pChild->zBaseline==0) ){
1393 content_deltify(pid, cid, 0);
1394 }else if( pChild->zBaseline==0 && pParent->zBaseline!=0 ){
1395 content_deltify(pParent->pBaseline->rid, cid, 0);
1396 }
1397
1398 /* Remember all children less than a few seconds younger than their parent,
1399 ** as we might want to fudge the times for those children.
1400 */
@@ -1423,32 +1414,31 @@
1414 int mperm = manifest_file_mperm(pChildFile);
1415 if( pChildFile->zPrior ){
1416 pParentFile = manifest_file_seek(pParent, pChildFile->zPrior, 0);
1417 if( pParentFile ){
1418 /* File with name change */
1419 add_one_mlink(cid, pParentFile->zUuid, pChildFile->zUuid,
1420 pChildFile->zName, pChildFile->zPrior, isPublic, mperm);
 
1421 }else{
1422 /* File name changed, but the old name is not found in the parent!
1423 ** Treat this like a new file. */
1424 add_one_mlink(cid, 0, pChildFile->zUuid, pChildFile->zName, 0,
1425 isPublic, mperm);
1426 }
1427 }else{
1428 pParentFile = manifest_file_seek(pParent, pChildFile->zName, 0);
1429 if( pParentFile==0 ){
1430 if( pChildFile->zUuid ){
1431 /* A new file */
1432 add_one_mlink(cid, 0, pChildFile->zUuid, pChildFile->zName, 0,
1433 isPublic, mperm);
1434 }
1435 }else if( fossil_strcmp(pChildFile->zUuid, pParentFile->zUuid)!=0
1436 || manifest_file_mperm(pParentFile)!=mperm ){
1437 /* Changes in file content or permissions */
1438 add_one_mlink(cid, pParentFile->zUuid, pChildFile->zUuid,
1439 pChildFile->zName, 0, isPublic, mperm);
1440 }
1441 }
1442 }
1443 if( pParent->zBaseline && pChild->zBaseline ){
1444 /* Both parent and child are delta manifests. Look for files that
@@ -1460,22 +1450,22 @@
1450 pChildFile = manifest_file_seek_base(pChild, pParentFile->zName, 0);
1451 if( pChildFile==0 ){
1452 /* The child file reverts to baseline. Show this as a change */
1453 pChildFile = manifest_file_seek(pChild, pParentFile->zName, 0);
1454 if( pChildFile ){
1455 add_one_mlink(cid, pParentFile->zUuid, pChildFile->zUuid,
1456 pChildFile->zName, 0, isPublic,
1457 manifest_file_mperm(pChildFile));
1458 }
1459 }
1460 }else{
1461 pChildFile = manifest_file_seek(pChild, pParentFile->zName, 0);
1462 if( pChildFile ){
1463 /* File resurrected in the child after having been deleted in
1464 ** the parent. Show this as an added file. */
1465 add_one_mlink(cid, 0, pChildFile->zUuid, pChildFile->zName, 0,
1466 isPublic, manifest_file_mperm(pChildFile));
1467 }
1468 }
1469 }
1470 }else if( pChild->zBaseline==0 ){
1471 /* pChild is a baseline. Look for files that are present in pParent
@@ -1482,12 +1472,12 @@
1472 ** but are missing from pChild and mark them as having been deleted. */
1473 manifest_file_rewind(pParent);
1474 while( (pParentFile = manifest_file_next(pParent,0))!=0 ){
1475 pChildFile = manifest_file_seek(pChild, pParentFile->zName, 0);
1476 if( pChildFile==0 && pParentFile->zUuid!=0 ){
1477 add_one_mlink(cid, pParentFile->zUuid, 0, pParentFile->zName, 0,
1478 isPublic, 0);
1479 }
1480 }
1481 }
1482 manifest_cache_insert(*ppOther);
1483 }
@@ -1791,46 +1781,45 @@
1781 sqlite3_snprintf(sizeof(zBaseId), zBaseId, "%d",
1782 uuid_to_rid(p->zBaseline,1));
1783 }else{
1784 sqlite3_snprintf(sizeof(zBaseId), zBaseId, "NULL");
1785 }
1786 (void)db_schema_is_outofdate(); /* Make sure g.zAuxSchema is initialized */
1787 for(i=0; i<p->nParent; i++){
1788 int pid = uuid_to_rid(p->azParent[i], 1);
1789 if( strcmp(g.zAuxSchema,"2014-11-24 20:35")>=0 ){
1790 /* Support for PLINK.BASEID added on 2014-11-24 */
1791 db_multi_exec(
1792 "INSERT OR IGNORE INTO plink(pid, cid, isprim, mtime, baseid)"
1793 "VALUES(%d, %d, %d, %.17g, %s)",
1794 pid, rid, i==0, p->rDate, zBaseId/*safe-for-%s*/);
1795 }else{
1796 /* Continue to work with older schema to avoid an unnecessary
1797 ** rebuild */
1798 db_multi_exec(
1799 "INSERT OR IGNORE INTO plink(pid, cid, isprim, mtime)"
1800 "VALUES(%d, %d, %d, %.17g)",
1801 pid, rid, i==0, p->rDate);
1802 }
1803 if( i==0 ){
1804 add_mlink(pid, 0, rid, p);
1805 parentid = pid;
1806 }
1807 }
1808 db_prepare(&q, "SELECT cid FROM plink WHERE pid=%d AND isprim", rid);
 
1809 while( db_step(&q)==SQLITE_ROW ){
1810 int cid = db_column_int(&q, 0);
1811 add_mlink(rid, p, cid, 0);
 
1812 }
1813 db_finalize(&q);
1814 if( p->nParent==0 ){
1815 /* For root files (files without parents) add mlink entries
1816 ** showing all content as new. */
1817 int isPublic = !content_is_private(rid);
1818 for(i=0; i<p->nFile; i++){
1819 add_one_mlink(rid, 0, p->aFile[i].zUuid, p->aFile[i].zName, 0,
1820 isPublic, manifest_file_mperm(&p->aFile[i]));
1821 }
1822 }
1823 db_multi_exec(
1824 "REPLACE INTO event(type,mtime,objid,user,comment,"
1825 "bgcolor,euser,ecomment,omtime)"
1826
+7 -30
--- src/schema.c
+++ src/schema.c
@@ -45,14 +45,11 @@
4545
** we have to execute special procedures to update the schema. When
4646
** the aux schema changes, all we need to do is rebuild the database.
4747
*/
4848
#define CONTENT_SCHEMA "2"
4949
#define AUX_SCHEMA_MIN "2011-04-25 19:50"
50
-#define AUX_SCHEMA_MAX "2015-01-24"
51
-/* NB: Some features require the latest schema. Warning or error messages
52
-** will appear if an older schema is used. However, the older schemas are
53
-** adequate for many common functions. */
50
+#define AUX_SCHEMA_MAX "2014-11-24 20:35"
5451
5552
#endif /* INTERFACE */
5653
5754
5855
/*
@@ -230,41 +227,21 @@
230227
@ name TEXT UNIQUE -- Name of file page
231228
@ );
232229
@
233230
@ -- Linkages between checkins, files created by each checkin, and
234231
@ -- the names of those files.
235
-@ --
236
-@ -- Each entry represents a file that changed content from pid to fid
237
-@ -- due to the check-in that goes from pmid to mid. fnid is the name
238
-@ -- of the file in the mid check-in. If the file was renamed as part
239
-@ -- of the mid check-in, then pfnid is the previous filename.
240
-@
241
-@ -- There can be multiple entries for (mid,fid) if the mid checkin was
242
-@ -- a merge. Entries with isaux==0 are from the primary parent. Merge
243
-@ -- parents have isaux set to true.
244
-@ --
245
-@ -- Field name mnemonics:
246
-@ -- mid = Manifest ID. (Each check-in is stored as a "Manifest")
247
-@ -- fid = File ID.
248
-@ -- pmid = Parent Manifest ID.
249
-@ -- pid = Parent file ID.
250
-@ -- fnid = File Name ID.
251
-@ -- pfnid = Parent File Name ID.
252
-@ -- isaux = pmid IS AUXiliary parent, not primary parent
253232
@ --
254233
@ -- pid==0 if the file is added by checkin mid.
255234
@ -- fid==0 if the file is removed by checkin mid.
256235
@ --
257236
@ CREATE TABLE mlink(
258
-@ mid INTEGER REFERENCES plink(cid), -- Checkin that contains fid
259
-@ fid INTEGER REFERENCES blob, -- New file content. 0 if deleted
260
-@ pmid INTEGER REFERENCES plink(cid), -- Checkin that contains pid
261
-@ pid INTEGER REFERENCES blob, -- Prev file content. 0 if new
237
+@ mid INTEGER REFERENCES blob, -- Manifest ID where change occurs
238
+@ pid INTEGER REFERENCES blob, -- File ID in parent manifest
239
+@ fid INTEGER REFERENCES blob, -- Changed file ID in this manifest
262240
@ fnid INTEGER REFERENCES filename, -- Name of the file
263241
@ pfnid INTEGER REFERENCES filename, -- Previous name. 0 if unchanged
264
-@ mperm INTEGER, -- File permissions. 1==exec
265
-@ isaux BOOLEAN DEFAULT 0 -- TRUE if pmid is the primary
242
+@ mperm INTEGER -- File permissions. 1==exec
266243
@ );
267244
@ CREATE INDEX mlink_i1 ON mlink(mid);
268245
@ CREATE INDEX mlink_i2 ON mlink(fnid);
269246
@ CREATE INDEX mlink_i3 ON mlink(fid);
270247
@ CREATE INDEX mlink_i4 ON mlink(pid);
@@ -274,11 +251,11 @@
274251
@ CREATE TABLE plink(
275252
@ pid INTEGER REFERENCES blob, -- Parent manifest
276253
@ cid INTEGER REFERENCES blob, -- Child manifest
277254
@ isprim BOOLEAN, -- pid is the primary parent of cid
278255
@ mtime DATETIME, -- the date/time stamp on cid. Julian day.
279
-@ baseid INTEGER REFERENCES blob, -- Baseline if cid is a delta manifest.
256
+@ baseid INTEGER REFERENCES blob, -- Baseline if child is a delta manifest
280257
@ UNIQUE(pid, cid)
281258
@ );
282259
@ CREATE INDEX plink_i2 ON plink(cid,pid);
283260
@
284261
@ -- A "leaf" checkin is a checkin that has no children in the same
@@ -511,11 +488,11 @@
511488
@ -- current version of the file is already in the repository.
512489
@ --
513490
@ CREATE TABLE vfile(
514491
@ id INTEGER PRIMARY KEY, -- ID of the checked out file
515492
@ vid INTEGER REFERENCES blob, -- The baseline this file is part of.
516
-@ chnged INT DEFAULT 0, -- 0:unchng 1:edit 2:m-chng 3:m-add 4:i-chng 5:i-add
493
+@ chnged INT DEFAULT 0, -- 0:unchnged 1:edited 2:m-chng 3:m-add 4:i-chng 5:i-add
517494
@ deleted BOOLEAN DEFAULT 0, -- True if deleted
518495
@ isexe BOOLEAN, -- True if file should be executable
519496
@ islink BOOLEAN, -- True if file should be symlink
520497
@ rid INTEGER, -- Originally from this repository record
521498
@ mrid INTEGER, -- Based on this record due to a merge
522499
--- src/schema.c
+++ src/schema.c
@@ -45,14 +45,11 @@
45 ** we have to execute special procedures to update the schema. When
46 ** the aux schema changes, all we need to do is rebuild the database.
47 */
48 #define CONTENT_SCHEMA "2"
49 #define AUX_SCHEMA_MIN "2011-04-25 19:50"
50 #define AUX_SCHEMA_MAX "2015-01-24"
51 /* NB: Some features require the latest schema. Warning or error messages
52 ** will appear if an older schema is used. However, the older schemas are
53 ** adequate for many common functions. */
54
55 #endif /* INTERFACE */
56
57
58 /*
@@ -230,41 +227,21 @@
230 @ name TEXT UNIQUE -- Name of file page
231 @ );
232 @
233 @ -- Linkages between checkins, files created by each checkin, and
234 @ -- the names of those files.
235 @ --
236 @ -- Each entry represents a file that changed content from pid to fid
237 @ -- due to the check-in that goes from pmid to mid. fnid is the name
238 @ -- of the file in the mid check-in. If the file was renamed as part
239 @ -- of the mid check-in, then pfnid is the previous filename.
240 @
241 @ -- There can be multiple entries for (mid,fid) if the mid checkin was
242 @ -- a merge. Entries with isaux==0 are from the primary parent. Merge
243 @ -- parents have isaux set to true.
244 @ --
245 @ -- Field name mnemonics:
246 @ -- mid = Manifest ID. (Each check-in is stored as a "Manifest")
247 @ -- fid = File ID.
248 @ -- pmid = Parent Manifest ID.
249 @ -- pid = Parent file ID.
250 @ -- fnid = File Name ID.
251 @ -- pfnid = Parent File Name ID.
252 @ -- isaux = pmid IS AUXiliary parent, not primary parent
253 @ --
254 @ -- pid==0 if the file is added by checkin mid.
255 @ -- fid==0 if the file is removed by checkin mid.
256 @ --
257 @ CREATE TABLE mlink(
258 @ mid INTEGER REFERENCES plink(cid), -- Checkin that contains fid
259 @ fid INTEGER REFERENCES blob, -- New file content. 0 if deleted
260 @ pmid INTEGER REFERENCES plink(cid), -- Checkin that contains pid
261 @ pid INTEGER REFERENCES blob, -- Prev file content. 0 if new
262 @ fnid INTEGER REFERENCES filename, -- Name of the file
263 @ pfnid INTEGER REFERENCES filename, -- Previous name. 0 if unchanged
264 @ mperm INTEGER, -- File permissions. 1==exec
265 @ isaux BOOLEAN DEFAULT 0 -- TRUE if pmid is the primary
266 @ );
267 @ CREATE INDEX mlink_i1 ON mlink(mid);
268 @ CREATE INDEX mlink_i2 ON mlink(fnid);
269 @ CREATE INDEX mlink_i3 ON mlink(fid);
270 @ CREATE INDEX mlink_i4 ON mlink(pid);
@@ -274,11 +251,11 @@
274 @ CREATE TABLE plink(
275 @ pid INTEGER REFERENCES blob, -- Parent manifest
276 @ cid INTEGER REFERENCES blob, -- Child manifest
277 @ isprim BOOLEAN, -- pid is the primary parent of cid
278 @ mtime DATETIME, -- the date/time stamp on cid. Julian day.
279 @ baseid INTEGER REFERENCES blob, -- Baseline if cid is a delta manifest.
280 @ UNIQUE(pid, cid)
281 @ );
282 @ CREATE INDEX plink_i2 ON plink(cid,pid);
283 @
284 @ -- A "leaf" checkin is a checkin that has no children in the same
@@ -511,11 +488,11 @@
511 @ -- current version of the file is already in the repository.
512 @ --
513 @ CREATE TABLE vfile(
514 @ id INTEGER PRIMARY KEY, -- ID of the checked out file
515 @ vid INTEGER REFERENCES blob, -- The baseline this file is part of.
516 @ chnged INT DEFAULT 0, -- 0:unchng 1:edit 2:m-chng 3:m-add 4:i-chng 5:i-add
517 @ deleted BOOLEAN DEFAULT 0, -- True if deleted
518 @ isexe BOOLEAN, -- True if file should be executable
519 @ islink BOOLEAN, -- True if file should be symlink
520 @ rid INTEGER, -- Originally from this repository record
521 @ mrid INTEGER, -- Based on this record due to a merge
522
--- src/schema.c
+++ src/schema.c
@@ -45,14 +45,11 @@
45 ** we have to execute special procedures to update the schema. When
46 ** the aux schema changes, all we need to do is rebuild the database.
47 */
48 #define CONTENT_SCHEMA "2"
49 #define AUX_SCHEMA_MIN "2011-04-25 19:50"
50 #define AUX_SCHEMA_MAX "2014-11-24 20:35"
 
 
 
51
52 #endif /* INTERFACE */
53
54
55 /*
@@ -230,41 +227,21 @@
227 @ name TEXT UNIQUE -- Name of file page
228 @ );
229 @
230 @ -- Linkages between checkins, files created by each checkin, and
231 @ -- the names of those files.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
232 @ --
233 @ -- pid==0 if the file is added by checkin mid.
234 @ -- fid==0 if the file is removed by checkin mid.
235 @ --
236 @ CREATE TABLE mlink(
237 @ mid INTEGER REFERENCES blob, -- Manifest ID where change occurs
238 @ pid INTEGER REFERENCES blob, -- File ID in parent manifest
239 @ fid INTEGER REFERENCES blob, -- Changed file ID in this manifest
 
240 @ fnid INTEGER REFERENCES filename, -- Name of the file
241 @ pfnid INTEGER REFERENCES filename, -- Previous name. 0 if unchanged
242 @ mperm INTEGER -- File permissions. 1==exec
 
243 @ );
244 @ CREATE INDEX mlink_i1 ON mlink(mid);
245 @ CREATE INDEX mlink_i2 ON mlink(fnid);
246 @ CREATE INDEX mlink_i3 ON mlink(fid);
247 @ CREATE INDEX mlink_i4 ON mlink(pid);
@@ -274,11 +251,11 @@
251 @ CREATE TABLE plink(
252 @ pid INTEGER REFERENCES blob, -- Parent manifest
253 @ cid INTEGER REFERENCES blob, -- Child manifest
254 @ isprim BOOLEAN, -- pid is the primary parent of cid
255 @ mtime DATETIME, -- the date/time stamp on cid. Julian day.
256 @ baseid INTEGER REFERENCES blob, -- Baseline if child is a delta manifest
257 @ UNIQUE(pid, cid)
258 @ );
259 @ CREATE INDEX plink_i2 ON plink(cid,pid);
260 @
261 @ -- A "leaf" checkin is a checkin that has no children in the same
@@ -511,11 +488,11 @@
488 @ -- current version of the file is already in the repository.
489 @ --
490 @ CREATE TABLE vfile(
491 @ id INTEGER PRIMARY KEY, -- ID of the checked out file
492 @ vid INTEGER REFERENCES blob, -- The baseline this file is part of.
493 @ chnged INT DEFAULT 0, -- 0:unchnged 1:edited 2:m-chng 3:m-add 4:i-chng 5:i-add
494 @ deleted BOOLEAN DEFAULT 0, -- True if deleted
495 @ isexe BOOLEAN, -- True if file should be executable
496 @ islink BOOLEAN, -- True if file should be symlink
497 @ rid INTEGER, -- Originally from this repository record
498 @ mrid INTEGER, -- Based on this record due to a merge
499

Keyboard Shortcuts

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