create IntoPathBuf
This commit is contained in:
parent
d323ae3070
commit
aced8b992a
@ -27,6 +27,12 @@ pub fn push() {
|
||||
|
||||
let staged_objs = status::get_all_staged();
|
||||
|
||||
// exit if there is nothing to push
|
||||
if staged_objs.len() == 0 {
|
||||
println!("Everything up-to-date");
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
// path that certify that all its children can be push whithout hesistation
|
||||
// (e.g. if remote dir has no changes since last sync all children
|
||||
// can be pushed without verification)
|
||||
|
@ -23,7 +23,7 @@ pub fn remote_diff() {
|
||||
|
||||
pub fn get_diff(path: PathBuf) -> (Vec<ObjProps>, Vec<ObjProps>) {
|
||||
|
||||
let depth = "2"; // todo
|
||||
let depth = "2"; // todo opti
|
||||
let api_props = get_api_props();
|
||||
|
||||
enumerate_remote(
|
||||
|
@ -145,7 +145,7 @@ pub fn get_all_staged() -> Vec<LocalObj> {
|
||||
let mut staged_objs = vec![];
|
||||
|
||||
for line in lines {
|
||||
let obj = Blob::new(PathBuf::from(line)).get_local_obj();
|
||||
let obj = Blob::new(line).get_local_obj();
|
||||
if obj.state != State::Default {
|
||||
staged_objs.push(obj);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ use std::time::SystemTime;
|
||||
use crypto::sha1::Sha1;
|
||||
use crypto::digest::Digest;
|
||||
use crate::commands::status::{LocalObj, State};
|
||||
use crate::utils::into::IntoPathBuf;
|
||||
use crate::utils::path::path_buf_to_string;
|
||||
use crate::utils::{path, read};
|
||||
use crate::store::head;
|
||||
@ -24,7 +25,8 @@ pub struct Blob {
|
||||
}
|
||||
|
||||
impl Blob {
|
||||
pub fn new(r_path: PathBuf) -> Blob {
|
||||
pub fn new<S>(r_path: S) -> Blob where S: IntoPathBuf {
|
||||
let r_path = r_path.into();
|
||||
let mut hasher = Sha1::new();
|
||||
hasher.input_str(r_path.to_str().unwrap());
|
||||
let hash = hasher.result_str();
|
||||
@ -351,7 +353,7 @@ impl Blob {
|
||||
} else if !has_obj_ref && blob_exists {
|
||||
let identical_blobs = self.get_all_identical_blobs();
|
||||
if identical_blobs.len() != 0 {
|
||||
let identical_blob = Blob::new(identical_blobs[0].clone().into())
|
||||
let identical_blob = Blob::new(identical_blobs[0].clone())
|
||||
.get_local_obj();
|
||||
if identical_blob.state == State::Deleted {
|
||||
path_from = Some(identical_blob.path);
|
||||
|
@ -4,3 +4,4 @@ pub mod nextsyncignore;
|
||||
pub mod api;
|
||||
pub mod time;
|
||||
pub mod remote;
|
||||
pub mod into;
|
||||
|
18
src/utils/into.rs
Normal file
18
src/utils/into.rs
Normal file
@ -0,0 +1,18 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub trait IntoPathBuf {
|
||||
fn into(self) -> PathBuf;
|
||||
}
|
||||
|
||||
impl IntoPathBuf for PathBuf {
|
||||
fn into(self) -> PathBuf {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoPathBuf for String {
|
||||
fn into(self) -> PathBuf {
|
||||
PathBuf::from(self)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user