commit

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2026 License: GPL-3.0, LGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package commit defines the Commit object (CAS type 5): the analogue of a git commit — a directory root, ordered parent commits, author, committer and message, with an optional opaque signature — extended with what a jj commit carries besides: a change id, and the further terms and the labels of a conflicted tree. Encoding is RFC 8949 §4.2 core-deterministic CBOR (canonical map, integer keys), the fstree and reference convention. The key's length field is a footprint, like a directory's: the commit's own bytes plus its trees. See architecture/commits.md.

Index

Constants

View Source
const (
	// MaxParents is the maximum number of parent commits.
	MaxParents = 256
	// MaxIdentityLen is the maximum byte length of an identity's name or email.
	MaxIdentityLen = 1024
	// MaxMessageLen is the maximum message length in bytes (1 MiB).
	MaxMessageLen = 1 << 20
	// MaxSignatureLen is the maximum Signature length in bytes (64 KiB).
	MaxSignatureLen = 64 << 10
	// MaxPublicKeyLen is the maximum PublicKey length in bytes (16 KiB).
	MaxPublicKeyLen = 16 << 10
	// MaxTZOffset bounds Identity.TZOffset to under a day either side of UTC.
	MaxTZOffset = 1439
	// MaxChangeIDLen is the maximum ChangeID length in bytes.
	MaxChangeIDLen = 64
	// MaxConflictTerms is the maximum number of conflict terms after the
	// tree. The number is always even: a remove for every further add.
	MaxConflictTerms = 254
	// MaxLabelLen is the maximum byte length of one conflict label. jj makes
	// a label from a commit's short ids and the whole first line of its
	// description, which nothing bounds; its adapter truncates beyond this.
	MaxLabelLen = 64 << 10
)

Variables

This section is empty.

Functions

func Footprint added in v0.0.10

func Footprint(own uint64, trees []key.Key) (uint64, error)

Footprint is the length field of the key of a commit whose encoding is own bytes long and which records trees. It is an error for the sum not to fit.

Types

type Commit

type Commit struct {
	Tree      key.Key   // DirLeaf or DirNode
	Parents   []key.Key // Commit keys, no duplicates
	Author    Identity
	Committer Identity
	Message   string // UTF-8, may be empty
	Signature []byte // raw SSHSIG blob, nil when unsigned
	PublicKey []byte // signer's key, SSH wire format, nil when absent

	ChangeID       []byte    // opaque, 1..MaxChangeIDLen bytes: follows the change through rewrites; nil when absent
	ConflictTerms  []key.Key // DirLeaf or DirNode keys, an even number; nil when the tree is resolved
	ConflictLabels []string  // one per term counting Tree, at least one non-empty; nil when no term is labelled
}

Commit is a snapshot record. Parents are ordered — the first is the mainline — and empty for a root commit. Signature and PublicKey are carried opaquely; the core neither creates nor verifies signatures.

A conflicted commit records the tree A0 − R0 + A1 − R1 + …: Tree holds A0 and ConflictTerms holds R0, A1, R1, A2, … (jj's order), so their number is even. Wherever a commit stands for a directory it stands for Tree.

func Decode

func Decode(b []byte) (Commit, error)

Decode parses and validates a commit. It rejects non-canonical encodings: the input must be byte-for-byte what Encode produces for the same record (extra or missing map keys, reordered keys, indefinite-length items, non-minimal integers and trailing bytes are all rejected).

func (Commit) Conflicted added in v0.0.10

func (c Commit) Conflicted() bool

Conflicted reports whether the commit records a conflicted tree.

func (Commit) Encode

func (c Commit) Encode() ([]byte, error)

Encode returns the deterministic CBOR encoding of a validated commit.

func (Commit) Object

func (c Commit) Object() (key.Key, []byte, error)

Object encodes c and derives its key: type Commit, the length field a footprint as a directory's is — the encoding's own byte length plus the length of every tree (Trees). Parents are not counted: a parent's length would hold its own parents', so every merge would count the history its parents share twice, roughly doubling the value until it no longer fit; and a directory that holds a commit reports, through this length, the size of what is beneath it, not of its history.

func (Commit) SignaturePayload

func (c Commit) SignaturePayload() ([]byte, error)

SignaturePayload returns the bytes a signature runs over: the deterministic encoding without the Signature field. PublicKey stays in, so the payload binds the signer's key; set it before computing the payload.

func (Commit) Trees added in v0.0.10

func (c Commit) Trees() []key.Key

Trees returns every tree the commit records: Tree, then the conflict terms in order. The key's length and the object graph both go by this list.

type Identity

type Identity struct {
	Name     string // 0..MaxIdentityLen bytes, no control characters; empty when the user configured none
	Email    string // 0..MaxIdentityLen bytes, no control characters
	When     int64  // ns since the Unix epoch
	TZOffset int    // minutes east of UTC, -MaxTZOffset..MaxTZOffset
}

Identity is who acted and when: git's "Name <email> time tz".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL