summaryrefslogtreecommitdiff
path: root/src/odb.h
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-09-10 12:24:05 -0700
committerRussell Belfer <rb@github.com>2012-09-10 12:24:05 -0700
commitc6ac28fdc57d04a9a5eba129cfd267c7adde43b3 (patch)
tree180cf940b152faebf95dc415ce4ff1dd3ec8d8bd /src/odb.h
parente597b1890ebd43e398d84b7bf4ca366365b24d27 (diff)
downloadlibgit2-c6ac28fdc57d04a9a5eba129cfd267c7adde43b3.tar.gz
Reorg internal odb read header and object lookup
Often `git_odb_read_header` will "fail" and have to read the entire object into memory instead of just the header. When this happens, the object is loaded and then disposed of immediately, which makes it difficult to efficiently use the header information to decide if the object should be loaded (since attempting to do so will often result in loading the object twice). This commit takes the existing code and reorganizes it to have two new functions: - `git_odb__read_header_or_object` which acts just like the old read header function except that it returns the object, too, if it was forced to load the whole thing. It then becomes the callers responsibility to free the `git_odb_object`. - `git_object__from_odb_object` which was extracted from the old `git_object_lookup` and creates a subclass of `git_object` from an existing `git_odb_object` (separating the ODB lookup from the `git_object` creation). This allows you to use the first header reading function efficiently without instantiating the `git_odb_object` twice. There is no net change to the behavior of any of the existing functions, but this allows internal code to tap into the ODB lookup and object creation to be more efficient.
Diffstat (limited to 'src/odb.h')
-rw-r--r--src/odb.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/odb.h b/src/odb.h
index 696e12943..e9e33dde8 100644
--- a/src/odb.h
+++ b/src/odb.h
@@ -84,4 +84,12 @@ int git_odb__error_notfound(const char *message, const git_oid *oid);
*/
int git_odb__error_ambiguous(const char *message);
+/*
+ * Attempt to read object header or just return whole object if it could
+ * not be read.
+ */
+int git_odb__read_header_or_object(
+ git_odb_object **out, size_t *len_p, git_otype *type_p,
+ git_odb *db, const git_oid *id);
+
#endif