forked from mirrors/jj
cli: allow pruning more than one revision
This commit is contained in:
parent
bbbdb11289
commit
440a423b54
1 changed files with 39 additions and 10 deletions
|
@ -249,6 +249,15 @@ impl RepoCommandHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn resolve_revset(&mut self, revision_str: &str) -> Result<Vec<Commit>, CommandError> {
|
||||||
|
let revset_expression = self.parse_revset(revision_str)?;
|
||||||
|
let revset = revset_expression.evaluate(self.repo.as_repo_ref())?;
|
||||||
|
Ok(revset
|
||||||
|
.iter()
|
||||||
|
.map(|entry| self.repo.store().get_commit(&entry.commit_id()).unwrap())
|
||||||
|
.collect())
|
||||||
|
}
|
||||||
|
|
||||||
fn parse_revset(&mut self, revision_str: &str) -> Result<RevsetExpression, CommandError> {
|
fn parse_revset(&mut self, revision_str: &str) -> Result<RevsetExpression, CommandError> {
|
||||||
// If we're looking up the working copy commit ("@"), make sure that it is up to
|
// If we're looking up the working copy commit ("@"), make sure that it is up to
|
||||||
// date (the lib crate only looks at the checkout in the view).
|
// date (the lib crate only looks at the checkout in the view).
|
||||||
|
@ -270,9 +279,16 @@ impl RepoCommandHelper {
|
||||||
|
|
||||||
fn check_rewriteable(&self, commit: &Commit) -> Result<(), CommandError> {
|
fn check_rewriteable(&self, commit: &Commit) -> Result<(), CommandError> {
|
||||||
if commit.id() == self.repo.store().root_commit_id() {
|
if commit.id() == self.repo.store().root_commit_id() {
|
||||||
return Err(CommandError::UserError(String::from(
|
return Err(CommandError::UserError(
|
||||||
"Cannot rewrite the root commit",
|
"Cannot rewrite the root commit".to_string(),
|
||||||
)));
|
));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_non_empty(&self, commits: &[Commit]) -> Result<(), CommandError> {
|
||||||
|
if commits.is_empty() {
|
||||||
|
return Err(CommandError::UserError("Empty revision set".to_string()));
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1488,14 +1504,27 @@ fn cmd_prune(
|
||||||
sub_matches: &ArgMatches,
|
sub_matches: &ArgMatches,
|
||||||
) -> Result<(), CommandError> {
|
) -> Result<(), CommandError> {
|
||||||
let mut repo_command = command.repo_helper(ui)?;
|
let mut repo_command = command.repo_helper(ui)?;
|
||||||
let predecessor = repo_command.resolve_revision_arg(sub_matches)?;
|
let predecessors = repo_command.resolve_revset(sub_matches.value_of("revision").unwrap())?;
|
||||||
repo_command.check_rewriteable(&predecessor)?;
|
repo_command.check_non_empty(&predecessors)?;
|
||||||
|
for predecessor in &predecessors {
|
||||||
|
repo_command.check_rewriteable(&predecessor)?;
|
||||||
|
}
|
||||||
let repo = repo_command.repo();
|
let repo = repo_command.repo();
|
||||||
let mut tx =
|
let transaction_description = if predecessors.len() == 1 {
|
||||||
repo_command.start_transaction(&format!("prune commit {}", predecessor.id().hex()));
|
format!("prune commit {}", predecessors[0].id().hex())
|
||||||
CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &predecessor)
|
} else {
|
||||||
.set_pruned(true)
|
format!(
|
||||||
.write_to_repo(tx.mut_repo());
|
"prune commit {} and {} more",
|
||||||
|
predecessors[0].id().hex(),
|
||||||
|
predecessors.len() - 1
|
||||||
|
)
|
||||||
|
};
|
||||||
|
let mut tx = repo_command.start_transaction(&transaction_description);
|
||||||
|
for predecessor in predecessors {
|
||||||
|
CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &predecessor)
|
||||||
|
.set_pruned(true)
|
||||||
|
.write_to_repo(tx.mut_repo());
|
||||||
|
}
|
||||||
repo_command.finish_transaction(ui, tx)?;
|
repo_command.finish_transaction(ui, tx)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue