Skip to content

Commit ac7fa66

Browse files
committed
UpstreamIndex: Extract crates_from_index_head() method
1 parent d35f770 commit ac7fa66

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

src/tests/git.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,29 @@ impl UpstreamIndex {
2424
Url::from_file_path(&bare()).unwrap()
2525
}
2626

27+
/// Obtain a list of crates from the index HEAD
28+
pub fn crates_from_index_head(&self, crate_name: &str) -> Vec<cargo_registry::git::Crate> {
29+
let repo = &self.repository;
30+
31+
let path = cargo_registry::git::Repository::relative_index_file(crate_name);
32+
let tree = repo.head().unwrap().peel_to_tree().unwrap();
33+
let blob = tree
34+
.get_path(&path)
35+
.unwrap()
36+
.to_object(repo)
37+
.unwrap()
38+
.peel_to_blob()
39+
.unwrap();
40+
let content = blob.content();
41+
42+
// The index format consists of one JSON object per line
43+
// It is not a JSON array
44+
let lines = std::str::from_utf8(content).unwrap().lines();
45+
lines
46+
.map(|line| serde_json::from_str(line).unwrap())
47+
.collect()
48+
}
49+
2750
pub fn create_empty_commit(&self) -> anyhow::Result<()> {
2851
let repo = &self.repository;
2952

src/tests/util/test_app.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use cargo_registry::{
1111
};
1212
use std::{rc::Rc, sync::Arc, time::Duration};
1313

14-
use cargo_registry::git::{Repository as WorkerRepository, Repository};
14+
use cargo_registry::git::Repository as WorkerRepository;
1515
use diesel::PgConnection;
1616
use reqwest::{blocking::Client, Proxy};
1717
use std::collections::HashSet;
@@ -139,24 +139,7 @@ impl TestApp {
139139

140140
/// Obtain a list of crates from the index HEAD
141141
pub fn crates_from_index_head(&self, crate_name: &str) -> Vec<cargo_registry::git::Crate> {
142-
let path = Repository::relative_index_file(crate_name);
143-
let index = self.upstream_repository();
144-
let tree = index.head().unwrap().peel_to_tree().unwrap();
145-
let blob = tree
146-
.get_path(&path)
147-
.unwrap()
148-
.to_object(index)
149-
.unwrap()
150-
.peel_to_blob()
151-
.unwrap();
152-
let content = blob.content();
153-
154-
// The index format consists of one JSON object per line
155-
// It is not a JSON array
156-
let lines = std::str::from_utf8(content).unwrap().lines();
157-
lines
158-
.map(|line| serde_json::from_str(line).unwrap())
159-
.collect()
142+
self.upstream_index().crates_from_index_head(crate_name)
160143
}
161144

162145
pub fn run_pending_background_jobs(&self) {

0 commit comments

Comments
 (0)