Matthias Andreas Benkard | b5d657a | 2022-02-03 21:14:30 +0100 | [diff] [blame^] | 1 | // SPDX-FileCopyrightText: © 2021 Matthias Andreas Benkard <code@mail.matthias.benkard.de> |
| 2 | // |
| 3 | // SPDX-License-Identifier: LGPL-3.0-or-later |
| 4 | |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 5 | package eu.mulk.jgvariant.ostree; |
| 6 | |
| 7 | import eu.mulk.jgvariant.core.Decoder; |
| 8 | import java.nio.ByteOrder; |
| 9 | import java.nio.charset.StandardCharsets; |
| 10 | import 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 Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 18 | * |
| 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 Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 31 | */ |
| 32 | public 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 Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 42 | /** |
| 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 Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 48 | 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 Benkard | 0511464 | 2021-12-29 21:51:29 +0100 | [diff] [blame] | 71 | /** |
| 72 | * Acquires a {@link Decoder} for the enclosing type. |
| 73 | * |
| 74 | * @return a possibly shared {@link Decoder}. |
| 75 | */ |
Matthias Andreas Benkard | 4e8423d | 2021-12-19 22:56:09 +0100 | [diff] [blame] | 76 | public static Decoder<Commit> decoder() { |
| 77 | return DECODER; |
| 78 | } |
| 79 | } |