]> git.proxmox.com Git - libgit2.git/blobdiff - include/git2/odb.h
New upstream version 1.1.0+dfsg.1
[libgit2.git] / include / git2 / odb.h
index 4f1e18bc1a58e74c749317c10a86132832bfab81..c4bfa5290b0e9a7e1ec779ab6c332d44a97ed0b3 100644 (file)
@@ -10,6 +10,8 @@
 #include "common.h"
 #include "types.h"
 #include "oid.h"
+#include "oidarray.h"
+#include "indexer.h"
 
 /**
  * @file git2/odb.h
@@ -23,7 +25,7 @@ GIT_BEGIN_DECL
 /**
  * Function type for callbacks from git_odb_foreach.
  */
-typedef int (*git_odb_foreach_cb)(const git_oid *id, void *payload);
+typedef int GIT_CALLBACK(git_odb_foreach_cb)(const git_oid *id, void *payload);
 
 /**
  * Create a new object database with no backends.
@@ -145,7 +147,7 @@ GIT_EXTERN(int) git_odb_read_prefix(git_odb_object **out, git_odb *db, const git
  * - 0 if the object was read;
  * - GIT_ENOTFOUND if the object is not in the database.
  */
-GIT_EXTERN(int) git_odb_read_header(size_t *len_out, git_otype *type_out, git_odb *db, const git_oid *id);
+GIT_EXTERN(int) git_odb_read_header(size_t *len_out, git_object_t *type_out, git_odb *db, const git_oid *id);
 
 /**
  * Determine if the given object can be found in the object database.
@@ -159,7 +161,8 @@ GIT_EXTERN(int) git_odb_read_header(size_t *len_out, git_otype *type_out, git_od
 GIT_EXTERN(int) git_odb_exists(git_odb *db, const git_oid *id);
 
 /**
- * Determine if objects can be found in the object database from a short OID.
+ * Determine if an object can be found in the object database by an
+ * abbreviated object ID.
  *
  * @param out The full OID of the found object if just one is found.
  * @param db The database to be searched for the given object.
@@ -171,6 +174,50 @@ GIT_EXTERN(int) git_odb_exists(git_odb *db, const git_oid *id);
 GIT_EXTERN(int) git_odb_exists_prefix(
        git_oid *out, git_odb *db, const git_oid *short_id, size_t len);
 
+/**
+ * The information about object IDs to query in `git_odb_expand_ids`,
+ * which will be populated upon return.
+ */
+typedef struct git_odb_expand_id {
+       /** The object ID to expand */
+       git_oid id;
+
+       /**
+        * The length of the object ID (in nibbles, or packets of 4 bits; the
+        * number of hex characters)
+        * */
+       unsigned short length;
+
+       /**
+        * The (optional) type of the object to search for; leave as `0` or set
+        * to `GIT_OBJECT_ANY` to query for any object matching the ID.
+        */
+       git_object_t type;
+} git_odb_expand_id;
+
+/**
+ * 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.)
+ *
+ * @param db The database to be searched for the given objects.
+ * @param ids An array of short object IDs to search for
+ * @param count The length of the `ids` array
+ * @return 0 on success or an error code on failure
+ */
+GIT_EXTERN(int) git_odb_expand_ids(
+       git_odb *db,
+       git_odb_expand_id *ids,
+       size_t count);
+
 /**
  * Refresh the object database to load newly added files.
  *
@@ -224,7 +271,7 @@ GIT_EXTERN(int) git_odb_foreach(git_odb *db, git_odb_foreach_cb cb, void *payloa
  * @param type type of the data to store
  * @return 0 or an error code
  */
-GIT_EXTERN(int) git_odb_write(git_oid *out, git_odb *odb, const void *data, size_t len, git_otype type);
+GIT_EXTERN(int) git_odb_write(git_oid *out, git_odb *odb, const void *data, size_t len, git_object_t type);
 
 /**
  * Open a stream to write an object into the ODB
@@ -247,7 +294,7 @@ GIT_EXTERN(int) git_odb_write(git_oid *out, git_odb *odb, const void *data, size
  * @param type type of the object that will be written
  * @return 0 if the stream was created; error code otherwise
  */
