Functions
2.1 Annotated Commit
2.2 Blame
2.3 Blob
2.4 Branch
2.5 Buffer
2.6 Checkout
2.7 Cherrypick
2.8 Clone
2.9 Commit
2.10 Config
2.11 Credentials
2.12 Describe
2.13 Diff
2.14 Fetch
2.15 Filter
2.16 Errors
2.17 Graph
2.18 Ignore
2.19 Index
2.20 Indexer
2.21 Global
2.22 Merge
2.23 Message
2.24 Note
2.25 Object
2.26 Object Database
2.27 Oid
2.28 Oid Array
2.29 Packbuilder
2.30 Patch
2.31 Pathspec
2.32 Proxy
2.33 Push
2.34 Rebase
2.35 Refdb
2.36 Reference
2.37 Reflog
2.38 Refspec
2.39 Remote
2.40 Repository
2.41 Reset
2.42 Revert
2.43 Revparse
2.44 Revwalk
2.45 Signature
2.46 Stash
2.47 Status
2.48 Strarray
2.49 Submodule
2.50 Tag
2.51 Tree
2.52 Treebuilder
On this page:
git_  blob_  create_  frombuffer
git_  blob_  create_  fromdisk
git_  blob_  create_  fromstream
git_  blob_  create_  fromstream_  commit
git_  blob_  create_  fromworkdir
git_  blob_  dup
git_  blob_  filtered_  content
git_  blob_  free
git_  blob_  id
git_  blob_  is_  binary
git_  blob_  lookup
git_  blob_  lookup_  prefix
git_  blob_  owner
git_  blob_  rawcontent
git_  blob_  rawsize
7.7

2.3 Blob

 (require libgit2/include/blob) package: libgit2

procedure

(git_blob_create_frombuffer id    
  repo    
  buffer    
  len)  integer?
  id : oid?
  repo : repository?
  buffer : (cpointer void)
  len : integer?
Write an in-memory buffer to the ODB as a blob

procedure

(git_blob_create_fromdisk id repo path)  integer?

  id : oid?
  repo : repository?
  path : string?
Read a file from the filesystem and write its content to the Object Database as a loose blob

procedure

(git_blob_create_fromstream repo hintpath)  writestream?

  repo : repository?
  hintpath : string?
Create a stream to write a new blob into the object db

This function may need to buffer the data on disk and will in general not be the right choice if you know the size of the data to write. If you have data in memory, use git_blob_create_frombuffer(). If you do not, but know the size of the contents (and don’t want/need to perform filtering), use git_odb_open_wstream().

Don’t close this stream yourself but pass it to git_blob_create_fromstream_commit() to commit the write to the object db and get the object id.

If the hintpath parameter is filled, it will be used to determine what git filters should be applied to the object before it is written to the object database.

procedure

(git_blob_create_fromstream_commit out    
  stream)  integer?
  out : oid?
  stream : writestream?
Close the stream and write the blob to the object db

The stream will be closed and freed.

procedure

(git_blob_create_fromworkdir id    
  repo    
  relative_path)  integer?
  id : oid?
  repo : repository?
  relative_path : string?
Read a file from the working folder of a repository and write it to the Object Database as a loose blob

procedure

(git_blob_dup source)  blob?

  source : blob?
Create an in-memory copy of a blob. The copy must be explicitly free’d or it will leak.

procedure

(git_blob_filtered_content out    
  blob    
  as_path    
  check_for_binary_data)  integer?
  out : buf?
  blob : blob?
  as_path : string?
  check_for_binary_data : boolean?
Get a buffer with the filtered content of a blob.

This applies filters as if the blob was being checked out to the working directory under the specified filename. This may apply CRLF filtering or other types of changes depending on the file attributes set for the blob and the content detected in it.

The output is written into a git_buf which the caller must free when done (via git_buf_free).

If no filters need to be applied, then the out buffer will just be populated with a pointer to the raw content of the blob. In that case, be careful to not free the blob until done with the buffer or copy it into memory you own.

procedure

(git_blob_free blob)  void?

  blob : blob?
Close an open blob

This is a wrapper around git_object_free()

IMPORTANT: It is necessary to call this method when you stop using a blob. Failure to do so will cause a memory leak.

procedure

(git_blob_id blob)  oid?

  blob : blob?
Get the id of a blob.

procedure

(git_blob_is_binary blob)  boolean?

  blob : blob?
Determine if the blob content is most certainly binary or not.

The heuristic used to guess if a file is binary is taken from core git: Searching for NUL bytes and looking for a reasonable ratio of printable to non-printable characters among the first 8000 bytes.

procedure

(git_blob_lookup repo id)  blob?

  repo : repository?
  id : oid?
Lookup a blob object from a repository.

procedure

(git_blob_lookup_prefix repo id len)  blob?

  repo : repository?
  id : oid?
  len : size_t
Lookup a blob object from a repository, given a prefix of its identifier (short id).

procedure

(git_blob_owner blob)  repository?

  blob : blob?
Get the repository that contains the blob.

procedure

(git_blob_rawcontent blob)  bytes?

  blob : blob?
Get a read-only buffer with the raw content of a blob.

A pointer to the raw content of a blob is returned; this pointer is owned internally by the object and shall not be free’d. The pointer may be invalidated at a later time.

procedure

(git_blob_rawsize blob)  git_off_t?

  blob : blob?
Get the size in bytes of the contents of a blob