|
5 | 5 | //!
|
6 | 6 | //! ### House-~~Rules~~ Guidance
|
7 | 7 | //!
|
8 |
| -//! * Try hard to do write all the 'right' tests |
| 8 | +//! * **Try hard to do write all the 'right' tests** |
9 | 9 | //! - Tests should challenge the implementation, try hard to break it.
|
10 | 10 | //! - capture *all* business requirements
|
11 | 11 | //! - Try to avoid doing read-only filesystem fixtures with `tempdir`, instead use `gitbutler-testtools::readonly`.
|
12 |
| -//! * minimal dependencies |
13 |
| -//! - both for the crate and for parameters of functions as well. |
| 12 | +//! * **minimal dependencies** |
| 13 | +//! - both for the *crate* and for *parameters* of functions as well. |
14 | 14 | //! - i.e. try to avoid 'God' structures so the function only has access to what it needs to.
|
15 |
| -//! * The filesystem is `Sync` but we don't have atomic operations |
| 15 | +//! * **The filesystem is `Sync` but we don't have atomic operations** |
16 | 16 | //! - Let's be very careful about changes to the filesystem, must at least be on the level of Git which means `.lock` files instead of direct writes.
|
17 | 17 | //! - If only one part of the application is supposed to change the worktree, let's protect the Application from itself by using `gitbutler::access` just like we do now.
|
18 |
| -//! * Make it work, make it work right, and if time and profiler permits, make it work fast. |
19 |
| -//! * All of the above can and should be scrutinized and is there is no hard rules. |
| 18 | +//! * **Implement `Serialize` on utility types to facilitate transfer to the frontend** |
| 19 | +//! - But don't make bigger types frontend-specific. If that is needed, create a new type in the frontend-crate that uses frontend types. |
| 20 | +//! - `BString` has a `BStringForFrontend` counterpart. |
| 21 | +//! - `gix::ObjectId` has a `with = gitbutler_serde::object_id` serialization module. |
| 22 | +//! * **Make it work, make it work right, and if time and profiler permits, make it work fast**. |
| 23 | +//! * **All of the above can and should be scrutinized and is there is no hard rules.** |
| 24 | +//! |
| 25 | +//! ### Terminology |
| 26 | +//! |
| 27 | +//! * **Worktree** |
| 28 | +//! - A git worktree, i.e. the checkout of a tree that makes the tree accessible on disk. |
| 29 | +//! * **Workspace** |
| 30 | +//! - A GitButler concept of the combination of one or more branches into one worktree. This allows |
| 31 | +//! multiple branches to be perceived in one worktree, by merging multiple branches together. |
| 32 | +//! |
20 | 33 |
|
21 | 34 | /// Functions related to a Git worktree, i.e. the files checked out from a repository.
|
22 | 35 | pub mod worktree {
|
| 36 | + use bstr::BString; |
| 37 | + use serde::{Deserialize, Serialize}; |
23 | 38 | use std::path::Path;
|
24 | 39 |
|
25 |
| - /// Return a list of items that live underneath `worktree_root` that changed and thus can become part of a commit. |
26 |
| - pub fn committable_entries(_worktree_root: &Path) -> anyhow::Result<()> { |
| 40 | + /// Identify where a [`Committable`] is from. |
| 41 | + #[derive(Debug, Clone, Copy, Serialize, Deserialize)] |
| 42 | + pub enum DiffKind { |
| 43 | + /// The change was detected when doing a diff between a tree and an index. |
| 44 | + TreeIndex, |
| 45 | + /// The change was detected when doing a diff between an index and a worktree. |
| 46 | + IndexWorktree, |
| 47 | + } |
| 48 | + |
| 49 | + /// Something that fully identifies the state of a [`Committable`]. |
| 50 | + #[derive(Debug, Clone, Copy)] |
| 51 | + pub struct CommittableState { |
| 52 | + /// The content of the committable. |
| 53 | + /// |
| 54 | + /// If [`null`](gix::ObjectId::is_null), the current state isn't known which can happen |
| 55 | + /// if this state is living in the worktree and has never been hashed. |
| 56 | + pub id: gix::ObjectId, |
| 57 | + /// The kind of the committable. |
| 58 | + pub kind: gix::object::tree::EntryKind, |
| 59 | + } |
| 60 | + |
| 61 | + /// An entry in the worktree that changed and thus is eligible to being committed. |
| 62 | + /// |
| 63 | + /// It either lives (or lived) in the in `.git/index`, or in the `worktree`. |
| 64 | + /// |
| 65 | + /// ### Note |
| 66 | + /// |
| 67 | + /// For simplicity, copy-tracking is not representable right now, but `copy: bool` could be added |
| 68 | + /// if needed. |
| 69 | + #[derive(Debug, Clone)] |
| 70 | + pub struct Committable { |
| 71 | + /// If this item was renamed, this is the previous path relative to the worktree where it |
| 72 | + /// was moved from. |
| 73 | + pub previous_path: Option<BString>, |
| 74 | + /// The *relative* path in the worktree where the entry can be found. |
| 75 | + pub path: BString, |
| 76 | + /// The state that was previously recorded. |
| 77 | + /// |
| 78 | + /// If `None`, there is no known previous value, so this is a newly added item. |
| 79 | + pub previous_state: Option<CommittableState>, |
| 80 | + /// The content that the entry has currently. |
| 81 | + /// |
| 82 | + /// If `None`, this means the entry was deleted, and no current state of it can be known. |
| 83 | + pub state: Option<CommittableState>, |
| 84 | + } |
| 85 | + |
| 86 | + /// Return a list of `(DiffKind, Committable)` that live underneath `worktree_root` that changed and thus can become part of a commit. |
| 87 | + /// |
| 88 | + /// The [`DiffKind`] determines which diff was performed to learn about the [`Committable`]. |
| 89 | + pub fn committables(_worktree_root: &Path) -> anyhow::Result<Vec<(DiffKind, Committable)>> { |
27 | 90 | todo!()
|
28 | 91 | }
|
29 | 92 | }
|
0 commit comments