aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2022-07-29 20:28:53 +0200
committerMartin Fischer <martin@push-f.com>2022-07-29 20:28:53 +0200
commitd9cd7ab6f46ddc71206bb75bb72eb9dc36743cac (patch)
tree53fc33582ad451b51ab910db4bf70c8d6288e410 /src
parent4c036ec89cebabd4fcf068177cc668110c5a42ed (diff)
refactor: introduce SoloController::new
Diffstat (limited to 'src')
-rw-r--r--src/controller.rs14
-rw-r--r--src/main.rs14
2 files changed, 15 insertions, 13 deletions
diff --git a/src/controller.rs b/src/controller.rs
index 55ff4c2..7a4a44a 100644
--- a/src/controller.rs
+++ b/src/controller.rs
@@ -75,6 +75,20 @@ pub trait Controller {
pub struct SoloController(pub Branch);
+impl SoloController {
+ pub fn new(repo: &Repository) -> Self {
+ Self(Branch(
+ repo.find_reference("HEAD")
+ .unwrap()
+ .symbolic_target()
+ .unwrap()
+ .strip_prefix("refs/heads/")
+ .unwrap()
+ .to_owned(),
+ ))
+ }
+}
+
const USERNAME_HEADER: &str = "Username";
impl Controller for SoloController {
diff --git a/src/main.rs b/src/main.rs
index ab65d75..9251003 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -100,19 +100,7 @@ async fn main() {
if args.multiuser {
serve(MultiUserController::new(&repo), args).await;
} else {
- serve(
- SoloController(Branch(
- repo.find_reference("HEAD")
- .unwrap()
- .symbolic_target()
- .unwrap()
- .strip_prefix("refs/heads/")
- .unwrap()
- .to_owned(),
- )),
- args,
- )
- .await;
+ serve(SoloController::new(&repo), args).await;
}
}