cli_util: add a helper for creating a Transaction without owning a Workspace
@@ -923,33 +923,7 @@ impl WorkspaceCommandHelper {
}
pub fn start_transaction(&self, description: &str) -> Transaction {
- let mut tx = self.repo.start_transaction(&self.settings, description);
- // TODO: Either do better shell-escaping here or store the values in some list
- // type (which we currently don't have).
- let shell_escape = |arg: &String| {
- if arg.as_bytes().iter().all(|b| {
- matches!(b,
- b'A'..=b'Z'
- | b'a'..=b'z'
- | b'0'..=b'9'
- | b','
- | b'-'
- | b'.'
- | b'/'
- | b':'
- | b'@'
- | b'_'
- )
- }) {
- arg.clone()
- } else {
- format!("'{}'", arg.replace('\'', "\\'"))
- }
- };
- let mut quoted_strings = vec!["jj".to_string()];
- quoted_strings.extend(self.string_args.iter().skip(1).map(shell_escape));
- tx.set_tag("args".to_string(), quoted_strings.join(" "));
- tx
+ start_repo_transaction(&self.repo, &self.settings, &self.string_args, description)
}
pub fn finish_transaction(
@@ -1046,6 +1020,41 @@ jj init --git-repo=.",
})
}
+pub fn start_repo_transaction(
+ repo: &Arc<ReadonlyRepo>,
+ settings: &UserSettings,
+ string_args: &[String],
+ description: &str,
+) -> Transaction {
+ let mut tx = repo.start_transaction(settings, description);
+ // TODO: Either do better shell-escaping here or store the values in some list
+ // type (which we currently don't have).
+ let shell_escape = |arg: &String| {
+ if arg.as_bytes().iter().all(|b| {
+ matches!(b,
+ b'A'..=b'Z'
+ | b'a'..=b'z'
+ | b'0'..=b'9'
+ | b','
+ | b'-'
+ | b'.'
+ | b'/'
+ | b':'
+ | b'@'
+ | b'_'
+ )
+ }) {
+ arg.clone()
+ } else {
+ format!("'{}'", arg.replace('\'', "\\'"))
+ }
+ };
+ let mut quoted_strings = vec!["jj".to_string()];
+ quoted_strings.extend(string_args.iter().skip(1).map(shell_escape));
+ tx.set_tag("args".to_string(), quoted_strings.join(" "));
+ tx
+}
+
#[derive(Debug, Error)]
pub enum StaleWorkingCopyError {
#[error("The working copy is behind the latest operation")]
