Skip to content

Improve docs for PushUpdate, push_negotiation, plus a bit more #1044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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