Fossil SCM
When reverting or updating a file, set the mtime to 0 as already done with merge and stash. Effectively, we don't trust the hash until next time we evaluate the status of the file, at which point we'll update vfile.mtime with the real mtime of the file. Based on discussions in [forum:/forumpost/58bef43842be6fc3|forum thread 58bef43842be6fc3]. 15:10:38 [229360b12e] *UNPUBLISHED* Consistently set vfile.mtime to 0 when merging, updating, reverting and changing a file. (user: preben tags: new-mtime-update)
Commit
f9686d02de6245a114fd6cd2a2ec2e331725e650c929770110e270609c23d157
Parent
25f486135d98290…
2 files changed
+2
-4
+12
-8
+2
-4
| --- src/update.c | ||
| +++ src/update.c | ||
| @@ -946,11 +946,10 @@ | ||
| 946 | 946 | zFile, zFile |
| 947 | 947 | ); |
| 948 | 948 | }else if( file_unsafe_in_tree_path(zFull) ){ |
| 949 | 949 | /* Ignore this file */ |
| 950 | 950 | }else{ |
| 951 | - sqlite3_int64 mtime; | |
| 952 | 951 | int rvChnged = 0; |
| 953 | 952 | int rvPerm = manifest_file_mperm(pRvFile); |
| 954 | 953 | |
| 955 | 954 | /* Determine if reverted-to file is different than checked-out file. */ |
| 956 | 955 | if( pCoManifest && (pCoFile = manifest_file_find(pCoManifest, zFile)) ){ |
| @@ -972,17 +971,16 @@ | ||
| 972 | 971 | }else{ |
| 973 | 972 | blob_write_to_file(&record, zFull); |
| 974 | 973 | } |
| 975 | 974 | file_setexe(zFull, rvPerm==PERM_EXE); |
| 976 | 975 | fossil_print("REVERT %s\n", zFile); |
| 977 | - mtime = file_mtime(zFull, RepoFILE); | |
| 978 | 976 | db_multi_exec( |
| 979 | 977 | "UPDATE vfile" |
| 980 | - " SET mtime=%lld, chnged=%d, deleted=0, isexe=%d, islink=%d," | |
| 978 | + " SET mtime=0, chnged=%d, deleted=0, isexe=%d, islink=%d," | |
| 981 | 979 | " mrid=rid, mhash=NULL" |
| 982 | 980 | " WHERE pathname=%Q OR origname=%Q", |
| 983 | - mtime, rvChnged, rvPerm==PERM_EXE, rvPerm==PERM_LNK, zFile, zFile | |
| 981 | + rvChnged, rvPerm==PERM_EXE, rvPerm==PERM_LNK, zFile, zFile | |
| 984 | 982 | ); |
| 985 | 983 | } |
| 986 | 984 | blob_reset(&record); |
| 987 | 985 | free(zFull); |
| 988 | 986 | } |
| 989 | 987 |
| --- src/update.c | |
| +++ src/update.c | |
| @@ -946,11 +946,10 @@ | |
| 946 | zFile, zFile |
| 947 | ); |
| 948 | }else if( file_unsafe_in_tree_path(zFull) ){ |
| 949 | /* Ignore this file */ |
| 950 | }else{ |
| 951 | sqlite3_int64 mtime; |
| 952 | int rvChnged = 0; |
| 953 | int rvPerm = manifest_file_mperm(pRvFile); |
| 954 | |
| 955 | /* Determine if reverted-to file is different than checked-out file. */ |
| 956 | if( pCoManifest && (pCoFile = manifest_file_find(pCoManifest, zFile)) ){ |
| @@ -972,17 +971,16 @@ | |
| 972 | }else{ |
| 973 | blob_write_to_file(&record, zFull); |
| 974 | } |
| 975 | file_setexe(zFull, rvPerm==PERM_EXE); |
| 976 | fossil_print("REVERT %s\n", zFile); |
| 977 | mtime = file_mtime(zFull, RepoFILE); |
| 978 | db_multi_exec( |
| 979 | "UPDATE vfile" |
| 980 | " SET mtime=%lld, chnged=%d, deleted=0, isexe=%d, islink=%d," |
| 981 | " mrid=rid, mhash=NULL" |
| 982 | " WHERE pathname=%Q OR origname=%Q", |
| 983 | mtime, rvChnged, rvPerm==PERM_EXE, rvPerm==PERM_LNK, zFile, zFile |
| 984 | ); |
| 985 | } |
| 986 | blob_reset(&record); |
| 987 | free(zFull); |
| 988 | } |
| 989 |
| --- src/update.c | |
| +++ src/update.c | |
| @@ -946,11 +946,10 @@ | |
| 946 | zFile, zFile |
| 947 | ); |
| 948 | }else if( file_unsafe_in_tree_path(zFull) ){ |
| 949 | /* Ignore this file */ |
| 950 | }else{ |
| 951 | int rvChnged = 0; |
| 952 | int rvPerm = manifest_file_mperm(pRvFile); |
| 953 | |
| 954 | /* Determine if reverted-to file is different than checked-out file. */ |
| 955 | if( pCoManifest && (pCoFile = manifest_file_find(pCoManifest, zFile)) ){ |
| @@ -972,17 +971,16 @@ | |
| 971 | }else{ |
| 972 | blob_write_to_file(&record, zFull); |
| 973 | } |
| 974 | file_setexe(zFull, rvPerm==PERM_EXE); |
| 975 | fossil_print("REVERT %s\n", zFile); |
| 976 | db_multi_exec( |
| 977 | "UPDATE vfile" |
| 978 | " SET mtime=0, chnged=%d, deleted=0, isexe=%d, islink=%d," |
| 979 | " mrid=rid, mhash=NULL" |
| 980 | " WHERE pathname=%Q OR origname=%Q", |
| 981 | rvChnged, rvPerm==PERM_EXE, rvPerm==PERM_LNK, zFile, zFile |
| 982 | ); |
| 983 | } |
| 984 | blob_reset(&record); |
| 985 | free(zFull); |
| 986 | } |
| 987 |
+12
-8
| --- src/vfile.c | ||
| +++ src/vfile.c | ||
| @@ -234,22 +234,28 @@ | ||
| 234 | 234 | const char *zUuid = db_column_text(&q, 5); |
| 235 | 235 | int nUuid = db_column_bytes(&q, 5); |
| 236 | 236 | assert( origSize==currentSize ); |
| 237 | 237 | if( hname_verify_file_hash(zName, zUuid, nUuid) ) chnged = 0; |
| 238 | 238 | }else if( (chnged==0 || chnged==2 || chnged==4) |
| 239 | - && (useMtime==0 || currentMtime!=oldMtime || oldMtime==now) ){ | |
| 239 | + && (useMtime==0 || currentMtime!=oldMtime) ){ | |
| 240 | 240 | /* For files that were formerly believed to be unchanged or that were |
| 241 | 241 | ** changed by merging, if their mtime changes, or unconditionally |
| 242 | 242 | ** if --hash is used, check to see if they have been edited by |
| 243 | - ** looking at their artifact hashes. Also check if mtime is current | |
| 244 | - ** in case a commit took place the same clock second checks started. */ | |
| 243 | + ** looking at their artifact hashes */ | |
| 245 | 244 | const char *zUuid = db_column_text(&q, 5); |
| 246 | 245 | int nUuid = db_column_bytes(&q, 5); |
| 247 | 246 | assert( origSize==currentSize ); |
| 248 | 247 | if( !hname_verify_file_hash(zName, zUuid, nUuid) ) chnged = 1; |
| 249 | 248 | } |
| 250 | - if( (cksigFlags & CKSIG_SETMTIME) && (chnged==0 || chnged==2 || chnged==4)){ | |
| 249 | + /* Before updating VFILE below, currentMtime may need an update: | |
| 250 | + ** 1. If file was modified just now, set to 0 as done when merging. | |
| 251 | + ** Next time we check, we will likely check the hash and update mtime. | |
| 252 | + ** 2. Set to manifest time, if requested. | |
| 253 | + */ | |
| 254 | + if( currentMtime >= now ){ | |
| 255 | + currentMtime = 0; | |
| 256 | + } else if( (cksigFlags & CKSIG_SETMTIME) && (chnged==0 || chnged==2 || chnged==4)){ | |
| 251 | 257 | i64 desiredMtime; |
| 252 | 258 | if( mtime_of_manifest_file(vid,rid,&desiredMtime)==0 ){ |
| 253 | 259 | if( currentMtime!=desiredMtime ){ |
| 254 | 260 | file_set_mtime(zName, desiredMtime); |
| 255 | 261 | currentMtime = file_mtime(zName, RepoFILE); |
| @@ -326,12 +332,11 @@ | ||
| 326 | 332 | } |
| 327 | 333 | content_get(rid, &content); |
| 328 | 334 | if( file_is_the_same(&content, zName) ){ |
| 329 | 335 | blob_reset(&content); |
| 330 | 336 | if( file_setexe(zName, isExe) ){ |
| 331 | - db_multi_exec("UPDATE vfile SET mtime=%lld WHERE id=%d", | |
| 332 | - file_mtime(zName, RepoFILE), id); | |
| 337 | + db_multi_exec("UPDATE vfile SET mtime=0 WHERE id=%d", id); | |
| 333 | 338 | } |
| 334 | 339 | continue; |
| 335 | 340 | } |
| 336 | 341 | if( promptFlag && file_size(zName, RepoFILE)>=0 ){ |
| 337 | 342 | Blob ans; |
| @@ -362,12 +367,11 @@ | ||
| 362 | 367 | }else{ |
| 363 | 368 | blob_write_to_file(&content, zName); |
| 364 | 369 | } |
| 365 | 370 | file_setexe(zName, isExe); |
| 366 | 371 | blob_reset(&content); |
| 367 | - db_multi_exec("UPDATE vfile SET mtime=%lld WHERE id=%d", | |
| 368 | - file_mtime(zName, RepoFILE), id); | |
| 372 | + db_multi_exec("UPDATE vfile SET mtime=0 WHERE id=%d", id); | |
| 369 | 373 | } |
| 370 | 374 | db_finalize(&q); |
| 371 | 375 | } |
| 372 | 376 | |
| 373 | 377 | /* |
| 374 | 378 |
| --- src/vfile.c | |
| +++ src/vfile.c | |
| @@ -234,22 +234,28 @@ | |
| 234 | const char *zUuid = db_column_text(&q, 5); |
| 235 | int nUuid = db_column_bytes(&q, 5); |
| 236 | assert( origSize==currentSize ); |
| 237 | if( hname_verify_file_hash(zName, zUuid, nUuid) ) chnged = 0; |
| 238 | }else if( (chnged==0 || chnged==2 || chnged==4) |
| 239 | && (useMtime==0 || currentMtime!=oldMtime || oldMtime==now) ){ |
| 240 | /* For files that were formerly believed to be unchanged or that were |
| 241 | ** changed by merging, if their mtime changes, or unconditionally |
| 242 | ** if --hash is used, check to see if they have been edited by |
| 243 | ** looking at their artifact hashes. Also check if mtime is current |
| 244 | ** in case a commit took place the same clock second checks started. */ |
| 245 | const char *zUuid = db_column_text(&q, 5); |
| 246 | int nUuid = db_column_bytes(&q, 5); |
| 247 | assert( origSize==currentSize ); |
| 248 | if( !hname_verify_file_hash(zName, zUuid, nUuid) ) chnged = 1; |
| 249 | } |
| 250 | if( (cksigFlags & CKSIG_SETMTIME) && (chnged==0 || chnged==2 || chnged==4)){ |
| 251 | i64 desiredMtime; |
| 252 | if( mtime_of_manifest_file(vid,rid,&desiredMtime)==0 ){ |
| 253 | if( currentMtime!=desiredMtime ){ |
| 254 | file_set_mtime(zName, desiredMtime); |
| 255 | currentMtime = file_mtime(zName, RepoFILE); |
| @@ -326,12 +332,11 @@ | |
| 326 | } |
| 327 | content_get(rid, &content); |
| 328 | if( file_is_the_same(&content, zName) ){ |
| 329 | blob_reset(&content); |
| 330 | if( file_setexe(zName, isExe) ){ |
| 331 | db_multi_exec("UPDATE vfile SET mtime=%lld WHERE id=%d", |
| 332 | file_mtime(zName, RepoFILE), id); |
| 333 | } |
| 334 | continue; |
| 335 | } |
| 336 | if( promptFlag && file_size(zName, RepoFILE)>=0 ){ |
| 337 | Blob ans; |
| @@ -362,12 +367,11 @@ | |
| 362 | }else{ |
| 363 | blob_write_to_file(&content, zName); |
| 364 | } |
| 365 | file_setexe(zName, isExe); |
| 366 | blob_reset(&content); |
| 367 | db_multi_exec("UPDATE vfile SET mtime=%lld WHERE id=%d", |
| 368 | file_mtime(zName, RepoFILE), id); |
| 369 | } |
| 370 | db_finalize(&q); |
| 371 | } |
| 372 | |
| 373 | /* |
| 374 |
| --- src/vfile.c | |
| +++ src/vfile.c | |
| @@ -234,22 +234,28 @@ | |
| 234 | const char *zUuid = db_column_text(&q, 5); |
| 235 | int nUuid = db_column_bytes(&q, 5); |
| 236 | assert( origSize==currentSize ); |
| 237 | if( hname_verify_file_hash(zName, zUuid, nUuid) ) chnged = 0; |
| 238 | }else if( (chnged==0 || chnged==2 || chnged==4) |
| 239 | && (useMtime==0 || currentMtime!=oldMtime) ){ |
| 240 | /* For files that were formerly believed to be unchanged or that were |
| 241 | ** changed by merging, if their mtime changes, or unconditionally |
| 242 | ** if --hash is used, check to see if they have been edited by |
| 243 | ** looking at their artifact hashes */ |
| 244 | const char *zUuid = db_column_text(&q, 5); |
| 245 | int nUuid = db_column_bytes(&q, 5); |
| 246 | assert( origSize==currentSize ); |
| 247 | if( !hname_verify_file_hash(zName, zUuid, nUuid) ) chnged = 1; |
| 248 | } |
| 249 | /* Before updating VFILE below, currentMtime may need an update: |
| 250 | ** 1. If file was modified just now, set to 0 as done when merging. |
| 251 | ** Next time we check, we will likely check the hash and update mtime. |
| 252 | ** 2. Set to manifest time, if requested. |
| 253 | */ |
| 254 | if( currentMtime >= now ){ |
| 255 | currentMtime = 0; |
| 256 | } else if( (cksigFlags & CKSIG_SETMTIME) && (chnged==0 || chnged==2 || chnged==4)){ |
| 257 | i64 desiredMtime; |
| 258 | if( mtime_of_manifest_file(vid,rid,&desiredMtime)==0 ){ |
| 259 | if( currentMtime!=desiredMtime ){ |
| 260 | file_set_mtime(zName, desiredMtime); |
| 261 | currentMtime = file_mtime(zName, RepoFILE); |
| @@ -326,12 +332,11 @@ | |
| 332 | } |
| 333 | content_get(rid, &content); |
| 334 | if( file_is_the_same(&content, zName) ){ |
| 335 | blob_reset(&content); |
| 336 | if( file_setexe(zName, isExe) ){ |
| 337 | db_multi_exec("UPDATE vfile SET mtime=0 WHERE id=%d", id); |
| 338 | } |
| 339 | continue; |
| 340 | } |
| 341 | if( promptFlag && file_size(zName, RepoFILE)>=0 ){ |
| 342 | Blob ans; |
| @@ -362,12 +367,11 @@ | |
| 367 | }else{ |
| 368 | blob_write_to_file(&content, zName); |
| 369 | } |
| 370 | file_setexe(zName, isExe); |
| 371 | blob_reset(&content); |
| 372 | db_multi_exec("UPDATE vfile SET mtime=0 WHERE id=%d", id); |
| 373 | } |
| 374 | db_finalize(&q); |
| 375 | } |
| 376 | |
| 377 | /* |
| 378 |