Skip to main content

Module object_abbreviation

Module object_abbreviation 

Source
Expand description

The abbreviated object name Git prints (core.abbrev, the automatic length, uniqueness), computed without starting Git. What: The abbreviated name Git prints for an object (git commit’s [main 30b2211], git log --oneline), computed in process: the length from core.abbrev or from the number of packed objects, then lengthened until no other object shares the name. Why: A fixed seven characters turns ambiguous as a repository grows (Git itself prints ten in a repository of some hundred thousand objects), and a person may copy the name. Git’s rules are odb_find_abbrev_len (odb.c) for the length and find_abbrev_len_for_pack (odb/source-packed.c) and odb_source_loose_find_abbrev_len (odb/source-loose.c) for the uniqueness, all read from the Git 2.56.0 sources. The count is the approximate one: the objects of the pack indexes (a multi-pack-index counts for the packs it covers), loose objects not counted, alternates included. Reading the indexes needs no Git process; a shape this reader does not model (an incremental multi-pack-index chain, a version 1 pack index with a name it cannot read) answers nothing and the caller asks Git.

In TS you’d write (pseudocode):

const short = abbreviate({ objectDirectory, setting: settingOf(config['core.abbrev']), name }); // undefined: ask Git

Enums§

Setting
How a repository asks for the length of an abbreviation.

Constants§

FALLBACK_ABBREVIATION
Git’s FALLBACK_DEFAULT_ABBREV: the shortest automatic length.
MINIMUM_ABBREVIATION
Git’s minimum_abbrev: the shortest length core.abbrev may name.

Functions§

abbreviate
What: The abbreviation of hex that Git prints: at least the length the setting asks for, and longer until no other object of the repository or its alternates starts with the same characters. Why: The answer is Git’s own without starting Git. Nothing is answered when the object directory, an alternate or a pack index has a shape this reader does not model, so the caller can ask Git.
automatic_length
What: The length Git starts from for a repository of count packed objects. Why: About 2^bits objects expect a collision at 2^(bits/2); four bits make a character, and small repositories keep the fallback.
setting_of
What: The setting the value of core.abbrev stands for. Why: Git reads auto as the automatic length, a false word (or an empty value) as the whole name and a number from four up as that many characters; anything else makes Git report the key and keep the automatic length.