1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use std::{
    fmt::{Debug, Formatter},
    ops::{Deref, DerefMut},
};

use crate::config::{CommitAutoRollback, Snapshot, SnapshotMut};

impl Debug for Snapshot<'_> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        f.write_str(&self.repo.config.resolved.to_string())
    }
}

impl Debug for CommitAutoRollback<'_> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        f.write_str(&self.repo.as_ref().expect("still present").config.resolved.to_string())
    }
}

impl Debug for SnapshotMut<'_> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        f.write_str(&self.config.to_string())
    }
}

impl Drop for SnapshotMut<'_> {
    fn drop(&mut self) {
        if let Some(repo) = self.repo.take() {
            self.commit_inner(repo).ok();
        };
    }
}

impl Drop for CommitAutoRollback<'_> {
    fn drop(&mut self) {
        if let Some(repo) = self.repo.take() {
            self.rollback_inner(repo).ok();
        }
    }
}

impl Deref for SnapshotMut<'_> {
    type Target = gix_config::File<'static>;

    fn deref(&self) -> &Self::Target {
        &self.config
    }
}

impl Deref for Snapshot<'_> {
    type Target = gix_config::File<'static>;

    fn deref(&self) -> &Self::Target {
        self.plumbing()
    }
}

impl Deref for CommitAutoRollback<'_> {
    type Target = crate::Repository;

    fn deref(&self) -> &Self::Target {
        self.repo.as_ref().expect("always present")
    }
}

impl DerefMut for CommitAutoRollback<'_> {
    fn deref_mut(&mut self) -> &mut Self::Target {
        self.repo.as_mut().expect("always present")
    }
}

impl DerefMut for SnapshotMut<'_> {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.config
    }
}