Skip to content

Commit

Permalink
Merge pull request #1044 from ilyagr/docs
Browse files Browse the repository at this point in the history
Improve docs for PushUpdate, push_negotiation, plus a bit more
  • Loading branch information
ehuss committed Apr 15, 2024
2 parents 04427a3 + 9c9305e commit c3454fe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/push_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ impl PushUpdate<'_> {
unsafe { crate::opt_bytes(self, (*self.raw).src_refname).unwrap() }
}

/// Returns the source name of the reference.
/// Returns the source name of the reference, or None if it is not valid UTF-8.
pub fn src_refname(&self) -> Option<&str> {
str::from_utf8(self.src_refname_bytes()).ok()
}

/// Returns the destination name of the reference as a byte slice.
/// Returns the name of the reference to update on the server as a byte slice.
pub fn dst_refname_bytes(&self) -> &[u8] {
unsafe { crate::opt_bytes(self, (*self.raw).dst_refname).unwrap() }
}

/// Returns the destination name of the reference.
/// Returns the name of the reference to update on the server, or None if it is not valid UTF-8.
pub fn dst_refname(&self) -> Option<&str> {
str::from_utf8(self.dst_refname_bytes()).ok()
}
Expand Down
34 changes: 26 additions & 8 deletions src/remote_callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,23 @@ pub type PushUpdateReference<'a> = dyn FnMut(&str, Option<&str>) -> Result<(), E
/// Callback for push transfer progress
///
/// Parameters:
/// * current
/// * total
/// * bytes
/// * current
/// * total
/// * bytes
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
/// * 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 c3454fe

Please sign in to comment.