Fossil SCM

Add the --setmtime command-line option to "fossil update". When this option is used, the mtime of all unmodified managed files is set to the time when that file was originally checked in.

drh 2012-10-11 19:22 trunk
Commit ae092ec605eed11fc5790718aff2b110b156c97d
+2 -2
--- src/checkin.c
+++ src/checkin.c
@@ -160,11 +160,11 @@
160160
int cwdRelative = 0;
161161
db_must_be_within_tree();
162162
cwdRelative = determine_cwd_relative_option();
163163
blob_zero(&report);
164164
vid = db_lget_int("checkout", 0);
165
- vfile_check_signature(vid, 0, useSha1sum);
165
+ vfile_check_signature(vid, useSha1sum ? CKSIG_SHA1 : 0);
166166
status_report(&report, "", 0, cwdRelative);
167167
if( verbose && blob_size(&report)==0 ){
168168
blob_append(&report, " (none)\n", -1);
169169
}
170170
if( showHdr && blob_size(&report)>0 ){
@@ -244,11 +244,11 @@
244244
}else{
245245
zOrderBy = "mtime DESC";
246246
}
247247
}
248248
verify_all_options();
249
- vfile_check_signature(vid, 0, 0);
249
+ vfile_check_signature(vid, 0);
250250
if( showAge ){
251251
db_prepare(&q,
252252
"SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0),"
253253
" datetime(checkin_mtime(%d,rid),'unixepoch','localtime')"
254254
" FROM vfile"
255255
--- src/checkin.c
+++ src/checkin.c
@@ -160,11 +160,11 @@
160 int cwdRelative = 0;
161 db_must_be_within_tree();
162 cwdRelative = determine_cwd_relative_option();
163 blob_zero(&report);
164 vid = db_lget_int("checkout", 0);
165 vfile_check_signature(vid, 0, useSha1sum);
166 status_report(&report, "", 0, cwdRelative);
167 if( verbose && blob_size(&report)==0 ){
168 blob_append(&report, " (none)\n", -1);
169 }
170 if( showHdr && blob_size(&report)>0 ){
@@ -244,11 +244,11 @@
244 }else{
245 zOrderBy = "mtime DESC";
246 }
247 }
248 verify_all_options();
249 vfile_check_signature(vid, 0, 0);
250 if( showAge ){
251 db_prepare(&q,
252 "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0),"
253 " datetime(checkin_mtime(%d,rid),'unixepoch','localtime')"
254 " FROM vfile"
255
--- src/checkin.c
+++ src/checkin.c
@@ -160,11 +160,11 @@
160 int cwdRelative = 0;
161 db_must_be_within_tree();
162 cwdRelative = determine_cwd_relative_option();
163 blob_zero(&report);
164 vid = db_lget_int("checkout", 0);
165 vfile_check_signature(vid, useSha1sum ? CKSIG_SHA1 : 0);
166 status_report(&report, "", 0, cwdRelative);
167 if( verbose && blob_size(&report)==0 ){
168 blob_append(&report, " (none)\n", -1);
169 }
170 if( showHdr && blob_size(&report)>0 ){
@@ -244,11 +244,11 @@
244 }else{
245 zOrderBy = "mtime DESC";
246 }
247 }
248 verify_all_options();
249 vfile_check_signature(vid, 0);
250 if( showAge ){
251 db_prepare(&q,
252 "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0),"
253 " datetime(checkin_mtime(%d,rid),'unixepoch','localtime')"
254 " FROM vfile"
255
+1 -1
--- src/checkout.c
+++ src/checkout.c
@@ -33,11 +33,11 @@
3333
int unsaved_changes(void){
3434
int vid;
3535
db_must_be_within_tree();
3636
vid = db_lget_int("checkout",0);
3737
if( vid==0 ) return 2;
38
- vfile_check_signature(vid, 1, 0);
38
+ vfile_check_signature(vid, CKSIG_ENOTFILE);
3939
return db_exists("SELECT 1 FROM vfile WHERE chnged"
4040
" OR coalesce(origname!=pathname,0)");
4141
}
4242
4343
/*
4444
--- src/checkout.c
+++ src/checkout.c
@@ -33,11 +33,11 @@
33 int unsaved_changes(void){
34 int vid;
35 db_must_be_within_tree();
36 vid = db_lget_int("checkout",0);
37 if( vid==0 ) return 2;
38 vfile_check_signature(vid, 1, 0);
39 return db_exists("SELECT 1 FROM vfile WHERE chnged"
40 " OR coalesce(origname!=pathname,0)");
41 }
42
43 /*
44
--- src/checkout.c
+++ src/checkout.c
@@ -33,11 +33,11 @@
33 int unsaved_changes(void){
34 int vid;
35 db_must_be_within_tree();
36 vid = db_lget_int("checkout",0);
37 if( vid==0 ) return 2;
38 vfile_check_signature(vid, CKSIG_ENOTFILE);
39 return db_exists("SELECT 1 FROM vfile WHERE chnged"
40 " OR coalesce(origname!=pathname,0)");
41 }
42
43 /*
44
+1 -1
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -322,11 +322,11 @@
322322
Stmt q;
323323
int asNewFile; /* Treat non-existant files as empty files */
324324
325325
asNewFile = (diffFlags & DIFF_NEWFILE)!=0;
326326
vid = db_lget_int("checkout", 0);
327
- vfile_check_signature(vid, 1, 0);
327
+ vfile_check_signature(vid, CKSIG_ENOTFILE);
328328
blob_zero(&sql);
329329
db_begin_transaction();
330330
if( zFrom ){
331331
int rid = name_to_typed_rid(zFrom, "ci");
332332
if( !is_a_version(rid) ){
333333
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -322,11 +322,11 @@
322 Stmt q;
323 int asNewFile; /* Treat non-existant files as empty files */
324
325 asNewFile = (diffFlags & DIFF_NEWFILE)!=0;
326 vid = db_lget_int("checkout", 0);
327 vfile_check_signature(vid, 1, 0);
328 blob_zero(&sql);
329 db_begin_transaction();
330 if( zFrom ){
331 int rid = name_to_typed_rid(zFrom, "ci");
332 if( !is_a_version(rid) ){
333
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -322,11 +322,11 @@
322 Stmt q;
323 int asNewFile; /* Treat non-existant files as empty files */
324
325 asNewFile = (diffFlags & DIFF_NEWFILE)!=0;
326 vid = db_lget_int("checkout", 0);
327 vfile_check_signature(vid, CKSIG_ENOTFILE);
328 blob_zero(&sql);
329 db_begin_transaction();
330 if( zFrom ){
331 int rid = name_to_typed_rid(zFrom, "ci");
332 if( !is_a_version(rid) ){
333
+1 -1
--- src/finfo.c
+++ src/finfo.c
@@ -66,11 +66,11 @@
6666
if( g.argc!=3 ) usage("-s|--status FILENAME");
6767
vid = db_lget_int("checkout", 0);
6868
if( vid==0 ){
6969
fossil_panic("no checkout to finfo files in");
7070
}
71
- vfile_check_signature(vid, 1, 0);
71
+ vfile_check_signature(vid, CKSIG_ENOTFILE);
7272
file_tree_name(g.argv[2], &fname, 1);
7373
db_prepare(&q,
7474
"SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0)"
7575
" FROM vfile WHERE vfile.pathname=%B %s",
7676
&fname, filename_collation());
7777
--- src/finfo.c
+++ src/finfo.c
@@ -66,11 +66,11 @@
66 if( g.argc!=3 ) usage("-s|--status FILENAME");
67 vid = db_lget_int("checkout", 0);
68 if( vid==0 ){
69 fossil_panic("no checkout to finfo files in");
70 }
71 vfile_check_signature(vid, 1, 0);
72 file_tree_name(g.argv[2], &fname, 1);
73 db_prepare(&q,
74 "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0)"
75 " FROM vfile WHERE vfile.pathname=%B %s",
76 &fname, filename_collation());
77
--- src/finfo.c
+++ src/finfo.c
@@ -66,11 +66,11 @@
66 if( g.argc!=3 ) usage("-s|--status FILENAME");
67 vid = db_lget_int("checkout", 0);
68 if( vid==0 ){
69 fossil_panic("no checkout to finfo files in");
70 }
71 vfile_check_signature(vid, CKSIG_ENOTFILE);
72 file_tree_name(g.argv[2], &fname, 1);
73 db_prepare(&q,
74 "SELECT pathname, deleted, rid, chnged, coalesce(origname!=pathname,0)"
75 " FROM vfile WHERE vfile.pathname=%B %s",
76 &fname, filename_collation());
77
+1 -1
--- src/merge.c
+++ src/merge.c
@@ -189,11 +189,11 @@
189189
}
190190
if( detailFlag ){
191191
print_checkin_description(mid, 12, "merge-from:");
192192
print_checkin_description(pid, 12, "baseline:");
193193
}
194
- vfile_check_signature(vid, 1, 0);
194
+ vfile_check_signature(vid, CKSIG_ENOTFILE);
195195
db_begin_transaction();
196196
if( !nochangeFlag ) undo_begin();
197197
load_vfile_from_rid(mid);
198198
load_vfile_from_rid(pid);
199199
if( debugFlag ){
200200
--- src/merge.c
+++ src/merge.c
@@ -189,11 +189,11 @@
189 }
190 if( detailFlag ){
191 print_checkin_description(mid, 12, "merge-from:");
192 print_checkin_description(pid, 12, "baseline:");
193 }
194 vfile_check_signature(vid, 1, 0);
195 db_begin_transaction();
196 if( !nochangeFlag ) undo_begin();
197 load_vfile_from_rid(mid);
198 load_vfile_from_rid(pid);
199 if( debugFlag ){
200
--- src/merge.c
+++ src/merge.c
@@ -189,11 +189,11 @@
189 }
190 if( detailFlag ){
191 print_checkin_description(mid, 12, "merge-from:");
192 print_checkin_description(pid, 12, "baseline:");
193 }
194 vfile_check_signature(vid, CKSIG_ENOTFILE);
195 db_begin_transaction();
196 if( !nochangeFlag ) undo_begin();
197 load_vfile_from_rid(mid);
198 load_vfile_from_rid(pid);
199 if( debugFlag ){
200
+1 -1
--- src/stash.c
+++ src/stash.c
@@ -172,11 +172,11 @@
172172
zComment = blob_str(&comment);
173173
}
174174
stashid = db_lget_int("stash-next", 1);
175175
db_lset_int("stash-next", stashid+1);
176176
vid = db_lget_int("checkout", 0);
177
- vfile_check_signature(vid, 0, 0);
177
+ vfile_check_signature(vid, 0);
178178
db_multi_exec(
179179
"INSERT INTO stash(stashid,vid,comment,ctime)"
180180
"VALUES(%d,%d,%Q,julianday('now'))",
181181
stashid, vid, zComment
182182
);
183183
--- src/stash.c
+++ src/stash.c
@@ -172,11 +172,11 @@
172 zComment = blob_str(&comment);
173 }
174 stashid = db_lget_int("stash-next", 1);
175 db_lset_int("stash-next", stashid+1);
176 vid = db_lget_int("checkout", 0);
177 vfile_check_signature(vid, 0, 0);
178 db_multi_exec(
179 "INSERT INTO stash(stashid,vid,comment,ctime)"
180 "VALUES(%d,%d,%Q,julianday('now'))",
181 stashid, vid, zComment
182 );
183
--- src/stash.c
+++ src/stash.c
@@ -172,11 +172,11 @@
172 zComment = blob_str(&comment);
173 }
174 stashid = db_lget_int("stash-next", 1);
175 db_lset_int("stash-next", stashid+1);
176 vid = db_lget_int("checkout", 0);
177 vfile_check_signature(vid, 0);
178 db_multi_exec(
179 "INSERT INTO stash(stashid,vid,comment,ctime)"
180 "VALUES(%d,%d,%Q,julianday('now'))",
181 stashid, vid, zComment
182 );
183
+5 -2
--- src/update.c
+++ src/update.c
@@ -100,10 +100,11 @@
100100
Stmt q;
101101
int latestFlag; /* --latest. Pick the latest version if true */
102102
int nochangeFlag; /* -n or --nochange. Do a dry run */
103103
int verboseFlag; /* -v or --verbose. Output extra information */
104104
int debugFlag; /* --debug option */
105
+ int setmtimeFlag; /* --setmtime. Set mtimes on files */
105106
int nChng; /* Number of file renames */
106107
int *aChng; /* Array of file renames */
107108
int i; /* Loop counter */
108109
int nConflict = 0; /* Number of merge conflicts */
109110
int nOverwrite = 0; /* Number of unmanaged files overwritten */
@@ -116,10 +117,11 @@
116117
}
117118
latestFlag = find_option("latest",0, 0)!=0;
118119
nochangeFlag = find_option("nochange","n",0)!=0;
119120
verboseFlag = find_option("verbose","v",0)!=0;
120121
debugFlag = find_option("debug",0,0)!=0;
122
+ setmtimeFlag = find_option("setmtime",0,0)!=0;
121123
db_must_be_within_tree();
122124
vid = db_lget_int("checkout", 0);
123125
if( vid==0 ){
124126
fossil_fatal("cannot find current version");
125127
}
@@ -194,11 +196,11 @@
194196
if( tid==0 ){
195197
fossil_panic("Internal Error: unable to find a version to update to.");
196198
}
197199
198200
db_begin_transaction();
199
- vfile_check_signature(vid, 1, 0);
201
+ vfile_check_signature(vid, CKSIG_ENOTFILE);
200202
if( !nochangeFlag && !internalUpdate ) undo_begin();
201203
load_vfile_from_rid(tid);
202204
203205
/*
204206
** The record.fn field is used to match files against each other. The
@@ -529,10 +531,11 @@
529531
/* A subset of files have been checked out. Keep the current
530532
** checkout unchanged. */
531533
db_multi_exec("DELETE FROM vfile WHERE vid!=%d", vid);
532534
}
533535
if( !internalUpdate ) undo_finish();
536
+ if( setmtimeFlag ) vfile_check_signature(vid, CKSIG_SETMTIME);
534537
db_end_transaction(0);
535538
}
536539
}
537540
538541
/*
@@ -696,11 +699,11 @@
696699
blob_reset(&fname);
697700
}
698701
}else{
699702
int vid;
700703
vid = db_lget_int("checkout", 0);
701
- vfile_check_signature(vid, 0, 0);
704
+ vfile_check_signature(vid, 0);
702705
db_multi_exec(
703706
"DELETE FROM vmerge;"
704707
"INSERT INTO torevert "
705708
"SELECT pathname"
706709
" FROM vfile "
707710
--- src/update.c
+++ src/update.c
@@ -100,10 +100,11 @@
100 Stmt q;
101 int latestFlag; /* --latest. Pick the latest version if true */
102 int nochangeFlag; /* -n or --nochange. Do a dry run */
103 int verboseFlag; /* -v or --verbose. Output extra information */
104 int debugFlag; /* --debug option */
 
105 int nChng; /* Number of file renames */
106 int *aChng; /* Array of file renames */
107 int i; /* Loop counter */
108 int nConflict = 0; /* Number of merge conflicts */
109 int nOverwrite = 0; /* Number of unmanaged files overwritten */
@@ -116,10 +117,11 @@
116 }
117 latestFlag = find_option("latest",0, 0)!=0;
118 nochangeFlag = find_option("nochange","n",0)!=0;
119 verboseFlag = find_option("verbose","v",0)!=0;
120 debugFlag = find_option("debug",0,0)!=0;
 
121 db_must_be_within_tree();
122 vid = db_lget_int("checkout", 0);
123 if( vid==0 ){
124 fossil_fatal("cannot find current version");
125 }
@@ -194,11 +196,11 @@
194 if( tid==0 ){
195 fossil_panic("Internal Error: unable to find a version to update to.");
196 }
197
198 db_begin_transaction();
199 vfile_check_signature(vid, 1, 0);
200 if( !nochangeFlag && !internalUpdate ) undo_begin();
201 load_vfile_from_rid(tid);
202
203 /*
204 ** The record.fn field is used to match files against each other. The
@@ -529,10 +531,11 @@
529 /* A subset of files have been checked out. Keep the current
530 ** checkout unchanged. */
531 db_multi_exec("DELETE FROM vfile WHERE vid!=%d", vid);
532 }
533 if( !internalUpdate ) undo_finish();
 
534 db_end_transaction(0);
535 }
536 }
537
538 /*
@@ -696,11 +699,11 @@
696 blob_reset(&fname);
697 }
698 }else{
699 int vid;
700 vid = db_lget_int("checkout", 0);
701 vfile_check_signature(vid, 0, 0);
702 db_multi_exec(
703 "DELETE FROM vmerge;"
704 "INSERT INTO torevert "
705 "SELECT pathname"
706 " FROM vfile "
707
--- src/update.c
+++ src/update.c
@@ -100,10 +100,11 @@
100 Stmt q;
101 int latestFlag; /* --latest. Pick the latest version if true */
102 int nochangeFlag; /* -n or --nochange. Do a dry run */
103 int verboseFlag; /* -v or --verbose. Output extra information */
104 int debugFlag; /* --debug option */
105 int setmtimeFlag; /* --setmtime. Set mtimes on files */
106 int nChng; /* Number of file renames */
107 int *aChng; /* Array of file renames */
108 int i; /* Loop counter */
109 int nConflict = 0; /* Number of merge conflicts */
110 int nOverwrite = 0; /* Number of unmanaged files overwritten */
@@ -116,10 +117,11 @@
117 }
118 latestFlag = find_option("latest",0, 0)!=0;
119 nochangeFlag = find_option("nochange","n",0)!=0;
120 verboseFlag = find_option("verbose","v",0)!=0;
121 debugFlag = find_option("debug",0,0)!=0;
122 setmtimeFlag = find_option("setmtime",0,0)!=0;
123 db_must_be_within_tree();
124 vid = db_lget_int("checkout", 0);
125 if( vid==0 ){
126 fossil_fatal("cannot find current version");
127 }
@@ -194,11 +196,11 @@
196 if( tid==0 ){
197 fossil_panic("Internal Error: unable to find a version to update to.");
198 }
199
200 db_begin_transaction();
201 vfile_check_signature(vid, CKSIG_ENOTFILE);
202 if( !nochangeFlag && !internalUpdate ) undo_begin();
203 load_vfile_from_rid(tid);
204
205 /*
206 ** The record.fn field is used to match files against each other. The
@@ -529,10 +531,11 @@
531 /* A subset of files have been checked out. Keep the current
532 ** checkout unchanged. */
533 db_multi_exec("DELETE FROM vfile WHERE vid!=%d", vid);
534 }
535 if( !internalUpdate ) undo_finish();
536 if( setmtimeFlag ) vfile_check_signature(vid, CKSIG_SETMTIME);
537 db_end_transaction(0);
538 }
539 }
540
541 /*
@@ -696,11 +699,11 @@
699 blob_reset(&fname);
700 }
701 }else{
702 int vid;
703 vid = db_lget_int("checkout", 0);
704 vfile_check_signature(vid, 0);
705 db_multi_exec(
706 "DELETE FROM vmerge;"
707 "INSERT INTO torevert "
708 "SELECT pathname"
709 " FROM vfile "
710
+29 -8
--- src/vfile.c
+++ src/vfile.c
@@ -118,19 +118,30 @@
118118
db_finalize(&ins);
119119
manifest_destroy(p);
120120
db_end_transaction(0);
121121
}
122122
123
+#if INTERFACE
124
+/*
125
+** The cksigFlags parameter to vfile_check_signature() is an OR-ed
126
+** combination of the following bits:
127
+*/
128
+#define CKSIG_ENOTFILE 0x001 /* non-file FS objects throw an error */
129
+#define CKSIG_SHA1 0x002 /* Verify file content using sha1sum */
130
+#define CKSIG_SETMTIME 0x004 /* Set mtime to last check-out time */
131
+
132
+#endif /* INTERFACE */
133
+
123134
/*
124
-** Look at every VFILE entry with the given vid and set update
125
-** VFILE.CHNGED field on every file according to whether or not
126
-** the file has changes. 0 means no change. 1 means edited. 2 means
135
+** Look at every VFILE entry with the given vid and update
136
+** VFILE.CHNGED field according to whether or not
137
+** the file has changed. 0 means no change. 1 means edited. 2 means
127138
** the file has changed due to a merge. 3 means the file was added
128139
** by a merge.
129140
**
130
-** If VFILE.DELETED is true or if VFILE.RID is zero, then the file was
131
-** either removed from managemented via "fossil rm" or added via
141
+** If VFILE.DELETED is true or if VFILE.RID is zero, then the file was either
142
+** removed from configuration management via "fossil rm" or added via
132143
** "fossil add", respectively, and in both cases we always know that
133144
** the file has changed without having the check the size, mtime,
134145
** or on-disk content.
135146
**
136147
** If the size of the file has changed, then we always know that the file
@@ -144,15 +155,16 @@
144155
**
145156
** If the mtime is used, it is used only to determine if files are the same.
146157
** If the mtime of a file has changed, we still examine the on-disk content
147158
** to see whether or not the edit was a null-edit.
148159
*/
149
-void vfile_check_signature(int vid, int notFileIsFatal, int useSha1sum){
160
+void vfile_check_signature(int vid, unsigned int cksigFlags){
150161
int nErr = 0;
151162
Stmt q;
152163
Blob fileCksum, origCksum;
153
- int useMtime = useSha1sum==0 && db_get_boolean("mtime-changes", 1);
164
+ int useMtime = (cksigFlags & CKSIG_SHA1)==0
165
+ && db_get_boolean("mtime-changes", 1);
154166
155167
db_begin_transaction();
156168
db_prepare(&q, "SELECT id, %Q || pathname,"
157169
" vfile.mrid, deleted, chnged, uuid, size, mtime"
158170
" FROM vfile LEFT JOIN blob ON vfile.mrid=blob.rid"
@@ -178,11 +190,11 @@
178190
currentMtime = file_wd_mtime(0);
179191
if( chnged==0 && (isDeleted || rid==0) ){
180192
/* "fossil rm" or "fossil add" always change the file */
181193
chnged = 1;
182194
}else if( !file_wd_isfile_or_link(0) && currentSize>=0 ){
183
- if( notFileIsFatal ){
195
+ if( cksigFlags & CKSIG_ENOTFILE ){
184196
fossil_warning("not an ordinary file: %s", zName);
185197
nErr++;
186198
}
187199
chnged = 1;
188200
}
@@ -217,10 +229,19 @@
217229
if( blob_compare(&fileCksum, &origCksum) ){
218230
chnged = 1;
219231
}
220232
blob_reset(&origCksum);
221233
blob_reset(&fileCksum);
234
+ }
235
+ if( (cksigFlags & CKSIG_SETMTIME) && (chnged==0 || chnged==2) ){
236
+ i64 desiredMtime;
237
+ if( mtime_of_manifest_file(vid,rid,&desiredMtime)==0 ){
238
+ if( currentMtime!=desiredMtime ){
239
+ file_set_mtime(zName, desiredMtime);
240
+ currentMtime = file_wd_mtime(zName);
241
+ }
242
+ }
222243
}
223244
if( currentMtime!=oldMtime || chnged!=oldChnged ){
224245
db_multi_exec("UPDATE vfile SET mtime=%lld, chnged=%d WHERE id=%d",
225246
currentMtime, chnged, id);
226247
}
227248
--- src/vfile.c
+++ src/vfile.c
@@ -118,19 +118,30 @@
118 db_finalize(&ins);
119 manifest_destroy(p);
120 db_end_transaction(0);
121 }
122
 
 
 
 
 
 
 
 
 
 
 
123 /*
124 ** Look at every VFILE entry with the given vid and set update
125 ** VFILE.CHNGED field on every file according to whether or not
126 ** the file has changes. 0 means no change. 1 means edited. 2 means
127 ** the file has changed due to a merge. 3 means the file was added
128 ** by a merge.
129 **
130 ** If VFILE.DELETED is true or if VFILE.RID is zero, then the file was
131 ** either removed from managemented via "fossil rm" or added via
132 ** "fossil add", respectively, and in both cases we always know that
133 ** the file has changed without having the check the size, mtime,
134 ** or on-disk content.
135 **
136 ** If the size of the file has changed, then we always know that the file
@@ -144,15 +155,16 @@
144 **
145 ** If the mtime is used, it is used only to determine if files are the same.
146 ** If the mtime of a file has changed, we still examine the on-disk content
147 ** to see whether or not the edit was a null-edit.
148 */
149 void vfile_check_signature(int vid, int notFileIsFatal, int useSha1sum){
150 int nErr = 0;
151 Stmt q;
152 Blob fileCksum, origCksum;
153 int useMtime = useSha1sum==0 && db_get_boolean("mtime-changes", 1);
 
154
155 db_begin_transaction();
156 db_prepare(&q, "SELECT id, %Q || pathname,"
157 " vfile.mrid, deleted, chnged, uuid, size, mtime"
158 " FROM vfile LEFT JOIN blob ON vfile.mrid=blob.rid"
@@ -178,11 +190,11 @@
178 currentMtime = file_wd_mtime(0);
179 if( chnged==0 && (isDeleted || rid==0) ){
180 /* "fossil rm" or "fossil add" always change the file */
181 chnged = 1;
182 }else if( !file_wd_isfile_or_link(0) && currentSize>=0 ){
183 if( notFileIsFatal ){
184 fossil_warning("not an ordinary file: %s", zName);
185 nErr++;
186 }
187 chnged = 1;
188 }
@@ -217,10 +229,19 @@
217 if( blob_compare(&fileCksum, &origCksum) ){
218 chnged = 1;
219 }
220 blob_reset(&origCksum);
221 blob_reset(&fileCksum);
 
 
 
 
 
 
 
 
 
222 }
223 if( currentMtime!=oldMtime || chnged!=oldChnged ){
224 db_multi_exec("UPDATE vfile SET mtime=%lld, chnged=%d WHERE id=%d",
225 currentMtime, chnged, id);
226 }
227
--- src/vfile.c
+++ src/vfile.c
@@ -118,19 +118,30 @@
118 db_finalize(&ins);
119 manifest_destroy(p);
120 db_end_transaction(0);
121 }
122
123 #if INTERFACE
124 /*
125 ** The cksigFlags parameter to vfile_check_signature() is an OR-ed
126 ** combination of the following bits:
127 */
128 #define CKSIG_ENOTFILE 0x001 /* non-file FS objects throw an error */
129 #define CKSIG_SHA1 0x002 /* Verify file content using sha1sum */
130 #define CKSIG_SETMTIME 0x004 /* Set mtime to last check-out time */
131
132 #endif /* INTERFACE */
133
134 /*
135 ** Look at every VFILE entry with the given vid and update
136 ** VFILE.CHNGED field according to whether or not
137 ** the file has changed. 0 means no change. 1 means edited. 2 means
138 ** the file has changed due to a merge. 3 means the file was added
139 ** by a merge.
140 **
141 ** If VFILE.DELETED is true or if VFILE.RID is zero, then the file was either
142 ** removed from configuration management via "fossil rm" or added via
143 ** "fossil add", respectively, and in both cases we always know that
144 ** the file has changed without having the check the size, mtime,
145 ** or on-disk content.
146 **
147 ** If the size of the file has changed, then we always know that the file
@@ -144,15 +155,16 @@
155 **
156 ** If the mtime is used, it is used only to determine if files are the same.
157 ** If the mtime of a file has changed, we still examine the on-disk content
158 ** to see whether or not the edit was a null-edit.
159 */
160 void vfile_check_signature(int vid, unsigned int cksigFlags){
161 int nErr = 0;
162 Stmt q;
163 Blob fileCksum, origCksum;
164 int useMtime = (cksigFlags & CKSIG_SHA1)==0
165 && db_get_boolean("mtime-changes", 1);
166
167 db_begin_transaction();
168 db_prepare(&q, "SELECT id, %Q || pathname,"
169 " vfile.mrid, deleted, chnged, uuid, size, mtime"
170 " FROM vfile LEFT JOIN blob ON vfile.mrid=blob.rid"
@@ -178,11 +190,11 @@
190 currentMtime = file_wd_mtime(0);
191 if( chnged==0 && (isDeleted || rid==0) ){
192 /* "fossil rm" or "fossil add" always change the file */
193 chnged = 1;
194 }else if( !file_wd_isfile_or_link(0) && currentSize>=0 ){
195 if( cksigFlags & CKSIG_ENOTFILE ){
196 fossil_warning("not an ordinary file: %s", zName);
197 nErr++;
198 }
199 chnged = 1;
200 }
@@ -217,10 +229,19 @@
229 if( blob_compare(&fileCksum, &origCksum) ){
230 chnged = 1;
231 }
232 blob_reset(&origCksum);
233 blob_reset(&fileCksum);
234 }
235 if( (cksigFlags & CKSIG_SETMTIME) && (chnged==0 || chnged==2) ){
236 i64 desiredMtime;
237 if( mtime_of_manifest_file(vid,rid,&desiredMtime)==0 ){
238 if( currentMtime!=desiredMtime ){
239 file_set_mtime(zName, desiredMtime);
240 currentMtime = file_wd_mtime(zName);
241 }
242 }
243 }
244 if( currentMtime!=oldMtime || chnged!=oldChnged ){
245 db_multi_exec("UPDATE vfile SET mtime=%lld, chnged=%d WHERE id=%d",
246 currentMtime, chnged, id);
247 }
248

Keyboard Shortcuts

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