summaryrefslogtreecommitdiff
path: root/src/object.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/object.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/object.h')
-rw-r--r--src/object.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/object.h b/src/object.h
new file mode 100644
index 000000000..bc12aad04
--- /dev/null
+++ b/src/object.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_object_h__
+#define INCLUDE_object_h__
+
+/** Base git object for inheritance */
+struct git_object {
+ git_cached_obj cached;
+ git_repository *repo;
+ git_otype type;
+};
+
+/* fully free the object; internal method, DO NOT EXPORT */
+void git_object__free(void *object);
+
+GIT_INLINE(int) git_object__dup(git_object **dest, git_object *source)
+{
+ git_cached_obj_incref(source);
+ *dest = source;
+ return 0;
+}
+
+int git_object__from_odb_object(
+ git_object **object_out,
+ git_repository *repo,
+ git_odb_object *odb_obj,
+ git_otype type);
+
+int git_object__resolve_to_type(git_object **obj, git_otype type);
+
+int git_oid__parse(git_oid *oid, const char **buffer_out, const char *buffer_end, const char *header);
+
+void git_oid__writebuf(git_buf *buf, const char *header, const git_oid *oid);
+
+#endif