blob: f14e758bfdf631c9f370cc1257071be0350bd55a [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
Matthias Andreas Benkard91dbd742022-10-17 19:38:56 +02007import static java.nio.charset.StandardCharsets.UTF_8;
8
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +01009import eu.mulk.jgvariant.core.Decoder;
10import java.nio.ByteOrder;
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010011import java.util.List;
12
13/**
14 * A commit in an OSTree repository.
15 *
16 * <p>Has an optional parent, a root directory, and various metadata.
17 *
18 * <p>Reference: {@code ostree-core.h#OSTREE_COMMIT_GVARIANT_STRING}
Matthias Andreas Benkard05114642021-12-29 21:51:29 +010019 *
20 * @param metadata arbitrary metadata supplied by the user who made the commit.
21 * @param parentChecksum a (possibly {@link Checksum#isEmpty()}) reference to this commit's parent
22 * commit.
23 * @param relatedObjects references to related commits.
24 * @param subject the subject line part of the commit message.
25 * @param body the body part of the commit message.
26 * @param timestamp UNIX epoch seconds of when the commit was done.
27 * @param rootDirTreeChecksum the checksum of the {@link DirTree} file describing the root
28 * directory.
29 * @param rootDirMetaChecksum the checksum of the {@link DirMeta} file describing the root
30 * directory.
31 * @see ObjectType#COMMIT
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010032 */
33public record Commit(
34 Metadata metadata,
35 Checksum parentChecksum,
36 List<RelatedObject> relatedObjects,
37 String subject,
38 String body,
39 long timestamp,
40 Checksum rootDirTreeChecksum,
41 Checksum rootDirMetaChecksum) {
42
Matthias Andreas Benkard05114642021-12-29 21:51:29 +010043 /**
44 * A reference to a related commit.
45 *
46 * @param ref the name of the reference.
47 * @param commitChecksum the checksum of the related commit.
48 */
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010049 public record RelatedObject(String ref, Checksum commitChecksum) {
50
51 private static final Decoder<RelatedObject> DECODER =
Matthias Andreas Benkard91dbd742022-10-17 19:38:56 +020052 Decoder.ofStructure(RelatedObject.class, Decoder.ofString(UTF_8), Checksum.decoder());
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010053
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()),
Matthias Andreas Benkard91dbd742022-10-17 19:38:56 +020065 Decoder.ofString(UTF_8),
66 Decoder.ofString(UTF_8),
Matthias Andreas Benkard4e8423d2021-12-19 22:56:09 +010067 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}