On this page:
git_  odb_  add_  alternate
git_  odb_  add_  backend
git_  odb_  add_  disk_  alternate
git_  odb_  backend_  loose
git_  odb_  backend_  one_  pack
git_  odb_  backend_  pack
git_  odb_  exists
git_  odb_  exists_  prefix
git_  odb_  expand_  ids
git_  odb_  foreach
git_  odb_  free
git_  odb_  get_  backend
git_  odb_  hash
git_  odb_  hashfile
git_  odb_  init_  backend
git_  odb_  new
git_  odb_  num_  backends
git_  odb_  object_  data
git_  odb_  object_  dup
git_  odb_  object_  free
git_  odb_  object_  id
git_  odb_  object_  size
git_  odb_  object_  type
git_  odb_  open
git_  odb_  open_  rstream
git_  odb_  open_  wstream
git_  odb_  read
git_  odb_  read_  header
git_  odb_  read_  prefix
git_  odb_  refresh
git_  odb_  stream_  finalize_  write
git_  odb_  stream_  free
git_  odb_  stream_  read
git_  odb_  stream_  write
git_  odb_  write
git_  odb_  write_  pack
8.12

24 Object Database🔗ℹ

 (require libgit2/include/odb) package: libgit2

procedure

(git_odb_add_alternate odb backend priority)  integer?

  odb : odb?
  backend : odb_backend?
  priority : integer?
Add a custom backend to an existing Object DB; this backend will work as an alternate.

Alternate backends are always checked for objects after all the main backends have been exhausted.

The backends are checked in relative ordering, based on the value of the priority parameter.

Writing is disabled on alternate backends.

Read for more information.

procedure

(git_odb_add_backend odb backend priority)  integer?

  odb : odb?
  backend : odb_backend?
  priority : integer?
Add a custom backend to an existing Object DB

The backends are checked in relative ordering, based on the value of the priority parameter.

Read for more information.

procedure

(git_odb_add_disk_alternate odb path)  integer?

  odb : odb?
  path : string?
Add an on-disk alternate to an existing Object DB.

Note that the added path must point to an objects, not to a full repository, to use it as an alternate store.

Alternate backends are always checked for objects after all the main backends have been exhausted.

Writing is disabled on alternate backends.

procedure

(git_odb_backend_loose objects_dir    
  compression_level    
  do_fsync    
  dir_mode    
  file_mode)  odb_backend?
  objects_dir : string?
  compression_level : integer?
  do_fsync : boolean?
  dir_mode : exact-positive-integer?
  file_mode : exact-positive-integer?
Create a backend for loose objects

procedure

(git_odb_backend_one_pack index_file)  odb_backend?

  index_file : string?
Create a backend out of a single packfile

This can be useful for inspecting the contents of a single packfile.

procedure

(git_odb_backend_pack objects_dir)  odb_backend?

  objects_dir : string?
Create a backend for the packfiles.

procedure

(git_odb_exists db id)  boolean?

  db : odb?
  id : oid?
Determine if the given object can be found in the object database.

procedure

(git_odb_exists_prefix out db short_id len)  boolean?

  out : oid?
  db : odb?
  short_id : oid?
  len : integer?
Determine if an object can be found in the object database by an abbreviated object ID.

procedure

(git_odb_expand_ids db ids count)  integer?

  db : odb?
  ids : git_odb_expand_id?
  count : integer?
Determine if one or more objects can be found in the object database by their abbreviated object ID and type. The given array will be updated in place: for each abbreviated ID that is unique in the database, and of the given type (if specified), the full object ID, object ID length (GIT_OID_HEXSZ) and type will be written back to the array. For IDs that are not found (or are ambiguous), the array entry will be zeroed.

Note that since this function operates on multiple objects, the underlying database will not be asked to be reloaded if an object is not found (which is unlike other object database operations.)

procedure

(git_odb_foreach db cb payload)  integer?

  db : odb?
  cb : git_odb_foreach_cb
  payload : bytes?
List all objects available in the database

The callback will be called for each object available in the database. Note that the objects are likely to be returned in the index order, which would make accessing the objects in that order inefficient. Return a non-zero value from the callback to stop looping.

procedure

(git_odb_free db)  void?

  db : odb?
Close an open object database.

procedure

(git_odb_get_backend odb pos)  odb_backend?

  odb : odb?
  pos : integer?
Lookup an ODB backend object by index

procedure

(git_odb_hash out data len type)  integer?

  out : oid?
  data : bytes?
  len : integer?
  type : git_otype
Determine the object-ID (sha1 hash) of a data buffer

The resulting SHA-1 OID will be the identifier for the data buffer as if the data buffer it were to written to the ODB.

procedure

(git_odb_hashfile out path type)  integer?

  out : oid?
  path : string?
  type : git_otype
Read a file from disk and fill a git_oid with the object id that the file would have if it were written to the Object Database as an object of the given type (w/o applying filters). Similar functionality to git.git’s git hash-object without the -w flag, however, with the –no-filters flag. If you need filters, see git_repository_hashfile.

procedure

(git_odb_init_backend backend int)  integer?

  backend : odb_backend?
  int : unsigned
Initializes a git_odb_backend with default values. Equivalent to creating an instance with GIT_ODB_BACKEND_INIT.

procedure

(git_odb_new)  odb?

Create a new object database with no backends.

Before the ODB can be used for read/writing, a custom database backend must be manually added using git_odb_add_backend()

procedure

(git_odb_num_backends odb)  integer?

  odb : odb?
Get the number of ODB backend objects

procedure

(git_odb_object_data object)  bytes?

  object : odb_object?
