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