Skip to content

Commit

Permalink
Add documentation comments for several types
Browse files Browse the repository at this point in the history
These comments are intended to make it easier for new developers to get up to
speed with the project. This is just a starting point... there are other types
and functions that could benefit from documentation.
  • Loading branch information
emesterhazy committed Mar 2, 2024
1 parent b8aa9a1 commit daa9930
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ impl Timestamp {
}
}

/// Represents a [`Commit`] signature.
#[derive(ContentHash, Debug, PartialEq, Eq, Clone)]
pub struct Signature {
pub name: String,
pub email: String,
pub timestamp: Timestamp,
}

/// Represents a cryptographically signed [`Commit`] signature.
#[derive(ContentHash, Debug, PartialEq, Eq, Clone)]
pub struct SecureSig {
pub data: Vec<u8>,
Expand Down Expand Up @@ -331,6 +333,7 @@ pub fn make_root_commit(root_change_id: ChangeId, empty_tree_id: TreeId) -> Comm
}
}

/// Defines the interface for commit backends.
#[async_trait]
pub trait Backend: Send + Sync + Debug {
fn as_any(&self) -> &dyn Any;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/fsmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::str::FromStr;
/// The recognized kinds of filesystem monitors.
#[derive(Eq, PartialEq)]
pub enum FsmonitorKind {
/// The Watchman filesystem monitor (https://facebook.github.io/watchman/).
/// The Watchman filesystem monitor (<https://facebook.github.io/watchman/>).
Watchman,

/// Only used in tests.
Expand Down
9 changes: 8 additions & 1 deletion lib/src/object_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,19 @@ macro_rules! impl_id_type {

pub(crate) use {id_type, impl_id_type};

/// An identifier prefix (typically from a type implementing the [`ObjectId`]
/// trait) with facilities for converting between bytes and a hex string.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct HexPrefix {
// For odd-length prefix, lower 4 bits of the last byte is padded with 0
// For odd-length prefixes, the lower 4 bits of the last byte are
// zero-filled (e.g. the prefix "abc" is stored in two bytes as "abc0").
min_prefix_bytes: Vec<u8>,
has_odd_byte: bool,
}

impl HexPrefix {
/// Returns a new `HexPrefix` or `None` if `prefix` cannot be decoded from
/// hex to bytes.
pub fn new(prefix: &str) -> Option<HexPrefix> {
let has_odd_byte = prefix.len() & 1 != 0;
let min_prefix_bytes = if has_odd_byte {
Expand Down Expand Up @@ -160,6 +165,7 @@ impl HexPrefix {
}
}

/// Returns whether the stored prefix matches the prefix of `id`.
pub fn matches<Q: ObjectId>(&self, id: &Q) -> bool {
let id_bytes = id.as_bytes();
let (maybe_odd, prefix) = self.split_odd_byte();
Expand All @@ -175,6 +181,7 @@ impl HexPrefix {
}
}

/// The result of a prefix search.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PrefixResolution<T> {
NoMatch,
Expand Down
6 changes: 4 additions & 2 deletions lib/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ pub enum WorkspaceLoadError {
Path(#[from] PathError),
}

/// Represents a workspace, i.e. what's typically the .jj/ directory and its
/// parent.
/// Represents the combination of a repo and working copy, i.e. what's typically
/// the .jj/ directory and its parent. See
/// <https://github.com/martinvonz/jj/blob/main/docs/working-copy.md#workspaces>
/// for more information.
pub struct Workspace {
// Path to the workspace root (typically the parent of a .jj/ directory), which is where
// working copy files live.
Expand Down

0 comments on commit daa9930

Please sign in to comment.