improve staging to take files in new folders
This commit is contained in:
parent
601f176198
commit
f812ad411e
@ -31,8 +31,7 @@ pub enum State {
|
|||||||
pub fn status() {
|
pub fn status() {
|
||||||
let (mut new_objs_hashes, mut del_objs_hashes) = get_diff();
|
let (mut new_objs_hashes, mut del_objs_hashes) = get_diff();
|
||||||
// get copy, modified
|
// get copy, modified
|
||||||
let mut staged_objs = get_staged(&mut del_objs_hashes);
|
let mut staged_objs = get_staged(&mut new_objs_hashes, &mut del_objs_hashes);
|
||||||
staged_objs.append(&mut get_staged(&mut new_objs_hashes));
|
|
||||||
|
|
||||||
let mut objs: Vec<LocalObj> = del_objs_hashes.iter().map(|x| {
|
let mut objs: Vec<LocalObj> = del_objs_hashes.iter().map(|x| {
|
||||||
x.1.clone()
|
x.1.clone()
|
||||||
@ -58,14 +57,13 @@ pub struct LocalObj {
|
|||||||
pub fn get_all_staged() -> Vec<LocalObj> {
|
pub fn get_all_staged() -> Vec<LocalObj> {
|
||||||
let (mut new_objs_hashes, mut del_objs_hashes) = get_diff();
|
let (mut new_objs_hashes, mut del_objs_hashes) = get_diff();
|
||||||
// get copy, modified
|
// get copy, modified
|
||||||
let mut staged_objs = get_staged(&mut del_objs_hashes);
|
let mut staged_objs = get_staged(&mut new_objs_hashes, &mut del_objs_hashes);
|
||||||
staged_objs.append(&mut get_staged(&mut new_objs_hashes));
|
|
||||||
|
|
||||||
staged_objs.clone()
|
staged_objs.clone()
|
||||||
// todo opti getting staged and then finding differences ?
|
// todo opti getting staged and then finding differences ?
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_staged(objs_hashes: &mut HashMap<String, LocalObj>) -> Vec<LocalObj> {
|
fn get_staged(new_objs_h: &mut HashMap<String, LocalObj>, del_objs_h: &mut HashMap<String, LocalObj>) -> Vec<LocalObj> {
|
||||||
let mut lines: Vec<String> = vec![];
|
let mut lines: Vec<String> = vec![];
|
||||||
|
|
||||||
if let Ok(entries) = index::read_line() {
|
if let Ok(entries) = index::read_line() {
|
||||||
@ -78,6 +76,7 @@ fn get_staged(objs_hashes: &mut HashMap<String, LocalObj>) -> Vec<LocalObj> {
|
|||||||
let mut hasher = Sha1::new();
|
let mut hasher = Sha1::new();
|
||||||
let mut staged_objs: Vec<LocalObj> = vec![];
|
let mut staged_objs: Vec<LocalObj> = vec![];
|
||||||
|
|
||||||
|
let ref_p = path::repo_root();
|
||||||
for obj in lines {
|
for obj in lines {
|
||||||
// hash the object
|
// hash the object
|
||||||
hasher.input_str(&obj);
|
hasher.input_str(&obj);
|
||||||
@ -85,9 +84,27 @@ fn get_staged(objs_hashes: &mut HashMap<String, LocalObj>) -> Vec<LocalObj> {
|
|||||||
hasher.reset();
|
hasher.reset();
|
||||||
|
|
||||||
// find it on the list of hashes
|
// find it on the list of hashes
|
||||||
if objs_hashes.contains_key(&hash) {
|
if new_objs_h.contains_key(&hash) {
|
||||||
staged_objs.push(objs_hashes.get(&hash).unwrap().clone());
|
staged_objs.push(new_objs_h.get(&hash).unwrap().clone());
|
||||||
objs_hashes.remove(&hash);
|
new_objs_h.remove(&hash);
|
||||||
|
} else if del_objs_h.contains_key(&hash) {
|
||||||
|
staged_objs.push(del_objs_h.get(&hash).unwrap().clone());
|
||||||
|
del_objs_h.remove(&hash);
|
||||||
|
}else {
|
||||||
|
let mut t_path = ref_p.clone();
|
||||||
|
t_path.push(PathBuf::from(obj.clone()));
|
||||||
|
staged_objs.push(LocalObj {
|
||||||
|
otype: get_otype(t_path.clone()),
|
||||||
|
name: obj.to_string(),
|
||||||
|
path: t_path.clone(),
|
||||||
|
state: {
|
||||||
|
if t_path.exists() {
|
||||||
|
State::New
|
||||||
|
} else {
|
||||||
|
State::Deleted
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user