Skip to content

Commit

Permalink
docs: unify docs for callback types and functions that set callbacks
Browse files Browse the repository at this point in the history
This was motivated by the observations that:

- The `PushNegotiation` docstring was previously much more informative
  than the docstring for `push_negotiation`.

- The `PushNegotiation` docstring does not seem to be accessible via
  https://docs.rs/git2/0.18.3/git2/index.html. Only the less helpful
docstring is accessible at
https://docs.rs/git2/0.18.3/git2/struct.RemoteCallbacks.html#method.push_negotiation.
  • Loading branch information
ilyagr committed Apr 14, 2024
1 parent 5a5c86d commit c7a0775
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/remote_callbacks.rs
Expand Up @@ -83,13 +83,16 @@ pub type PushTransferProgress<'a> = dyn FnMut(usize, usize, usize) + 'a;

/// Callback for pack progress
///
/// Be aware that this is called inline with pack building operations,
/// so performance may be affected.
///
/// Parameters:
/// * stage
/// * current
/// * total
pub type PackProgress<'a> = dyn FnMut(PackBuilderStage, usize, usize) + 'a;

/// Callback used to inform of upcoming updates.
/// The callback is called once between the negotiation step and the upload.
///
/// The argument is a slice containing the updates which will be sent as
/// commands to the destination.
Expand Down Expand Up @@ -204,6 +207,11 @@ impl<'a> RemoteCallbacks<'a> {
}

/// The callback through which progress of push transfer is monitored
///
/// Parameters:
/// * current
/// * total
/// * bytes
pub fn push_transfer_progress<F>(&mut self, cb: F) -> &mut RemoteCallbacks<'a>
where
F: FnMut(usize, usize, usize) + 'a,
Expand All @@ -213,8 +221,14 @@ impl<'a> RemoteCallbacks<'a> {
}

/// Function to call with progress information during pack building.
///
/// Be aware that this is called inline with pack building operations,
/// so performance may be affected.
///
/// Parameters:
/// * stage
/// * current
/// * total
pub fn pack_progress<F>(&mut self, cb: F) -> &mut RemoteCallbacks<'a>
where
F: FnMut(PackBuilderStage, usize, usize) + 'a,
Expand All @@ -224,7 +238,11 @@ impl<'a> RemoteCallbacks<'a> {
}

/// The callback is called once between the negotiation step and the upload.
/// It provides information about what updates will be performed.
///
/// The argument to the callback is a slice containing the updates which
/// will be sent as commands to the destination.
///
/// The push is cancelled if the callback returns an error.
pub fn push_negotiation<F>(&mut self, cb: F) -> &mut RemoteCallbacks<'a>
where
F: FnMut(&[PushUpdate<'_>]) -> Result<(), Error> + 'a,
Expand Down

0 comments on commit c7a0775

Please sign in to comment.