Module ODB
Class "ODB".
Functions
ODB.hash (data, otype) | module function. |
ODB.hashfile (path, otype) | module function. |
ODB.new () | Create a new ODB object. |
ODB.open (object_dir) | Create a new ODB object. |
ODB:add_alternate (backend, priority) | object method. |
ODB:add_backend (backend, priority) | object method. |
ODB:exists (id) | object method. |
ODB:free () | Destroy this object (will be called by Garbage Collector). |
ODB:read (id) | object method. |
ODB:read_header (id) | object method. |
ODB:read_prefix (short_id, len) | object method. |
ODB:write (data, type) | object method. |
Functions
- ODB.hash (data, otype)
-
module function.
Calls git_odb_hash:
The resulting SHA-1 OID will the itentifier for the data buffer as if the data buffer it were to written to the ODB.
Parameters
-
data: data to hash. Must be of type
string
. -
otype: Must be of type
integer
.
Return values:
- OID or
nil
on error. - Error string.
-
data: data to hash. Must be of type
- ODB.hashfile (path, otype)
-
module function.
Calls git_odb_hashfile:
Parameters
-
path: file to read and determine object id for. Must be of type
string
. -
otype: Must be of type
integer
.
Return values:
- OID or
nil
on error. - Error string.
-
path: file to read and determine object id for. Must be of type
- ODB.new ()
-
Create a new ODB object.
Calls git_odb_new:
Before the ODB can be used for read/writing, a custom database backend must be manually added using `git_odb_add_backend()`
Return values:
- ODB or
nil
on error. - Error string.
- ODB or
- ODB.open (object_dir)
-
Create a new ODB object.
Calls git_odb_open:
- 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
Parameters
-
object_dir: Must be of type
string
.
Return values:
- ODB or
nil
on error. - Error string.
-
object_dir: Must be of type
- ODB:add_alternate (backend, priority)
-
object method.
Parameters
- backend: Must be of type ODBBackend.
-
priority: Must be of type
integer
.
Return values:
true
if no error.- Error string.
- ODB:add_backend (backend, priority)
-
object method.
Parameters
- backend: Must be of type ODBBackend.
-
priority: Must be of type
integer
.
Return values:
true
if no error.- Error string.
- ODB:exists (id)
-
object method.
Calls git_odb_exists:
@return - 1, if the object was found - 0, otherwise
Parameters
- id: the object to search for.. Must be of type OID.
Return values:
true
if no error.- Error string.
- ODB:free ()
-
Destroy this object (will be called by Garbage Collector).
Calls git_odb_free:
- ODB:read (id)
-
object method.
Calls git_odb_read:
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.
@return - 0 if the object was read; - GIT_ENOTFOUND if the object is not in the database.
Parameters
- id: identity of the object to read.. Must be of type OID.
Return values:
- OdbObject or
nil
on error. - Error string.
- ODB:read_header (id)
-
object method.
Calls git_odb_read_header:
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.
@return - 0 if the object was read; - GIT_ENOTFOUND if the object is not in the database.
Parameters
- id: identity of the object to read.. Must be of type OID.
Return values:
integer
ornil
on error.string
ornil
on error.- Error string.
- ODB:read_prefix (short_id, len)
-
object method.
Calls git_odb_read_prefix:
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.
Parameters
- short_id: a prefix of the id of the object to read.. Must be of type OID.
-
len: the length of the prefix. Must be of type
integer
.
Return values:
- OdbObject or
nil
on error. - Error string.
- ODB:write (data, type)
-
object method.
Calls git_odb_write:
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
Parameters
-
data: buffer with the data to storr. Must be of type
string
. -
type: type of the data to store. Must be of type
string
.
Return values:
- OID or
nil
on error. - Error string.
-
data: buffer with the data to storr. Must be of type