Skip to content

Commit f188fc2

Browse files
committed
Rename enums and variants with namespacing in mind
1 parent a072b20 commit f188fc2

File tree

10 files changed

+99
-103
lines changed

10 files changed

+99
-103
lines changed

src/branch.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ impl<'a> Iterator<(Branch<'a>, BranchType)> for Branches<'a> {
119119
}
120120
assert_eq!(rc, 0);
121121
let typ = match typ {
122-
raw::GIT_BRANCH_LOCAL => ::BranchLocal,
123-
raw::GIT_BRANCH_REMOTE => ::BranchRemote,
122+
raw::GIT_BRANCH_LOCAL => BranchType::Local,
123+
raw::GIT_BRANCH_REMOTE => BranchType::Remote,
124124
raw::GIT_BRANCH_ALL => panic!("unexected branch type"),
125125
};
126126
Some((Branch::wrap(Reference::from_raw(self.repo, ret)), typ))
@@ -137,6 +137,8 @@ impl<'a> Drop for Branches<'a> {
137137

138138
#[cfg(test)]
139139
mod tests {
140+
use BranchType;
141+
140142
#[test]
141143
fn smoke() {
142144
let (_td, repo) = ::test::repo_init();
@@ -150,7 +152,7 @@ mod tests {
150152
repo.branch("foo2", &commit, false, None, None).unwrap();
151153

152154
assert_eq!(repo.branches(None).unwrap().count(), 3);
153-
repo.find_branch("foo", ::BranchLocal).unwrap();
155+
repo.find_branch("foo", BranchType::Local).unwrap();
154156
let mut b1 = b1.rename("bar", false, Some(&sig), "bar2").unwrap();
155157
assert_eq!(b1.name().unwrap(), Some("bar"));
156158
assert!(b1.upstream().is_err());

src/call.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ mod impls {
3737
use std::c_str::CString;
3838
use libc;
3939

40-
use raw;
40+
use {raw, ConfigLevel, ResetType, ObjectType, BranchType, Direction};
4141
use call::Convert;
4242

4343
macro_rules! primitive( ($($p:ident)*) => (
@@ -104,67 +104,67 @@ mod impls {
104104
}
105105
}
106106

107-
impl Convert<raw::git_reset_t> for ::ResetType {
107+
impl Convert<raw::git_reset_t> for ResetType {
108108
fn convert(&self) -> raw::git_reset_t {
109109
match *self {
110-
::Soft => raw::GIT_RESET_SOFT,
111-
::Hard => raw::GIT_RESET_HARD,
112-
::Mixed => raw::GIT_RESET_MIXED,
110+
ResetType::Soft => raw::GIT_RESET_SOFT,
111+
ResetType::Hard => raw::GIT_RESET_HARD,
112+
ResetType::Mixed => raw::GIT_RESET_MIXED,
113113
}
114114
}
115115
}
116116

117-
impl Convert<raw::git_direction> for ::Direction {
117+
impl Convert<raw::git_direction> for Direction {
118118
fn convert(&self) -> raw::git_direction {
119119
match *self {
120-
::DirPush => raw::GIT_DIRECTION_PUSH,
121-
::DirFetch => raw::GIT_DIRECTION_FETCH,
120+
Direction::Push => raw::GIT_DIRECTION_PUSH,
121+
Direction::Fetch => raw::GIT_DIRECTION_FETCH,
122122
}
123123
}
124124
}
125125

126-
impl Convert<raw::git_otype> for ::ObjectType {
126+
impl Convert<raw::git_otype> for ObjectType {
127127
fn convert(&self) -> raw::git_otype {
128128
match *self {
129-
::ObjectAny => raw::GIT_OBJ_ANY,
130-
::ObjectCommit => raw::GIT_OBJ_COMMIT,
131-
::ObjectTree => raw::GIT_OBJ_TREE,
132-
::ObjectBlob => raw::GIT_OBJ_BLOB,
133-
::ObjectTag => raw::GIT_OBJ_TAG,
129+
ObjectType::Any => raw::GIT_OBJ_ANY,
130+
ObjectType::Commit => raw::GIT_OBJ_COMMIT,
131+
ObjectType::Tree => raw::GIT_OBJ_TREE,
132+
ObjectType::Blob => raw::GIT_OBJ_BLOB,
133+
ObjectType::Tag => raw::GIT_OBJ_TAG,
134134
}
135135
}
136136
}
137137

138-
impl Convert<raw::git_otype> for Option<::ObjectType> {
138+
impl Convert<raw::git_otype> for Option<ObjectType> {
139139
fn convert(&self) -> raw::git_otype {
140-
self.unwrap_or(::ObjectAny).convert()
140+
self.unwrap_or(ObjectType::Any).convert()
141141
}
142142
}
143143

144-
impl Convert<raw::git_branch_t> for ::BranchType {
144+
impl Convert<raw::git_branch_t> for BranchType {
145145
fn convert(&self) -> raw::git_branch_t {
146146
match *self {
147-
::BranchRemote => raw::GIT_BRANCH_REMOTE,
148-
::BranchLocal => raw::GIT_BRANCH_LOCAL,
147+
BranchType::Remote => raw::GIT_BRANCH_REMOTE,
148+
BranchType::Local => raw::GIT_BRANCH_LOCAL,
149149
}
150150
}
151151
}
152152

153-
impl Convert<raw::git_branch_t> for Option<::BranchType> {
153+
impl Convert<raw::git_branch_t> for Option<BranchType> {
154154
fn convert(&self) -> raw::git_branch_t {
155155
self.map(|s| s.convert()).unwrap_or(raw::GIT_BRANCH_ALL)
156156
}
157157
}
158158

159-
impl Convert<raw::git_config_level_t> for ::ConfigLevel {
159+
impl Convert<raw::git_config_level_t> for ConfigLevel {
160160
fn convert(&self) -> raw::git_config_level_t {
161161
match *self {
162-
::ConfigSystem => raw::GIT_CONFIG_LEVEL_SYSTEM,
163-
::ConfigXDG => raw::GIT_CONFIG_LEVEL_XDG,
164-
::ConfigGlobal => raw::GIT_CONFIG_LEVEL_GLOBAL,
165-
::ConfigLocal => raw::GIT_CONFIG_LEVEL_LOCAL,
166-
::ConfigApp => raw::GIT_CONFIG_LEVEL_APP,
167-
::ConfigHighest => raw::GIT_CONFIG_HIGHEST_LEVEL,
162+
ConfigLevel::System => raw::GIT_CONFIG_LEVEL_SYSTEM,
163+
ConfigLevel::XDG => raw::GIT_CONFIG_LEVEL_XDG,
164+
ConfigLevel::Global => raw::GIT_CONFIG_LEVEL_GLOBAL,
165+
ConfigLevel::Local => raw::GIT_CONFIG_LEVEL_LOCAL,
166+
ConfigLevel::App => raw::GIT_CONFIG_LEVEL_APP,
167+
ConfigLevel::Highest => raw::GIT_CONFIG_HIGHEST_LEVEL,
168168
}
169169
}
170170
}

src/cred.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,12 @@ mod test {
337337
use std::io::{mod, TempDir, File, fs};
338338
use std::os;
339339

340-
use {Cred, Config, CredentialHelper};
340+
use {Cred, Config, CredentialHelper, ConfigLevel};
341341

342342
macro_rules! cfg( ($($k:expr => $v:expr),*) => ({
343343
let td = TempDir::new("git2-rs").unwrap();
344344
let mut cfg = Config::new().unwrap();
345-
cfg.add_file(&td.path().join("cfg"), ::ConfigHighest, false).unwrap();
345+
cfg.add_file(&td.path().join("cfg"), ConfigLevel::Highest, false).unwrap();
346346
$(cfg.set_str($k, $v).unwrap();)*
347347
cfg
348348
}) )

src/error.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,23 @@ impl Error {
3939
/// Return the error code associated with this error.
4040
pub fn code(&self) -> ErrorCode {
4141
match self.raw_code() {
42-
raw::GIT_OK => super::GenericError,
43-
raw::GIT_ERROR => super::GenericError,
44-
raw::GIT_ENOTFOUND => super::NotFound,
45-
raw::GIT_EEXISTS => super::Exists,
46-
raw::GIT_EAMBIGUOUS => super::Ambiguous,
47-
raw::GIT_EBUFS => super::BufSize,
48-
raw::GIT_EUSER => super::User,
49-
raw::GIT_EBAREREPO => super::BareRepo,
50-
raw::GIT_EUNBORNBRANCH => super::UnbornBranch,
51-
raw::GIT_EUNMERGED => super::Unmerged,
52-
raw::GIT_ENONFASTFORWARD => super::NotFastForward,
53-
raw::GIT_EINVALIDSPEC => super::InvalidSpec,
54-
raw::GIT_EMERGECONFLICT => super::MergeConflict,
55-
raw::GIT_ELOCKED => super::Locked,
56-
raw::GIT_EMODIFIED => super::Modified,
57-
raw::GIT_PASSTHROUGH => super::GenericError,
58-
raw::GIT_ITEROVER => super::GenericError,
42+
raw::GIT_OK => super::ErrorCode::GenericError,
43+
raw::GIT_ERROR => super::ErrorCode::GenericError,
44+
raw::GIT_ENOTFOUND => super::ErrorCode::NotFound,
45+
raw::GIT_EEXISTS => super::ErrorCode::Exists,
46+
raw::GIT_EAMBIGUOUS => super::ErrorCode::Ambiguous,
47+
raw::GIT_EBUFS => super::ErrorCode::BufSize,
48+
raw::GIT_EUSER => super::ErrorCode::User,
49+
raw::GIT_EBAREREPO => super::ErrorCode::BareRepo,
50+
raw::GIT_EUNBORNBRANCH => super::ErrorCode::UnbornBranch,
51+
raw::GIT_EUNMERGED => super::ErrorCode::Unmerged,
52+
raw::GIT_ENONFASTFORWARD => super::ErrorCode::NotFastForward,
53+
raw::GIT_EINVALIDSPEC => super::ErrorCode::InvalidSpec,
54+
raw::GIT_EMERGECONFLICT => super::ErrorCode::MergeConflict,
55+
raw::GIT_ELOCKED => super::ErrorCode::Locked,
56+
raw::GIT_EMODIFIED => super::ErrorCode::Modified,
57+
raw::GIT_PASSTHROUGH => super::ErrorCode::GenericError,
58+
raw::GIT_ITEROVER => super::ErrorCode::GenericError,
5959
}
6060
}
6161

src/index.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ mod tests {
475475
use std::io::{mod, fs, File, TempDir};
476476
use url::Url;
477477

478-
use {Index, Repository};
478+
use {Index, Repository, ResetType};
479479

480480
#[test]
481481
fn smoke() {
@@ -552,14 +552,14 @@ mod tests {
552552
let commit = repo.commit(Some("HEAD"), &sig, &sig, "commit",
553553
&tree, [&parent]).unwrap();
554554
let obj = repo.find_object(commit, None).unwrap();
555-
repo.reset(&obj, ::Hard, None, None).unwrap();
555+
repo.reset(&obj, ResetType::Hard, None, None).unwrap();
556556

557557
let td2 = TempDir::new("git").unwrap();
558558
let url = Url::from_file_path(&root).unwrap();
559559
let url = url.to_string();
560560
let repo = Repository::clone(url.as_slice(), td2.path()).unwrap();
561561
let obj = repo.find_object(commit, None).unwrap();
562-
repo.reset(&obj, ::Hard, None, None).unwrap();
562+
repo.reset(&obj, ResetType::Hard, None, None).unwrap();
563563
}
564564
}
565565

src/lib.rs

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
//! source `Repository`, to ensure that they do not outlive the repository
6464
//! itself.
6565
66-
#![feature(globs, macro_rules, unsafe_destructor)]
66+
#![feature(macro_rules, unsafe_destructor)]
6767
#![deny(missing_docs)]
6868

6969
extern crate libc;
@@ -78,14 +78,6 @@ use std::rt;
7878
use std::str;
7979
use std::sync::{Once, ONCE_INIT};
8080

81-
pub use BranchType::*;
82-
pub use ConfigLevel::*;
83-
pub use Direction::*;
84-
pub use ErrorCode::*;
85-
pub use ObjectType::*;
86-
pub use RepositoryState::*;
87-
pub use ResetType::*;
88-
8981
pub use blob::Blob;
9082
pub use branch::{Branch, Branches};
9183
pub use buf::Buf;
@@ -163,9 +155,9 @@ pub enum RepositoryState {
163155
/// An enumeration of the possible directions for a remote.
164156
pub enum Direction {
165157
/// Data will be fetched (read) from this remote.
166-
DirFetch,
158+
Fetch,
167159
/// Data will be pushed (written) to this remote.
168-
DirPush,
160+
Push,
169161
}
170162

171163
/// An enumeration of the operations that can be performed for the `reset`
@@ -183,24 +175,24 @@ pub enum ResetType {
183175
#[deriving(PartialEq, Eq)]
184176
pub enum ObjectType {
185177
/// An object which corresponds to a any git object
186-
ObjectAny,
178+
Any,
187179
/// An object which corresponds to a git commit
188-
ObjectCommit,
180+
Commit,
189181
/// An object which corresponds to a git tree
190-
ObjectTree,
182+
Tree,
191183
/// An object which corresponds to a git blob
192-
ObjectBlob,
184+
Blob,
193185
/// An object which corresponds to a git tag
194-
ObjectTag,
186+
Tag,
195187
}
196188

197189
/// An enumeration for the possible types of branches
198190
#[deriving(PartialEq, Eq, Show)]
199191
pub enum BranchType {
200192
/// A local branch not on a remote.
201-
BranchLocal,
193+
Local,
202194
/// A branch for a remote.
203-
BranchRemote,
195+
Remote,
204196
}
205197

206198
/// An enumeration of the possible priority levels of a config file.
@@ -210,17 +202,17 @@ pub enum BranchType {
210202
#[deriving(PartialEq, Eq, Show)]
211203
pub enum ConfigLevel {
212204
/// System-wide configuration file, e.g. /etc/gitconfig
213-
ConfigSystem,
205+
System,
214206
/// XDG-compatible configuration file, e.g. ~/.config/git/config
215-
ConfigXDG,
207+
XDG,
216208
/// User-specific configuration, e.g. ~/.gitconfig
217-
ConfigGlobal,
209+
Global,
218210
/// Reopsitory specific config, e.g. $PWD/.git/config
219-
ConfigLocal,
211+
Local,
220212
/// Application specific configuration file
221-
ConfigApp,
213+
App,
222214
/// Highest level available
223-
ConfigHighest,
215+
Highest,
224216
}
225217

226218
bitflags! {
@@ -319,13 +311,13 @@ impl ObjectType {
319311
/// Convert a raw git_otype to an ObjectType
320312
pub fn from_raw(raw: raw::git_otype) -> Option<ObjectType> {
321313
match raw {
322-
raw::GIT_OBJ_ANY => Some(ObjectAny),
314+
raw::GIT_OBJ_ANY => Some(ObjectType::Any),
323315
raw::GIT_OBJ_BAD => None,
324316
raw::GIT_OBJ__EXT1 => None,
325-
raw::GIT_OBJ_COMMIT => Some(ObjectCommit),
326-
raw::GIT_OBJ_TREE => Some(ObjectTree),
327-
raw::GIT_OBJ_BLOB => Some(ObjectBlob),
328-
raw::GIT_OBJ_TAG => Some(ObjectTag),
317+
raw::GIT_OBJ_COMMIT => Some(ObjectType::Commit),
318+
raw::GIT_OBJ_TREE => Some(ObjectType::Tree),
319+
raw::GIT_OBJ_BLOB => Some(ObjectType::Blob),
320+
raw::GIT_OBJ_TAG => Some(ObjectType::Tag),
329321
raw::GIT_OBJ__EXT2 => None,
330322
raw::GIT_OBJ_OFS_DELTA => None,
331323
raw::GIT_OBJ_REF_DELTA => None,
@@ -354,12 +346,12 @@ impl ConfigLevel {
354346
/// Converts a raw configuration level to a ConfigLevel
355347
pub fn from_raw(raw: raw::git_config_level_t) -> ConfigLevel {
356348
match raw {
357-
raw::GIT_CONFIG_LEVEL_SYSTEM => ::ConfigSystem,
358-
raw::GIT_CONFIG_LEVEL_XDG => ::ConfigXDG,
359-
raw::GIT_CONFIG_LEVEL_GLOBAL => ::ConfigGlobal,
360-
raw::GIT_CONFIG_LEVEL_LOCAL => ::ConfigLocal,
361-
raw::GIT_CONFIG_LEVEL_APP => ::ConfigApp,
362-
raw::GIT_CONFIG_HIGHEST_LEVEL => ::ConfigHighest,
349+
raw::GIT_CONFIG_LEVEL_SYSTEM => ConfigLevel::System,
350+
raw::GIT_CONFIG_LEVEL_XDG => ConfigLevel::XDG,
351+
raw::GIT_CONFIG_LEVEL_GLOBAL => ConfigLevel::Global,
352+
raw::GIT_CONFIG_LEVEL_LOCAL => ConfigLevel::Local,
353+
raw::GIT_CONFIG_LEVEL_APP => ConfigLevel::App,
354+
raw::GIT_CONFIG_HIGHEST_LEVEL => ConfigLevel::Highest,
363355
}
364356
}
365357
}
@@ -370,9 +362,9 @@ mod tests {
370362

371363
#[test]
372364
fn convert() {
373-
assert_eq!(::ObjectBlob.str(), "blob");
374-
assert_eq!(ObjectType::from_str("blob"), Some(::ObjectBlob));
375-
assert!(::ObjectBlob.is_loose());
365+
assert_eq!(ObjectType::Blob.str(), "blob");
366+
assert_eq!(ObjectType::from_str("blob"), Some(ObjectType::Blob));
367+
assert!(ObjectType::Blob.is_loose());
376368
}
377369

378370
}

src/refspec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::kinds::marker;
22
use std::str;
33

4-
use {raw, Remote, Direction, DirPush, DirFetch};
4+
use {raw, Remote, Direction} ;
55

66
/// A structure to represent a git [refspec][1].
77
///
@@ -34,8 +34,8 @@ impl<'a> Refspec<'a> {
3434
/// Get the refspec's direction.
3535
pub fn direction(&self) -> Direction {
3636
match unsafe { raw::git_refspec_direction(self.raw) } {
37-
raw::GIT_DIRECTION_FETCH => DirFetch,
38-
raw::GIT_DIRECTION_PUSH => DirPush,
37+
raw::GIT_DIRECTION_FETCH => Direction::Fetch,
38+
raw::GIT_DIRECTION_PUSH => Direction::Push,
3939
}
4040
}
4141

src/remote.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ mod tests {
377377
use std::io::TempDir;
378378
use std::cell::Cell;
379379
use url::Url;
380-
use {Repository, Remote, RemoteCallbacks};
380+
use {Repository, Remote, RemoteCallbacks, Direction};
381381

382382
#[test]
383383
fn smoke() {
@@ -426,11 +426,11 @@ mod tests {
426426
assert_eq!(remotes.iter().next().unwrap(), Some("origin"));
427427
}
428428

429-
origin.connect(::DirPush).unwrap();
429+
origin.connect(Direction::Push).unwrap();
430430
assert!(origin.connected());
431431
origin.disconnect();
432432

433-
origin.connect(::DirFetch).unwrap();
433+
origin.connect(Direction::Fetch).unwrap();
434434
assert!(origin.connected());
435435
origin.download().unwrap();
436436
origin.disconnect();

0 commit comments

Comments
 (0)