mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-24 12:48:55 +00:00
cli: add test of jj debug reindex
, do full reindexing
I broke the commands in a27da7d8d5
and thought I just fixed it in
c7cf914694a8. However, as I added a test, I realized that I made it
only reindex the commits since the previous operation. I meant for the
command to do a full reindexing of th repo. This fixes that.
This commit is contained in:
parent
23bed2731c
commit
504a2b3fd0
3 changed files with 65 additions and 22 deletions
|
@ -66,9 +66,10 @@ impl DefaultIndexStore {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn reinit(&self, op_id: &OperationId) {
|
||||
let op_id_file = self.dir.join("operations").join(op_id.hex());
|
||||
std::fs::remove_file(op_id_file).unwrap();
|
||||
pub fn reinit(&self) {
|
||||
let op_dir = self.dir.join("operations");
|
||||
std::fs::remove_dir_all(&op_dir).unwrap();
|
||||
std::fs::create_dir(op_dir).unwrap();
|
||||
}
|
||||
|
||||
fn load_index_at_operation(
|
||||
|
|
|
@ -3110,9 +3110,8 @@ fn cmd_debug(
|
|||
let default_index_store: Option<&DefaultIndexStore> =
|
||||
repo.index_store().as_any().downcast_ref();
|
||||
if let Some(default_index_store) = default_index_store {
|
||||
let op = repo.operation();
|
||||
default_index_store.reinit(op.id());
|
||||
let repo = repo.reload_at(op);
|
||||
default_index_store.reinit();
|
||||
let repo = repo.reload_at(repo.operation());
|
||||
writeln!(
|
||||
ui,
|
||||
"Finished indexing {:?} commits.",
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
use insta::assert_snapshot;
|
||||
use regex::Regex;
|
||||
|
||||
use crate::common::TestEnvironment;
|
||||
|
||||
|
@ -44,21 +45,63 @@ fn test_debug_index() {
|
|||
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
||||
let workspace_path = test_env.env_root().join("repo");
|
||||
let stdout = test_env.jj_cmd_success(&workspace_path, &["debug", "index"]);
|
||||
insta::with_settings!(
|
||||
{filters => vec![
|
||||
(r" Name: [0-9a-z]+", " Name: [hash]"),
|
||||
]},
|
||||
{
|
||||
assert_snapshot!(stdout, @r###"
|
||||
assert_snapshot!(filter_index_stats(&stdout), @r###"
|
||||
Number of commits: 2
|
||||
Number of merges: 0
|
||||
Max generation number: 1
|
||||
Number of heads: 1
|
||||
Number of changes: 2
|
||||
Stats per level:
|
||||
Level 0:
|
||||
Number of commits: 2
|
||||
Number of merges: 0
|
||||
Max generation number: 1
|
||||
Number of heads: 1
|
||||
Number of changes: 2
|
||||
Stats per level:
|
||||
Level 0:
|
||||
Number of commits: 2
|
||||
Name: [hash]
|
||||
"###)
|
||||
});
|
||||
Name: [hash]
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_debug_reindex() {
|
||||
let test_env = TestEnvironment::default();
|
||||
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
||||
let workspace_path = test_env.env_root().join("repo");
|
||||
test_env.jj_cmd_success(&workspace_path, &["new"]);
|
||||
test_env.jj_cmd_success(&workspace_path, &["new"]);
|
||||
let stdout = test_env.jj_cmd_success(&workspace_path, &["debug", "index"]);
|
||||
assert_snapshot!(filter_index_stats(&stdout), @r###"
|
||||
Number of commits: 4
|
||||
Number of merges: 0
|
||||
Max generation number: 3
|
||||
Number of heads: 1
|
||||
Number of changes: 4
|
||||
Stats per level:
|
||||
Level 0:
|
||||
Number of commits: 3
|
||||
Name: [hash]
|
||||
Level 1:
|
||||
Number of commits: 1
|
||||
Name: [hash]
|
||||
"###
|
||||
);
|
||||
let stdout = test_env.jj_cmd_success(&workspace_path, &["debug", "reindex"]);
|
||||
assert_snapshot!(stdout, @r###"
|
||||
Finished indexing 4 commits.
|
||||
"###);
|
||||
let stdout = test_env.jj_cmd_success(&workspace_path, &["debug", "index"]);
|
||||
assert_snapshot!(filter_index_stats(&stdout), @r###"
|
||||
Number of commits: 4
|
||||
Number of merges: 0
|
||||
Max generation number: 3
|
||||
Number of heads: 1
|
||||
Number of changes: 4
|
||||
Stats per level:
|
||||
Level 0:
|
||||
Number of commits: 4
|
||||
Name: [hash]
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
fn filter_index_stats(text: &str) -> String {
|
||||
let regex = Regex::new(r" Name: [0-9a-z]+").unwrap();
|
||||
regex.replace_all(text, " Name: [hash]").to_string()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue