summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Ericsson <ae@op5.se>2008-11-18 01:18:52 +0100
committerShawn O. Pearce <spearce@spearce.org>2008-11-18 10:32:53 -0800
commitd4043ee9d97031e94f205110996d2381dd26c540 (patch)
tree41c1bdce587d5c8b8ca03a5a8691ea3f09f16316 /src
parent1b9e92c73bd223661fe63dffa0c9138da4e1ea80 (diff)
downloadlibgit2-d4043ee9d97031e94f205110996d2381dd26c540.tar.gz
Move public headers to src/git
It's arguably smoother to keep them close to the source, as that's where one's working when modifying them. More importantly, though, is the ability to use private headers in the src/ dir that simply include "git/$samename.h" to get to the public API at the same time. Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'src')
-rw-r--r--src/git/commit.h72
-rw-r--r--src/git/common.h92
-rw-r--r--src/git/config.h.in31
-rw-r--r--src/git/odb.h139
-rw-r--r--src/git/oid.h90
-rw-r--r--src/git/os/unix.h123
-rw-r--r--src/git/revwalk.h90
-rw-r--r--src/git/zlib.h60
8 files changed, 697 insertions, 0 deletions
diff --git a/src/git/commit.h b/src/git/commit.h
new file mode 100644
index 000000000..8cb3e7d4c
--- /dev/null
+++ b/src/git/commit.h
@@ -0,0 +1,72 @@
+/*
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2,
+ * as published by the Free Software Foundation.
+ *
+ * In addition to the permissions in the GNU General Public License,
+ * the authors give you unlimited permission to link the compiled
+ * version of this file into combinations with other programs,
+ * and to distribute those combinations without any restriction
+ * coming from the use of this file. (The General Public License
+ * restrictions do apply in other respects; for example, they cover
+ * modification of the file, and distribution when not linked into
+ * a combined executable.)
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDE_git_commit_h__
+#define INCLUDE_git_commit_h__
+
+#include "common.h"
+#include "oid.h"
+
+/**
+ * @file git/commit.h
+ * @brief Git commit parsing, formatting routines
+ * @defgroup git_commit Git commit parsing, formatting routines
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/** Parsed representation of a commit object. */
+typedef struct git_commit git_commit;
+#ifdef GIT__PRIVATE
+struct git_commit {
+ git_oid id;
+ time_t commit_time;
+ unsigned parsed:1,
+ flags:26;
+};
+#endif
+
+/**
+ * Parse (or lookup) a commit from a revision pool.
+ * @param pool the pool to use when parsing/caching the commit.
+ * @param id identity of the commit to locate. If the object is
+ * an annotated tag it will be peeled back to the commit.
+ * @return the commit; NULL if the commit does not exist in the
+ * pool's git_odb, or if the commit is present but is
+ * too malformed to be parsed successfully.
+ */
+GIT_EXTERN(git_commit*) git_commit_parse(git_revpool *pool, const git_oid *id);
+
+/**
+ * Get the id of a commit.
+ * @param commit a previously parsed commit.
+ * @return object identity for the commit.
+ */
+GIT_EXTERN(const git_oid*) git_commit_id(git_commit *commit);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/src/git/common.h b/src/git/common.h
new file mode 100644
index 000000000..47ee6e207
--- /dev/null
+++ b/src/git/common.h
@@ -0,0 +1,92 @@
+/*
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2,
+ * as published by the Free Software Foundation.
+ *
+ * In addition to the permissions in the GNU General Public License,
+ * the authors give you unlimited permission to link the compiled
+ * version of this file into combinations with other programs,
+ * and to distribute those combinations without any restriction
+ * coming from the use of this file. (The General Public License
+ * restrictions do apply in other respects; for example, they cover
+ * modification of the file, and distribution when not linked into
+ * a combined executable.)
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDE_git_common_h__
+#define INCLUDE_git_common_h__
+
+#ifdef __cplusplus
+# define GIT_BEGIN_DECL extern "C" {
+# define GIT_END_DECL }
+#else
+ /** Start declarations in C mode */
+# define GIT_BEGIN_DECL /* empty */
+ /** End declarations in C mode */
+# define GIT_END_DECL /* empty */
+#endif
+
+/** Declare a public function exported for application use. */
+#ifdef __GNUC__
+# define GIT_EXTERN(type) extern \
+ __attribute__((visibility("default"))) \
+ type
+#else
+# define GIT_EXTERN(type) extern type
+#endif
+
+/** Declare a function as always inlined. */
+# define GIT_INLINE(type) static inline type
+
+/** Declare a function's takes printf style arguments. */
+#ifdef __GNUC__
+# define GIT_FORMAT_PRINTF(a,b) __attribute__((format (printf, a, b)))
+#else
+# define GIT_FORMAT_PRINTF(a,b) /* empty */
+#endif
+
+/**
+ * @file git/common.h
+ * @brief Git common platform definitions
+ * @defgroup git_common Git common platform definitions
+ * @ingroup Git
+ * @{
+ */
+
+/** Operation completed successfully. */
+#define GIT_SUCCESS 0
+
+/**
+ * Operation failed, with unspecified reason.
+ * This value also serves as the base error code; all other
+ * error codes are subtracted from it such that all errors
+ * are < 0, in typical POSIX C tradition.
+ */
+#define GIT_ERROR -1
+
+/** Input was not a properly formatted Git object id. */
+#define GIT_ENOTOID (GIT_ERROR - 1)
+
+/** Input does not exist in the scope searched. */
+#define GIT_ENOTFOUND (GIT_ERROR - 2)
+
+#include "git/config.h"
+
+GIT_BEGIN_DECL
+
+/** A revision traversal pool. */
+typedef struct git_revpool git_revpool;
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/src/git/config.h.in b/src/git/config.h.in
new file mode 100644
index 000000000..44b6a517f
--- /dev/null
+++ b/src/git/config.h.in
@@ -0,0 +1,31 @@
+/*
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2,
+ * as published by the Free Software Foundation.
+ *
+ * In addition to the permissions in the GNU General Public License,
+ * the authors give you unlimited permission to link the compiled
+ * version of this file into combinations with other programs,
+ * and to distribute those combinations without any restriction
+ * coming from the use of this file. (The General Public License
+ * restrictions do apply in other respects; for example, they cover
+ * modification of the file, and distribution when not linked into
+ * a combined executable.)
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDE_git_config_h__
+#define INCLUDE_git_config_h__
+
+#include "git/os/@@OS@@.h"
+
+#endif
diff --git a/src/git/odb.h b/src/git/odb.h
new file mode 100644
index 000000000..6a840ebc2
--- /dev/null
+++ b/src/git/odb.h
@@ -0,0 +1,139 @@
+/*
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2,
+ * as published by the Free Software Foundation.
+ *
+ * In addition to the permissions in the GNU General Public License,
+ * the authors give you unlimited permission to link the compiled
+ * version of this file into combinations with other programs,
+ * and to distribute those combinations without any restriction
+ * coming from the use of this file. (The General Public License
+ * restrictions do apply in other respects; for example, they cover
+ * modification of the file, and distribution when not linked into
+ * a combined executable.)
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDE_git_odb_h__
+#define INCLUDE_git_odb_h__
+
+#include "common.h"
+#include "oid.h"
+
+/**
+ * @file git/odb.h
+ * @brief Git object database routines
+ * @defgroup git_odb Git object database routines
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/** An open object database handle. */
+typedef struct git_odb git_odb;
+
+/**
+ * Open an object database for read/write access.
+ * @param out location to store the database pointer, if opened.
+ * Set to NULL if the open failed.
+ * @param objects_dir path of the database's "objects" directory.
+ * @return GIT_SUCCESS if the database opened; otherwise an error
+ * code describing why the open was not possible.
+ */
+GIT_EXTERN(int) git_odb_open(git_odb **out, const char *objects_dir);
+
+/**
+ * Close an open object database.
+ * @param db database pointer to close. If NULL no action is taken.
+ */
+GIT_EXTERN(void) git_odb_close(git_odb *db);
+
+/** Basic type (loose or packed) of any Git object. */
+typedef enum {
+ GIT_OBJ_BAD = -1, /**< Object is invalid. */
+ GIT_OBJ__EXT1 = 0, /**< Reserved for future use. */
+ GIT_OBJ_COMMIT = 1, /**< A commit object. */
+ GIT_OBJ_TREE = 2, /**< A tree (directory listing) object. */
+ GIT_OBJ_BLOB = 3, /**< A file revision object. */
+ GIT_OBJ_TAG = 4, /**< An annotated tag object. */
+ GIT_OBJ__EXT2 = 5, /**< Reserved for future use. */
+ GIT_OBJ_OFS_DELTA = 6, /**< A delta, base is given by an offset. */
+ GIT_OBJ_REF_DELTA = 7, /**< A delta, base is given by object id. */
+} git_otype;
+
+/** A small object read from the database. */
+typedef struct {
+ void *data; /**< Raw, decompressed object data. */
+ size_t len; /**< Total number of bytes in data. */
+ git_otype type; /**< Type of this object. */
+} git_obj;
+
+/**
+ * Read a small object from the database.
+ *
+ * If GIT_ENOTFOUND then out->data is set to NULL.
+ *
+ * @param out object descriptor to populate upon reading.
+ * @param db database to search for the object in.
+ * @param id identity of the object to read.
+ * @return
+ * - GIT_SUCCESS if the object was read;
+ * - GIT_ENOTFOUND if the object is not in the database.
+ */
+GIT_EXTERN(int) git_odb_read(git_obj *out, git_odb *db, const git_oid *id);
+
+/**
+ * Read a small object from the database using only pack files.
+ *
+ * If GIT_ENOTFOUND then out->data is set to NULL.
+ *
+ * @param out object descriptor to populate upon reading.
+ * @param db database to search for the object in.
+ * @param id identity of the object to read.
+ * @return
+ * - GIT_SUCCESS if the object was read.
+ * - GIT_ENOTFOUND if the object is not in the database.
+ */
+GIT_EXTERN(int) git_odb__read_packed(git_obj *out, git_odb *db, const git_oid *id);
+
+/**
+ * Read a small object from the database using only loose object files.
+ *
+ * If GIT_ENOTFOUND then out->data is set to NULL.
+ *
+ * @param out object descriptor to populate upon reading.
+ * @param db database to search for the object in.
+ * @param id identity of the object to read.
+ * @return
+ * - GIT_SUCCESS if the object was read.
+ * - GIT_ENOTFOUND if the object is not in the database.
+ */
+GIT_EXTERN(int) git_odb__read_loose(git_obj *out, git_odb *db, const git_oid *id);
+
+/**
+ * Release all memory used by the sobj structure.
+ *
+ * As a result of this call, obj->data will be set to NULL.
+ *
+ * If obj->data is already NULL, nothing happens.
+ *
+ * @param obj object descriptor to free.
+ */
+GIT_INLINE(void) git_obj_close(git_obj *obj)
+{
+ free(obj->data);
+ obj->data = NULL;
+}
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/src/git/oid.h b/src/git/oid.h
new file mode 100644
index 000000000..dd95fb53d
--- /dev/null
+++ b/src/git/oid.h
@@ -0,0 +1,90 @@
+/*
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2,
+ * as published by the Free Software Foundation.
+ *
+ * In addition to the permissions in the GNU General Public License,
+ * the authors give you unlimited permission to link the compiled
+ * version of this file into combinations with other programs,
+ * and to distribute those combinations without any restriction
+ * coming from the use of this file. (The General Public License
+ * restrictions do apply in other respects; for example, they cover
+ * modification of the file, and distribution when not linked into
+ * a combined executable.)
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDE_git_oid_h__
+#define INCLUDE_git_oid_h__
+
+#include "common.h"
+
+/**
+ * @file git/oid.h
+ * @brief Git object id routines
+ * @defgroup git_oid Git object id routines
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/** Unique identity of any object (commit, tree, blob, tag). */
+typedef struct
+{
+ /** raw binary formatted id */
+ unsigned char id[20];
+} git_oid;
+
+/**
+ * Parse a hex formatted object id into a git_oid.
+ * @param out oid structure the result is written into.
+ * @param str input hex string; must be pointing at the start of
+ * the hex sequence and have at least the number of bytes
+ * needed for an oid encoded in hex (40 bytes).
+ * @return GIT_SUCCESS if valid; GIT_ENOTOID on failure.
+ */
+GIT_EXTERN(int) git_oid_mkstr(git_oid *out, const char *str);
+
+/**
+ * Copy an already raw oid into a git_oid structure.
+ * @param out oid structure the result is written into.
+ * @param raw the raw input bytes to be copied.
+ */
+GIT_INLINE(void) git_oid_mkraw(git_oid *out, const unsigned char *raw)
+{
+ memcpy(out->id, raw, sizeof(out->id));
+}
+
+/**
+ * Copy an oid from one structure to another.
+ * @param out oid structure the result is written into.
+ * @param src oid structure to copy from.
+ */
+GIT_INLINE(void) git_oid_cpy(git_oid *out, const git_oid *src)
+{
+ memcpy(out->id, src->id, sizeof(out->id));
+}
+
+/**
+ * Compare two oid structures.
+ * @param a first oid structure.
+ * @param b second oid structure.
+ * @return <0, 0, >0 if a < b, a == b, a > b.
+ */
+GIT_INLINE(int) git_oid_cmp(const git_oid *a, const git_oid *b)
+{
+ return memcmp(a->id, b->id, sizeof(a->id));
+}
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/src/git/os/unix.h b/src/git/os/unix.h
new file mode 100644
index 000000000..475fe13a5
--- /dev/null
+++ b/src/git/os/unix.h
@@ -0,0 +1,123 @@
+/*
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2,
+ * as published by the Free Software Foundation.
+ *
+ * In addition to the permissions in the GNU General Public License,
+ * the authors give you unlimited permission to link the compiled
+ * version of this file into combinations with other programs,
+ * and to distribute those combinations without any restriction
+ * coming from the use of this file. (The General Public License
+ * restrictions do apply in other respects; for example, they cover
+ * modification of the file, and distribution when not linked into
+ * a combined executable.)
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDE_git_os_abstraction_h__
+#define INCLUDE_git_os_abstraction_h__
+
+/** Force 64 bit off_t size on POSIX. */
+#define _FILE_OFFSET_BITS 64
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <time.h>
+#include <stdlib.h>
+#include <string.h>
+
+/**
+ * @file git/os/unix.h
+ * @brief Portable operating system abstractions
+ * @defgroup git_os_abstraction Portable operating system abstractions
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/** Descriptor to an open file in the filesystem. */
+typedef int git_file;
+
+/**
+ * Open a file by path name.
+ *
+ * Valid flags are:
+ * - O_CREAT: Create the file if it does not yet exist.
+ * - O_RDONLY: Open the file for reading.
+ * - O_WRONLY: Open the file for writing.
+ * - O_RDWR: Open the file for both reading and writing.
+ *
+ * @param out descriptor storage to populate on success.
+ * @param path path name of the file to open.
+ * @param flags bitmask of access requested to the file.
+ * @return
+ * - On success, GIT_SUCCESS.
+ * - On error, <0.
+ */
+GIT_EXTERN(int) git_fopen(git_file *out, const char *path, int flags);
+
+/**
+ * Read from an open file descriptor at the current position.
+ *
+ * Exactly the requested number of bytes is read. If the stream
+ * ends early, an error is indicated, and the exact number of bytes
+ * transferred is unspecified.
+ *
+ * @param fd open descriptor.
+ * @param buf buffer to store the read data into.
+ * @param cnt number of bytes to transfer.
+ * @return
+ * - On success, GIT_SUCCESS.
+ * - On error, <0.
+ */
+GIT_EXTERN(int) git_fread(git_file fd, void *buf, size_t cnt);
+
+/**
+ * Write to an open file descriptor at the current position.
+ *
+ * Exactly the requested number of bytes is written. If the stream
+ * ends early, an error is indicated, and the exact number of bytes
+ * transferred is unspecified.
+ *
+ * @param fd open descriptor.
+ * @param buf buffer to write data from.
+ * @param cnt number of bytes to transfer.
+ * @return
+ * - On success, GIT_SUCCESS.
+ * - On error, <0.
+ */
+GIT_EXTERN(int) git_fwrite(git_file fd, void *buf, size_t cnt);
+
+/**
+ * Get the current size of an open file.
+ * @param fd open descriptor.
+ * @return
+ * - On success, >= 0, indicating the file size in bytes.
+ * - On error, <0.
+ */
+GIT_EXTERN(off_t) git_fsize(git_file fd);
+
+/**
+ * Close an open file descriptor.
+ * @param fd descriptor to close.
+ * @return
+ * - On success, GIT_SUCCESS.
+ * - On error, <0.
+ */
+#define git_fclose(fd) close(fd)
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/src/git/revwalk.h b/src/git/revwalk.h
new file mode 100644
index 000000000..5c0b005b6
--- /dev/null
+++ b/src/git/revwalk.h
@@ -0,0 +1,90 @@
+/*
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2,
+ * as published by the Free Software Foundation.
+ *
+ * In addition to the permissions in the GNU General Public License,
+ * the authors give you unlimited permission to link the compiled
+ * version of this file into combinations with other programs,
+ * and to distribute those combinations without any restriction
+ * coming from the use of this file. (The General Public License
+ * restrictions do apply in other respects; for example, they cover
+ * modification of the file, and distribution when not linked into
+ * a combined executable.)
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDE_git_revwalk_h__
+#define INCLUDE_git_revwalk_h__
+
+#include "common.h"
+#include "odb.h"
+#include "commit.h"
+
+/**
+ * @file git/revwalk.h
+ * @brief Git revision traversal routines
+ * @defgroup git_revwalk Git revision traversal routines
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+/**
+ * Allocate a new revision traversal pool.
+ *
+ * The configuration is copied during allocation. Changes
+ * to the configuration after allocation do not affect the pool
+ * returned by this function. Callers may safely free the
+ * passed configuration after the function completes.
+ *
+ * @param db the database objects are read from.
+ * @return the new traversal handle; NULL if memory is exhausted.
+ */
+GIT_EXTERN(git_revpool*) gitrp_alloc(git_odb *db);
+
+/**
+ * Reset the traversal machinary for reuse.
+ * @param pool traversal handle to reset.
+ */
+GIT_EXTERN(void) gitrp_reset(git_revpool *pool);
+
+/**
+ * Mark an object to start traversal from.
+ * @param pool the pool being used for the traversal.
+ * @param commit the commit the commit to start from.
+ */
+GIT_EXTERN(void) gitrp_push(git_revpool *pool, git_commit *commit);
+
+/**
+ * Mark a commit (and its ancestors) uninteresting for the output.
+ * @param pool the pool being used for the traversal.
+ * @param commit the commit the commit to start from.
+ */
+GIT_EXTERN(void) gitrp_hide(git_revpool *pool, git_commit *commit);
+
+/**
+ * Get the next commit from the revision traversal.
+ * @param pool the pool to pop the commit from.
+ * @return next commit; NULL if there is no more output.
+ */
+GIT_EXTERN(git_commit*) gitrp_next(git_revpool *pool);
+
+/**
+ * Free a revwalk previously allocated.
+ * @param pool traversal handle to close. If NULL nothing occurs.
+ */
+GIT_EXTERN(void) gitrp_free(git_revpool *pool);
+
+/** @} */
+GIT_END_DECL
+#endif
diff --git a/src/git/zlib.h b/src/git/zlib.h
new file mode 100644
index 000000000..7e44c57fb
--- /dev/null
+++ b/src/git/zlib.h
@@ -0,0 +1,60 @@
+/*
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2,
+ * as published by the Free Software Foundation.
+ *
+ * In addition to the permissions in the GNU General Public License,
+ * the authors give you unlimited permission to link the compiled
+ * version of this file into combinations with other programs,
+ * and to distribute those combinations without any restriction
+ * coming from the use of this file. (The General Public License
+ * restrictions do apply in other respects; for example, they cover
+ * modification of the file, and distribution when not linked into
+ * a combined executable.)
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; see the file COPYING. If not, write to
+ * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDE_git_zlib_h__
+#define INCLUDE_git_zlib_h__
+
+#include "common.h"
+#include <zlib.h>
+
+/**
+ * @file git/zlib.h
+ * @brief Git data compression routines
+ * @defgroup git_zlib Git data compression routines
+ * @ingroup Git
+ * @{
+ */
+GIT_BEGIN_DECL
+
+#if defined(NO_DEFLATE_BOUND) || ZLIB_VERNUM < 0x1200
+/**
+ * deflateBound returns an upper bound on the compressed size.
+ *
+ * This is a stub function used when zlib does not supply the
+ * deflateBound() implementation itself.
+ *
+ * @param stream the stream pointer.
+ * @param s total length of the source data (in bytes).
+ * @return maximum length of the compressed data.
+ */
+GIT_INLINE(size_t) deflateBound(z_streamp stream, size_t s)
+{
+ return (s + ((s + 7) >> 3) + ((s + 63) >> 6) + 11);
+}
+#endif
+
+/** @} */
+GIT_END_DECL
+#endif