mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-04 07:08:53 +00:00
Merge branch 'fix/better-pull-strategy' into 'main'
fix: better pull/checkout strategy with fetch, checkout and merge Closes #65 See merge request gabmus/envision!17
This commit is contained in:
commit
15543619fb
7 changed files with 48 additions and 111 deletions
|
@ -1,7 +1,4 @@
|
||||||
use crate::{
|
use crate::ui::job_worker::job::{FuncWorkerOut, WorkerJob};
|
||||||
profile::Profile,
|
|
||||||
ui::job_worker::job::{FuncWorkerOut, WorkerJob},
|
|
||||||
};
|
|
||||||
use git2::Repository;
|
use git2::Repository;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
@ -9,9 +6,16 @@ use std::path::Path;
|
||||||
pub struct Git {
|
pub struct Git {
|
||||||
pub repo: String,
|
pub repo: String,
|
||||||
pub dir: String,
|
pub dir: String,
|
||||||
|
pub default_branch: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Git {
|
impl Git {
|
||||||
|
fn cmd(&self, args: Vec<String>) -> WorkerJob {
|
||||||
|
let mut nargs = vec!["-C".into(), self.dir.clone()];
|
||||||
|
nargs.extend(args);
|
||||||
|
WorkerJob::new_cmd(None, "git".into(), Some(nargs))
|
||||||
|
}
|
||||||
|
|
||||||
fn get_repo(&self) -> String {
|
fn get_repo(&self) -> String {
|
||||||
self.repo
|
self.repo
|
||||||
.split('#')
|
.split('#')
|
||||||
|
@ -27,16 +31,7 @@ impl Git {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_reset_job(&self) -> WorkerJob {
|
pub fn get_reset_job(&self) -> WorkerJob {
|
||||||
WorkerJob::new_cmd(
|
self.cmd(vec!["reset".into(), "--hard".into()])
|
||||||
None,
|
|
||||||
"git".into(),
|
|
||||||
Some(vec![
|
|
||||||
"-C".into(),
|
|
||||||
self.dir.clone(),
|
|
||||||
"reset".into(),
|
|
||||||
"--hard".into(),
|
|
||||||
]),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_override_remote_url_job(&self) -> WorkerJob {
|
pub fn get_override_remote_url_job(&self) -> WorkerJob {
|
||||||
|
@ -76,11 +71,7 @@ impl Git {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_pull_job(&self) -> WorkerJob {
|
pub fn get_pull_job(&self) -> WorkerJob {
|
||||||
WorkerJob::new_cmd(
|
self.cmd(vec!["pull".into()])
|
||||||
None,
|
|
||||||
"git".into(),
|
|
||||||
Some(vec!["-C".into(), self.dir.clone(), "pull".into()]),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_clone_job(&self) -> WorkerJob {
|
pub fn get_clone_job(&self) -> WorkerJob {
|
||||||
|
@ -96,32 +87,37 @@ impl Git {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_checkout_ref_job(&self) -> Option<WorkerJob> {
|
pub fn get_checkout_ref_job(&self) -> WorkerJob {
|
||||||
self.get_ref().map(|r| {
|
let gref = self.get_ref().unwrap_or(self.default_branch.clone());
|
||||||
WorkerJob::new_cmd(
|
self.cmd(vec!["checkout".into(), gref])
|
||||||
None,
|
|
||||||
"git".into(),
|
|
||||||
Some(vec!["-C".into(), self.dir.clone(), "checkout".into(), r]),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_clone_or_not_job(&self) -> Option<WorkerJob> {
|
pub fn get_fetch_job(&self) -> WorkerJob {
|
||||||
|
self.cmd(vec!["fetch".into()])
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_merge_job(&self) -> WorkerJob {
|
||||||
|
self.cmd(vec!["merge".into(), "--ff-only".into()])
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clone_exists(&self) -> bool {
|
||||||
let path_s = format!("{}/.git", self.dir.clone());
|
let path_s = format!("{}/.git", self.dir.clone());
|
||||||
let path = Path::new(&path_s);
|
Path::new(&path_s).is_dir()
|
||||||
if path.is_dir() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
Some(self.get_clone_job())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_clone_or_pull_job(&self, profile: &Profile) -> Option<WorkerJob> {
|
pub fn get_pre_build_jobs(&self, pull_on_build: bool) -> Vec<WorkerJob> {
|
||||||
match self.get_clone_or_not_job() {
|
let mut jobs = Vec::<WorkerJob>::new();
|
||||||
Some(j) => Some(j),
|
if self.clone_exists() {
|
||||||
None => match profile.pull_on_build {
|
if pull_on_build {
|
||||||
true => Some(self.get_pull_job()),
|
jobs.push(self.get_override_remote_url_job());
|
||||||
false => None,
|
jobs.push(self.get_fetch_job());
|
||||||
},
|
jobs.push(self.get_checkout_ref_job());
|
||||||
}
|
jobs.push(self.get_pull_job());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
jobs.push(self.get_clone_job());
|
||||||
|
jobs.push(self.get_checkout_ref_job());
|
||||||
|
}
|
||||||
|
jobs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,20 +18,10 @@ pub fn get_build_basalt_jobs(profile: &Profile, clean_build: bool) -> VecDeque<W
|
||||||
None => "https://gitlab.freedesktop.org/mateosss/basalt.git".into(),
|
None => "https://gitlab.freedesktop.org/mateosss/basalt.git".into(),
|
||||||
},
|
},
|
||||||
dir: profile.features.basalt.path.as_ref().unwrap().clone(),
|
dir: profile.features.basalt.path.as_ref().unwrap().clone(),
|
||||||
|
default_branch: "main".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
jobs.push_back(git.get_override_remote_url_job());
|
jobs.extend(git.get_pre_build_jobs(profile.pull_on_build));
|
||||||
|
|
||||||
git.get_clone_or_pull_job(profile).map(|j| {
|
|
||||||
jobs.push_back(j);
|
|
||||||
});
|
|
||||||
|
|
||||||
git.get_checkout_ref_job().map(|j| {
|
|
||||||
jobs.push_back(j);
|
|
||||||
if profile.pull_on_build {
|
|
||||||
jobs.push_back(git.get_pull_job());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let build_dir = format!("{}/build", profile.features.basalt.path.as_ref().unwrap());
|
let build_dir = format!("{}/build", profile.features.basalt.path.as_ref().unwrap());
|
||||||
let mut cmake_vars: HashMap<String, String> = HashMap::new();
|
let mut cmake_vars: HashMap<String, String> = HashMap::new();
|
||||||
|
|
|
@ -18,20 +18,10 @@ pub fn get_build_libsurvive_jobs(profile: &Profile, clean_build: bool) -> VecDeq
|
||||||
None => "https://github.com/cntools/libsurvive".into(),
|
None => "https://github.com/cntools/libsurvive".into(),
|
||||||
},
|
},
|
||||||
dir: profile.features.libsurvive.path.as_ref().unwrap().clone(),
|
dir: profile.features.libsurvive.path.as_ref().unwrap().clone(),
|
||||||
|
default_branch: "master".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
jobs.push_back(git.get_override_remote_url_job());
|
jobs.extend(git.get_pre_build_jobs(profile.pull_on_build));
|
||||||
|
|
||||||
git.get_clone_or_pull_job(profile).map(|j| {
|
|
||||||
jobs.push_back(j);
|
|
||||||
});
|
|
||||||
|
|
||||||
git.get_checkout_ref_job().map(|j| {
|
|
||||||
jobs.push_back(j);
|
|
||||||
if profile.pull_on_build {
|
|
||||||
jobs.push_back(git.get_pull_job());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let build_dir = format!(
|
let build_dir = format!(
|
||||||
"{}/build",
|
"{}/build",
|
||||||
|
|
|
@ -22,19 +22,10 @@ pub fn get_build_monado_jobs(
|
||||||
None => "https://gitlab.freedesktop.org/monado/monado".into(),
|
None => "https://gitlab.freedesktop.org/monado/monado".into(),
|
||||||
},
|
},
|
||||||
dir: profile.xrservice_path.clone(),
|
dir: profile.xrservice_path.clone(),
|
||||||
|
default_branch: "main".into(),
|
||||||
};
|
};
|
||||||
jobs.push_back(git.get_override_remote_url_job());
|
|
||||||
|
|
||||||
git.get_clone_or_pull_job(profile).map(|j| {
|
jobs.extend(git.get_pre_build_jobs(profile.pull_on_build));
|
||||||
jobs.push_back(j);
|
|
||||||
});
|
|
||||||
|
|
||||||
git.get_checkout_ref_job().map(|j| {
|
|
||||||
jobs.push_back(j);
|
|
||||||
if profile.pull_on_build {
|
|
||||||
jobs.push_back(git.get_pull_job());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let build_dir = format!("{}/build", profile.xrservice_path);
|
let build_dir = format!("{}/build", profile.xrservice_path);
|
||||||
let mut env: HashMap<String, String> = HashMap::new();
|
let mut env: HashMap<String, String> = HashMap::new();
|
||||||
|
|
|
@ -18,20 +18,10 @@ pub fn get_build_opencomposite_jobs(profile: &Profile, clean_build: bool) -> Vec
|
||||||
None => "https://gitlab.com/znixian/OpenOVR.git".into(),
|
None => "https://gitlab.com/znixian/OpenOVR.git".into(),
|
||||||
},
|
},
|
||||||
dir: profile.opencomposite_path.clone(),
|
dir: profile.opencomposite_path.clone(),
|
||||||
|
default_branch: "openxr".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
jobs.push_back(git.get_override_remote_url_job());
|
jobs.extend(git.get_pre_build_jobs(profile.pull_on_build));
|
||||||
|
|
||||||
git.get_clone_or_pull_job(profile).map(|j| {
|
|
||||||
jobs.push_back(j);
|
|
||||||
});
|
|
||||||
|
|
||||||
git.get_checkout_ref_job().map(|j| {
|
|
||||||
jobs.push_back(j);
|
|
||||||
if profile.pull_on_build {
|
|
||||||
jobs.push_back(git.get_pull_job());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let build_dir = format!("{}/build", profile.opencomposite_path);
|
let build_dir = format!("{}/build", profile.opencomposite_path);
|
||||||
let mut cmake_vars: HashMap<String, String> = HashMap::new();
|
let mut cmake_vars: HashMap<String, String> = HashMap::new();
|
||||||
|
|
|
@ -18,20 +18,10 @@ pub fn get_build_openhmd_jobs(profile: &Profile, clean_build: bool) -> VecDeque<
|
||||||
None => "https://github.com/OpenHMD/OpenHMD".into(),
|
None => "https://github.com/OpenHMD/OpenHMD".into(),
|
||||||
},
|
},
|
||||||
dir: profile.features.openhmd.path.as_ref().unwrap().clone(),
|
dir: profile.features.openhmd.path.as_ref().unwrap().clone(),
|
||||||
|
default_branch: "master".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
jobs.push_back(git.get_override_remote_url_job());
|
jobs.extend(git.get_pre_build_jobs(profile.pull_on_build));
|
||||||
|
|
||||||
git.get_clone_or_pull_job(profile).map(|j| {
|
|
||||||
jobs.push_back(j);
|
|
||||||
});
|
|
||||||
|
|
||||||
git.get_checkout_ref_job().map(|j| {
|
|
||||||
jobs.push_back(j);
|
|
||||||
if profile.pull_on_build {
|
|
||||||
jobs.push_back(git.get_pull_job());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let build_dir = format!("{}/build", profile.features.openhmd.path.as_ref().unwrap());
|
let build_dir = format!("{}/build", profile.features.openhmd.path.as_ref().unwrap());
|
||||||
let mut cmake_vars: HashMap<String, String> = HashMap::new();
|
let mut cmake_vars: HashMap<String, String> = HashMap::new();
|
||||||
|
|
|
@ -22,20 +22,10 @@ pub fn get_build_wivrn_jobs(
|
||||||
None => "https://github.com/Meumeu/WiVRn".into(),
|
None => "https://github.com/Meumeu/WiVRn".into(),
|
||||||
},
|
},
|
||||||
dir: profile.xrservice_path.clone(),
|
dir: profile.xrservice_path.clone(),
|
||||||
|
default_branch: "master".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
jobs.push_back(git.get_override_remote_url_job());
|
jobs.extend(git.get_pre_build_jobs(profile.pull_on_build));
|
||||||
|
|
||||||
git.get_clone_or_pull_job(profile).map(|j| {
|
|
||||||
jobs.push_back(j);
|
|
||||||
});
|
|
||||||
|
|
||||||
git.get_checkout_ref_job().map(|j| {
|
|
||||||
jobs.push_back(j);
|
|
||||||
if profile.pull_on_build {
|
|
||||||
jobs.push_back(git.get_pull_job());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let build_dir = format!("{}/build", profile.xrservice_path);
|
let build_dir = format!("{}/build", profile.xrservice_path);
|
||||||
let mut cmake_vars: HashMap<String, String> = HashMap::new();
|
let mut cmake_vars: HashMap<String, String> = HashMap::new();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue