Skip to content

Commit

Permalink
Add documentation comments for operation, transaction, and view types
Browse files Browse the repository at this point in the history
  • Loading branch information
emesterhazy committed Mar 2, 2024
1 parent b8aa9a1 commit fa17944
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ impl ReadonlyUserRepo {
}
}

// Provides utilities for writing a command that works on a workspace (like most
// commands do).
/// Provides utilities for writing a command that works on a [`Workspace`]
/// (which most commands do).
pub struct WorkspaceCommandHelper {
cwd: PathBuf,
string_args: Vec<String>,
Expand Down Expand Up @@ -1286,6 +1286,12 @@ Then run `jj squash` to move the resolution into the conflicted commit."#,
}
}

/// A [`Transaction`] tied to a particular workspace.
/// `WorkspaceCommandTransaction`s are created with
/// [`WorkspaceCommandHelper::start_transaction`] and committed with
/// [`WorkspaceCommandTransaction::finish`]. The inner `Transaction` can also be
/// extracted using [`WorkspaceCommandTransaction::into_inner`] in situations
/// where finer-grained control over the `Transaction` is necessary.
#[must_use]
pub struct WorkspaceCommandTransaction<'a> {
helper: &'a mut WorkspaceCommandHelper,
Expand Down Expand Up @@ -1351,6 +1357,10 @@ impl WorkspaceCommandTransaction<'_> {
self.helper.finish_transaction(ui, self.tx, description)
}

/// Returns the wrapped [`Transaction`] for circumstances where
/// finer-grained control is needed. The caller becomes responsible for
/// finishing the `Transaction`, including rebasing descendants and updating
/// the working copy, if applicable.
pub fn into_inner(self) -> Transaction {
self.tx
}
Expand Down
2 changes: 2 additions & 0 deletions lib/src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use crate::op_store;
use crate::op_store::{OpStore, OpStoreResult, OperationId, OperationMetadata, ViewId};
use crate::view::View;

/// A wrapper around [`op_store::Operation`] that defines additional methods and
/// stores a pointer to the `OpStore` the operation belongs to.
#[derive(Clone)]
pub struct Operation {
op_store: Arc<dyn OpStore>,
Expand Down
11 changes: 11 additions & 0 deletions lib/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ use crate::settings::UserSettings;
use crate::view::View;
use crate::{dag_walk, op_store};

/// An in-memory representation of a repo and any changes being made to it.
///
/// Within the scope of a transaction, changes to the repository are made
/// in-memory to `mut_repo` and published to the repo backend when
/// [`Transaction::commit`] is called. When a transaction is committed, it
/// becomes atomically visible as an Operation in the op log that represents the
/// transaction itself, and as a View that represents the state of the repo
/// after the transaction. This is similar to how a Commit represents a change
/// to the contents of the repository and a Tree represents the repository's
/// contents after the change. See the documentation for [`op_store::Operation`]
/// and [`op_store::View`] for more information.
pub struct Transaction {
mut_repo: MutableRepo,
parent_ops: Vec<Operation>,
Expand Down
1 change: 1 addition & 0 deletions lib/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::refs::LocalAndRemoteRef;
use crate::str_util::StringPattern;
use crate::{op_store, refs};

/// A wrapper around [`op_store::View`] that defines additional methods.
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct View {
data: op_store::View,
Expand Down

0 comments on commit fa17944

Please sign in to comment.