Skip to content

Commit aecd5ff

Browse files
committed
Change hierarchy format (sync with cargo)
1 parent 7129aef commit aecd5ff

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/git.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,16 @@ pub fn add_package(app: &App, package: &NewPackage) -> CargoResult<()> {
9494
let repo = app.git_repo.lock();
9595
let repo = &*repo;
9696
let name = package.name.as_slice();
97-
let (c1, c2) = match name.len() {
98-
0 => unreachable!(),
99-
1 => (format!("{}:", name.slice_to(1)), format!("::")),
100-
2 => (format!("{}", name.slice_to(2)), format!("::")),
101-
3 => (format!("{}", name.slice_to(2)), format!("{}:", name.char_at(2))),
102-
_ => (name.slice_to(2).to_string(), name.slice(2, 4).to_string()),
97+
let repo_path = repo.path().dir_path();
98+
let dst = match name.len() {
99+
1 => repo_path.join("1").join(name),
100+
2 => repo_path.join("2").join(name),
101+
3 => repo_path.join("3").join(name.slice_to(1)).join(name),
102+
_ => repo_path.join(name.slice(0, 2))
103+
.join(name.slice(2, 4))
104+
.join(name),
103105
};
104106

105-
let part = Path::new(c1).join(c2).join(name);
106-
let dst = repo.path().dir_path().join(&part);
107-
108107
// Attempt to commit the package in a loop. It's possible that we're going
109108
// to need to rebase our repository, and after that it's possible that we're
110109
// going to race to commit the changes. For now we just cap out the maximum
@@ -123,7 +122,7 @@ pub fn add_package(app: &App, package: &NewPackage) -> CargoResult<()> {
123122

124123
// git add $file
125124
let mut index = try!(repo.index());
126-
try!(index.add_path(&part));
125+
try!(index.add_path(&dst.path_relative_from(&repo_path).unwrap()));
127126
try!(index.write());
128127
let tree_id = try!(index.write_tree());
129128
let tree = try!(repo.find_tree(tree_id));

src/tests/package.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ fn new_package_git_upload() {
208208
let mut response = ok_resp!(middle.call(&mut req));
209209
::json::<GoodPackage>(&mut response);
210210

211-
let path = ::git::checkout().join("fo/o:/foo");
211+
let path = ::git::checkout().join("3/f/foo");
212212
assert!(path.exists());
213213
let contents = File::open(&path).read_to_string().unwrap();
214214
let p: GitPackage = json::decode(contents.as_slice()).unwrap();
@@ -223,7 +223,7 @@ fn new_package_git_upload() {
223223
fn new_package_git_upload_appends() {
224224
let (_b, _app, mut middle) = ::app();
225225
let user = ::user();
226-
let path = ::git::checkout().join("fo/o:/foo");
226+
let path = ::git::checkout().join("3/f/foo");
227227
fs::mkdir_recursive(&path.dir_path(), io::UserRWX).unwrap();
228228
File::create(&path).write_str(
229229
r#"{"name":"foo","vers":"0.0.1","deps":[],"cksum":"3j3"}"#

0 commit comments

Comments
 (0)