Remove unneeded maybe!
(#7576)
This PR removes an unneeded `maybe!` from `get_permalink_to_line`. As this is a `Result`-returning function, we don't need the inner level of wrapping. Release Notes: - N/A
This commit is contained in:
parent
b25044393e
commit
b77d452b90
1 changed files with 35 additions and 38 deletions
|
@ -8396,50 +8396,47 @@ impl Editor {
|
||||||
fn get_permalink_to_line(&mut self, cx: &mut ViewContext<Self>) -> Result<url::Url> {
|
fn get_permalink_to_line(&mut self, cx: &mut ViewContext<Self>) -> Result<url::Url> {
|
||||||
use git::permalink::{build_permalink, BuildPermalinkParams};
|
use git::permalink::{build_permalink, BuildPermalinkParams};
|
||||||
|
|
||||||
let permalink = maybe!({
|
let project = self.project.clone().ok_or_else(|| anyhow!("no project"))?;
|
||||||
let project = self.project.clone().ok_or_else(|| anyhow!("no project"))?;
|
let project = project.read(cx);
|
||||||
let project = project.read(cx);
|
|
||||||
|
|
||||||
let worktree = project
|
let worktree = project
|
||||||
.visible_worktrees(cx)
|
.visible_worktrees(cx)
|
||||||
.next()
|
.next()
|
||||||
.ok_or_else(|| anyhow!("no worktree"))?;
|
.ok_or_else(|| anyhow!("no worktree"))?;
|
||||||
|
|
||||||
let mut cwd = worktree.read(cx).abs_path().to_path_buf();
|
let mut cwd = worktree.read(cx).abs_path().to_path_buf();
|
||||||
cwd.push(".git");
|
cwd.push(".git");
|
||||||
|
|
||||||
const REMOTE_NAME: &'static str = "origin";
|
const REMOTE_NAME: &'static str = "origin";
|
||||||
let repo = project
|
let repo = project
|
||||||
.fs()
|
.fs()
|
||||||
.open_repo(&cwd)
|
.open_repo(&cwd)
|
||||||
.ok_or_else(|| anyhow!("no Git repo"))?;
|
.ok_or_else(|| anyhow!("no Git repo"))?;
|
||||||
let origin_url = repo
|
let origin_url = repo
|
||||||
.lock()
|
.lock()
|
||||||
.remote_url(REMOTE_NAME)
|
.remote_url(REMOTE_NAME)
|
||||||
.ok_or_else(|| anyhow!("remote \"{REMOTE_NAME}\" not found"))?;
|
.ok_or_else(|| anyhow!("remote \"{REMOTE_NAME}\" not found"))?;
|
||||||
let sha = repo
|
let sha = repo
|
||||||
.lock()
|
.lock()
|
||||||
.head_sha()
|
.head_sha()
|
||||||
.ok_or_else(|| anyhow!("failed to read HEAD SHA"))?;
|
.ok_or_else(|| anyhow!("failed to read HEAD SHA"))?;
|
||||||
|
|
||||||
let path = maybe!({
|
let path = maybe!({
|
||||||
let buffer = self.buffer().read(cx).as_singleton()?;
|
let buffer = self.buffer().read(cx).as_singleton()?;
|
||||||
let file = buffer.read(cx).file().and_then(|f| f.as_local())?;
|
let file = buffer.read(cx).file().and_then(|f| f.as_local())?;
|
||||||
file.path().to_str().map(|path| path.to_string())
|
file.path().to_str().map(|path| path.to_string())
|
||||||
})
|
})
|
||||||
.ok_or_else(|| anyhow!("failed to determine file path"))?;
|
.ok_or_else(|| anyhow!("failed to determine file path"))?;
|
||||||
|
|
||||||
let selections = self.selections.all::<Point>(cx);
|
let selections = self.selections.all::<Point>(cx);
|
||||||
let selection = selections.iter().peekable().next();
|
let selection = selections.iter().peekable().next();
|
||||||
|
|
||||||
build_permalink(BuildPermalinkParams {
|
build_permalink(BuildPermalinkParams {
|
||||||
remote_url: &origin_url,
|
remote_url: &origin_url,
|
||||||
sha: &sha,
|
sha: &sha,
|
||||||
path: &path,
|
path: &path,
|
||||||
selection: selection.map(|selection| selection.range()),
|
selection: selection.map(|selection| selection.range()),
|
||||||
})
|
})
|
||||||
});
|
|
||||||
permalink
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn copy_permalink_to_line(&mut self, _: &CopyPermalinkToLine, cx: &mut ViewContext<Self>) {
|
pub fn copy_permalink_to_line(&mut self, _: &CopyPermalinkToLine, cx: &mut ViewContext<Self>) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue