rust/hg-core/src/dirstate_tree/status.rs
author Raphaël Gomès <rgomes@octobus.net>
Tue, 05 Apr 2022 10:55:28 +0200
branchstable
changeset 49000 dd6b67d5c256
parent 48973 e2f8ed37201c
child 49127 f3e8b0b0a8c2
child 49337 6cd249556e20
permissions -rw-r--r--
rust: fix unsound `OwningDirstateMap` As per the previous patch, `OwningDirstateMap` is unsound. Self-referential structs are difficult to implement correctly in Rust since the compiler is free to move structs around as much as it wants to. They are also very rarely needed in practice, so the state-of-the-art on how they should be done within the Rust rules is still a bit new. The crate `ouroboros` is an attempt at providing a safe way (in the Rust sense) of declaring self-referential structs. It is getting a lot attention and was improved very quickly when soundness issues were found in the past: rather than relying on our own (limited) review circle, we might as well use the de-facto common crate to fix this problem. This will give us a much better chance of finding issues should any new ones be discovered as well as the benefit of fewer `unsafe` APIs of our own. I was starting to think about how I would present a safe API to the old struct but soon realized that the callback-based approach was already done in `ouroboros`, along with a lot more care towards refusing incorrect structs. In short: we don't return a mutable reference to the `DirstateMap` anymore, we expect users of its API to pass a `FnOnce` that takes the map as an argument. This allows our `OwningDirstateMap` to control the input and output lifetimes of the code that modifies it to prevent such issues. Changing to `ouroboros` meant changing every API with it, but it is relatively low churn in the end. It correctly identified the example buggy modification of `copy_map_insert` outlined in the previous patch as violating the borrow rules. Differential Revision: https://phab.mercurial-scm.org/D12429
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48193
320de901896a dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents: 48192
diff changeset
     1
use crate::dirstate::entry::TruncatedTimestamp;
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
     2
use crate::dirstate::status::IgnoreFnType;
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
     3
use crate::dirstate::status::StatusPath;
47347
73ddcedeaadf dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47346
diff changeset
     4
use crate::dirstate_tree::dirstate_map::BorrowedPath;
47333
69530e5d4fe5 dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents: 47331
diff changeset
     5
use crate::dirstate_tree::dirstate_map::ChildNodesRef;
47112
d5956136d19d dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
     6
use crate::dirstate_tree::dirstate_map::DirstateMap;
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
     7
use crate::dirstate_tree::dirstate_map::NodeData;
47333
69530e5d4fe5 dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents: 47331
diff changeset
     8
use crate::dirstate_tree::dirstate_map::NodeRef;
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
     9
use crate::dirstate_tree::on_disk::DirstateV2ParseError;
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    10
use crate::matchers::get_ignore_function;
47112
d5956136d19d dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    11
use crate::matchers::Matcher;
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    12
use crate::utils::files::get_bytes_from_os_string;
47338
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
    13
use crate::utils::files::get_path_from_bytes;
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    14
use crate::utils::hg_path::HgPath;
47115
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
    15
use crate::BadMatch;
47112
d5956136d19d dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    16
use crate::DirstateStatus;
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    17
use crate::EntryState;
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    18
use crate::HgPathBuf;
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
    19
use crate::HgPathCow;
47112
d5956136d19d dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    20
use crate::PatternFileWarning;
d5956136d19d dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    21
use crate::StatusError;
d5956136d19d dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    22
use crate::StatusOptions;
47118
c92e63762573 dirstate-tree: Add #[timed] attribute to `status` and `DirstateMap::read`
Simon Sapin <simon.sapin@octobus.net>
parents: 47117
diff changeset
    23
use micro_timer::timed;
47117
60d852ae7e7b dirstate-tree: Paralellize the status algorithm with Rayon
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
    24
use rayon::prelude::*;
47409
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
    25
use sha1::{Digest, Sha1};
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
    26
use std::borrow::Cow;
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    27
use std::io;
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    28
use std::path::Path;
47112
d5956136d19d dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    29
use std::path::PathBuf;
47117
60d852ae7e7b dirstate-tree: Paralellize the status algorithm with Rayon
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
    30
use std::sync::Mutex;
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
    31
use std::time::SystemTime;
47112
d5956136d19d dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
    32
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    33
/// Returns the status of the working directory compared to its parent
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    34
/// changeset.
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    35
///
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    36
/// This algorithm is based on traversing the filesystem tree (`fs` in function
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    37
/// and variable names) and dirstate tree at the same time. The core of this
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    38
/// traversal is the recursive `traverse_fs_directory_and_dirstate` function
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    39
/// and its use of `itertools::merge_join_by`. When reaching a path that only
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    40
/// exists in one of the two trees, depending on information requested by
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    41
/// `options` we may need to traverse the remaining subtree.
47118
c92e63762573 dirstate-tree: Add #[timed] attribute to `status` and `DirstateMap::read`
Simon Sapin <simon.sapin@octobus.net>
parents: 47117
diff changeset
    42
#[timed]
49000
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48973
diff changeset
    43
pub fn status<'dirstate>(
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48973
diff changeset
    44
    dmap: &'dirstate mut DirstateMap,
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    45
    matcher: &(dyn Matcher + Sync),
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    46
    root_dir: PathBuf,
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    47
    ignore_files: Vec<PathBuf>,
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    48
    options: StatusOptions,
