Skip to content

Commit c8b227c

Browse files
committed
chore: Implement handling of --ignore-older flag
1 parent 68a8598 commit c8b227c

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/lib.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,16 @@ fn diff_affects_oid(diff: &Diff, oid: &Oid, touchable_path: &mut Utf8PathBuf) ->
253253
})
254254
}
255255

256-
fn touch_if_time_mismatch(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> {
257262
let commit_time = FileTime::from_unix_time(time, 0);
258263
let metadata = fs::metadata(&path).context(IoSnafu)?;
259264
let file_mtime = FileTime::from_last_modification_time(&metadata);
260-
if file_mtime != commit_time {
265+
if file_mtime > commit_time || (!ignore_older && file_mtime < commit_time) {
261266
filetime::set_file_mtime(&path, commit_time).context(IoSnafu)?;
262267
if verbose {
263268
println!("Rewound the clock: {path}");
@@ -313,9 +318,12 @@ fn process_touchables(repo: &Repository, touchables: FileSet, opts: &Options) ->
313318
let affected = diff_affects_oid(&diff, oid, touchable_path);
314319
if affected {
315320
let time = commit.time().seconds();
316-
if let Ok(true) =
317-
touch_if_time_mismatch(touchable_path.to_path_buf(), time, opts.verbose)
318-
{
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+
) {
319327
touched
320328
.write()
321329
.unwrap()

0 commit comments

Comments
 (0)