mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-01 12:26:02 +03:00
Merge pull request #3856 from gitbutlerapp/branch-refactor-branch-implementation
remove unsed branch from implementation
This commit is contained in:
commit
528c0d7598
@ -87,144 +87,3 @@ pub struct BranchCreateRequest {
|
||||
pub order: Option<usize>,
|
||||
pub selected_for_changes: Option<bool>,
|
||||
}
|
||||
|
||||
impl Branch {
|
||||
pub fn from_reader(reader: &crate::reader::Reader<'_>) -> Result<Self, crate::reader::Error> {
|
||||
let results = reader.batch(&[
|
||||
"id",
|
||||
"meta/name",
|
||||
"meta/notes",
|
||||
"meta/applied",
|
||||
"meta/order",
|
||||
"meta/upstream",
|
||||
"meta/upstream_head",
|
||||
"meta/tree",
|
||||
"meta/head",
|
||||
"meta/created_timestamp_ms",
|
||||
"meta/updated_timestamp_ms",
|
||||
"meta/ownership",
|
||||
"meta/selected_for_changes",
|
||||
])?;
|
||||
|
||||
let id: String = results[0].clone()?.try_into()?;
|
||||
let id: BranchId = id.parse().map_err(|e| {
|
||||
crate::reader::Error::Io(
|
||||
std::io::Error::new(std::io::ErrorKind::Other, format!("id: {}", e)).into(),
|
||||
)
|
||||
})?;
|
||||
let name: String = results[1].clone()?.try_into()?;
|
||||
|
||||
let notes: String = match results[2].clone() {
|
||||
Ok(notes) => Ok(notes.try_into()?),
|
||||
Err(crate::reader::Error::NotFound) => Ok(String::new()),
|
||||
Err(e) => Err(e),
|
||||
}?;
|
||||
|
||||
let applied = match results[3].clone() {
|
||||
Ok(applied) => applied.try_into(),
|
||||
_ => Ok(false),
|
||||
}
|
||||
.unwrap_or(false);
|
||||
|
||||
let order: usize = match results[4].clone() {
|
||||
Ok(order) => Ok(order.try_into()?),
|
||||
Err(crate::reader::Error::NotFound) => Ok(0),
|
||||
Err(e) => Err(e),
|
||||
}?;
|
||||
|
||||
let upstream = match results[5].clone() {
|
||||
Ok(crate::reader::Content::UTF8(upstream)) => {
|
||||
if upstream.is_empty() {
|
||||
Ok(None)
|
||||
} else {
|
||||
upstream
|
||||
.parse::<git::RemoteRefname>()
|
||||
.map(Some)
|
||||
.map_err(|e| {
|
||||
crate::reader::Error::Io(
|
||||
std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
format!("meta/upstream: {}", e),
|
||||
)
|
||||
.into(),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
Ok(_) | Err(crate::reader::Error::NotFound) => Ok(None),
|
||||
Err(e) => Err(e),
|
||||
}?;
|
||||
|
||||
let upstream_head = match results[6].clone() {
|
||||
Ok(crate::reader::Content::UTF8(upstream_head)) => {
|
||||
upstream_head.parse().map(Some).map_err(|e| {
|
||||
crate::reader::Error::Io(
|
||||
std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
format!("meta/upstream_head: {}", e),
|
||||
)
|
||||
.into(),
|
||||
)
|
||||
})
|
||||
}
|
||||
Ok(_) | Err(crate::reader::Error::NotFound) => Ok(None),
|
||||
Err(e) => Err(e),
|
||||
}?;
|
||||
|
||||
let tree: String = results[7].clone()?.try_into()?;
|
||||
let head: String = results[8].clone()?.try_into()?;
|
||||
let created_timestamp_ms = results[9].clone()?.try_into()?;
|
||||
let updated_timestamp_ms = results[10].clone()?.try_into()?;
|
||||
|
||||
let ownership_string: String = results[11].clone()?.try_into()?;
|
||||
let ownership = ownership_string.parse().map_err(|e| {
|
||||
crate::reader::Error::Io(
|
||||
std::io::Error::new(std::io::ErrorKind::Other, format!("meta/ownership: {}", e))
|
||||
.into(),
|
||||
)
|
||||
})?;
|
||||
|
||||
let selected_for_changes = match results[12].clone() {
|
||||
Ok(raw_ts) => {
|
||||
let ts = raw_ts.try_into().map_err(|e| {
|
||||
crate::reader::Error::Io(
|
||||
std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
format!("meta/selected_for_changes: {}", e),
|
||||
)
|
||||
.into(),
|
||||
)
|
||||
})?;
|
||||
Ok(Some(ts))
|
||||
}
|
||||
Err(crate::reader::Error::NotFound) => Ok(None),
|
||||
Err(e) => Err(e),
|
||||
}?;
|
||||
|
||||
Ok(Self {
|
||||
id,
|
||||
name,
|
||||
notes,
|
||||
applied,
|
||||
upstream,
|
||||
upstream_head,
|
||||
tree: tree.parse().map_err(|e| {
|
||||
crate::reader::Error::Io(
|
||||
std::io::Error::new(std::io::ErrorKind::Other, format!("meta/tree: {}", e))
|
||||
.into(),
|
||||
)
|
||||
})?,
|
||||
head: head.parse().map_err(|e| {
|
||||
crate::reader::Error::Io(
|
||||
std::io::Error::new(std::io::ErrorKind::Other, format!("meta/head: {}", e))
|
||||
.into(),
|
||||
)
|
||||
})?,
|
||||
created_timestamp_ms,
|
||||
updated_timestamp_ms,
|
||||
ownership,
|
||||
order,
|
||||
selected_for_changes,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user