Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Fix revert -r option to mark a reverted file as edited if the reverted-to version does not exactly match the checkout version, even if the file size is equal |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA1: |
f9080683f04371609df7a92597f5a1e8 |
| User & Date: | andygoth 2016-11-15 23:29:47.894 |
Context
|
2016-11-15
| ||
| 23:41 | Allow uv delete (or del) as an alias for uv remove or uv rm. See [http://www.mail-archive.com/fossil-users@lists.fossil-scm.org/msg24322.html]. check-in: b59fa7d0e7 user: andygoth tags: trunk | |
| 23:29 | Fix revert -r option to mark a reverted file as edited if the reverted-to version does not exactly match the checkout version, even if the file size is equal check-in: f9080683f0 user: andygoth tags: trunk | |
| 23:23 | Make changing to a symlink take priority over all other change types. This might also be a solution to the problem fixed by the previous commit, but it also avoids having a file that becomes a symlink (with target string length not equal to former file size) being marked as an ordinary edit. check-in: f10a284abb user: andygoth tags: trunk | |
Changes
Changes to src/db.c.
| ︙ | ︙ | |||
2213 2214 2215 2216 2217 2218 2219 |
blob_zero(&setting);
blob_appendf(&versionedPathname, "%s.fossil-settings/%s",
g.zLocalRoot, zName);
if( !g.localOpen ){
/* Repository is in the process of being opened, but files have not been
* written to disk. Load from the database. */
Blob noWarnFile;
| < | | < | | | 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 |
blob_zero(&setting);
blob_appendf(&versionedPathname, "%s.fossil-settings/%s",
g.zLocalRoot, zName);
if( !g.localOpen ){
/* Repository is in the process of being opened, but files have not been
* written to disk. Load from the database. */
Blob noWarnFile;
if( historical_blob(g.zOpenRevision, blob_str(&versionedPathname),
&setting, 0) ){
found = 1;
}
/* See if there's a no-warn flag */
blob_append(&versionedPathname, ".no-warn", -1);
blob_zero(&noWarnFile);
if( historical_blob(g.zOpenRevision, blob_str(&versionedPathname),
&noWarnFile, 0) ){
noWarn = 1;
}
blob_reset(&noWarnFile);
}else if( file_size(blob_str(&versionedPathname))>=0 ){
/* File exists, and contains the value for this setting. Load from
** the file. */
if( blob_read_from_file(&setting, blob_str(&versionedPathname))>=0 ){
|
| ︙ | ︙ |
Changes to src/finfo.c.
| ︙ | ︙ | |||
122 123 124 125 126 127 128 |
const char *zRevision = find_option("revision", "r", 1);
/* We should be done with options.. */
verify_all_options();
file_tree_name(g.argv[2], &fname, 0, 1);
if( zRevision ){
| | | 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
const char *zRevision = find_option("revision", "r", 1);
/* We should be done with options.. */
verify_all_options();
file_tree_name(g.argv[2], &fname, 0, 1);
if( zRevision ){
historical_blob(zRevision, blob_str(&fname), &record, 1);
}else{
int rid = db_int(0, "SELECT rid FROM vfile WHERE pathname=%B %s",
&fname, filename_collation());
if( rid==0 ){
fossil_fatal("no history for file: %b", &fname);
}
content_get(rid, &record);
|
| ︙ | ︙ | |||
247 248 249 250 251 252 253 |
** -R|--repository FILE Extract artifacts from repository FILE
** -r VERSION The specific check-in containing the file
**
** See also: finfo
*/
void cat_cmd(void){
int i;
| < | < < < | 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
** -R|--repository FILE Extract artifacts from repository FILE
** -r VERSION The specific check-in containing the file
**
** See also: finfo
*/
void cat_cmd(void){
int i;
Blob content, fname;
const char *zRev;
db_find_and_open_repository(0, 0);
zRev = find_option("r","r",1);
/* We should be done with options.. */
verify_all_options();
for(i=2; i<g.argc; i++){
file_tree_name(g.argv[i], &fname, 0, 1);
blob_zero(&content);
historical_blob(zRev, blob_str(&fname), &content, 1);
blob_write_to_file(&content, "-");
blob_reset(&fname);
blob_reset(&content);
}
}
/* Values for the debug= query parameter to finfo */
|
| ︙ | ︙ |
Changes to src/update.c.
| ︙ | ︙ | |||
628 629 630 631 632 633 634 635 636 |
blob_reset(&dirName);
}
blob_reset(&dirsList);
fossil_free(zEmptyDirs);
}
}
/*
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | | | | < < < > > > > | > > | < > > > | | < < | < < < < | | < | > > > | | | | > | < | | < < < < < < < | < < < | > | | > | < | 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 |
blob_reset(&dirName);
}
blob_reset(&dirsList);
fossil_free(zEmptyDirs);
}
}
/*
** Get the manifest record for a given revision, or the current checkout if
** zRevision is NULL.
*/
Manifest *historical_manifest(
const char *zRevision /* The check-in to query, or NULL for current */
){
int vid;
Manifest *pManifest;
/* Determine the check-in manifest artifact ID. Panic on failure. */
if( zRevision ){
vid = name_to_typed_rid(zRevision, "ci");
}else if( !g.localOpen ){
vid = name_to_typed_rid(db_get("main-branch", "trunk"), "ci");
}else{
vid = db_lget_int("checkout", 0);
if( !is_a_version(vid) ){
zRevision = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid);
if( zRevision ){
fossil_fatal("checkout artifact is not a check-in: %s", zRevision);
}else{
fossil_fatal("invalid checkout artifact ID: %d", vid);
}
}
}
/* Parse the manifest, given its artifact ID. Panic on failure. */
if( !(pManifest = manifest_get(vid, CFTYPE_MANIFEST, 0)) ){
if( zRevision ){
fossil_fatal("could not parse manifest for check-in: %s", zRevision);
}else{
fossil_fatal("could not parse manifest for current checkout");
}
}
/* Return the manifest pointer. The caller must use manifest_destroy() to
* clean up when finished using the manifest. */
return pManifest;
}
/*
** Get the contents of a file within the check-in "zRevision". If
** zRevision==NULL then get the file content for the current checkout.
*/
int historical_blob(
const char *zRevision, /* The check-in containing the file */
const char *zFile, /* Full treename of the file */
Blob *pBlob, /* Put the content here */
int fatal /* If nonzero, panic if file/artifact not found */
){
int result = 0;
/* Get the manifest for the requested check-in version. This call unavoidably
* panics on failure even if fatal is not set. */
Manifest *pManifest = historical_manifest(zRevision);
/* Try to find the file record within the manifest. */
ManifestFile *pFile = manifest_file_find(pManifest, zFile);
if( !pFile ){
/* Process file-not-found errors. */
if( fatal ){
if( zRevision ){
fossil_fatal("file %s does not exist in check-in %s", zFile, zRevision);
}else{
fossil_fatal("no such file: %s", zFile);
}
}
}else{
/* Get the file's contents. */
result = content_get(fast_uuid_to_rid(pFile->zUuid), pBlob);
/* Process artifact-not-found errors. */
if( !result && fatal ){
if( zRevision ){
fossil_fatal("missing artifact %s for file %s in check-in %s",
pFile->zUuid, zFile, zRevision);
}else{
fossil_fatal("missing artifact %s for file %s", pFile->zUuid, zFile);
}
}
}
/* Deallocate the parsed manifest structure. */
manifest_destroy(pManifest);
/* Return 1 on success and (assuming fatal is not set) 0 if not found. */
return result;
}
/*
** COMMAND: revert
**
** Usage: %fossil revert ?-r REVISION? ?FILE ...?
**
** Revert to the current repository version of FILE, or to
|
| ︙ | ︙ | |||
710 711 712 713 714 715 716 |
**
** Options:
** -r REVISION revert given FILE(s) back to given REVISION
**
** See also: redo, undo, update
*/
void revert_cmd(void){
| > > > > | | | < > > > > > | 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 |
**
** Options:
** -r REVISION revert given FILE(s) back to given REVISION
**
** See also: redo, undo, update
*/
void revert_cmd(void){
Manifest *pCoManifest; /* Manifest of current checkout */
Manifest *pRvManifest; /* Manifest of selected revert version */
ManifestFile *pCoFile; /* File within current checkout manifest */
ManifestFile *pRvFile; /* File within revert version manifest */
const char *zFile; /* Filename relative to checkout root */
const char *zRevision; /* Selected revert version, NULL if current */
Blob record = BLOB_INITIALIZER; /* Contents of each reverted file */
int i;
Stmt q;
undo_capture_command_line();
zRevision = find_option("revision", "r", 1);
verify_all_options();
if( g.argc<2 ){
usage("?OPTIONS? [FILE] ...");
}
if( zRevision && g.argc<3 ){
fossil_fatal("the --revision option does not work for the entire tree");
}
db_must_be_within_tree();
/* Get manifests of revert version and (if different) current checkout. */
pRvManifest = historical_manifest(zRevision);
pCoManifest = zRevision ? historical_manifest(0) : 0;
db_begin_transaction();
undo_begin();
db_multi_exec("CREATE TEMP TABLE torevert(name UNIQUE);");
if( g.argc>2 ){
for(i=2; i<g.argc; i++){
Blob fname;
|
| ︙ | ︙ | |||
773 774 775 776 777 778 779 |
blob_zero(&record);
db_prepare(&q, "SELECT name FROM torevert");
if( zRevision==0 ){
int vid = db_lget_int("checkout", 0);
zRevision = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid);
}
while( db_step(&q)==SQLITE_ROW ){
| < < | < | > > > > > > > > > > > > | | | | | | > > > > | 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 |
blob_zero(&record);
db_prepare(&q, "SELECT name FROM torevert");
if( zRevision==0 ){
int vid = db_lget_int("checkout", 0);
zRevision = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid);
}
while( db_step(&q)==SQLITE_ROW ){
char *zFull;
zFile = db_column_text(&q, 0);
zFull = mprintf("%/%/", g.zLocalRoot, zFile);
pRvFile = manifest_file_find(pRvManifest, zFile);
if( !pRvFile ){
if( db_int(0, "SELECT rid FROM vfile WHERE pathname=%Q OR origname=%Q",
zFile, zFile)==0 ){
fossil_print("UNMANAGE %s\n", zFile);
}else{
undo_save(zFile);
file_delete(zFull);
fossil_print("DELETE %s\n", zFile);
}
db_multi_exec(
"UPDATE OR REPLACE vfile"
" SET pathname=origname, origname=NULL"
" WHERE pathname=%Q AND origname!=pathname;"
"DELETE FROM vfile WHERE pathname=%Q",
zFile, zFile
);
}else{
sqlite3_int64 mtime;
int rvChnged = 0;
int rvPerm = manifest_file_mperm(pRvFile);
/* Determine if reverted-to file is different than checked out file. */
if( pCoManifest && (pCoFile = manifest_file_find(pCoManifest, zFile)) ){
rvChnged = manifest_file_mperm(pRvFile)!=rvPerm
|| fossil_strcmp(pRvFile->zUuid, pCoFile->zUuid)!=0;
}
/* Get contents of reverted-to file. */
content_get(fast_uuid_to_rid(pRvFile->zUuid), &record);
undo_save(zFile);
if( file_wd_size(zFull)>=0 && (rvPerm==PERM_LNK || file_wd_islink(0)) ){
file_delete(zFull);
}
if( rvPerm==PERM_LNK ){
symlink_create(blob_str(&record), zFull);
}else{
blob_write_to_file(&record, zFull);
}
file_wd_setexe(zFull, rvPerm==PERM_EXE);
fossil_print("REVERT %s\n", zFile);
mtime = file_wd_mtime(zFull);
db_multi_exec(
"UPDATE vfile"
" SET mtime=%lld, chnged=%d, deleted=0, isexe=%d, islink=%d,mrid=rid"
" WHERE pathname=%Q OR origname=%Q",
mtime, rvChnged, rvPerm==PERM_EXE, rvPerm==PERM_LNK, zFile, zFile
);
}
blob_reset(&record);
free(zFull);
}
db_finalize(&q);
undo_finish();
db_end_transaction(0);
/* Deallocate parsed manifest structures. */
manifest_destroy(pRvManifest);
manifest_destroy(pCoManifest);
}
|