author | Raphaël Gomès <rgomes@octobus.net> |
Thu, 10 Aug 2023 11:00:34 +0200 | |
changeset 50977 | 1928b770e3e7 |
parent 49985 | e57f76c28f7b |
permissions | -rw-r--r-- |
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 |
|
46443
43d63979a75e
rust: use HgError in RevlogError and Vfs
Simon Sapin <simon.sapin@octobus.net>
parents:
46440
diff
changeset
|
8 |
use crate::errors::HgError; |
49985
e57f76c28f7b
rhg-files: add support for narrow when specifying a revision
Raphaël Gomès <rgomes@octobus.net>
parents:
49980
diff
changeset
|
9 |
use crate::matchers::Matcher; |
46167
8a4914397d02
rust: introduce Repo and Vfs types for filesystem abstraction
Simon Sapin <simon.sapin@octobus.net>
parents:
46135
diff
changeset
|
10 |
use crate::repo::Repo; |
47959
21d25e9ee58e
rust: Keep lazily-initialized Changelog and Manifest log on the Repo object
Simon Sapin <simon.sapin@octobus.net>
parents:
47957
diff
changeset
|
11 |
use crate::revlog::manifest::Manifest; |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
49136
diff
changeset
|
12 |
use crate::revlog::RevlogError; |
49985
e57f76c28f7b
rhg-files: add support for narrow when specifying a revision
Raphaël Gomès <rgomes@octobus.net>
parents:
49980
diff
changeset
|
13 |
use crate::utils::filter_map_results; |
45359
0f5286ccf82c
hg-core: define a `ListTrackedFiles` `Operation`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
14 |
use crate::utils::hg_path::HgPath; |
45536
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
15 |
|
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
16 |
/// 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
|
17 |
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
|
18 |
repo: &Repo, |
46433
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
46431
diff
changeset
|
19 |
revset: &str, |
49985
e57f76c28f7b
rhg-files: add support for narrow when specifying a revision
Raphaël Gomès <rgomes@octobus.net>
parents:
49980
diff
changeset
|
20 |
narrow_matcher: Box<dyn Matcher>, |
46437
b274aa2f20fd
rust: remove three enums that were identical to `RevlogError`
Simon Sapin <simon.sapin@octobus.net>
parents:
46435
diff
changeset
|
21 |
) -> Result<FilesForRev, RevlogError> { |
46433
4b381dbbf8b7
rhg: centralize parsing of `--rev` CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
46431
diff
changeset
|
22 |
let rev = crate::revset::resolve_single(revset, repo)?; |
49985
e57f76c28f7b
rhg-files: add support for narrow when specifying a revision
Raphaël Gomès <rgomes@octobus.net>
parents:
49980
diff
changeset
|
23 |
Ok(FilesForRev { |
50977
1928b770e3e7
rust: use the new `UncheckedRevision` everywhere applicable
Raphaël Gomès <rgomes@octobus.net>
parents:
49985
diff
changeset
|
24 |
manifest: repo.manifest_for_rev(rev.into())?, |
49985
e57f76c28f7b
rhg-files: add support for narrow when specifying a revision
Raphaël Gomès <rgomes@octobus.net>
parents:
49980
diff
changeset
|
25 |
narrow_matcher, |
e57f76c28f7b
rhg-files: add support for narrow when specifying a revision
Raphaël Gomès <rgomes@octobus.net>
parents:
49980
diff
changeset
|
26 |
}) |
45536
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
27 |
} |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
28 |
|
49985
e57f76c28f7b
rhg-files: add support for narrow when specifying a revision
Raphaël Gomès <rgomes@octobus.net>
parents:
49980
diff
changeset
|
29 |
pub struct FilesForRev { |
e57f76c28f7b
rhg-files: add support for narrow when specifying a revision
Raphaël Gomès <rgomes@octobus.net>
parents:
49980
diff
changeset
|
30 |
manifest: Manifest, |
e57f76c28f7b
rhg-files: add support for narrow when specifying a revision
Raphaël Gomès <rgomes@octobus.net>
parents:
49980
diff
changeset
|
31 |
narrow_matcher: Box<dyn Matcher>, |
e57f76c28f7b
rhg-files: add support for narrow when specifying a revision
Raphaël Gomès <rgomes@octobus.net>
parents:
49980
diff
changeset
|
32 |
} |
45536
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
33 |
|
46135
dca9cb99971c
rust: replace most "operation" structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46134
diff
changeset
|
34 |
impl FilesForRev { |
48342
10c32e1b892a
rhg: Propogate manifest parse errors instead of panicking
Simon Sapin <simon.sapin@octobus.net>
parents:
48022
diff
changeset
|
35 |
pub fn iter(&self) -> impl Iterator<Item = Result<&HgPath, HgError>> { |
49985
e57f76c28f7b
rhg-files: add support for narrow when specifying a revision
Raphaël Gomès <rgomes@octobus.net>
parents:
49980
diff
changeset
|
36 |
filter_map_results(self.manifest.iter(), |entry| { |
e57f76c28f7b
rhg-files: add support for narrow when specifying a revision
Raphaël Gomès <rgomes@octobus.net>
parents:
49980
diff
changeset
|
37 |
let path = entry.path; |
e57f76c28f7b
rhg-files: add support for narrow when specifying a revision
Raphaël Gomès <rgomes@octobus.net>
parents:
49980
diff
changeset
|
38 |
Ok(if self.narrow_matcher.matches(path) { |
e57f76c28f7b
rhg-files: add support for narrow when specifying a revision
Raphaël Gomès <rgomes@octobus.net>
parents:
49980
diff
changeset
|
39 |
Some(path) |
e57f76c28f7b
rhg-files: add support for narrow when specifying a revision
Raphaël Gomès <rgomes@octobus.net>
parents:
49980
diff
changeset
|
40 |
} else { |
e57f76c28f7b
rhg-files: add support for narrow when specifying a revision
Raphaël Gomès <rgomes@octobus.net>
parents:
49980
diff
changeset
|
41 |
None |
e57f76c28f7b
rhg-files: add support for narrow when specifying a revision
Raphaël Gomès <rgomes@octobus.net>
parents:
49980
diff
changeset
|
42 |
}) |
e57f76c28f7b
rhg-files: add support for narrow when specifying a revision
Raphaël Gomès <rgomes@octobus.net>
parents:
49980
diff
changeset
|
43 |
}) |
45536
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
44 |
} |
639f33f22faf
hg-core: add a `ListRevTrackedFiles` operation
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45535
diff
changeset
|
45 |
} |