M src/git/get_all.rs => src/git/get_all.rs +6 -7
@@ 1,10 1,6 @@
use crate::config::CONFIG;
use git2::ObjectType;
-
-
-
-
pub fn files(repo: String, branch: String, path: String) -> Option<Vec<String>> {
if branch.contains(":") {
return None;
@@ 21,9 17,12 @@ pub fn files(repo: String, branch: String, path: String) -> Option<Vec<String>>
for entry in tree.iter() {
if entry.kind() == Some(ObjectType::Blob) {
returns.push(format!("{}{}", path, entry.name()?));
- }
- else {
- for i in files(repo_clone.clone(), branch.clone(), format!("{}{}/", path, entry.name()?))? {
+ } else {
+ for i in files(
+ repo_clone.clone(),
+ branch.clone(),
+ format!("{}{}/", path, entry.name()?),
+ )? {
returns.push(i);
}
}
M src/git/mod.rs => src/git/mod.rs +1 -1
@@ 3,7 3,7 @@ pub mod branches;
pub mod commits;
pub mod diffs;
pub mod file;
+pub mod get_all;
pub mod main_branch;
pub mod repos;
pub mod tag;
-pub mod get_all;
M src/main.rs => src/main.rs +1 -1
@@ 11,6 11,7 @@ use utils::config;
use rocket::fs::relative;
use std::path::Path;
+use crate::repository::archive;
use crate::repository::blame;
use crate::repository::commit;
use crate::repository::log;
@@ 18,7 19,6 @@ use crate::repository::raw;
use crate::repository::refs;
use crate::repository::summary;
use crate::repository::tree;
-use crate::repository::archive;
use crate::utils::own_pathbuf::PathBufWithDotfiles;
use rocket_dyn_templates::Template;
M src/repository/archive.rs => src/repository/archive.rs +8 -5
@@ 1,16 1,14 @@
use crate::config::CONFIG;
use crate::git::get_all::files;
-use tar::{Builder, Header};
use rocket::response::stream::ByteStream;
-
-
+use tar::{Builder, Header};
#[get("/<repo>/archive/<oid>", rank = 2)]
pub fn archive(repo: String, oid: String) -> ByteStream![Vec<u8>] {
ByteStream! {
let oid = oid[..oid.len()-7].to_string();
let files = files(repo.clone(), oid.clone(), "".to_string()).unwrap();
- for i in files {
+ for i in files {
match get_tar(repo.clone(), oid.clone(), i) {
Some(x) => yield x[..x.len()-1024].to_vec(),
None => {},
@@ 31,6 29,11 @@ fn get_tar(repo: String, oid: String, path: String) -> Option<Vec<u8>> {
header.set_size(blob.size() as u64);
header.set_cksum();
let mut ar = Builder::new(Vec::new());
- ar.append_data(&mut header, format!("{}/{}", repo_clone, path), blob.content()).unwrap();
+ ar.append_data(
+ &mut header,
+ format!("{}/{}", repo_clone, path),
+ blob.content(),
+ )
+ .unwrap();
Some(ar.into_inner().ok()?)
}
M src/repository/mod.rs => src/repository/mod.rs +1 -1
@@ 1,3 1,4 @@
+pub mod archive;
pub mod blame;
pub mod commit;
pub mod log;
@@ 5,4 6,3 @@ pub mod raw;
pub mod refs;
pub mod summary;
pub mod tree;
-pub mod archive;