@@ -56,6 +56,7 @@ pub struct Options {
56
56
paths : Option < FileSet > ,
57
57
dirty : bool ,
58
58
ignored : bool ,
59
+ ignore_older : bool ,
59
60
verbose : bool ,
60
61
}
61
62
@@ -74,6 +75,7 @@ impl Options {
74
75
paths : None ,
75
76
dirty : false ,
76
77
ignored : false ,
78
+ ignore_older : false ,
77
79
verbose : false ,
78
80
}
79
81
}
@@ -84,6 +86,7 @@ impl Options {
84
86
paths : self . paths . clone ( ) ,
85
87
dirty : flag,
86
88
ignored : self . ignored ,
89
+ ignore_older : self . ignore_older ,
87
90
verbose : self . verbose ,
88
91
}
89
92
}
@@ -94,6 +97,18 @@ impl Options {
94
97
paths : self . paths . clone ( ) ,
95
98
dirty : self . dirty ,
96
99
ignored : flag,
100
+ ignore_older : self . ignore_older ,
101
+ verbose : self . verbose ,
102
+ }
103
+ }
104
+
105
+ /// Whether or not to touch files older than history, default is true
106
+ pub fn ignore_older ( & self , flag : bool ) -> Options {
107
+ Options {
108
+ paths : self . paths . clone ( ) ,
109
+ dirty : self . dirty ,
110
+ ignored : self . ignored ,
111
+ ignore_older : flag,
97
112
verbose : self . verbose ,
98
113
}
99
114
}
@@ -104,6 +119,7 @@ impl Options {
104
119
paths : self . paths . clone ( ) ,
105
120
dirty : self . dirty ,
106
121
ignored : self . ignored ,
122
+ ignore_older : self . ignore_older ,
107
123
verbose : flag,
108
124
}
109
125
}
@@ -114,6 +130,7 @@ impl Options {
114
130
paths : input,
115
131
dirty : self . dirty ,
116
132
ignored : self . ignored ,
133
+ ignore_older : self . ignore_older ,
117
134
verbose : self . verbose ,
118
135
}
119
136
}
@@ -236,11 +253,16 @@ fn diff_affects_oid(diff: &Diff, oid: &Oid, touchable_path: &mut Utf8PathBuf) ->
236
253
} )
237
254
}
238
255
239
- fn touch_if_older ( path : Utf8PathBuf , time : i64 , verbose : bool ) -> Result < bool > {
256
+ fn touch_if_time_mismatch (
257
+ path : Utf8PathBuf ,
258
+ time : i64 ,
259
+ verbose : bool ,
260
+ ignore_older : bool ,
261
+ ) -> Result < bool > {
240
262
let commit_time = FileTime :: from_unix_time ( time, 0 ) ;
241
263
let metadata = fs:: metadata ( & path) . context ( IoSnafu ) ?;
242
264
let file_mtime = FileTime :: from_last_modification_time ( & metadata) ;
243
- if file_mtime != commit_time {
265
+ if file_mtime > commit_time || ( !ignore_older && file_mtime < commit_time) {
244
266
filetime:: set_file_mtime ( & path, commit_time) . context ( IoSnafu ) ?;
245
267
if verbose {
246
268
println ! ( "Rewound the clock: {path}" ) ;
@@ -296,7 +318,12 @@ fn process_touchables(repo: &Repository, touchables: FileSet, opts: &Options) ->
296
318
let affected = diff_affects_oid ( & diff, oid, touchable_path) ;
297
319
if affected {
298
320
let time = commit. time ( ) . seconds ( ) ;
299
- if let Ok ( true ) = touch_if_older ( touchable_path. to_path_buf ( ) , time, opts. verbose ) {
321
+ if let Ok ( true ) = touch_if_time_mismatch (
322
+ touchable_path. to_path_buf ( ) ,
323
+ time,
324
+ opts. verbose ,
325
+ opts. ignore_older ,
326
+ ) {
300
327
touched
301
328
. write ( )
302
329
. unwrap ( )
0 commit comments