1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
|
for(i=1; i<pChild->nParent; i++){
pmid = uuid_to_rid(pChild->azParent[i], 0);
if( pmid<=0 ) continue;
add_mlink(pmid, 0, mid, pChild, 0);
}
}
}
/*
** Setup to do multiple manifest_crosslink() calls.
** This is only required if processing ticket changes.
*/
void manifest_crosslink_begin(void){
assert( manifest_crosslink_busy==0 );
manifest_crosslink_busy = 1;
db_begin_transaction();
db_multi_exec(
"CREATE TEMP TABLE pending_tkt(uuid TEXT UNIQUE);"
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
|
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
|
for(i=1; i<pChild->nParent; i++){
pmid = uuid_to_rid(pChild->azParent[i], 0);
if( pmid<=0 ) continue;
add_mlink(pmid, 0, mid, pChild, 0);
}
}
}
/*
** For a check-in with RID "rid" that has nParent parent check-ins given
** by the UUIDs in azParent[], create all appropriate plink and mlink table
** entries.
**
** The primary parent is the first UUID on the azParent[] list.
**
** Return the RID of the primary parent.
*/
static int manifest_add_checkin_linkages(
int rid, /* The RID of the check-in */
Manifest *p, /* Manifest for this check-in */
int nParent, /* Number of parents for this check-in */
char **azParent /* UUIDs for each parent */
){
int i;
int parentid = 0;
char zBaseId[30]; /* Baseline manifest RID for deltas. "NULL" otherwise */
Stmt q;
if( p->zBaseline ){
sqlite3_snprintf(sizeof(zBaseId), zBaseId, "%d",
uuid_to_rid(p->zBaseline,1));
}else{
sqlite3_snprintf(sizeof(zBaseId), zBaseId, "NULL");
}
for(i=0; i<nParent; i++){
int pid = uuid_to_rid(azParent[i], 1);
db_multi_exec(
"INSERT OR IGNORE INTO plink(pid, cid, isprim, mtime, baseid)"
"VALUES(%d, %d, %d, %.17g, %s)",
pid, rid, i==0, p->rDate, zBaseId/*safe-for-%s*/);
if( i==0 ) parentid = pid;
}
add_mlink(parentid, 0, rid, p, 1);
if( nParent>1 ){
/* Change MLINK.PID from 0 to -1 for files that are added by merge. */
db_multi_exec(
"UPDATE mlink SET pid=-1"
" WHERE mid=%d"
" AND pid=0"
" AND fnid IN "
" (SELECT fnid FROM mlink WHERE mid=%d GROUP BY fnid"
" HAVING count(*)<%d)",
rid, rid, nParent
);
}
db_prepare(&q, "SELECT cid, isprim FROM plink WHERE pid=%d", rid);
while( db_step(&q)==SQLITE_ROW ){
int cid = db_column_int(&q, 0);
int isprim = db_column_int(&q, 1);
add_mlink(rid, p, cid, 0, isprim);
}
db_finalize(&q);
if( nParent==0 ){
/* For root files (files without parents) add mlink entries
** showing all content as new. */
int isPublic = !content_is_private(rid);
for(i=0; i<p->nFile; i++){
add_one_mlink(0, 0, rid, p->aFile[i].zUuid, p->aFile[i].zName, 0,
isPublic, 1, manifest_file_mperm(&p->aFile[i]));
}
}
return parentid;
}
/*
** There exists a "parent" tag against checkin rid that has value zValue.
** If value is well-formed (meaning that is is a list of UUIDs), then use
** zValue to reparent check-in rid.
*/
void manifest_reparent_checkin(int rid, const char *zValue){
int nParent;
char *zCopy = 0;
char **azParent = 0;
Manifest *p = 0;
int i;
int n = (int)strlen(zValue);
nParent = (n+1)/(UUID_SIZE+1);
if( nParent*(UUID_SIZE+1) - 1 !=n ) return;
if( nParent<1 ) return;
zCopy = fossil_strdup(zValue);
azParent = fossil_malloc( sizeof(azParent[0])*nParent );
for(i=0; i<nParent; i++){
azParent[i] = &zCopy[i*(UUID_SIZE+1)];
if( i<nParent-1 && azParent[i][UUID_SIZE]!=' ' ) break;
azParent[i][UUID_SIZE] = 0;
if( !validate16(azParent[i],UUID_SIZE) ) break;
}
if( i==nParent
&& !db_exists("SELECT 1 FROM plink WHERE cid=%d AND pid=%d",
rid, uuid_to_rid(azParent[0],0))
){
p = manifest_get(rid, CFTYPE_MANIFEST, 0);
}
if( p!=0 ){
db_multi_exec(
"DELETE FROM plink WHERE cid=%d;"
"DELETE FROM mlink WHERE mid=%d;",
rid, rid
);
manifest_add_checkin_linkages(rid,p,nParent,azParent);
}
manifest_destroy(p);
fossil_free(azParent);
fossil_free(zCopy);
}
/*
** Setup to do multiple manifest_crosslink() calls.
**
** This routine creates TEMP tables for holding information for
** processing that must be deferred until all artifacts have been
** seen at least once. The deferred processing is accomplished
** by the call to manifest_crosslink_end().
*/
void manifest_crosslink_begin(void){
assert( manifest_crosslink_busy==0 );
manifest_crosslink_busy = 1;
db_begin_transaction();
db_multi_exec(
"CREATE TEMP TABLE pending_tkt(uuid TEXT UNIQUE);"
|
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
|
assert( manifest_crosslink_busy==1 );
if( permitHooks ){
rc = xfer_run_common_script();
if( rc==TH_OK ){
zScript = xfer_ticket_code();
}
}
db_prepare(&q, "SELECT uuid FROM pending_tkt");
while( db_step(&q)==SQLITE_ROW ){
const char *zUuid = db_column_text(&q, 0);
ticket_rebuild_entry(zUuid);
if( permitHooks && rc==TH_OK ){
rc = xfer_run_script(zScript, zUuid, 0);
}
|
>
>
>
>
>
>
>
>
>
>
>
|
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
|
assert( manifest_crosslink_busy==1 );
if( permitHooks ){
rc = xfer_run_common_script();
if( rc==TH_OK ){
zScript = xfer_ticket_code();
}
}
db_prepare(&q,
"SELECT rid, value FROM tagxref"
" WHERE tagid=%d AND tagtype=1",
TAG_PARENT
);
while( db_step(&q)==SQLITE_ROW ){
int rid = db_column_int(&q,0);
const char *zValue = db_column_text(&q,1);
manifest_reparent_checkin(rid, zValue);
}
db_finalize(&q);
db_prepare(&q, "SELECT uuid FROM pending_tkt");
while( db_step(&q)==SQLITE_ROW ){
const char *zUuid = db_column_text(&q, 0);
ticket_rebuild_entry(zUuid);
if( permitHooks && rc==TH_OK ){
rc = xfer_run_script(zScript, zUuid, 0);
}
|
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
|
if( p->type==CFTYPE_MANIFEST ){
if( permitHooks ){
zScript = xfer_commit_code();
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
}
if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d", rid) ){
char *zCom;
char zBaseId[30];
if( p->zBaseline ){
sqlite3_snprintf(sizeof(zBaseId), zBaseId, "%d",
uuid_to_rid(p->zBaseline,1));
}else{
sqlite3_snprintf(sizeof(zBaseId), zBaseId, "NULL");
}
for(i=0; i<p->nParent; i++){
int pid = uuid_to_rid(p->azParent[i], 1);
db_multi_exec(
"INSERT OR IGNORE INTO plink(pid, cid, isprim, mtime, baseid)"
"VALUES(%d, %d, %d, %.17g, %s)",
pid, rid, i==0, p->rDate, zBaseId/*safe-for-%s*/);
if( i==0 ) parentid = pid;
}
add_mlink(parentid, 0, rid, p, 1);
if( p->nParent>1 ){
/* Change MLINK.PID from 0 to -1 for files that are added by merge. */
db_multi_exec(
"UPDATE mlink SET pid=-1"
" WHERE mid=%d"
" AND pid=0"
" AND fnid IN "
" (SELECT fnid FROM mlink WHERE mid=%d GROUP BY fnid"
" HAVING count(*)<%d)",
rid, rid, p->nParent
);
}
db_prepare(&q, "SELECT cid, isprim FROM plink WHERE pid=%d", rid);
while( db_step(&q)==SQLITE_ROW ){
int cid = db_column_int(&q, 0);
int isprim = db_column_int(&q, 1);
add_mlink(rid, p, cid, 0, isprim);
}
db_finalize(&q);
if( p->nParent==0 ){
/* For root files (files without parents) add mlink entries
** showing all content as new. */
int isPublic = !content_is_private(rid);
for(i=0; i<p->nFile; i++){
add_one_mlink(0, 0, rid, p->aFile[i].zUuid, p->aFile[i].zName, 0,
isPublic, 1, manifest_file_mperm(&p->aFile[i]));
}
}
search_doc_touch('c', rid, 0);
db_multi_exec(
"REPLACE INTO event(type,mtime,objid,user,comment,"
"bgcolor,euser,ecomment,omtime)"
"VALUES('ci',"
" coalesce("
" (SELECT julianday(value) FROM tagxref WHERE tagid=%d AND rid=%d),"
|
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
|
if( p->type==CFTYPE_MANIFEST ){
if( permitHooks ){
zScript = xfer_commit_code();
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
}
if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d", rid) ){
char *zCom;
parentid = manifest_add_checkin_linkages(rid,p,p->nParent,p->azParent);
search_doc_touch('c', rid, 0);
db_multi_exec(
"REPLACE INTO event(type,mtime,objid,user,comment,"
"bgcolor,euser,ecomment,omtime)"
"VALUES('ci',"
" coalesce("
" (SELECT julianday(value) FROM tagxref WHERE tagid=%d AND rid=%d),"
|