blob: 209827d0c3e82471458187efb90f4745b3327e77 [file] [log] [blame]
Matthias Andreas Benkardb5d657a2022-02-03 21:14:30 +01001// SPDX-FileCopyrightText: © 2021 Matthias Andreas Benkard <code@mail.matthias.benkard.de>
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +01005package eu.mulk.jgvariant.ostree;
6
7import eu.mulk.jgvariant.core.Decoder;
8import java.nio.ByteOrder;
9import java.nio.charset.StandardCharsets;
10import java.util.List;
11
12/**
13 * A commit in an OSTree repository.
14 *
15 * <p>Has an optional parent, a root directory, and various metadata.
16 *
17 * <p>Reference: {@code ostree-core.h#OSTREE_COMMIT_GVARIANT_STRING}
Matthias Andreas Benkard05114642021-12-29 21:51:29 +010018 *
19 * @param metadata arbitrary metadata supplied by the user who made the commit.
20 * @param parentChecksum a (possibly {@link Checksum#isEmpty()}) reference to this commit's parent
21 * commit.
22 * @param relatedObjects references to related commits.
23 * @param subject the subject line part of the commit message.
24 * @param body the body part of the commit message.
25 * @param timestamp UNIX epoch seconds of when the commit was done.
26 * @param rootDirTreeChecksum the checksum of the {@link DirTree} file describing the root
27 * directory.
28 * @param rootDirMetaChecksum the checksum of the {@link DirMeta} file describing the root
29 * directory.
30 * @see ObjectType#COMMIT
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010031 */
32public record Commit(
33 Metadata metadata,
34 Checksum parentChecksum,
35 List<RelatedObject> relatedObjects,
36 String subject,
37 String body,
38 long timestamp,
39 Checksum rootDirTreeChecksum,
40 Checksum rootDirMetaChecksum) {
41
Matthias Andreas Benkard05114642021-12-29 21:51:29 +010042 /**
43 * A reference to a related commit.
44 *
45 * @param ref the name of the reference.
46 * @param commitChecksum the checksum of the related commit.
47 */
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010048 public record RelatedObject(String ref, Checksum commitChecksum) {
49
50 private static final Decoder<RelatedObject> DECODER =
51 Decoder.ofStructure(
52 RelatedObject.class, Decoder.ofString(StandardCharsets.UTF_8), Checksum.decoder());
53
54 public static Decoder<RelatedObject> decoder() {
55 return DECODER;
56 }
57 }
58
59 private static final Decoder<Commit> DECODER =
60 Decoder.ofStructure(
61 Commit.class,
62 Metadata.decoder(),
63 Checksum.decoder(),
64 Decoder.ofArray(RelatedObject.decoder()),
65 Decoder.ofString(StandardCharsets.UTF_8),
66 Decoder.ofString(StandardCharsets.UTF_8),
67 Decoder.ofLong().withByteOrder(ByteOrder.BIG_ENDIAN),
68 Checksum.decoder(),
69 Checksum.decoder());
70
Matthias Andreas Benkard05114642021-12-29 21:51:29 +010071 /**
72 * Acquires a {@link Decoder} for the enclosing type.
73 *
74 * @return a possibly shared {@link Decoder}.
75 */
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010076 public static Decoder<Commit> decoder() {
77 return DECODER;
78 }
79}