Return the data of an ODB object

This is the uncompressed, raw data as read from the ODB, without the leading header.

This pointer is owned by the object and shall not be free’d.

procedure

(git_odb_object_dup source)  odb_object?

  source : odb_object?
Create a copy of an odb_object

The returned copy must be manually freed with git_odb_object_free. Note that because of an implementation detail, the returned copy will be the same pointer as source: the object is internally refcounted, so the copy still needs to be freed twice.

procedure

(git_odb_object_free object)  void?

  object : odb_object?
Close an ODB object

This method must always be called once a git_odb_object is no longer needed, otherwise memory will leak.

procedure

(git_odb_object_id object)  oid?

  object : odb_object?
Return the OID of an ODB object

This is the OID from which the object was read from

procedure

(git_odb_object_size object)  integer?

  object : odb_object?
Return the size of an ODB object

This is the real size of the data buffer, not the actual size of the object.

procedure

(git_odb_object_type object)  git_otype

  object : odb_object?
Return the type of an ODB object

procedure

(git_odb_open objects_dir)  odb?

  objects_dir : string?
Create a new object database and automatically add the two default backends:

- git_odb_backend_loose: read and write loose object files from disk, assuming ‘objects_dir‘ as the Objects folder

- git_odb_backend_pack: read objects from packfiles, assuming ‘objects_dir‘ as the Objects folder which contains a ’pack/’ folder with the corresponding data

procedure

(git_odb_open_rstream db oid)  odb_stream?

  db : odb?
  oid : oid?
Open a stream to read an object from the ODB

Note that most backends do not support streaming reads because they store their objects as compressed/delta’ed blobs.

It’s recommended to use git_odb_read instead, which is assured to work on all backends.

The returned stream will be of type GIT_STREAM_RDONLY and will have the following methods:

- stream->read: read ‘n‘ bytes from the stream - stream->free: free the stream The stream must always be free’d or will leak memory.

procedure

(git_odb_open_wstream db size type)  odb_stream?

  db : odb?
  size : git_off_t
  type : git_otype
Open a stream to write an object into the ODB

The type and final length of the object must be specified when opening the stream.

The returned stream will be of type GIT_STREAM_WRONLY, and it won’t be effective until git_odb_stream_finalize_write is called and returns without an error

The stream must always be freed when done with git_odb_stream_free or will leak memory.

procedure

(git_odb_read db id)  odb_object?

  db : odb?
  id : oid?
Read an object from the database.

This method queries all available ODB backends trying to read the given OID.

The returned object is reference counted and internally cached, so it should be closed by the user once it’s no longer in use.

procedure

(git_odb_read_header len_out type_out db id)  integer?

  len_out : (cpoiner size)
  type_out : (cpointer git_otype)
  db : odb?
  id : oid?
Read the header of an object from the database, without reading its full contents.

The header includes the length and the type of an object.

Note that most backends do not support reading only the header of an object, so the whole object will be read and then the header will be returned.

procedure

(git_odb_read_prefix db short_id len)  odb_object?

  db : odb?
  short_id : oid?
  len : integer?
Read an object from the database, given a prefix of its identifier.

This method queries all available ODB backends trying to match the ’len’ first hexadecimal characters of the ’short_id’. The remaining (GIT_OID_HEXSZ-len)*4 bits of ’short_id’ must be 0s. ’len’ must be at least GIT_OID_MINPREFIXLEN, and the prefix must be long enough to identify a unique object in all the backends; the method will fail otherwise.

The returned object is reference counted and internally cached, so it should be closed by the user once it’s no longer in use.

procedure

(git_odb_refresh db)  integer?

  db : odb?
Refresh the object database to load newly added files.

If the object databases have changed on disk while the library is running, this function will force a reload of the underlying indexes.

Use this function when you’re confident that an external application has tampered with the ODB.

NOTE that it is not necessary to call this function at all. The library will automatically attempt to refresh the ODB when a lookup fails, to see if the looked up object exists on disk but hasn’t been loaded yet.

procedure

(git_odb_stream_finalize_write out stream)  integer?

  out : oid?
  stream : odb_stream?
Finish writing to an odb stream

The object will take its final name and will be available to the odb.

This method will fail if the total number of received bytes differs from the size declared with git_odb_open_wstream()

procedure

(git_odb_stream_free stream)  void?

  stream : odb_stream?
Free an odb stream

procedure

(git_odb_stream_read stream buffer len)  integer?

  stream : odb_stream?
  buffer : bytes?
  len : integer?
Read from an odb stream

Most backends don’t implement streaming reads

procedure

(git_odb_stream_write stream buffer len)  integer?

  stream : odb_stream?
  buffer : string?
  len : size_t
Write to an odb stream

This method will fail if the total number of received bytes exceeds the size declared with git_odb_open_wstream()

procedure

(git_odb_write out odb data len type)  integer?

  out : oid?
  odb : odb?
  data : bytes?
  len : integer?
  type : git_otype
Write an object directly into the ODB

This method writes a full object straight into the ODB. For most cases, it is preferred to write objects through a write stream, which is both faster and less memory intensive, specially for big objects.

This method is provided for compatibility with custom backends which are not able to support streaming writes

procedure

(git_odb_write_pack db    
  progress_cb    
  progress_payload)  odb_writepack?
  db : odb?
  progress_cb : git_transfer_progress_cb
  progress_payload : bytes?
Open a stream for writing a pack file to the ODB.

If the ODB layer understands pack files, then the given packfile will likely be streamed directly to disk (and a corresponding index created). If the ODB layer does not understand pack files, the objects will be stored in whatever format the ODB layer uses.