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 1, 2024
1 parent 5c252bd commit 0d2f366
Show file tree
Hide file tree
Showing 4 changed files with 33 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 @@ -790,8 +790,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 @@ -1689,6 +1689,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 @@ -1803,6 +1809,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
/// includes a pointer to the `OpStore` the operation belongs to.
#[derive(Clone)]
pub struct Operation {
op_store: Arc<dyn OpStore>,
Expand Down
18 changes: 18 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 Expand Up @@ -153,6 +164,13 @@ struct NewRepoData {
index: Box<dyn ReadonlyIndex>,
}

/// An Operation which has been written to the operation store but not
/// published. The repo can be loaded at an unpublished Operation, but the
/// Operation will not be visible in the op log if the repo is loaded at head.
///
/// Either [`UnpublishedOperation::publish`] or
/// [`UnpublishedOperation::leave_unpublished`] be called to finish the
/// operation.
pub struct UnpublishedOperation {
repo_loader: RepoLoader,
data: Option<NewRepoData>,
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 0d2f366

Please sign in to comment.