Mercurial > hg
annotate rust/hg-core/src/operations/list_tracked_files.rs @ 46167:8a4914397d02
rust: introduce Repo and Vfs types for filesystem abstraction
This is similar to the corresponding Python classes.
Repo represents a repository and knows the path to the `.hg` directory,
the `store` directory, and the working directory.
Separating these will enable supporting the share extension.
A Vfs is created from a Repo for one of these three directories.
It has filesystem access APIs that take a relative std::path::Path
as a parameter.
Differential Revision: https://phab.mercurial-scm.org/D9596
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Mon, 14 Dec 2020 16:33:15 +0100 |
parents | dca9cb99971c |
children | 645ee7225fab |
rev | line source |
---|---|
45359
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
1 // list_tracked_files.rs |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
2 // |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
3 // Copyright 2020 Antoine Cezar <antoine.cezar@octobus.net> |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
4 // |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
5 // This software may be used and distributed according to the terms of the |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
6 // GNU General Public License version 2 or any later version. |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
7 |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
8 use crate::dirstate::parsers::parse_dirstate; |
46167
8a4914397d02
rust: introduce Repo and Vfs types for filesystem abstraction
Simon Sapin <simon.sapin@octobus.net>
parents:
46135
diff
changeset
|
9 use crate::repo::Repo; |
45536
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
10 use crate::revlog::changelog::Changelog; |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
11 use crate::revlog::manifest::{Manifest, ManifestEntry}; |
46033
88e741bf2d93
rust: use NodePrefix::from_hex instead of hex::decode directly
Simon Sapin <simon-commits@exyr.org>
parents:
46032
diff
changeset
|
12 use crate::revlog::node::{Node, NodePrefix}; |
45536
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
13 use crate::revlog::revlog::RevlogError; |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
14 use crate::revlog::Revision; |
45359
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
15 use crate::utils::hg_path::HgPath; |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
16 use crate::{DirstateParseError, EntryState}; |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
17 use rayon::prelude::*; |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
18 use std::convert::From; |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
19 |
45535
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
20 /// Kind of error encountered by `ListDirstateTrackedFiles` |
45359
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
21 #[derive(Debug)] |
45535
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
22 pub enum ListDirstateTrackedFilesErrorKind { |
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
23 /// Error when reading the `dirstate` file |
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
24 IoError(std::io::Error), |
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
25 /// Error when parsing the `dirstate` file |
45359
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
26 ParseError(DirstateParseError), |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
27 } |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
28 |
45535
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
29 /// A `ListDirstateTrackedFiles` error |
45359
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
30 #[derive(Debug)] |
45535
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
31 pub struct ListDirstateTrackedFilesError { |
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
32 /// Kind of error encountered by `ListDirstateTrackedFiles` |
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
33 pub kind: ListDirstateTrackedFilesErrorKind, |
45359
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
34 } |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
35 |
45535
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
36 impl From<ListDirstateTrackedFilesErrorKind> |
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
37 for ListDirstateTrackedFilesError |
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
38 { |
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
39 fn from(kind: ListDirstateTrackedFilesErrorKind) -> Self { |
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
40 ListDirstateTrackedFilesError { kind } |
45359
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
41 } |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
42 } |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
43 |
45535
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
44 impl From<std::io::Error> for ListDirstateTrackedFilesError { |
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
45 fn from(err: std::io::Error) -> Self { |
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
46 let kind = ListDirstateTrackedFilesErrorKind::IoError(err); |
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
47 ListDirstateTrackedFilesError { kind } |
45436
1b3197047f5c
rhg: make output of `files` relative to the current directory and the root
Raphaël Gomès <rgomes@octobus.net>
parents:
45359
diff
changeset
|
48 } |
45359
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
49 } |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
50 |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
51 /// List files under Mercurial control in the working directory |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
52 /// by reading the dirstate |
46135
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
53 pub struct Dirstate { |
45535
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
54 /// The `dirstate` content. |
45359
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
55 content: Vec<u8>, |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
56 } |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
57 |
46135
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
58 impl Dirstate { |
46167
8a4914397d02
rust: introduce Repo and Vfs types for filesystem abstraction
Simon Sapin <simon.sapin@octobus.net>
parents:
46135
diff
changeset
|
59 pub fn new(repo: &Repo) -> Result<Self, ListDirstateTrackedFilesError> { |
8a4914397d02
rust: introduce Repo and Vfs types for filesystem abstraction
Simon Sapin <simon.sapin@octobus.net>
parents:
46135
diff
changeset
|
60 let content = repo.hg_vfs().read("dirstate")?; |
45535
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
61 Ok(Self { content }) |
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
62 } |
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
63 |
46135
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
64 pub fn tracked_files( |
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
65 &self, |
45535
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
66 ) -> Result<Vec<&HgPath>, ListDirstateTrackedFilesError> { |
45359
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
67 let (_, entries, _) = parse_dirstate(&self.content) |
45535
72b7d58d6e35
hg-core: simplify `list_tracked_files` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45436
diff
changeset
|
68 .map_err(ListDirstateTrackedFilesErrorKind::ParseError)?; |
45359
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
69 let mut files: Vec<&HgPath> = entries |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
70 .into_iter() |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
71 .filter_map(|(path, entry)| match entry.state { |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
72 EntryState::Removed => None, |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
73 _ => Some(path), |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
74 }) |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
75 .collect(); |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
76 files.par_sort_unstable(); |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
77 Ok(files) |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
78 } |
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
79 } |
45536
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
80 |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
81 /// Kind of error encountered by `ListRevTrackedFiles` |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
82 #[derive(Debug)] |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
83 pub enum ListRevTrackedFilesErrorKind { |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
84 /// Error when reading a `revlog` file. |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
85 IoError(std::io::Error), |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
86 /// The revision has not been found. |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
87 InvalidRevision, |
46032
8d6164098782
rhg: allow specifying a changeset ID prefix
Simon Sapin <simon-commits@exyr.org>
parents:
45603
diff
changeset
|
88 /// Found more than one revision whose ID match the requested prefix |
8d6164098782
rhg: allow specifying a changeset ID prefix
Simon Sapin <simon-commits@exyr.org>
parents:
45603
diff
changeset
|
89 AmbiguousPrefix, |
45536
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
90 /// A `revlog` file is corrupted. |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
91 CorruptedRevlog, |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
92 /// The `revlog` format version is not supported. |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
93 UnsuportedRevlogVersion(u16), |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
94 /// The `revlog` data format is not supported. |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
95 UnknowRevlogDataFormat(u8), |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
96 } |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
97 |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
98 /// A `ListRevTrackedFiles` error |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
99 #[derive(Debug)] |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
100 pub struct ListRevTrackedFilesError { |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
101 /// Kind of error encountered by `ListRevTrackedFiles` |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
102 pub kind: ListRevTrackedFilesErrorKind, |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
103 } |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
104 |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
105 impl From<ListRevTrackedFilesErrorKind> for ListRevTrackedFilesError { |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
106 fn from(kind: ListRevTrackedFilesErrorKind) -> Self { |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
107 ListRevTrackedFilesError { kind } |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
108 } |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
109 } |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
110 |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
111 impl From<RevlogError> for ListRevTrackedFilesError { |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
112 fn from(err: RevlogError) -> Self { |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
113 match err { |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
114 RevlogError::IoError(err) => { |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
115 ListRevTrackedFilesErrorKind::IoError(err) |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
116 } |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
117 RevlogError::UnsuportedVersion(version) => { |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
118 ListRevTrackedFilesErrorKind::UnsuportedRevlogVersion(version) |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
119 } |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
120 RevlogError::InvalidRevision => { |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
121 ListRevTrackedFilesErrorKind::InvalidRevision |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
122 } |
46032
8d6164098782
rhg: allow specifying a changeset ID prefix
Simon Sapin <simon-commits@exyr.org>
parents:
45603
diff
changeset
|
123 RevlogError::AmbiguousPrefix => { |
8d6164098782
rhg: allow specifying a changeset ID prefix
Simon Sapin <simon-commits@exyr.org>
parents:
45603
diff
changeset
|
124 ListRevTrackedFilesErrorKind::AmbiguousPrefix |
8d6164098782
rhg: allow specifying a changeset ID prefix
Simon Sapin <simon-commits@exyr.org>
parents:
45603
diff
changeset
|
125 } |
45536
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
126 RevlogError::Corrupted => { |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
127 ListRevTrackedFilesErrorKind::CorruptedRevlog |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
128 } |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
129 RevlogError::UnknowDataFormat(format) => { |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
130 ListRevTrackedFilesErrorKind::UnknowRevlogDataFormat(format) |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
131 } |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
132 } |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
133 .into() |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
134 } |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
135 } |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
136 |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
137 /// List files under Mercurial control at a given revision. |
46135
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
138 pub fn list_rev_tracked_files( |
46167
8a4914397d02
rust: introduce Repo and Vfs types for filesystem abstraction
Simon Sapin <simon.sapin@octobus.net>
parents:
46135
diff
changeset
|
139 repo: &Repo, |
46135
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
140 rev: &str, |
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
141 ) -> Result<FilesForRev, ListRevTrackedFilesError> { |
46167
8a4914397d02
rust: introduce Repo and Vfs types for filesystem abstraction
Simon Sapin <simon.sapin@octobus.net>
parents:
46135
diff
changeset
|
142 let changelog = Changelog::open(repo)?; |
8a4914397d02
rust: introduce Repo and Vfs types for filesystem abstraction
Simon Sapin <simon.sapin@octobus.net>
parents:
46135
diff
changeset
|
143 let manifest = Manifest::open(repo)?; |
46135
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
144 |
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
145 let changelog_entry = match rev.parse::<Revision>() { |
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
146 Ok(rev) => changelog.get_rev(rev)?, |
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
147 _ => { |
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
148 let changelog_node = NodePrefix::from_hex(&rev) |
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
149 .or(Err(ListRevTrackedFilesErrorKind::InvalidRevision))?; |
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
150 changelog.get_node(changelog_node.borrow())? |
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
151 } |
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
152 }; |
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
153 let manifest_node = Node::from_hex(&changelog_entry.manifest_node()?) |
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
154 .or(Err(ListRevTrackedFilesErrorKind::CorruptedRevlog))?; |
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
155 let manifest_entry = manifest.get_node((&manifest_node).into())?; |
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
156 Ok(FilesForRev(manifest_entry)) |
45536
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
157 } |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
158 |
46135
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
159 pub struct FilesForRev(ManifestEntry); |
45536
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
160 |
46135
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
161 impl FilesForRev { |
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
162 pub fn iter(&self) -> impl Iterator<Item = &HgPath> { |
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
163 self.0.files() |
45536
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
164 } |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
165 } |