Mercurial > hg
annotate rust/rhg/src/commands/status.rs @ 47674:ff97e793ed36
dirstate-v2: Introduce a docket file
.hg/dirstate now only contains some metadata to point to a separate data file
named .hg/dirstate.{}.d with a random hexadecimal identifier. For now every
update creates a new data file and removes the old one, but later we’ll
(usually) append to an existing file.
Separating into two files allows doing the "write to a temporary file then
atomically rename into destination" dance with only a small docket file,
without always rewriting a lot of data.
Differential Revision: https://phab.mercurial-scm.org/D11088
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Thu, 08 Jul 2021 12:18:21 +0200 |
parents | bd88b6bfd8da |
children | 48aec076b8fb |
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; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
9 use crate::ui::Ui; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
10 use clap::{Arg, SubCommand}; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
11 use hg; |
47374
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47322
diff
changeset
|
12 use hg::dirstate_tree::dirstate_map::DirstateMap; |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
13 use hg::dirstate_tree::on_disk; |
47322
1760de72a992
rhg: A missing .hg/dirstate file is not an error
Simon Sapin <simon.sapin@octobus.net>
parents:
47321
diff
changeset
|
14 use hg::errors::HgResultExt; |
46822
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
15 use hg::errors::IoResultExt; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
16 use hg::matchers::AlwaysMatcher; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
17 use hg::operations::cat; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
18 use hg::repo::Repo; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
19 use hg::revlog::node::Node; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
20 use hg::utils::hg_path::{hg_path_to_os_string, HgPath}; |
47374
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47322
diff
changeset
|
21 use hg::StatusError; |
46822
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
22 use hg::{HgPathCow, StatusOptions}; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
23 use log::{info, warn}; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
24 use std::convert::TryInto; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
25 use std::fs; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
26 use std::io::BufReader; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
27 use std::io::Read; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
28 |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
29 pub const HELP_TEXT: &str = " |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
30 Show changed files in the working directory |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
31 |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
32 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
|
33 |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
34 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
|
35 "; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
36 |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
37 pub fn args() -> clap::App<'static, 'static> { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
38 SubCommand::with_name("status") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
39 .alias("st") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
40 .about(HELP_TEXT) |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
41 .arg( |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
42 Arg::with_name("all") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
43 .help("show status of all files") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
44 .short("-A") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
45 .long("--all"), |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
46 ) |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
47 .arg( |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
48 Arg::with_name("modified") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
49 .help("show only modified files") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
50 .short("-m") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
51 .long("--modified"), |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
52 ) |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
53 .arg( |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
54 Arg::with_name("added") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
55 .help("show only added files") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
56 .short("-a") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
57 .long("--added"), |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
58 ) |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
59 .arg( |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
60 Arg::with_name("removed") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
61 .help("show only removed files") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
62 .short("-r") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
63 .long("--removed"), |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
64 ) |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
65 .arg( |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
66 Arg::with_name("clean") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
67 .help("show only clean files") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
68 .short("-c") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
69 .long("--clean"), |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
70 ) |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
71 .arg( |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
72 Arg::with_name("deleted") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
73 .help("show only deleted files") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
74 .short("-d") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
75 .long("--deleted"), |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
76 ) |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
77 .arg( |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
78 Arg::with_name("unknown") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
79 .help("show only unknown (not tracked) files") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
80 .short("-u") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
81 .long("--unknown"), |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
82 ) |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
83 .arg( |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
84 Arg::with_name("ignored") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
85 .help("show only ignored files") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
86 .short("-i") |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
87 .long("--ignored"), |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
88 ) |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
89 } |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
90 |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
91 /// 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
|
92 #[derive(Copy, Clone, Debug)] |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
93 pub struct DisplayStates { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
94 pub modified: bool, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
95 pub added: bool, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
96 pub removed: bool, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
97 pub clean: bool, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
98 pub deleted: bool, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
99 pub unknown: bool, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
100 pub ignored: bool, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
101 } |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
102 |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
103 pub const DEFAULT_DISPLAY_STATES: DisplayStates = DisplayStates { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
104 modified: true, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
105 added: true, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
106 removed: true, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
107 clean: false, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
108 deleted: true, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
109 unknown: true, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
110 ignored: false, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
111 }; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
112 |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
113 pub const ALL_DISPLAY_STATES: DisplayStates = DisplayStates { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
114 modified: true, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
115 added: true, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
116 removed: true, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
117 clean: true, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
118 deleted: true, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
119 unknown: true, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
120 ignored: true, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
121 }; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
122 |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
123 impl DisplayStates { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
124 pub fn is_empty(&self) -> bool { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
125 !(self.modified |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
126 || self.added |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
127 || self.removed |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
128 || self.clean |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
129 || self.deleted |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
130 || self.unknown |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
131 || self.ignored) |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
132 } |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
133 } |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
134 |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
135 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
136 let status_enabled_default = false; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
137 let status_enabled = invocation.config.get_option(b"rhg", b"status")?; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
138 if !status_enabled.unwrap_or(status_enabled_default) { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
139 return Err(CommandError::unsupported( |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
140 "status is experimental in rhg (enable it with 'rhg.status = true' \ |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
141 or enable fallback with 'rhg.on-unsupported = fallback')" |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
142 )); |
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 let ui = invocation.ui; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
146 let args = invocation.subcommand_args; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
147 let display_states = if args.is_present("all") { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
148 // 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
|
149 // from `--all` |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
150 ALL_DISPLAY_STATES |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
151 } else { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
152 let requested = DisplayStates { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
153 modified: args.is_present("modified"), |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
154 added: args.is_present("added"), |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
155 removed: args.is_present("removed"), |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
156 clean: args.is_present("clean"), |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
157 deleted: args.is_present("deleted"), |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
158 unknown: args.is_present("unknown"), |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
159 ignored: args.is_present("ignored"), |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
160 }; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
161 if requested.is_empty() { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
162 DEFAULT_DISPLAY_STATES |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
163 } else { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
164 requested |
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 |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
168 let repo = invocation.repo?; |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
169 let dirstate_data_mmap; |
47374
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47322
diff
changeset
|
170 let (mut dmap, parents) = if repo.has_dirstate_v2() { |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
171 let parents; |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
172 let dirstate_data; |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
173 if let Some(docket_data) = |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
174 repo.hg_vfs().read("dirstate").io_not_found_as_none()? |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
175 { |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
176 let docket = on_disk::read_docket(&docket_data)?; |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
177 parents = Some(docket.parents()); |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
178 dirstate_data_mmap = repo |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
179 .hg_vfs() |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
180 .mmap_open(docket.data_filename()) |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
181 .io_not_found_as_none()?; |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
182 dirstate_data = dirstate_data_mmap.as_deref().unwrap_or(b""); |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
183 } else { |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
184 parents = None; |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
185 dirstate_data = b""; |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
186 } |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
187 let dmap = DirstateMap::new_v2(dirstate_data)?; |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
188 (dmap, parents) |
47374
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47322
diff
changeset
|
189 } else { |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
190 dirstate_data_mmap = |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
191 repo.hg_vfs().mmap_open("dirstate").io_not_found_as_none()?; |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
192 let dirstate_data = dirstate_data_mmap.as_deref().unwrap_or(b""); |
47374
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47322
diff
changeset
|
193 DirstateMap::new_v1(dirstate_data)? |
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47322
diff
changeset
|
194 }; |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47374
diff
changeset
|
195 |
46822
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
196 let options = StatusOptions { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
197 // TODO should be provided by the dirstate parsing and |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
198 // hence be stored on dmap. Using a value that assumes we aren't |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
199 // below the time resolution granularity of the FS and the |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
200 // dirstate. |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
201 last_normal_time: 0, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
202 // we're currently supporting file systems with exec flags only |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
203 // anyway |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
204 check_exec: true, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
205 list_clean: display_states.clean, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
206 list_unknown: display_states.unknown, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
207 list_ignored: display_states.ignored, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
208 collect_traversed_dirs: false, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
209 }; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
210 let ignore_file = repo.working_directory_vfs().join(".hgignore"); // TODO hardcoded |
47374
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47322
diff
changeset
|
211 let (mut ds_status, pattern_warnings) = hg::dirstate_tree::status::status( |
bd88b6bfd8da
rhg: Add support for dirstate-v2
Simon Sapin <simon.sapin@octobus.net>
parents:
47322
diff
changeset
|
212 &mut dmap, |
46822
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
213 &AlwaysMatcher, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
214 repo.working_directory_path().to_owned(), |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
215 vec![ignore_file], |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
216 options, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
217 )?; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
218 if !pattern_warnings.is_empty() { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
219 warn!("Pattern warnings: {:?}", &pattern_warnings); |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
220 } |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
221 |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
222 if !ds_status.bad.is_empty() { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
223 warn!("Bad matches {:?}", &(ds_status.bad)) |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
224 } |
47110
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
46822
diff
changeset
|
225 if !ds_status.unsure.is_empty() { |
46822
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
226 info!( |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
227 "Files to be rechecked by retrieval from filelog: {:?}", |
47110
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
46822
diff
changeset
|
228 &ds_status.unsure |
46822
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
229 ); |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
230 } |
47321
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
231 if !ds_status.unsure.is_empty() |
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
232 && (display_states.modified || display_states.clean) |
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
233 { |
46822
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
234 let p1: Node = parents |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
235 .expect( |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
236 "Dirstate with no parents should not list any file to |
47321
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
237 be rechecked for modifications", |
46822
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
238 ) |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
239 .p1 |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
240 .into(); |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
241 let p1_hex = format!("{:x}", p1); |
47110
9c6b458a08e1
rust: Move "lookup" a.k.a. "unsure" paths into `DirstateStatus` struct
Simon Sapin <simon.sapin@octobus.net>
parents:
46822
diff
changeset
|
242 for to_check in ds_status.unsure { |
46822
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
243 if cat_file_is_modified(repo, &to_check, &p1_hex)? { |
47321
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
244 if display_states.modified { |
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
245 ds_status.modified.push(to_check); |
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
246 } |
46822
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
247 } else { |
47321
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
248 if display_states.clean { |
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
249 ds_status.clean.push(to_check); |
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
250 } |
46822
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
251 } |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
252 } |
47321
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
253 } |
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
254 if display_states.modified { |
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
255 display_status_paths(ui, &mut ds_status.modified, b"M")?; |
46822
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
256 } |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
257 if display_states.added { |
47321
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
258 display_status_paths(ui, &mut ds_status.added, b"A")?; |
46822
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
259 } |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
260 if display_states.removed { |
47321
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
261 display_status_paths(ui, &mut ds_status.removed, b"R")?; |
46822
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
262 } |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
263 if display_states.deleted { |
47321
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
264 display_status_paths(ui, &mut ds_status.deleted, b"!")?; |
46822
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
265 } |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
266 if display_states.unknown { |
47321
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
267 display_status_paths(ui, &mut ds_status.unknown, b"?")?; |
46822
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
268 } |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
269 if display_states.ignored { |
47321
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
270 display_status_paths(ui, &mut ds_status.ignored, b"I")?; |
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
271 } |
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
272 if display_states.clean { |
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
273 display_status_paths(ui, &mut ds_status.clean, b"C")?; |
46822
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
274 } |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
275 Ok(()) |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
276 } |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
277 |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
278 // Probably more elegant to use a Deref or Borrow trait rather than |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
279 // harcode HgPathBuf, but probably not really useful at this point |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
280 fn display_status_paths( |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
281 ui: &Ui, |
47321
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
282 paths: &mut [HgPathCow], |
46822
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
283 status_prefix: &[u8], |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
284 ) -> Result<(), CommandError> { |
47321
62225f9da938
rhg: Sort `rhg status` output correctly
Simon Sapin <simon.sapin@octobus.net>
parents:
47110
diff
changeset
|
285 paths.sort_unstable(); |
46822
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
286 for path in paths { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
287 // Same TODO as in commands::root |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
288 let bytes: &[u8] = path.as_bytes(); |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
289 // TODO optim, probably lots of unneeded copies here, especially |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
290 // if out stream is buffered |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
291 ui.write_stdout(&[status_prefix, b" ", bytes, b"\n"].concat())?; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
292 } |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
293 Ok(()) |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
294 } |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
295 |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
296 /// 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
|
297 /// |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
298 /// 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
|
299 /// to time resolution limits. |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
300 /// |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
301 /// TODO: detect permission bits and similar metadata modifications |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
302 fn cat_file_is_modified( |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
303 repo: &Repo, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
304 hg_path: &HgPath, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
305 rev: &str, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
306 ) -> Result<bool, CommandError> { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
307 // TODO CatRev expects &[HgPathBuf], something like |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
308 // &[impl Deref<HgPath>] would be nicer and should avoid the copy |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
309 let path_bufs = [hg_path.into()]; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
310 // TODO IIUC CatRev returns a simple Vec<u8> for all files |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
311 // being able to tell them apart as (path, bytes) would be nicer |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
312 // and OPTIM would allow manifest resolution just once. |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
313 let output = cat(repo, rev, &path_bufs).map_err(|e| (e, rev))?; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
314 |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
315 let fs_path = repo |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
316 .working_directory_vfs() |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
317 .join(hg_path_to_os_string(hg_path).expect("HgPath conversion")); |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
318 let hg_data_len: u64 = match output.concatenated.len().try_into() { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
319 Ok(v) => v, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
320 Err(_) => { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
321 // conversion of data length to u64 failed, |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
322 // good luck for any file to have this content |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
323 return Ok(true); |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
324 } |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
325 }; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
326 let fobj = fs::File::open(&fs_path).when_reading_file(&fs_path)?; |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
327 if fobj.metadata().map_err(|e| StatusError::from(e))?.len() != hg_data_len |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
328 { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
329 return Ok(true); |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
330 } |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
331 for (fs_byte, hg_byte) in |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
332 BufReader::new(fobj).bytes().zip(output.concatenated) |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
333 { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
334 if fs_byte.map_err(|e| StatusError::from(e))? != hg_byte { |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
335 return Ok(true); |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
336 } |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
337 } |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
338 Ok(false) |
c71e8d9e7f2a
rhg: Initial support for the 'status' command
Georges Racinet <georges.racinet@octobus.net>
parents:
diff
changeset
|
339 } |