Skip to content

Commit

Permalink
Update to bitflags 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rcook committed Apr 24, 2023
1 parent 88c67f7 commit 6532a79
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ edition = "2018"

[dependencies]
url = "2.0"
bitflags = "1.1.0"
bitflags = "2.1.0"
libc = "0.2"
log = "0.4.8"
libgit2-sys = { path = "libgit2-sys", version = "0.15.1" }
Expand Down
54 changes: 54 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ pub enum FileFavor {

bitflags! {
/// Orderings that may be specified for Revwalk iteration.
#[derive(PartialEq)]
pub struct Sort: u32 {
/// Sort the repository contents in no particular ordering.
///
Expand Down Expand Up @@ -449,6 +450,7 @@ impl Sort {

bitflags! {
/// Types of credentials that can be requested by a credential callback.
#[derive(PartialEq)]
pub struct CredentialType: u32 {
#[allow(missing_docs)]
const USER_PASS_PLAINTEXT = raw::GIT_CREDTYPE_USERPASS_PLAINTEXT as u32;
Expand Down Expand Up @@ -485,6 +487,7 @@ impl Default for CredentialType {

bitflags! {
/// Flags for the `flags` field of an IndexEntry.
#[derive(PartialEq)]
pub struct IndexEntryFlag: u16 {
/// Set when the `extended_flags` field is valid.
const EXTENDED = raw::GIT_INDEX_ENTRY_EXTENDED as u16;
Expand All @@ -500,6 +503,7 @@ impl IndexEntryFlag {

bitflags! {
/// Flags for the `extended_flags` field of an IndexEntry.
#[derive(PartialEq)]
pub struct IndexEntryExtendedFlag: u16 {
/// An "intent to add" entry from "git add -N"
const INTENT_TO_ADD = raw::GIT_INDEX_ENTRY_INTENT_TO_ADD as u16;
Expand All @@ -519,6 +523,7 @@ impl IndexEntryExtendedFlag {

bitflags! {
/// Flags for APIs that add files matching pathspec
#[derive(PartialEq)]
pub struct IndexAddOption: u32 {
#[allow(missing_docs)]
const DEFAULT = raw::GIT_INDEX_ADD_DEFAULT as u32;
Expand Down Expand Up @@ -550,6 +555,7 @@ impl Default for IndexAddOption {

bitflags! {
/// Flags for `Repository::open_ext`
#[derive(PartialEq)]
pub struct RepositoryOpenFlags: u32 {
/// Only open the specified path; don't walk upward searching.
const NO_SEARCH = raw::GIT_REPOSITORY_OPEN_NO_SEARCH as u32;
Expand All @@ -574,6 +580,7 @@ impl RepositoryOpenFlags {

bitflags! {
/// Flags for the return value of `Repository::revparse`
#[derive(PartialEq)]
pub struct RevparseMode: u32 {
/// The spec targeted a single object
const SINGLE = raw::GIT_REVPARSE_SINGLE as u32;
Expand All @@ -592,6 +599,7 @@ impl RevparseMode {

bitflags! {
/// The results of `merge_analysis` indicating the merge opportunities.
#[derive(PartialEq)]
pub struct MergeAnalysis: u32 {
/// No merge is possible.
const ANALYSIS_NONE = raw::GIT_MERGE_ANALYSIS_NONE as u32;
Expand Down Expand Up @@ -622,6 +630,7 @@ impl MergeAnalysis {

bitflags! {
/// The user's stated preference for merges.
#[derive(PartialEq)]
pub struct MergePreference: u32 {
/// No configuration was found that suggests a preferred behavior for
/// merge.
Expand All @@ -643,6 +652,7 @@ impl MergePreference {

bitflags! {
/// Flags controlling the behavior of ODB lookup operations
#[derive(PartialEq)]
pub struct OdbLookupFlags: u32 {
/// Don't call `git_odb_refresh` if the lookup fails. Useful when doing
/// a batch of lookup operations for objects that may legitimately not
Expand Down Expand Up @@ -997,6 +1007,7 @@ bitflags! {
/// represents the status of file in the index relative to the HEAD, and the
/// `STATUS_WT_*` set of flags represent the status of the file in the
/// working directory relative to the index.
#[derive(PartialEq)]
pub struct Status: u32 {
#[allow(missing_docs)]
const CURRENT = raw::GIT_STATUS_CURRENT as u32;
Expand Down Expand Up @@ -1047,6 +1058,7 @@ impl Status {

bitflags! {
/// Mode options for RepositoryInitOptions
#[derive(PartialEq)]
pub struct RepositoryInitMode: u32 {
/// Use permissions configured by umask - the default
const SHARED_UMASK = raw::GIT_REPOSITORY_INIT_SHARED_UMASK as u32;
Expand Down Expand Up @@ -1179,6 +1191,7 @@ bitflags! {
/// Lastly, the following will only be returned for ignore "NONE".
///
/// * WD_UNTRACKED - workdir contains untracked files
#[derive(PartialEq)]
pub struct SubmoduleStatus: u32 {
#[allow(missing_docs)]
const IN_HEAD = raw::GIT_SUBMODULE_STATUS_IN_HEAD as u32;
Expand Down Expand Up @@ -1275,6 +1288,7 @@ pub enum SubmoduleUpdate {

bitflags! {
/// ...
#[derive(PartialEq)]
pub struct PathspecFlags: u32 {
/// Use the default pathspec matching configuration.
const DEFAULT = raw::GIT_PATHSPEC_DEFAULT as u32;
Expand Down Expand Up @@ -1320,6 +1334,7 @@ impl Default for PathspecFlags {

bitflags! {
/// Types of notifications emitted from checkouts.
#[derive(PartialEq)]
pub struct CheckoutNotificationType: u32 {
/// Notification about a conflict.
const CONFLICT = raw::GIT_CHECKOUT_NOTIFY_CONFLICT as u32;
Expand Down Expand Up @@ -1361,6 +1376,7 @@ pub enum DiffFormat {

bitflags! {
/// Formatting options for diff stats
#[derive(PartialEq)]
pub struct DiffStatsFormat: raw::git_diff_stats_format_t {
/// Don't generate any stats
const NONE = raw::GIT_DIFF_STATS_NONE;
Expand Down Expand Up @@ -1431,6 +1447,7 @@ pub enum StashApplyProgress {

bitflags! {
#[allow(missing_docs)]
#[derive(PartialEq)]
pub struct StashApplyFlags: u32 {
#[allow(missing_docs)]
const DEFAULT = raw::GIT_STASH_APPLY_DEFAULT as u32;
Expand All @@ -1453,6 +1470,7 @@ impl Default for StashApplyFlags {

bitflags! {
#[allow(missing_docs)]
#[derive(PartialEq)]
pub struct StashFlags: u32 {
#[allow(missing_docs)]
const DEFAULT = raw::GIT_STASH_DEFAULT as u32;
Expand Down Expand Up @@ -1483,6 +1501,7 @@ impl Default for StashFlags {

bitflags! {
#[allow(missing_docs)]
#[derive(PartialEq)]
pub struct AttrCheckFlags: u32 {
/// Check the working directory, then the index.
const FILE_THEN_INDEX = raw::GIT_ATTR_CHECK_FILE_THEN_INDEX as u32;
Expand All @@ -1503,6 +1522,7 @@ impl Default for AttrCheckFlags {

bitflags! {
#[allow(missing_docs)]
#[derive(PartialEq)]
pub struct DiffFlags: u32 {
/// File(s) treated as binary data.
const BINARY = raw::GIT_DIFF_FLAG_BINARY as u32;
Expand All @@ -1524,6 +1544,7 @@ impl DiffFlags {

bitflags! {
/// Options for [`Reference::normalize_name`].
#[derive(PartialEq)]
pub struct ReferenceFormat: u32 {
/// No particular normalization.
const NORMAL = raw::GIT_REFERENCE_FORMAT_NORMAL as u32;
Expand Down Expand Up @@ -1576,4 +1597,37 @@ mod tests {
assert_eq!(u32::from(FileMode::BlobGroupWritable), 0o100664);
assert_eq!(u32::from(FileMode::BlobExecutable), 0o100755);
}

#[test]
fn bitflags_partial_eq() {
use super::{
AttrCheckFlags, CheckoutNotificationType, CredentialType, DiffFlags, DiffStatsFormat,
IndexAddOption, IndexEntryExtendedFlag, IndexEntryFlag, MergeAnalysis, MergePreference,
OdbLookupFlags, PathspecFlags, ReferenceFormat, RepositoryInitMode,
RepositoryOpenFlags, RevparseMode, Sort, StashApplyFlags, StashFlags, Status,
SubmoduleStatus,
};

assert!(AttrCheckFlags::FILE_THEN_INDEX == AttrCheckFlags::FILE_THEN_INDEX);
assert!(CheckoutNotificationType::CONFLICT == CheckoutNotificationType::CONFLICT);
assert!(CredentialType::USER_PASS_PLAINTEXT == CredentialType::USER_PASS_PLAINTEXT);
assert!(DiffFlags::BINARY == DiffFlags::BINARY);
assert!(DiffStatsFormat::INCLUDE_SUMMARY == DiffStatsFormat::INCLUDE_SUMMARY);
assert!(IndexAddOption::CHECK_PATHSPEC == IndexAddOption::CHECK_PATHSPEC);
assert!(IndexEntryExtendedFlag::INTENT_TO_ADD == IndexEntryExtendedFlag::INTENT_TO_ADD);
assert!(IndexEntryFlag::EXTENDED == IndexEntryFlag::EXTENDED);
assert!(MergeAnalysis::ANALYSIS_FASTFORWARD == MergeAnalysis::ANALYSIS_FASTFORWARD);
assert!(MergePreference::FASTFORWARD_ONLY == MergePreference::FASTFORWARD_ONLY);
assert!(OdbLookupFlags::NO_REFRESH == OdbLookupFlags::NO_REFRESH);
assert!(PathspecFlags::FAILURES_ONLY == PathspecFlags::FAILURES_ONLY);
assert!(ReferenceFormat::ALLOW_ONELEVEL == ReferenceFormat::ALLOW_ONELEVEL);
assert!(RepositoryInitMode::SHARED_ALL == RepositoryInitMode::SHARED_ALL);
assert!(RepositoryOpenFlags::CROSS_FS == RepositoryOpenFlags::CROSS_FS);
assert!(RevparseMode::RANGE == RevparseMode::RANGE);
assert!(Sort::REVERSE == Sort::REVERSE);
assert!(StashApplyFlags::REINSTATE_INDEX == StashApplyFlags::REINSTATE_INDEX);
assert!(StashFlags::INCLUDE_IGNORED == StashFlags::INCLUDE_IGNORED);
assert!(Status::WT_MODIFIED == Status::WT_MODIFIED);
assert!(SubmoduleStatus::WD_ADDED == SubmoduleStatus::WD_ADDED);
}
}
4 changes: 2 additions & 2 deletions src/revspec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<'repo> Revspec<'repo> {
}

/// Returns the intent of the revspec.
pub fn mode(&self) -> RevparseMode {
self.mode
pub fn mode(&self) -> &RevparseMode {
&self.mode
}
}

0 comments on commit 6532a79

Please sign in to comment.