diff --git a/src/blame.rs b/src/blame.rs index 4bf41fed1e..c02705b184 100644 --- a/src/blame.rs +++ b/src/blame.rs @@ -94,7 +94,7 @@ impl<'repo> Blame<'repo> { } impl<'blame> BlameHunk<'blame> { - unsafe fn from_raw_const(raw: *const raw::git_blame_hunk) -> BlameHunk<'blame> { + unsafe fn from_raw_const(raw: *const raw::git_blame_hunk) -> Self { BlameHunk { raw: raw as *mut raw::git_blame_hunk, _marker: marker::PhantomData, @@ -172,7 +172,7 @@ impl Default for BlameOptions { impl BlameOptions { /// Initialize options - pub fn new() -> BlameOptions { + pub fn new() -> Self { unsafe { let mut raw: raw::git_blame_options = mem::zeroed(); assert_eq!( @@ -184,7 +184,7 @@ impl BlameOptions { } } - fn flag(&mut self, opt: u32, val: bool) -> &mut BlameOptions { + fn flag(&mut self, opt: u32, val: bool) -> &mut Self { if val { self.raw.flags |= opt; } else { @@ -194,47 +194,47 @@ impl BlameOptions { } /// Track lines that have moved within a file. - pub fn track_copies_same_file(&mut self, opt: bool) -> &mut BlameOptions { + pub fn track_copies_same_file(&mut self, opt: bool) -> &mut Self { self.flag(raw::GIT_BLAME_TRACK_COPIES_SAME_FILE, opt) } /// Track lines that have moved across files in the same commit. - pub fn track_copies_same_commit_moves(&mut self, opt: bool) -> &mut BlameOptions { + pub fn track_copies_same_commit_moves(&mut self, opt: bool) -> &mut Self { self.flag(raw::GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES, opt) } /// Track lines that have been copied from another file that exists /// in the same commit. - pub fn track_copies_same_commit_copies(&mut self, opt: bool) -> &mut BlameOptions { + pub fn track_copies_same_commit_copies(&mut self, opt: bool) -> &mut Self { self.flag(raw::GIT_BLAME_TRACK_COPIES_SAME_COMMIT_COPIES, opt) } /// Track lines that have been copied from another file that exists /// in any commit. - pub fn track_copies_any_commit_copies(&mut self, opt: bool) -> &mut BlameOptions { + pub fn track_copies_any_commit_copies(&mut self, opt: bool) -> &mut Self { self.flag(raw::GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES, opt) } /// Restrict the search of commits to those reachable following only /// the first parents. - pub fn first_parent(&mut self, opt: bool) -> &mut BlameOptions { + pub fn first_parent(&mut self, opt: bool) -> &mut Self { self.flag(raw::GIT_BLAME_FIRST_PARENT, opt) } /// Use mailmap file to map author and committer names and email addresses /// to canonical real names and email addresses. The mailmap will be read /// from the working directory, or HEAD in a bare repository. - pub fn use_mailmap(&mut self, opt: bool) -> &mut BlameOptions { + pub fn use_mailmap(&mut self, opt: bool) -> &mut Self { self.flag(raw::GIT_BLAME_USE_MAILMAP, opt) } /// Ignore whitespace differences. - pub fn ignore_whitespace(&mut self, opt: bool) -> &mut BlameOptions { + pub fn ignore_whitespace(&mut self, opt: bool) -> &mut Self { self.flag(raw::GIT_BLAME_IGNORE_WHITESPACE, opt) } /// Setter for the id of the newest commit to consider. - pub fn newest_commit(&mut self, id: Oid) -> &mut BlameOptions { + pub fn newest_commit(&mut self, id: Oid) -> &mut Self { unsafe { self.raw.newest_commit = *id.raw(); } @@ -242,7 +242,7 @@ impl BlameOptions { } /// Setter for the id of the oldest commit to consider. - pub fn oldest_commit(&mut self, id: Oid) -> &mut BlameOptions { + pub fn oldest_commit(&mut self, id: Oid) -> &mut Self { unsafe { self.raw.oldest_commit = *id.raw(); } @@ -250,13 +250,13 @@ impl BlameOptions { } /// The first line in the file to blame. - pub fn min_line(&mut self, lineno: usize) -> &mut BlameOptions { + pub fn min_line(&mut self, lineno: usize) -> &mut Self { self.raw.min_line = lineno; self } /// The last line in the file to blame. - pub fn max_line(&mut self, lineno: usize) -> &mut BlameOptions { + pub fn max_line(&mut self, lineno: usize) -> &mut Self { self.raw.max_line = lineno; self } @@ -265,7 +265,7 @@ impl BlameOptions { impl<'repo> Binding for Blame<'repo> { type Raw = *mut raw::git_blame; - unsafe fn from_raw(raw: *mut raw::git_blame) -> Blame<'repo> { + unsafe fn from_raw(raw: *mut raw::git_blame) -> Self { Blame { raw, _marker: marker::PhantomData, @@ -286,7 +286,7 @@ impl<'repo> Drop for Blame<'repo> { impl<'blame> Binding for BlameHunk<'blame> { type Raw = *mut raw::git_blame_hunk; - unsafe fn from_raw(raw: *mut raw::git_blame_hunk) -> BlameHunk<'blame> { + unsafe fn from_raw(raw: *mut raw::git_blame_hunk) -> Self { BlameHunk { raw, _marker: marker::PhantomData, @@ -301,8 +301,8 @@ impl<'blame> Binding for BlameHunk<'blame> { impl Binding for BlameOptions { type Raw = *mut raw::git_blame_options; - unsafe fn from_raw(opts: *mut raw::git_blame_options) -> BlameOptions { - BlameOptions { raw: *opts } + unsafe fn from_raw(opts: *mut raw::git_blame_options) -> Self { + Self { raw: *opts } } fn raw(&self) -> *mut raw::git_blame_options { diff --git a/src/blob.rs b/src/blob.rs index 5c4a6ce6b8..9e582f5231 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -54,7 +54,7 @@ impl<'repo> Blob<'repo> { impl<'repo> Binding for Blob<'repo> { type Raw = *mut raw::git_blob; - unsafe fn from_raw(raw: *mut raw::git_blob) -> Blob<'repo> { + unsafe fn from_raw(raw: *mut raw::git_blob) -> Self { Blob { raw, _marker: marker::PhantomData, @@ -108,7 +108,7 @@ impl<'repo> BlobWriter<'repo> { impl<'repo> Binding for BlobWriter<'repo> { type Raw = *mut raw::git_writestream; - unsafe fn from_raw(raw: *mut raw::git_writestream) -> BlobWriter<'repo> { + unsafe fn from_raw(raw: *mut raw::git_writestream) -> Self { BlobWriter { raw, need_cleanup: true, diff --git a/src/branch.rs b/src/branch.rs index e1eba99c2b..06c79cc9f4 100644 --- a/src/branch.rs +++ b/src/branch.rs @@ -68,7 +68,7 @@ impl<'repo> Branch<'repo> { } /// Move/rename an existing local branch reference. - pub fn rename(&mut self, new_branch_name: &str, force: bool) -> Result, Error> { + pub fn rename(&mut self, new_branch_name: &str, force: bool) -> Result { let mut ret = ptr::null_mut(); let new_branch_name = CString::new(new_branch_name)?; unsafe { @@ -100,7 +100,7 @@ impl<'repo> Branch<'repo> { /// Return the reference supporting the remote tracking branch, given a /// local branch reference. - pub fn upstream(&self) -> Result, Error> { + pub fn upstream(&self) -> Result { let mut ret = ptr::null_mut(); unsafe { try_call!(raw::git_branch_upstream(&mut ret, &*self.get().raw())); @@ -129,7 +129,7 @@ impl<'repo> Branches<'repo> { /// /// This function is unsafe as it is not guaranteed that `raw` is a valid /// pointer. - pub unsafe fn from_raw(raw: *mut raw::git_branch_iterator) -> Branches<'repo> { + pub unsafe fn from_raw(raw: *mut raw::git_branch_iterator) -> Self { Branches { raw, _marker: marker::PhantomData, diff --git a/src/buf.rs b/src/buf.rs index fd2bcbf96f..fcfb3ca37d 100644 --- a/src/buf.rs +++ b/src/buf.rs @@ -22,7 +22,7 @@ impl Default for Buf { impl Buf { /// Creates a new empty buffer. - pub fn new() -> Buf { + pub fn new() -> Self { crate::init(); unsafe { Binding::from_raw(&mut raw::git_buf { @@ -56,8 +56,8 @@ impl DerefMut for Buf { impl Binding for Buf { type Raw = *mut raw::git_buf; - unsafe fn from_raw(raw: *mut raw::git_buf) -> Buf { - Buf { raw: *raw } + unsafe fn from_raw(raw: *mut raw::git_buf) -> Self { + Self { raw: *raw } } fn raw(&self) -> *mut raw::git_buf { &self.raw as *const _ as *mut _ diff --git a/src/build.rs b/src/build.rs index 4ac62439b7..4071e3b17b 100644 --- a/src/build.rs +++ b/src/build.rs @@ -150,7 +150,7 @@ impl<'cb> RepoBuilder<'cb> { /// /// When ready, the `clone()` method can be used to clone a new repository /// using this configuration. - pub fn new() -> RepoBuilder<'cb> { + pub fn new() -> Self { crate::init(); RepoBuilder { bare: false, @@ -166,7 +166,7 @@ impl<'cb> RepoBuilder<'cb> { /// Indicate whether the repository will be cloned as a bare repository or /// not. - pub fn bare(&mut self, bare: bool) -> &mut RepoBuilder<'cb> { + pub fn bare(&mut self, bare: bool) -> &mut Self { self.bare = bare; self } @@ -174,7 +174,7 @@ impl<'cb> RepoBuilder<'cb> { /// Specify the name of the branch to check out after the clone. /// /// If not specified, the remote's default branch will be used. - pub fn branch(&mut self, branch: &str) -> &mut RepoBuilder<'cb> { + pub fn branch(&mut self, branch: &str) -> &mut Self { self.branch = Some(CString::new(branch).unwrap()); self } @@ -184,7 +184,7 @@ impl<'cb> RepoBuilder<'cb> { /// Bypassing it means that instead of a fetch libgit2 will copy the object /// database directory instead of figuring out what it needs, which is /// faster. If possible, it will hardlink the files to save space. - pub fn clone_local(&mut self, clone_local: CloneLocal) -> &mut RepoBuilder<'cb> { + pub fn clone_local(&mut self, clone_local: CloneLocal) -> &mut Self { self.clone_local = Some(clone_local); self } @@ -196,7 +196,7 @@ impl<'cb> RepoBuilder<'cb> { /// `false`, the git-aware transport will not be bypassed. #[deprecated(note = "use `clone_local` instead")] #[doc(hidden)] - pub fn local(&mut self, local: bool) -> &mut RepoBuilder<'cb> { + pub fn local(&mut self, local: bool) -> &mut Self { self.local = local; self } @@ -205,14 +205,14 @@ impl<'cb> RepoBuilder<'cb> { /// transport mechanism. #[deprecated(note = "use `clone_local` instead")] #[doc(hidden)] - pub fn hardlinks(&mut self, links: bool) -> &mut RepoBuilder<'cb> { + pub fn hardlinks(&mut self, links: bool) -> &mut Self { self.hardlinks = links; self } /// Configure the checkout which will be performed by consuming a checkout /// builder. - pub fn with_checkout(&mut self, checkout: CheckoutBuilder<'cb>) -> &mut RepoBuilder<'cb> { + pub fn with_checkout(&mut self, checkout: CheckoutBuilder<'cb>) -> &mut Self { self.checkout = Some(checkout); self } @@ -221,14 +221,14 @@ impl<'cb> RepoBuilder<'cb> { /// /// The callbacks are used for reporting fetch progress, and for acquiring /// credentials in the event they are needed. - pub fn fetch_options(&mut self, fetch_opts: FetchOptions<'cb>) -> &mut RepoBuilder<'cb> { + pub fn fetch_options(&mut self, fetch_opts: FetchOptions<'cb>) -> &mut Self { self.fetch_opts = Some(fetch_opts); self } /// Configures a callback used to create the git remote, prior to its being /// used to perform the clone operation. - pub fn remote_create(&mut self, f: F) -> &mut RepoBuilder<'cb> + pub fn remote_create(&mut self, f: F) -> &mut Self where F: for<'a> FnMut(&'a Repository, &str, &str) -> Result, Error> + 'cb, { @@ -326,7 +326,7 @@ impl<'cb> Default for CheckoutBuilder<'cb> { impl<'cb> CheckoutBuilder<'cb> { /// Creates a new builder for checkouts with all of its default /// configuration. - pub fn new() -> CheckoutBuilder<'cb> { + pub fn new() -> Self { crate::init(); CheckoutBuilder { disable_filters: false, @@ -347,7 +347,7 @@ impl<'cb> CheckoutBuilder<'cb> { /// Indicate that this checkout should perform a dry run by checking for /// conflicts but not make any actual changes. - pub fn dry_run(&mut self) -> &mut CheckoutBuilder<'cb> { + pub fn dry_run(&mut self) -> &mut Self { self.checkout_opts &= !((1 << 4) - 1); self.checkout_opts |= raw::GIT_CHECKOUT_NONE as u32; self @@ -355,7 +355,7 @@ impl<'cb> CheckoutBuilder<'cb> { /// Take any action necessary to get the working directory to match the /// target including potentially discarding modified files. - pub fn force(&mut self) -> &mut CheckoutBuilder<'cb> { + pub fn force(&mut self) -> &mut Self { self.checkout_opts &= !((1 << 4) - 1); self.checkout_opts |= raw::GIT_CHECKOUT_FORCE as u32; self @@ -365,13 +365,13 @@ impl<'cb> CheckoutBuilder<'cb> { /// files to be created but not overwriting existing files or changes. /// /// This is the default. - pub fn safe(&mut self) -> &mut CheckoutBuilder<'cb> { + pub fn safe(&mut self) -> &mut Self { self.checkout_opts &= !((1 << 4) - 1); self.checkout_opts |= raw::GIT_CHECKOUT_SAFE as u32; self } - fn flag(&mut self, bit: raw::git_checkout_strategy_t, on: bool) -> &mut CheckoutBuilder<'cb> { + fn flag(&mut self, bit: raw::git_checkout_strategy_t, on: bool) -> &mut Self { if on { self.checkout_opts |= bit as u32; } else { @@ -383,7 +383,7 @@ impl<'cb> CheckoutBuilder<'cb> { /// In safe mode, create files that don't exist. /// /// Defaults to false. - pub fn recreate_missing(&mut self, allow: bool) -> &mut CheckoutBuilder<'cb> { + pub fn recreate_missing(&mut self, allow: bool) -> &mut Self { self.flag(raw::GIT_CHECKOUT_RECREATE_MISSING, allow) } @@ -391,21 +391,21 @@ impl<'cb> CheckoutBuilder<'cb> { /// instead of canceling the checkout. /// /// Defaults to false. - pub fn allow_conflicts(&mut self, allow: bool) -> &mut CheckoutBuilder<'cb> { + pub fn allow_conflicts(&mut self, allow: bool) -> &mut Self { self.flag(raw::GIT_CHECKOUT_ALLOW_CONFLICTS, allow) } /// Remove untracked files from the working dir. /// /// Defaults to false. - pub fn remove_untracked(&mut self, remove: bool) -> &mut CheckoutBuilder<'cb> { + pub fn remove_untracked(&mut self, remove: bool) -> &mut Self { self.flag(raw::GIT_CHECKOUT_REMOVE_UNTRACKED, remove) } /// Remove ignored files from the working dir. /// /// Defaults to false. - pub fn remove_ignored(&mut self, remove: bool) -> &mut CheckoutBuilder<'cb> { + pub fn remove_ignored(&mut self, remove: bool) -> &mut Self { self.flag(raw::GIT_CHECKOUT_REMOVE_IGNORED, remove) } @@ -414,7 +414,7 @@ impl<'cb> CheckoutBuilder<'cb> { /// If set, files will not be created or deleted. /// /// Defaults to false. - pub fn update_only(&mut self, update: bool) -> &mut CheckoutBuilder<'cb> { + pub fn update_only(&mut self, update: bool) -> &mut Self { self.flag(raw::GIT_CHECKOUT_UPDATE_ONLY, update) } @@ -422,7 +422,7 @@ impl<'cb> CheckoutBuilder<'cb> { /// index. /// /// Defaults to true. - pub fn update_index(&mut self, update: bool) -> &mut CheckoutBuilder<'cb> { + pub fn update_index(&mut self, update: bool) -> &mut Self { self.flag(raw::GIT_CHECKOUT_DONT_UPDATE_INDEX, !update) } @@ -430,14 +430,14 @@ impl<'cb> CheckoutBuilder<'cb> { /// disk before any operations. /// /// Defaults to true, - pub fn refresh(&mut self, refresh: bool) -> &mut CheckoutBuilder<'cb> { + pub fn refresh(&mut self, refresh: bool) -> &mut Self { self.flag(raw::GIT_CHECKOUT_NO_REFRESH, !refresh) } /// Skip files with unmerged index entries. /// /// Defaults to false. - pub fn skip_unmerged(&mut self, skip: bool) -> &mut CheckoutBuilder<'cb> { + pub fn skip_unmerged(&mut self, skip: bool) -> &mut Self { self.flag(raw::GIT_CHECKOUT_SKIP_UNMERGED, skip) } @@ -445,7 +445,7 @@ impl<'cb> CheckoutBuilder<'cb> { /// stage 2 version of the file ("ours"). /// /// Defaults to false. - pub fn use_ours(&mut self, ours: bool) -> &mut CheckoutBuilder<'cb> { + pub fn use_ours(&mut self, ours: bool) -> &mut Self { self.flag(raw::GIT_CHECKOUT_USE_OURS, ours) } @@ -453,21 +453,21 @@ impl<'cb> CheckoutBuilder<'cb> { /// stage 3 version of the file ("theirs"). /// /// Defaults to false. - pub fn use_theirs(&mut self, theirs: bool) -> &mut CheckoutBuilder<'cb> { + pub fn use_theirs(&mut self, theirs: bool) -> &mut Self { self.flag(raw::GIT_CHECKOUT_USE_THEIRS, theirs) } /// Indicate whether ignored files should be overwritten during the checkout. /// /// Defaults to true. - pub fn overwrite_ignored(&mut self, overwrite: bool) -> &mut CheckoutBuilder<'cb> { + pub fn overwrite_ignored(&mut self, overwrite: bool) -> &mut Self { self.flag(raw::GIT_CHECKOUT_DONT_OVERWRITE_IGNORED, !overwrite) } /// Indicate whether a normal merge file should be written for conflicts. /// /// Defaults to false. - pub fn conflict_style_merge(&mut self, on: bool) -> &mut CheckoutBuilder<'cb> { + pub fn conflict_style_merge(&mut self, on: bool) -> &mut Self { self.flag(raw::GIT_CHECKOUT_CONFLICT_STYLE_MERGE, on) } @@ -475,10 +475,7 @@ impl<'cb> CheckoutBuilder<'cb> { /// callback. /// /// Defaults to none. - pub fn notify_on( - &mut self, - notification_types: CheckoutNotificationType, - ) -> &mut CheckoutBuilder<'cb> { + pub fn notify_on(&mut self, notification_types: CheckoutNotificationType) -> &mut Self { self.notify_flags = notification_types; self } @@ -487,18 +484,18 @@ impl<'cb> CheckoutBuilder<'cb> { /// for conflicts. /// /// Defaults to false. - pub fn conflict_style_diff3(&mut self, on: bool) -> &mut CheckoutBuilder<'cb> { + pub fn conflict_style_diff3(&mut self, on: bool) -> &mut Self { self.flag(raw::GIT_CHECKOUT_CONFLICT_STYLE_DIFF3, on) } /// Treat paths specified in [`CheckoutBuilder::path`] as exact file paths /// instead of as pathspecs. - pub fn disable_pathspec_match(&mut self, on: bool) -> &mut CheckoutBuilder<'cb> { + pub fn disable_pathspec_match(&mut self, on: bool) -> &mut Self { self.flag(raw::GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH, on) } /// Indicate whether to apply filters like CRLF conversion. - pub fn disable_filters(&mut self, disable: bool) -> &mut CheckoutBuilder<'cb> { + pub fn disable_filters(&mut self, disable: bool) -> &mut Self { self.disable_filters = disable; self } @@ -506,7 +503,7 @@ impl<'cb> CheckoutBuilder<'cb> { /// Set the mode with which new directories are created. /// /// Default is 0755 - pub fn dir_perm(&mut self, perm: i32) -> &mut CheckoutBuilder<'cb> { + pub fn dir_perm(&mut self, perm: i32) -> &mut Self { self.dir_perm = Some(perm); self } @@ -514,7 +511,7 @@ impl<'cb> CheckoutBuilder<'cb> { /// Set the mode with which new files are created. /// /// The default is 0644 or 0755 as dictated by the blob. - pub fn file_perm(&mut self, perm: i32) -> &mut CheckoutBuilder<'cb> { + pub fn file_perm(&mut self, perm: i32) -> &mut Self { self.file_perm = Some(perm); self } @@ -528,7 +525,7 @@ impl<'cb> CheckoutBuilder<'cb> { /// only these specified paths are checked out. /// /// [pathspec]: https://git-scm.com/docs/gitglossary.html#Documentation/gitglossary.txt-aiddefpathspecapathspec - pub fn path(&mut self, path: T) -> &mut CheckoutBuilder<'cb> { + pub fn path(&mut self, path: T) -> &mut Self { let path = util::cstring_to_repo_path(path).unwrap(); self.path_ptrs.push(path.as_ptr()); self.paths.push(path); @@ -536,32 +533,32 @@ impl<'cb> CheckoutBuilder<'cb> { } /// Set the directory to check out to - pub fn target_dir(&mut self, dst: &Path) -> &mut CheckoutBuilder<'cb> { + pub fn target_dir(&mut self, dst: &Path) -> &mut Self { // Normal file path OK (does not need Windows conversion). self.target_dir = Some(dst.into_c_string().unwrap()); self } /// The name of the common ancestor side of conflicts - pub fn ancestor_label(&mut self, label: &str) -> &mut CheckoutBuilder<'cb> { + pub fn ancestor_label(&mut self, label: &str) -> &mut Self { self.ancestor_label = Some(CString::new(label).unwrap()); self } /// The name of the common our side of conflicts - pub fn our_label(&mut self, label: &str) -> &mut CheckoutBuilder<'cb> { + pub fn our_label(&mut self, label: &str) -> &mut Self { self.our_label = Some(CString::new(label).unwrap()); self } /// The name of the common their side of conflicts - pub fn their_label(&mut self, label: &str) -> &mut CheckoutBuilder<'cb> { + pub fn their_label(&mut self, label: &str) -> &mut Self { self.their_label = Some(CString::new(label).unwrap()); self } /// Set a callback to receive notifications of checkout progress. - pub fn progress(&mut self, cb: F) -> &mut CheckoutBuilder<'cb> + pub fn progress(&mut self, cb: F) -> &mut Self where F: FnMut(Option<&Path>, usize, usize) + 'cb, { @@ -573,7 +570,7 @@ impl<'cb> CheckoutBuilder<'cb> { /// /// Callbacks are invoked prior to modifying any files on disk. /// Returning `false` from the callback will cancel the checkout. - pub fn notify(&mut self, cb: F) -> &mut CheckoutBuilder<'cb> + pub fn notify(&mut self, cb: F) -> &mut Self where F: FnMut( CheckoutNotificationType, diff --git a/src/call.rs b/src/call.rs index 9aa3ae667f..0b075d1e1f 100644 --- a/src/call.rs +++ b/src/call.rs @@ -107,9 +107,9 @@ mod impls { impl Convert for ResetType { fn convert(&self) -> raw::git_reset_t { match *self { - ResetType::Soft => raw::GIT_RESET_SOFT, - ResetType::Hard => raw::GIT_RESET_HARD, - ResetType::Mixed => raw::GIT_RESET_MIXED, + Self::Soft => raw::GIT_RESET_SOFT, + Self::Hard => raw::GIT_RESET_HARD, + Self::Mixed => raw::GIT_RESET_MIXED, } } } @@ -117,8 +117,8 @@ mod impls { impl Convert for Direction { fn convert(&self) -> raw::git_direction { match *self { - Direction::Push => raw::GIT_DIRECTION_PUSH, - Direction::Fetch => raw::GIT_DIRECTION_FETCH, + Self::Push => raw::GIT_DIRECTION_PUSH, + Self::Fetch => raw::GIT_DIRECTION_FETCH, } } } @@ -126,11 +126,11 @@ mod impls { impl Convert for ObjectType { fn convert(&self) -> raw::git_object_t { match *self { - ObjectType::Any => raw::GIT_OBJECT_ANY, - ObjectType::Commit => raw::GIT_OBJECT_COMMIT, - ObjectType::Tree => raw::GIT_OBJECT_TREE, - ObjectType::Blob => raw::GIT_OBJECT_BLOB, - ObjectType::Tag => raw::GIT_OBJECT_TAG, + Self::Any => raw::GIT_OBJECT_ANY, + Self::Commit => raw::GIT_OBJECT_COMMIT, + Self::Tree => raw::GIT_OBJECT_TREE, + Self::Blob => raw::GIT_OBJECT_BLOB, + Self::Tag => raw::GIT_OBJECT_TAG, } } } @@ -144,8 +144,8 @@ mod impls { impl Convert for BranchType { fn convert(&self) -> raw::git_branch_t { match *self { - BranchType::Remote => raw::GIT_BRANCH_REMOTE, - BranchType::Local => raw::GIT_BRANCH_LOCAL, + Self::Remote => raw::GIT_BRANCH_REMOTE, + Self::Local => raw::GIT_BRANCH_LOCAL, } } } @@ -159,14 +159,14 @@ mod impls { impl Convert for ConfigLevel { fn convert(&self) -> raw::git_config_level_t { match *self { - ConfigLevel::ProgramData => raw::GIT_CONFIG_LEVEL_PROGRAMDATA, - ConfigLevel::System => raw::GIT_CONFIG_LEVEL_SYSTEM, - ConfigLevel::XDG => raw::GIT_CONFIG_LEVEL_XDG, - ConfigLevel::Global => raw::GIT_CONFIG_LEVEL_GLOBAL, - ConfigLevel::Local => raw::GIT_CONFIG_LEVEL_LOCAL, - ConfigLevel::Worktree => raw::GIT_CONFIG_LEVEL_WORKTREE, - ConfigLevel::App => raw::GIT_CONFIG_LEVEL_APP, - ConfigLevel::Highest => raw::GIT_CONFIG_HIGHEST_LEVEL, + Self::ProgramData => raw::GIT_CONFIG_LEVEL_PROGRAMDATA, + Self::System => raw::GIT_CONFIG_LEVEL_SYSTEM, + Self::XDG => raw::GIT_CONFIG_LEVEL_XDG, + Self::Global => raw::GIT_CONFIG_LEVEL_GLOBAL, + Self::Local => raw::GIT_CONFIG_LEVEL_LOCAL, + Self::Worktree => raw::GIT_CONFIG_LEVEL_WORKTREE, + Self::App => raw::GIT_CONFIG_LEVEL_APP, + Self::Highest => raw::GIT_CONFIG_HIGHEST_LEVEL, } } } @@ -174,12 +174,12 @@ mod impls { impl Convert for DiffFormat { fn convert(&self) -> raw::git_diff_format_t { match *self { - DiffFormat::Patch => raw::GIT_DIFF_FORMAT_PATCH, - DiffFormat::PatchHeader => raw::GIT_DIFF_FORMAT_PATCH_HEADER, - DiffFormat::Raw => raw::GIT_DIFF_FORMAT_RAW, - DiffFormat::NameOnly => raw::GIT_DIFF_FORMAT_NAME_ONLY, - DiffFormat::NameStatus => raw::GIT_DIFF_FORMAT_NAME_STATUS, - DiffFormat::PatchId => raw::GIT_DIFF_FORMAT_PATCH_ID, + Self::Patch => raw::GIT_DIFF_FORMAT_PATCH, + Self::PatchHeader => raw::GIT_DIFF_FORMAT_PATCH_HEADER, + Self::Raw => raw::GIT_DIFF_FORMAT_RAW, + Self::NameOnly => raw::GIT_DIFF_FORMAT_NAME_ONLY, + Self::NameStatus => raw::GIT_DIFF_FORMAT_NAME_STATUS, + Self::PatchId => raw::GIT_DIFF_FORMAT_PATCH_ID, } } } @@ -187,10 +187,10 @@ mod impls { impl Convert for FileFavor { fn convert(&self) -> raw::git_merge_file_favor_t { match *self { - FileFavor::Normal => raw::GIT_MERGE_FILE_FAVOR_NORMAL, - FileFavor::Ours => raw::GIT_MERGE_FILE_FAVOR_OURS, - FileFavor::Theirs => raw::GIT_MERGE_FILE_FAVOR_THEIRS, - FileFavor::Union => raw::GIT_MERGE_FILE_FAVOR_UNION, + Self::Normal => raw::GIT_MERGE_FILE_FAVOR_NORMAL, + Self::Ours => raw::GIT_MERGE_FILE_FAVOR_OURS, + Self::Theirs => raw::GIT_MERGE_FILE_FAVOR_THEIRS, + Self::Union => raw::GIT_MERGE_FILE_FAVOR_UNION, } } } @@ -198,11 +198,11 @@ mod impls { impl Convert for SubmoduleIgnore { fn convert(&self) -> raw::git_submodule_ignore_t { match *self { - SubmoduleIgnore::Unspecified => raw::GIT_SUBMODULE_IGNORE_UNSPECIFIED, - SubmoduleIgnore::None => raw::GIT_SUBMODULE_IGNORE_NONE, - SubmoduleIgnore::Untracked => raw::GIT_SUBMODULE_IGNORE_UNTRACKED, - SubmoduleIgnore::Dirty => raw::GIT_SUBMODULE_IGNORE_DIRTY, - SubmoduleIgnore::All => raw::GIT_SUBMODULE_IGNORE_ALL, + Self::Unspecified => raw::GIT_SUBMODULE_IGNORE_UNSPECIFIED, + Self::None => raw::GIT_SUBMODULE_IGNORE_NONE, + Self::Untracked => raw::GIT_SUBMODULE_IGNORE_UNTRACKED, + Self::Dirty => raw::GIT_SUBMODULE_IGNORE_DIRTY, + Self::All => raw::GIT_SUBMODULE_IGNORE_ALL, } } } @@ -210,11 +210,11 @@ mod impls { impl Convert for SubmoduleUpdate { fn convert(&self) -> raw::git_submodule_update_t { match *self { - SubmoduleUpdate::Checkout => raw::GIT_SUBMODULE_UPDATE_CHECKOUT, - SubmoduleUpdate::Rebase => raw::GIT_SUBMODULE_UPDATE_REBASE, - SubmoduleUpdate::Merge => raw::GIT_SUBMODULE_UPDATE_MERGE, - SubmoduleUpdate::None => raw::GIT_SUBMODULE_UPDATE_NONE, - SubmoduleUpdate::Default => raw::GIT_SUBMODULE_UPDATE_DEFAULT, + Self::Checkout => raw::GIT_SUBMODULE_UPDATE_CHECKOUT, + Self::Rebase => raw::GIT_SUBMODULE_UPDATE_REBASE, + Self::Merge => raw::GIT_SUBMODULE_UPDATE_MERGE, + Self::None => raw::GIT_SUBMODULE_UPDATE_NONE, + Self::Default => raw::GIT_SUBMODULE_UPDATE_DEFAULT, } } } @@ -222,10 +222,10 @@ mod impls { impl Convert for AutotagOption { fn convert(&self) -> raw::git_remote_autotag_option_t { match *self { - AutotagOption::Unspecified => raw::GIT_REMOTE_DOWNLOAD_TAGS_UNSPECIFIED, - AutotagOption::None => raw::GIT_REMOTE_DOWNLOAD_TAGS_NONE, - AutotagOption::Auto => raw::GIT_REMOTE_DOWNLOAD_TAGS_AUTO, - AutotagOption::All => raw::GIT_REMOTE_DOWNLOAD_TAGS_ALL, + Self::Unspecified => raw::GIT_REMOTE_DOWNLOAD_TAGS_UNSPECIFIED, + Self::None => raw::GIT_REMOTE_DOWNLOAD_TAGS_NONE, + Self::Auto => raw::GIT_REMOTE_DOWNLOAD_TAGS_AUTO, + Self::All => raw::GIT_REMOTE_DOWNLOAD_TAGS_ALL, } } } @@ -233,9 +233,9 @@ mod impls { impl Convert for FetchPrune { fn convert(&self) -> raw::git_fetch_prune_t { match *self { - FetchPrune::Unspecified => raw::GIT_FETCH_PRUNE_UNSPECIFIED, - FetchPrune::On => raw::GIT_FETCH_PRUNE, - FetchPrune::Off => raw::GIT_FETCH_NO_PRUNE, + Self::Unspecified => raw::GIT_FETCH_PRUNE_UNSPECIFIED, + Self::On => raw::GIT_FETCH_PRUNE, + Self::Off => raw::GIT_FETCH_NO_PRUNE, } } } diff --git a/src/cert.rs b/src/cert.rs index b232cc3ce8..2dec700edd 100644 --- a/src/cert.rs +++ b/src/cert.rs @@ -51,26 +51,26 @@ impl SshHostKeyType { /// The name of the key type as encoded in the known_hosts file. pub fn name(&self) -> &'static str { match self { - SshHostKeyType::Unknown => "unknown", - SshHostKeyType::Rsa => "ssh-rsa", - SshHostKeyType::Dss => "ssh-dss", - SshHostKeyType::Ecdsa256 => "ecdsa-sha2-nistp256", - SshHostKeyType::Ecdsa384 => "ecdsa-sha2-nistp384", - SshHostKeyType::Ecdsa521 => "ecdsa-sha2-nistp521", - SshHostKeyType::Ed255219 => "ssh-ed25519", + Self::Unknown => "unknown", + Self::Rsa => "ssh-rsa", + Self::Dss => "ssh-dss", + Self::Ecdsa256 => "ecdsa-sha2-nistp256", + Self::Ecdsa384 => "ecdsa-sha2-nistp384", + Self::Ecdsa521 => "ecdsa-sha2-nistp521", + Self::Ed255219 => "ssh-ed25519", } } /// A short name of the key type, the colloquial form used as a human-readable description. pub fn short_name(&self) -> &'static str { match self { - SshHostKeyType::Unknown => "Unknown", - SshHostKeyType::Rsa => "RSA", - SshHostKeyType::Dss => "DSA", - SshHostKeyType::Ecdsa256 => "ECDSA", - SshHostKeyType::Ecdsa384 => "ECDSA", - SshHostKeyType::Ecdsa521 => "ECDSA", - SshHostKeyType::Ed255219 => "ED25519", + Self::Unknown => "Unknown", + Self::Rsa => "RSA", + Self::Dss => "DSA", + Self::Ecdsa256 => "ECDSA", + Self::Ecdsa384 => "ECDSA", + Self::Ecdsa521 => "ECDSA", + Self::Ed255219 => "ED25519", } } } @@ -179,7 +179,7 @@ impl<'a> CertX509<'a> { impl<'a> Binding for Cert<'a> { type Raw = *mut raw::git_cert; - unsafe fn from_raw(raw: *mut raw::git_cert) -> Cert<'a> { + unsafe fn from_raw(raw: *mut raw::git_cert) -> Self { Cert { raw, _marker: marker::PhantomData, diff --git a/src/cherrypick.rs b/src/cherrypick.rs index 659b73089b..ff3d61b789 100644 --- a/src/cherrypick.rs +++ b/src/cherrypick.rs @@ -14,7 +14,7 @@ pub struct CherrypickOptions<'cb> { impl<'cb> CherrypickOptions<'cb> { /// Creates a default set of cherrypick options - pub fn new() -> CherrypickOptions<'cb> { + pub fn new() -> Self { CherrypickOptions { mainline: 0, checkout_builder: None, diff --git a/src/commit.rs b/src/commit.rs index 7fef508096..ba68109d22 100644 --- a/src/commit.rs +++ b/src/commit.rs @@ -291,7 +291,7 @@ impl<'repo> Commit<'repo> { /// Get the specified parent of the commit. /// /// Use the `parents` iterator to return an iterator over all parents. - pub fn parent(&self, i: usize) -> Result, Error> { + pub fn parent(&self, i: usize) -> Result { unsafe { let mut raw = ptr::null_mut(); try_call!(raw::git_commit_parent( @@ -334,7 +334,7 @@ impl<'repo> Commit<'repo> { impl<'repo> Binding for Commit<'repo> { type Raw = *mut raw::git_commit; - unsafe fn from_raw(raw: *mut raw::git_commit) -> Commit<'repo> { + unsafe fn from_raw(raw: *mut raw::git_commit) -> Self { Commit { raw, _marker: marker::PhantomData, diff --git a/src/config.rs b/src/config.rs index 9ba0a6da64..724c3e2304 100644 --- a/src/config.rs +++ b/src/config.rs @@ -63,7 +63,7 @@ impl Config { /// /// This object is empty, so you have to add a file to it before you can do /// anything with it. - pub fn new() -> Result { + pub fn new() -> Result { crate::init(); let mut raw = ptr::null_mut(); unsafe { @@ -73,7 +73,7 @@ impl Config { } /// Create a new config instance containing a single on-disk file - pub fn open(path: &Path) -> Result { + pub fn open(path: &Path) -> Result { crate::init(); let mut raw = ptr::null_mut(); // Normal file path OK (does not need Windows conversion). @@ -89,7 +89,7 @@ impl Config { /// Utility wrapper that finds the global, XDG and system configuration /// files and opens them into a single prioritized config object that can /// be used when accessing default config data outside a repository. - pub fn open_default() -> Result { + pub fn open_default() -> Result { crate::init(); let mut raw = ptr::null_mut(); unsafe { @@ -377,7 +377,7 @@ impl Config { /// `$XDG_CONFIG_HOME/git/config`. For backwards compatibility, the XDG file /// shouldn't be used unless the use has created it explicitly. With this /// function you'll open the correct one to write to. - pub fn open_global(&mut self) -> Result { + pub fn open_global(&mut self) -> Result { let mut raw = ptr::null_mut(); unsafe { try_call!(raw::git_config_open_global(&mut raw, self.raw)); @@ -389,7 +389,7 @@ impl Config { /// /// The returned config object can be used to perform get/set/delete /// operations on a single specific level. - pub fn open_level(&self, level: ConfigLevel) -> Result { + pub fn open_level(&self, level: ConfigLevel) -> Result { let mut raw = ptr::null_mut(); unsafe { try_call!(raw::git_config_open_level(&mut raw, &*self.raw, level)); @@ -457,7 +457,7 @@ impl Config { /// Create a snapshot of the current state of a configuration, which allows /// you to look into a consistent view of the configuration for looking up /// complex values (e.g. a remote, submodule). - pub fn snapshot(&mut self) -> Result { + pub fn snapshot(&mut self) -> Result { let mut ret = ptr::null_mut(); unsafe { try_call!(raw::git_config_snapshot(&mut ret, self.raw)); @@ -506,8 +506,8 @@ impl Config { impl Binding for Config { type Raw = *mut raw::git_config; - unsafe fn from_raw(raw: *mut raw::git_config) -> Config { - Config { raw } + unsafe fn from_raw(raw: *mut raw::git_config) -> Self { + Self { raw } } fn raw(&self) -> *mut raw::git_config { self.raw @@ -574,7 +574,7 @@ impl<'cfg> ConfigEntry<'cfg> { impl<'cfg> Binding for ConfigEntry<'cfg> { type Raw = *mut raw::git_config_entry; - unsafe fn from_raw(raw: *mut raw::git_config_entry) -> ConfigEntry<'cfg> { + unsafe fn from_raw(raw: *mut raw::git_config_entry) -> Self { ConfigEntry { raw, _marker: marker::PhantomData, @@ -589,7 +589,7 @@ impl<'cfg> Binding for ConfigEntry<'cfg> { impl<'cfg> Binding for ConfigEntries<'cfg> { type Raw = *mut raw::git_config_iterator; - unsafe fn from_raw(raw: *mut raw::git_config_iterator) -> ConfigEntries<'cfg> { + unsafe fn from_raw(raw: *mut raw::git_config_iterator) -> Self { ConfigEntries { raw, current: None, diff --git a/src/cred.rs b/src/cred.rs index 3def56ab6e..50e703c7f1 100644 --- a/src/cred.rs +++ b/src/cred.rs @@ -30,7 +30,7 @@ pub struct CredentialHelper { impl Cred { /// Create a "default" credential usable for Negotiate mechanisms like NTLM /// or Kerberos authentication. - pub fn default() -> Result { + pub fn default() -> Result { crate::init(); let mut out = ptr::null_mut(); unsafe { @@ -42,7 +42,7 @@ impl Cred { /// Create a new ssh key credential object used for querying an ssh-agent. /// /// The username specified is the username to authenticate. - pub fn ssh_key_from_agent(username: &str) -> Result { + pub fn ssh_key_from_agent(username: &str) -> Result { crate::init(); let mut out = ptr::null_mut(); let username = CString::new(username)?; @@ -58,7 +58,7 @@ impl Cred { publickey: Option<&Path>, privatekey: &Path, passphrase: Option<&str>, - ) -> Result { + ) -> Result { crate::init(); let username = CString::new(username)?; let publickey = crate::opt_cstr(publickey)?; @@ -79,7 +79,7 @@ impl Cred { publickey: Option<&str>, privatekey: &str, passphrase: Option<&str>, - ) -> Result { + ) -> Result { crate::init(); let username = CString::new(username)?; let publickey = crate::opt_cstr(publickey)?; @@ -95,7 +95,7 @@ impl Cred { } /// Create a new plain-text username and password credential object. - pub fn userpass_plaintext(username: &str, password: &str) -> Result { + pub fn userpass_plaintext(username: &str, password: &str) -> Result { crate::init(); let username = CString::new(username)?; let password = CString::new(password)?; @@ -122,13 +122,13 @@ impl Cred { config: &Config, url: &str, username: Option<&str>, - ) -> Result { + ) -> Result { match CredentialHelper::new(url) .config(config) .username(username) .execute() { - Some((username, password)) => Cred::userpass_plaintext(&username, &password), + Some((username, password)) => Self::userpass_plaintext(&username, &password), None => Err(Error::from_str( "failed to acquire username/password \ from local configuration", @@ -140,7 +140,7 @@ impl Cred { /// /// This is used with ssh authentication to query for the username if none is /// specified in the URL. - pub fn username(username: &str) -> Result { + pub fn username(username: &str) -> Result { crate::init(); let username = CString::new(username)?; let mut out = ptr::null_mut(); @@ -169,8 +169,8 @@ impl Cred { impl Binding for Cred { type Raw = *mut raw::git_cred; - unsafe fn from_raw(raw: *mut raw::git_cred) -> Cred { - Cred { raw } + unsafe fn from_raw(raw: *mut raw::git_cred) -> Self { + Self { raw } } fn raw(&self) -> *mut raw::git_cred { self.raw @@ -195,8 +195,8 @@ impl CredentialHelper { /// /// The URL specified is the namespace on which this will query credentials. /// Invalid URLs are currently ignored. - pub fn new(url: &str) -> CredentialHelper { - let mut ret = CredentialHelper { + pub fn new(url: &str) -> Self { + let mut ret = Self { protocol: None, host: None, port: None, @@ -220,14 +220,14 @@ impl CredentialHelper { /// Set the username that this credential helper will query with. /// /// By default the username is `None`. - pub fn username(&mut self, username: Option<&str>) -> &mut CredentialHelper { + pub fn username(&mut self, username: Option<&str>) -> &mut Self { self.username = username.map(|s| s.to_string()); self } /// Query the specified configuration object to discover commands to /// execute, usernames to query, etc. - pub fn config(&mut self, config: &Config) -> &mut CredentialHelper { + pub fn config(&mut self, config: &Config) -> &mut Self { // Figure out the configured username/helper program. // // see http://git-scm.com/docs/gitcredentials.html#_configuration_options diff --git a/src/describe.rs b/src/describe.rs index cbaa1893b6..b5b027a269 100644 --- a/src/describe.rs +++ b/src/describe.rs @@ -42,7 +42,7 @@ impl<'repo> Describe<'repo> { impl<'repo> Binding for Describe<'repo> { type Raw = *mut raw::git_describe_result; - unsafe fn from_raw(raw: *mut raw::git_describe_result) -> Describe<'repo> { + unsafe fn from_raw(raw: *mut raw::git_describe_result) -> Self { Describe { raw, _marker: marker::PhantomData, @@ -67,8 +67,8 @@ impl Default for DescribeFormatOptions { impl DescribeFormatOptions { /// Creates a new blank set of formatting options for a description. - pub fn new() -> DescribeFormatOptions { - let mut opts = DescribeFormatOptions { + pub fn new() -> Self { + let mut opts = Self { raw: unsafe { mem::zeroed() }, dirty_suffix: CString::new(Vec::new()).unwrap(), }; @@ -110,8 +110,8 @@ impl Default for DescribeOptions { impl DescribeOptions { /// Creates a new blank set of formatting options for a description. - pub fn new() -> DescribeOptions { - let mut opts = DescribeOptions { + pub fn new() -> Self { + let mut opts = Self { raw: unsafe { mem::zeroed() }, pattern: CString::new(Vec::new()).unwrap(), }; @@ -168,7 +168,7 @@ impl DescribeOptions { impl Binding for DescribeOptions { type Raw = *mut raw::git_describe_options; - unsafe fn from_raw(_raw: *mut raw::git_describe_options) -> DescribeOptions { + unsafe fn from_raw(_raw: *mut raw::git_describe_options) -> Self { panic!("unimplemened") } fn raw(&self) -> *mut raw::git_describe_options { diff --git a/src/diff.rs b/src/diff.rs index 3070550390..763c499836 100644 --- a/src/diff.rs +++ b/src/diff.rs @@ -136,7 +136,7 @@ impl<'repo> Diff<'repo> { /// as if the old version was from the "onto" list and the new version /// is from the "from" list (with the exception that if the item has a /// pending DELETE in the middle, then it will show as deleted). - pub fn merge(&mut self, from: &Diff<'repo>) -> Result<(), Error> { + pub fn merge(&mut self, from: &Self) -> Result<(), Error> { unsafe { try_call!(raw::git_diff_merge(self.raw, &*from.raw)); } @@ -312,7 +312,7 @@ impl Diff<'static> { /// two trees, however there may be subtle differences. For example, /// a patch file likely contains abbreviated object IDs, so the /// object IDs parsed by this function will also be abbreviated. - pub fn from_buffer(buffer: &[u8]) -> Result, Error> { + pub fn from_buffer(buffer: &[u8]) -> Result { crate::init(); let mut diff: *mut raw::git_diff = std::ptr::null_mut(); unsafe { @@ -449,7 +449,7 @@ pub extern "C" fn line_cb_c( impl<'repo> Binding for Diff<'repo> { type Raw = *mut raw::git_diff; - unsafe fn from_raw(raw: *mut raw::git_diff) -> Diff<'repo> { + unsafe fn from_raw(raw: *mut raw::git_diff) -> Self { Diff { raw, _marker: marker::PhantomData, @@ -547,7 +547,7 @@ impl<'a> DiffDelta<'a> { impl<'a> Binding for DiffDelta<'a> { type Raw = *mut raw::git_diff_delta; - unsafe fn from_raw(raw: *mut raw::git_diff_delta) -> DiffDelta<'a> { + unsafe fn from_raw(raw: *mut raw::git_diff_delta) -> Self { DiffDelta { raw, _marker: marker::PhantomData, @@ -633,7 +633,7 @@ impl<'a> DiffFile<'a> { impl<'a> Binding for DiffFile<'a> { type Raw = *const raw::git_diff_file; - unsafe fn from_raw(raw: *const raw::git_diff_file) -> DiffFile<'a> { + unsafe fn from_raw(raw: *const raw::git_diff_file) -> Self { DiffFile { raw, _marker: marker::PhantomData, @@ -669,8 +669,8 @@ impl DiffOptions { /// /// All flags and other options are defaulted to false or their otherwise /// zero equivalents. - pub fn new() -> DiffOptions { - let mut opts = DiffOptions { + pub fn new() -> Self { + let mut opts = Self { pathspec: Vec::new(), pathspec_ptrs: Vec::new(), raw: unsafe { mem::zeroed() }, @@ -681,7 +681,7 @@ impl DiffOptions { opts } - fn flag(&mut self, opt: raw::git_diff_option_t, val: bool) -> &mut DiffOptions { + fn flag(&mut self, opt: raw::git_diff_option_t, val: bool) -> &mut Self { let opt = opt as u32; if val { self.raw.flags |= opt; @@ -692,38 +692,38 @@ impl DiffOptions { } /// Flag indicating whether the sides of the diff will be reversed. - pub fn reverse(&mut self, reverse: bool) -> &mut DiffOptions { + pub fn reverse(&mut self, reverse: bool) -> &mut Self { self.flag(raw::GIT_DIFF_REVERSE, reverse) } /// Flag indicating whether ignored files are included. - pub fn include_ignored(&mut self, include: bool) -> &mut DiffOptions { + pub fn include_ignored(&mut self, include: bool) -> &mut Self { self.flag(raw::GIT_DIFF_INCLUDE_IGNORED, include) } /// Flag indicating whether ignored directories are traversed deeply or not. - pub fn recurse_ignored_dirs(&mut self, recurse: bool) -> &mut DiffOptions { + pub fn recurse_ignored_dirs(&mut self, recurse: bool) -> &mut Self { self.flag(raw::GIT_DIFF_RECURSE_IGNORED_DIRS, recurse) } /// Flag indicating whether untracked files are in the diff - pub fn include_untracked(&mut self, include: bool) -> &mut DiffOptions { + pub fn include_untracked(&mut self, include: bool) -> &mut Self { self.flag(raw::GIT_DIFF_INCLUDE_UNTRACKED, include) } /// Flag indicating whether untracked directories are traversed deeply or /// not. - pub fn recurse_untracked_dirs(&mut self, recurse: bool) -> &mut DiffOptions { + pub fn recurse_untracked_dirs(&mut self, recurse: bool) -> &mut Self { self.flag(raw::GIT_DIFF_RECURSE_UNTRACKED_DIRS, recurse) } /// Flag indicating whether unmodified files are in the diff. - pub fn include_unmodified(&mut self, include: bool) -> &mut DiffOptions { + pub fn include_unmodified(&mut self, include: bool) -> &mut Self { self.flag(raw::GIT_DIFF_INCLUDE_UNMODIFIED, include) } /// If enabled, then Typechange delta records are generated. - pub fn include_typechange(&mut self, include: bool) -> &mut DiffOptions { + pub fn include_typechange(&mut self, include: bool) -> &mut Self { self.flag(raw::GIT_DIFF_INCLUDE_TYPECHANGE, include) } @@ -732,35 +732,35 @@ impl DiffOptions { /// typechange record with the `new_file`'s mode set to tree. /// /// Note that the tree SHA will not be available. - pub fn include_typechange_trees(&mut self, include: bool) -> &mut DiffOptions { + pub fn include_typechange_trees(&mut self, include: bool) -> &mut Self { self.flag(raw::GIT_DIFF_INCLUDE_TYPECHANGE_TREES, include) } /// Flag indicating whether file mode changes are ignored. - pub fn ignore_filemode(&mut self, ignore: bool) -> &mut DiffOptions { + pub fn ignore_filemode(&mut self, ignore: bool) -> &mut Self { self.flag(raw::GIT_DIFF_IGNORE_FILEMODE, ignore) } /// Flag indicating whether all submodules should be treated as unmodified. - pub fn ignore_submodules(&mut self, ignore: bool) -> &mut DiffOptions { + pub fn ignore_submodules(&mut self, ignore: bool) -> &mut Self { self.flag(raw::GIT_DIFF_IGNORE_SUBMODULES, ignore) } /// Flag indicating whether case insensitive filenames should be used. - pub fn ignore_case(&mut self, ignore: bool) -> &mut DiffOptions { + pub fn ignore_case(&mut self, ignore: bool) -> &mut Self { self.flag(raw::GIT_DIFF_IGNORE_CASE, ignore) } /// If pathspecs are specified, this flag means that they should be applied /// as an exact match instead of a fnmatch pattern. - pub fn disable_pathspec_match(&mut self, disable: bool) -> &mut DiffOptions { + pub fn disable_pathspec_match(&mut self, disable: bool) -> &mut Self { self.flag(raw::GIT_DIFF_DISABLE_PATHSPEC_MATCH, disable) } /// Disable updating the `binary` flag in delta records. This is useful when /// iterating over a diff if you don't need hunk and data callbacks and want /// to avoid having to load a file completely. - pub fn skip_binary_check(&mut self, skip: bool) -> &mut DiffOptions { + pub fn skip_binary_check(&mut self, skip: bool) -> &mut Self { self.flag(raw::GIT_DIFF_SKIP_BINARY_CHECK, skip) } @@ -772,7 +772,7 @@ impl DiffOptions { /// /// This flag turns off that scan and immediately labels an untracked /// directory as untracked (changing the behavior to not match core git). - pub fn enable_fast_untracked_dirs(&mut self, enable: bool) -> &mut DiffOptions { + pub fn enable_fast_untracked_dirs(&mut self, enable: bool) -> &mut Self { self.flag(raw::GIT_DIFF_ENABLE_FAST_UNTRACKED_DIRS, enable) } @@ -780,47 +780,47 @@ impl DiffOptions { /// different from the index, but the OID ends up being the same, write the /// correct stat information into the index. Note: without this flag, diff /// will always leave the index untouched. - pub fn update_index(&mut self, update: bool) -> &mut DiffOptions { + pub fn update_index(&mut self, update: bool) -> &mut Self { self.flag(raw::GIT_DIFF_UPDATE_INDEX, update) } /// Include unreadable files in the diff - pub fn include_unreadable(&mut self, include: bool) -> &mut DiffOptions { + pub fn include_unreadable(&mut self, include: bool) -> &mut Self { self.flag(raw::GIT_DIFF_INCLUDE_UNREADABLE, include) } /// Include unreadable files in the diff as untracked files - pub fn include_unreadable_as_untracked(&mut self, include: bool) -> &mut DiffOptions { + pub fn include_unreadable_as_untracked(&mut self, include: bool) -> &mut Self { self.flag(raw::GIT_DIFF_INCLUDE_UNREADABLE_AS_UNTRACKED, include) } /// Treat all files as text, disabling binary attributes and detection. - pub fn force_text(&mut self, force: bool) -> &mut DiffOptions { + pub fn force_text(&mut self, force: bool) -> &mut Self { self.flag(raw::GIT_DIFF_FORCE_TEXT, force) } /// Treat all files as binary, disabling text diffs - pub fn force_binary(&mut self, force: bool) -> &mut DiffOptions { + pub fn force_binary(&mut self, force: bool) -> &mut Self { self.flag(raw::GIT_DIFF_FORCE_BINARY, force) } /// Ignore all whitespace - pub fn ignore_whitespace(&mut self, ignore: bool) -> &mut DiffOptions { + pub fn ignore_whitespace(&mut self, ignore: bool) -> &mut Self { self.flag(raw::GIT_DIFF_IGNORE_WHITESPACE, ignore) } /// Ignore changes in the amount of whitespace - pub fn ignore_whitespace_change(&mut self, ignore: bool) -> &mut DiffOptions { + pub fn ignore_whitespace_change(&mut self, ignore: bool) -> &mut Self { self.flag(raw::GIT_DIFF_IGNORE_WHITESPACE_CHANGE, ignore) } /// Ignore whitespace at the end of line - pub fn ignore_whitespace_eol(&mut self, ignore: bool) -> &mut DiffOptions { + pub fn ignore_whitespace_eol(&mut self, ignore: bool) -> &mut Self { self.flag(raw::GIT_DIFF_IGNORE_WHITESPACE_EOL, ignore) } /// Ignore blank lines - pub fn ignore_blank_lines(&mut self, ignore: bool) -> &mut DiffOptions { + pub fn ignore_blank_lines(&mut self, ignore: bool) -> &mut Self { self.flag(raw::GIT_DIFF_IGNORE_BLANK_LINES, ignore) } @@ -829,7 +829,7 @@ impl DiffOptions { /// This automatically turns on `include_untracked` but it does not turn on /// `recurse_untracked_dirs`. Add that flag if you want the content of every /// single untracked file. - pub fn show_untracked_content(&mut self, show: bool) -> &mut DiffOptions { + pub fn show_untracked_content(&mut self, show: bool) -> &mut Self { self.flag(raw::GIT_DIFF_SHOW_UNTRACKED_CONTENT, show) } @@ -837,30 +837,30 @@ impl DiffOptions { /// are included in the `Diff`. Normally these are skipped in the formats /// that list files (e.g. name-only, name-status, raw). Even with this these /// will not be included in the patch format. - pub fn show_unmodified(&mut self, show: bool) -> &mut DiffOptions { + pub fn show_unmodified(&mut self, show: bool) -> &mut Self { self.flag(raw::GIT_DIFF_SHOW_UNMODIFIED, show) } /// Use the "patience diff" algorithm - pub fn patience(&mut self, patience: bool) -> &mut DiffOptions { + pub fn patience(&mut self, patience: bool) -> &mut Self { self.flag(raw::GIT_DIFF_PATIENCE, patience) } /// Take extra time to find the minimal diff - pub fn minimal(&mut self, minimal: bool) -> &mut DiffOptions { + pub fn minimal(&mut self, minimal: bool) -> &mut Self { self.flag(raw::GIT_DIFF_MINIMAL, minimal) } /// Include the necessary deflate/delta information so that `git-apply` can /// apply given diff information to binary files. - pub fn show_binary(&mut self, show: bool) -> &mut DiffOptions { + pub fn show_binary(&mut self, show: bool) -> &mut Self { self.flag(raw::GIT_DIFF_SHOW_BINARY, show) } /// Use a heuristic that takes indentation and whitespace into account /// which generally can produce better diffs when dealing with ambiguous /// diff hunks. - pub fn indent_heuristic(&mut self, heuristic: bool) -> &mut DiffOptions { + pub fn indent_heuristic(&mut self, heuristic: bool) -> &mut Self { self.flag(raw::GIT_DIFF_INDENT_HEURISTIC, heuristic) } @@ -868,7 +868,7 @@ impl DiffOptions { /// (and to display before and after). /// /// The default value for this is 3. - pub fn context_lines(&mut self, lines: u32) -> &mut DiffOptions { + pub fn context_lines(&mut self, lines: u32) -> &mut Self { self.raw.context_lines = lines; self } @@ -877,13 +877,13 @@ impl DiffOptions { /// the hunks will be merged into one. /// /// The default value for this is 0. - pub fn interhunk_lines(&mut self, lines: u32) -> &mut DiffOptions { + pub fn interhunk_lines(&mut self, lines: u32) -> &mut Self { self.raw.interhunk_lines = lines; self } /// The default value for this is `core.abbrev` or 7 if unset. - pub fn id_abbrev(&mut self, abbrev: u16) -> &mut DiffOptions { + pub fn id_abbrev(&mut self, abbrev: u16) -> &mut Self { self.raw.id_abbrev = abbrev; self } @@ -894,7 +894,7 @@ impl DiffOptions { /// A negative value will disable this entirely. /// /// The default value for this is 512MB. - pub fn max_size(&mut self, size: i64) -> &mut DiffOptions { + pub fn max_size(&mut self, size: i64) -> &mut Self { self.raw.max_size = size as raw::git_off_t; self } @@ -902,7 +902,7 @@ impl DiffOptions { /// The virtual "directory" to prefix old file names with in hunk headers. /// /// The default value for this is "a". - pub fn old_prefix(&mut self, t: T) -> &mut DiffOptions { + pub fn old_prefix(&mut self, t: T) -> &mut Self { self.old_prefix = Some(t.into_c_string().unwrap()); self } @@ -910,13 +910,13 @@ impl DiffOptions { /// The virtual "directory" to prefix new file names with in hunk headers. /// /// The default value for this is "b". - pub fn new_prefix(&mut self, t: T) -> &mut DiffOptions { + pub fn new_prefix(&mut self, t: T) -> &mut Self { self.new_prefix = Some(t.into_c_string().unwrap()); self } /// Add to the array of paths/fnmatch patterns to constrain the diff. - pub fn pathspec(&mut self, pathspec: T) -> &mut DiffOptions { + pub fn pathspec(&mut self, pathspec: T) -> &mut Self { let s = util::cstring_to_repo_path(pathspec).unwrap(); self.pathspec_ptrs.push(s.as_ptr()); self.pathspec.push(s); @@ -992,29 +992,29 @@ impl Binding for DiffLineType { type Raw = raw::git_diff_line_t; unsafe fn from_raw(raw: raw::git_diff_line_t) -> Self { match raw { - raw::GIT_DIFF_LINE_CONTEXT => DiffLineType::Context, - raw::GIT_DIFF_LINE_ADDITION => DiffLineType::Addition, - raw::GIT_DIFF_LINE_DELETION => DiffLineType::Deletion, - raw::GIT_DIFF_LINE_CONTEXT_EOFNL => DiffLineType::ContextEOFNL, - raw::GIT_DIFF_LINE_ADD_EOFNL => DiffLineType::AddEOFNL, - raw::GIT_DIFF_LINE_DEL_EOFNL => DiffLineType::DeleteEOFNL, - raw::GIT_DIFF_LINE_FILE_HDR => DiffLineType::FileHeader, - raw::GIT_DIFF_LINE_HUNK_HDR => DiffLineType::HunkHeader, - raw::GIT_DIFF_LINE_BINARY => DiffLineType::Binary, + raw::GIT_DIFF_LINE_CONTEXT => Self::Context, + raw::GIT_DIFF_LINE_ADDITION => Self::Addition, + raw::GIT_DIFF_LINE_DELETION => Self::Deletion, + raw::GIT_DIFF_LINE_CONTEXT_EOFNL => Self::ContextEOFNL, + raw::GIT_DIFF_LINE_ADD_EOFNL => Self::AddEOFNL, + raw::GIT_DIFF_LINE_DEL_EOFNL => Self::DeleteEOFNL, + raw::GIT_DIFF_LINE_FILE_HDR => Self::FileHeader, + raw::GIT_DIFF_LINE_HUNK_HDR => Self::HunkHeader, + raw::GIT_DIFF_LINE_BINARY => Self::Binary, _ => panic!("Unknown git diff line type"), } } fn raw(&self) -> raw::git_diff_line_t { match *self { - DiffLineType::Context => raw::GIT_DIFF_LINE_CONTEXT, - DiffLineType::Addition => raw::GIT_DIFF_LINE_ADDITION, - DiffLineType::Deletion => raw::GIT_DIFF_LINE_DELETION, - DiffLineType::ContextEOFNL => raw::GIT_DIFF_LINE_CONTEXT_EOFNL, - DiffLineType::AddEOFNL => raw::GIT_DIFF_LINE_ADD_EOFNL, - DiffLineType::DeleteEOFNL => raw::GIT_DIFF_LINE_DEL_EOFNL, - DiffLineType::FileHeader => raw::GIT_DIFF_LINE_FILE_HDR, - DiffLineType::HunkHeader => raw::GIT_DIFF_LINE_HUNK_HDR, - DiffLineType::Binary => raw::GIT_DIFF_LINE_BINARY, + Self::Context => raw::GIT_DIFF_LINE_CONTEXT, + Self::Addition => raw::GIT_DIFF_LINE_ADDITION, + Self::Deletion => raw::GIT_DIFF_LINE_DELETION, + Self::ContextEOFNL => raw::GIT_DIFF_LINE_CONTEXT_EOFNL, + Self::AddEOFNL => raw::GIT_DIFF_LINE_ADD_EOFNL, + Self::DeleteEOFNL => raw::GIT_DIFF_LINE_DEL_EOFNL, + Self::FileHeader => raw::GIT_DIFF_LINE_FILE_HDR, + Self::HunkHeader => raw::GIT_DIFF_LINE_HUNK_HDR, + Self::Binary => raw::GIT_DIFF_LINE_BINARY, } } } @@ -1091,7 +1091,7 @@ impl<'a> DiffLine<'a> { impl<'a> Binding for DiffLine<'a> { type Raw = *const raw::git_diff_line; - unsafe fn from_raw(raw: *const raw::git_diff_line) -> DiffLine<'a> { + unsafe fn from_raw(raw: *const raw::git_diff_line) -> Self { DiffLine { raw, _marker: marker::PhantomData, @@ -1153,7 +1153,7 @@ impl<'a> DiffHunk<'a> { impl<'a> Binding for DiffHunk<'a> { type Raw = *const raw::git_diff_hunk; - unsafe fn from_raw(raw: *const raw::git_diff_hunk) -> DiffHunk<'a> { + unsafe fn from_raw(raw: *const raw::git_diff_hunk) -> Self { DiffHunk { raw, _marker: marker::PhantomData, @@ -1210,8 +1210,8 @@ impl DiffStats { impl Binding for DiffStats { type Raw = *mut raw::git_diff_stats; - unsafe fn from_raw(raw: *mut raw::git_diff_stats) -> DiffStats { - DiffStats { raw } + unsafe fn from_raw(raw: *mut raw::git_diff_stats) -> Self { + Self { raw } } fn raw(&self) -> *mut raw::git_diff_stats { self.raw @@ -1258,7 +1258,7 @@ impl<'a> DiffBinary<'a> { impl<'a> Binding for DiffBinary<'a> { type Raw = *const raw::git_diff_binary; - unsafe fn from_raw(raw: *const raw::git_diff_binary) -> DiffBinary<'a> { + unsafe fn from_raw(raw: *const raw::git_diff_binary) -> Self { DiffBinary { raw, _marker: marker::PhantomData, @@ -1290,7 +1290,7 @@ impl<'a> DiffBinaryFile<'a> { impl<'a> Binding for DiffBinaryFile<'a> { type Raw = *const raw::git_diff_binary_file; - unsafe fn from_raw(raw: *const raw::git_diff_binary_file) -> DiffBinaryFile<'a> { + unsafe fn from_raw(raw: *const raw::git_diff_binary_file) -> Self { DiffBinaryFile { raw, _marker: marker::PhantomData, @@ -1303,19 +1303,19 @@ impl<'a> Binding for DiffBinaryFile<'a> { impl Binding for DiffBinaryKind { type Raw = raw::git_diff_binary_t; - unsafe fn from_raw(raw: raw::git_diff_binary_t) -> DiffBinaryKind { + unsafe fn from_raw(raw: raw::git_diff_binary_t) -> Self { match raw { - raw::GIT_DIFF_BINARY_NONE => DiffBinaryKind::None, - raw::GIT_DIFF_BINARY_LITERAL => DiffBinaryKind::Literal, - raw::GIT_DIFF_BINARY_DELTA => DiffBinaryKind::Delta, + raw::GIT_DIFF_BINARY_NONE => Self::None, + raw::GIT_DIFF_BINARY_LITERAL => Self::Literal, + raw::GIT_DIFF_BINARY_DELTA => Self::Delta, _ => panic!("Unknown git diff binary kind"), } } fn raw(&self) -> raw::git_diff_binary_t { match *self { - DiffBinaryKind::None => raw::GIT_DIFF_BINARY_NONE, - DiffBinaryKind::Literal => raw::GIT_DIFF_BINARY_LITERAL, - DiffBinaryKind::Delta => raw::GIT_DIFF_BINARY_DELTA, + Self::None => raw::GIT_DIFF_BINARY_NONE, + Self::Literal => raw::GIT_DIFF_BINARY_LITERAL, + Self::Delta => raw::GIT_DIFF_BINARY_DELTA, } } } @@ -1331,8 +1331,8 @@ impl DiffFindOptions { /// /// All flags and other options are defaulted to false or their otherwise /// zero equivalents. - pub fn new() -> DiffFindOptions { - let mut opts = DiffFindOptions { + pub fn new() -> Self { + let mut opts = Self { raw: unsafe { mem::zeroed() }, }; assert_eq!( @@ -1342,7 +1342,7 @@ impl DiffFindOptions { opts } - fn flag(&mut self, opt: u32, val: bool) -> &mut DiffFindOptions { + fn flag(&mut self, opt: u32, val: bool) -> &mut Self { if val { self.raw.flags |= opt; } else { @@ -1354,22 +1354,22 @@ impl DiffFindOptions { /// Reset all flags back to their unset state, indicating that /// `diff.renames` should be used instead. This is overridden once any flag /// is set. - pub fn by_config(&mut self) -> &mut DiffFindOptions { + pub fn by_config(&mut self) -> &mut Self { self.flag(0xffffffff, false) } /// Look for renames? - pub fn renames(&mut self, find: bool) -> &mut DiffFindOptions { + pub fn renames(&mut self, find: bool) -> &mut Self { self.flag(raw::GIT_DIFF_FIND_RENAMES, find) } /// Consider old side of modified for renames? - pub fn renames_from_rewrites(&mut self, find: bool) -> &mut DiffFindOptions { + pub fn renames_from_rewrites(&mut self, find: bool) -> &mut Self { self.flag(raw::GIT_DIFF_FIND_RENAMES_FROM_REWRITES, find) } /// Look for copies? - pub fn copies(&mut self, find: bool) -> &mut DiffFindOptions { + pub fn copies(&mut self, find: bool) -> &mut Self { self.flag(raw::GIT_DIFF_FIND_COPIES, find) } @@ -1377,22 +1377,22 @@ impl DiffFindOptions { /// /// For this to work correctly, use `include_unmodified` when the initial /// diff is being generated. - pub fn copies_from_unmodified(&mut self, find: bool) -> &mut DiffFindOptions { + pub fn copies_from_unmodified(&mut self, find: bool) -> &mut Self { self.flag(raw::GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED, find) } /// Mark significant rewrites for split. - pub fn rewrites(&mut self, find: bool) -> &mut DiffFindOptions { + pub fn rewrites(&mut self, find: bool) -> &mut Self { self.flag(raw::GIT_DIFF_FIND_REWRITES, find) } /// Actually split large rewrites into delete/add pairs - pub fn break_rewrites(&mut self, find: bool) -> &mut DiffFindOptions { + pub fn break_rewrites(&mut self, find: bool) -> &mut Self { self.flag(raw::GIT_DIFF_BREAK_REWRITES, find) } #[doc(hidden)] - pub fn break_rewries(&mut self, find: bool) -> &mut DiffFindOptions { + pub fn break_rewries(&mut self, find: bool) -> &mut Self { self.break_rewrites(find) } @@ -1400,32 +1400,32 @@ impl DiffFindOptions { /// /// For this to work correctly use the `include_untracked` option when the /// initial diff is being generated. - pub fn for_untracked(&mut self, find: bool) -> &mut DiffFindOptions { + pub fn for_untracked(&mut self, find: bool) -> &mut Self { self.flag(raw::GIT_DIFF_FIND_FOR_UNTRACKED, find) } /// Turn on all finding features. - pub fn all(&mut self, find: bool) -> &mut DiffFindOptions { + pub fn all(&mut self, find: bool) -> &mut Self { self.flag(raw::GIT_DIFF_FIND_ALL, find) } /// Measure similarity ignoring leading whitespace (default) - pub fn ignore_leading_whitespace(&mut self, ignore: bool) -> &mut DiffFindOptions { + pub fn ignore_leading_whitespace(&mut self, ignore: bool) -> &mut Self { self.flag(raw::GIT_DIFF_FIND_IGNORE_LEADING_WHITESPACE, ignore) } /// Measure similarity ignoring all whitespace - pub fn ignore_whitespace(&mut self, ignore: bool) -> &mut DiffFindOptions { + pub fn ignore_whitespace(&mut self, ignore: bool) -> &mut Self { self.flag(raw::GIT_DIFF_FIND_IGNORE_WHITESPACE, ignore) } /// Measure similarity including all data - pub fn dont_ignore_whitespace(&mut self, dont: bool) -> &mut DiffFindOptions { + pub fn dont_ignore_whitespace(&mut self, dont: bool) -> &mut Self { self.flag(raw::GIT_DIFF_FIND_DONT_IGNORE_WHITESPACE, dont) } /// Measure similarity only by comparing SHAs (fast and cheap) - pub fn exact_match_only(&mut self, exact: bool) -> &mut DiffFindOptions { + pub fn exact_match_only(&mut self, exact: bool) -> &mut Self { self.flag(raw::GIT_DIFF_FIND_EXACT_MATCH_ONLY, exact) } @@ -1439,7 +1439,7 @@ impl DiffFindOptions { /// If you add this flag in and the split pair is not used for an actual /// rename or copy, then the modified record will be restored to a regular /// modified record instead of being split. - pub fn break_rewrites_for_renames_only(&mut self, b: bool) -> &mut DiffFindOptions { + pub fn break_rewrites_for_renames_only(&mut self, b: bool) -> &mut Self { self.flag(raw::GIT_DIFF_BREAK_REWRITES_FOR_RENAMES_ONLY, b) } @@ -1449,30 +1449,30 @@ impl DiffFindOptions { /// behavior requires building a diff with the `include_unmodified` flag. If /// you do not want unmodified records in the final result, pas this flag to /// have them removed. - pub fn remove_unmodified(&mut self, remove: bool) -> &mut DiffFindOptions { + pub fn remove_unmodified(&mut self, remove: bool) -> &mut Self { self.flag(raw::GIT_DIFF_FIND_REMOVE_UNMODIFIED, remove) } /// Similarity to consider a file renamed (default 50) - pub fn rename_threshold(&mut self, thresh: u16) -> &mut DiffFindOptions { + pub fn rename_threshold(&mut self, thresh: u16) -> &mut Self { self.raw.rename_threshold = thresh; self } /// Similarity of modified to be eligible rename source (default 50) - pub fn rename_from_rewrite_threshold(&mut self, thresh: u16) -> &mut DiffFindOptions { + pub fn rename_from_rewrite_threshold(&mut self, thresh: u16) -> &mut Self { self.raw.rename_from_rewrite_threshold = thresh; self } /// Similarity to consider a file copy (default 50) - pub fn copy_threshold(&mut self, thresh: u16) -> &mut DiffFindOptions { + pub fn copy_threshold(&mut self, thresh: u16) -> &mut Self { self.raw.copy_threshold = thresh; self } /// Similarity to split modify into delete/add pair (default 60) - pub fn break_rewrite_threshold(&mut self, thresh: u16) -> &mut DiffFindOptions { + pub fn break_rewrite_threshold(&mut self, thresh: u16) -> &mut Self { self.raw.break_rewrite_threshold = thresh; self } @@ -1481,7 +1481,7 @@ impl DiffFindOptions { /// git-diff's `-l` option or `diff.renameLimit` config) /// /// Defaults to 200 - pub fn rename_limit(&mut self, limit: usize) -> &mut DiffFindOptions { + pub fn rename_limit(&mut self, limit: usize) -> &mut Self { self.raw.rename_limit = limit as size_t; self } @@ -1504,7 +1504,7 @@ impl DiffFormatEmailOptions { /// Creates a new set of email options, /// initialized to the default values pub fn new() -> Self { - let mut opts = DiffFormatEmailOptions { + let mut opts = Self { raw: unsafe { mem::zeroed() }, }; assert_eq!( @@ -1536,7 +1536,7 @@ impl DiffPatchidOptions { /// Creates a new set of patchid options, /// initialized to the default values pub fn new() -> Self { - let mut opts = DiffPatchidOptions { + let mut opts = Self { raw: unsafe { mem::zeroed() }, }; assert_eq!( diff --git a/src/error.rs b/src/error.rs index ecc7f4f776..367a498ec3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -22,7 +22,7 @@ impl Error { /// database backends, where it is desirable to propagate an [`Error`] /// through `libgit2`. pub fn new>(code: ErrorCode, class: ErrorClass, message: S) -> Self { - let mut err = Error::from_str(message.as_ref()); + let mut err = Self::from_str(message.as_ref()); err.set_code(code); err.set_class(class); err @@ -32,7 +32,7 @@ impl Error { /// /// The `code` argument typically comes from the return value of a function /// call. This code will later be returned from the `code` function. - pub fn last_error(code: c_int) -> Error { + pub fn last_error(code: c_int) -> Self { crate::init(); unsafe { // Note that whenever libgit2 returns an error any negative value @@ -52,21 +52,21 @@ impl Error { // canned error out. let ptr = raw::git_error_last(); let err = if ptr.is_null() { - let mut error = Error::from_str("an unknown git error occurred"); + let mut error = Self::from_str("an unknown git error occurred"); error.code = code; error } else { - Error::from_raw(code, ptr) + Self::from_raw(code, ptr) }; raw::git_error_clear(); err } } - unsafe fn from_raw(code: c_int, ptr: *const raw::git_error) -> Error { + unsafe fn from_raw(code: c_int, ptr: *const raw::git_error) -> Self { let message = CStr::from_ptr((*ptr).message as *const _).to_bytes(); let message = String::from_utf8_lossy(message).into_owned().into(); - Error { + Self { code, klass: (*ptr).klass, message, @@ -77,8 +77,8 @@ impl Error { /// /// The error returned will have the code `GIT_ERROR` and the class /// `GIT_ERROR_NONE`. - pub fn from_str(s: &str) -> Error { - Error { + pub fn from_str(s: &str) -> Self { + Self { code: raw::GIT_ERROR as c_int, klass: raw::GIT_ERROR_NONE as c_int, message: s.into(), @@ -384,8 +384,8 @@ impl fmt::Display for Error { } impl From for Error { - fn from(_: NulError) -> Error { - Error::from_str( + fn from(_: NulError) -> Self { + Self::from_str( "data contained a nul byte that could not be \ represented as a string", ) @@ -393,8 +393,8 @@ impl From for Error { } impl From for Error { - fn from(e: JoinPathsError) -> Error { - Error::from_str(&e.to_string()) + fn from(e: JoinPathsError) -> Self { + Self::from_str(&e.to_string()) } } diff --git a/src/index.rs b/src/index.rs index c0d9294520..f7a0a5491f 100644 --- a/src/index.rs +++ b/src/index.rs @@ -90,7 +90,7 @@ impl Index { /// /// This index object cannot be read/written to the filesystem, but may be /// used to perform in-memory index operations. - pub fn new() -> Result { + pub fn new() -> Result { crate::init(); let mut raw = ptr::null_mut(); unsafe { @@ -107,7 +107,7 @@ impl Index { /// /// If you need an index attached to a repository, use the `index()` method /// on `Repository`. - pub fn open(index_path: &Path) -> Result { + pub fn open(index_path: &Path) -> Result { crate::init(); let mut raw = ptr::null_mut(); // Normal file path OK (does not need Windows conversion). @@ -704,8 +704,8 @@ impl IndexEntry { impl Binding for Index { type Raw = *mut raw::git_index; - unsafe fn from_raw(raw: *mut raw::git_index) -> Index { - Index { raw } + unsafe fn from_raw(raw: *mut raw::git_index) -> Self { + Self { raw } } fn raw(&self) -> *mut raw::git_index { self.raw @@ -715,7 +715,7 @@ impl Binding for Index { impl<'index> Binding for IndexConflicts<'index> { type Raw = *mut raw::git_index_conflict_iterator; - unsafe fn from_raw(raw: *mut raw::git_index_conflict_iterator) -> IndexConflicts<'index> { + unsafe fn from_raw(raw: *mut raw::git_index_conflict_iterator) -> Self { IndexConflicts { conflict_iter: raw, _marker: marker::PhantomData, @@ -796,7 +796,7 @@ impl<'index> Iterator for IndexConflicts<'index> { impl Binding for IndexEntry { type Raw = raw::git_index_entry; - unsafe fn from_raw(raw: raw::git_index_entry) -> IndexEntry { + unsafe fn from_raw(raw: raw::git_index_entry) -> Self { let raw::git_index_entry { ctime, mtime, @@ -822,7 +822,7 @@ impl Binding for IndexEntry { let path = slice::from_raw_parts(path as *const u8, pathlen); - IndexEntry { + Self { dev, ino, mode, diff --git a/src/indexer.rs b/src/indexer.rs index 3a3ff62a5a..5c5ff182ad 100644 --- a/src/indexer.rs +++ b/src/indexer.rs @@ -71,7 +71,7 @@ impl<'a> Progress<'a> { impl<'a> Binding for Progress<'a> { type Raw = *const raw::git_indexer_progress; - unsafe fn from_raw(raw: *const raw::git_indexer_progress) -> Progress<'a> { + unsafe fn from_raw(raw: *const raw::git_indexer_progress) -> Self { Progress { raw: ProgressState::Borrowed(raw), _marker: marker::PhantomData, diff --git a/src/lib.rs b/src/lib.rs index 28f0887b82..d4392d44ba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -485,7 +485,7 @@ impl CredentialType { impl Default for CredentialType { fn default() -> Self { - CredentialType::DEFAULT + Self::DEFAULT } } @@ -553,7 +553,7 @@ impl IndexAddOption { impl Default for IndexAddOption { fn default() -> Self { - IndexAddOption::DEFAULT + Self::DEFAULT } } @@ -915,13 +915,13 @@ impl ObjectType { } /// Convert a raw git_object_t to an ObjectType - pub fn from_raw(raw: raw::git_object_t) -> Option { + pub fn from_raw(raw: raw::git_object_t) -> Option { match raw { - raw::GIT_OBJECT_ANY => Some(ObjectType::Any), - raw::GIT_OBJECT_COMMIT => Some(ObjectType::Commit), - raw::GIT_OBJECT_TREE => Some(ObjectType::Tree), - raw::GIT_OBJECT_BLOB => Some(ObjectType::Blob), - raw::GIT_OBJECT_TAG => Some(ObjectType::Tag), + raw::GIT_OBJECT_ANY => Some(Self::Any), + raw::GIT_OBJECT_COMMIT => Some(Self::Commit), + raw::GIT_OBJECT_TREE => Some(Self::Tree), + raw::GIT_OBJECT_BLOB => Some(Self::Blob), + raw::GIT_OBJECT_TAG => Some(Self::Tag), _ => None, } } @@ -932,9 +932,9 @@ impl ObjectType { } /// Convert a string object type representation to its object type. - pub fn from_str(s: &str) -> Option { + pub fn from_str(s: &str) -> Option { let raw = unsafe { call!(raw::git_object_string2type(CString::new(s).unwrap())) }; - ObjectType::from_raw(raw) + Self::from_raw(raw) } } @@ -948,16 +948,16 @@ impl ReferenceType { /// Convert an object type to its string representation. pub fn str(&self) -> &'static str { match self { - ReferenceType::Direct => "direct", - ReferenceType::Symbolic => "symbolic", + Self::Direct => "direct", + Self::Symbolic => "symbolic", } } /// Convert a raw git_reference_t to a ReferenceType. - pub fn from_raw(raw: raw::git_reference_t) -> Option { + pub fn from_raw(raw: raw::git_reference_t) -> Option { match raw { - raw::GIT_REFERENCE_DIRECT => Some(ReferenceType::Direct), - raw::GIT_REFERENCE_SYMBOLIC => Some(ReferenceType::Symbolic), + raw::GIT_REFERENCE_DIRECT => Some(Self::Direct), + raw::GIT_REFERENCE_SYMBOLIC => Some(Self::Symbolic), _ => None, } } @@ -971,16 +971,16 @@ impl fmt::Display for ReferenceType { impl ConfigLevel { /// Converts a raw configuration level to a ConfigLevel - pub fn from_raw(raw: raw::git_config_level_t) -> ConfigLevel { + pub fn from_raw(raw: raw::git_config_level_t) -> Self { match raw { - raw::GIT_CONFIG_LEVEL_PROGRAMDATA => ConfigLevel::ProgramData, - raw::GIT_CONFIG_LEVEL_SYSTEM => ConfigLevel::System, - raw::GIT_CONFIG_LEVEL_XDG => ConfigLevel::XDG, - raw::GIT_CONFIG_LEVEL_GLOBAL => ConfigLevel::Global, - raw::GIT_CONFIG_LEVEL_LOCAL => ConfigLevel::Local, - raw::GIT_CONFIG_LEVEL_WORKTREE => ConfigLevel::Worktree, - raw::GIT_CONFIG_LEVEL_APP => ConfigLevel::App, - raw::GIT_CONFIG_HIGHEST_LEVEL => ConfigLevel::Highest, + raw::GIT_CONFIG_LEVEL_PROGRAMDATA => Self::ProgramData, + raw::GIT_CONFIG_LEVEL_SYSTEM => Self::System, + raw::GIT_CONFIG_LEVEL_XDG => Self::XDG, + raw::GIT_CONFIG_LEVEL_GLOBAL => Self::Global, + raw::GIT_CONFIG_LEVEL_LOCAL => Self::Local, + raw::GIT_CONFIG_LEVEL_WORKTREE => Self::Worktree, + raw::GIT_CONFIG_LEVEL_APP => Self::App, + raw::GIT_CONFIG_HIGHEST_LEVEL => Self::Highest, n => panic!("unknown config level: {}", n), } } @@ -990,11 +990,11 @@ impl SubmoduleIgnore { /// Converts a [`raw::git_submodule_ignore_t`] to a [`SubmoduleIgnore`] pub fn from_raw(raw: raw::git_submodule_ignore_t) -> Self { match raw { - raw::GIT_SUBMODULE_IGNORE_UNSPECIFIED => SubmoduleIgnore::Unspecified, - raw::GIT_SUBMODULE_IGNORE_NONE => SubmoduleIgnore::None, - raw::GIT_SUBMODULE_IGNORE_UNTRACKED => SubmoduleIgnore::Untracked, - raw::GIT_SUBMODULE_IGNORE_DIRTY => SubmoduleIgnore::Dirty, - raw::GIT_SUBMODULE_IGNORE_ALL => SubmoduleIgnore::All, + raw::GIT_SUBMODULE_IGNORE_UNSPECIFIED => Self::Unspecified, + raw::GIT_SUBMODULE_IGNORE_NONE => Self::None, + raw::GIT_SUBMODULE_IGNORE_UNTRACKED => Self::Untracked, + raw::GIT_SUBMODULE_IGNORE_DIRTY => Self::Dirty, + raw::GIT_SUBMODULE_IGNORE_ALL => Self::All, n => panic!("unknown submodule ignore rule: {}", n), } } @@ -1004,11 +1004,11 @@ impl SubmoduleUpdate { /// Converts a [`raw::git_submodule_update_t`] to a [`SubmoduleUpdate`] pub fn from_raw(raw: raw::git_submodule_update_t) -> Self { match raw { - raw::GIT_SUBMODULE_UPDATE_CHECKOUT => SubmoduleUpdate::Checkout, - raw::GIT_SUBMODULE_UPDATE_REBASE => SubmoduleUpdate::Rebase, - raw::GIT_SUBMODULE_UPDATE_MERGE => SubmoduleUpdate::Merge, - raw::GIT_SUBMODULE_UPDATE_NONE => SubmoduleUpdate::None, - raw::GIT_SUBMODULE_UPDATE_DEFAULT => SubmoduleUpdate::Default, + raw::GIT_SUBMODULE_UPDATE_CHECKOUT => Self::Checkout, + raw::GIT_SUBMODULE_UPDATE_REBASE => Self::Rebase, + raw::GIT_SUBMODULE_UPDATE_MERGE => Self::Merge, + raw::GIT_SUBMODULE_UPDATE_NONE => Self::None, + raw::GIT_SUBMODULE_UPDATE_DEFAULT => Self::Default, n => panic!("unknown submodule update strategy: {}", n), } } @@ -1141,29 +1141,29 @@ pub enum FileMode { } impl From for i32 { - fn from(mode: FileMode) -> i32 { + fn from(mode: FileMode) -> Self { match mode { - FileMode::Unreadable => raw::GIT_FILEMODE_UNREADABLE as i32, - FileMode::Tree => raw::GIT_FILEMODE_TREE as i32, - FileMode::Blob => raw::GIT_FILEMODE_BLOB as i32, - FileMode::BlobGroupWritable => raw::GIT_FILEMODE_BLOB_GROUP_WRITABLE as i32, - FileMode::BlobExecutable => raw::GIT_FILEMODE_BLOB_EXECUTABLE as i32, - FileMode::Link => raw::GIT_FILEMODE_LINK as i32, - FileMode::Commit => raw::GIT_FILEMODE_COMMIT as i32, + FileMode::Unreadable => raw::GIT_FILEMODE_UNREADABLE as Self, + FileMode::Tree => raw::GIT_FILEMODE_TREE as Self, + FileMode::Blob => raw::GIT_FILEMODE_BLOB as Self, + FileMode::BlobGroupWritable => raw::GIT_FILEMODE_BLOB_GROUP_WRITABLE as Self, + FileMode::BlobExecutable => raw::GIT_FILEMODE_BLOB_EXECUTABLE as Self, + FileMode::Link => raw::GIT_FILEMODE_LINK as Self, + FileMode::Commit => raw::GIT_FILEMODE_COMMIT as Self, } } } impl From for u32 { - fn from(mode: FileMode) -> u32 { + fn from(mode: FileMode) -> Self { match mode { - FileMode::Unreadable => raw::GIT_FILEMODE_UNREADABLE as u32, - FileMode::Tree => raw::GIT_FILEMODE_TREE as u32, - FileMode::Blob => raw::GIT_FILEMODE_BLOB as u32, - FileMode::BlobGroupWritable => raw::GIT_FILEMODE_BLOB_GROUP_WRITABLE as u32, - FileMode::BlobExecutable => raw::GIT_FILEMODE_BLOB_EXECUTABLE as u32, - FileMode::Link => raw::GIT_FILEMODE_LINK as u32, - FileMode::Commit => raw::GIT_FILEMODE_COMMIT as u32, + FileMode::Unreadable => raw::GIT_FILEMODE_UNREADABLE as Self, + FileMode::Tree => raw::GIT_FILEMODE_TREE as Self, + FileMode::Blob => raw::GIT_FILEMODE_BLOB as Self, + FileMode::BlobGroupWritable => raw::GIT_FILEMODE_BLOB_GROUP_WRITABLE as Self, + FileMode::BlobExecutable => raw::GIT_FILEMODE_BLOB_EXECUTABLE as Self, + FileMode::Link => raw::GIT_FILEMODE_LINK as Self, + FileMode::Commit => raw::GIT_FILEMODE_COMMIT as Self, } } } @@ -1346,7 +1346,7 @@ impl PathspecFlags { impl Default for PathspecFlags { fn default() -> Self { - PathspecFlags::DEFAULT + Self::DEFAULT } } @@ -1482,7 +1482,7 @@ impl StashApplyFlags { impl Default for StashApplyFlags { fn default() -> Self { - StashApplyFlags::DEFAULT + Self::DEFAULT } } @@ -1515,7 +1515,7 @@ impl StashFlags { impl Default for StashFlags { fn default() -> Self { - StashFlags::DEFAULT + Self::DEFAULT } } @@ -1536,7 +1536,7 @@ bitflags! { impl Default for AttrCheckFlags { fn default() -> Self { - AttrCheckFlags::FILE_THEN_INDEX + Self::FILE_THEN_INDEX } } @@ -1593,7 +1593,7 @@ impl ReferenceFormat { impl Default for ReferenceFormat { fn default() -> Self { - ReferenceFormat::NORMAL + Self::NORMAL } } diff --git a/src/mailmap.rs b/src/mailmap.rs index 096b3227c7..45371fe993 100644 --- a/src/mailmap.rs +++ b/src/mailmap.rs @@ -14,8 +14,8 @@ pub struct Mailmap { impl Binding for Mailmap { type Raw = *mut raw::git_mailmap; - unsafe fn from_raw(ptr: *mut raw::git_mailmap) -> Mailmap { - Mailmap { raw: ptr } + unsafe fn from_raw(ptr: *mut raw::git_mailmap) -> Self { + Self { raw: ptr } } fn raw(&self) -> *mut raw::git_mailmap { @@ -33,7 +33,7 @@ impl Drop for Mailmap { impl Mailmap { /// Creates an empty, in-memory mailmap object. - pub fn new() -> Result { + pub fn new() -> Result { crate::init(); let mut ret = ptr::null_mut(); unsafe { @@ -43,7 +43,7 @@ impl Mailmap { } /// Creates an in-memory mailmap object representing the given buffer. - pub fn from_buffer(buf: &str) -> Result { + pub fn from_buffer(buf: &str) -> Result { crate::init(); let mut ret = ptr::null_mut(); let len = buf.len(); diff --git a/src/mempack.rs b/src/mempack.rs index a780707913..8e50c5637c 100644 --- a/src/mempack.rs +++ b/src/mempack.rs @@ -14,7 +14,7 @@ pub struct Mempack<'odb> { impl<'odb> Binding for Mempack<'odb> { type Raw = *mut raw::git_odb_backend; - unsafe fn from_raw(raw: *mut raw::git_odb_backend) -> Mempack<'odb> { + unsafe fn from_raw(raw: *mut raw::git_odb_backend) -> Self { Mempack { raw, _marker: marker::PhantomData, diff --git a/src/merge.rs b/src/merge.rs index bdb32970a9..9524514b41 100644 --- a/src/merge.rs +++ b/src/merge.rs @@ -65,15 +65,15 @@ impl Default for MergeOptions { impl MergeOptions { /// Creates a default set of merge options. - pub fn new() -> MergeOptions { - let mut opts = MergeOptions { + pub fn new() -> Self { + let mut opts = Self { raw: unsafe { mem::zeroed() }, }; assert_eq!(unsafe { raw::git_merge_init_options(&mut opts.raw, 1) }, 0); opts } - fn flag(&mut self, opt: u32, val: bool) -> &mut MergeOptions { + fn flag(&mut self, opt: u32, val: bool) -> &mut Self { if val { self.raw.flags |= opt; } else { @@ -83,30 +83,30 @@ impl MergeOptions { } /// Detect file renames - pub fn find_renames(&mut self, find: bool) -> &mut MergeOptions { + pub fn find_renames(&mut self, find: bool) -> &mut Self { self.flag(raw::GIT_MERGE_FIND_RENAMES as u32, find) } /// If a conflict occurs, exit immediately instead of attempting to continue /// resolving conflicts - pub fn fail_on_conflict(&mut self, fail: bool) -> &mut MergeOptions { + pub fn fail_on_conflict(&mut self, fail: bool) -> &mut Self { self.flag(raw::GIT_MERGE_FAIL_ON_CONFLICT as u32, fail) } /// Do not write the REUC extension on the generated index - pub fn skip_reuc(&mut self, skip: bool) -> &mut MergeOptions { + pub fn skip_reuc(&mut self, skip: bool) -> &mut Self { self.flag(raw::GIT_MERGE_FAIL_ON_CONFLICT as u32, skip) } /// If the commits being merged have multiple merge bases, do not build a /// recursive merge base (by merging the multiple merge bases), instead /// simply use the first base. - pub fn no_recursive(&mut self, disable: bool) -> &mut MergeOptions { + pub fn no_recursive(&mut self, disable: bool) -> &mut Self { self.flag(raw::GIT_MERGE_NO_RECURSIVE as u32, disable) } /// Similarity to consider a file renamed (default 50) - pub fn rename_threshold(&mut self, thresh: u32) -> &mut MergeOptions { + pub fn rename_threshold(&mut self, thresh: u32) -> &mut Self { self.raw.rename_threshold = thresh; self } @@ -115,7 +115,7 @@ impl MergeOptions { /// If the number of rename candidates (add / delete pairs) is greater /// than this value, inexact rename detection is aborted. This setting /// overrides the `merge.renameLimit` configuration value. - pub fn target_limit(&mut self, limit: u32) -> &mut MergeOptions { + pub fn target_limit(&mut self, limit: u32) -> &mut Self { self.raw.target_limit = limit as c_uint; self } @@ -124,18 +124,18 @@ impl MergeOptions { /// virtual merge base when faced with criss-cross merges. When /// this limit is reached, the next ancestor will simply be used /// instead of attempting to merge it. The default is unlimited. - pub fn recursion_limit(&mut self, limit: u32) -> &mut MergeOptions { + pub fn recursion_limit(&mut self, limit: u32) -> &mut Self { self.raw.recursion_limit = limit as c_uint; self } /// Specify a side to favor for resolving conflicts - pub fn file_favor(&mut self, favor: FileFavor) -> &mut MergeOptions { + pub fn file_favor(&mut self, favor: FileFavor) -> &mut Self { self.raw.file_favor = favor.convert(); self } - fn file_flag(&mut self, opt: u32, val: bool) -> &mut MergeOptions { + fn file_flag(&mut self, opt: u32, val: bool) -> &mut Self { if val { self.raw.file_flags |= opt; } else { @@ -145,42 +145,42 @@ impl MergeOptions { } /// Create standard conflicted merge files - pub fn standard_style(&mut self, standard: bool) -> &mut MergeOptions { + pub fn standard_style(&mut self, standard: bool) -> &mut Self { self.file_flag(raw::GIT_MERGE_FILE_STYLE_MERGE as u32, standard) } /// Create diff3-style file - pub fn diff3_style(&mut self, diff3: bool) -> &mut MergeOptions { + pub fn diff3_style(&mut self, diff3: bool) -> &mut Self { self.file_flag(raw::GIT_MERGE_FILE_STYLE_DIFF3 as u32, diff3) } /// Condense non-alphanumeric regions for simplified diff file - pub fn simplify_alnum(&mut self, simplify: bool) -> &mut MergeOptions { + pub fn simplify_alnum(&mut self, simplify: bool) -> &mut Self { self.file_flag(raw::GIT_MERGE_FILE_SIMPLIFY_ALNUM as u32, simplify) } /// Ignore all whitespace - pub fn ignore_whitespace(&mut self, ignore: bool) -> &mut MergeOptions { + pub fn ignore_whitespace(&mut self, ignore: bool) -> &mut Self { self.file_flag(raw::GIT_MERGE_FILE_IGNORE_WHITESPACE as u32, ignore) } /// Ignore changes in amount of whitespace - pub fn ignore_whitespace_change(&mut self, ignore: bool) -> &mut MergeOptions { + pub fn ignore_whitespace_change(&mut self, ignore: bool) -> &mut Self { self.file_flag(raw::GIT_MERGE_FILE_IGNORE_WHITESPACE_CHANGE as u32, ignore) } /// Ignore whitespace at end of line - pub fn ignore_whitespace_eol(&mut self, ignore: bool) -> &mut MergeOptions { + pub fn ignore_whitespace_eol(&mut self, ignore: bool) -> &mut Self { self.file_flag(raw::GIT_MERGE_FILE_IGNORE_WHITESPACE_EOL as u32, ignore) } /// Use the "patience diff" algorithm - pub fn patience(&mut self, patience: bool) -> &mut MergeOptions { + pub fn patience(&mut self, patience: bool) -> &mut Self { self.file_flag(raw::GIT_MERGE_FILE_DIFF_PATIENCE as u32, patience) } /// Take extra time to find minimal diff - pub fn minimal(&mut self, minimal: bool) -> &mut MergeOptions { + pub fn minimal(&mut self, minimal: bool) -> &mut Self { self.file_flag(raw::GIT_MERGE_FILE_DIFF_MINIMAL as u32, minimal) } @@ -192,7 +192,7 @@ impl MergeOptions { impl<'repo> Binding for AnnotatedCommit<'repo> { type Raw = *mut raw::git_annotated_commit; - unsafe fn from_raw(raw: *mut raw::git_annotated_commit) -> AnnotatedCommit<'repo> { + unsafe fn from_raw(raw: *mut raw::git_annotated_commit) -> Self { AnnotatedCommit { raw, _marker: marker::PhantomData, @@ -217,8 +217,8 @@ impl Default for MergeFileOptions { impl MergeFileOptions { /// Creates a default set of merge file options. - pub fn new() -> MergeFileOptions { - let mut opts = MergeFileOptions { + pub fn new() -> Self { + let mut opts = Self { ancestor_label: None, our_label: None, their_label: None, @@ -233,7 +233,7 @@ impl MergeFileOptions { /// Label for the ancestor file side of the conflict which will be prepended /// to labels in diff3-format merge files. - pub fn ancestor_label(&mut self, t: T) -> &mut MergeFileOptions { + pub fn ancestor_label(&mut self, t: T) -> &mut Self { self.ancestor_label = Some(t.into_c_string().unwrap()); self.raw.ancestor_label = self @@ -247,7 +247,7 @@ impl MergeFileOptions { /// Label for our file side of the conflict which will be prepended to labels /// in merge files. - pub fn our_label(&mut self, t: T) -> &mut MergeFileOptions { + pub fn our_label(&mut self, t: T) -> &mut Self { self.our_label = Some(t.into_c_string().unwrap()); self.raw.our_label = self @@ -261,7 +261,7 @@ impl MergeFileOptions { /// Label for their file side of the conflict which will be prepended to labels /// in merge files. - pub fn their_label(&mut self, t: T) -> &mut MergeFileOptions { + pub fn their_label(&mut self, t: T) -> &mut Self { self.their_label = Some(t.into_c_string().unwrap()); self.raw.their_label = self @@ -274,12 +274,12 @@ impl MergeFileOptions { } /// Specify a side to favor for resolving conflicts - pub fn favor(&mut self, favor: FileFavor) -> &mut MergeFileOptions { + pub fn favor(&mut self, favor: FileFavor) -> &mut Self { self.raw.favor = favor.convert(); self } - fn flag(&mut self, opt: raw::git_merge_file_flag_t, val: bool) -> &mut MergeFileOptions { + fn flag(&mut self, opt: raw::git_merge_file_flag_t, val: bool) -> &mut Self { if val { self.raw.flags |= opt as u32; } else { @@ -289,57 +289,57 @@ impl MergeFileOptions { } /// Create standard conflicted merge files - pub fn style_standard(&mut self, standard: bool) -> &mut MergeFileOptions { + pub fn style_standard(&mut self, standard: bool) -> &mut Self { self.flag(raw::GIT_MERGE_FILE_STYLE_MERGE, standard) } /// Create diff3-style file - pub fn style_diff3(&mut self, diff3: bool) -> &mut MergeFileOptions { + pub fn style_diff3(&mut self, diff3: bool) -> &mut Self { self.flag(raw::GIT_MERGE_FILE_STYLE_DIFF3, diff3) } /// Condense non-alphanumeric regions for simplified diff file - pub fn simplify_alnum(&mut self, simplify: bool) -> &mut MergeFileOptions { + pub fn simplify_alnum(&mut self, simplify: bool) -> &mut Self { self.flag(raw::GIT_MERGE_FILE_SIMPLIFY_ALNUM, simplify) } /// Ignore all whitespace - pub fn ignore_whitespace(&mut self, ignore: bool) -> &mut MergeFileOptions { + pub fn ignore_whitespace(&mut self, ignore: bool) -> &mut Self { self.flag(raw::GIT_MERGE_FILE_IGNORE_WHITESPACE, ignore) } /// Ignore changes in amount of whitespace - pub fn ignore_whitespace_change(&mut self, ignore: bool) -> &mut MergeFileOptions { + pub fn ignore_whitespace_change(&mut self, ignore: bool) -> &mut Self { self.flag(raw::GIT_MERGE_FILE_IGNORE_WHITESPACE_CHANGE, ignore) } /// Ignore whitespace at end of line - pub fn ignore_whitespace_eol(&mut self, ignore: bool) -> &mut MergeFileOptions { + pub fn ignore_whitespace_eol(&mut self, ignore: bool) -> &mut Self { self.flag(raw::GIT_MERGE_FILE_IGNORE_WHITESPACE_EOL, ignore) } /// Use the "patience diff" algorithm - pub fn patience(&mut self, patience: bool) -> &mut MergeFileOptions { + pub fn patience(&mut self, patience: bool) -> &mut Self { self.flag(raw::GIT_MERGE_FILE_DIFF_PATIENCE, patience) } /// Take extra time to find minimal diff - pub fn minimal(&mut self, minimal: bool) -> &mut MergeFileOptions { + pub fn minimal(&mut self, minimal: bool) -> &mut Self { self.flag(raw::GIT_MERGE_FILE_DIFF_MINIMAL, minimal) } /// Create zdiff3 ("zealous diff3")-style files - pub fn style_zdiff3(&mut self, zdiff3: bool) -> &mut MergeFileOptions { + pub fn style_zdiff3(&mut self, zdiff3: bool) -> &mut Self { self.flag(raw::GIT_MERGE_FILE_STYLE_ZDIFF3, zdiff3) } /// Do not produce file conflicts when common regions have changed - pub fn accept_conflicts(&mut self, accept: bool) -> &mut MergeFileOptions { + pub fn accept_conflicts(&mut self, accept: bool) -> &mut Self { self.flag(raw::GIT_MERGE_FILE_ACCEPT_CONFLICTS, accept) } /// The size of conflict markers (eg, "<<<<<<<"). Default is 7. - pub fn marker_size(&mut self, size: u16) -> &mut MergeFileOptions { + pub fn marker_size(&mut self, size: u16) -> &mut Self { self.raw.marker_size = size as c_ushort; self } @@ -387,8 +387,8 @@ impl MergeFileResult { impl Binding for MergeFileResult { type Raw = raw::git_merge_file_result; - unsafe fn from_raw(raw: raw::git_merge_file_result) -> MergeFileResult { - MergeFileResult { raw } + unsafe fn from_raw(raw: raw::git_merge_file_result) -> Self { + Self { raw } } fn raw(&self) -> raw::git_merge_file_result { unimplemented!() diff --git a/src/message.rs b/src/message.rs index a7041da3ae..6754020b0c 100644 --- a/src/message.rs +++ b/src/message.rs @@ -100,7 +100,7 @@ struct MessageTrailers { } impl MessageTrailers { - fn new() -> MessageTrailers { + fn new() -> Self { crate::init(); unsafe { Binding::from_raw(&mut raw::git_message_trailer_array { @@ -134,8 +134,8 @@ impl Drop for MessageTrailers { impl Binding for MessageTrailers { type Raw = *mut raw::git_message_trailer_array; - unsafe fn from_raw(raw: *mut raw::git_message_trailer_array) -> MessageTrailers { - MessageTrailers { raw: *raw } + unsafe fn from_raw(raw: *mut raw::git_message_trailer_array) -> Self { + Self { raw: *raw } } fn raw(&self) -> *mut raw::git_message_trailer_array { &self.raw as *const _ as *mut _ diff --git a/src/note.rs b/src/note.rs index 50e5800fe7..1cf8635d16 100644 --- a/src/note.rs +++ b/src/note.rs @@ -51,7 +51,7 @@ impl<'repo> Note<'repo> { impl<'repo> Binding for Note<'repo> { type Raw = *mut raw::git_note; - unsafe fn from_raw(raw: *mut raw::git_note) -> Note<'repo> { + unsafe fn from_raw(raw: *mut raw::git_note) -> Self { Note { raw, _marker: marker::PhantomData, @@ -78,7 +78,7 @@ impl<'repo> Drop for Note<'repo> { impl<'repo> Binding for Notes<'repo> { type Raw = *mut raw::git_note_iterator; - unsafe fn from_raw(raw: *mut raw::git_note_iterator) -> Notes<'repo> { + unsafe fn from_raw(raw: *mut raw::git_note_iterator) -> Self { Notes { raw, _marker: marker::PhantomData, diff --git a/src/object.rs b/src/object.rs index fcae0066cb..91f0ee2b90 100644 --- a/src/object.rs +++ b/src/object.rs @@ -32,7 +32,7 @@ impl<'repo> Object<'repo> { /// If you pass `Any` as the target type, then the object will be /// peeled until the type changes (e.g. a tag will be chased until the /// referenced object is no longer a tag). - pub fn peel(&self, kind: ObjectType) -> Result, Error> { + pub fn peel(&self, kind: ObjectType) -> Result { let mut raw = ptr::null_mut(); unsafe { try_call!(raw::git_object_peel(&mut raw, &*self.raw(), kind)); @@ -88,7 +88,7 @@ impl<'repo> Object<'repo> { /// Attempt to consume this object and return a commit. /// /// Returns `Err(self)` if this object is not actually a commit. - pub fn into_commit(self) -> Result, Object<'repo>> { + pub fn into_commit(self) -> Result, Self> { self.cast_into(ObjectType::Commit) } @@ -102,7 +102,7 @@ impl<'repo> Object<'repo> { /// Attempt to consume this object and return a tag. /// /// Returns `Err(self)` if this object is not actually a tag. - pub fn into_tag(self) -> Result, Object<'repo>> { + pub fn into_tag(self) -> Result, Self> { self.cast_into(ObjectType::Tag) } @@ -116,7 +116,7 @@ impl<'repo> Object<'repo> { /// Attempt to consume this object and return a tree. /// /// Returns `Err(self)` if this object is not actually a tree. - pub fn into_tree(self) -> Result, Object<'repo>> { + pub fn into_tree(self) -> Result, Self> { self.cast_into(ObjectType::Tree) } @@ -130,7 +130,7 @@ impl<'repo> Object<'repo> { /// Attempt to consume this object and return a blob. /// /// Returns `Err(self)` if this object is not actually a blob. - pub fn into_blob(self) -> Result, Object<'repo>> { + pub fn into_blob(self) -> Result, Self> { self.cast_into(ObjectType::Blob) } @@ -154,7 +154,7 @@ impl<'repo> Object<'repo> { } } - fn cast_into(self, kind: ObjectType) -> Result> { + fn cast_into(self, kind: ObjectType) -> Result { assert_eq!(mem::size_of_val(&self), mem::size_of::()); if self.kind() == Some(kind) { Ok(unsafe { @@ -202,7 +202,7 @@ impl<'repo> CastOrPanic for Object<'repo> { } impl<'repo> Clone for Object<'repo> { - fn clone(&self) -> Object<'repo> { + fn clone(&self) -> Self { let mut raw = ptr::null_mut(); unsafe { let rc = raw::git_object_dup(&mut raw, self.raw); @@ -230,7 +230,7 @@ impl<'repo> std::fmt::Debug for Object<'repo> { impl<'repo> Binding for Object<'repo> { type Raw = *mut raw::git_object; - unsafe fn from_raw(raw: *mut raw::git_object) -> Object<'repo> { + unsafe fn from_raw(raw: *mut raw::git_object) -> Self { Object { raw, _marker: marker::PhantomData, diff --git a/src/odb.rs b/src/odb.rs index 2019908c48..9fd3027606 100644 --- a/src/odb.rs +++ b/src/odb.rs @@ -26,7 +26,7 @@ unsafe impl<'repo> Sync for Odb<'repo> {} impl<'repo> Binding for Odb<'repo> { type Raw = *mut raw::git_odb; - unsafe fn from_raw(raw: *mut raw::git_odb) -> Odb<'repo> { + unsafe fn from_raw(raw: *mut raw::git_odb) -> Self { Odb { raw, _marker: marker::PhantomData, @@ -280,7 +280,7 @@ pub struct OdbObject<'a> { impl<'a> Binding for OdbObject<'a> { type Raw = *mut raw::git_odb_object; - unsafe fn from_raw(raw: *mut raw::git_odb_object) -> OdbObject<'a> { + unsafe fn from_raw(raw: *mut raw::git_odb_object) -> Self { OdbObject { raw, _marker: marker::PhantomData, @@ -338,7 +338,7 @@ unsafe impl<'repo> Send for OdbReader<'repo> {} impl<'repo> Binding for OdbReader<'repo> { type Raw = *mut raw::git_odb_stream; - unsafe fn from_raw(raw: *mut raw::git_odb_stream) -> OdbReader<'repo> { + unsafe fn from_raw(raw: *mut raw::git_odb_stream) -> Self { OdbReader { raw, _marker: marker::PhantomData, @@ -401,7 +401,7 @@ impl<'repo> OdbWriter<'repo> { impl<'repo> Binding for OdbWriter<'repo> { type Raw = *mut raw::git_odb_stream; - unsafe fn from_raw(raw: *mut raw::git_odb_stream) -> OdbWriter<'repo> { + unsafe fn from_raw(raw: *mut raw::git_odb_stream) -> Self { OdbWriter { raw, _marker: marker::PhantomData, @@ -467,7 +467,7 @@ impl<'repo> OdbPackwriter<'repo> { /// The callback through which progress is monitored. Be aware that this is /// called inline, so performance may be affected. - pub fn progress(&mut self, cb: F) -> &mut OdbPackwriter<'repo> + pub fn progress(&mut self, cb: F) -> &mut Self where F: FnMut(Progress<'_>) -> bool + 'repo, { diff --git a/src/oid.rs b/src/oid.rs index 35516cb181..1456e3a8f4 100644 --- a/src/oid.rs +++ b/src/oid.rs @@ -22,7 +22,7 @@ impl Oid { /// /// Returns an error if the string is empty, is longer than 40 hex /// characters, or contains any non-hex characters. - pub fn from_str(s: &str) -> Result { + pub fn from_str(s: &str) -> Result { crate::init(); let mut raw = raw::git_oid { id: [0; raw::GIT_OID_RAWSZ], @@ -34,13 +34,13 @@ impl Oid { s.len() as libc::size_t )); } - Ok(Oid { raw }) + Ok(Self { raw }) } /// Parse a raw object id into an Oid structure. /// /// If the array given is not 20 bytes in length, an error is returned. - pub fn from_bytes(bytes: &[u8]) -> Result { + pub fn from_bytes(bytes: &[u8]) -> Result { crate::init(); let mut raw = raw::git_oid { id: [0; raw::GIT_OID_RAWSZ], @@ -51,22 +51,22 @@ impl Oid { unsafe { try_call!(raw::git_oid_fromraw(&mut raw, bytes.as_ptr())); } - Ok(Oid { raw }) + Ok(Self { raw }) } } /// Creates an all zero Oid structure. - pub fn zero() -> Oid { + pub fn zero() -> Self { let out = raw::git_oid { id: [0; raw::GIT_OID_RAWSZ], }; - Oid { raw: out } + Self { raw: out } } /// Hashes the provided data as an object of the provided type, and returns /// an Oid corresponding to the result. This does not store the object /// inside any object database or repository. - pub fn hash_object(kind: ObjectType, bytes: &[u8]) -> Result { + pub fn hash_object(kind: ObjectType, bytes: &[u8]) -> Result { crate::init(); let mut out = raw::git_oid { @@ -81,13 +81,13 @@ impl Oid { )); } - Ok(Oid { raw: out }) + Ok(Self { raw: out }) } /// Hashes the content of the provided file as an object of the provided type, /// and returns an Oid corresponding to the result. This does not store the object /// inside any object database or repository. - pub fn hash_file>(kind: ObjectType, path: P) -> Result { + pub fn hash_file>(kind: ObjectType, path: P) -> Result { crate::init(); // Normal file path OK (does not need Windows conversion). @@ -100,7 +100,7 @@ impl Oid { try_call!(raw::git_odb_hashfile(&mut out, rpath, kind.raw())); } - Ok(Oid { raw: out }) + Ok(Self { raw: out }) } /// View this OID as a byte-slice 20 bytes in length. @@ -117,8 +117,8 @@ impl Oid { impl Binding for Oid { type Raw = *const raw::git_oid; - unsafe fn from_raw(oid: *const raw::git_oid) -> Oid { - Oid { raw: *oid } + unsafe fn from_raw(oid: *const raw::git_oid) -> Self { + Self { raw: *oid } } fn raw(&self) -> *const raw::git_oid { &self.raw as *const _ @@ -156,26 +156,26 @@ impl str::FromStr for Oid { /// /// Returns an error if the string is empty, is longer than 40 hex /// characters, or contains any non-hex characters. - fn from_str(s: &str) -> Result { - Oid::from_str(s) + fn from_str(s: &str) -> Result { + Self::from_str(s) } } impl PartialEq for Oid { - fn eq(&self, other: &Oid) -> bool { + fn eq(&self, other: &Self) -> bool { unsafe { raw::git_oid_equal(&self.raw, &other.raw) != 0 } } } impl Eq for Oid {} impl PartialOrd for Oid { - fn partial_cmp(&self, other: &Oid) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } impl Ord for Oid { - fn cmp(&self, other: &Oid) -> Ordering { + fn cmp(&self, other: &Self) -> Ordering { c_cmp_to_ordering(unsafe { raw::git_oid_cmp(&self.raw, &other.raw) }) } } diff --git a/src/oid_array.rs b/src/oid_array.rs index 0d87ce9954..87153249a0 100644 --- a/src/oid_array.rs +++ b/src/oid_array.rs @@ -31,8 +31,8 @@ impl Deref for OidArray { impl Binding for OidArray { type Raw = raw::git_oidarray; - unsafe fn from_raw(raw: raw::git_oidarray) -> OidArray { - OidArray { raw } + unsafe fn from_raw(raw: raw::git_oidarray) -> Self { + Self { raw } } fn raw(&self) -> raw::git_oidarray { self.raw diff --git a/src/packbuilder.rs b/src/packbuilder.rs index de47bbce32..c2b5bc7208 100644 --- a/src/packbuilder.rs +++ b/src/packbuilder.rs @@ -216,7 +216,7 @@ impl<'repo> PackBuilder<'repo> { impl<'repo> Binding for PackBuilder<'repo> { type Raw = *mut raw::git_packbuilder; - unsafe fn from_raw(ptr: *mut raw::git_packbuilder) -> PackBuilder<'repo> { + unsafe fn from_raw(ptr: *mut raw::git_packbuilder) -> Self { PackBuilder { raw: ptr, _progress: None, @@ -239,17 +239,17 @@ impl<'repo> Drop for PackBuilder<'repo> { impl Binding for PackBuilderStage { type Raw = raw::git_packbuilder_stage_t; - unsafe fn from_raw(raw: raw::git_packbuilder_stage_t) -> PackBuilderStage { + unsafe fn from_raw(raw: raw::git_packbuilder_stage_t) -> Self { match raw { - raw::GIT_PACKBUILDER_ADDING_OBJECTS => PackBuilderStage::AddingObjects, - raw::GIT_PACKBUILDER_DELTAFICATION => PackBuilderStage::Deltafication, + raw::GIT_PACKBUILDER_ADDING_OBJECTS => Self::AddingObjects, + raw::GIT_PACKBUILDER_DELTAFICATION => Self::Deltafication, _ => panic!("Unknown git diff binary kind"), } } fn raw(&self) -> raw::git_packbuilder_stage_t { match *self { - PackBuilderStage::AddingObjects => raw::GIT_PACKBUILDER_ADDING_OBJECTS, - PackBuilderStage::Deltafication => raw::GIT_PACKBUILDER_DELTAFICATION, + Self::AddingObjects => raw::GIT_PACKBUILDER_ADDING_OBJECTS, + Self::Deltafication => raw::GIT_PACKBUILDER_DELTAFICATION, } } } diff --git a/src/pathspec.rs b/src/pathspec.rs index 16850dc210..8895b52bde 100644 --- a/src/pathspec.rs +++ b/src/pathspec.rs @@ -40,7 +40,7 @@ pub struct PathspecFailedEntries<'list> { impl Pathspec { /// Creates a new pathspec from a list of specs to match against. - pub fn new(specs: I) -> Result + pub fn new(specs: I) -> Result where T: IntoCString, I: IntoIterator, @@ -167,8 +167,8 @@ impl Pathspec { impl Binding for Pathspec { type Raw = *mut raw::git_pathspec; - unsafe fn from_raw(raw: *mut raw::git_pathspec) -> Pathspec { - Pathspec { raw } + unsafe fn from_raw(raw: *mut raw::git_pathspec) -> Self { + Self { raw } } fn raw(&self) -> *mut raw::git_pathspec { self.raw @@ -266,7 +266,7 @@ impl<'ps> PathspecMatchList<'ps> { impl<'ps> Binding for PathspecMatchList<'ps> { type Raw = *mut raw::git_pathspec_match_list; - unsafe fn from_raw(raw: *mut raw::git_pathspec_match_list) -> PathspecMatchList<'ps> { + unsafe fn from_raw(raw: *mut raw::git_pathspec_match_list) -> Self { PathspecMatchList { raw, _marker: marker::PhantomData, diff --git a/src/proxy_options.rs b/src/proxy_options.rs index b19ba3a527..545c65678d 100644 --- a/src/proxy_options.rs +++ b/src/proxy_options.rs @@ -15,7 +15,7 @@ pub struct ProxyOptions<'a> { impl<'a> ProxyOptions<'a> { /// Creates a new set of proxy options ready to be configured. - pub fn new() -> ProxyOptions<'a> { + pub fn new() -> Self { Default::default() } @@ -39,7 +39,7 @@ impl<'a> ProxyOptions<'a> { impl<'a> Binding for ProxyOptions<'a> { type Raw = raw::git_proxy_options; - unsafe fn from_raw(_raw: raw::git_proxy_options) -> ProxyOptions<'a> { + unsafe fn from_raw(_raw: raw::git_proxy_options) -> Self { panic!("can't create proxy from raw options") } diff --git a/src/push_update.rs b/src/push_update.rs index 97bebb1921..574312c145 100644 --- a/src/push_update.rs +++ b/src/push_update.rs @@ -11,7 +11,7 @@ pub struct PushUpdate<'a> { impl<'a> Binding for PushUpdate<'a> { type Raw = *const raw::git_push_update; - unsafe fn from_raw(raw: *const raw::git_push_update) -> PushUpdate<'a> { + unsafe fn from_raw(raw: *const raw::git_push_update) -> Self { PushUpdate { raw, _marker: marker::PhantomData, diff --git a/src/rebase.rs b/src/rebase.rs index 2bf8fe3e8a..1dba4a67c6 100644 --- a/src/rebase.rs +++ b/src/rebase.rs @@ -23,7 +23,7 @@ impl<'cb> Default for RebaseOptions<'cb> { impl<'cb> RebaseOptions<'cb> { /// Creates a new default set of rebase options. - pub fn new() -> RebaseOptions<'cb> { + pub fn new() -> Self { let mut opts = RebaseOptions { raw: unsafe { mem::zeroed() }, rewrite_notes_ref: None, @@ -39,7 +39,7 @@ impl<'cb> RebaseOptions<'cb> { /// provide in an application-specific manner. This has no effect upon /// libgit2 directly, but is provided for interoperability between Git /// tools. - pub fn quiet(&mut self, quiet: bool) -> &mut RebaseOptions<'cb> { + pub fn quiet(&mut self, quiet: bool) -> &mut Self { self.raw.quiet = quiet as i32; self } @@ -49,7 +49,7 @@ impl<'cb> RebaseOptions<'cb> { /// commit the rebased changes, but will not rewind HEAD or update the /// repository to be in a rebasing state. This will not interfere with /// the working directory (if there is one). - pub fn inmemory(&mut self, inmemory: bool) -> &mut RebaseOptions<'cb> { + pub fn inmemory(&mut self, inmemory: bool) -> &mut Self { self.raw.inmemory = inmemory as i32; self } @@ -60,13 +60,13 @@ impl<'cb> RebaseOptions<'cb> { /// is examined, unless the configuration option `notes.rewrite.rebase` /// is set to false. If `notes.rewriteRef` is also NULL, notes will /// not be rewritten. - pub fn rewrite_notes_ref(&mut self, rewrite_notes_ref: &str) -> &mut RebaseOptions<'cb> { + pub fn rewrite_notes_ref(&mut self, rewrite_notes_ref: &str) -> &mut Self { self.rewrite_notes_ref = Some(CString::new(rewrite_notes_ref).unwrap()); self } /// Options to control how trees are merged during `next()`. - pub fn merge_options(&mut self, opts: MergeOptions) -> &mut RebaseOptions<'cb> { + pub fn merge_options(&mut self, opts: MergeOptions) -> &mut Self { self.merge_options = Some(opts); self } @@ -76,7 +76,7 @@ impl<'cb> RebaseOptions<'cb> { /// `GIT_CHECKOUT_SAFE` is defaulted in `init` and `next`, and a minimum /// strategy of `GIT_CHECKOUT_FORCE` is defaulted in `abort` to match git /// semantics. - pub fn checkout_options(&mut self, opts: CheckoutBuilder<'cb>) -> &mut RebaseOptions<'cb> { + pub fn checkout_options(&mut self, opts: CheckoutBuilder<'cb>) -> &mut Self { self.checkout_options = Some(opts); self } @@ -228,7 +228,7 @@ impl<'rebase> Iterator for Rebase<'rebase> { impl<'repo> Binding for Rebase<'repo> { type Raw = *mut raw::git_rebase; - unsafe fn from_raw(raw: *mut raw::git_rebase) -> Rebase<'repo> { + unsafe fn from_raw(raw: *mut raw::git_rebase) -> Self { Rebase { raw, _marker: marker::PhantomData, @@ -278,14 +278,14 @@ pub enum RebaseOperationType { impl RebaseOperationType { /// Convert from the int into an enum. Returns None if invalid. - pub fn from_raw(raw: raw::git_rebase_operation_t) -> Option { + pub fn from_raw(raw: raw::git_rebase_operation_t) -> Option { match raw { - raw::GIT_REBASE_OPERATION_PICK => Some(RebaseOperationType::Pick), - raw::GIT_REBASE_OPERATION_REWORD => Some(RebaseOperationType::Reword), - raw::GIT_REBASE_OPERATION_EDIT => Some(RebaseOperationType::Edit), - raw::GIT_REBASE_OPERATION_SQUASH => Some(RebaseOperationType::Squash), - raw::GIT_REBASE_OPERATION_FIXUP => Some(RebaseOperationType::Fixup), - raw::GIT_REBASE_OPERATION_EXEC => Some(RebaseOperationType::Exec), + raw::GIT_REBASE_OPERATION_PICK => Some(Self::Pick), + raw::GIT_REBASE_OPERATION_REWORD => Some(Self::Reword), + raw::GIT_REBASE_OPERATION_EDIT => Some(Self::Edit), + raw::GIT_REBASE_OPERATION_SQUASH => Some(Self::Squash), + raw::GIT_REBASE_OPERATION_FIXUP => Some(Self::Fixup), + raw::GIT_REBASE_OPERATION_EXEC => Some(Self::Exec), _ => None, } } @@ -322,7 +322,7 @@ impl<'rebase> RebaseOperation<'rebase> { impl<'rebase> Binding for RebaseOperation<'rebase> { type Raw = *const raw::git_rebase_operation; - unsafe fn from_raw(raw: *const raw::git_rebase_operation) -> RebaseOperation<'rebase> { + unsafe fn from_raw(raw: *const raw::git_rebase_operation) -> Self { RebaseOperation { raw, _marker: marker::PhantomData, diff --git a/src/reference.rs b/src/reference.rs index 0af845d7c5..857193a7e0 100644 --- a/src/reference.rs +++ b/src/reference.rs @@ -279,7 +279,7 @@ impl<'repo> Reference<'repo> { /// /// If a direct reference is passed as an argument, a copy of that /// reference is returned. - pub fn resolve(&self) -> Result, Error> { + pub fn resolve(&self) -> Result { let mut raw = ptr::null_mut(); unsafe { try_call!(raw::git_reference_resolve(&mut raw, &*self.raw)); @@ -339,12 +339,7 @@ impl<'repo> Reference<'repo> { /// /// If the force flag is not enabled, and there's already a reference with /// the given name, the renaming will fail. - pub fn rename( - &mut self, - new_name: &str, - force: bool, - msg: &str, - ) -> Result, Error> { + pub fn rename(&mut self, new_name: &str, force: bool, msg: &str) -> Result { let mut raw = ptr::null_mut(); let new_name = CString::new(new_name)?; let msg = CString::new(msg)?; @@ -362,7 +357,7 @@ impl<'repo> Reference<'repo> { /// /// The new reference will be written to disk, overwriting the given /// reference. - pub fn set_target(&mut self, id: Oid, reflog_msg: &str) -> Result, Error> { + pub fn set_target(&mut self, id: Oid, reflog_msg: &str) -> Result { let mut raw = ptr::null_mut(); let msg = CString::new(reflog_msg)?; unsafe { @@ -389,11 +384,7 @@ impl<'repo> Reference<'repo> { /// The message for the reflog will be ignored if the reference does not /// belong in the standard set (HEAD, branches and remote-tracking /// branches) and it does not have a reflog. - pub fn symbolic_set_target( - &mut self, - target: &str, - reflog_msg: &str, - ) -> Result, Error> { + pub fn symbolic_set_target(&mut self, target: &str, reflog_msg: &str) -> Result { let mut raw = ptr::null_mut(); let target = CString::new(target)?; let msg = CString::new(reflog_msg)?; @@ -407,19 +398,19 @@ impl<'repo> Reference<'repo> { } impl<'repo> PartialOrd for Reference<'repo> { - fn partial_cmp(&self, other: &Reference<'repo>) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } impl<'repo> Ord for Reference<'repo> { - fn cmp(&self, other: &Reference<'repo>) -> Ordering { + fn cmp(&self, other: &Self) -> Ordering { c_cmp_to_ordering(unsafe { raw::git_reference_cmp(&*self.raw, &*other.raw) }) } } impl<'repo> PartialEq for Reference<'repo> { - fn eq(&self, other: &Reference<'repo>) -> bool { + fn eq(&self, other: &Self) -> bool { self.cmp(other) == Ordering::Equal } } @@ -428,7 +419,7 @@ impl<'repo> Eq for Reference<'repo> {} impl<'repo> Binding for Reference<'repo> { type Raw = *mut raw::git_reference; - unsafe fn from_raw(raw: *mut raw::git_reference) -> Reference<'repo> { + unsafe fn from_raw(raw: *mut raw::git_reference) -> Self { Reference { raw, _marker: marker::PhantomData, @@ -460,7 +451,7 @@ impl<'repo> References<'repo> { impl<'repo> Binding for References<'repo> { type Raw = *mut raw::git_reference_iterator; - unsafe fn from_raw(raw: *mut raw::git_reference_iterator) -> References<'repo> { + unsafe fn from_raw(raw: *mut raw::git_reference_iterator) -> Self { References { raw, _marker: marker::PhantomData, diff --git a/src/reflog.rs b/src/reflog.rs index bbd2140ab2..7d8810a573 100644 --- a/src/reflog.rs +++ b/src/reflog.rs @@ -103,8 +103,8 @@ impl Reflog { impl Binding for Reflog { type Raw = *mut raw::git_reflog; - unsafe fn from_raw(raw: *mut raw::git_reflog) -> Reflog { - Reflog { raw } + unsafe fn from_raw(raw: *mut raw::git_reflog) -> Self { + Self { raw } } fn raw(&self) -> *mut raw::git_reflog { self.raw @@ -150,7 +150,7 @@ impl<'reflog> ReflogEntry<'reflog> { impl<'reflog> Binding for ReflogEntry<'reflog> { type Raw = *const raw::git_reflog_entry; - unsafe fn from_raw(raw: *const raw::git_reflog_entry) -> ReflogEntry<'reflog> { + unsafe fn from_raw(raw: *const raw::git_reflog_entry) -> Self { ReflogEntry { raw, _marker: marker::PhantomData, diff --git a/src/refspec.rs b/src/refspec.rs index 3f62e991c7..40f54c466d 100644 --- a/src/refspec.rs +++ b/src/refspec.rs @@ -110,7 +110,7 @@ impl<'remote> Refspec<'remote> { impl<'remote> Binding for Refspec<'remote> { type Raw = *const raw::git_refspec; - unsafe fn from_raw(raw: *const raw::git_refspec) -> Refspec<'remote> { + unsafe fn from_raw(raw: *const raw::git_refspec) -> Self { Refspec { raw, _marker: marker::PhantomData, diff --git a/src/remote.rs b/src/remote.rs index 0c13a53fcf..ba4a5e1a1d 100644 --- a/src/remote.rs +++ b/src/remote.rs @@ -113,7 +113,7 @@ impl<'repo> Remote<'repo> { /// when you have a URL instead of a remote's name. /// Contrasted with an anonymous remote, a detached remote will not /// consider any repo configuration values. - pub fn create_detached>>(url: S) -> Result, Error> { + pub fn create_detached>>(url: S) -> Result { crate::init(); let mut ret = ptr::null_mut(); let url = CString::new(url)?; @@ -421,7 +421,7 @@ impl<'repo> Remote<'repo> { } impl<'repo> Clone for Remote<'repo> { - fn clone(&self) -> Remote<'repo> { + fn clone(&self) -> Self { let mut ret = ptr::null_mut(); let rc = unsafe { call!(raw::git_remote_dup(&mut ret, self.raw)) }; assert_eq!(rc, 0); @@ -435,7 +435,7 @@ impl<'repo> Clone for Remote<'repo> { impl<'repo> Binding for Remote<'repo> { type Raw = *mut raw::git_remote; - unsafe fn from_raw(raw: *mut raw::git_remote) -> Remote<'repo> { + unsafe fn from_raw(raw: *mut raw::git_remote) -> Self { Remote { raw, _marker: marker::PhantomData, @@ -504,7 +504,7 @@ impl<'cb> Default for FetchOptions<'cb> { impl<'cb> FetchOptions<'cb> { /// Creates a new blank set of fetch options - pub fn new() -> FetchOptions<'cb> { + pub fn new() -> Self { FetchOptions { callbacks: None, proxy: None, @@ -598,7 +598,7 @@ impl<'cb> FetchOptions<'cb> { impl<'cb> Binding for FetchOptions<'cb> { type Raw = raw::git_fetch_options; - unsafe fn from_raw(_raw: raw::git_fetch_options) -> FetchOptions<'cb> { + unsafe fn from_raw(_raw: raw::git_fetch_options) -> Self { panic!("unimplemented"); } fn raw(&self) -> raw::git_fetch_options { @@ -638,7 +638,7 @@ impl<'cb> Default for PushOptions<'cb> { impl<'cb> PushOptions<'cb> { /// Creates a new blank set of push options - pub fn new() -> PushOptions<'cb> { + pub fn new() -> Self { PushOptions { callbacks: None, proxy: None, @@ -712,7 +712,7 @@ impl<'cb> PushOptions<'cb> { impl<'cb> Binding for PushOptions<'cb> { type Raw = raw::git_push_options; - unsafe fn from_raw(_raw: raw::git_push_options) -> PushOptions<'cb> { + unsafe fn from_raw(_raw: raw::git_push_options) -> Self { panic!("unimplemented"); } fn raw(&self) -> raw::git_push_options { @@ -778,16 +778,16 @@ impl<'repo, 'connection, 'cb> Drop for RemoteConnection<'repo, 'connection, 'cb> impl Default for RemoteRedirect { fn default() -> Self { - RemoteRedirect::Initial + Self::Initial } } impl RemoteRedirect { fn raw(&self) -> raw::git_remote_redirect_t { match self { - RemoteRedirect::None => raw::GIT_REMOTE_REDIRECT_NONE, - RemoteRedirect::Initial => raw::GIT_REMOTE_REDIRECT_INITIAL, - RemoteRedirect::All => raw::GIT_REMOTE_REDIRECT_ALL, + Self::None => raw::GIT_REMOTE_REDIRECT_NONE, + Self::Initial => raw::GIT_REMOTE_REDIRECT_INITIAL, + Self::All => raw::GIT_REMOTE_REDIRECT_ALL, } } } diff --git a/src/remote_callbacks.rs b/src/remote_callbacks.rs index 2df2e7b015..e6915608fb 100644 --- a/src/remote_callbacks.rs +++ b/src/remote_callbacks.rs @@ -108,7 +108,7 @@ impl<'a> Default for RemoteCallbacks<'a> { impl<'a> RemoteCallbacks<'a> { /// Creates a new set of empty callbacks - pub fn new() -> RemoteCallbacks<'a> { + pub fn new() -> Self { RemoteCallbacks { credentials: None, progress: None, @@ -143,7 +143,7 @@ impl<'a> RemoteCallbacks<'a> { /// ) /// }); /// ``` - pub fn credentials(&mut self, cb: F) -> &mut RemoteCallbacks<'a> + pub fn credentials(&mut self, cb: F) -> &mut Self where F: FnMut(&str, Option<&str>, CredentialType) -> Result + 'a, { @@ -152,7 +152,7 @@ impl<'a> RemoteCallbacks<'a> { } /// The callback through which progress is monitored. - pub fn transfer_progress(&mut self, cb: F) -> &mut RemoteCallbacks<'a> + pub fn transfer_progress(&mut self, cb: F) -> &mut Self where F: FnMut(Progress<'_>) -> bool + 'a, { @@ -164,7 +164,7 @@ impl<'a> RemoteCallbacks<'a> { /// /// Text sent over the progress side-band will be passed to this function /// (this is the 'counting objects' output). - pub fn sideband_progress(&mut self, cb: F) -> &mut RemoteCallbacks<'a> + pub fn sideband_progress(&mut self, cb: F) -> &mut Self where F: FnMut(&[u8]) -> bool + 'a, { @@ -174,7 +174,7 @@ impl<'a> RemoteCallbacks<'a> { /// Each time a reference is updated locally, the callback will be called /// with information about it. - pub fn update_tips(&mut self, cb: F) -> &mut RemoteCallbacks<'a> + pub fn update_tips(&mut self, cb: F) -> &mut Self where F: FnMut(&str, Oid, Oid) -> bool + 'a, { @@ -185,7 +185,7 @@ impl<'a> RemoteCallbacks<'a> { /// If certificate verification fails, then this callback will be invoked to /// let the caller make the final decision of whether to allow the /// connection to proceed. - pub fn certificate_check(&mut self, cb: F) -> &mut RemoteCallbacks<'a> + pub fn certificate_check(&mut self, cb: F) -> &mut Self where F: FnMut(&Cert<'_>, &str) -> Result + 'a, { @@ -198,7 +198,7 @@ impl<'a> RemoteCallbacks<'a> { /// The first argument to the callback is the name of the reference and the /// second is a status message sent by the server. If the status is `Some` /// then the push was rejected. - pub fn push_update_reference(&mut self, cb: F) -> &mut RemoteCallbacks<'a> + pub fn push_update_reference(&mut self, cb: F) -> &mut Self where F: FnMut(&str, Option<&str>) -> Result<(), Error> + 'a, { @@ -212,7 +212,7 @@ impl<'a> RemoteCallbacks<'a> { /// * current /// * total /// * bytes - pub fn push_transfer_progress(&mut self, cb: F) -> &mut RemoteCallbacks<'a> + pub fn push_transfer_progress(&mut self, cb: F) -> &mut Self where F: FnMut(usize, usize, usize) + 'a, { @@ -229,7 +229,7 @@ impl<'a> RemoteCallbacks<'a> { /// * stage /// * current /// * total - pub fn pack_progress(&mut self, cb: F) -> &mut RemoteCallbacks<'a> + pub fn pack_progress(&mut self, cb: F) -> &mut Self where F: FnMut(PackBuilderStage, usize, usize) + 'a, { @@ -243,7 +243,7 @@ impl<'a> RemoteCallbacks<'a> { /// will be sent as commands to the destination. /// /// The push is cancelled if the callback returns an error. - pub fn push_negotiation(&mut self, cb: F) -> &mut RemoteCallbacks<'a> + pub fn push_negotiation(&mut self, cb: F) -> &mut Self where F: FnMut(&[PushUpdate<'_>]) -> Result<(), Error> + 'a, { @@ -254,7 +254,7 @@ impl<'a> RemoteCallbacks<'a> { impl<'a> Binding for RemoteCallbacks<'a> { type Raw = raw::git_remote_callbacks; - unsafe fn from_raw(_raw: raw::git_remote_callbacks) -> RemoteCallbacks<'a> { + unsafe fn from_raw(_raw: raw::git_remote_callbacks) -> Self { panic!("unimplemented"); } diff --git a/src/repo.rs b/src/repo.rs index 061078d670..3ee0722e8d 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -129,7 +129,7 @@ impl Repository { /// Attempt to open an already-existing repository at `path`. /// /// The path can point to either a normal or bare repository. - pub fn open>(path: P) -> Result { + pub fn open>(path: P) -> Result { crate::init(); // Normal file path OK (does not need Windows conversion). let path = path.as_ref().into_c_string()?; @@ -143,7 +143,7 @@ impl Repository { /// Attempt to open an already-existing bare repository at `path`. /// /// The path can point to only a bare repository. - pub fn open_bare>(path: P) -> Result { + pub fn open_bare>(path: P) -> Result { crate::init(); // Normal file path OK (does not need Windows conversion). let path = path.as_ref().into_c_string()?; @@ -159,7 +159,7 @@ impl Repository { /// [FROM_ENV](RepositoryOpenFlags::FROM_ENV) flag, but additionally respects `$GIT_DIR`. /// With `$GIT_DIR` unset, this will search for a repository starting in /// the current directory. - pub fn open_from_env() -> Result { + pub fn open_from_env() -> Result { crate::init(); let mut ret = ptr::null_mut(); let flags = raw::GIT_REPOSITORY_OPEN_FROM_ENV; @@ -206,7 +206,7 @@ impl Repository { path: P, flags: RepositoryOpenFlags, ceiling_dirs: I, - ) -> Result + ) -> Result where P: AsRef, O: AsRef, @@ -230,7 +230,7 @@ impl Repository { } /// Attempt to open an already-existing repository from a worktree. - pub fn open_from_worktree(worktree: &Worktree) -> Result { + pub fn open_from_worktree(worktree: &Worktree) -> Result { let mut ret = ptr::null_mut(); unsafe { try_call!(raw::git_repository_open_from_worktree( @@ -245,7 +245,7 @@ impl Repository { /// /// This starts at `path` and looks up the filesystem hierarchy /// until it finds a repository. - pub fn discover>(path: P) -> Result { + pub fn discover>(path: P) -> Result { // TODO: this diverges significantly from the libgit2 API crate::init(); let buf = Buf::new(); @@ -259,7 +259,7 @@ impl Repository { ptr::null() )); } - Repository::open(util::bytes2path(&*buf)) + Self::open(util::bytes2path(&*buf)) } /// Attempt to find the path to a git repo for a given path @@ -294,24 +294,21 @@ impl Repository { /// This by default will create any necessary directories to create the /// repository, and it will read any user-specified templates when creating /// the repository. This behavior can be configured through `init_opts`. - pub fn init>(path: P) -> Result { - Repository::init_opts(path, &RepositoryInitOptions::new()) + pub fn init>(path: P) -> Result { + Self::init_opts(path, &RepositoryInitOptions::new()) } /// Creates a new `--bare` repository in the specified folder. /// /// The folder must exist prior to invoking this function. - pub fn init_bare>(path: P) -> Result { - Repository::init_opts(path, RepositoryInitOptions::new().bare(true)) + pub fn init_bare>(path: P) -> Result { + Self::init_opts(path, RepositoryInitOptions::new().bare(true)) } /// Creates a new repository in the specified folder with the given options. /// /// See `RepositoryInitOptions` struct for more information. - pub fn init_opts>( - path: P, - opts: &RepositoryInitOptions, - ) -> Result { + pub fn init_opts>(path: P, opts: &RepositoryInitOptions) -> Result { crate::init(); // Normal file path OK (does not need Windows conversion). let path = path.as_ref().into_c_string()?; @@ -327,7 +324,7 @@ impl Repository { /// /// See the `RepoBuilder` struct for more information. This function will /// delegate to a fresh `RepoBuilder` - pub fn clone>(url: &str, into: P) -> Result { + pub fn clone>(url: &str, into: P) -> Result { crate::init(); RepoBuilder::new().clone(url, into.as_ref()) } @@ -336,14 +333,14 @@ impl Repository { /// recursively. /// /// This is similar to `git clone --recursive`. - pub fn clone_recurse>(url: &str, into: P) -> Result { - let repo = Repository::clone(url, into)?; + pub fn clone_recurse>(url: &str, into: P) -> Result { + let repo = Self::clone(url, into)?; repo.update_submodules()?; Ok(repo) } /// Attempt to wrap an object database as a repository. - pub fn from_odb(odb: Odb<'_>) -> Result { + pub fn from_odb(odb: Odb<'_>) -> Result { crate::init(); let mut ret = ptr::null_mut(); unsafe { @@ -3371,8 +3368,8 @@ impl Repository { impl Binding for Repository { type Raw = *mut raw::git_repository; - unsafe fn from_raw(ptr: *mut raw::git_repository) -> Repository { - Repository { raw: ptr } + unsafe fn from_raw(ptr: *mut raw::git_repository) -> Self { + Self { raw: ptr } } fn raw(&self) -> *mut raw::git_repository { self.raw @@ -3390,8 +3387,8 @@ impl RepositoryInitOptions { /// /// By default this will set flags for creating all necessary directories /// and initializing a directory from the user-configured templates path. - pub fn new() -> RepositoryInitOptions { - RepositoryInitOptions { + pub fn new() -> Self { + Self { flags: raw::GIT_REPOSITORY_INIT_MKDIR as u32 | raw::GIT_REPOSITORY_INIT_MKPATH as u32 | raw::GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE as u32, @@ -3407,7 +3404,7 @@ impl RepositoryInitOptions { /// Create a bare repository with no working directory. /// /// Defaults to false. - pub fn bare(&mut self, bare: bool) -> &mut RepositoryInitOptions { + pub fn bare(&mut self, bare: bool) -> &mut Self { self.flag(raw::GIT_REPOSITORY_INIT_BARE, bare) } @@ -3415,7 +3412,7 @@ impl RepositoryInitOptions { /// repository. /// /// Defaults to false. - pub fn no_reinit(&mut self, enabled: bool) -> &mut RepositoryInitOptions { + pub fn no_reinit(&mut self, enabled: bool) -> &mut Self { self.flag(raw::GIT_REPOSITORY_INIT_NO_REINIT, enabled) } @@ -3424,7 +3421,7 @@ impl RepositoryInitOptions { /// behavior. /// /// Defaults to false. - pub fn no_dotgit_dir(&mut self, enabled: bool) -> &mut RepositoryInitOptions { + pub fn no_dotgit_dir(&mut self, enabled: bool) -> &mut Self { self.flag(raw::GIT_REPOSITORY_INIT_NO_DOTGIT_DIR, enabled) } @@ -3432,7 +3429,7 @@ impl RepositoryInitOptions { /// will always be created regardless of this flag. /// /// Defaults to true. - pub fn mkdir(&mut self, enabled: bool) -> &mut RepositoryInitOptions { + pub fn mkdir(&mut self, enabled: bool) -> &mut Self { self.flag(raw::GIT_REPOSITORY_INIT_MKDIR, enabled) } @@ -3440,12 +3437,12 @@ impl RepositoryInitOptions { /// necessary. /// /// Defaults to true. - pub fn mkpath(&mut self, enabled: bool) -> &mut RepositoryInitOptions { + pub fn mkpath(&mut self, enabled: bool) -> &mut Self { self.flag(raw::GIT_REPOSITORY_INIT_MKPATH, enabled) } /// Set to one of the `RepositoryInit` constants, or a custom value. - pub fn mode(&mut self, mode: RepositoryInitMode) -> &mut RepositoryInitOptions { + pub fn mode(&mut self, mode: RepositoryInitMode) -> &mut Self { self.mode = mode.bits(); self } @@ -3457,15 +3454,11 @@ impl RepositoryInitOptions { /// `/usr/share/git-core-templates` will be used (if it exists). /// /// Defaults to true. - pub fn external_template(&mut self, enabled: bool) -> &mut RepositoryInitOptions { + pub fn external_template(&mut self, enabled: bool) -> &mut Self { self.flag(raw::GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE, enabled) } - fn flag( - &mut self, - flag: raw::git_repository_init_flag_t, - on: bool, - ) -> &mut RepositoryInitOptions { + fn flag(&mut self, flag: raw::git_repository_init_flag_t, on: bool) -> &mut Self { if on { self.flags |= flag as u32; } else { @@ -3479,7 +3472,7 @@ impl RepositoryInitOptions { /// If this is a relative path it will be evaluated relative to the repo /// path. If this is not the "natural" working directory, a .git gitlink /// file will be created here linking to the repo path. - pub fn workdir_path(&mut self, path: &Path) -> &mut RepositoryInitOptions { + pub fn workdir_path(&mut self, path: &Path) -> &mut Self { // Normal file path OK (does not need Windows conversion). self.workdir_path = Some(path.into_c_string().unwrap()); self @@ -3487,7 +3480,7 @@ impl RepositoryInitOptions { /// If set, this will be used to initialize the "description" file in the /// repository instead of using the template content. - pub fn description(&mut self, desc: &str) -> &mut RepositoryInitOptions { + pub fn description(&mut self, desc: &str) -> &mut Self { self.description = Some(CString::new(desc).unwrap()); self } @@ -3497,7 +3490,7 @@ impl RepositoryInitOptions { /// /// If this is not configured, then the default locations will be searched /// instead. - pub fn template_path(&mut self, path: &Path) -> &mut RepositoryInitOptions { + pub fn template_path(&mut self, path: &Path) -> &mut Self { // Normal file path OK (does not need Windows conversion). self.template_path = Some(path.into_c_string().unwrap()); self @@ -3508,14 +3501,14 @@ impl RepositoryInitOptions { /// If not configured, this will be taken from your git configuration. /// If this begins with `refs/` it will be used verbatim; /// otherwise `refs/heads/` will be prefixed - pub fn initial_head(&mut self, head: &str) -> &mut RepositoryInitOptions { + pub fn initial_head(&mut self, head: &str) -> &mut Self { self.initial_head = Some(CString::new(head).unwrap()); self } /// If set, then after the rest of the repository initialization is /// completed an `origin` remote will be added pointing to this URL. - pub fn origin_url(&mut self, url: &str) -> &mut RepositoryInitOptions { + pub fn origin_url(&mut self, url: &str) -> &mut Self { self.origin_url = Some(CString::new(url).unwrap()); self } diff --git a/src/revert.rs b/src/revert.rs index 55d702600e..05c1d44cdb 100644 --- a/src/revert.rs +++ b/src/revert.rs @@ -14,7 +14,7 @@ pub struct RevertOptions<'cb> { impl<'cb> RevertOptions<'cb> { /// Creates a default set of revert options - pub fn new() -> RevertOptions<'cb> { + pub fn new() -> Self { RevertOptions { mainline: 0, checkout_builder: None, diff --git a/src/revspec.rs b/src/revspec.rs index d2e08670af..4a5e441038 100644 --- a/src/revspec.rs +++ b/src/revspec.rs @@ -13,7 +13,7 @@ impl<'repo> Revspec<'repo> { from: Option>, to: Option>, mode: RevparseMode, - ) -> Revspec<'repo> { + ) -> Self { Revspec { from, to, mode } } diff --git a/src/revwalk.rs b/src/revwalk.rs index 7837f00d63..a8648a2e17 100644 --- a/src/revwalk.rs +++ b/src/revwalk.rs @@ -218,7 +218,7 @@ impl<'repo> Revwalk<'repo> { impl<'repo> Binding for Revwalk<'repo> { type Raw = *mut raw::git_revwalk; - unsafe fn from_raw(raw: *mut raw::git_revwalk) -> Revwalk<'repo> { + unsafe fn from_raw(raw: *mut raw::git_revwalk) -> Self { Revwalk { raw, _marker: marker::PhantomData, diff --git a/src/signature.rs b/src/signature.rs index 7c9ffb3933..162bba8b0f 100644 --- a/src/signature.rs +++ b/src/signature.rs @@ -102,7 +102,7 @@ impl<'a> Signature<'a> { impl<'a> Binding for Signature<'a> { type Raw = *mut raw::git_signature; - unsafe fn from_raw(raw: *mut raw::git_signature) -> Signature<'a> { + unsafe fn from_raw(raw: *mut raw::git_signature) -> Self { Signature { raw, _marker: marker::PhantomData, @@ -128,7 +128,7 @@ pub unsafe fn from_raw_const<'b, T>(_lt: &'b T, raw: *const raw::git_signature) } impl Clone for Signature<'static> { - fn clone(&self) -> Signature<'static> { + fn clone(&self) -> Self { // TODO: can this be defined for 'a and just do a plain old copy if the // lifetime isn't static? let mut raw = ptr::null_mut(); diff --git a/src/stash.rs b/src/stash.rs index ea898e46ba..1e09e5671b 100644 --- a/src/stash.rs +++ b/src/stash.rs @@ -94,7 +94,7 @@ impl<'cb> Default for StashApplyOptions<'cb> { impl<'cb> StashApplyOptions<'cb> { /// Creates a default set of merge options. - pub fn new() -> StashApplyOptions<'cb> { + pub fn new() -> Self { let mut opts = StashApplyOptions { progress: None, checkout_options: None, @@ -108,13 +108,13 @@ impl<'cb> StashApplyOptions<'cb> { } /// Set stash application flag to GIT_STASH_APPLY_REINSTATE_INDEX - pub fn reinstantiate_index(&mut self) -> &mut StashApplyOptions<'cb> { + pub fn reinstantiate_index(&mut self) -> &mut Self { self.raw_opts.flags = raw::GIT_STASH_APPLY_REINSTATE_INDEX as u32; self } /// Options to use when writing files to the working directory - pub fn checkout_options(&mut self, opts: CheckoutBuilder<'cb>) -> &mut StashApplyOptions<'cb> { + pub fn checkout_options(&mut self, opts: CheckoutBuilder<'cb>) -> &mut Self { self.checkout_options = Some(opts); self } @@ -123,7 +123,7 @@ impl<'cb> StashApplyOptions<'cb> { /// /// Return `true` to continue processing, or `false` to /// abort the stash application. - pub fn progress_cb(&mut self, callback: C) -> &mut StashApplyOptions<'cb> + pub fn progress_cb(&mut self, callback: C) -> &mut Self where C: FnMut(StashApplyProgress) -> bool + 'cb, { diff --git a/src/status.rs b/src/status.rs index a5a8cffd39..892f2289f2 100644 --- a/src/status.rs +++ b/src/status.rs @@ -67,12 +67,12 @@ impl Default for StatusOptions { impl StatusOptions { /// Creates a new blank set of status options. - pub fn new() -> StatusOptions { + pub fn new() -> Self { unsafe { let mut raw = mem::zeroed(); let r = raw::git_status_init_options(&mut raw, raw::GIT_STATUS_OPTIONS_VERSION); assert_eq!(r, 0); - StatusOptions { + Self { raw, pathspec: Vec::new(), ptrs: Vec::new(), @@ -84,7 +84,7 @@ impl StatusOptions { /// /// The default, if unspecified, is to show the index and the working /// directory. - pub fn show(&mut self, show: StatusShow) -> &mut StatusOptions { + pub fn show(&mut self, show: StatusShow) -> &mut Self { self.raw.show = match show { StatusShow::Index => raw::GIT_STATUS_SHOW_INDEX_ONLY, StatusShow::Workdir => raw::GIT_STATUS_SHOW_WORKDIR_ONLY, @@ -98,14 +98,14 @@ impl StatusOptions { /// If the `disable_pathspec_match` option is given, then this is a literal /// path to match. If this is not called, then there will be no patterns to /// match and the entire directory will be used. - pub fn pathspec(&mut self, pathspec: T) -> &mut StatusOptions { + pub fn pathspec(&mut self, pathspec: T) -> &mut Self { let s = util::cstring_to_repo_path(pathspec).unwrap(); self.ptrs.push(s.as_ptr()); self.pathspec.push(s); self } - fn flag(&mut self, flag: raw::git_status_opt_t, val: bool) -> &mut StatusOptions { + fn flag(&mut self, flag: raw::git_status_opt_t, val: bool) -> &mut Self { if val { self.raw.flags |= flag as c_uint; } else { @@ -118,7 +118,7 @@ impl StatusOptions { /// /// Untracked files will only be included if the workdir files are included /// in the status "show" option. - pub fn include_untracked(&mut self, include: bool) -> &mut StatusOptions { + pub fn include_untracked(&mut self, include: bool) -> &mut Self { self.flag(raw::GIT_STATUS_OPT_INCLUDE_UNTRACKED, include) } @@ -126,12 +126,12 @@ impl StatusOptions { /// /// The files will only be included if the workdir files are included /// in the status "show" option. - pub fn include_ignored(&mut self, include: bool) -> &mut StatusOptions { + pub fn include_ignored(&mut self, include: bool) -> &mut Self { self.flag(raw::GIT_STATUS_OPT_INCLUDE_IGNORED, include) } /// Flag to include unmodified files. - pub fn include_unmodified(&mut self, include: bool) -> &mut StatusOptions { + pub fn include_unmodified(&mut self, include: bool) -> &mut Self { self.flag(raw::GIT_STATUS_OPT_INCLUDE_UNMODIFIED, include) } @@ -139,7 +139,7 @@ impl StatusOptions { /// /// This only applies if there are no pending typechanges to the submodule /// (either from or to another type). - pub fn exclude_submodules(&mut self, exclude: bool) -> &mut StatusOptions { + pub fn exclude_submodules(&mut self, exclude: bool) -> &mut Self { self.flag(raw::GIT_STATUS_OPT_EXCLUDE_SUBMODULES, exclude) } @@ -147,52 +147,52 @@ impl StatusOptions { /// /// Normally if an entire directory is new then just the top-level directory /// is included (with a trailing slash on the entry name). - pub fn recurse_untracked_dirs(&mut self, include: bool) -> &mut StatusOptions { + pub fn recurse_untracked_dirs(&mut self, include: bool) -> &mut Self { self.flag(raw::GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS, include) } /// Indicates that the given paths should be treated as literals paths, note /// patterns. - pub fn disable_pathspec_match(&mut self, include: bool) -> &mut StatusOptions { + pub fn disable_pathspec_match(&mut self, include: bool) -> &mut Self { self.flag(raw::GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH, include) } /// Indicates that the contents of ignored directories should be included in /// the status. - pub fn recurse_ignored_dirs(&mut self, include: bool) -> &mut StatusOptions { + pub fn recurse_ignored_dirs(&mut self, include: bool) -> &mut Self { self.flag(raw::GIT_STATUS_OPT_RECURSE_IGNORED_DIRS, include) } /// Indicates that rename detection should be processed between the head. - pub fn renames_head_to_index(&mut self, include: bool) -> &mut StatusOptions { + pub fn renames_head_to_index(&mut self, include: bool) -> &mut Self { self.flag(raw::GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX, include) } /// Indicates that rename detection should be run between the index and the /// working directory. - pub fn renames_index_to_workdir(&mut self, include: bool) -> &mut StatusOptions { + pub fn renames_index_to_workdir(&mut self, include: bool) -> &mut Self { self.flag(raw::GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR, include) } /// Override the native case sensitivity for the file system and force the /// output to be in case sensitive order. - pub fn sort_case_sensitively(&mut self, include: bool) -> &mut StatusOptions { + pub fn sort_case_sensitively(&mut self, include: bool) -> &mut Self { self.flag(raw::GIT_STATUS_OPT_SORT_CASE_SENSITIVELY, include) } /// Override the native case sensitivity for the file system and force the /// output to be in case-insensitive order. - pub fn sort_case_insensitively(&mut self, include: bool) -> &mut StatusOptions { + pub fn sort_case_insensitively(&mut self, include: bool) -> &mut Self { self.flag(raw::GIT_STATUS_OPT_SORT_CASE_INSENSITIVELY, include) } /// Indicates that rename detection should include rewritten files. - pub fn renames_from_rewrites(&mut self, include: bool) -> &mut StatusOptions { + pub fn renames_from_rewrites(&mut self, include: bool) -> &mut Self { self.flag(raw::GIT_STATUS_OPT_RENAMES_FROM_REWRITES, include) } /// Bypasses the default status behavior of doing a "soft" index reload. - pub fn no_refresh(&mut self, include: bool) -> &mut StatusOptions { + pub fn no_refresh(&mut self, include: bool) -> &mut Self { self.flag(raw::GIT_STATUS_OPT_NO_REFRESH, include) } @@ -201,26 +201,26 @@ impl StatusOptions { /// /// This will result in less work being done on subsequent calls to fetching /// the status. - pub fn update_index(&mut self, include: bool) -> &mut StatusOptions { + pub fn update_index(&mut self, include: bool) -> &mut Self { self.flag(raw::GIT_STATUS_OPT_UPDATE_INDEX, include) } // erm... #[allow(missing_docs)] - pub fn include_unreadable(&mut self, include: bool) -> &mut StatusOptions { + pub fn include_unreadable(&mut self, include: bool) -> &mut Self { self.flag(raw::GIT_STATUS_OPT_INCLUDE_UNREADABLE, include) } // erm... #[allow(missing_docs)] - pub fn include_unreadable_as_untracked(&mut self, include: bool) -> &mut StatusOptions { + pub fn include_unreadable_as_untracked(&mut self, include: bool) -> &mut Self { self.flag(raw::GIT_STATUS_OPT_INCLUDE_UNREADABLE_AS_UNTRACKED, include) } /// Set threshold above which similar files will be considered renames. /// /// This is equivalent to the `-M` option. Defaults to 50. - pub fn rename_threshold(&mut self, threshold: u16) -> &mut StatusOptions { + pub fn rename_threshold(&mut self, threshold: u16) -> &mut Self { self.raw.rename_threshold = threshold; self } @@ -271,7 +271,7 @@ impl<'repo> Statuses<'repo> { impl<'repo> Binding for Statuses<'repo> { type Raw = *mut raw::git_status_list; - unsafe fn from_raw(raw: *mut raw::git_status_list) -> Statuses<'repo> { + unsafe fn from_raw(raw: *mut raw::git_status_list) -> Self { Statuses { raw, _marker: marker::PhantomData, @@ -356,7 +356,7 @@ impl<'statuses> StatusEntry<'statuses> { impl<'statuses> Binding for StatusEntry<'statuses> { type Raw = *const raw::git_status_entry; - unsafe fn from_raw(raw: *const raw::git_status_entry) -> StatusEntry<'statuses> { + unsafe fn from_raw(raw: *const raw::git_status_entry) -> Self { StatusEntry { raw, _marker: marker::PhantomData, diff --git a/src/string_array.rs b/src/string_array.rs index c77ccdab96..a4fcc23307 100644 --- a/src/string_array.rs +++ b/src/string_array.rs @@ -79,8 +79,8 @@ impl StringArray { impl Binding for StringArray { type Raw = raw::git_strarray; - unsafe fn from_raw(raw: raw::git_strarray) -> StringArray { - StringArray { raw } + unsafe fn from_raw(raw: raw::git_strarray) -> Self { + Self { raw } } fn raw(&self) -> raw::git_strarray { self.raw diff --git a/src/submodule.rs b/src/submodule.rs index 06a6359400..2dc3565c9a 100644 --- a/src/submodule.rs +++ b/src/submodule.rs @@ -250,7 +250,7 @@ impl<'repo> Submodule<'repo> { impl<'repo> Binding for Submodule<'repo> { type Raw = *mut raw::git_submodule; - unsafe fn from_raw(raw: *mut raw::git_submodule) -> Submodule<'repo> { + unsafe fn from_raw(raw: *mut raw::git_submodule) -> Self { Submodule { raw, _marker: marker::PhantomData, diff --git a/src/tag.rs b/src/tag.rs index 6986c7c160..b94131f907 100644 --- a/src/tag.rs +++ b/src/tag.rs @@ -130,7 +130,7 @@ impl<'repo> std::fmt::Debug for Tag<'repo> { impl<'repo> Binding for Tag<'repo> { type Raw = *mut raw::git_tag; - unsafe fn from_raw(raw: *mut raw::git_tag) -> Tag<'repo> { + unsafe fn from_raw(raw: *mut raw::git_tag) -> Self { Tag { raw, _marker: marker::PhantomData, diff --git a/src/time.rs b/src/time.rs index 46b5bd3f94..ed06c4a4c6 100644 --- a/src/time.rs +++ b/src/time.rs @@ -19,7 +19,7 @@ pub struct IndexTime { impl Time { /// Creates a new time structure from its components. - pub fn new(time: i64, offset: i32) -> Time { + pub fn new(time: i64, offset: i32) -> Self { unsafe { Binding::from_raw(raw::git_time { time: time as raw::git_time_t, @@ -47,21 +47,21 @@ impl Time { } impl PartialOrd for Time { - fn partial_cmp(&self, other: &Time) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } impl Ord for Time { - fn cmp(&self, other: &Time) -> Ordering { + fn cmp(&self, other: &Self) -> Ordering { (self.raw.time, self.raw.offset).cmp(&(other.raw.time, other.raw.offset)) } } impl Binding for Time { type Raw = raw::git_time; - unsafe fn from_raw(raw: raw::git_time) -> Time { - Time { raw } + unsafe fn from_raw(raw: raw::git_time) -> Self { + Self { raw } } fn raw(&self) -> raw::git_time { self.raw @@ -70,7 +70,7 @@ impl Binding for Time { impl IndexTime { /// Creates a new time structure from its components. - pub fn new(seconds: i32, nanoseconds: u32) -> IndexTime { + pub fn new(seconds: i32, nanoseconds: u32) -> Self { unsafe { Binding::from_raw(raw::git_index_time { seconds, @@ -91,8 +91,8 @@ impl IndexTime { impl Binding for IndexTime { type Raw = raw::git_index_time; - unsafe fn from_raw(raw: raw::git_index_time) -> IndexTime { - IndexTime { raw } + unsafe fn from_raw(raw: raw::git_index_time) -> Self { + Self { raw } } fn raw(&self) -> raw::git_index_time { self.raw @@ -100,13 +100,13 @@ impl Binding for IndexTime { } impl PartialOrd for IndexTime { - fn partial_cmp(&self, other: &IndexTime) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } impl Ord for IndexTime { - fn cmp(&self, other: &IndexTime) -> Ordering { + fn cmp(&self, other: &Self) -> Ordering { let me = (self.raw.seconds, self.raw.nanoseconds); let other = (other.raw.seconds, other.raw.nanoseconds); me.cmp(&other) diff --git a/src/transaction.rs b/src/transaction.rs index 4f661f1d48..1cd6cd3c8b 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -23,7 +23,7 @@ impl Drop for Transaction<'_> { impl<'repo> Binding for Transaction<'repo> { type Raw = *mut raw::git_transaction; - unsafe fn from_raw(ptr: *mut raw::git_transaction) -> Transaction<'repo> { + unsafe fn from_raw(ptr: *mut raw::git_transaction) -> Self { Transaction { raw: ptr, _marker: marker::PhantomData, diff --git a/src/transport.rs b/src/transport.rs index b1ca3f8b80..1280c6c237 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -132,7 +132,7 @@ impl Transport { /// /// The `rpc` argument is `true` if the protocol is stateless, false /// otherwise. For example `http://` is stateless but `git://` is not. - pub fn smart(remote: &Remote<'_>, rpc: bool, subtransport: S) -> Result + pub fn smart(remote: &Remote<'_>, rpc: bool, subtransport: S) -> Result where S: SmartSubtransport, { @@ -170,7 +170,7 @@ impl Transport { )); mem::forget(raw); // ownership transport to `ret` } - return Ok(Transport { + return Ok(Self { raw: ret, owned: true, }); diff --git a/src/tree.rs b/src/tree.rs index e683257436..4b9b900e52 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -233,7 +233,7 @@ extern "C" fn treewalk_cb>( impl<'repo> Binding for Tree<'repo> { type Raw = *mut raw::git_tree; - unsafe fn from_raw(raw: *mut raw::git_tree) -> Tree<'repo> { + unsafe fn from_raw(raw: *mut raw::git_tree) -> Self { Tree { raw, _marker: marker::PhantomData, @@ -342,7 +342,7 @@ impl<'tree> TreeEntry<'tree> { impl<'a> Binding for TreeEntry<'a> { type Raw = *mut raw::git_tree_entry; - unsafe fn from_raw(raw: *mut raw::git_tree_entry) -> TreeEntry<'a> { + unsafe fn from_raw(raw: *mut raw::git_tree_entry) -> Self { TreeEntry { raw, owned: true, @@ -355,7 +355,7 @@ impl<'a> Binding for TreeEntry<'a> { } impl<'a> Clone for TreeEntry<'a> { - fn clone(&self) -> TreeEntry<'a> { + fn clone(&self) -> Self { let mut ret = ptr::null_mut(); unsafe { assert_eq!(raw::git_tree_entry_dup(&mut ret, &*self.raw()), 0); @@ -365,18 +365,18 @@ impl<'a> Clone for TreeEntry<'a> { } impl<'a> PartialOrd for TreeEntry<'a> { - fn partial_cmp(&self, other: &TreeEntry<'a>) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } impl<'a> Ord for TreeEntry<'a> { - fn cmp(&self, other: &TreeEntry<'a>) -> Ordering { + fn cmp(&self, other: &Self) -> Ordering { c_cmp_to_ordering(unsafe { raw::git_tree_entry_cmp(&*self.raw(), &*other.raw()) }) } } impl<'a> PartialEq for TreeEntry<'a> { - fn eq(&self, other: &TreeEntry<'a>) -> bool { + fn eq(&self, other: &Self) -> bool { self.cmp(other) == Ordering::Equal } } diff --git a/src/treebuilder.rs b/src/treebuilder.rs index 1548a048cf..e487ae8977 100644 --- a/src/treebuilder.rs +++ b/src/treebuilder.rs @@ -147,7 +147,7 @@ extern "C" fn filter_cb(entry: *const raw::git_tree_entry, payload: *mut c_void) impl<'repo> Binding for TreeBuilder<'repo> { type Raw = *mut raw::git_treebuilder; - unsafe fn from_raw(raw: *mut raw::git_treebuilder) -> TreeBuilder<'repo> { + unsafe fn from_raw(raw: *mut raw::git_treebuilder) -> Self { TreeBuilder { raw, _marker: marker::PhantomData, diff --git a/src/version.rs b/src/version.rs index b5dd4fb123..435b4a55d6 100644 --- a/src/version.rs +++ b/src/version.rs @@ -18,8 +18,8 @@ macro_rules! flag_test { impl Version { /// Returns a [`Version`] which provides information about libgit2. - pub fn get() -> Version { - let mut v = Version { + pub fn get() -> Self { + let mut v = Self { major: 0, minor: 0, rev: 0, diff --git a/src/worktree.rs b/src/worktree.rs index fc32902db1..03a57b00d3 100644 --- a/src/worktree.rs +++ b/src/worktree.rs @@ -43,7 +43,7 @@ impl Worktree { /// If a repository is not the main tree but a worktree, this /// function will look up the worktree inside the parent /// repository and create a new `git_worktree` structure. - pub fn open_from_repository(repo: &Repository) -> Result { + pub fn open_from_repository(repo: &Repository) -> Result { let mut raw = ptr::null_mut(); unsafe { try_call!(raw::git_worktree_open_from_repository(&mut raw, repo.raw())); @@ -145,7 +145,7 @@ impl<'a> WorktreeAddOptions<'a> { /// Creates a default set of add options. /// /// By default this will not lock the worktree - pub fn new() -> WorktreeAddOptions<'a> { + pub fn new() -> Self { unsafe { let mut raw = mem::zeroed(); assert_eq!( @@ -160,22 +160,19 @@ impl<'a> WorktreeAddOptions<'a> { } /// If enabled, this will cause the newly added worktree to be locked - pub fn lock(&mut self, enabled: bool) -> &mut WorktreeAddOptions<'a> { + pub fn lock(&mut self, enabled: bool) -> &mut Self { self.raw.lock = enabled as c_int; self } /// If enabled, this will checkout the existing branch matching the worktree name. - pub fn checkout_existing(&mut self, enabled: bool) -> &mut WorktreeAddOptions<'a> { + pub fn checkout_existing(&mut self, enabled: bool) -> &mut Self { self.raw.checkout_existing = enabled as c_int; self } /// reference to use for the new worktree HEAD - pub fn reference( - &mut self, - reference: Option<&'a Reference<'_>>, - ) -> &mut WorktreeAddOptions<'a> { + pub fn reference(&mut self, reference: Option<&'a Reference<'_>>) -> &mut Self { self.raw.reference = if let Some(reference) = reference { reference.raw() } else { @@ -195,7 +192,7 @@ impl WorktreePruneOptions { /// /// By defaults this will prune only worktrees that are no longer valid /// unlocked and not checked out - pub fn new() -> WorktreePruneOptions { + pub fn new() -> Self { unsafe { let mut raw = mem::zeroed(); assert_eq!( @@ -205,7 +202,7 @@ impl WorktreePruneOptions { ), 0 ); - WorktreePruneOptions { raw } + Self { raw } } } @@ -213,25 +210,25 @@ impl WorktreePruneOptions { /// will be pruned /// /// Defaults to false - pub fn valid(&mut self, valid: bool) -> &mut WorktreePruneOptions { + pub fn valid(&mut self, valid: bool) -> &mut Self { self.flag(raw::GIT_WORKTREE_PRUNE_VALID, valid) } /// Controls whether locked worktrees will be pruned /// /// Defaults to false - pub fn locked(&mut self, locked: bool) -> &mut WorktreePruneOptions { + pub fn locked(&mut self, locked: bool) -> &mut Self { self.flag(raw::GIT_WORKTREE_PRUNE_LOCKED, locked) } /// Controls whether the actual working tree on the filesystem is recursively removed /// /// Defaults to false - pub fn working_tree(&mut self, working_tree: bool) -> &mut WorktreePruneOptions { + pub fn working_tree(&mut self, working_tree: bool) -> &mut Self { self.flag(raw::GIT_WORKTREE_PRUNE_WORKING_TREE, working_tree) } - fn flag(&mut self, flag: raw::git_worktree_prune_t, on: bool) -> &mut WorktreePruneOptions { + fn flag(&mut self, flag: raw::git_worktree_prune_t, on: bool) -> &mut Self { if on { self.raw.flags |= flag as u32; } else { @@ -248,8 +245,8 @@ impl WorktreePruneOptions { impl Binding for Worktree { type Raw = *mut raw::git_worktree; - unsafe fn from_raw(ptr: *mut raw::git_worktree) -> Worktree { - Worktree { raw: ptr } + unsafe fn from_raw(ptr: *mut raw::git_worktree) -> Self { + Self { raw: ptr } } fn raw(&self) -> *mut raw::git_worktree { self.raw