annotate rust/rhg/src/commands/status.rs @ 50866:c112cc9effdc

rhg: support "status FILE" This change adds a new [file] argument to rhg status, parses them as patterns, canonicalizes the paths, and constructs a new PatternMatcher to intersect with the existing matcher being passed to the status implementation. We also make filepatterns a public module so we can access the pattern-parsing functionality we need from commands/status.rs.
author Spencer Baugh <sbaugh@janestreet.com>
date Wed, 02 Aug 2023 10:46:47 -0400
parents f8412da86d05
children 976403c95ba3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
1 // status.rs
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
2 //
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
3 // Copyright 2020, Georges Racinet <georges.racinets@octobus.net>
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
4 //
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
5 // This software may be used and distributed according to the terms of the
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
6 // GNU General Public License version 2 or any later version.
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
7
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
8 use crate::error::CommandError;
49981
364e78389653 rust-ui: refactor ui code for printing narrow/sparse warnings
Raphaël Gomès <rgomes@octobus.net>
parents: 49948
diff changeset
9 use crate::ui::{
50763
f8412da86d05 rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents: 50463
diff changeset
10 format_pattern_file_warning, print_narrow_sparse_warnings, relative_paths,
f8412da86d05 rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents: 50463
diff changeset
11 RelativePaths, Ui,
49981
364e78389653 rust-ui: refactor ui code for printing narrow/sparse warnings
Raphaël Gomès <rgomes@octobus.net>
parents: 49948
diff changeset
12 };
48453
9b0e1f64656f rhg: refactor relativize_path into a struct + method
Simon Sapin <simon.sapin@octobus.net>
parents: 48452
diff changeset
13 use crate::utils::path_utils::RelativizePaths;
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
14 use clap::Arg;
48349
c12ed33558cb rhg: Add support for `rhg status -n`
Simon Sapin <simon.sapin@octobus.net>
parents: 48345
diff changeset
15 use format_bytes::format_bytes;
48175
707c58880cd0 rhg: add relative paths support in `rhg status`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 48171
diff changeset
16 use hg::config::Config;
48391
b80e5e75d51e dirstate: remove `lastnormaltime` mechanism
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48349
diff changeset
17 use hg::dirstate::has_exec_bit;
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48453
diff changeset
18 use hg::dirstate::status::StatusPath;
48422
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
19 use hg::dirstate::TruncatedTimestamp;
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
20 use hg::errors::{HgError, IoResultExt};
50866
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
21 use hg::filepatterns::parse_pattern_args;
48422
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
22 use hg::lock::LockError;
47964
796206e74b10 rhg: Reuse manifest when checking status of multiple ambiguous files
Simon Sapin <simon.sapin@octobus.net>
parents: 47956
diff changeset
23 use hg::manifest::Manifest;
49489
7c93e38a0bbd rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents: 49485
diff changeset
24 use hg::matchers::{AlwaysMatcher, IntersectionMatcher};
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
25 use hg::repo::Repo;
50215
ae61851e6fe2 dirstate: add a way to test races happening during status
Raphaël Gomès <rgomes@octobus.net>, Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50178
diff changeset
26 use hg::utils::debug::debug_wait_for_file;
50866
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
27 use hg::utils::files::{
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
28 get_bytes_from_os_str, get_bytes_from_os_string, get_path_from_bytes,
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
29 };
48422
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
30 use hg::utils::hg_path::{hg_path_to_path_buf, HgPath};
49000
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
31 use hg::DirstateStatus;
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
32 use hg::PatternFileWarning;
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
33 use hg::StatusError;
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48453
diff changeset
34 use hg::StatusOptions;
49489
7c93e38a0bbd rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents: 49485
diff changeset
35 use hg::{self, narrow, sparse};
48511
c9abfb80b4e3 rhg: Properly format warnings related to ignore patterns
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
36 use log::info;
49517
52464a20add0 rhg: parallellize computation of [unsure_is_modified]
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49516
diff changeset
37 use rayon::prelude::*;
48422
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
38 use std::io;
48451
4a983b69e519 rhg: Add support for ui.ignore and ui.ignore.* config
Simon Sapin <simon.sapin@octobus.net>
parents: 48443
diff changeset
39 use std::path::PathBuf;
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
40
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
41 pub const HELP_TEXT: &str = "
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
42 Show changed files in the working directory
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
43
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
44 This is a pure Rust version of `hg status`.
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
45
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
46 Some options might be missing, check the list below.
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
47 ";
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
48
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
49 pub fn args() -> clap::Command {
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
50 clap::command!("status")
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
51 .alias("st")
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
52 .about(HELP_TEXT)
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
53 .arg(
50866
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
54 Arg::new("file")
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
55 .value_parser(clap::value_parser!(std::ffi::OsString))
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
56 .help("show only these files")
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
57 .action(clap::ArgAction::Append),
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
58 )
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
59 .arg(
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
60 Arg::new("all")
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
61 .help("show status of all files")
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
62 .short('A')
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
63 .action(clap::ArgAction::SetTrue)
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
64 .long("all"),
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
65 )
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
66 .arg(
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
67 Arg::new("modified")
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
68 .help("show only modified files")
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
69 .short('m')
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
70 .action(clap::ArgAction::SetTrue)
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
71 .long("modified"),
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
72 )
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
73 .arg(
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
74 Arg::new("added")
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
75 .help("show only added files")
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
76 .short('a')
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
77 .action(clap::ArgAction::SetTrue)
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
78 .long("added"),
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
79 )
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
80 .arg(
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
81 Arg::new("removed")
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
82 .help("show only removed files")
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
83 .short('r')
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
84 .action(clap::ArgAction::SetTrue)
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
85 .long("removed"),
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
86 )
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
87 .arg(
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
88 Arg::new("clean")
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
89 .help("show only clean files")
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
90 .short('c')
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
91 .action(clap::ArgAction::SetTrue)
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
92 .long("clean"),
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
93 )
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
94 .arg(
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
95 Arg::new("deleted")
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
96 .help("show only deleted files")
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
97 .short('d')
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
98 .action(clap::ArgAction::SetTrue)
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
99 .long("deleted"),
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
100 )
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
101 .arg(
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
102 Arg::new("unknown")
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
103 .help("show only unknown (not tracked) files")
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
104 .short('u')
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
105 .action(clap::ArgAction::SetTrue)
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
106 .long("unknown"),
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
107 )
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
108 .arg(
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
109 Arg::new("ignored")
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
110 .help("show only ignored files")
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
111 .short('i')
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
112 .action(clap::ArgAction::SetTrue)
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
113 .long("ignored"),
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
114 )
48349
c12ed33558cb rhg: Add support for `rhg status -n`
Simon Sapin <simon.sapin@octobus.net>
parents: 48345
diff changeset
115 .arg(
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
116 Arg::new("copies")
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48453
diff changeset
117 .help("show source of copied files (DEFAULT: ui.statuscopies)")
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
118 .short('C')
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
119 .action(clap::ArgAction::SetTrue)
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
120 .long("copies"),
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48453
diff changeset
121 )
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48453
diff changeset
122 .arg(
50427
98fc949bec14 rhg: support `status --print0`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50252
diff changeset
123 Arg::new("print0")
98fc949bec14 rhg: support `status --print0`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50252
diff changeset
124 .help("end filenames with NUL, for use with xargs")
98fc949bec14 rhg: support `status --print0`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50252
diff changeset
125 .short('0')
98fc949bec14 rhg: support `status --print0`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50252
diff changeset
126 .action(clap::ArgAction::SetTrue)
98fc949bec14 rhg: support `status --print0`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50252
diff changeset
127 .long("print0"),
98fc949bec14 rhg: support `status --print0`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50252
diff changeset
128 )
98fc949bec14 rhg: support `status --print0`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50252
diff changeset
129 .arg(
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
130 Arg::new("no-status")
48349
c12ed33558cb rhg: Add support for `rhg status -n`
Simon Sapin <simon.sapin@octobus.net>
parents: 48345
diff changeset
131 .help("hide status prefix")
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
132 .short('n')
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
133 .action(clap::ArgAction::SetTrue)
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
134 .long("no-status"),
48349
c12ed33558cb rhg: Add support for `rhg status -n`
Simon Sapin <simon.sapin@octobus.net>
parents: 48345
diff changeset
135 )
49439
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
136 .arg(
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
137 Arg::new("verbose")
49439
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
138 .help("enable additional output")
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
139 .short('v')
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
140 .action(clap::ArgAction::SetTrue)
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
141 .long("verbose"),
49439
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
142 )
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
143 }
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
144
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
145 /// Pure data type allowing the caller to specify file states to display
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
146 #[derive(Copy, Clone, Debug)]
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
147 pub struct DisplayStates {
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
148 pub modified: bool,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
149 pub added: bool,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
150 pub removed: bool,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
151 pub clean: bool,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
152 pub deleted: bool,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
153 pub unknown: bool,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
154 pub ignored: bool,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
155 }
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
156
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
157 pub const DEFAULT_DISPLAY_STATES: DisplayStates = DisplayStates {
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
158 modified: true,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
159 added: true,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
160 removed: true,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
161 clean: false,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
162 deleted: true,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
163 unknown: true,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
164 ignored: false,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
165 };
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
166
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
167 pub const ALL_DISPLAY_STATES: DisplayStates = DisplayStates {
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
168 modified: true,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
169 added: true,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
170 removed: true,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
171 clean: true,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
172 deleted: true,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
173 unknown: true,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
174 ignored: true,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
175 };
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
176
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
177 impl DisplayStates {
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
178 pub fn is_empty(&self) -> bool {
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
179 !(self.modified
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
180 || self.added
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
181 || self.removed
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
182 || self.clean
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
183 || self.deleted
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
184 || self.unknown
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
185 || self.ignored)
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
186 }
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
187 }
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
188
49439
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
189 fn has_unfinished_merge(repo: &Repo) -> Result<bool, CommandError> {
49914
58074252db3c rust: run `cargo clippy`
Raphaël Gomès <rgomes@octobus.net>
parents: 49894
diff changeset
190 Ok(repo.dirstate_parents()?.is_merge())
49439
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
191 }
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
192
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
193 fn has_unfinished_state(repo: &Repo) -> Result<bool, CommandError> {
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
194 // These are all the known values for the [fname] argument of
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
195 // [addunfinished] function in [state.py]
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
196 let known_state_files: &[&str] = &[
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
197 "bisect.state",
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
198 "graftstate",
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
199 "histedit-state",
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
200 "rebasestate",
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
201 "shelvedstate",
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
202 "transplant/journal",
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
203 "updatestate",
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
204 ];
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
205 if has_unfinished_merge(repo)? {
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
206 return Ok(true);
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
207 };
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
208 for f in known_state_files {
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
209 if repo.hg_vfs().join(f).exists() {
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
210 return Ok(true);
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
211 }
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
212 }
49914
58074252db3c rust: run `cargo clippy`
Raphaël Gomès <rgomes@octobus.net>
parents: 49894
diff changeset
213 Ok(false)
49439
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
214 }
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
215
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
216 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
48171
64b8676f11bb rhg: fallback if tweakdefaults or statuscopies is enabled with status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 48069
diff changeset
217 // TODO: lift these limitations
48338
f9db8eeb3aec rhg: Config commands.status.terse is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48337
diff changeset
218 if invocation
f9db8eeb3aec rhg: Config commands.status.terse is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48337
diff changeset
219 .config
f9db8eeb3aec rhg: Config commands.status.terse is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48337
diff changeset
220 .get(b"commands", b"status.terse")
f9db8eeb3aec rhg: Config commands.status.terse is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48337
diff changeset
221 .is_some()
f9db8eeb3aec rhg: Config commands.status.terse is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48337
diff changeset
222 {
f9db8eeb3aec rhg: Config commands.status.terse is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48337
diff changeset
223 return Err(CommandError::unsupported(
f9db8eeb3aec rhg: Config commands.status.terse is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48337
diff changeset
224 "status.terse is not yet supported with rhg status",
f9db8eeb3aec rhg: Config commands.status.terse is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48337
diff changeset
225 ));
f9db8eeb3aec rhg: Config commands.status.terse is not supported
Simon Sapin <simon.sapin@octobus.net>
parents: 48337
diff changeset
226 }
48171
64b8676f11bb rhg: fallback if tweakdefaults or statuscopies is enabled with status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 48069
diff changeset
227
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
228 let ui = invocation.ui;
48175
707c58880cd0 rhg: add relative paths support in `rhg status`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 48171
diff changeset
229 let config = invocation.config;
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
230 let args = invocation.subcommand_args;
48513
47f2a82ae3e4 rhg: Fall back to Python if verbose status is requested by config
Simon Sapin <simon.sapin@octobus.net>
parents: 48511
diff changeset
231
50427
98fc949bec14 rhg: support `status --print0`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50252
diff changeset
232 let print0 = args.get_flag("print0");
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
233 let verbose = args.get_flag("verbose")
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
234 || config.get_bool(b"ui", b"verbose")?
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
235 || config.get_bool(b"commands", b"status.verbose")?;
50427
98fc949bec14 rhg: support `status --print0`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50252
diff changeset
236 let verbose = verbose && !print0;
48513
47f2a82ae3e4 rhg: Fall back to Python if verbose status is requested by config
Simon Sapin <simon.sapin@octobus.net>
parents: 48511
diff changeset
237
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
238 let all = args.get_flag("all");
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48453
diff changeset
239 let display_states = if all {
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
240 // TODO when implementing `--quiet`: it excludes clean files
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
241 // from `--all`
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
242 ALL_DISPLAY_STATES
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
243 } else {
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
244 let requested = DisplayStates {
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
245 modified: args.get_flag("modified"),
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
246 added: args.get_flag("added"),
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
247 removed: args.get_flag("removed"),
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
248 clean: args.get_flag("clean"),
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
249 deleted: args.get_flag("deleted"),
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
250 unknown: args.get_flag("unknown"),
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
251 ignored: args.get_flag("ignored"),
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
252 };
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
253 if requested.is_empty() {
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
254 DEFAULT_DISPLAY_STATES
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
255 } else {
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
256 requested
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
257 }
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
258 };
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
259 let no_status = args.get_flag("no-status");
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48453
diff changeset
260 let list_copies = all
49640
37bc3edef76f rhg: upgrade `clap` dependency
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
261 || args.get_flag("copies")
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48453
diff changeset
262 || config.get_bool(b"ui", b"statuscopies")?;
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
263
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
264 let repo = invocation.repo?;
48409
005ae1a343f8 rhg: add support for narrow clones and sparse checkouts
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 48391
diff changeset
265
49914
58074252db3c rust: run `cargo clippy`
Raphaël Gomès <rgomes@octobus.net>
parents: 49894
diff changeset
266 if verbose && has_unfinished_state(repo)? {
58074252db3c rust: run `cargo clippy`
Raphaël Gomès <rgomes@octobus.net>
parents: 49894
diff changeset
267 return Err(CommandError::unsupported(
58074252db3c rust: run `cargo clippy`
Raphaël Gomès <rgomes@octobus.net>
parents: 49894
diff changeset
268 "verbose status output is not supported by rhg (and is needed because we're in an unfinished operation)",
58074252db3c rust: run `cargo clippy`
Raphaël Gomès <rgomes@octobus.net>
parents: 49894
diff changeset
269 ));
49439
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
270 }
b07465adbcc8 rhg: make [rhg status -v] work when it needs no extra output
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49374
diff changeset
271
47956
81aedf1fc897 rust: Add Repo::dirstate_map and use it in `rhg status`
Simon Sapin <simon.sapin@octobus.net>
parents: 47682
diff changeset
272 let mut dmap = repo.dirstate_map_mut()?;
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47374
diff changeset
273
49894
678588b01af1 rhg: implement checkexec to support weird filesystems
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49640
diff changeset
274 let check_exec = hg::checkexec::check_exec(repo.working_directory_path());
678588b01af1 rhg: implement checkexec to support weird filesystems
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49640
diff changeset
275
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
276 let options = StatusOptions {
49894
678588b01af1 rhg: implement checkexec to support weird filesystems
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49640
diff changeset
277 check_exec,
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
278 list_clean: display_states.clean,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
279 list_unknown: display_states.unknown,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
280 list_ignored: display_states.ignored,
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48453
diff changeset
281 list_copies,
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
282 collect_traversed_dirs: false,
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
283 };
49000
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
284
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
285 type StatusResult<'a> =
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
286 Result<(DirstateStatus<'a>, Vec<PatternFileWarning>), StatusError>;
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
287
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
288 let after_status = |res: StatusResult| -> Result<_, CommandError> {
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
289 let (mut ds_status, pattern_warnings) = res?;
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
290 for warning in pattern_warnings {
49981
364e78389653 rust-ui: refactor ui code for printing narrow/sparse warnings
Raphaël Gomès <rgomes@octobus.net>
parents: 49948
diff changeset
291 ui.write_stderr(&format_pattern_file_warning(&warning, repo))?;
48511
c9abfb80b4e3 rhg: Properly format warnings related to ignore patterns
Simon Sapin <simon.sapin@octobus.net>
parents: 48501
diff changeset
292 }
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
293
49000
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
294 for (path, error) in ds_status.bad {
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
295 let error = match error {
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
296 hg::BadMatch::OsError(code) => {
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
297 std::io::Error::from_raw_os_error(code).to_string()
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
298 }
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
299 hg::BadMatch::BadType(ty) => {
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
300 format!("unsupported file type (type is {})", ty)
47321
62225f9da938 rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents: 47110
diff changeset
301 }
49000
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
302 };
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
303 ui.write_stderr(&format_bytes!(
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
304 b"{}: {}\n",
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
305 path.as_bytes(),
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
306 error.as_bytes()
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
307 ))?
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
308 }
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
309 if !ds_status.unsure.is_empty() {
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
310 info!(
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
311 "Files to be rechecked by retrieval from filelog: {:?}",
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
312 ds_status.unsure.iter().map(|s| &s.path).collect::<Vec<_>>()
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
313 );
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
314 }
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
315 let mut fixup = Vec::new();
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
316 if !ds_status.unsure.is_empty()
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
317 && (display_states.modified || display_states.clean)
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
318 {
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
319 let p1 = repo.dirstate_parents()?.p1;
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
320 let manifest = repo.manifest_for_node(p1).map_err(|e| {
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
321 CommandError::from((e, &*format!("{:x}", p1.short())))
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
322 })?;
49517
52464a20add0 rhg: parallellize computation of [unsure_is_modified]
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49516
diff changeset
323 let working_directory_vfs = repo.working_directory_vfs();
52464a20add0 rhg: parallellize computation of [unsure_is_modified]
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49516
diff changeset
324 let store_vfs = repo.store_vfs();
52464a20add0 rhg: parallellize computation of [unsure_is_modified]
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49516
diff changeset
325 let res: Vec<_> = ds_status
52464a20add0 rhg: parallellize computation of [unsure_is_modified]
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49516
diff changeset
326 .unsure
52464a20add0 rhg: parallellize computation of [unsure_is_modified]
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49516
diff changeset
327 .into_par_iter()
52464a20add0 rhg: parallellize computation of [unsure_is_modified]
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49516
diff changeset
328 .map(|to_check| {
50226
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
329 // The compiler seems to get a bit confused with complex
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
330 // inference when using a parallel iterator + map
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
331 // + map_err + collect, so let's just inline some of the
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
332 // logic.
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
333 match unsure_is_modified(
49517
52464a20add0 rhg: parallellize computation of [unsure_is_modified]
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49516
diff changeset
334 working_directory_vfs,
52464a20add0 rhg: parallellize computation of [unsure_is_modified]
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49516
diff changeset
335 store_vfs,
49894
678588b01af1 rhg: implement checkexec to support weird filesystems
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49640
diff changeset
336 check_exec,
49517
52464a20add0 rhg: parallellize computation of [unsure_is_modified]
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49516
diff changeset
337 &manifest,
52464a20add0 rhg: parallellize computation of [unsure_is_modified]
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49516
diff changeset
338 &to_check.path,
50226
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
339 ) {
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
340 Err(HgError::IoError { .. }) => {
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
341 // IO errors most likely stem from the file being
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
342 // deleted even though we know it's in the
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
343 // dirstate.
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
344 Ok((to_check, UnsureOutcome::Deleted))
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
345 }
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
346 Ok(outcome) => Ok((to_check, outcome)),
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
347 Err(e) => Err(e),
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
348 }
49517
52464a20add0 rhg: parallellize computation of [unsure_is_modified]
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49516
diff changeset
349 })
52464a20add0 rhg: parallellize computation of [unsure_is_modified]
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49516
diff changeset
350 .collect::<Result<_, _>>()?;
50226
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
351 for (status_path, outcome) in res.into_iter() {
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
352 match outcome {
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
353 UnsureOutcome::Clean => {
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
354 if display_states.clean {
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
355 ds_status.clean.push(status_path.clone());
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
356 }
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
357 fixup.push(status_path.path.into_owned())
49000
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
358 }
50226
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
359 UnsureOutcome::Modified => {
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
360 if display_states.modified {
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
361 ds_status.modified.push(status_path);
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
362 }
49000
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
363 }
50226
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
364 UnsureOutcome::Deleted => {
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
365 if display_states.deleted {
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
366 ds_status.deleted.push(status_path);
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
367 }
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
368 }
47321
62225f9da938 rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents: 47110
diff changeset
369 }
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
370 }
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
371 }
50763
f8412da86d05 rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents: 50463
diff changeset
372
f8412da86d05 rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents: 50463
diff changeset
373 let relative_status = config
49512
6939d5ed20e0 rhg: central treatment of PLAIN and PLAINEXCEPT
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49489
diff changeset
374 .get_option(b"commands", b"status.relative")?
50763
f8412da86d05 rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents: 50463
diff changeset
375 .expect("commands.status.relative should have a default value");
f8412da86d05 rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents: 50463
diff changeset
376
f8412da86d05 rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents: 50463
diff changeset
377 let relativize_paths = relative_status || {
f8412da86d05 rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents: 50463
diff changeset
378 // See in Python code with `getuipathfn` usage in `commands.py`.
50866
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
379 let legacy_relative_behavior = args.contains_id("file");
50763
f8412da86d05 rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents: 50463
diff changeset
380 match relative_paths(invocation.config)? {
f8412da86d05 rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents: 50463
diff changeset
381 RelativePaths::Legacy => legacy_relative_behavior,
f8412da86d05 rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents: 50463
diff changeset
382 RelativePaths::Bool(v) => v,
f8412da86d05 rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents: 50463
diff changeset
383 }
f8412da86d05 rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents: 50463
diff changeset
384 };
f8412da86d05 rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents: 50463
diff changeset
385
49000
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
386 let output = DisplayStatusPaths {
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
387 ui,
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
388 no_status,
50763
f8412da86d05 rust-config: add support for default config items
Raphaël Gomès <rgomes@octobus.net>
parents: 50463
diff changeset
389 relativize: if relativize_paths {
49000
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
390 Some(RelativizePaths::new(repo)?)
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
391 } else {
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
392 None
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
393 },
50427
98fc949bec14 rhg: support `status --print0`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50252
diff changeset
394 print0,
49000
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
395 };
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
396 if display_states.modified {
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
397 output.display(b"M ", "status.modified", ds_status.modified)?;
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
398 }
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
399 if display_states.added {
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
400 output.display(b"A ", "status.added", ds_status.added)?;
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
401 }
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
402 if display_states.removed {
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
403 output.display(b"R ", "status.removed", ds_status.removed)?;
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
404 }
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
405 if display_states.deleted {
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
406 output.display(b"! ", "status.deleted", ds_status.deleted)?;
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
407 }
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
408 if display_states.unknown {
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
409 output.display(b"? ", "status.unknown", ds_status.unknown)?;
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
410 }
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
411 if display_states.ignored {
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
412 output.display(b"I ", "status.ignored", ds_status.ignored)?;
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
413 }
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
414 if display_states.clean {
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
415 output.display(b"C ", "status.clean", ds_status.clean)?;
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
416 }
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
417
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
418 let dirstate_write_needed = ds_status.dirty;
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
419 let filesystem_time_at_status_start =
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
420 ds_status.filesystem_time_at_status_start;
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
421
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
422 Ok((
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
423 fixup,
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
424 dirstate_write_needed,
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
425 filesystem_time_at_status_start,
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
426 ))
48452
2afaa0145584 rhg: refactor display_status_paths with a struct for common arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 48451
diff changeset
427 };
49489
7c93e38a0bbd rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents: 49485
diff changeset
428 let (narrow_matcher, narrow_warnings) = narrow::matcher(repo)?;
7c93e38a0bbd rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents: 49485
diff changeset
429 let (sparse_matcher, sparse_warnings) = sparse::matcher(repo)?;
7c93e38a0bbd rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents: 49485
diff changeset
430 let matcher = match (repo.has_narrow(), repo.has_sparse()) {
7c93e38a0bbd rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents: 49485
diff changeset
431 (true, true) => {
7c93e38a0bbd rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents: 49485
diff changeset
432 Box::new(IntersectionMatcher::new(narrow_matcher, sparse_matcher))
7c93e38a0bbd rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents: 49485
diff changeset
433 }
7c93e38a0bbd rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents: 49485
diff changeset
434 (true, false) => narrow_matcher,
7c93e38a0bbd rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents: 49485
diff changeset
435 (false, true) => sparse_matcher,
7c93e38a0bbd rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents: 49485
diff changeset
436 (false, false) => Box::new(AlwaysMatcher),
7c93e38a0bbd rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents: 49485
diff changeset
437 };
50866
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
438 let matcher = match args.get_many::<std::ffi::OsString>("file") {
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
439 None => matcher,
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
440 Some(files) => {
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
441 let patterns: Vec<Vec<u8>> = files
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
442 .filter(|s| !s.is_empty())
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
443 .map(get_bytes_from_os_str)
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
444 .collect();
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
445 for file in &patterns {
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
446 if file.starts_with(b"set:") {
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
447 return Err(CommandError::unsupported("fileset"));
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
448 }
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
449 }
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
450 let cwd = hg::utils::current_dir()?;
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
451 let root = repo.working_directory_path();
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
452 let ignore_patterns = parse_pattern_args(patterns, &cwd, root)?;
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
453 let files_matcher =
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
454 hg::matchers::PatternMatcher::new(ignore_patterns)?;
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
455 Box::new(IntersectionMatcher::new(
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
456 Box::new(files_matcher),
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
457 matcher,
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
458 ))
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
459 }
c112cc9effdc rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents: 50763
diff changeset
460 };
49485
ffd4b1f1c9cb rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents: 49483
diff changeset
461
49981
364e78389653 rust-ui: refactor ui code for printing narrow/sparse warnings
Raphaël Gomès <rgomes@octobus.net>
parents: 49948
diff changeset
462 print_narrow_sparse_warnings(
364e78389653 rust-ui: refactor ui code for printing narrow/sparse warnings
Raphaël Gomès <rgomes@octobus.net>
parents: 49948
diff changeset
463 &narrow_warnings,
364e78389653 rust-ui: refactor ui code for printing narrow/sparse warnings
Raphaël Gomès <rgomes@octobus.net>
parents: 49948
diff changeset
464 &sparse_warnings,
364e78389653 rust-ui: refactor ui code for printing narrow/sparse warnings
Raphaël Gomès <rgomes@octobus.net>
parents: 49948
diff changeset
465 ui,
364e78389653 rust-ui: refactor ui code for printing narrow/sparse warnings
Raphaël Gomès <rgomes@octobus.net>
parents: 49948
diff changeset
466 repo,
364e78389653 rust-ui: refactor ui code for printing narrow/sparse warnings
Raphaël Gomès <rgomes@octobus.net>
parents: 49948
diff changeset
467 )?;
49000
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
468 let (fixup, mut dirstate_write_needed, filesystem_time_at_status_start) =
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
469 dmap.with_status(
49485
ffd4b1f1c9cb rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents: 49483
diff changeset
470 matcher.as_ref(),
49000
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
471 repo.working_directory_path().to_owned(),
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
472 ignore_files(repo, config),
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
473 options,
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
474 after_status,
dd6b67d5c256 rust: fix unsound `OwningDirstateMap`
Raphaël Gomès <rgomes@octobus.net>
parents: 48738
diff changeset
475 )?;
48422
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
476
50215
ae61851e6fe2 dirstate: add a way to test races happening during status
Raphaël Gomès <rgomes@octobus.net>, Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50178
diff changeset
477 // Development config option to test write races
ae61851e6fe2 dirstate: add a way to test races happening during status
Raphaël Gomès <rgomes@octobus.net>, Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50178
diff changeset
478 if let Err(e) =
50252
a6b8b1ab9116 branching: merge stable into default
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50094 50226
diff changeset
479 debug_wait_for_file(config, "status.pre-dirstate-write-file")
50215
ae61851e6fe2 dirstate: add a way to test races happening during status
Raphaël Gomès <rgomes@octobus.net>, Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50178
diff changeset
480 {
ae61851e6fe2 dirstate: add a way to test races happening during status
Raphaël Gomès <rgomes@octobus.net>, Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50178
diff changeset
481 ui.write_stderr(e.as_bytes()).ok();
ae61851e6fe2 dirstate: add a way to test races happening during status
Raphaël Gomès <rgomes@octobus.net>, Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50178
diff changeset
482 }
ae61851e6fe2 dirstate: add a way to test races happening during status
Raphaël Gomès <rgomes@octobus.net>, Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50178
diff changeset
483
48422
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
484 if (fixup.is_empty() || filesystem_time_at_status_start.is_none())
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
485 && !dirstate_write_needed
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
486 {
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
487 // Nothing to update
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
488 return Ok(());
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
489 }
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
490
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
491 // Update the dirstate on disk if we can
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
492 let with_lock_result =
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
493 repo.try_with_wlock_no_wait(|| -> Result<(), CommandError> {
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
494 if let Some(mtime_boundary) = filesystem_time_at_status_start {
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
495 for hg_path in fixup {
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
496 use std::os::unix::fs::MetadataExt;
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
497 let fs_path = hg_path_to_path_buf(&hg_path)
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
498 .expect("HgPath conversion");
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
499 // Specifically do not reuse `fs_metadata` from
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
500 // `unsure_is_clean` which was needed before reading
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
501 // contents. Here we access metadata again after reading
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
502 // content, in case it changed in the meantime.
50225
53ca3e3bc013 rhg: fix race when a fixup file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50215
diff changeset
503 let metadata_res = repo
48422
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
504 .working_directory_vfs()
50225
53ca3e3bc013 rhg: fix race when a fixup file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50215
diff changeset
505 .symlink_metadata(&fs_path);
53ca3e3bc013 rhg: fix race when a fixup file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50215
diff changeset
506 let fs_metadata = match metadata_res {
53ca3e3bc013 rhg: fix race when a fixup file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50215
diff changeset
507 Ok(meta) => meta,
53ca3e3bc013 rhg: fix race when a fixup file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50215
diff changeset
508 Err(err) => match err {
53ca3e3bc013 rhg: fix race when a fixup file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50215
diff changeset
509 HgError::IoError { .. } => {
53ca3e3bc013 rhg: fix race when a fixup file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50215
diff changeset
510 // The file has probably been deleted. In any
53ca3e3bc013 rhg: fix race when a fixup file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50215
diff changeset
511 // case, it was in the dirstate before, so
53ca3e3bc013 rhg: fix race when a fixup file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50215
diff changeset
512 // let's ignore the error.
53ca3e3bc013 rhg: fix race when a fixup file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50215
diff changeset
513 continue;
53ca3e3bc013 rhg: fix race when a fixup file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50215
diff changeset
514 }
53ca3e3bc013 rhg: fix race when a fixup file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50215
diff changeset
515 _ => return Err(err.into()),
53ca3e3bc013 rhg: fix race when a fixup file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50215
diff changeset
516 },
53ca3e3bc013 rhg: fix race when a fixup file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50215
diff changeset
517 };
48443
112184713852 rhg: Set second_ambiguous as needed in post-status fixup
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
518 if let Some(mtime) =
112184713852 rhg: Set second_ambiguous as needed in post-status fixup
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
519 TruncatedTimestamp::for_reliable_mtime_of(
112184713852 rhg: Set second_ambiguous as needed in post-status fixup
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
520 &fs_metadata,
112184713852 rhg: Set second_ambiguous as needed in post-status fixup
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
521 &mtime_boundary,
112184713852 rhg: Set second_ambiguous as needed in post-status fixup
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
522 )
112184713852 rhg: Set second_ambiguous as needed in post-status fixup
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
523 .when_reading_file(&fs_path)?
112184713852 rhg: Set second_ambiguous as needed in post-status fixup
Simon Sapin <simon.sapin@octobus.net>
parents: 48422
diff changeset
524 {
48422
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
525 let mode = fs_metadata.mode();
49110
4d3f6767319f rhg: use the new `set_clean` API
Raphaël Gomès <rgomes@octobus.net>
parents: 49000
diff changeset
526 let size = fs_metadata.len();
4d3f6767319f rhg: use the new `set_clean` API
Raphaël Gomès <rgomes@octobus.net>
parents: 49000
diff changeset
527 dmap.set_clean(&hg_path, mode, size as u32, mtime)?;
48422
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
528 dirstate_write_needed = true
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
529 }
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
530 }
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
531 }
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
532 drop(dmap); // Avoid "already mutably borrowed" RefCell panics
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
533 if dirstate_write_needed {
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
534 repo.write_dirstate()?
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
535 }
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
536 Ok(())
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
537 });
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
538 match with_lock_result {
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
539 Ok(closure_result) => closure_result?,
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
540 Err(LockError::AlreadyHeld) => {
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
541 // Not updating the dirstate is not ideal but not critical:
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
542 // don’t keep our caller waiting until some other Mercurial
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
543 // process releases the lock.
50178
baa4e2c93642 rust: add debug log about skipping dirstate update
Raphaël Gomès <rgomes@octobus.net>
parents: 49517
diff changeset
544 log::info!("not writing dirstate from `status`: lock is held")
48422
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
545 }
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
546 Err(LockError::Other(HgError::IoError { error, .. }))
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
547 if error.kind() == io::ErrorKind::PermissionDenied =>
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
548 {
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
549 // `hg status` on a read-only repository is fine
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
550 }
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
551 Err(LockError::Other(error)) => {
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
552 // Report other I/O errors
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
553 Err(error)?
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
554 }
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
555 }
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
556 Ok(())
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
557 }
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
558
48451
4a983b69e519 rhg: Add support for ui.ignore and ui.ignore.* config
Simon Sapin <simon.sapin@octobus.net>
parents: 48443
diff changeset
559 fn ignore_files(repo: &Repo, config: &Config) -> Vec<PathBuf> {
4a983b69e519 rhg: Add support for ui.ignore and ui.ignore.* config
Simon Sapin <simon.sapin@octobus.net>
parents: 48443
diff changeset
560 let mut ignore_files = Vec::new();
4a983b69e519 rhg: Add support for ui.ignore and ui.ignore.* config
Simon Sapin <simon.sapin@octobus.net>
parents: 48443
diff changeset
561 let repo_ignore = repo.working_directory_vfs().join(".hgignore");
4a983b69e519 rhg: Add support for ui.ignore and ui.ignore.* config
Simon Sapin <simon.sapin@octobus.net>
parents: 48443
diff changeset
562 if repo_ignore.exists() {
4a983b69e519 rhg: Add support for ui.ignore and ui.ignore.* config
Simon Sapin <simon.sapin@octobus.net>
parents: 48443
diff changeset
563 ignore_files.push(repo_ignore)
4a983b69e519 rhg: Add support for ui.ignore and ui.ignore.* config
Simon Sapin <simon.sapin@octobus.net>
parents: 48443
diff changeset
564 }
4a983b69e519 rhg: Add support for ui.ignore and ui.ignore.* config
Simon Sapin <simon.sapin@octobus.net>
parents: 48443
diff changeset
565 for (key, value) in config.iter_section(b"ui") {
4a983b69e519 rhg: Add support for ui.ignore and ui.ignore.* config
Simon Sapin <simon.sapin@octobus.net>
parents: 48443
diff changeset
566 if key == b"ignore" || key.starts_with(b"ignore.") {
4a983b69e519 rhg: Add support for ui.ignore and ui.ignore.* config
Simon Sapin <simon.sapin@octobus.net>
parents: 48443
diff changeset
567 let path = get_path_from_bytes(value);
4a983b69e519 rhg: Add support for ui.ignore and ui.ignore.* config
Simon Sapin <simon.sapin@octobus.net>
parents: 48443
diff changeset
568 // TODO: expand "~/" and environment variable here, like Python
4a983b69e519 rhg: Add support for ui.ignore and ui.ignore.* config
Simon Sapin <simon.sapin@octobus.net>
parents: 48443
diff changeset
569 // does with `os.path.expanduser` and `os.path.expandvars`
4a983b69e519 rhg: Add support for ui.ignore and ui.ignore.* config
Simon Sapin <simon.sapin@octobus.net>
parents: 48443
diff changeset
570
4a983b69e519 rhg: Add support for ui.ignore and ui.ignore.* config
Simon Sapin <simon.sapin@octobus.net>
parents: 48443
diff changeset
571 let joined = repo.working_directory_path().join(path);
4a983b69e519 rhg: Add support for ui.ignore and ui.ignore.* config
Simon Sapin <simon.sapin@octobus.net>
parents: 48443
diff changeset
572 ignore_files.push(joined);
4a983b69e519 rhg: Add support for ui.ignore and ui.ignore.* config
Simon Sapin <simon.sapin@octobus.net>
parents: 48443
diff changeset
573 }
4a983b69e519 rhg: Add support for ui.ignore and ui.ignore.* config
Simon Sapin <simon.sapin@octobus.net>
parents: 48443
diff changeset
574 }
4a983b69e519 rhg: Add support for ui.ignore and ui.ignore.* config
Simon Sapin <simon.sapin@octobus.net>
parents: 48443
diff changeset
575 ignore_files
4a983b69e519 rhg: Add support for ui.ignore and ui.ignore.* config
Simon Sapin <simon.sapin@octobus.net>
parents: 48443
diff changeset
576 }
4a983b69e519 rhg: Add support for ui.ignore and ui.ignore.* config
Simon Sapin <simon.sapin@octobus.net>
parents: 48443
diff changeset
577
48452
2afaa0145584 rhg: refactor display_status_paths with a struct for common arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 48451
diff changeset
578 struct DisplayStatusPaths<'a> {
2afaa0145584 rhg: refactor display_status_paths with a struct for common arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 48451
diff changeset
579 ui: &'a Ui,
48349
c12ed33558cb rhg: Add support for `rhg status -n`
Simon Sapin <simon.sapin@octobus.net>
parents: 48345
diff changeset
580 no_status: bool,
48453
9b0e1f64656f rhg: refactor relativize_path into a struct + method
Simon Sapin <simon.sapin@octobus.net>
parents: 48452
diff changeset
581 relativize: Option<RelativizePaths>,
50427
98fc949bec14 rhg: support `status --print0`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50252
diff changeset
582 print0: bool,
48452
2afaa0145584 rhg: refactor display_status_paths with a struct for common arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 48451
diff changeset
583 }
2afaa0145584 rhg: refactor display_status_paths with a struct for common arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 48451
diff changeset
584
2afaa0145584 rhg: refactor display_status_paths with a struct for common arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 48451
diff changeset
585 impl DisplayStatusPaths<'_> {
2afaa0145584 rhg: refactor display_status_paths with a struct for common arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 48451
diff changeset
586 // Probably more elegant to use a Deref or Borrow trait rather than
2afaa0145584 rhg: refactor display_status_paths with a struct for common arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 48451
diff changeset
587 // harcode HgPathBuf, but probably not really useful at this point
2afaa0145584 rhg: refactor display_status_paths with a struct for common arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 48451
diff changeset
588 fn display(
2afaa0145584 rhg: refactor display_status_paths with a struct for common arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 48451
diff changeset
589 &self,
2afaa0145584 rhg: refactor display_status_paths with a struct for common arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 48451
diff changeset
590 status_prefix: &[u8],
48734
3e2b4bb286e7 rhg: Colorize `rhg status` output when appropriate
Simon Sapin <simon.sapin@octobus.net>
parents: 48729
diff changeset
591 label: &'static str,
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48453
diff changeset
592 mut paths: Vec<StatusPath<'_>>,
48452
2afaa0145584 rhg: refactor display_status_paths with a struct for common arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 48451
diff changeset
593 ) -> Result<(), CommandError> {
2afaa0145584 rhg: refactor display_status_paths with a struct for common arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 48451
diff changeset
594 paths.sort_unstable();
48738
00efd2d5037d rust: fix code formatting
Simon Sapin <simon.sapin@octobus.net>
parents: 48735
diff changeset
595 // TODO: get the stdout lock once for the whole loop
00efd2d5037d rust: fix code formatting
Simon Sapin <simon.sapin@octobus.net>
parents: 48735
diff changeset
596 // instead of in each write
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48453
diff changeset
597 for StatusPath { path, copy_source } in paths {
50362
51041a1a4c59 rhg: correctly relativize copy source path
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents: 50361
diff changeset
598 let relative_path;
51041a1a4c59 rhg: correctly relativize copy source path
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents: 50361
diff changeset
599 let relative_source;
51041a1a4c59 rhg: correctly relativize copy source path
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents: 50361
diff changeset
600 let (path, copy_source) = if let Some(relativize) =
51041a1a4c59 rhg: correctly relativize copy source path
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents: 50361
diff changeset
601 &self.relativize
51041a1a4c59 rhg: correctly relativize copy source path
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents: 50361
diff changeset
602 {
51041a1a4c59 rhg: correctly relativize copy source path
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents: 50361
diff changeset
603 relative_path = relativize.relativize(&path);
51041a1a4c59 rhg: correctly relativize copy source path
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents: 50361
diff changeset
604 relative_source =
51041a1a4c59 rhg: correctly relativize copy source path
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents: 50361
diff changeset
605 copy_source.as_ref().map(|s| relativize.relativize(s));
51041a1a4c59 rhg: correctly relativize copy source path
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents: 50361
diff changeset
606 (&*relative_path, relative_source.as_deref())
48453
9b0e1f64656f rhg: refactor relativize_path into a struct + method
Simon Sapin <simon.sapin@octobus.net>
parents: 48452
diff changeset
607 } else {
50362
51041a1a4c59 rhg: correctly relativize copy source path
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents: 50361
diff changeset
608 (path.as_bytes(), copy_source.as_ref().map(|s| s.as_bytes()))
48453
9b0e1f64656f rhg: refactor relativize_path into a struct + method
Simon Sapin <simon.sapin@octobus.net>
parents: 48452
diff changeset
609 };
48734
3e2b4bb286e7 rhg: Colorize `rhg status` output when appropriate
Simon Sapin <simon.sapin@octobus.net>
parents: 48729
diff changeset
610 // TODO: Add a way to use `write_bytes!` instead of `format_bytes!`
3e2b4bb286e7 rhg: Colorize `rhg status` output when appropriate
Simon Sapin <simon.sapin@octobus.net>
parents: 48729
diff changeset
611 // in order to stream to stdout instead of allocating an
3e2b4bb286e7 rhg: Colorize `rhg status` output when appropriate
Simon Sapin <simon.sapin@octobus.net>
parents: 48729
diff changeset
612 // itermediate `Vec<u8>`.
3e2b4bb286e7 rhg: Colorize `rhg status` output when appropriate
Simon Sapin <simon.sapin@octobus.net>
parents: 48729
diff changeset
613 if !self.no_status {
3e2b4bb286e7 rhg: Colorize `rhg status` output when appropriate
Simon Sapin <simon.sapin@octobus.net>
parents: 48729
diff changeset
614 self.ui.write_stdout_labelled(status_prefix, label)?
48452
2afaa0145584 rhg: refactor display_status_paths with a struct for common arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 48451
diff changeset
615 }
50427
98fc949bec14 rhg: support `status --print0`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50252
diff changeset
616 let linebreak = if self.print0 { b"\x00" } else { b"\n" };
98fc949bec14 rhg: support `status --print0`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50252
diff changeset
617 self.ui.write_stdout_labelled(
98fc949bec14 rhg: support `status --print0`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50252
diff changeset
618 &format_bytes!(b"{}{}", path, linebreak),
98fc949bec14 rhg: support `status --print0`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50252
diff changeset
619 label,
98fc949bec14 rhg: support `status --print0`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 50252
diff changeset
620 )?;
50361
668a871454e8 rhg: don't print copy source when --no-status is passed
Arun Kulshreshtha <akulshreshtha@janestreet.com>
parents: 50252
diff changeset
621 if let Some(source) = copy_source.filter(|_| !self.no_status) {
48734
3e2b4bb286e7 rhg: Colorize `rhg status` output when appropriate
Simon Sapin <simon.sapin@octobus.net>
parents: 48729
diff changeset
622 let label = "status.copied";
3e2b4bb286e7 rhg: Colorize `rhg status` output when appropriate
Simon Sapin <simon.sapin@octobus.net>
parents: 48729
diff changeset
623 self.ui.write_stdout_labelled(
50463
f57f5ab0e220 branching: merge stable into default
Raphaël Gomès <rgomes@octobus.net>
parents: 50427 50362
diff changeset
624 &format_bytes!(b" {}{}", source, linebreak),
48734
3e2b4bb286e7 rhg: Colorize `rhg status` output when appropriate
Simon Sapin <simon.sapin@octobus.net>
parents: 48729
diff changeset
625 label,
3e2b4bb286e7 rhg: Colorize `rhg status` output when appropriate
Simon Sapin <simon.sapin@octobus.net>
parents: 48729
diff changeset
626 )?
48454
473af5cbc209 rhg: Add support for `rhg status --copies`
Simon Sapin <simon.sapin@octobus.net>
parents: 48453
diff changeset
627 }
48349
c12ed33558cb rhg: Add support for `rhg status -n`
Simon Sapin <simon.sapin@octobus.net>
parents: 48345
diff changeset
628 }
48452
2afaa0145584 rhg: refactor display_status_paths with a struct for common arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 48451
diff changeset
629 Ok(())
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
630 }
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
631 }
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
632
50226
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
633 /// Outcome of the additional check for an ambiguous tracked file
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
634 enum UnsureOutcome {
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
635 /// The file is actually clean
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
636 Clean,
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
637 /// The file has been modified
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
638 Modified,
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
639 /// The file was deleted on disk (or became another type of fs entry)
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
640 Deleted,
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
641 }
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
642
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
643 /// Check if a file is modified by comparing actual repo store and file system.
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
644 ///
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
645 /// This meant to be used for those that the dirstate cannot resolve, due
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
646 /// to time resolution limits.
48344
b6d8eea9872c rhg: Rename cat_file_is_modified
Simon Sapin <simon.sapin@octobus.net>
parents: 48343
diff changeset
647 fn unsure_is_modified(
49517
52464a20add0 rhg: parallellize computation of [unsure_is_modified]
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49516
diff changeset
648 working_directory_vfs: hg::vfs::Vfs,
52464a20add0 rhg: parallellize computation of [unsure_is_modified]
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49516
diff changeset
649 store_vfs: hg::vfs::Vfs,
49894
678588b01af1 rhg: implement checkexec to support weird filesystems
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49640
diff changeset
650 check_exec: bool,
47964
796206e74b10 rhg: Reuse manifest when checking status of multiple ambiguous files
Simon Sapin <simon.sapin@octobus.net>
parents: 47956
diff changeset
651 manifest: &Manifest,
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
652 hg_path: &HgPath,
50226
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
653 ) -> Result<UnsureOutcome, HgError> {
49517
52464a20add0 rhg: parallellize computation of [unsure_is_modified]
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49516
diff changeset
654 let vfs = working_directory_vfs;
48422
000130cfafb6 rhg: Update the dirstate on disk after status
Simon Sapin <simon.sapin@octobus.net>
parents: 48409
diff changeset
655 let fs_path = hg_path_to_path_buf(hg_path).expect("HgPath conversion");
48345
d5a91701f7dc rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents: 48344
diff changeset
656 let fs_metadata = vfs.symlink_metadata(&fs_path)?;
d5a91701f7dc rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents: 48344
diff changeset
657 let is_symlink = fs_metadata.file_type().is_symlink();
49894
678588b01af1 rhg: implement checkexec to support weird filesystems
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49640
diff changeset
658
678588b01af1 rhg: implement checkexec to support weird filesystems
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49640
diff changeset
659 let entry = manifest
678588b01af1 rhg: implement checkexec to support weird filesystems
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49640
diff changeset
660 .find_by_path(hg_path)?
678588b01af1 rhg: implement checkexec to support weird filesystems
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49640
diff changeset
661 .expect("ambgious file not in p1");
678588b01af1 rhg: implement checkexec to support weird filesystems
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49640
diff changeset
662
48391
b80e5e75d51e dirstate: remove `lastnormaltime` mechanism
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48349
diff changeset
663 // TODO: Also account for `FALLBACK_SYMLINK` and `FALLBACK_EXEC` from the
b80e5e75d51e dirstate: remove `lastnormaltime` mechanism
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48349
diff changeset
664 // dirstate
48345
d5a91701f7dc rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents: 48344
diff changeset
665 let fs_flags = if is_symlink {
d5a91701f7dc rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents: 48344
diff changeset
666 Some(b'l')
49894
678588b01af1 rhg: implement checkexec to support weird filesystems
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49640
diff changeset
667 } else if check_exec && has_exec_bit(&fs_metadata) {
48345
d5a91701f7dc rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents: 48344
diff changeset
668 Some(b'x')
d5a91701f7dc rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents: 48344
diff changeset
669 } else {
d5a91701f7dc rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents: 48344
diff changeset
670 None
d5a91701f7dc rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents: 48344
diff changeset
671 };
d5a91701f7dc rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents: 48344
diff changeset
672
49894
678588b01af1 rhg: implement checkexec to support weird filesystems
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49640
diff changeset
673 let entry_flags = if check_exec {
678588b01af1 rhg: implement checkexec to support weird filesystems
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49640
diff changeset
674 entry.flags
49948
70b4c7af9cdb rust-clippy: fix warning about nested ifs
Raphaël Gomès <rgomes@octobus.net>
parents: 49914
diff changeset
675 } else if entry.flags == Some(b'x') {
70b4c7af9cdb rust-clippy: fix warning about nested ifs
Raphaël Gomès <rgomes@octobus.net>
parents: 49914
diff changeset
676 None
49894
678588b01af1 rhg: implement checkexec to support weird filesystems
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49640
diff changeset
677 } else {
49948
70b4c7af9cdb rust-clippy: fix warning about nested ifs
Raphaël Gomès <rgomes@octobus.net>
parents: 49914
diff changeset
678 entry.flags
49894
678588b01af1 rhg: implement checkexec to support weird filesystems
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49640
diff changeset
679 };
678588b01af1 rhg: implement checkexec to support weird filesystems
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49640
diff changeset
680
678588b01af1 rhg: implement checkexec to support weird filesystems
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49640
diff changeset
681 if entry_flags != fs_flags {
50226
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
682 return Ok(UnsureOutcome::Modified);
48345
d5a91701f7dc rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents: 48344
diff changeset
683 }
49517
52464a20add0 rhg: parallellize computation of [unsure_is_modified]
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49516
diff changeset
684 let filelog = hg::filelog::Filelog::open_vfs(&store_vfs, hg_path)?;
48471
b005d07ded7d rhg: Skip reading the contents of ambiguous files in some cases
Simon Sapin <simon.sapin@octobus.net>
parents: 48467
diff changeset
685 let fs_len = fs_metadata.len();
49374
455fce57e89e rust: don't swallow valuable error information
Raphaël Gomès <rgomes@octobus.net>
parents: 49110
diff changeset
686 let file_node = entry.node_id()?;
455fce57e89e rust: don't swallow valuable error information
Raphaël Gomès <rgomes@octobus.net>
parents: 49110
diff changeset
687 let filelog_entry = filelog.entry_for_node(file_node).map_err(|_| {
455fce57e89e rust: don't swallow valuable error information
Raphaël Gomès <rgomes@octobus.net>
parents: 49110
diff changeset
688 HgError::corrupted(format!(
50094
1cffc156f7cd rhg: nicer error message
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49981
diff changeset
689 "filelog {:?} missing node {:?} from manifest",
1cffc156f7cd rhg: nicer error message
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49981
diff changeset
690 hg_path, file_node
49374
455fce57e89e rust: don't swallow valuable error information
Raphaël Gomès <rgomes@octobus.net>
parents: 49110
diff changeset
691 ))
455fce57e89e rust: don't swallow valuable error information
Raphaël Gomès <rgomes@octobus.net>
parents: 49110
diff changeset
692 })?;
48546
e91aa800ae5b rhg: desambiguate status without decompressing filelog if possible
Simon Sapin <simon.sapin@octobus.net>
parents: 48542
diff changeset
693 if filelog_entry.file_data_len_not_equal_to(fs_len) {
e91aa800ae5b rhg: desambiguate status without decompressing filelog if possible
Simon Sapin <simon.sapin@octobus.net>
parents: 48542
diff changeset
694 // No need to read file contents:
e91aa800ae5b rhg: desambiguate status without decompressing filelog if possible
Simon Sapin <simon.sapin@octobus.net>
parents: 48542
diff changeset
695 // it cannot be equal if it has a different length.
50226
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
696 return Ok(UnsureOutcome::Modified);
48546
e91aa800ae5b rhg: desambiguate status without decompressing filelog if possible
Simon Sapin <simon.sapin@octobus.net>
parents: 48542
diff changeset
697 }
e91aa800ae5b rhg: desambiguate status without decompressing filelog if possible
Simon Sapin <simon.sapin@octobus.net>
parents: 48542
diff changeset
698
e91aa800ae5b rhg: desambiguate status without decompressing filelog if possible
Simon Sapin <simon.sapin@octobus.net>
parents: 48542
diff changeset
699 let p1_filelog_data = filelog_entry.data()?;
e91aa800ae5b rhg: desambiguate status without decompressing filelog if possible
Simon Sapin <simon.sapin@octobus.net>
parents: 48542
diff changeset
700 let p1_contents = p1_filelog_data.file_data()?;
e91aa800ae5b rhg: desambiguate status without decompressing filelog if possible
Simon Sapin <simon.sapin@octobus.net>
parents: 48542
diff changeset
701 if p1_contents.len() as u64 != fs_len {
e91aa800ae5b rhg: desambiguate status without decompressing filelog if possible
Simon Sapin <simon.sapin@octobus.net>
parents: 48542
diff changeset
702 // No need to read file contents:
48471
b005d07ded7d rhg: Skip reading the contents of ambiguous files in some cases
Simon Sapin <simon.sapin@octobus.net>
parents: 48467
diff changeset
703 // it cannot be equal if it has a different length.
50226
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
704 return Ok(UnsureOutcome::Modified);
48471
b005d07ded7d rhg: Skip reading the contents of ambiguous files in some cases
Simon Sapin <simon.sapin@octobus.net>
parents: 48467
diff changeset
705 }
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
706
48345
d5a91701f7dc rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents: 48344
diff changeset
707 let fs_contents = if is_symlink {
d5a91701f7dc rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents: 48344
diff changeset
708 get_bytes_from_os_string(vfs.read_link(fs_path)?.into_os_string())
d5a91701f7dc rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents: 48344
diff changeset
709 } else {
d5a91701f7dc rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents: 48344
diff changeset
710 vfs.read(fs_path)?
d5a91701f7dc rhg: Fix status desambiguation of symlinks and executable files
Simon Sapin <simon.sapin@octobus.net>
parents: 48344
diff changeset
711 };
50226
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
712
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
713 Ok(if p1_contents != &*fs_contents {
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
714 UnsureOutcome::Modified
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
715 } else {
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
716 UnsureOutcome::Clean
8fcd5302243a rhg: fix race when an ambiguous file is deleted on disk
Raphaël Gomès <rgomes@octobus.net>
parents: 50225
diff changeset
717 })
46822
c71e8d9e7f2a rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
718 }