-GIT_EXTERN(int) git_odb_open_wstream(git_odb_stream **out, git_odb *db, git_off_t size, git_otype type);
+GIT_EXTERN(int) git_odb_open_wstream(git_odb_stream **out, git_odb *db, git_object_size_t size, git_object_t type);
 
 /**
  * Write to an odb stream
@@ -311,11 +358,18 @@ GIT_EXTERN(void) git_odb_stream_free(git_odb_stream *stream);
  * @see git_odb_stream
  *
  * @param out pointer where to store the stream
+ * @param len pointer where to store the length of the object
+ * @param type pointer where to store the type of the object
  * @param db object database where the stream will read from
  * @param oid oid of the object the stream will read from
  * @return 0 if the stream was created; error code otherwise
  */
-GIT_EXTERN(int) git_odb_open_rstream(git_odb_stream **out, git_odb *db, const git_oid *oid);
+GIT_EXTERN(int) git_odb_open_rstream(
+       git_odb_stream **out,
+       size_t *len,
+       git_object_t *type,
+       git_odb *db,
+       const git_oid *oid);
 
 /**
  * Open a stream for writing a pack file to the ODB.
@@ -338,7 +392,7 @@ GIT_EXTERN(int) git_odb_open_rstream(git_odb_stream **out, git_odb *db, const gi
 GIT_EXTERN(int) git_odb_write_pack(
        git_odb_writepack **out,
        git_odb *db,
-       git_transfer_progress_cb progress_cb,
+       git_indexer_progress_cb progress_cb,
        void *progress_payload);
 
 /**
@@ -353,7 +407,7 @@ GIT_EXTERN(int) git_odb_write_pack(
  * @param type of the data to hash
  * @return 0 or an error code
  */
-GIT_EXTERN(int) git_odb_hash(git_oid *out, const void *data, size_t len, git_otype type);
+GIT_EXTERN(int) git_odb_hash(git_oid *out, const void *data, size_t len, git_object_t type);
 
 /**
  * Read a file from disk and fill a git_oid with the object id
@@ -368,7 +422,7 @@ GIT_EXTERN(int) git_odb_hash(git_oid *out, const void *data, size_t len, git_oty
  * @param type the type of the object that will be hashed
  * @return 0 or an error code
  */
-GIT_EXTERN(int) git_odb_hashfile(git_oid *out, const char *path, git_otype type);
+GIT_EXTERN(int) git_odb_hashfile(git_oid *out, const char *path, git_object_t type);
 
 /**
  * Create a copy of an odb_object
@@ -434,7 +488,7 @@ GIT_EXTERN(size_t) git_odb_object_size(git_odb_object *object);
  * @param object the object
  * @return the type
  */
-GIT_EXTERN(git_otype) git_odb_object_type(git_odb_object *object);
+GIT_EXTERN(git_object_t) git_odb_object_type(git_odb_object *object);
 
 /**
  * Add a custom backend to an existing Object DB
@@ -442,7 +496,7 @@ GIT_EXTERN(git_otype) git_odb_object_type(git_odb_object *object);
  * The backends are checked in relative ordering, based on the
  * value of the `priority` parameter.
  *
- * Read <odb_backends.h> for more information.
+ * Read <sys/odb_backend.h> for more information.
  *
  * @param odb database to add the backend to
  * @param backend pointer to a git_odb_backend instance
@@ -463,7 +517,7 @@ GIT_EXTERN(int) git_odb_add_backend(git_odb *odb, git_odb_backend *backend, int
  *
  * Writing is disabled on alternate backends.
  *
- * Read <odb_backends.h> for more information.
+ * Read <sys/odb_backend.h> for more information.
  *
  * @param odb database to add the backend to
  * @param backend pointer to a git_odb_backend instance