step sixty one: push, send only missing objects
This commit is contained in:
parent
8144a96321
commit
4e1988997a
14
src/data.rs
14
src/data.rs
|
@ -176,11 +176,17 @@ pub fn fetch_object_if_missing(oid: String, remote_git_dir: String) {
|
||||||
|
|
||||||
pub fn push_object(oid: String, remote_git_dir: String) {
|
pub fn push_object(oid: String, remote_git_dir: String) {
|
||||||
let rgit_remote = remote_git_dir + "/.rgit";
|
let rgit_remote = remote_git_dir + "/.rgit";
|
||||||
|
let remote_object = format!("{}/objects/{}", rgit_remote, oid.clone());
|
||||||
|
|
||||||
|
if Path::new(&remote_object).exists() {
|
||||||
|
// Only push object if it doesn't exist.
|
||||||
|
// Different implementation from the tutorial, the end result should be
|
||||||
|
// the same.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let dir = RGIT_DIR.lock().unwrap().to_owned();
|
let dir = RGIT_DIR.lock().unwrap().to_owned();
|
||||||
fs::copy(
|
fs::copy(format!("{}/objects/{}", dir, oid), remote_object)
|
||||||
format!("{}/objects/{}", dir, oid),
|
|
||||||
format!("{}/objects/{}", rgit_remote, oid.clone()),
|
|
||||||
)
|
|
||||||
.expect(format!("Failed to push {}", oid).as_str());
|
.expect(format!("Failed to push {}", oid).as_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue