| | @@ -1187,18 +1187,16 @@ |
| 1187 | 1187 | /* |
| 1188 | 1188 | ** Add a single entry to the mlink table. Also add the filename to |
| 1189 | 1189 | ** the filename table if it is not there already. |
| 1190 | 1190 | */ |
| 1191 | 1191 | static void add_one_mlink( |
| 1192 | | - int pmid, /* The parent manifest */ |
| 1193 | | - const char *zFromUuid, /* UUID for content in parent */ |
| 1194 | 1192 | 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 */ |
| 1196 | 1195 | const char *zFilename, /* Filename */ |
| 1197 | 1196 | const char *zPrior, /* Previous filename. NULL if unchanged */ |
| 1198 | 1197 | int isPublic, /* True if mid is not a private manifest */ |
| 1199 | | - int isPrimary, /* pmid is the primary parent of mid */ |
| 1200 | 1198 | int mperm /* 1: exec, 2: symlink */ |
| 1201 | 1199 | ){ |
| 1202 | 1200 | int fnid, pfnid, pid, fid; |
| 1203 | 1201 | static Stmt s1; |
| 1204 | 1202 | |
| | @@ -1218,21 +1216,19 @@ |
| 1218 | 1216 | }else{ |
| 1219 | 1217 | fid = uuid_to_rid(zToUuid, 1); |
| 1220 | 1218 | if( isPublic ) content_make_public(fid); |
| 1221 | 1219 | } |
| 1222 | 1220 | 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)" |
| 1225 | 1223 | ); |
| 1226 | 1224 | db_bind_int(&s1, ":m", mid); |
| 1227 | | - db_bind_int(&s1, ":f", fid); |
| 1228 | | - db_bind_int(&s1, ":pm", pmid); |
| 1229 | 1225 | db_bind_int(&s1, ":p", pid); |
| 1226 | + db_bind_int(&s1, ":f", fid); |
| 1230 | 1227 | db_bind_int(&s1, ":n", fnid); |
| 1231 | 1228 | db_bind_int(&s1, ":pfn", pfnid); |
| 1232 | 1229 | db_bind_int(&s1, ":mp", mperm); |
| 1233 | | - db_bind_int(&s1, ":isaux", isPrimary==0); |
| 1234 | 1230 | db_exec(&s1); |
| 1235 | 1231 | if( pid && fid ){ |
| 1236 | 1232 | content_deltify(pid, fid, 0); |
| 1237 | 1233 | } |
| 1238 | 1234 | } |
| | @@ -1346,29 +1342,24 @@ |
| 1346 | 1342 | ** |
| 1347 | 1343 | ** Deleted files have mlink.fid=0. |
| 1348 | 1344 | ** Added files have mlink.pid=0. |
| 1349 | 1345 | ** Edited files have both mlink.pid!=0 and mlink.fid!=0 |
| 1350 | 1346 | */ |
| 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){ |
| 1356 | 1348 | Blob otherContent; |
| 1357 | 1349 | int otherRid; |
| 1358 | 1350 | int i, rc; |
| 1359 | 1351 | ManifestFile *pChildFile, *pParentFile; |
| 1360 | 1352 | Manifest **ppOther; |
| 1361 | 1353 | static Stmt eq; |
| 1362 | 1354 | int isPublic; /* True if pChild is non-private */ |
| 1363 | 1355 | |
| 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. |
| 1366 | 1358 | */ |
| 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); |
| 1370 | 1361 | rc = db_step(&eq); |
| 1371 | 1362 | db_reset(&eq); |
| 1372 | 1363 | if( rc==SQLITE_ROW ) return; |
| 1373 | 1364 | |
| 1374 | 1365 | /* Compute the value of the missing pParent or pChild parameter. |
| | @@ -1375,14 +1366,14 @@ |
| 1375 | 1366 | ** Fetch the baseline checkins for both. |
| 1376 | 1367 | */ |
| 1377 | 1368 | assert( pParent==0 || pChild==0 ); |
| 1378 | 1369 | if( pParent==0 ){ |
| 1379 | 1370 | ppOther = &pParent; |
| 1380 | | - otherRid = pmid; |
| 1371 | + otherRid = pid; |
| 1381 | 1372 | }else{ |
| 1382 | 1373 | ppOther = &pChild; |
| 1383 | | - otherRid = mid; |
| 1374 | + otherRid = cid; |
| 1384 | 1375 | } |
| 1385 | 1376 | if( (*ppOther = manifest_cache_find(otherRid))==0 ){ |
| 1386 | 1377 | content_get(otherRid, &otherContent); |
| 1387 | 1378 | if( blob_size(&otherContent)==0 ) return; |
| 1388 | 1379 | *ppOther = manifest_parse(&otherContent, otherRid, 0); |
| | @@ -1390,20 +1381,20 @@ |
| 1390 | 1381 | } |
| 1391 | 1382 | if( fetch_baseline(pParent, 0) || fetch_baseline(pChild, 0) ){ |
| 1392 | 1383 | manifest_destroy(*ppOther); |
| 1393 | 1384 | return; |
| 1394 | 1385 | } |
| 1395 | | - isPublic = !content_is_private(mid); |
| 1386 | + isPublic = !content_is_private(cid); |
| 1396 | 1387 | |
| 1397 | 1388 | /* Try to make the parent manifest a delta from the child, if that |
| 1398 | 1389 | ** is an appropriate thing to do. For a new baseline, make the |
| 1399 | 1390 | ** previous baseline a delta from the current baseline. |
| 1400 | 1391 | */ |
| 1401 | 1392 | if( (pParent->zBaseline==0)==(pChild->zBaseline==0) ){ |
| 1402 | | - content_deltify(pmid, mid, 0); |
| 1393 | + content_deltify(pid, cid, 0); |
| 1403 | 1394 | }else if( pChild->zBaseline==0 && pParent->zBaseline!=0 ){ |
| 1404 | | - content_deltify(pParent->pBaseline->rid, mid, 0); |
| 1395 | + content_deltify(pParent->pBaseline->rid, cid, 0); |
| 1405 | 1396 | } |
| 1406 | 1397 | |
| 1407 | 1398 | /* Remember all children less than a few seconds younger than their parent, |
| 1408 | 1399 | ** as we might want to fudge the times for those children. |
| 1409 | 1400 | */ |
| | @@ -1423,32 +1414,31 @@ |
| 1423 | 1414 | int mperm = manifest_file_mperm(pChildFile); |
| 1424 | 1415 | if( pChildFile->zPrior ){ |
| 1425 | 1416 | pParentFile = manifest_file_seek(pParent, pChildFile->zPrior, 0); |
| 1426 | 1417 | if( pParentFile ){ |
| 1427 | 1418 | /* 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); |
| 1431 | 1421 | }else{ |
| 1432 | 1422 | /* File name changed, but the old name is not found in the parent! |
| 1433 | 1423 | ** 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); |
| 1436 | 1426 | } |
| 1437 | 1427 | }else{ |
| 1438 | 1428 | pParentFile = manifest_file_seek(pParent, pChildFile->zName, 0); |
| 1439 | 1429 | if( pParentFile==0 ){ |
| 1440 | 1430 | if( pChildFile->zUuid ){ |
| 1441 | 1431 | /* 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); |
| 1444 | 1434 | } |
| 1445 | 1435 | }else if( fossil_strcmp(pChildFile->zUuid, pParentFile->zUuid)!=0 |
| 1446 | 1436 | || manifest_file_mperm(pParentFile)!=mperm ){ |
| 1447 | 1437 | /* 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); |
| 1450 | 1440 | } |
| 1451 | 1441 | } |
| 1452 | 1442 | } |
| 1453 | 1443 | if( pParent->zBaseline && pChild->zBaseline ){ |
| 1454 | 1444 | /* Both parent and child are delta manifests. Look for files that |
| | @@ -1460,22 +1450,22 @@ |
| 1460 | 1450 | pChildFile = manifest_file_seek_base(pChild, pParentFile->zName, 0); |
| 1461 | 1451 | if( pChildFile==0 ){ |
| 1462 | 1452 | /* The child file reverts to baseline. Show this as a change */ |
| 1463 | 1453 | pChildFile = manifest_file_seek(pChild, pParentFile->zName, 0); |
| 1464 | 1454 | 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, |
| 1467 | 1457 | manifest_file_mperm(pChildFile)); |
| 1468 | 1458 | } |
| 1469 | 1459 | } |
| 1470 | 1460 | }else{ |
| 1471 | 1461 | pChildFile = manifest_file_seek(pChild, pParentFile->zName, 0); |
| 1472 | 1462 | if( pChildFile ){ |
| 1473 | 1463 | /* File resurrected in the child after having been deleted in |
| 1474 | 1464 | ** 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)); |
| 1477 | 1467 | } |
| 1478 | 1468 | } |
| 1479 | 1469 | } |
| 1480 | 1470 | }else if( pChild->zBaseline==0 ){ |
| 1481 | 1471 | /* pChild is a baseline. Look for files that are present in pParent |
| | @@ -1482,12 +1472,12 @@ |
| 1482 | 1472 | ** but are missing from pChild and mark them as having been deleted. */ |
| 1483 | 1473 | manifest_file_rewind(pParent); |
| 1484 | 1474 | while( (pParentFile = manifest_file_next(pParent,0))!=0 ){ |
| 1485 | 1475 | pChildFile = manifest_file_seek(pChild, pParentFile->zName, 0); |
| 1486 | 1476 | 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); |
| 1489 | 1479 | } |
| 1490 | 1480 | } |
| 1491 | 1481 | } |
| 1492 | 1482 | manifest_cache_insert(*ppOther); |
| 1493 | 1483 | } |
| | @@ -1791,46 +1781,45 @@ |
| 1791 | 1781 | sqlite3_snprintf(sizeof(zBaseId), zBaseId, "%d", |
| 1792 | 1782 | uuid_to_rid(p->zBaseline,1)); |
| 1793 | 1783 | }else{ |
| 1794 | 1784 | sqlite3_snprintf(sizeof(zBaseId), zBaseId, "NULL"); |
| 1795 | 1785 | } |
| 1786 | + (void)db_schema_is_outofdate(); /* Make sure g.zAuxSchema is initialized */ |
| 1796 | 1787 | for(i=0; i<p->nParent; i++){ |
| 1797 | 1788 | 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); |
| 1819 | 1809 | while( db_step(&q)==SQLITE_ROW ){ |
| 1820 | 1810 | 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); |
| 1823 | 1812 | } |
| 1824 | 1813 | db_finalize(&q); |
| 1825 | 1814 | if( p->nParent==0 ){ |
| 1826 | 1815 | /* For root files (files without parents) add mlink entries |
| 1827 | 1816 | ** showing all content as new. */ |
| 1828 | 1817 | int isPublic = !content_is_private(rid); |
| 1829 | 1818 | 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])); |
| 1832 | 1821 | } |
| 1833 | 1822 | } |
| 1834 | 1823 | db_multi_exec( |
| 1835 | 1824 | "REPLACE INTO event(type,mtime,objid,user,comment," |
| 1836 | 1825 | "bgcolor,euser,ecomment,omtime)" |
| 1837 | 1826 | |