diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/git2.h | 1 | ||||
-rw-r--r-- | include/git2/common.h | 5 | ||||
-rw-r--r-- | include/git2/deprecated.h | 6 | ||||
-rw-r--r-- | include/git2/diff.h | 2 | ||||
-rw-r--r-- | include/git2/odb.h | 65 | ||||
-rw-r--r-- | include/git2/odb_backend.h | 56 | ||||
-rw-r--r-- | include/git2/oid.h | 130 | ||||
-rw-r--r-- | include/git2/sys/odb_backend.h | 2 | ||||
-rw-r--r-- | include/git2/version.h | 8 |
9 files changed, 238 insertions, 37 deletions
diff --git a/include/git2.h b/include/git2.h index 2961cc3e5..3457e5f04 100644 --- a/include/git2.h +++ b/include/git2.h @@ -28,6 +28,7 @@ #include "git2/diff.h" #include "git2/email.h" #include "git2/errors.h" +#include "git2/experimental.h" #include "git2/filter.h" #include "git2/global.h" #include "git2/graph.h" diff --git a/include/git2/common.h b/include/git2/common.h index 4e47488d7..defa24a6a 100644 --- a/include/git2/common.h +++ b/include/git2/common.h @@ -106,11 +106,6 @@ GIT_BEGIN_DECL #define GIT_PATH_MAX 4096 /** - * The string representation of the null object ID. - */ -#define GIT_OID_HEX_ZERO "0000000000000000000000000000000000000000" - -/** * Return the version of the libgit2 library * being currently used. * diff --git a/include/git2/deprecated.h b/include/git2/deprecated.h index c32abeeb7..52864ebe1 100644 --- a/include/git2/deprecated.h +++ b/include/git2/deprecated.h @@ -777,6 +777,12 @@ typedef git_trace_cb git_trace_callback; */ /**@{*/ +#ifndef GIT_EXPERIMENTAL_SHA256 +# define GIT_OID_RAWSZ GIT_OID_SHA1_SIZE +# define GIT_OID_HEXSZ GIT_OID_SHA1_HEXSIZE +# define GIT_OID_HEX_ZERO GIT_OID_SHA1_HEXZERO +#endif + GIT_EXTERN(int) git_oid_iszero(const git_oid *id); /**@}*/ diff --git a/include/git2/diff.h b/include/git2/diff.h index 3839f0033..850d215a6 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -274,7 +274,7 @@ typedef struct { /** * Represents the known length of the `id` field, when - * converted to a hex string. It is generally `GIT_OID_HEXSZ`, unless this + * converted to a hex string. It is generally `GIT_OID_SHA1_HEXSIZE`, unless this * delta was created from reading a patch file, in which case it may be * abbreviated to something reasonable, like 7 characters. */ diff --git a/include/git2/odb.h b/include/git2/odb.h index 0ffe3f328..c7d6a894c 100644 --- a/include/git2/odb.h +++ b/include/git2/odb.h @@ -38,6 +38,25 @@ typedef enum { */ typedef int GIT_CALLBACK(git_odb_foreach_cb)(const git_oid *id, void *payload); +/** Options for configuring a loose object backend. */ +typedef struct { + unsigned int version; /**< version for the struct */ + + /** + * Type of object IDs to use for this object database, or + * 0 for default (currently SHA1). + */ + git_oid_t oid_type; +} git_odb_options; + +/* The current version of the diff options structure */ +#define GIT_ODB_OPTIONS_VERSION 1 + +/* Stack initializer for odb options. Alternatively use + * `git_odb_options_init` programmatic initialization. + */ +#define GIT_ODB_OPTIONS_INIT { GIT_ODB_OPTIONS_VERSION } + /** * Create a new object database with no backends. * @@ -46,9 +65,14 @@ typedef int GIT_CALLBACK(git_odb_foreach_cb)(const git_oid *id, void *payload); * * @param out location to store the database pointer, if opened. * Set to NULL if the open failed. + * @param opts the options for this object database or NULL for defaults * @return 0 or an error code */ +#ifdef GIT_EXPERIMENTAL_SHA256 +GIT_EXTERN(int) git_odb_new(git_odb **out, const git_odb_options *opts); +#else GIT_EXTERN(int) git_odb_new(git_odb **out); +#endif /** * Create a new object database and automatically add @@ -64,9 +88,17 @@ GIT_EXTERN(int) git_odb_new(git_odb **out); * @param out location to store the database pointer, if opened. * Set to NULL if the open failed. * @param objects_dir path of the backends' "objects" directory. + * @param opts the options for this object database or NULL for defaults * @return 0 or an error code */ +#ifdef GIT_EXPERIMENTAL_SHA256 +GIT_EXTERN(int) git_odb_open( + git_odb **out, + const char *objects_dir, + const git_odb_options *opts); +#else GIT_EXTERN(int) git_odb_open(git_odb **out, const char *objects_dir); +#endif /** * Add an on-disk alternate to an existing Object DB. @@ -117,7 +149,7 @@ GIT_EXTERN(int) git_odb_read(git_odb_object **out, git_odb *db, const git_oid *i * 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 + * The remaining (GIT_OID_SHA1_HEXSIZE-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 @@ -218,7 +250,7 @@ typedef struct git_odb_expand_id { * * 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 + * the full object ID, object ID length (`GIT_OID_SHA1_HEXSIZE`) and type will be * written back to the array. For IDs that are not found (or are ambiguous), * the array entry will be zeroed. * @@ -435,18 +467,28 @@ GIT_EXTERN(int) git_odb_write_multi_pack_index( git_odb *db); /** - * Determine the object-ID (sha1 hash) of a data buffer + * Determine the object-ID (sha1 or sha256 hash) of a data buffer * - * The resulting SHA-1 OID will be the identifier for the data - * buffer as if the data buffer it were to written to the ODB. + * The resulting OID will be the identifier for the data buffer as if + * the data buffer it were to written to the ODB. * * @param out the resulting object-ID. * @param data data to hash * @param len size of the data - * @param type of the data to hash + * @param object_type of the data to hash + * @param oid_type the oid type to hash to * @return 0 or an error code */ +#ifdef GIT_EXPERIMENTAL_SHA256 +GIT_EXTERN(int) git_odb_hash( + git_oid *out, + const void *data, + size_t len, + git_object_t object_type, + git_oid_t oid_type); +#else GIT_EXTERN(int) git_odb_hash(git_oid *out, const void *data, size_t len, git_object_t type); +#endif /** * Read a file from disk and fill a git_oid with the object id @@ -458,10 +500,19 @@ GIT_EXTERN(int) git_odb_hash(git_oid *out, const void *data, size_t len, git_obj * * @param out oid structure the result is written into. * @param path file to read and determine object id for - * @param type the type of the object that will be hashed + * @param object_type of the data to hash + * @param oid_type the oid type to hash to * @return 0 or an error code */ +#ifdef GIT_EXPERIMENTAL_SHA256 +GIT_EXTERN(int) git_odb_hashfile( + git_oid *out, + const char *path, + git_object_t object_type, + git_oid_t oid_type); +#else GIT_EXTERN(int) git_odb_hashfile(git_oid *out, const char *path, git_object_t type); +#endif /** * Create a copy of an odb_object diff --git a/include/git2/odb_backend.h b/include/git2/odb_backend.h index 5ad777b17..a31d1b782 100644 --- a/include/git2/odb_backend.h +++ b/include/git2/odb_backend.h @@ -34,18 +34,63 @@ GIT_BEGIN_DECL */ GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **out, const char *objects_dir); +typedef enum { + GIT_ODB_BACKEND_LOOSE_FSYNC = (1 << 0) +} git_odb_backend_loose_flag_t; + +/** Options for configuring a loose object backend. */ +typedef struct { + unsigned int version; /**< version for the struct */ + + /** A combination of the `git_odb_backend_loose_flag_t` types. */ + uint32_t flags; + + /** + * zlib compression level to use (0-9), where 1 is the fastest + * at the expense of larger files, and 9 produces the best + * compression at the expense of speed. 0 indicates that no + * compression should be performed. -1 is the default (currently + * optimizing for speed). + */ + int compression_level; + + /** Permissions to use creating a directory or 0 for defaults */ + unsigned int dir_mode; + + /** Permissions to use creating a file or 0 for defaults */ + unsigned int file_mode; + + /** + * Type of object IDs to use for this object database, or + * 0 for default (currently SHA1). + */ + git_oid_t oid_type; +} git_odb_backend_loose_options; + +/* The current version of the diff options structure */ +#define GIT_ODB_BACKEND_LOOSE_OPTIONS_VERSION 1 + +/* Stack initializer for odb loose backend options. Alternatively use + * `git_odb_backend_loose_options_init` programmatic initialization. + */ +#define GIT_ODB_BACKEND_LOOSE_OPTIONS_INIT \ + { GIT_ODB_BACKEND_LOOSE_OPTIONS_VERSION, 0, -1 } + /** * Create a backend for loose objects * * @param out location to store the odb backend pointer * @param objects_dir the Git repository's objects directory - * @param compression_level zlib compression level to use - * @param do_fsync whether to do an fsync() after writing - * @param dir_mode permissions to use creating a directory or 0 for defaults - * @param file_mode permissions to use creating a file or 0 for defaults + * @param opts options for the loose object backend or NULL * * @return 0 or an error code */ +#ifdef GIT_EXPERIMENTAL_SHA256 +GIT_EXTERN(int) git_odb_backend_loose( + git_odb_backend **out, + const char *objects_dir, + git_odb_backend_loose_options *opts); +#else GIT_EXTERN(int) git_odb_backend_loose( git_odb_backend **out, const char *objects_dir, @@ -53,6 +98,7 @@ GIT_EXTERN(int) git_odb_backend_loose( int do_fsync, unsigned int dir_mode, unsigned int file_mode); +#endif /** * Create a backend out of a single packfile @@ -87,6 +133,8 @@ struct git_odb_stream { unsigned int mode; void *hash_ctx; + git_oid_t oid_type; + git_object_size_t declared_size; git_object_size_t received_bytes; diff --git a/include/git2/oid.h b/include/git2/oid.h index 549df4eab..399b7b907 100644 --- a/include/git2/oid.h +++ b/include/git2/oid.h @@ -9,6 +9,7 @@ #include "common.h" #include "types.h" +#include "experimental.h" /** * @file git2/oid.h @@ -19,11 +20,76 @@ */ GIT_BEGIN_DECL -/** Size (in bytes) of a raw/binary oid */ -#define GIT_OID_RAWSZ 20 +/** The type of object id. */ +typedef enum { -/** Size (in bytes) of a hex formatted oid */ -#define GIT_OID_HEXSZ (GIT_OID_RAWSZ * 2) +#ifdef GIT_EXPERIMENTAL_SHA256 + GIT_OID_SHA1 = 1, /**< SHA1 */ + GIT_OID_SHA256 = 2 /**< SHA256 */ +#else + GIT_OID_SHA1 = 1 /**< SHA1 */ +#endif + +} git_oid_t; + +/* + * SHA1 is currently the only supported object ID type. + */ + +/** SHA1 is currently libgit2's default oid type. */ +#define GIT_OID_DEFAULT GIT_OID_SHA1 + +/** Size (in bytes) of a raw/binary sha1 oid */ +#define GIT_OID_SHA1_SIZE 20 +/** Size (in bytes) of a hex formatted sha1 oid */ +#define GIT_OID_SHA1_HEXSIZE (GIT_OID_SHA1_SIZE * 2) + +/** + * The binary representation of the null sha1 object ID. + */ +#ifndef GIT_EXPERIMENTAL_SHA256 +# define GIT_OID_SHA1_ZERO { { 0 } } +#else +# define GIT_OID_SHA1_ZERO { GIT_OID_SHA1, { 0 } } +#endif + +/** + * The string representation of the null sha1 object ID. + */ +#define GIT_OID_SHA1_HEXZERO "0000000000000000000000000000000000000000" + +/* + * Experimental SHA256 support is a breaking change to the API. + * This exists for application compatibility testing. + */ + +#ifdef GIT_EXPERIMENTAL_SHA256 + +/** Size (in bytes) of a raw/binary sha256 oid */ +# define GIT_OID_SHA256_SIZE 32 +/** Size (in bytes) of a hex formatted sha256 oid */ +# define GIT_OID_SHA256_HEXSIZE (GIT_OID_SHA256_SIZE * 2) + +/** + * The binary representation of the null sha256 object ID. + */ +# define GIT_OID_SHA256_ZERO { GIT_OID_SHA256, { 0 } } + +/** + * The string representation of the null sha256 object ID. + */ +# define GIT_OID_SHA256_HEXZERO "0000000000000000000000000000000000000000000000000000000000000000" + +#endif + +/* Maximum possible object ID size in raw / hex string format. */ +#ifndef GIT_EXPERIMENTAL_SHA256 +# define GIT_OID_MAX_SIZE GIT_OID_SHA1_SIZE +# define GIT_OID_MAX_HEXSIZE GIT_OID_SHA1_HEXSIZE +#else +# define GIT_OID_MAX_SIZE GIT_OID_SHA256_SIZE +# define GIT_OID_MAX_HEXSIZE GIT_OID_SHA256_HEXSIZE +#endif /** Minimum length (in number of hex characters, * i.e. packets of 4 bits) of an oid prefix */ @@ -31,29 +97,50 @@ GIT_BEGIN_DECL /** Unique identity of any object (commit, tree, blob, tag). */ typedef struct git_oid { + +#ifdef GIT_EXPERIMENTAL_SHA256 + /** type of object id */ + unsigned char type; +#endif + /** raw binary formatted id */ - unsigned char id[GIT_OID_RAWSZ]; + unsigned char id[GIT_OID_MAX_SIZE]; } git_oid; /** * Parse a hex formatted object id into a git_oid. * + * The appropriate number of bytes for the given object ID type will + * be read from the string - 40 bytes for SHA1, 64 bytes for SHA256. + * The given string need not be NUL terminated. + * * @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). + * needed for an oid encoded in hex (40 bytes for sha1, + * 256 bytes for sha256). + * @param type the type of object id * @return 0 or an error code */ +#ifdef GIT_EXPERIMENTAL_SHA256 +GIT_EXTERN(int) git_oid_fromstr(git_oid *out, const char *str, git_oid_t type); +#else GIT_EXTERN(int) git_oid_fromstr(git_oid *out, const char *str); +#endif /** - * Parse a hex formatted null-terminated string into a git_oid. + * Parse a hex formatted NUL-terminated string into a git_oid. * * @param out oid structure the result is written into. * @param str input hex string; must be null-terminated. + * @param type the type of object id * @return 0 or an error code */ +#ifdef GIT_EXPERIMENTAL_SHA256 +GIT_EXTERN(int) git_oid_fromstrp(git_oid *out, const char *str, git_oid_t type); +#else GIT_EXTERN(int) git_oid_fromstrp(git_oid *out, const char *str); +#endif /** * Parse N characters of a hex formatted object id into a git_oid. @@ -64,9 +151,14 @@ GIT_EXTERN(int) git_oid_fromstrp(git_oid *out, const char *str); * @param out oid structure the result is written into. * @param str input hex string of at least size `length` * @param length length of the input string + * @param type the type of object id * @return 0 or an error code */ +#ifdef GIT_EXPERIMENTAL_SHA256 +GIT_EXTERN(int) git_oid_fromstrn(git_oid *out, const char *str, size_t length, git_oid_t type); +#else GIT_EXTERN(int) git_oid_fromstrn(git_oid *out, const char *str, size_t length); +#endif /** * Copy an already raw oid into a git_oid structure. @@ -75,16 +167,21 @@ GIT_EXTERN(int) git_oid_fromstrn(git_oid *out, const char *str, size_t length); * @param raw the raw input bytes to be copied. * @return 0 on success or error code */ +#ifdef GIT_EXPERIMENTAL_SHA256 +GIT_EXTERN(int) git_oid_fromraw(git_oid *out, const unsigned char *raw, git_oid_t type); +#else GIT_EXTERN(int) git_oid_fromraw(git_oid *out, const unsigned char *raw); +#endif /** * Format a git_oid into a hex string. * * @param out output 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). Only the - * oid digits are written; a '\\0' terminator must be added - * by the caller if it is required. + * needed for an oid encoded in hex (40 bytes for SHA1, + * 64 bytes for SHA256). Only the oid digits are written; + * a '\\0' terminator must be added by the caller if it is + * required. * @param id oid structure to format. * @return 0 on success or error code */ @@ -94,7 +191,7 @@ GIT_EXTERN(int) git_oid_fmt(char *out, const git_oid *id); * Format a git_oid into a partial hex string. * * @param out output hex string; you say how many bytes to write. - * If the number of bytes is > GIT_OID_HEXSZ, extra bytes + * If the number of bytes is > GIT_OID_SHA1_HEXSIZE, extra bytes * will be zeroed; if not, a '\0' terminator is NOT added. * @param n number of characters to write into out string * @param id oid structure to format. @@ -110,9 +207,10 @@ GIT_EXTERN(int) git_oid_nfmt(char *out, size_t n, const git_oid *id); * * @param out output 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 (41 bytes). Only the - * oid digits are written; a '\\0' terminator must be added - * by the caller if it is required. + * needed for an oid encoded in hex (41 bytes for SHA1, + * 65 bytes for SHA256). Only the oid digits are written; + * a '\\0' terminator must be added by the caller if it + * is required. * @param id oid structure to format. * @return 0 on success, non-zero callback return value, or error code */ @@ -134,7 +232,9 @@ GIT_EXTERN(char *) git_oid_tostr_s(const git_oid *oid); /** * Format a git_oid into a buffer as a hex format c-string. * - * If the buffer is smaller than GIT_OID_HEXSZ+1, then the resulting + * If the buffer is smaller than the size of a hex-formatted oid string + * plus an additional byte (GIT_OID_SHA_HEXSIZE + 1 for SHA1 or + * GIT_OID_SHA256_HEXSIZE + 1 for SHA256), then the resulting * oid c-string will be truncated to n-1 characters (but will still be * NUL-byte terminated). * diff --git a/include/git2/sys/odb_backend.h b/include/git2/sys/odb_backend.h index 8598f94e5..c42abd370 100644 --- a/include/git2/sys/odb_backend.h +++ b/include/git2/sys/odb_backend.h @@ -36,7 +36,7 @@ struct git_odb_backend { void **, size_t *, git_object_t *, git_odb_backend *, const git_oid *); /* To find a unique object given a prefix of its oid. The oid given - * must be so that the remaining (GIT_OID_HEXSZ - len)*4 bits are 0s. + * must be so that the remaining (GIT_OID_SHA1_HEXSIZE - len)*4 bits are 0s. */ int GIT_CALLBACK(read_prefix)( git_oid *, void **, size_t *, git_object_t *, diff --git a/include/git2/version.h b/include/git2/version.h index d591904fd..09f4ae3e4 100644 --- a/include/git2/version.h +++ b/include/git2/version.h @@ -11,13 +11,13 @@ * The version string for libgit2. This string follows semantic * versioning (v2) guidelines. */ -#define LIBGIT2_VERSION "1.5.0" +#define LIBGIT2_VERSION "1.6.0-alpha" /** The major version number for this version of libgit2. */ #define LIBGIT2_VER_MAJOR 1 /** The minor version number for this version of libgit2. */ -#define LIBGIT2_VER_MINOR 5 +#define LIBGIT2_VER_MINOR 6 /** The revision ("teeny") version number for this version of libgit2. */ #define LIBGIT2_VER_REVISION 0 @@ -31,9 +31,9 @@ * a prerelease name like "beta" or "rc1". For final releases, this will * be `NULL`. */ -#define LIBGIT2_VER_PRERELEASE NULL +#define LIBGIT2_VER_PRERELEASE "alpha" /** The library ABI soversion for this version of libgit2. */ -#define LIBGIT2_SOVERSION "1.5" +#define LIBGIT2_SOVERSION "1.6" #endif |