comparison rust/rhg/src/commands/files.rs @ 48457:005ae1a343f8

rhg: add support for narrow clones and sparse checkouts This adds a minimal support that can be implemented without parsing the narrowspec. We can parse the narrowspec and add support for more operations later. The reason we need so few code changes is as follows: Most operations need no special treatment of sparse because some of them only read dirstate (`rhg files` without `-r`), which bakes in the filtering, some of them only read store (`rhg files -r`, `rhg cat`), and some of them read no data at all (`rhg root`, `rhg debugrequirements`). `status` is the command that might care about sparse, so we just disable rhg on it. For narrow clones, `rhg files` clearly needs the narrowspec to work correctly, so we fall back. `rhg cat` seems to work consistently with `hg cat` if the file exists. If the file is hidden by narrow spec, the error message is different and confusing, so that's something that we should improve in follow-up patches. Differential Revision: https://phab.mercurial-scm.org/D11764
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Tue, 16 Nov 2021 11:53:58 +0000
parents 10c32e1b892a
children 9b0e1f64656f
comparison
equal deleted inserted replaced
48456:f77e4daaf612 48457:005ae1a343f8
38 } 38 }
39 39
40 let rev = invocation.subcommand_args.value_of("rev"); 40 let rev = invocation.subcommand_args.value_of("rev");
41 41
42 let repo = invocation.repo?; 42 let repo = invocation.repo?;
43
44 // It seems better if this check is removed: this would correspond to
45 // automatically enabling the extension if the repo requires it.
46 // However we need this check to be in sync with vanilla hg so hg tests
47 // pass.
48 if repo.has_sparse()
49 && invocation.config.get(b"extensions", b"sparse").is_none()
50 {
51 return Err(CommandError::unsupported(
52 "repo is using sparse, but sparse extension is not enabled",
53 ));
54 }
55
43 if let Some(rev) = rev { 56 if let Some(rev) = rev {
57 if repo.has_narrow() {
58 return Err(CommandError::unsupported(
59 "rhg files -r <rev> is not supported in narrow clones",
60 ));
61 }
44 let files = list_rev_tracked_files(repo, rev).map_err(|e| (e, rev))?; 62 let files = list_rev_tracked_files(repo, rev).map_err(|e| (e, rev))?;
45 display_files(invocation.ui, repo, files.iter()) 63 display_files(invocation.ui, repo, files.iter())
46 } else { 64 } else {
65 // The dirstate always reflects the sparse narrowspec, so if
66 // we only have sparse without narrow all is fine.
67 // If we have narrow, then [hg files] needs to check if
68 // the store narrowspec is in sync with the one of the dirstate,
69 // so we can't support that without explicit code.
70 if repo.has_narrow() {
71 return Err(CommandError::unsupported(
72 "rhg files is not supported in narrow clones",
73 ));
74 }
47 let distate = Dirstate::new(repo)?; 75 let distate = Dirstate::new(repo)?;
48 let files = distate.tracked_files()?; 76 let files = distate.tracked_files()?;
49 display_files(invocation.ui, repo, files.into_iter().map(Ok)) 77 display_files(invocation.ui, repo, files.into_iter().map(Ok))
50 } 78 }
51 } 79 }