summaryrefslogtreecommitdiff
path: root/src/git/config.rs
diff options
context:
space:
mode:
authorKim Altintop <kim@eagain.io>2023-01-09 13:18:33 +0100
committerKim Altintop <kim@eagain.io>2023-01-09 13:18:33 +0100
commitd2f423521ec76406944ad83098ec33afe20c692b (patch)
treeafd86bcb088eebdd61ba4e52fa666ff0f41c42a2 /src/git/config.rs
This is it
Squashed commit of all the exploration history. Development starts here. Signed-off-by: Kim Altintop <kim@eagain.io>
Diffstat (limited to 'src/git/config.rs')
-rw-r--r--src/git/config.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/git/config.rs b/src/git/config.rs
new file mode 100644
index 0000000..bc8dfcc
--- /dev/null
+++ b/src/git/config.rs
@@ -0,0 +1,31 @@
+// Copyright © 2022 Kim Altintop <kim@eagain.io>
+// SPDX-License-Identifier: GPL-2.0-only WITH openvpn-openssl-exception
+
+use std::ops::Deref;
+
+/// A read-only snapshot of a [`git2::Config`]
+pub struct Snapshot(git2::Config);
+
+impl Deref for Snapshot {
+ type Target = git2::Config;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+
+impl TryFrom<git2::Config> for Snapshot {
+ type Error = git2::Error;
+
+ fn try_from(mut cfg: git2::Config) -> Result<Self, Self::Error> {
+ cfg.snapshot().map(Self)
+ }
+}
+
+impl TryFrom<&mut git2::Config> for Snapshot {
+ type Error = git2::Error;
+
+ fn try_from(cfg: &mut git2::Config) -> Result<Self, Self::Error> {
+ cfg.snapshot().map(Self)
+ }
+}