Skip to main content

git_lfs_api/
models.rs

1//! Types shared between the batch and locking endpoints.
2
3use serde::{Deserialize, Serialize};
4
5/// A server refspec, used by both batch and locking requests for
6/// auth schemes that take the ref into account (added in LFS v2.4).
7///
8/// See the [batch spec][batch] ยง "Ref Property".
9///
10/// [batch]: https://gitlab.com/rustutils/git-lfs/-/blob/master/docs/api/batch.md
11#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
12pub struct Ref {
13    /// Full refname, e.g. `refs/heads/main`.
14    pub name: String,
15}
16
17impl Ref {
18    /// Build a refspec from a refname.
19    pub fn new(name: impl Into<String>) -> Self {
20        Self { name: name.into() }
21    }
22}
23
24/// User identity attached to a lock by the server.
25#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
26pub struct Owner {
27    /// Server-supplied display name of the lock owner.
28    pub name: String,
29}
30
31/// A lock record returned by the locking API.
32///
33/// `locked_at` is an uppercase RFC 3339-formatted timestamp with second
34/// precision per the spec. Carried as a string; parsing into a typed
35/// timestamp is left to callers (avoids pulling in a date/time crate here).
36///
37/// Field order matters for `--json` output: the upstream test fixtures
38/// `grep -E` against literal `{"id":...,"path":...,"owner":...,"locked_at":...}`,
39/// and serde's derived `Serialize` follows declaration order.
40#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
41pub struct Lock {
42    /// Server-assigned lock identifier.
43    pub id: String,
44    /// Repo-relative path that's locked.
45    pub path: String,
46    /// User who holds the lock. Servers may omit when the requester
47    /// lacks permission to see the owner.
48    #[serde(default, skip_serializing_if = "Option::is_none")]
49    pub owner: Option<Owner>,
50    /// RFC 3339 timestamp when the lock was created.
51    pub locked_at: String,
52}