Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Automatically update the VFILE and VMERGE tables when the fingerprinting detects that a repository has been replaced by clone. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | rid-renumbering |
Files: | files | file ages | folders |
SHA3-256: |
b03652382a3277406e94d412e61e7468 |
User & Date: | drh 2019-01-20 21:29:22 |
Context
2019-01-20
| ||
23:42 | Minor comment changes. ... (check-in: e2a73756 user: drh tags: rid-renumbering) | |
21:29 | Automatically update the VFILE and VMERGE tables when the fingerprinting detects that a repository has been replaced by clone. ... (check-in: b0365238 user: drh tags: rid-renumbering) | |
16:51 | Merge fixes and enhancements from trunk. ... (check-in: 1a7cc263 user: drh tags: rid-renumbering) | |
Changes
Changes to src/add.c.
︙ | ︙ | |||
185 186 187 188 189 190 191 | db_multi_exec("UPDATE vfile SET deleted=0" " WHERE pathname=%Q %s AND deleted", zPath, filename_collation()); }else{ char *zFullname = mprintf("%s%s", g.zLocalRoot, zPath); int isExe = file_isexe(zFullname, RepoFILE); db_multi_exec( | | | | 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | db_multi_exec("UPDATE vfile SET deleted=0" " WHERE pathname=%Q %s AND deleted", zPath, filename_collation()); }else{ char *zFullname = mprintf("%s%s", g.zLocalRoot, zPath); int isExe = file_isexe(zFullname, RepoFILE); db_multi_exec( "INSERT INTO vfile(vid,deleted,rid,mrid,pathname,isexe,islink,mhash)" "VALUES(%d,0,0,0,%Q,%d,%d,NULL)", vid, zPath, isExe, file_islink(0)); fossil_free(zFullname); } if( db_changes() ){ fossil_print("ADDED %s\n", zPath); return 1; }else{ |
︙ | ︙ |
Changes to src/bisect.c.
︙ | ︙ | |||
284 285 286 287 288 289 290 291 292 293 294 295 296 297 | db_column_text(&q, 3), db_column_text(&q, 2), (db_column_int(&q, 4) && zGoodBad[0]!='C') ? " CURRENT" : ""); } db_finalize(&q); } /* ** COMMAND: bisect ** ** Usage: %fossil bisect SUBCOMMAND ... ** ** Run various subcommands useful for searching for bugs. ** | > > > > > > > > > > > | 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | db_column_text(&q, 3), db_column_text(&q, 2), (db_column_int(&q, 4) && zGoodBad[0]!='C') ? " CURRENT" : ""); } db_finalize(&q); } /* ** Reset the bisect subsystem. */ void bisect_reset(void){ db_multi_exec( "DELETE FROM vvar WHERE name IN " " ('bisect-good', 'bisect-bad', 'bisect-log')" ); } /* ** COMMAND: bisect ** ** Usage: %fossil bisect SUBCOMMAND ... ** ** Run various subcommands useful for searching for bugs. ** |
︙ | ︙ | |||
487 488 489 490 491 492 493 | if( i>=count(aBisectOption) ){ fossil_fatal("no such bisect option: %s", g.argv[3]); } }else{ usage("options ?NAME? ?VALUE?"); } }else if( strncmp(zCmd, "reset", n)==0 ){ | < < < | | 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 | if( i>=count(aBisectOption) ){ fossil_fatal("no such bisect option: %s", g.argv[3]); } }else{ usage("options ?NAME? ?VALUE?"); } }else if( strncmp(zCmd, "reset", n)==0 ){ bisect_reset(); }else if( strcmp(zCmd, "ui")==0 ){ char *newArgv[8]; newArgv[0] = g.argv[0]; newArgv[1] = "ui"; newArgv[2] = "--page"; newArgv[3] = "timeline?bisect"; newArgv[4] = 0; |
︙ | ︙ |
Changes to src/checkin.c.
︙ | ︙ | |||
2396 2397 2398 2399 2400 2401 2402 | blob_reset(&fname); } nrid = content_put(&content); blob_reset(&content); if( rid>0 ){ content_deltify(rid, &nrid, 1, 0); } | | > | 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 | blob_reset(&fname); } nrid = content_put(&content); blob_reset(&content); if( rid>0 ){ content_deltify(rid, &nrid, 1, 0); } db_multi_exec("UPDATE vfile SET mrid=%d, rid=%d, mhash=NULL WHERE id=%d", nrid,nrid,id); db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nrid); } db_finalize(&q); if( nConflict && !allowConflict ){ fossil_fatal("abort due to unresolved merge conflicts; " "use --allow-conflict to override"); }else if( abortCommit ){ |
︙ | ︙ | |||
2530 2531 2532 2533 2534 2535 2536 | } /* Update the vfile and vmerge tables */ db_multi_exec( "DELETE FROM vfile WHERE (vid!=%d OR deleted) AND is_selected(id);" "DELETE FROM vmerge;" "UPDATE vfile SET vid=%d;" | | | 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 | } /* Update the vfile and vmerge tables */ db_multi_exec( "DELETE FROM vfile WHERE (vid!=%d OR deleted) AND is_selected(id);" "DELETE FROM vmerge;" "UPDATE vfile SET vid=%d;" "UPDATE vfile SET rid=mrid, mhash=NULL, chnged=0, deleted=0, origname=NULL" " WHERE is_selected(id);" , vid, nvid ); db_set_checkout(nvid); /* Update the isexe and islink columns of the vfile table */ db_prepare(&q, |
︙ | ︙ |
Changes to src/db.c.
︙ | ︙ | |||
1672 1673 1674 1675 1676 1677 1678 | ** version 2.0 and later. */ rebuild_schema_update_2_0(); /* Do the Fossil-2.0 schema updates */ /* Additional checks that occur when opening the checkout database */ if( g.localOpen ){ | | | | > > | | | | | | < | > > > > > > > > > > > > > > | < < < < < | < < < < < < < > > | < < < | > > | > > | > | > > > > > > > | | | | | | | | | > | 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 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 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 | ** version 2.0 and later. */ rebuild_schema_update_2_0(); /* Do the Fossil-2.0 schema updates */ /* Additional checks that occur when opening the checkout database */ if( g.localOpen ){ /* If the repository database that was just opened has been ** eplaced by a clone of the same project, with different RID ** values, then renumber the RID values stored in various tables ** of the checkout database, so that the repository and checkout ** databases align. */ if( !db_fingerprint_ok() ){ if( find_option("no-rid-adjust",0,0)!=0 ){ /* The --no-rid-adjust command-line option bypasses the RID value ** updates. Intended for use during debugging, especially to be ** able to run "fossil sql" after a database swap. */ fossil_print( "WARNING: repository change detected, but no adjust made.\n" ); }else if( find_option("rid-renumber-dryrun",0,0)!=0 ){ /* the --rid-renumber-dryrun option shows how RID values would be ** renumbered, but does not actually perform the renumbering. ** This is a debugging-only option. */ vfile_rid_renumbering_event(1); exit(0); }else{ char *z; stash_rid_renumbering_event(); vfile_rid_renumbering_event(0); undo_reset(); bisect_reset(); z = db_fingerprint(0); db_lset("fingerprint", z); fossil_free(z); fossil_print( "WARNING: The repository database has been replaced by a clone.\n" "Bisect history and undo have been lost.\n" ); } } /* Make sure the checkout database schema migration of 2019-01-20 ** has occurred. ** ** The 2019-01-19 migration is the addition of the vmerge.mhash and ** vfile.mhash columns and making the vmerge.mhash column part of the ** PRIMARY KEY for vmerge. */ if( !db_table_has_column("localdb", "vfile", "mhash") ){ db_multi_exec("ALTER TABLE vfile ADD COLUMN mhash;"); db_multi_exec( "UPDATE vfile" " SET mhash=(SELECT uuid FROM blob WHERE blob.rid=vfile.mrid)" " WHERE mrid!=rid;" ); if( !db_table_has_column("localdb", "vmerge", "mhash") ){ db_multi_exec("ALTER TABLE vmerge RENAME TO old_vmerge;"); db_multi_exec(zLocalSchemaVmerge /*works-like:""*/); db_multi_exec( "INSERT OR IGNORE INTO vmerge(id,merge,mhash)" " SELECT id, merge, blob.uuid FROM old_vmerge, blob" " WHERE old_vmerge.merge=blob.rid;" "DROP TABLE old_vmerge;" ); } } } } /* ** Return true if there have been any changes to the repository ** database since it was opened. |
︙ | ︙ |
Changes to src/foci.c.
︙ | ︙ | |||
119 120 121 122 123 124 125 | ** ** (0) A full scan. Visit every manifest in the repo. (Slow) ** (1) checkinID=?. visit only the single manifest specified. ** (2) symName=? visit only the single manifest specified. */ static int fociBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ int i; | | > | 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | ** ** (0) A full scan. Visit every manifest in the repo. (Slow) ** (1) checkinID=?. visit only the single manifest specified. ** (2) symName=? visit only the single manifest specified. */ static int fociBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ int i; pIdxInfo->estimatedCost = 1000000000.0; for(i=0; i<pIdxInfo->nConstraint; i++){ if( !pIdxInfo->aConstraint[i].usable ) continue; if( pIdxInfo->aConstraint[i].op==SQLITE_INDEX_CONSTRAINT_EQ && (pIdxInfo->aConstraint[i].iColumn==FOCI_CHECKINID || pIdxInfo->aConstraint[i].iColumn==FOCI_SYMNAME) ){ if( pIdxInfo->aConstraint[i].iColumn==FOCI_CHECKINID ){ pIdxInfo->idxNum = 1; }else{ |
︙ | ︙ |
Changes to src/merge.c.
︙ | ︙ | |||
602 603 604 605 606 607 608 | const char *zName = db_column_text(&q, 2); int islinkm = db_column_int(&q, 3); /* Copy content from idm over into idv. Overwrite idv. */ fossil_print("UPDATE %s\n", zName); if( !dryRunFlag ){ undo_save(zName); db_multi_exec( | | > > | | 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | const char *zName = db_column_text(&q, 2); int islinkm = db_column_int(&q, 3); /* Copy content from idm over into idv. Overwrite idv. */ fossil_print("UPDATE %s\n", zName); if( !dryRunFlag ){ undo_save(zName); db_multi_exec( "UPDATE vfile SET mtime=0, mrid=%d, chnged=%d, islink=%d," " mhash=CASE WHEN rid<>%d" " THEN (SELECT uuid FROM blob WHERE blob.rid=%d) END" " WHERE id=%d", ridm, integrateFlag?4:2, islinkm, ridm, ridm, idv ); vfile_to_disk(0, idv, 0, 0); } } db_finalize(&q); /* |
︙ | ︙ | |||
793 794 795 796 797 798 799 | " WHERE idp=0 AND idv=0 AND idm>0" ); while( db_step(&q)==SQLITE_ROW ){ int idm = db_column_int(&q, 0); const char *zName; char *zFullName; db_multi_exec( | | > | > > > | 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 | " WHERE idp=0 AND idv=0 AND idm>0" ); while( db_step(&q)==SQLITE_ROW ){ int idm = db_column_int(&q, 0); const char *zName; char *zFullName; db_multi_exec( "REPLACE INTO vfile(vid,chnged,deleted,rid,mrid," "isexe,islink,pathname,mhash)" " SELECT %d,%d,0,rid,mrid,isexe,islink,pathname," "CASE WHEN rid<>mrid" " THEN (SELECT uuid FROM blob WHERE blob.rid=vfile.mrid) END " "FROM vfile WHERE id=%d", vid, integrateFlag?5:3, idm ); zName = db_column_text(&q, 1); zFullName = mprintf("%s%s", g.zLocalRoot, zName); if( file_isfile_or_link(zFullName) && !db_exists("SELECT 1 FROM fv WHERE fn=%Q", zName) ){ fossil_print("ADDED %s (overwrites an unmanaged file)\n", zName); |
︙ | ︙ |
Changes to src/schema.c.
︙ | ︙ | |||
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 | @ isexe BOOLEAN, -- True if file should be executable @ islink BOOLEAN, -- True if file should be symlink @ rid INTEGER, -- Originally from this repository record @ mrid INTEGER, -- Based on this record due to a merge @ mtime INTEGER, -- Mtime of file on disk. sec since 1970 @ pathname TEXT, -- Full pathname relative to root @ origname TEXT, -- Original pathname. NULL if unchanged @ UNIQUE(pathname,vid) @ ); @ @ -- Identifier for this file type. @ -- The integer is the same as 'FSLC'. @ PRAGMA application_id=252006674; ; /* Additional local database initialization following the schema ** enhancement of 2019-01-19, in which the mhash column was added | > | | 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | @ isexe BOOLEAN, -- True if file should be executable @ islink BOOLEAN, -- True if file should be symlink @ rid INTEGER, -- Originally from this repository record @ mrid INTEGER, -- Based on this record due to a merge @ mtime INTEGER, -- Mtime of file on disk. sec since 1970 @ pathname TEXT, -- Full pathname relative to root @ origname TEXT, -- Original pathname. NULL if unchanged @ mhash TEXT, -- Hash of mrid iff mrid!=rid @ UNIQUE(pathname,vid) @ ); @ @ -- Identifier for this file type. @ -- The integer is the same as 'FSLC'. @ PRAGMA application_id=252006674; ; /* Additional local database initialization following the schema ** enhancement of 2019-01-19, in which the mhash column was added ** to vmerge and vfile. */ const char zLocalSchemaVmerge[] = @ -- This table holds a record of uncommitted merges in the local @ -- file tree. If a VFILE entry with id has merged with another @ -- record, there is an entry in this table with (id,merge) where @ -- merge is the RECORD table entry that the file merged against. @ -- An id of 0 or <-3 here means the version record itself. When |
︙ | ︙ |
Changes to src/update.c.
︙ | ︙ | |||
862 863 864 865 866 867 868 | blob_write_to_file(&record, zFull); } file_setexe(zFull, rvPerm==PERM_EXE); fossil_print("REVERT %s\n", zFile); mtime = file_mtime(zFull, RepoFILE); db_multi_exec( "UPDATE vfile" | | > | 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 | blob_write_to_file(&record, zFull); } file_setexe(zFull, rvPerm==PERM_EXE); fossil_print("REVERT %s\n", zFile); mtime = file_mtime(zFull, RepoFILE); db_multi_exec( "UPDATE vfile" " SET mtime=%lld, chnged=%d, deleted=0, isexe=%d, islink=%d," " mrid=rid, mhash=NULL" " WHERE pathname=%Q OR origname=%Q", mtime, rvChnged, rvPerm==PERM_EXE, rvPerm==PERM_LNK, zFile, zFile ); } blob_reset(&record); free(zFull); } |
︙ | ︙ |
Changes to src/vfile.c.
︙ | ︙ | |||
86 87 88 89 90 91 92 | db_begin_transaction(); p = manifest_get(vid, CFTYPE_MANIFEST, 0); if( p==0 ) { db_end_transaction(1); return 0; } db_prepare(&ins, | | | | 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | db_begin_transaction(); p = manifest_get(vid, CFTYPE_MANIFEST, 0); if( p==0 ) { db_end_transaction(1); return 0; } db_prepare(&ins, "INSERT INTO vfile(vid,isexe,islink,rid,mrid,pathname,mhash) " " VALUES(:vid,:isexe,:islink,:id,:id,:name,NULL)"); db_prepare(&ridq, "SELECT rid,size FROM blob WHERE uuid=:uuid"); db_bind_int(&ins, ":vid", vid); manifest_file_rewind(p); nMissing = 0; while( (pFile = manifest_file_next(p,0))!=0 ){ if( pFile->zUuid==0 || uuid_is_shunned(pFile->zUuid) ) continue; db_bind_text(&ridq, ":uuid", pFile->zUuid); |
︙ | ︙ | |||
240 241 242 243 244 245 246 | ** if --hash is used, check to see if they have been edited by ** looking at their artifact hashes */ const char *zUuid = db_column_text(&q, 5); int nUuid = db_column_bytes(&q, 5); assert( origSize==currentSize ); if( !hname_verify_file_hash(zName, zUuid, nUuid) ) chnged = 1; } | | | 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | ** if --hash is used, check to see if they have been edited by ** looking at their artifact hashes */ const char *zUuid = db_column_text(&q, 5); int nUuid = db_column_bytes(&q, 5); assert( origSize==currentSize ); if( !hname_verify_file_hash(zName, zUuid, nUuid) ) chnged = 1; } if( (cksigFlags & CKSIG_SETMTIME) && (chnged==0 || chnged==2 || chnged==4)){ i64 desiredMtime; if( mtime_of_manifest_file(vid,rid,&desiredMtime)==0 ){ if( currentMtime!=desiredMtime ){ file_set_mtime(zName, desiredMtime); currentMtime = file_mtime(zName, RepoFILE); } } |
︙ | ︙ | |||
964 965 966 967 968 969 970 | vfile_aggregate_checksum_repository(vid, &hash); printf("archive: %s\n", blob_str(&hash)); blob_reset(&hash); vfile_aggregate_checksum_manifest(vid, &hash, &hash2); printf("manifest: %s\n", blob_str(&hash)); printf("recorded: %s\n", blob_str(&hash2)); } | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 | vfile_aggregate_checksum_repository(vid, &hash); printf("archive: %s\n", blob_str(&hash)); blob_reset(&hash); vfile_aggregate_checksum_manifest(vid, &hash, &hash2); printf("manifest: %s\n", blob_str(&hash)); printf("recorded: %s\n", blob_str(&hash2)); } /* ** This routine recomputes certain columns of the vfile and vmerge tables ** when the associated repository is swapped out for a clone of the same ** project, and the blob.rid value change. The following columns are ** updated: ** ** vmerge.merge ** vfile.vid ** vfile.rid ** vfile.mrid ** ** Also: ** ** vvar.value WHERE name='checkout' */ void vfile_rid_renumbering_event(int dryRun){ int oldVid; int newVid; char *zUnresolved; oldVid = db_lget_int("checkout", 0); newVid = db_int(0, "SELECT blob.rid FROM blob, vvar" " WHERE blob.uuid=vvar.value" " AND vvar.name='checkout-hash'"); /* The idMap table will make old RID values into new ones */ db_multi_exec( "CREATE TEMP TABLE idMap(oldrid INTEGER PRIMARY KEY, newrid INT);\n" ); /* Add the RID value for the current check-out */ db_multi_exec( "INSERT INTO idMap(oldrid, newrid) VALUES(%d,%d)", oldVid, newVid ); /* Add the RID values for any other check-ins that have been merged into ** the current check-out. */ db_multi_exec( "INSERT OR IGNORE INTO idMap(oldrid, newrid)" " SELECT vmerge.merge, blob.rid FROM vmerge, blob" " WHERE blob.uuid=vmerge.mhash;" ); /* Add RID values for files in the current check-out */ db_multi_exec( "CREATE TEMP TABLE hashoffile(name TEXT PRIMARY KEY, hash TEXT)" "WITHOUT ROWID;" "INSERT INTO hashoffile(name,hash)" " SELECT filename, uuid FROM vvar, files_of_checkin(vvar.value)" " WHERE vvar.name='checkout-hash';" "INSERT OR IGNORE INTO idMap(oldrid, newrid)" " SELECT vfile.rid, blob.rid FROM vfile, hashoffile, blob" " WHERE hashoffile.name=coalesce(vfile.origname,vfile.pathname)" " AND blob.uuid=hashoffile.hash;" ); /* Add RID values for merged-in files */ db_multi_exec( "INSERT OR IGNORE INTO idMap(oldrid, newrid)" " SELECT vfile.mrid, blob.rid FROM vfile, blob" " WHERE blob.uuid=vfile.mhash;" ); if( dryRun ){ Stmt q; db_prepare(&q, "SELECT oldrid, newrid, blob.uuid" " FROM idMap, blob WHERE blob.rid=idMap.newrid"); while( db_step(&q)==SQLITE_ROW ){ fossil_print("%8d -> %8d %.25s\n", db_column_int(&q,0), db_column_int(&q,1), db_column_text(&q,2)); } db_finalize(&q); } /* Verify that all RID values in the VFILE table and VMERGE table have ** been resolved. */ zUnresolved = db_text("", "WITH allrid(x) AS (" " SELECT rid FROM vfile" " UNION SELECT mrid FROM vfile" " UNION SELECT merge FROM vmerge" " UNION SELECT %d" ")" "SELECT group_concat(x,' ') FROM allrid" " WHERE x NOT IN (SELECT oldrid FROM idMap);", oldVid ); if( zUnresolved[0] ){ fossil_fatal("Unresolved RID values: %s\n", zUnresolved); } /* Make the changes to the VFILE and VMERGE tables */ if( !dryRun ){ db_multi_exec( "UPDATE vfile" " SET rid=(SELECT newrid FROM idMap WHERE oldrid=vfile.rid)" " WHERE vid=%d AND rid>0;", oldVid); db_multi_exec( "UPDATE vfile" " SET mrid=(SELECT newrid FROM idMap WHERE oldrid=vfile.mrid)" " WHERE vid=%d AND mrid>0;", oldVid); db_multi_exec( "UPDATE vfile" " SET vid=%d" " WHERE vid=%d", newVid, oldVid); db_multi_exec( "UPDATE vmerge" " SET merge=(SELECT newrid FROM idMap WHERE oldrid=vmerge.merge);"); db_lset_int("checkout",newVid); } /* Clear out the TEMP tables we constructed */ db_multi_exec( "DROP TABLE idMap;" "DROP TABLE hashoffile;" ); } |