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)

preben 2024-01-11 16:55 hash-if-mtime-is-current
Commit f9686d02de6245a114fd6cd2a2ec2e331725e650c929770110e270609c23d157
2 files changed +2 -4 +12 -8
+2 -4
--- src/update.c
+++ src/update.c
@@ -946,11 +946,10 @@
946946
zFile, zFile
947947
);
948948
}else if( file_unsafe_in_tree_path(zFull) ){
949949
/* Ignore this file */
950950
}else{
951
- sqlite3_int64 mtime;
952951
int rvChnged = 0;
953952
int rvPerm = manifest_file_mperm(pRvFile);
954953
955954
/* Determine if reverted-to file is different than checked-out file. */
956955
if( pCoManifest && (pCoFile = manifest_file_find(pCoManifest, zFile)) ){
@@ -972,17 +971,16 @@
972971
}else{
973972
blob_write_to_file(&record, zFull);
974973
}
975974
file_setexe(zFull, rvPerm==PERM_EXE);
976975
fossil_print("REVERT %s\n", zFile);
977
- mtime = file_mtime(zFull, RepoFILE);
978976
db_multi_exec(
979977
"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,"
981979
" mrid=rid, mhash=NULL"
982980
" 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
984982
);
985983
}
986984
blob_reset(&record);
987985
free(zFull);
988986
}
989987
--- 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 @@
234234
const char *zUuid = db_column_text(&q, 5);
235235
int nUuid = db_column_bytes(&q, 5);
236236
assert( origSize==currentSize );
237237
if( hname_verify_file_hash(zName, zUuid, nUuid) ) chnged = 0;
238238
}else if( (chnged==0 || chnged==2 || chnged==4)
239
- && (useMtime==0 || currentMtime!=oldMtime || oldMtime==now) ){
239
+ && (useMtime==0 || currentMtime!=oldMtime) ){
240240
/* For files that were formerly believed to be unchanged or that were
241241
** changed by merging, if their mtime changes, or unconditionally
242242
** 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 */
245244
const char *zUuid = db_column_text(&q, 5);
246245
int nUuid = db_column_bytes(&q, 5);
247246
assert( origSize==currentSize );
248247
if( !hname_verify_file_hash(zName, zUuid, nUuid) ) chnged = 1;
249248
}
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)){
251257
i64 desiredMtime;
252258
if( mtime_of_manifest_file(vid,rid,&desiredMtime)==0 ){
253259
if( currentMtime!=desiredMtime ){
254260
file_set_mtime(zName, desiredMtime);
255261
currentMtime = file_mtime(zName, RepoFILE);
@@ -326,12 +332,11 @@
326332
}
327333
content_get(rid, &content);
328334
if( file_is_the_same(&content, zName) ){
329335
blob_reset(&content);
330336
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);
333338
}
334339
continue;
335340
}
336341
if( promptFlag && file_size(zName, RepoFILE)>=0 ){
337342
Blob ans;
@@ -362,12 +367,11 @@
362367
}else{
363368
blob_write_to_file(&content, zName);
364369
}
365370
file_setexe(zName, isExe);
366371
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);
369373
}
370374
db_finalize(&q);
371375
}
372376
373377
/*
374378
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button