49000
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48973
diff changeset
    49
) -> Result<(DirstateStatus<'dirstate>, Vec<PatternFileWarning>), StatusError>
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48973
diff changeset
    50
{
48973
e2f8ed37201c rust-status: cap the number of concurrent threads to 16
Raphaël Gomès <rgomes@octobus.net>
parents: 48794
diff changeset
    51
    // Force the global rayon threadpool to not exceed 16 concurrent threads.
e2f8ed37201c rust-status: cap the number of concurrent threads to 16
Raphaël Gomès <rgomes@octobus.net>
parents: 48794
diff changeset
    52
    // This is a stop-gap measure until we figure out why using more than 16
e2f8ed37201c rust-status: cap the number of concurrent threads to 16
Raphaël Gomès <rgomes@octobus.net>
parents: 48794
diff changeset
    53
    // threads makes `status` slower for each additional thread.
e2f8ed37201c rust-status: cap the number of concurrent threads to 16
Raphaël Gomès <rgomes@octobus.net>
parents: 48794
diff changeset
    54
    // We use `ok()` in case the global threadpool has already been
e2f8ed37201c rust-status: cap the number of concurrent threads to 16
Raphaël Gomès <rgomes@octobus.net>
parents: 48794
diff changeset
    55
    // instantiated in `rhg` or some other caller.
e2f8ed37201c rust-status: cap the number of concurrent threads to 16
Raphaël Gomès <rgomes@octobus.net>
parents: 48794
diff changeset
    56
    // TODO find the underlying cause and fix it, then remove this.
e2f8ed37201c rust-status: cap the number of concurrent threads to 16
Raphaël Gomès <rgomes@octobus.net>
parents: 48794
diff changeset
    57
    rayon::ThreadPoolBuilder::new()
e2f8ed37201c rust-status: cap the number of concurrent threads to 16
Raphaël Gomès <rgomes@octobus.net>
parents: 48794
diff changeset
    58
        .num_threads(16)
e2f8ed37201c rust-status: cap the number of concurrent threads to 16
Raphaël Gomès <rgomes@octobus.net>
parents: 48794
diff changeset
    59
        .build_global()
e2f8ed37201c rust-status: cap the number of concurrent threads to 16
Raphaël Gomès <rgomes@octobus.net>
parents: 48794
diff changeset
    60
        .ok();
e2f8ed37201c rust-status: cap the number of concurrent threads to 16
Raphaël Gomès <rgomes@octobus.net>
parents: 48794
diff changeset
    61
47409
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
    62
    let (ignore_fn, warnings, patterns_changed): (IgnoreFnType, _, _) =
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    63
        if options.list_ignored || options.list_unknown {
47409
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
    64
            let mut hasher = Sha1::new();
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
    65
            let (ignore_fn, warnings) = get_ignore_function(
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
    66
                ignore_files,
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
    67
                &root_dir,
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
    68
                &mut |pattern_bytes| hasher.update(pattern_bytes),
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
    69
            )?;
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
    70
            let new_hash = *hasher.finalize().as_ref();
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
    71
            let changed = new_hash != dmap.ignore_patterns_hash;
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
    72
            dmap.ignore_patterns_hash = new_hash;
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
    73
            (ignore_fn, warnings, Some(changed))
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    74
        } else {
47409
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
    75
            (Box::new(|&_| true), vec![], None)
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    76
        };
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
    77
48501
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
    78
    let filesystem_time_at_status_start =
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
    79
        filesystem_now(&root_dir).ok().map(TruncatedTimestamp::from);
48745
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
    80
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
    81
    // If the repository is under the current directory, prefer using a
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
    82
    // relative path, so the kernel needs to traverse fewer directory in every
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
    83
    // call to `read_dir` or `symlink_metadata`.
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
    84
    // This is effective in the common case where the current directory is the
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
    85
    // repository root.
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
    86
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
    87
    // TODO: Better yet would be to use libc functions like `openat` and
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
    88
    // `fstatat` to remove such repeated traversals entirely, but the standard
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
    89
    // library does not provide APIs based on those.
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
    90
    // Maybe with a crate like https://crates.io/crates/openat instead?
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
    91
    let root_dir = if let Some(relative) = std::env::current_dir()
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
    92
        .ok()
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
    93
        .and_then(|cwd| root_dir.strip_prefix(cwd).ok())
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
    94
    {
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
    95
        relative
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
    96
    } else {
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
    97
        &root_dir
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
    98
    };
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
    99
48422
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48391
diff changeset
   100
    let outcome = DirstateStatus {
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48391
diff changeset
   101
        filesystem_time_at_status_start,
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48391
diff changeset
   102
        ..Default::default()
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48391
diff changeset
   103
    };
47117
60d852ae7e7b dirstate-tree: Paralellize the status algorithm with Rayon
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   104
    let common = StatusCommon {
47336
8d0260d0dbc9 dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents: 47335
diff changeset
   105
        dmap,
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   106
        options,
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   107
        matcher,
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   108
        ignore_fn,
48422
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48391
diff changeset
   109
        outcome: Mutex::new(outcome),
47409
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
   110
        ignore_patterns_have_changed: patterns_changed,
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
   111
        new_cachable_directories: Default::default(),
47474
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   112
        outated_cached_directories: Default::default(),
48422
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48391
diff changeset
   113
        filesystem_time_at_status_start,
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   114
    };
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   115
    let is_at_repo_root = true;
47347
73ddcedeaadf dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47346
diff changeset
   116
    let hg_path = &BorrowedPath::OnDisk(HgPath::new(""));
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   117
    let has_ignored_ancestor = false;
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   118
    let root_cached_mtime = None;
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   119
    let root_dir_metadata = None;
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   120
    // If the path we have for the repository root is a symlink, do follow it.
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   121
    // (As opposed to symlinks within the working directory which are not
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   122
    // followed, using `std::fs::symlink_metadata`.)
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   123
    common.traverse_fs_directory_and_dirstate(
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   124
        has_ignored_ancestor,
47333
69530e5d4fe5 dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents: 47331
diff changeset
   125
        dmap.root.as_ref(),
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   126
        hg_path,
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   127
        &root_dir,
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   128
        root_dir_metadata,
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   129
        root_cached_mtime,
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   130
        is_at_repo_root,
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
   131
    )?;
47350
04d1f17f49e7 dirstate-v2: Write .hg/dirstate back to disk on directory cache changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47349
diff changeset
   132
    let mut outcome = common.outcome.into_inner().unwrap();
47409
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
   133
    let new_cachable = common.new_cachable_directories.into_inner().unwrap();
47474
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   134
    let outdated = common.outated_cached_directories.into_inner().unwrap();
47409
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
   135
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
   136
    outcome.dirty = common.ignore_patterns_have_changed == Some(true)
47474
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   137
        || !outdated.is_empty()
47409
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
   138
        || !new_cachable.is_empty();
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
   139
47474
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   140
    // Remove outdated mtimes before adding new mtimes, in case a given
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   141
    // directory is both
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   142
    for path in &outdated {
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   143
        let node = dmap.get_or_insert(path)?;
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   144
        if let NodeData::CachedDirectory { .. } = &node.data {
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   145
            node.data = NodeData::None
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   146
        }
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   147
    }
47409
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
   148
    for (path, mtime) in &new_cachable {
47474
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   149
        let node = dmap.get_or_insert(path)?;
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   150
        match &node.data {
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   151
            NodeData::Entry(_) => {} // Don’t overwrite an entry
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   152
            NodeData::CachedDirectory { .. } | NodeData::None => {
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   153
                node.data = NodeData::CachedDirectory { mtime: *mtime }
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   154
            }
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   155
        }
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   156
    }
47409
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
   157
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   158
    Ok((outcome, warnings))
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   159
}
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   160
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   161
/// Bag of random things needed by various parts of the algorithm. Reduces the
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   162
/// number of parameters passed to functions.
47347
73ddcedeaadf dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47346
diff changeset
   163
struct StatusCommon<'a, 'tree, 'on_disk: 'tree> {
47336
8d0260d0dbc9 dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents: 47335
diff changeset
   164
    dmap: &'tree DirstateMap<'on_disk>,
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   165
    options: StatusOptions,
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   166
    matcher: &'a (dyn Matcher + Sync),
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   167
    ignore_fn: IgnoreFnType<'a>,
47347
73ddcedeaadf dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47346
diff changeset
   168
    outcome: Mutex<DirstateStatus<'on_disk>>,
48193
320de901896a dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents: 48192
diff changeset
   169
    new_cachable_directories:
320de901896a dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents: 48192
diff changeset
   170
        Mutex<Vec<(Cow<'on_disk, HgPath>, TruncatedTimestamp)>>,
47474
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   171
    outated_cached_directories: Mutex<Vec<Cow<'on_disk, HgPath>>>,
47409
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
   172
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
   173
    /// Whether ignore files like `.hgignore` have changed since the previous
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
   174
    /// time a `status()` call wrote their hash to the dirstate. `None` means
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
   175
    /// we don’t know as this run doesn’t list either ignored or uknown files
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
   176
    /// and therefore isn’t reading `.hgignore`.
0ef8231e413f dirstate-v2: Store a hash of ignore patterns (.hgignore)
Simon Sapin <simon.sapin@octobus.net>
parents: 47350
diff changeset
   177
    ignore_patterns_have_changed: Option<bool>,
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   178
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   179
    /// The current time at the start of the `status()` algorithm, as measured
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   180
    /// and possibly truncated by the filesystem.
48501
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   181
    filesystem_time_at_status_start: Option<TruncatedTimestamp>,
47112
d5956136d19d dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   182
}
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   183
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   184
enum Outcome {
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   185
    Modified,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   186
    Added,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   187
    Removed,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   188
    Deleted,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   189
    Clean,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   190
    Ignored,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   191
    Unknown,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   192
    Unsure,
47112
d5956136d19d dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents:
diff changeset
   193
}
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   194
47347
73ddcedeaadf dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47346
diff changeset
   195
impl<'a, 'tree, 'on_disk> StatusCommon<'a, 'tree, 'on_disk> {
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   196
    fn push_outcome(
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   197
        &self,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   198
        which: Outcome,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   199
        dirstate_node: &NodeRef<'tree, 'on_disk>,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   200
    ) -> Result<(), DirstateV2ParseError> {
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   201
        let path = dirstate_node
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   202
            .full_path_borrowed(self.dmap.on_disk)?
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   203
            .detach_from_tree();
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   204
        let copy_source = if self.options.list_copies {
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   205
            dirstate_node
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   206
                .copy_source_borrowed(self.dmap.on_disk)?
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   207
                .map(|source| source.detach_from_tree())
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   208
        } else {
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   209
            None
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   210
        };
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   211
        self.push_outcome_common(which, path, copy_source);
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   212
        Ok(())
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   213
    }
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   214
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   215
    fn push_outcome_without_copy_source(
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   216
        &self,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   217
        which: Outcome,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   218
        path: &BorrowedPath<'_, 'on_disk>,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   219
    ) {
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   220
        self.push_outcome_common(which, path.detach_from_tree(), None)
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   221
    }
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   222
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   223
    fn push_outcome_common(
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   224
        &self,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   225
        which: Outcome,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   226
        path: HgPathCow<'on_disk>,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   227
        copy_source: Option<HgPathCow<'on_disk>>,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   228
    ) {
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   229
        let mut outcome = self.outcome.lock().unwrap();
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   230
        let vec = match which {
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   231
            Outcome::Modified => &mut outcome.modified,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   232
            Outcome::Added => &mut outcome.added,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   233
            Outcome::Removed => &mut outcome.removed,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   234
            Outcome::Deleted => &mut outcome.deleted,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   235
            Outcome::Clean => &mut outcome.clean,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   236
            Outcome::Ignored => &mut outcome.ignored,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   237
            Outcome::Unknown => &mut outcome.unknown,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   238
            Outcome::Unsure => &mut outcome.unsure,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   239
        };
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   240
        vec.push(StatusPath { path, copy_source });
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   241
    }
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   242
47115
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   243
    fn read_dir(
47117
60d852ae7e7b dirstate-tree: Paralellize the status algorithm with Rayon
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   244
        &self,
47115
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   245
        hg_path: &HgPath,
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   246
        fs_path: &Path,
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   247
        is_at_repo_root: bool,
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   248
    ) -> Result<Vec<DirEntry>, ()> {
47338
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   249
        DirEntry::read_dir(fs_path, is_at_repo_root)
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   250
            .map_err(|error| self.io_error(error, hg_path))
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   251
    }
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   252
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   253
    fn io_error(&self, error: std::io::Error, hg_path: &HgPath) {
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   254
        let errno = error.raw_os_error().expect("expected real OS error");
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   255
        self.outcome
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   256
            .lock()
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   257
            .unwrap()
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   258
            .bad
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   259
            .push((hg_path.to_owned().into(), BadMatch::OsError(errno)))
47115
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   260
    }
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   261
47474
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   262
    fn check_for_outdated_directory_cache(
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   263
        &self,
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   264
        dirstate_node: &NodeRef<'tree, 'on_disk>,
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   265
    ) -> Result<(), DirstateV2ParseError> {
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   266
        if self.ignore_patterns_have_changed == Some(true)
48193
320de901896a dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents: 48192
diff changeset
   267
            && dirstate_node.cached_directory_mtime()?.is_some()
47474
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   268
        {
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   269
            self.outated_cached_directories.lock().unwrap().push(
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   270
                dirstate_node
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   271
                    .full_path_borrowed(self.dmap.on_disk)?
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   272
                    .detach_from_tree(),
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   273
            )
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   274
        }
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   275
        Ok(())
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   276
    }
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   277
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   278
    /// If this returns true, we can get accurate results by only using
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   279
    /// `symlink_metadata` for child nodes that exist in the dirstate and don’t
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   280
    /// need to call `read_dir`.
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   281
    fn can_skip_fs_readdir(
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   282
        &self,
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   283
        directory_metadata: Option<&std::fs::Metadata>,
48193
320de901896a dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents: 48192
diff changeset
   284
        cached_directory_mtime: Option<TruncatedTimestamp>,
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   285
    ) -> bool {
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   286
        if !self.options.list_unknown && !self.options.list_ignored {
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   287
            // All states that we care about listing have corresponding
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   288
            // dirstate entries.
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   289
            // This happens for example with `hg status -mard`.
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   290
            return true;
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   291
        }
47475
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   292
        if !self.options.list_ignored
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   293
            && self.ignore_patterns_have_changed == Some(false)
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   294
        {
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   295
            if let Some(cached_mtime) = cached_directory_mtime {
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   296
                // The dirstate contains a cached mtime for this directory, set
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   297
                // by a previous run of the `status` algorithm which found this
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   298
                // directory eligible for `read_dir` caching.
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   299
                if let Some(meta) = directory_metadata {
48218
15dedc0c5c35 status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents: 48193
diff changeset
   300
                    if cached_mtime
48257
f45d35950db6 dirstate: rename a `very_likely_equal` method to `likely_equal`
Simon Sapin <simon.sapin@octobus.net>
parents: 48218
diff changeset
   301
                        .likely_equal_to_mtime_of(meta)
48218
15dedc0c5c35 status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents: 48193
diff changeset
   302
                        .unwrap_or(false)
15dedc0c5c35 status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents: 48193
diff changeset
   303
                    {
15dedc0c5c35 status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents: 48193
diff changeset
   304
                        // The mtime of that directory has not changed
15dedc0c5c35 status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents: 48193
diff changeset
   305
                        // since then, which means that the results of
15dedc0c5c35 status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents: 48193
diff changeset
   306
                        // `read_dir` should also be unchanged.
15dedc0c5c35 status: Extract TruncatedTimestamp from fs::Metadata without SystemTime
Simon Sapin <simon.sapin@octobus.net>
parents: 48193
diff changeset
   307
                        return true;
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   308
                    }
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   309
                }
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   310
            }
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   311
        }
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   312
        false
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   313
    }
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   314
47475
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   315
    /// Returns whether all child entries of the filesystem directory have a
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   316
    /// corresponding dirstate node or are ignored.
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   317
    fn traverse_fs_directory_and_dirstate(
47117
60d852ae7e7b dirstate-tree: Paralellize the status algorithm with Rayon
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   318
        &self,
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   319
        has_ignored_ancestor: bool,
47347
73ddcedeaadf dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47346
diff changeset
   320
        dirstate_nodes: ChildNodesRef<'tree, 'on_disk>,
73ddcedeaadf dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47346
diff changeset
   321
        directory_hg_path: &BorrowedPath<'tree, 'on_disk>,
47115
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   322
        directory_fs_path: &Path,
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   323
        directory_metadata: Option<&std::fs::Metadata>,
48193
320de901896a dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents: 48192
diff changeset
   324
        cached_directory_mtime: Option<TruncatedTimestamp>,
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   325
        is_at_repo_root: bool,
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   326
    ) -> Result<bool, DirstateV2ParseError> {
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   327
        if self.can_skip_fs_readdir(directory_metadata, cached_directory_mtime)
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   328
        {
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   329
            dirstate_nodes
47338
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   330
                .par_iter()
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   331
                .map(|dirstate_node| {
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   332
                    let fs_path = directory_fs_path.join(get_path_from_bytes(
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   333
                        dirstate_node.base_name(self.dmap.on_disk)?.as_bytes(),
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   334
                    ));
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   335
                    match std::fs::symlink_metadata(&fs_path) {
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   336
                        Ok(fs_metadata) => self.traverse_fs_and_dirstate(
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   337
                            &fs_path,
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   338
                            &fs_metadata,
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   339
                            dirstate_node,
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   340
                            has_ignored_ancestor,
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   341
                        ),
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   342
                        Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   343
                            self.traverse_dirstate_only(dirstate_node)
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   344
                        }
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   345
                        Err(error) => {
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   346
                            let hg_path =
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   347
                                dirstate_node.full_path(self.dmap.on_disk)?;
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   348
                            Ok(self.io_error(error, hg_path))
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   349
                        }
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   350
                    }
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   351
                })
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   352
                .collect::<Result<_, _>>()?;
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   353
47475
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   354
            // We don’t know, so conservatively say this isn’t the case
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   355
            let children_all_have_dirstate_node_or_are_ignored = false;
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   356
47475
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   357
            return Ok(children_all_have_dirstate_node_or_are_ignored);
47338
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   358
        }
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   359
47115
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   360
        let mut fs_entries = if let Ok(entries) = self.read_dir(
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   361
            directory_hg_path,
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   362
            directory_fs_path,
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   363
            is_at_repo_root,
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   364
        ) {
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   365
            entries
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   366
        } else {
47346
5e12b6bfdd3e dirstate-tree: Fix status algorithm with unreadable directory
Simon Sapin <simon.sapin@octobus.net>
parents: 47338
diff changeset
   367
            // Treat an unreadable directory (typically because of insufficient
5e12b6bfdd3e dirstate-tree: Fix status algorithm with unreadable directory
Simon Sapin <simon.sapin@octobus.net>
parents: 47338
diff changeset
   368
            // permissions) like an empty directory. `self.read_dir` has
5e12b6bfdd3e dirstate-tree: Fix status algorithm with unreadable directory
Simon Sapin <simon.sapin@octobus.net>
parents: 47338
diff changeset
   369
            // already called `self.io_error` so a warning will be emitted.
5e12b6bfdd3e dirstate-tree: Fix status algorithm with unreadable directory
Simon Sapin <simon.sapin@octobus.net>
parents: 47338
diff changeset
   370
            Vec::new()
47115
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   371
        };
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   372
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   373
        // `merge_join_by` requires both its input iterators to be sorted:
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   374
47333
69530e5d4fe5 dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents: 47331
diff changeset
   375
        let dirstate_nodes = dirstate_nodes.sorted();
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   376
        // `sort_unstable_by_key` doesn’t allow keys borrowing from the value:
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   377
        // https://github.com/rust-lang/rust/issues/34162
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   378
        fs_entries.sort_unstable_by(|e1, e2| e1.base_name.cmp(&e2.base_name));
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   379
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
   380
        // Propagate here any error that would happen inside the comparison
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
   381
        // callback below
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
   382
        for dirstate_node in &dirstate_nodes {
47336
8d0260d0dbc9 dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents: 47335
diff changeset
   383
            dirstate_node.base_name(self.dmap.on_disk)?;
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
   384
        }
47117
60d852ae7e7b dirstate-tree: Paralellize the status algorithm with Rayon
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   385
        itertools::merge_join_by(
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   386
            dirstate_nodes,
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   387
            &fs_entries,
47333
69530e5d4fe5 dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents: 47331
diff changeset
   388
            |dirstate_node, fs_entry| {
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
   389
                // This `unwrap` never panics because we already propagated
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
   390
                // those errors above
47336
8d0260d0dbc9 dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents: 47335
diff changeset
   391
                dirstate_node
8d0260d0dbc9 dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents: 47335
diff changeset
   392
                    .base_name(self.dmap.on_disk)
8d0260d0dbc9 dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents: 47335
diff changeset
   393
                    .unwrap()
8d0260d0dbc9 dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents: 47335
diff changeset
   394
                    .cmp(&fs_entry.base_name)
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   395
            },
47117
60d852ae7e7b dirstate-tree: Paralellize the status algorithm with Rayon
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   396
        )
60d852ae7e7b dirstate-tree: Paralellize the status algorithm with Rayon
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   397
        .par_bridge()
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
   398
        .map(|pair| {
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   399
            use itertools::EitherOrBoth::*;
47475
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   400
            let has_dirstate_node_or_is_ignored;
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   401
            match pair {
47475
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   402
                Both(dirstate_node, fs_entry) => {
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   403
                    self.traverse_fs_and_dirstate(
47338
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   404
                        &fs_entry.full_path,
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   405
                        &fs_entry.metadata,
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   406
                        dirstate_node,
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   407
                        has_ignored_ancestor,
47475
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   408
                    )?;
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   409
                    has_dirstate_node_or_is_ignored = true
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   410
                }
47333
69530e5d4fe5 dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents: 47331
diff changeset
   411
                Left(dirstate_node) => {
47475
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   412
                    self.traverse_dirstate_only(dirstate_node)?;
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   413
                    has_dirstate_node_or_is_ignored = true;
47333
69530e5d4fe5 dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents: 47331
diff changeset
   414
                }
47475
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   415
                Right(fs_entry) => {
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   416
                    has_dirstate_node_or_is_ignored = self.traverse_fs_only(
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   417
                        has_ignored_ancestor,
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   418
                        directory_hg_path,
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   419
                        fs_entry,
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   420
                    )
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   421
                }
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   422
            }
47475
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   423
            Ok(has_dirstate_node_or_is_ignored)
47117
60d852ae7e7b dirstate-tree: Paralellize the status algorithm with Rayon
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   424
        })
47475
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   425
        .try_reduce(|| true, |a, b| Ok(a && b))
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   426
    }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   427
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   428
    fn traverse_fs_and_dirstate(
47117
60d852ae7e7b dirstate-tree: Paralellize the status algorithm with Rayon
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   429
        &self,
47338
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   430
        fs_path: &Path,
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   431
        fs_metadata: &std::fs::Metadata,
47347
73ddcedeaadf dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47346
diff changeset
   432
        dirstate_node: NodeRef<'tree, 'on_disk>,
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   433
        has_ignored_ancestor: bool,
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
   434
    ) -> Result<(), DirstateV2ParseError> {
47474
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   435
        self.check_for_outdated_directory_cache(&dirstate_node)?;
47347
73ddcedeaadf dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47346
diff changeset
   436
        let hg_path = &dirstate_node.full_path_borrowed(self.dmap.on_disk)?;
47338
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   437
        let file_type = fs_metadata.file_type();
47114
aeb03758f37a dirstate-tree: Ignore FIFOs etc. in the status algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47113
diff changeset
   438
        let file_or_symlink = file_type.is_file() || file_type.is_symlink();
aeb03758f37a dirstate-tree: Ignore FIFOs etc. in the status algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47113
diff changeset
   439
        if !file_or_symlink {
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   440
            // If we previously had a file here, it was removed (with
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   441
            // `hg rm` or similar) or deleted before it could be
47114
aeb03758f37a dirstate-tree: Ignore FIFOs etc. in the status algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47113
diff changeset
   442
            // replaced by a directory or something else.
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   443
            self.mark_removed_or_deleted_if_file(&dirstate_node)?;
47114
aeb03758f37a dirstate-tree: Ignore FIFOs etc. in the status algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47113
diff changeset
   444
        }
aeb03758f37a dirstate-tree: Ignore FIFOs etc. in the status algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47113
diff changeset
   445
        if file_type.is_dir() {
aeb03758f37a dirstate-tree: Ignore FIFOs etc. in the status algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47113
diff changeset
   446
            if self.options.collect_traversed_dirs {
47347
73ddcedeaadf dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47346
diff changeset
   447
                self.outcome
73ddcedeaadf dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47346
diff changeset
   448
                    .lock()
73ddcedeaadf dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47346
diff changeset
   449
                    .unwrap()
73ddcedeaadf dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47346
diff changeset
   450
                    .traversed
73ddcedeaadf dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47346
diff changeset
   451
                    .push(hg_path.detach_from_tree())
47114
aeb03758f37a dirstate-tree: Ignore FIFOs etc. in the status algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47113
diff changeset
   452
            }
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   453
            let is_ignored = has_ignored_ancestor || (self.ignore_fn)(hg_path);
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   454
            let is_at_repo_root = false;
47475
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   455
            let children_all_have_dirstate_node_or_are_ignored = self
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   456
                .traverse_fs_directory_and_dirstate(
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   457
                    is_ignored,
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   458
                    dirstate_node.children(self.dmap.on_disk)?,
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   459
                    hg_path,
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   460
                    fs_path,
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   461
                    Some(fs_metadata),
48193
320de901896a dirstate-v2: Truncate directory mtimes to 31 bits of seconds
Simon Sapin <simon.sapin@octobus.net>
parents: 48192
diff changeset
   462
                    dirstate_node.cached_directory_mtime()?,
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   463
                    is_at_repo_root,
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   464
                )?;
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   465
            self.maybe_save_directory_mtime(
47475
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   466
                children_all_have_dirstate_node_or_are_ignored,
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   467
                fs_metadata,
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   468
                dirstate_node,
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
   469
            )?
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   470
        } else {
47114
aeb03758f37a dirstate-tree: Ignore FIFOs etc. in the status algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47113
diff changeset
   471
            if file_or_symlink && self.matcher.matches(hg_path) {
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
   472
                if let Some(state) = dirstate_node.state()? {
47333
69530e5d4fe5 dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents: 47331
diff changeset
   473
                    match state {
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   474
                        EntryState::Added => {
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   475
                            self.push_outcome(Outcome::Added, &dirstate_node)?
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   476
                        }
47117
60d852ae7e7b dirstate-tree: Paralellize the status algorithm with Rayon
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   477
                        EntryState::Removed => self
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   478
                            .push_outcome(Outcome::Removed, &dirstate_node)?,
47117
60d852ae7e7b dirstate-tree: Paralellize the status algorithm with Rayon
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   479
                        EntryState::Merged => self
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   480
                            .push_outcome(Outcome::Modified, &dirstate_node)?,
47338
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   481
                        EntryState::Normal => self
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   482
                            .handle_normal_file(&dirstate_node, fs_metadata)?,
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   483
                    }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   484
                } else {
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   485
                    // `node.entry.is_none()` indicates a "directory"
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   486
                    // node, but the filesystem has a file
47475
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   487
                    self.mark_unknown_or_ignored(
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   488
                        has_ignored_ancestor,
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   489
                        hg_path,
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   490
                    );
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   491
                }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   492
            }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   493
47336
8d0260d0dbc9 dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents: 47335
diff changeset
   494
            for child_node in dirstate_node.children(self.dmap.on_disk)?.iter()
8d0260d0dbc9 dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents: 47335
diff changeset
   495
            {
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
   496
                self.traverse_dirstate_only(child_node)?
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   497
            }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   498
        }
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
   499
        Ok(())
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   500
    }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   501
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   502
    fn maybe_save_directory_mtime(
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   503
        &self,
47475
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   504
        children_all_have_dirstate_node_or_are_ignored: bool,
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   505
        directory_metadata: &std::fs::Metadata,
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   506
        dirstate_node: NodeRef<'tree, 'on_disk>,
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   507
    ) -> Result<(), DirstateV2ParseError> {
48501
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   508
        if !children_all_have_dirstate_node_or_are_ignored {
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   509
            return Ok(());
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   510
        }
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   511
        // All filesystem directory entries from `read_dir` have a
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   512
        // corresponding node in the dirstate, so we can reconstitute the
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   513
        // names of those entries without calling `read_dir` again.
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   514
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   515
        // TODO: use let-else here and below when available:
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   516
        // https://github.com/rust-lang/rust/issues/87335
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   517
        let status_start = if let Some(status_start) =
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   518
            &self.filesystem_time_at_status_start
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   519
        {
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   520
            status_start
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   521
        } else {
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   522
            return Ok(());
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   523
        };
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   524
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   525
        // Although the Rust standard library’s `SystemTime` type
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   526
        // has nanosecond precision, the times reported for a
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   527
        // directory’s (or file’s) modified time may have lower
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   528
        // resolution based on the filesystem (for example ext3
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   529
        // only stores integer seconds), kernel (see
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   530
        // https://stackoverflow.com/a/14393315/1162888), etc.
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   531
        let directory_mtime = if let Ok(option) =
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   532
            TruncatedTimestamp::for_reliable_mtime_of(
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   533
                directory_metadata,
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   534
                status_start,
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   535
            ) {
48501
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   536
            if let Some(directory_mtime) = option {
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   537
                directory_mtime
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   538
            } else {
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   539
                // The directory was modified too recently,
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   540
                // don’t cache its `read_dir` results.
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   541
                //
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   542
                // 1. A change to this directory (direct child was
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   543
                //    added or removed) cause its mtime to be set
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   544
                //    (possibly truncated) to `directory_mtime`
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   545
                // 2. This `status` algorithm calls `read_dir`
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   546
                // 3. An other change is made to the same directory is
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   547
                //    made so that calling `read_dir` agin would give
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   548
                //    different results, but soon enough after 1. that
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   549
                //    the mtime stays the same
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   550
                //
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   551
                // On a system where the time resolution poor, this
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   552
                // scenario is not unlikely if all three steps are caused
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   553
                // by the same script.
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   554
                return Ok(());
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   555
            }
48501
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   556
        } else {
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   557
            // OS/libc does not support mtime?
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   558
            return Ok(());
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   559
        };
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   560
        // We’ve observed (through `status_start`) that time has
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   561
        // “progressed” since `directory_mtime`, so any further
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   562
        // change to this directory is extremely likely to cause a
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   563
        // different mtime.
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   564
        //
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   565
        // Having the same mtime again is not entirely impossible
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   566
        // since the system clock is not monotonous. It could jump
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   567
        // backward to some point before `directory_mtime`, then a
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   568
        // directory change could potentially happen during exactly
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   569
        // the wrong tick.
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   570
        //
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   571
        // We deem this scenario (unlike the previous one) to be
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   572
        // unlikely enough in practice.
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   573
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   574
        let is_up_to_date =
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   575
            if let Some(cached) = dirstate_node.cached_directory_mtime()? {
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   576
                cached.likely_equal(directory_mtime)
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   577
            } else {
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   578
                false
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   579
            };
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   580
        if !is_up_to_date {
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   581
            let hg_path = dirstate_node
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   582
                .full_path_borrowed(self.dmap.on_disk)?
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   583
                .detach_from_tree();
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   584
            self.new_cachable_directories
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   585
                .lock()
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   586
                .unwrap()
4afb9627dc77 dirstate-v2: Apply SECOND_AMBIGUOUS to directory mtimes too
Simon Sapin <simon.sapin@octobus.net>
parents: 48454
diff changeset
   587
                .push((hg_path, directory_mtime))
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   588
        }
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   589
        Ok(())
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   590
    }
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   591
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   592
    /// A file with `EntryState::Normal` in the dirstate was found in the
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   593
    /// filesystem
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   594
    fn handle_normal_file(
47117
60d852ae7e7b dirstate-tree: Paralellize the status algorithm with Rayon
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   595
        &self,
47347
73ddcedeaadf dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47346
diff changeset
   596
        dirstate_node: &NodeRef<'tree, 'on_disk>,
47338
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   597
        fs_metadata: &std::fs::Metadata,
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
   598
    ) -> Result<(), DirstateV2ParseError> {
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   599
        // Keep the low 31 bits
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   600
        fn truncate_u64(value: u64) -> i32 {
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   601
            (value & 0x7FFF_FFFF) as i32
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   602
        }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   603
47333
69530e5d4fe5 dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents: 47331
diff changeset
   604
        let entry = dirstate_node
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
   605
            .entry()?
47333
69530e5d4fe5 dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents: 47331
diff changeset
   606
            .expect("handle_normal_file called with entry-less node");
47338
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   607
        let mode_changed =
f27f2afb15da dirstate-tree: Skip readdir() in `hg status -mard`
Simon Sapin <simon.sapin@octobus.net>
parents: 47336
diff changeset
   608
            || self.options.check_exec && entry.mode_changed(fs_metadata);
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47475
diff changeset
   609
        let size = entry.size();
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47475
diff changeset
   610
        let size_changed = size != truncate_u64(fs_metadata.len());
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47475
diff changeset
   611
        if size >= 0 && size_changed && fs_metadata.file_type().is_symlink() {
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   612
            // issue6456: Size returned may be longer due to encryption
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   613
            // on EXT-4 fscrypt. TODO maybe only do it on EXT4?
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   614
            self.push_outcome(Outcome::Unsure, dirstate_node)?
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
   615
        } else if dirstate_node.has_copy_source()
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   616
            || entry.is_from_other_parent()
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47475
diff changeset
   617
            || (size >= 0 && (size_changed || mode_changed()))
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   618
        {
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   619
            self.push_outcome(Outcome::Modified, dirstate_node)?
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   620
        } else {
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48257
diff changeset
   621
            let mtime_looks_clean;
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48257
diff changeset
   622
            if let Some(dirstate_mtime) = entry.truncated_mtime() {
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48257
diff changeset
   623
                let fs_mtime = TruncatedTimestamp::for_mtime_of(fs_metadata)
48263
83d0bd45b662 dirstate-v2: actually use sub-second mtime precision
Simon Sapin <simon.sapin@octobus.net>
parents: 48260
diff changeset
   624
                    .expect("OS/libc does not support mtime?");
48391
b80e5e75d51e dirstate: remove `lastnormaltime` mechanism
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48263
diff changeset
   625
                // There might be a change in the future if for example the
b80e5e75d51e dirstate: remove `lastnormaltime` mechanism
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48263
diff changeset
   626
                // internal clock become off while process run, but this is a
b80e5e75d51e dirstate: remove `lastnormaltime` mechanism
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48263
diff changeset
   627
                // case where the issues the user would face
b80e5e75d51e dirstate: remove `lastnormaltime` mechanism
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48263
diff changeset
   628
                // would be a lot worse and there is nothing we
b80e5e75d51e dirstate: remove `lastnormaltime` mechanism
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48263
diff changeset
   629
                // can really do.
48260
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48257
diff changeset
   630
                mtime_looks_clean = fs_mtime.likely_equal(dirstate_mtime)
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48257
diff changeset
   631
            } else {
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48257
diff changeset
   632
                // No mtime in the dirstate entry
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48257
diff changeset
   633
                mtime_looks_clean = false
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48257
diff changeset
   634
            };
269ff8978086 dirstate: store mtimes with nanosecond precision in memory
Simon Sapin <simon.sapin@octobus.net>
parents: 48257
diff changeset
   635
            if !mtime_looks_clean {
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   636
                self.push_outcome(Outcome::Unsure, dirstate_node)?
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   637
            } else if self.options.list_clean {
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   638
                self.push_outcome(Outcome::Clean, dirstate_node)?
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   639
            }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   640
        }
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
   641
        Ok(())
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   642
    }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   643
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   644
    /// A node in the dirstate tree has no corresponding filesystem entry
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
   645
    fn traverse_dirstate_only(
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
   646
        &self,
47347
73ddcedeaadf dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47346
diff changeset
   647
        dirstate_node: NodeRef<'tree, 'on_disk>,
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
   648
    ) -> Result<(), DirstateV2ParseError> {
47474
c657beacdf2e dirstate-v2: Drop cached read_dir results after .hgignore changes
Simon Sapin <simon.sapin@octobus.net>
parents: 47409
diff changeset
   649
        self.check_for_outdated_directory_cache(&dirstate_node)?;
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   650
        self.mark_removed_or_deleted_if_file(&dirstate_node)?;
47333
69530e5d4fe5 dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents: 47331
diff changeset
   651
        dirstate_node
47336
8d0260d0dbc9 dirstate-v2: Make the dirstate bytes buffer available in more places
Simon Sapin <simon.sapin@octobus.net>
parents: 47335
diff changeset
   652
            .children(self.dmap.on_disk)?
47333
69530e5d4fe5 dirstate-tree: Add `NodeRef` and `ChildNodesRef` enums
Simon Sapin <simon.sapin@octobus.net>
parents: 47331
diff changeset
   653
            .par_iter()
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
   654
            .map(|child_node| self.traverse_dirstate_only(child_node))
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47333
diff changeset
   655
            .collect()
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   656
    }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   657
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   658
    /// A node in the dirstate tree has no corresponding *file* on the
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   659
    /// filesystem
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   660
    ///
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   661
    /// Does nothing on a "directory" node
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   662
    fn mark_removed_or_deleted_if_file(
47117
60d852ae7e7b dirstate-tree: Paralellize the status algorithm with Rayon
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   663
        &self,
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   664
        dirstate_node: &NodeRef<'tree, 'on_disk>,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   665
    ) -> Result<(), DirstateV2ParseError> {
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   666
        if let Some(state) = dirstate_node.state()? {
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   667
            let path = dirstate_node.full_path(self.dmap.on_disk)?;
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   668
            if self.matcher.matches(path) {
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   669
                if let EntryState::Removed = state {
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   670
                    self.push_outcome(Outcome::Removed, dirstate_node)?
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   671
                } else {
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   672
                    self.push_outcome(Outcome::Deleted, &dirstate_node)?
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   673
                }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   674
            }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   675
        }
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   676
        Ok(())
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   677
    }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   678
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   679
    /// Something in the filesystem has no corresponding dirstate node
47475
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   680
    ///
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   681
    /// Returns whether that path is ignored
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   682
    fn traverse_fs_only(
47117
60d852ae7e7b dirstate-tree: Paralellize the status algorithm with Rayon
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   683
        &self,
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   684
        has_ignored_ancestor: bool,
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   685
        directory_hg_path: &HgPath,
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   686
        fs_entry: &DirEntry,
47475
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   687
    ) -> bool {
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   688
        let hg_path = directory_hg_path.join(&fs_entry.base_name);
47114
aeb03758f37a dirstate-tree: Ignore FIFOs etc. in the status algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47113
diff changeset
   689
        let file_type = fs_entry.metadata.file_type();
aeb03758f37a dirstate-tree: Ignore FIFOs etc. in the status algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47113
diff changeset
   690
        let file_or_symlink = file_type.is_file() || file_type.is_symlink();
aeb03758f37a dirstate-tree: Ignore FIFOs etc. in the status algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47113
diff changeset
   691
        if file_type.is_dir() {
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   692
            let is_ignored =
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   693
                has_ignored_ancestor || (self.ignore_fn)(&hg_path);
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   694
            let traverse_children = if is_ignored {
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   695
                // Descendants of an ignored directory are all ignored
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   696
                self.options.list_ignored
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   697
            } else {
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   698
                // Descendants of an unknown directory may be either unknown or
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   699
                // ignored
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   700
                self.options.list_unknown || self.options.list_ignored
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   701
            };
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   702
            if traverse_children {
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   703
                let is_at_repo_root = false;
47115
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   704
                if let Ok(children_fs_entries) = self.read_dir(
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   705
                    &hg_path,
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   706
                    &fs_entry.full_path,
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   707
                    is_at_repo_root,
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   708
                ) {
47117
60d852ae7e7b dirstate-tree: Paralellize the status algorithm with Rayon
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   709
                    children_fs_entries.par_iter().for_each(|child_fs_entry| {
47115
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   710
                        self.traverse_fs_only(
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   711
                            is_ignored,
1b4f0f819f92 dirstate-tree: Handle I/O errors in status
Simon Sapin <simon.sapin@octobus.net>
parents: 47114
diff changeset
   712
                            &hg_path,
47117
60d852ae7e7b dirstate-tree: Paralellize the status algorithm with Rayon
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   713
                            child_fs_entry,
47475
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   714
                        );
47117
60d852ae7e7b dirstate-tree: Paralellize the status algorithm with Rayon
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   715
                    })
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   716
                }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   717
            }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   718
            if self.options.collect_traversed_dirs {
47117
60d852ae7e7b dirstate-tree: Paralellize the status algorithm with Rayon
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   719
                self.outcome.lock().unwrap().traversed.push(hg_path.into())
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   720
            }
47475
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   721
            is_ignored
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   722
        } else {
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   723
            if file_or_symlink {
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   724
                if self.matcher.matches(&hg_path) {
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   725
                    self.mark_unknown_or_ignored(
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   726
                        has_ignored_ancestor,
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   727
                        &BorrowedPath::InMemory(&hg_path),
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   728
                    )
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   729
                } else {
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   730
                    // We haven’t computed whether this path is ignored. It
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   731
                    // might not be, and a future run of status might have a
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   732
                    // different matcher that matches it. So treat it as not
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   733
                    // ignored. That is, inhibit readdir caching of the parent
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   734
                    // directory.
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   735
                    false
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   736
                }
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   737
            } else {
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   738
                // This is neither a directory, a plain file, or a symlink.
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   739
                // Treat it like an ignored file.
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   740
                true
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   741
            }
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   742
        }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   743
    }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   744
47475
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   745
    /// Returns whether that path is ignored
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   746
    fn mark_unknown_or_ignored(
47117
60d852ae7e7b dirstate-tree: Paralellize the status algorithm with Rayon
Simon Sapin <simon.sapin@octobus.net>
parents: 47115
diff changeset
   747
        &self,
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   748
        has_ignored_ancestor: bool,
47347
73ddcedeaadf dirstate-tree: Change status() results to not borrow DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47346
diff changeset
   749
        hg_path: &BorrowedPath<'_, 'on_disk>,
47475
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   750
    ) -> bool {
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   751
        let is_ignored = has_ignored_ancestor || (self.ignore_fn)(&hg_path);
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   752
        if is_ignored {
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   753
            if self.options.list_ignored {
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   754
                self.push_outcome_without_copy_source(
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   755
                    Outcome::Ignored,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   756
                    hg_path,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   757
                )
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   758
            }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   759
        } else {
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   760
            if self.options.list_unknown {
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   761
                self.push_outcome_without_copy_source(
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   762
                    Outcome::Unknown,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   763
                    hg_path,
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
   764
                )
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   765
            }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   766
        }
47475
94e38822d395 status: Extend read_dir caching to directories with ignored files
Simon Sapin <simon.sapin@octobus.net>
parents: 47474
diff changeset
   767
        is_ignored
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   768
    }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   769
}
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   770
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   771
struct DirEntry {
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   772
    base_name: HgPathBuf,
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   773
    full_path: PathBuf,
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   774
    metadata: std::fs::Metadata,
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   775
}
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   776
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   777
impl DirEntry {
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   778
    /// Returns **unsorted** entries in the given directory, with name and
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   779
    /// metadata.
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   780
    ///
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   781
    /// If a `.hg` sub-directory is encountered:
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   782
    ///
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   783
    /// * At the repository root, ignore that sub-directory
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   784
    /// * Elsewhere, we’re listing the content of a sub-repo. Return an empty
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   785
    ///   list instead.
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   786
    fn read_dir(path: &Path, is_at_repo_root: bool) -> io::Result<Vec<Self>> {
48745
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
   787
        // `read_dir` returns a "not found" error for the empty path
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
   788
        let at_cwd = path == Path::new("");
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
   789
        let read_dir_path = if at_cwd { Path::new(".") } else { path };
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   790
        let mut results = Vec::new();
48745
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
   791
        for entry in read_dir_path.read_dir()? {
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   792
            let entry = entry?;
48774
dcec16e799dd status: fix hg status race against file deletion
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48263
diff changeset
   793
            let metadata = match entry.metadata() {
dcec16e799dd status: fix hg status race against file deletion
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48263
diff changeset
   794
                Ok(v) => v,
dcec16e799dd status: fix hg status race against file deletion
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48263
diff changeset
   795
                Err(e) => {
dcec16e799dd status: fix hg status race against file deletion
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48263
diff changeset
   796
                    // race with file deletion?
dcec16e799dd status: fix hg status race against file deletion
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48263
diff changeset
   797
                    if e.kind() == std::io::ErrorKind::NotFound {
dcec16e799dd status: fix hg status race against file deletion
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48263
diff changeset
   798
                        continue;
dcec16e799dd status: fix hg status race against file deletion
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48263
diff changeset
   799
                    } else {
dcec16e799dd status: fix hg status race against file deletion
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48263
diff changeset
   800
                        return Err(e);
dcec16e799dd status: fix hg status race against file deletion
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48263
diff changeset
   801
                    }
dcec16e799dd status: fix hg status race against file deletion
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48263
diff changeset
   802
                }
dcec16e799dd status: fix hg status race against file deletion
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48263
diff changeset
   803
            };
48745
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
   804
            let file_name = entry.file_name();
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   805
            // FIXME don't do this when cached
48745
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
   806
            if file_name == ".hg" {
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   807
                if is_at_repo_root {
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   808
                    // Skip the repo’s own .hg (might be a symlink)
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   809
                    continue;
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   810
                } else if metadata.is_dir() {
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   811
                    // A .hg sub-directory at another location means a subrepo,
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   812
                    // skip it entirely.
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   813
                    return Ok(Vec::new());
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   814
                }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   815
            }
48745
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
   816
            let full_path = if at_cwd {
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
   817
                file_name.clone().into()
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
   818
            } else {
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
   819
                entry.path()
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
   820
            };
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
   821
            let base_name = get_bytes_from_os_string(file_name).into();
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   822
            results.push(DirEntry {
48745
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
   823
                base_name,
94e36b230990 status: prefer relative paths in Rust code
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
   824
                full_path,
47113
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   825
                metadata,
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   826
            })
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   827
        }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   828
        Ok(results)
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   829
    }
be579775c2d9 dirstate-tree: Add the new `status()` algorithm
Simon Sapin <simon.sapin@octobus.net>
parents: 47112
diff changeset
   830
}
47349
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   831
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   832
/// Return the `mtime` of a temporary file newly-created in the `.hg` directory
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   833
/// of the give repository.
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   834
///
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   835
/// This is similar to `SystemTime::now()`, with the result truncated to the
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   836
/// same time resolution as other files’ modification times. Using `.hg`
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   837
/// instead of the system’s default temporary directory (such as `/tmp`) makes
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   838
/// it more likely the temporary file is in the same disk partition as contents
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   839
/// of the working directory, which can matter since different filesystems may
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   840
/// store timestamps with different resolutions.
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   841
///
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   842
/// This may fail, typically if we lack write permissions. In that case we
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   843
/// should continue the `status()` algoritm anyway and consider the current
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   844
/// date/time to be unknown.
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   845
fn filesystem_now(repo_root: &Path) -> Result<SystemTime, io::Error> {
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   846
    tempfile::tempfile_in(repo_root.join(".hg"))?
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   847
        .metadata()?
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   848
        .modified()
7138c863d0a1 dirstate-v2: Skip readdir in status based on directory mtime
Simon Sapin <simon.sapin@octobus.net>
parents: 47347
diff changeset
   849
}