Commit 87d9869f by Vicent Marti

Tabify everything

There were quite a few places were spaces were being used instead of
tabs. Try to catch them all. This should hopefully not break anything.
Except for `git blame`. Oh well.
parent bb742ede
...@@ -26,8 +26,8 @@ GIT_BEGIN_DECL ...@@ -26,8 +26,8 @@ GIT_BEGIN_DECL
* *
* @param commit pointer to the looked up commit * @param commit pointer to the looked up commit
* @param repo the repo to use when locating the commit. * @param repo the repo to use when locating the commit.
* @param id identity of the commit to locate. If the object is * @param id identity of the commit to locate. If the object is
* an annotated tag it will be peeled back to the commit. * an annotated tag it will be peeled back to the commit.
* @return GIT_SUCCESS or an error code * @return GIT_SUCCESS or an error code
*/ */
GIT_INLINE(int) git_commit_lookup(git_commit **commit, git_repository *repo, const git_oid *id) GIT_INLINE(int) git_commit_lookup(git_commit **commit, git_repository *repo, const git_oid *id)
...@@ -43,8 +43,8 @@ GIT_INLINE(int) git_commit_lookup(git_commit **commit, git_repository *repo, con ...@@ -43,8 +43,8 @@ GIT_INLINE(int) git_commit_lookup(git_commit **commit, git_repository *repo, con
* *
* @param commit pointer to the looked up commit * @param commit pointer to the looked up commit
* @param repo the repo to use when locating the commit. * @param repo the repo to use when locating the commit.
* @param id identity of the commit to locate. If the object is * @param id identity of the commit to locate. If the object is
* an annotated tag it will be peeled back to the commit. * an annotated tag it will be peeled back to the commit.
* @param len the length of the short identifier * @param len the length of the short identifier
* @return GIT_SUCCESS or an error code * @return GIT_SUCCESS or an error code
*/ */
...@@ -197,7 +197,7 @@ GIT_EXTERN(const git_oid *) git_commit_parent_oid(git_commit *commit, unsigned i ...@@ -197,7 +197,7 @@ GIT_EXTERN(const git_oid *) git_commit_parent_oid(git_commit *commit, unsigned i
* time of this commit * time of this commit
* *
* @param committer Signature representing the committer and the * @param committer Signature representing the committer and the
* commit time of this commit * commit time of this commit
* *
* @param message_encoding The encoding for the message in the * @param message_encoding The encoding for the message in the
* commit, represented with a standard encoding name. * commit, represented with a standard encoding name.
......
...@@ -12,20 +12,20 @@ ...@@ -12,20 +12,20 @@
#include <stdlib.h> #include <stdlib.h>
#ifdef __cplusplus #ifdef __cplusplus
# define GIT_BEGIN_DECL extern "C" { # define GIT_BEGIN_DECL extern "C" {
# define GIT_END_DECL } # define GIT_END_DECL }
#else #else
/** Start declarations in C mode */ /** Start declarations in C mode */
# define GIT_BEGIN_DECL /* empty */ # define GIT_BEGIN_DECL /* empty */
/** End declarations in C mode */ /** End declarations in C mode */
# define GIT_END_DECL /* empty */ # define GIT_END_DECL /* empty */
#endif #endif
/** Declare a public function exported for application use. */ /** Declare a public function exported for application use. */
#ifdef __GNUC__ #ifdef __GNUC__
# define GIT_EXTERN(type) extern \ # define GIT_EXTERN(type) extern \
__attribute__((visibility("default"))) \ __attribute__((visibility("default"))) \
type type
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
# define GIT_EXTERN(type) __declspec(dllexport) type # define GIT_EXTERN(type) __declspec(dllexport) type
#else #else
...@@ -35,9 +35,9 @@ ...@@ -35,9 +35,9 @@
/** Declare a public TLS symbol exported for application use. */ /** Declare a public TLS symbol exported for application use. */
#ifdef __GNUC__ #ifdef __GNUC__
# define GIT_EXTERN_TLS(type) extern \ # define GIT_EXTERN_TLS(type) extern \
__attribute__((visibility("default"))) \ __attribute__((visibility("default"))) \
GIT_TLS \ GIT_TLS \
type type
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
# define GIT_EXTERN_TLS(type) __declspec(dllexport) GIT_TLS type # define GIT_EXTERN_TLS(type) __declspec(dllexport) GIT_TLS type
#else #else
......
...@@ -64,7 +64,7 @@ typedef enum { ...@@ -64,7 +64,7 @@ typedef enum {
GIT_EINVALIDREFNAME = -15, GIT_EINVALIDREFNAME = -15,
/** The specified reference has its data corrupted */ /** The specified reference has its data corrupted */
GIT_EREFCORRUPTED = -16, GIT_EREFCORRUPTED = -16,
/** The specified symbolic reference is too deeply nested */ /** The specified symbolic reference is too deeply nested */
GIT_ETOONESTEDSYMREF = -17, GIT_ETOONESTEDSYMREF = -17,
...@@ -111,7 +111,7 @@ typedef enum { ...@@ -111,7 +111,7 @@ typedef enum {
/** The path pattern and string did not match */ /** The path pattern and string did not match */
GIT_ENOMATCH = -31, GIT_ENOMATCH = -31,
/** The buffer is too short to satisfy the request */ /** The buffer is too short to satisfy the request */
GIT_ESHORTBUFFER = -32, GIT_ESHORTBUFFER = -32,
} git_error; } git_error;
......
...@@ -20,10 +20,10 @@ ...@@ -20,10 +20,10 @@
*/ */
GIT_BEGIN_DECL GIT_BEGIN_DECL
#define GIT_IDXENTRY_NAMEMASK (0x0fff) #define GIT_IDXENTRY_NAMEMASK (0x0fff)
#define GIT_IDXENTRY_STAGEMASK (0x3000) #define GIT_IDXENTRY_STAGEMASK (0x3000)
#define GIT_IDXENTRY_EXTENDED (0x4000) #define GIT_IDXENTRY_EXTENDED (0x4000)
#define GIT_IDXENTRY_VALID (0x8000) #define GIT_IDXENTRY_VALID (0x8000)
#define GIT_IDXENTRY_STAGESHIFT 12 #define GIT_IDXENTRY_STAGESHIFT 12
/* /*
...@@ -33,26 +33,26 @@ GIT_BEGIN_DECL ...@@ -33,26 +33,26 @@ GIT_BEGIN_DECL
* *
* In-memory only flags: * In-memory only flags:
*/ */
#define GIT_IDXENTRY_UPDATE (1 << 0) #define GIT_IDXENTRY_UPDATE (1 << 0)
#define GIT_IDXENTRY_REMOVE (1 << 1) #define GIT_IDXENTRY_REMOVE (1 << 1)
#define GIT_IDXENTRY_UPTODATE (1 << 2) #define GIT_IDXENTRY_UPTODATE (1 << 2)
#define GIT_IDXENTRY_ADDED (1 << 3) #define GIT_IDXENTRY_ADDED (1 << 3)
#define GIT_IDXENTRY_HASHED (1 << 4) #define GIT_IDXENTRY_HASHED (1 << 4)
#define GIT_IDXENTRY_UNHASHED (1 << 5) #define GIT_IDXENTRY_UNHASHED (1 << 5)
#define GIT_IDXENTRY_WT_REMOVE (1 << 6) /* remove in work directory */ #define GIT_IDXENTRY_WT_REMOVE (1 << 6) /* remove in work directory */
#define GIT_IDXENTRY_CONFLICTED (1 << 7) #define GIT_IDXENTRY_CONFLICTED (1 << 7)
#define GIT_IDXENTRY_UNPACKED (1 << 8) #define GIT_IDXENTRY_UNPACKED (1 << 8)
#define GIT_IDXENTRY_NEW_SKIP_WORKTREE (1 << 9) #define GIT_IDXENTRY_NEW_SKIP_WORKTREE (1 << 9)
/* /*
* Extended on-disk flags: * Extended on-disk flags:
*/ */
#define GIT_IDXENTRY_INTENT_TO_ADD (1 << 13) #define GIT_IDXENTRY_INTENT_TO_ADD (1 << 13)
#define GIT_IDXENTRY_SKIP_WORKTREE (1 << 14) #define GIT_IDXENTRY_SKIP_WORKTREE (1 << 14)
/* GIT_IDXENTRY_EXTENDED2 is for future extension */ /* GIT_IDXENTRY_EXTENDED2 is for future extension */
#define GIT_IDXENTRY_EXTENDED2 (1 << 15) #define GIT_IDXENTRY_EXTENDED2 (1 << 15)
#define GIT_IDXENTRY_EXTENDED_FLAGS (GIT_IDXENTRY_INTENT_TO_ADD | GIT_IDXENTRY_SKIP_WORKTREE) #define GIT_IDXENTRY_EXTENDED_FLAGS (GIT_IDXENTRY_INTENT_TO_ADD | GIT_IDXENTRY_SKIP_WORKTREE)
......
...@@ -28,7 +28,7 @@ GIT_BEGIN_DECL ...@@ -28,7 +28,7 @@ GIT_BEGIN_DECL
* backend must be manually added using `git_odb_add_backend()` * backend must be manually added using `git_odb_add_backend()`
* *
* @param out location to store the database pointer, if opened. * @param out location to store the database pointer, if opened.
* Set to NULL if the open failed. * Set to NULL if the open failed.
* @return GIT_SUCCESS or an error code * @return GIT_SUCCESS or an error code
*/ */
GIT_EXTERN(int) git_odb_new(git_odb **out); GIT_EXTERN(int) git_odb_new(git_odb **out);
...@@ -45,7 +45,7 @@ GIT_EXTERN(int) git_odb_new(git_odb **out); ...@@ -45,7 +45,7 @@ GIT_EXTERN(int) git_odb_new(git_odb **out);
* contains a 'pack/' folder with the corresponding data * contains a 'pack/' folder with the corresponding data
* *
* @param out location to store the database pointer, if opened. * @param out location to store the database pointer, if opened.
* Set to NULL if the open failed. * Set to NULL if the open failed.
* @param objects_dir path of the backends' "objects" directory. * @param objects_dir path of the backends' "objects" directory.
* @return GIT_SUCCESS or an error code * @return GIT_SUCCESS or an error code
*/ */
...@@ -90,7 +90,7 @@ GIT_EXTERN(int) git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, in ...@@ -90,7 +90,7 @@ GIT_EXTERN(int) git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, in
/** /**
* Close an open object database. * Close an open object database.
* *
* @param db database pointer to close. If NULL no action is taken. * @param db database pointer to close. If NULL no action is taken.
*/ */
GIT_EXTERN(void) git_odb_close(git_odb *db); GIT_EXTERN(void) git_odb_close(git_odb *db);
......
...@@ -41,8 +41,8 @@ struct _git_oid { ...@@ -41,8 +41,8 @@ struct _git_oid {
* *
* @param out oid structure the result is written into. * @param out oid structure the result is written into.
* @param str input hex string; must be pointing at the start of * @param str input hex string; must be pointing at the start of
* the hex sequence and have at least the number of bytes * 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).
* @return GIT_SUCCESS or an error code * @return GIT_SUCCESS or an error code
*/ */
GIT_EXTERN(int) git_oid_fromstr(git_oid *out, const char *str); GIT_EXTERN(int) git_oid_fromstr(git_oid *out, const char *str);
...@@ -72,10 +72,10 @@ GIT_EXTERN(void) git_oid_fromraw(git_oid *out, const unsigned char *raw); ...@@ -72,10 +72,10 @@ GIT_EXTERN(void) git_oid_fromraw(git_oid *out, const unsigned char *raw);
* Format a git_oid into a hex string. * Format a git_oid into a hex string.
* *
* @param str output hex string; must be pointing at the start of * @param str output hex string; must be pointing at the start of
* the hex sequence and have at least the number of bytes * the hex sequence and have at least the number of bytes
* needed for an oid encoded in hex (40 bytes). Only the * needed for an oid encoded in hex (40 bytes). Only the
* oid digits are written; a '\\0' terminator must be added * oid digits are written; a '\\0' terminator must be added
* by the caller if it is required. * by the caller if it is required.
* @param oid oid structure to format. * @param oid oid structure to format.
*/ */
GIT_EXTERN(void) git_oid_fmt(char *str, const git_oid *oid); GIT_EXTERN(void) git_oid_fmt(char *str, const git_oid *oid);
...@@ -87,10 +87,10 @@ GIT_EXTERN(void) git_oid_fmt(char *str, const git_oid *oid); ...@@ -87,10 +87,10 @@ GIT_EXTERN(void) git_oid_fmt(char *str, const git_oid *oid);
* hex digitis of the oid and "..." is the remaining 38 digits. * hex digitis of the oid and "..." is the remaining 38 digits.
* *
* @param str output hex string; must be pointing at the start of * @param str output hex string; must be pointing at the start of
* the hex sequence and have at least the number of bytes * the hex sequence and have at least the number of bytes
* needed for an oid encoded in hex (41 bytes). Only the * needed for an oid encoded in hex (41 bytes). Only the
* oid digits are written; a '\\0' terminator must be added * oid digits are written; a '\\0' terminator must be added
* by the caller if it is required. * by the caller if it is required.
* @param oid oid structure to format. * @param oid oid structure to format.
*/ */
GIT_EXTERN(void) git_oid_pathfmt(char *str, const git_oid *oid); GIT_EXTERN(void) git_oid_pathfmt(char *str, const git_oid *oid);
...@@ -99,8 +99,8 @@ GIT_EXTERN(void) git_oid_pathfmt(char *str, const git_oid *oid); ...@@ -99,8 +99,8 @@ GIT_EXTERN(void) git_oid_pathfmt(char *str, const git_oid *oid);
* Format a git_oid into a newly allocated c-string. * Format a git_oid into a newly allocated c-string.
* *
* @param oid the oid structure to format * @param oid the oid structure to format
* @return the c-string; NULL if memory is exhausted. Caller must * @return the c-string; NULL if memory is exhausted. Caller must
* deallocate the string with free(). * deallocate the string with free().
*/ */
GIT_EXTERN(char *) git_oid_allocfmt(const git_oid *oid); GIT_EXTERN(char *) git_oid_allocfmt(const git_oid *oid);
...@@ -117,7 +117,7 @@ GIT_EXTERN(char *) git_oid_allocfmt(const git_oid *oid); ...@@ -117,7 +117,7 @@ GIT_EXTERN(char *) git_oid_allocfmt(const git_oid *oid);
* @param n the size of the out buffer. * @param n the size of the out buffer.
* @param oid the oid structure to format. * @param oid the oid structure to format.
* @return the out buffer pointer, assuming no input parameter * @return the out buffer pointer, assuming no input parameter
* errors, otherwise a pointer to an empty string. * errors, otherwise a pointer to an empty string.
*/ */
GIT_EXTERN(char *) git_oid_to_string(char *out, size_t n, const git_oid *oid); GIT_EXTERN(char *) git_oid_to_string(char *out, size_t n, const git_oid *oid);
......
...@@ -26,28 +26,28 @@ GIT_BEGIN_DECL ...@@ -26,28 +26,28 @@ GIT_BEGIN_DECL
* and subject to change at any time. * and subject to change at any time.
* This is the default sorting for new walkers. * This is the default sorting for new walkers.
*/ */
#define GIT_SORT_NONE (0) #define GIT_SORT_NONE (0)
/** /**
* Sort the repository contents in topological order * Sort the repository contents in topological order
* (parents before children); this sorting mode * (parents before children); this sorting mode
* can be combined with time sorting. * can be combined with time sorting.
*/ */
#define GIT_SORT_TOPOLOGICAL (1 << 0) #define GIT_SORT_TOPOLOGICAL (1 << 0)
/** /**
* Sort the repository contents by commit time; * Sort the repository contents by commit time;
* this sorting mode can be combined with * this sorting mode can be combined with
* topological sorting. * topological sorting.
*/ */
#define GIT_SORT_TIME (1 << 1) #define GIT_SORT_TIME (1 << 1)
/** /**
* Iterate through the repository contents in reverse * Iterate through the repository contents in reverse
* order; this sorting mode can be combined with * order; this sorting mode can be combined with
* any of the above. * any of the above.
*/ */
#define GIT_SORT_REVERSE (1 << 2) #define GIT_SORT_REVERSE (1 << 2)
/** /**
* Allocate a new revision walker to iterate through a repo. * Allocate a new revision walker to iterate through a repo.
...@@ -151,7 +151,7 @@ GIT_EXTERN(void) git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode); ...@@ -151,7 +151,7 @@ GIT_EXTERN(void) git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode);
/** /**
* Free a revision walker previously allocated. * Free a revision walker previously allocated.
* *
* @param walk traversal handle to close. If NULL nothing occurs. * @param walk traversal handle to close. If NULL nothing occurs.
*/ */
GIT_EXTERN(void) git_revwalk_free(git_revwalk *walk); GIT_EXTERN(void) git_revwalk_free(git_revwalk *walk);
......
...@@ -19,19 +19,19 @@ ...@@ -19,19 +19,19 @@
*/ */
GIT_BEGIN_DECL GIT_BEGIN_DECL
#define GIT_STATUS_CURRENT 0 #define GIT_STATUS_CURRENT 0
/** Flags for index status */ /** Flags for index status */
#define GIT_STATUS_INDEX_NEW (1 << 0) #define GIT_STATUS_INDEX_NEW (1 << 0)
#define GIT_STATUS_INDEX_MODIFIED (1 << 1) #define GIT_STATUS_INDEX_MODIFIED (1 << 1)
#define GIT_STATUS_INDEX_DELETED (1 << 2) #define GIT_STATUS_INDEX_DELETED (1 << 2)
/** Flags for worktree status */ /** Flags for worktree status */
#define GIT_STATUS_WT_NEW (1 << 3) #define GIT_STATUS_WT_NEW (1 << 3)
#define GIT_STATUS_WT_MODIFIED (1 << 4) #define GIT_STATUS_WT_MODIFIED (1 << 4)
#define GIT_STATUS_WT_DELETED (1 << 5) #define GIT_STATUS_WT_DELETED (1 << 5)
// TODO Ignored files not handled yet // TODO Ignored files not handled yet
#define GIT_STATUS_IGNORED (1 << 6) #define GIT_STATUS_IGNORED (1 << 6)
/** /**
* Gather file statuses and run a callback for each one. * Gather file statuses and run a callback for each one.
......
...@@ -152,7 +152,7 @@ GIT_EXTERN(const char *) git_tag_message(git_tag *tag); ...@@ -152,7 +152,7 @@ GIT_EXTERN(const char *) git_tag_message(git_tag *tag);
* must belong to the given `repo`. * must belong to the given `repo`.
* *
* @param tagger Signature of the tagger for this tag, and * @param tagger Signature of the tagger for this tag, and
* of the tagging time * of the tagging time
* *
* @param message Full message for this tag * @param message Full message for this tag
* *
...@@ -211,7 +211,7 @@ GIT_EXTERN(int) git_tag_create_frombuffer( ...@@ -211,7 +211,7 @@ GIT_EXTERN(int) git_tag_create_frombuffer(
* *
* @return GIT_SUCCESS or an error code * @return GIT_SUCCESS or an error code
* A proper reference is written in the /refs/tags folder, * A proper reference is written in the /refs/tags folder,
* pointing to the provided target object * pointing to the provided target object
*/ */
GIT_EXTERN(int) git_tag_create_lightweight( GIT_EXTERN(int) git_tag_create_lightweight(
git_oid *oid, git_oid *oid,
......
...@@ -10,51 +10,51 @@ ...@@ -10,51 +10,51 @@
/* /*
* How TLS works is compiler+platform dependant * How TLS works is compiler+platform dependant
* Sources: http://en.wikipedia.org/wiki/Thread-Specific_Storage * Sources: http://en.wikipedia.org/wiki/Thread-Specific_Storage
* http://predef.sourceforge.net/precomp.html * http://predef.sourceforge.net/precomp.html
*/ */
#ifdef GIT_THREADS #ifdef GIT_THREADS
# define GIT_HAS_TLS 1 # define GIT_HAS_TLS 1
/* No TLS in Cygwin */ /* No TLS in Cygwin */
# if defined(__CHECKER__) || defined(__CYGWIN__) # if defined(__CHECKER__) || defined(__CYGWIN__)
# undef GIT_HAS_TLS # undef GIT_HAS_TLS
# define GIT_TLS # define GIT_TLS
/* No TLS in Mach binaries for Mac OS X */ /* No TLS in Mach binaries for Mac OS X */
# elif defined(__APPLE__) && defined(__MACH__) # elif defined(__APPLE__) && defined(__MACH__)
# undef GIT_TLS # undef GIT_TLS
# define GIT_TLS # define GIT_TLS
/* Normal TLS for GCC */ /* Normal TLS for GCC */
# elif defined(__GNUC__) || \ # elif defined(__GNUC__) || \
defined(__SUNPRO_C) || \ defined(__SUNPRO_C) || \
defined(__SUNPRO_CC) || \ defined(__SUNPRO_CC) || \
defined(__xlc__) || \ defined(__xlc__) || \
defined(__xlC__) defined(__xlC__)
# define GIT_TLS __thread # define GIT_TLS __thread
/* ICC may run on Windows or Linux */ /* ICC may run on Windows or Linux */
# elif defined(__INTEL_COMPILER) # elif defined(__INTEL_COMPILER)
# if defined(_WIN32) || defined(_WIN32_CE) # if defined(_WIN32) || defined(_WIN32_CE)
# define GIT_TLS __declspec(thread) # define GIT_TLS __declspec(thread)
# else # else
# define GIT_TLS __thread # define GIT_TLS __thread
# endif # endif
/* Declspec for MSVC in Win32 */ /* Declspec for MSVC in Win32 */
# elif defined(_WIN32) || \ # elif defined(_WIN32) || \
defined(_WIN32_CE) || \ defined(_WIN32_CE) || \
defined(__BORLANDC__) defined(__BORLANDC__)
# define GIT_TLS __declspec(thread) # define GIT_TLS __declspec(thread)
/* Other platform; no TLS */ /* Other platform; no TLS */
# else # else
# undef GIT_HAS_TLS # undef GIT_HAS_TLS
# define GIT_TLS /* nothing: tls vars are thread-global */ # define GIT_TLS /* nothing: tls vars are thread-global */
# endif # endif
#else /* Disable TLS if libgit2 is not threadsafe */ #else /* Disable TLS if libgit2 is not threadsafe */
# define GIT_TLS # define GIT_TLS
#endif /* GIT_THREADS */ #endif /* GIT_THREADS */
#endif /* INCLUDE_git_thread_utils_h__ */ #endif /* INCLUDE_git_thread_utils_h__ */
...@@ -36,7 +36,7 @@ GIT_BEGIN_DECL ...@@ -36,7 +36,7 @@ GIT_BEGIN_DECL
#if defined(_MSC_VER) #if defined(_MSC_VER)
typedef __int64 git_off_t; typedef __int64 git_off_t;
typedef __time64_t git_time_t; typedef __time64_t git_time_t;
#elif defined(__MINGW32__) #elif defined(__MINGW32__)
...@@ -48,7 +48,7 @@ typedef __time64_t git_time_t; ...@@ -48,7 +48,7 @@ typedef __time64_t git_time_t;
typedef __haiku_std_int64 git_off_t; typedef __haiku_std_int64 git_off_t;
typedef __haiku_std_int64 git_time_t; typedef __haiku_std_int64 git_time_t;
#else /* POSIX */ #else /* POSIX */
/* /*
* Note: Can't use off_t since if a client program includes <sys/types.h> * Note: Can't use off_t since if a client program includes <sys/types.h>
...@@ -63,15 +63,15 @@ typedef int64_t git_time_t; ...@@ -63,15 +63,15 @@ typedef int64_t git_time_t;
/** Basic type (loose or packed) of any Git object. */ /** Basic type (loose or packed) of any Git object. */
typedef enum { typedef enum {
GIT_OBJ_ANY = -2, /**< Object can be any of the following */ GIT_OBJ_ANY = -2, /**< Object can be any of the following */
GIT_OBJ_BAD = -1, /**< Object is invalid. */ GIT_OBJ_BAD = -1, /**< Object is invalid. */
GIT_OBJ__EXT1 = 0, /**< Reserved for future use. */ GIT_OBJ__EXT1 = 0, /**< Reserved for future use. */
GIT_OBJ_COMMIT = 1, /**< A commit object. */ GIT_OBJ_COMMIT = 1, /**< A commit object. */
GIT_OBJ_TREE = 2, /**< A tree (directory listing) object. */ GIT_OBJ_TREE = 2, /**< A tree (directory listing) object. */
GIT_OBJ_BLOB = 3, /**< A file revision object. */ GIT_OBJ_BLOB = 3, /**< A file revision object. */
GIT_OBJ_TAG = 4, /**< An annotated tag object. */ GIT_OBJ_TAG = 4, /**< An annotated tag object. */
GIT_OBJ__EXT2 = 5, /**< Reserved for future use. */ GIT_OBJ__EXT2 = 5, /**< Reserved for future use. */
GIT_OBJ_OFS_DELTA = 6, /**< A delta, base is given by an offset. */ 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_OBJ_REF_DELTA = 7, /**< A delta, base is given by object id. */
} git_otype; } git_otype;
/** An open object database handle. */ /** An open object database handle. */
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
GIT_INLINE(uint32_t) default_swab32(uint32_t val) GIT_INLINE(uint32_t) default_swab32(uint32_t val)
{ {
return (((val & 0xff000000) >> 24) | return (((val & 0xff000000) >> 24) |
((val & 0x00ff0000) >> 8) | ((val & 0x00ff0000) >> 8) |
((val & 0x0000ff00) << 8) | ((val & 0x0000ff00) << 8) |
((val & 0x000000ff) << 24)); ((val & 0x000000ff) << 24));
} }
......
...@@ -12,18 +12,18 @@ ...@@ -12,18 +12,18 @@
*/ */
#ifndef GIT_FLEX_ARRAY #ifndef GIT_FLEX_ARRAY
# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) # if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
# define GIT_FLEX_ARRAY /* empty */ # define GIT_FLEX_ARRAY /* empty */
# elif defined(__GNUC__) # elif defined(__GNUC__)
# if (__GNUC__ >= 3) # if (__GNUC__ >= 3)
# define GIT_FLEX_ARRAY /* empty */ # define GIT_FLEX_ARRAY /* empty */
# else # else
# define GIT_FLEX_ARRAY 0 /* older GNU extension */ # define GIT_FLEX_ARRAY 0 /* older GNU extension */
# endif # endif
# endif # endif
/* Default to safer but a bit wasteful traditional style */ /* Default to safer but a bit wasteful traditional style */
# ifndef GIT_FLEX_ARRAY # ifndef GIT_FLEX_ARRAY
# define GIT_FLEX_ARRAY 1 # define GIT_FLEX_ARRAY 1
# endif # endif
#endif #endif
...@@ -37,9 +37,9 @@ ...@@ -37,9 +37,9 @@
# define GIT_UNUSED(x) # define GIT_UNUSED(x)
#else #else
# ifdef __GNUC__ # ifdef __GNUC__
# define GIT_UNUSED(x) x __attribute__ ((__unused__)) # define GIT_UNUSED(x) x __attribute__ ((__unused__))
# else # else
# define GIT_UNUSED(x) x # define GIT_UNUSED(x) x
# endif # endif
#endif #endif
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
# include "win32/msvc-compat.h" # include "win32/msvc-compat.h"
# include "win32/mingw-compat.h" # include "win32/mingw-compat.h"
# ifdef GIT_THREADS # ifdef GIT_THREADS
# include "win32/pthread.h" # include "win32/pthread.h"
#endif #endif
# define snprintf _snprintf # define snprintf _snprintf
...@@ -43,7 +43,7 @@ typedef SSIZE_T ssize_t; ...@@ -43,7 +43,7 @@ typedef SSIZE_T ssize_t;
# include <unistd.h> # include <unistd.h>
# ifdef GIT_THREADS # ifdef GIT_THREADS
# include <pthread.h> # include <pthread.h>
# endif # endif
#endif #endif
......
...@@ -151,7 +151,7 @@ int git_config_foreach(git_config *cfg, int (*fn)(const char *, const char *, vo ...@@ -151,7 +151,7 @@ int git_config_foreach(git_config *cfg, int (*fn)(const char *, const char *, vo
int git_config_delete(git_config *cfg, const char *name) int git_config_delete(git_config *cfg, const char *name)
{ {
return git_config_set_string(cfg, name, NULL); return git_config_set_string(cfg, name, NULL);
} }
/************** /**************
......
...@@ -748,7 +748,7 @@ static int skip_bom(diskfile_backend *cfg) ...@@ -748,7 +748,7 @@ static int skip_bom(diskfile_backend *cfg)
if (memcmp(cfg->reader.read_ptr, utf8_bom, sizeof(utf8_bom)) == 0) if (memcmp(cfg->reader.read_ptr, utf8_bom, sizeof(utf8_bom)) == 0)
cfg->reader.read_ptr += sizeof(utf8_bom); cfg->reader.read_ptr += sizeof(utf8_bom);
/* TODO: the reference implementation does pretty stupid /* TODO: the reference implementation does pretty stupid
shit with the BoM shit with the BoM
*/ */
...@@ -1019,7 +1019,7 @@ static int config_write(diskfile_backend *cfg, cvar_t *var) ...@@ -1019,7 +1019,7 @@ static int config_write(diskfile_backend *cfg, cvar_t *var)
/* And then the write out rest of the file */ /* And then the write out rest of the file */
error = git_filebuf_write(&file, post_start, error = git_filebuf_write(&file, post_start,
cfg->reader.buffer.len - (post_start - data_start)); cfg->reader.buffer.len - (post_start - data_start));
if (error < GIT_SUCCESS) { if (error < GIT_SUCCESS) {
git__rethrow(error, "Failed to write the rest of the file"); git__rethrow(error, "Failed to write the rest of the file");
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
/* /*
* This file was heavily cribbed from BinaryDelta.java in JGit, which * This file was heavily cribbed from BinaryDelta.java in JGit, which
* itself was heavily cribbed from <code>patch-delta.c</code> in the * itself was heavily cribbed from <code>patch-delta.c</code> in the
* GIT project. The original delta patching code was written by * GIT project. The original delta patching code was written by
* Nicolas Pitre <nico@cam.org>. * Nicolas Pitre <nico@cam.org>.
*/ */
...@@ -70,15 +70,15 @@ int git__delta_apply( ...@@ -70,15 +70,15 @@ int git__delta_apply(
*/ */
size_t off = 0, len = 0; size_t off = 0, len = 0;
if (cmd & 0x01) off = *delta++; if (cmd & 0x01) off = *delta++;
if (cmd & 0x02) off |= *delta++ << 8; if (cmd & 0x02) off |= *delta++ << 8;
if (cmd & 0x04) off |= *delta++ << 16; if (cmd & 0x04) off |= *delta++ << 16;
if (cmd & 0x08) off |= *delta++ << 24; if (cmd & 0x08) off |= *delta++ << 24;
if (cmd & 0x10) len = *delta++; if (cmd & 0x10) len = *delta++;
if (cmd & 0x20) len |= *delta++ << 8; if (cmd & 0x20) len |= *delta++ << 8;
if (cmd & 0x40) len |= *delta++ << 16; if (cmd & 0x40) len |= *delta++ << 16;
if (!len) len = 0x10000; if (!len) len = 0x10000;
if (base_len < off + len || res_sz < len) if (base_len < off + len || res_sz < len)
goto fail; goto fail;
...@@ -93,7 +93,7 @@ int git__delta_apply( ...@@ -93,7 +93,7 @@ int git__delta_apply(
if (delta_end - delta < cmd || res_sz < cmd) if (delta_end - delta < cmd || res_sz < cmd)
goto fail; goto fail;
memcpy(res_dp, delta, cmd); memcpy(res_dp, delta, cmd);
delta += cmd; delta += cmd;
res_dp += cmd; res_dp += cmd;
res_sz -= cmd; res_sz -= cmd;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#ifdef GIT_WIN32 #ifdef GIT_WIN32
struct git__dirent { struct git__dirent {
int d_ino; int d_ino;
char d_name[261]; char d_name[261];
}; };
...@@ -34,12 +34,12 @@ extern void git__rewinddir(git__DIR *); ...@@ -34,12 +34,12 @@ extern void git__rewinddir(git__DIR *);
extern int git__closedir(git__DIR *); extern int git__closedir(git__DIR *);
# ifndef GIT__WIN32_NO_WRAP_DIR # ifndef GIT__WIN32_NO_WRAP_DIR
# define dirent git__dirent # define dirent git__dirent
# define DIR git__DIR # define DIR git__DIR
# define opendir git__opendir # define opendir git__opendir
# define readdir git__readdir # define readdir git__readdir
# define rewinddir git__rewinddir # define rewinddir git__rewinddir
# define closedir git__closedir # define closedir git__closedir
# endif # endif
#endif #endif
......
...@@ -71,7 +71,7 @@ void git___rethrow(const char *msg, ...) ...@@ -71,7 +71,7 @@ void git___rethrow(const char *msg, ...)
va_end(va); va_end(va);
old_error = strdup(g_last_error); old_error = strdup(g_last_error);
snprintf(g_last_error, sizeof(g_last_error), "%s \n - %s", new_error, old_error); snprintf(g_last_error, sizeof(g_last_error), "%s \n - %s", new_error, old_error);
free(old_error); free(old_error);
} }
......
...@@ -194,7 +194,7 @@ int git_futils_readbuffer_updated(git_fbuffer *obj, const char *path, time_t *mt ...@@ -194,7 +194,7 @@ int git_futils_readbuffer_updated(git_fbuffer *obj, const char *path, time_t *mt
*updated = 1; *updated = 1;
obj->data = buff; obj->data = buff;
obj->len = len; obj->len = len;
return GIT_SUCCESS; return GIT_SUCCESS;
} }
...@@ -293,7 +293,7 @@ int git_futils_mkdir_r(const char *path, int mode) ...@@ -293,7 +293,7 @@ int git_futils_mkdir_r(const char *path, int mode)
{ {
int error, root_path_offset; int error, root_path_offset;
char *pp, *sp; char *pp, *sp;
char *path_copy = git__strdup(path); char *path_copy = git__strdup(path);
if (path_copy == NULL) if (path_copy == NULL)
return GIT_ENOMEM; return GIT_ENOMEM;
...@@ -305,7 +305,7 @@ int git_futils_mkdir_r(const char *path, int mode) ...@@ -305,7 +305,7 @@ int git_futils_mkdir_r(const char *path, int mode)
if (root_path_offset > 0) if (root_path_offset > 0)
pp += root_path_offset; /* On Windows, will skip the drive name (eg. C: or D:) */ pp += root_path_offset; /* On Windows, will skip the drive name (eg. C: or D:) */
while (error == GIT_SUCCESS && (sp = strchr(pp, '/')) != NULL) { while (error == GIT_SUCCESS && (sp = strchr(pp, '/')) != NULL) {
if (sp != pp && git_futils_isdir(path_copy) < GIT_SUCCESS) { if (sp != pp && git_futils_isdir(path_copy) < GIT_SUCCESS) {
*sp = 0; *sp = 0;
error = p_mkdir(path_copy, mode); error = p_mkdir(path_copy, mode);
...@@ -359,7 +359,7 @@ int git_futils_rmdir_r(const char *path, int force) ...@@ -359,7 +359,7 @@ int git_futils_rmdir_r(const char *path, int force)
{ {
char p[GIT_PATH_MAX]; char p[GIT_PATH_MAX];
strncpy(p, path, GIT_PATH_MAX); strncpy(p, path, GIT_PATH_MAX);
return _rmdir_recurs_foreach(&force, p); return _rmdir_recurs_foreach(&force, p);
} }
int git_futils_cmp_path(const char *name1, int len1, int isdir1, int git_futils_cmp_path(const char *name1, int len1, int isdir1,
...@@ -373,10 +373,10 @@ int git_futils_cmp_path(const char *name1, int len1, int isdir1, ...@@ -373,10 +373,10 @@ int git_futils_cmp_path(const char *name1, int len1, int isdir1,
return cmp; return cmp;
if (len1 < len2) if (len1 < len2)
return ((!isdir1 && !isdir2) ? -1 : return ((!isdir1 && !isdir2) ? -1 :
(isdir1 ? '/' - name2[len1] : name2[len1] - '/')); (isdir1 ? '/' - name2[len1] : name2[len1] - '/'));
if (len1 > len2) if (len1 > len2)
return ((!isdir1 && !isdir2) ? 1 : return ((!isdir1 && !isdir2) ? 1 :
(isdir2 ? name1[len2] - '/' : '/' - name1[len2])); (isdir2 ? name1[len2] - '/' : '/' - name1[len2]));
return 0; return 0;
} }
...@@ -20,9 +20,9 @@ ...@@ -20,9 +20,9 @@
*/ */
#define GIT_FBUFFER_INIT {NULL, 0} #define GIT_FBUFFER_INIT {NULL, 0}
typedef struct { /* file io buffer */ typedef struct { /* file io buffer */
void *data; /* data bytes */ void *data; /* data bytes */
size_t len; /* data length */ size_t len; /* data length */
} git_fbuffer; } git_fbuffer;
extern int git_futils_readbuffer(git_fbuffer *obj, const char *path); extern int git_futils_readbuffer(git_fbuffer *obj, const char *path);
...@@ -139,8 +139,8 @@ extern void git_futils_mmap_free(git_map *map); ...@@ -139,8 +139,8 @@ extern void git_futils_mmap_free(git_map *map);
* @param pathbuf buffer the function reads the initial directory * @param pathbuf buffer the function reads the initial directory
* path from, and updates with each successive entry's name. * path from, and updates with each successive entry's name.
* @param pathmax maximum allocation of pathbuf. * @param pathmax maximum allocation of pathbuf.
* @param fn function to invoke with each entry. The first arg is * @param fn function to invoke with each entry. The first arg is
* the input state and the second arg is pathbuf. The function * the input state and the second arg is pathbuf. The function
* may modify the pathbuf, but only by appending new text. * may modify the pathbuf, but only by appending new text.
* @param state to pass to fn as the first arg. * @param state to pass to fn as the first arg.
*/ */
......
...@@ -963,11 +963,11 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry) ...@@ -963,11 +963,11 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry)
ondisk->mtime.seconds = htonl((uint32_t)entry->mtime.seconds); ondisk->mtime.seconds = htonl((uint32_t)entry->mtime.seconds);
ondisk->ctime.nanoseconds = htonl(entry->ctime.nanoseconds); ondisk->ctime.nanoseconds = htonl(entry->ctime.nanoseconds);
ondisk->mtime.nanoseconds = htonl(entry->mtime.nanoseconds); ondisk->mtime.nanoseconds = htonl(entry->mtime.nanoseconds);
ondisk->dev = htonl(entry->dev); ondisk->dev = htonl(entry->dev);
ondisk->ino = htonl(entry->ino); ondisk->ino = htonl(entry->ino);
ondisk->mode = htonl(entry->mode); ondisk->mode = htonl(entry->mode);
ondisk->uid = htonl(entry->uid); ondisk->uid = htonl(entry->uid);
ondisk->gid = htonl(entry->gid); ondisk->gid = htonl(entry->gid);
ondisk->file_size = htonl((uint32_t)entry->file_size); ondisk->file_size = htonl((uint32_t)entry->file_size);
git_oid_cpy(&ondisk->oid, &entry->oid); git_oid_cpy(&ondisk->oid, &entry->oid);
......
...@@ -11,23 +11,23 @@ ...@@ -11,23 +11,23 @@
/* p_mmap() prot values */ /* p_mmap() prot values */
#define GIT_PROT_NONE 0x0 #define GIT_PROT_NONE 0x0
#define GIT_PROT_READ 0x1 #define GIT_PROT_READ 0x1
#define GIT_PROT_WRITE 0x2 #define GIT_PROT_WRITE 0x2
#define GIT_PROT_EXEC 0x4 #define GIT_PROT_EXEC 0x4
/* git__mmmap() flags values */ /* git__mmmap() flags values */
#define GIT_MAP_FILE 0 #define GIT_MAP_FILE 0
#define GIT_MAP_SHARED 1 #define GIT_MAP_SHARED 1
#define GIT_MAP_PRIVATE 2 #define GIT_MAP_PRIVATE 2
#define GIT_MAP_TYPE 0xf #define GIT_MAP_TYPE 0xf
#define GIT_MAP_FIXED 0x10 #define GIT_MAP_FIXED 0x10
typedef struct { /* memory mapped buffer */ typedef struct { /* memory mapped buffer */
void *data; /* data bytes */ void *data; /* data bytes */
size_t len; /* data length */ size_t len; /* data length */
#ifdef GIT_WIN32 #ifdef GIT_WIN32
HANDLE fmh; /* file mapping handle */ HANDLE fmh; /* file mapping handle */
#endif #endif
} git_map; } git_map;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#define DEFAULT_WINDOW_SIZE \ #define DEFAULT_WINDOW_SIZE \
(sizeof(void*) >= 8 \ (sizeof(void*) >= 8 \
? 1 * 1024 * 1024 * 1024 \ ? 1 * 1024 * 1024 * 1024 \
: 32 * 1024 * 1024) : 32 * 1024 * 1024)
#define DEFAULT_MAPPED_LIMIT \ #define DEFAULT_MAPPED_LIMIT \
...@@ -165,7 +165,7 @@ static git_mwindow *new_window(git_mwindow_file *mwf, git_file fd, git_off_t siz ...@@ -165,7 +165,7 @@ static git_mwindow *new_window(git_mwindow_file *mwf, git_file fd, git_off_t siz
ctl.mapped += (size_t)len; ctl.mapped += (size_t)len;
while(ctl.mapped_limit < ctl.mapped && while(ctl.mapped_limit < ctl.mapped &&
git_mwindow_close_lru(mwf) == GIT_SUCCESS) {} git_mwindow_close_lru(mwf) == GIT_SUCCESS) {}
/* FIXME: Shouldn't we error out if there's an error in closing lru? */ /* FIXME: Shouldn't we error out if there's an error in closing lru? */
...@@ -193,7 +193,7 @@ cleanup: ...@@ -193,7 +193,7 @@ cleanup:
* enough space. Don't forget to add it to your list * enough space. Don't forget to add it to your list
*/ */
unsigned char *git_mwindow_open(git_mwindow_file *mwf, git_mwindow **cursor, unsigned char *git_mwindow_open(git_mwindow_file *mwf, git_mwindow **cursor,
git_off_t offset, int extra, unsigned int *left) git_off_t offset, int extra, unsigned int *left)
{ {
git_mwindow *w = *cursor; git_mwindow *w = *cursor;
...@@ -241,7 +241,7 @@ int git_mwindow_file_register(git_mwindow_file *mwf) ...@@ -241,7 +241,7 @@ int git_mwindow_file_register(git_mwindow_file *mwf)
int error; int error;
if (ctl.windowfiles.length == 0 && if (ctl.windowfiles.length == 0 &&
(error = git_vector_init(&ctl.windowfiles, 8, NULL)) < GIT_SUCCESS) (error = git_vector_init(&ctl.windowfiles, 8, NULL)) < GIT_SUCCESS)
return error; return error;
return git_vector_insert(&ctl.windowfiles, mwf); return git_vector_insert(&ctl.windowfiles, mwf);
......
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
static const int OBJECT_BASE_SIZE = 4096; static const int OBJECT_BASE_SIZE = 4096;
static struct { static struct {
const char *str; /* type name string */ const char *str; /* type name string */
int loose; /* valid loose object type flag */ int loose; /* valid loose object type flag */
size_t size; /* size in bytes of the object structure */ size_t size; /* size in bytes of the object structure */
} git_objects_table[] = { } git_objects_table[] = {
/* 0 = GIT_OBJ__EXT1 */ /* 0 = GIT_OBJ__EXT1 */
...@@ -92,7 +92,7 @@ int git_object_lookup_prefix(git_object **object_out, git_repository *repo, cons ...@@ -92,7 +92,7 @@ int git_object_lookup_prefix(git_object **object_out, git_repository *repo, cons
if (len > GIT_OID_HEXSZ) if (len > GIT_OID_HEXSZ)
len = GIT_OID_HEXSZ; len = GIT_OID_HEXSZ;
if (len == GIT_OID_HEXSZ) { if (len == GIT_OID_HEXSZ) {
/* We want to match the full id : we can first look up in the cache, /* We want to match the full id : we can first look up in the cache,
* since there is no need to check for non ambiguousity * since there is no need to check for non ambiguousity
*/ */
...@@ -126,10 +126,10 @@ int git_object_lookup_prefix(git_object **object_out, git_repository *repo, cons ...@@ -126,10 +126,10 @@ int git_object_lookup_prefix(git_object **object_out, git_repository *repo, cons
/* If len < GIT_OID_HEXSZ (a strict short oid was given), we have /* If len < GIT_OID_HEXSZ (a strict short oid was given), we have
* 2 options : * 2 options :
* - We always search in the cache first. If we find that short oid is * - We always search in the cache first. If we find that short oid is
* ambiguous, we can stop. But in all the other cases, we must then * ambiguous, we can stop. But in all the other cases, we must then
* explore all the backends (to find an object if there was match, * explore all the backends (to find an object if there was match,
* or to check that oid is not ambiguous if we have found 1 match in * or to check that oid is not ambiguous if we have found 1 match in
* the cache) * the cache)
* - We never explore the cache, go right to exploring the backends * - We never explore the cache, go right to exploring the backends
* We chose the latter : we explore directly the backends. * We chose the latter : we explore directly the backends.
*/ */
......
...@@ -57,9 +57,9 @@ int git_odb__hash_obj(git_oid *id, git_rawobj *obj) ...@@ -57,9 +57,9 @@ int git_odb__hash_obj(git_oid *id, git_rawobj *obj)
return git__rethrow(hdrlen, "Failed to hash object"); return git__rethrow(hdrlen, "Failed to hash object");
vec[0].data = header; vec[0].data = header;
vec[0].len = hdrlen; vec[0].len = hdrlen;
vec[1].data = obj->data; vec[1].data = obj->data;
vec[1].len = obj->len; vec[1].len = obj->len;
git_hash_vec(id, vec, 2); git_hash_vec(id, vec, 2);
......
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
/* DO NOT EXPORT */ /* DO NOT EXPORT */
typedef struct { typedef struct {
void *data; /**< Raw, decompressed object data. */ void *data; /**< Raw, decompressed object data. */
size_t len; /**< Total number of bytes in data. */ size_t len; /**< Total number of bytes in data. */
git_otype type; /**< Type of this object. */ git_otype type; /**< Type of this object. */
} git_rawobj; } git_rawobj;
/* EXPORT */ /* EXPORT */
......
...@@ -18,9 +18,9 @@ ...@@ -18,9 +18,9 @@
#include "git2/odb_backend.h" #include "git2/odb_backend.h"
#include "git2/types.h" #include "git2/types.h"
typedef struct { /* object header data */ typedef struct { /* object header data */
git_otype type; /* object type */ git_otype type; /* object type */
size_t size; /* object size */ size_t size; /* object size */
} obj_hdr; } obj_hdr;
typedef struct { typedef struct {
...@@ -124,7 +124,7 @@ static size_t get_object_header(obj_hdr *hdr, unsigned char *data) ...@@ -124,7 +124,7 @@ static size_t get_object_header(obj_hdr *hdr, unsigned char *data)
if (used == 0) if (used == 0)
return 0; return 0;
hdr->type = git_object_string2type(typename); hdr->type = git_object_string2type(typename);
used++; /* consume the space */ used++; /* consume the space */
/* /*
* length follows immediately in decimal (without * length follows immediately in decimal (without
...@@ -164,19 +164,19 @@ static size_t get_object_header(obj_hdr *hdr, unsigned char *data) ...@@ -164,19 +164,19 @@ static size_t get_object_header(obj_hdr *hdr, unsigned char *data)
static void init_stream(z_stream *s, void *out, size_t len) static void init_stream(z_stream *s, void *out, size_t len)
{ {
memset(s, 0, sizeof(*s)); memset(s, 0, sizeof(*s));
s->next_out = out; s->next_out = out;
s->avail_out = (uInt)len; s->avail_out = (uInt)len;
} }
static void set_stream_input(z_stream *s, void *in, size_t len) static void set_stream_input(z_stream *s, void *in, size_t len)
{ {
s->next_in = in; s->next_in = in;
s->avail_in = (uInt)len; s->avail_in = (uInt)len;
} }
static void set_stream_output(z_stream *s, void *out, size_t len) static void set_stream_output(z_stream *s, void *out, size_t len)
{ {
s->next_out = out; s->next_out = out;
s->avail_out = (uInt)len; s->avail_out = (uInt)len;
} }
...@@ -224,10 +224,10 @@ static int inflate_buffer(void *in, size_t inlen, void *out, size_t outlen) ...@@ -224,10 +224,10 @@ static int inflate_buffer(void *in, size_t inlen, void *out, size_t outlen)
memset(&zs, 0x0, sizeof(zs)); memset(&zs, 0x0, sizeof(zs));
zs.next_out = out; zs.next_out = out;
zs.avail_out = (uInt)outlen; zs.avail_out = (uInt)outlen;
zs.next_in = in; zs.next_in = in;
zs.avail_in = (uInt)inlen; zs.avail_in = (uInt)inlen;
if (inflateInit(&zs) < Z_OK) if (inflateInit(&zs) < Z_OK)
...@@ -314,7 +314,7 @@ static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_fbuffer *obj) ...@@ -314,7 +314,7 @@ static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_fbuffer *obj)
if (!buf) if (!buf)
return GIT_ENOMEM; return GIT_ENOMEM;
in = ((unsigned char *)obj->data) + used; in = ((unsigned char *)obj->data) + used;
len = obj->len - used; len = obj->len - used;
if (inflate_buffer(in, len, buf, hdr.size)) { if (inflate_buffer(in, len, buf, hdr.size)) {
free(buf); free(buf);
...@@ -323,7 +323,7 @@ static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_fbuffer *obj) ...@@ -323,7 +323,7 @@ static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_fbuffer *obj)
buf[hdr.size] = '\0'; buf[hdr.size] = '\0';
out->data = buf; out->data = buf;
out->len = hdr.size; out->len = hdr.size;
out->type = hdr.type; out->type = hdr.type;
return GIT_SUCCESS; return GIT_SUCCESS;
...@@ -364,7 +364,7 @@ static int inflate_disk_obj(git_rawobj *out, git_fbuffer *obj) ...@@ -364,7 +364,7 @@ static int inflate_disk_obj(git_rawobj *out, git_fbuffer *obj)
buf[hdr.size] = '\0'; buf[hdr.size] = '\0';
out->data = buf; out->data = buf;
out->len = hdr.size; out->len = hdr.size;
out->type = hdr.type; out->type = hdr.type;
return GIT_SUCCESS; return GIT_SUCCESS;
...@@ -392,7 +392,7 @@ static int read_loose(git_rawobj *out, const char *loc) ...@@ -392,7 +392,7 @@ static int read_loose(git_rawobj *out, const char *loc)
assert(out && loc); assert(out && loc);
out->data = NULL; out->data = NULL;
out->len = 0; out->len = 0;
out->type = GIT_OBJ_BAD; out->type = GIT_OBJ_BAD;
if (git_futils_readbuffer(&obj, loc) < 0) if (git_futils_readbuffer(&obj, loc) < 0)
...@@ -443,7 +443,7 @@ static int read_header_loose(git_rawobj *out, const char *loc) ...@@ -443,7 +443,7 @@ static int read_header_loose(git_rawobj *out, const char *loc)
goto cleanup; goto cleanup;
} }
out->len = header_obj.size; out->len = header_obj.size;
out->type = header_obj.type; out->type = header_obj.type;
cleanup: cleanup:
...@@ -694,8 +694,8 @@ static int format_object_header(char *hdr, size_t n, size_t obj_len, git_otype o ...@@ -694,8 +694,8 @@ static int format_object_header(char *hdr, size_t n, size_t obj_len, git_otype o
const char *type_str = git_object_type2string(obj_type); const char *type_str = git_object_type2string(obj_type);
int len = snprintf(hdr, n, "%s %"PRIuZ, type_str, obj_len); int len = snprintf(hdr, n, "%s %"PRIuZ, type_str, obj_len);
assert(len > 0); /* otherwise snprintf() is broken */ assert(len > 0); /* otherwise snprintf() is broken */
assert(((size_t) len) < n); /* otherwise the caller is broken! */ assert(((size_t) len) < n); /* otherwise the caller is broken! */
if (len < 0 || ((size_t) len) >= n) if (len < 0 || ((size_t) len) >= n)
return git__throw(GIT_ERROR, "Failed to format object header. Length is out of bounds"); return git__throw(GIT_ERROR, "Failed to format object header. Length is out of bounds");
...@@ -708,7 +708,7 @@ int loose_backend__stream(git_odb_stream **stream_out, git_odb_backend *_backend ...@@ -708,7 +708,7 @@ int loose_backend__stream(git_odb_stream **stream_out, git_odb_backend *_backend
loose_writestream *stream; loose_writestream *stream;
char hdr[64], tmp_path[GIT_PATH_MAX]; char hdr[64], tmp_path[GIT_PATH_MAX];
int hdrlen; int hdrlen;
int error; int error;
assert(_backend); assert(_backend);
......
...@@ -30,9 +30,9 @@ struct pack_backend { ...@@ -30,9 +30,9 @@ struct pack_backend {
/** /**
* The wonderful tale of a Packed Object lookup query * The wonderful tale of a Packed Object lookup query
* =================================================== * ===================================================
* A riveting and epic story of epicness and ASCII * A riveting and epic story of epicness and ASCII
* art, presented by yours truly, * art, presented by yours truly,
* Sir Vicent of Marti * Sir Vicent of Marti
* *
* *
* Chapter 1: Once upon a time... * Chapter 1: Once upon a time...
...@@ -43,32 +43,32 @@ struct pack_backend { ...@@ -43,32 +43,32 @@ struct pack_backend {
* | Creates the pack backend structure, initializes the * | Creates the pack backend structure, initializes the
* | callback pointers to our default read() and exist() methods, * | callback pointers to our default read() and exist() methods,
* | and tries to preload all the known packfiles in the ODB. * | and tries to preload all the known packfiles in the ODB.
* | * |
* |-# packfile_load_all * |-# packfile_load_all
* | Tries to find the `pack` folder, if it exists. ODBs without * | Tries to find the `pack` folder, if it exists. ODBs without
* | a pack folder are ignored altogether. If there's a `pack` folder * | a pack folder are ignored altogether. If there's a `pack` folder
* | we run a `dirent` callback through every file in the pack folder * | we run a `dirent` callback through every file in the pack folder
* | to find our packfiles. The packfiles are then sorted according * | to find our packfiles. The packfiles are then sorted according
* | to a sorting callback. * | to a sorting callback.
* | * |
* |-# packfile_load__cb * |-# packfile_load__cb
* | | This callback is called from `dirent` with every single file * | | This callback is called from `dirent` with every single file
* | | inside the pack folder. We find the packs by actually locating * | | inside the pack folder. We find the packs by actually locating
* | | their index (ends in ".idx"). From that index, we verify that * | | their index (ends in ".idx"). From that index, we verify that
* | | the corresponding packfile exists and is valid, and if so, we * | | the corresponding packfile exists and is valid, and if so, we
* | | add it to the pack list. * | | add it to the pack list.
* | | * | |
* | |-# packfile_check * | |-# packfile_check
* | Make sure that there's a packfile to back this index, and store * | Make sure that there's a packfile to back this index, and store
* | some very basic information regarding the packfile itself, * | some very basic information regarding the packfile itself,
* | such as the full path, the size, and the modification time. * | such as the full path, the size, and the modification time.
* | We don't actually open the packfile to check for internal consistency. * | We don't actually open the packfile to check for internal consistency.
* | * |
* |-# packfile_sort__cb * |-# packfile_sort__cb
* Sort all the preloaded packs according to some specific criteria: * Sort all the preloaded packs according to some specific criteria:
* we prioritize the "newer" packs because it's more likely they * we prioritize the "newer" packs because it's more likely they
* contain the objects we are looking for, and we prioritize local * contain the objects we are looking for, and we prioritize local
* packs over remote ones. * packs over remote ones.
* *
* *
* *
...@@ -76,41 +76,41 @@ struct pack_backend { ...@@ -76,41 +76,41 @@ struct pack_backend {
* A standard packed `exist` query for an OID * A standard packed `exist` query for an OID
* -------------------------------------------------- * --------------------------------------------------
* *
* # pack_backend__exists * # pack_backend__exists
* | Check if the given SHA1 oid exists in any of the packs * | Check if the given SHA1 oid exists in any of the packs
* | that have been loaded for our ODB. * | that have been loaded for our ODB.
* | * |
* |-# pack_entry_find * |-# pack_entry_find
* | Iterate through all the packs that have been preloaded * | Iterate through all the packs that have been preloaded
* | (starting by the pack where the latest object was found) * | (starting by the pack where the latest object was found)
* | to try to find the OID in one of them. * | to try to find the OID in one of them.
* | * |
* |-# pack_entry_find1 * |-# pack_entry_find1
* | Check the index of an individual pack to see if the SHA1 * | Check the index of an individual pack to see if the SHA1
* | OID can be found. If we can find the offset to that SHA1 * | OID can be found. If we can find the offset to that SHA1
* | inside of the index, that means the object is contained * | inside of the index, that means the object is contained
* | inside of the packfile and we can stop searching. * | inside of the packfile and we can stop searching.
* | Before returning, we verify that the packfile behing the * | Before returning, we verify that the packfile behing the
* | index we are searching still exists on disk. * | index we are searching still exists on disk.
* | * |
* |-# pack_entry_find_offset * |-# pack_entry_find_offset
* | | Mmap the actual index file to disk if it hasn't been opened * | | Mmap the actual index file to disk if it hasn't been opened
* | | yet, and run a binary search through it to find the OID. * | | yet, and run a binary search through it to find the OID.
* | | See <http://book.git-scm.com/7_the_packfile.html> for specifics * | | See <http://book.git-scm.com/7_the_packfile.html> for specifics
* | | on the Packfile Index format and how do we find entries in it. * | | on the Packfile Index format and how do we find entries in it.
* | | * | |
* | |-# pack_index_open * | |-# pack_index_open
* | | Guess the name of the index based on the full path to the * | | Guess the name of the index based on the full path to the
* | | packfile, open it and verify its contents. Only if the index * | | packfile, open it and verify its contents. Only if the index
* | | has not been opened already. * | | has not been opened already.
* | | * | |
* | |-# pack_index_check * | |-# pack_index_check
* | Mmap the index file and do a quick run through the header * | Mmap the index file and do a quick run through the header
* | to guess the index version (right now we support v1 and v2), * | to guess the index version (right now we support v1 and v2),
* | and to verify that the size of the index makes sense. * | and to verify that the size of the index makes sense.
* | * |
* |-# packfile_open * |-# packfile_open
* See `packfile_open` in Chapter 3 * See `packfile_open` in Chapter 3
* *
* *
* *
...@@ -170,7 +170,7 @@ GIT_INLINE(int) pack_window_contains(git_mwindow *win, off_t offset) ...@@ -170,7 +170,7 @@ GIT_INLINE(int) pack_window_contains(git_mwindow *win, off_t offset)
/* We must promise at least 20 bytes (one hash) after the /* We must promise at least 20 bytes (one hash) after the
* offset is available from this window, otherwise the offset * offset is available from this window, otherwise the offset
* is not actually in this window and a different window (which * is not actually in this window and a different window (which
* has that one hash excess) must be used. This is to support * has that one hash excess) must be used. This is to support
* the object header and delta base parsing routines below. * the object header and delta base parsing routines below.
*/ */
return git_mwindow_contains(win, offset + 20); return git_mwindow_contains(win, offset + 20);
...@@ -184,7 +184,7 @@ static int packfile_sort__cb(const void *a_, const void *b_) ...@@ -184,7 +184,7 @@ static int packfile_sort__cb(const void *a_, const void *b_)
/* /*
* Local packs tend to contain objects specific to our * Local packs tend to contain objects specific to our
* variant of the project than remote ones. In addition, * variant of the project than remote ones. In addition,
* remote ones could be on a network mounted filesystem. * remote ones could be on a network mounted filesystem.
* Favor local ones for these reasons. * Favor local ones for these reasons.
*/ */
......
...@@ -15,7 +15,7 @@ static signed char from_hex[] = { ...@@ -15,7 +15,7 @@ static signed char from_hex[] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 00 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 00 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 10 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 10 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 20 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 20 */
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 30 */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 30 */
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 40 */ -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 40 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 50 */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 50 */
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 60 */ -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 60 */
...@@ -43,7 +43,7 @@ int git_oid_fromstrn(git_oid *out, const char *str, size_t length) ...@@ -43,7 +43,7 @@ int git_oid_fromstrn(git_oid *out, const char *str, size_t length)
for (p = 0; p < length; p += 2) { for (p = 0; p < length; p += 2) {
int v = (from_hex[(unsigned char)str[p + 0]] << 4) int v = (from_hex[(unsigned char)str[p + 0]] << 4)
| from_hex[(unsigned char)str[p + 1]]; | from_hex[(unsigned char)str[p + 1]];
if (v < 0) if (v < 0)
return git__throw(GIT_ENOTOID, "Failed to generate sha1. Given string is not a valid sha1 hash"); return git__throw(GIT_ENOTOID, "Failed to generate sha1. Given string is not a valid sha1 hash");
...@@ -104,7 +104,7 @@ char *git_oid_to_string(char *out, size_t n, const git_oid *oid) ...@@ -104,7 +104,7 @@ char *git_oid_to_string(char *out, size_t n, const git_oid *oid)
if (!out || n == 0 || !oid) if (!out || n == 0 || !oid)
return ""; return "";
n--; /* allow room for terminating NUL */ n--; /* allow room for terminating NUL */
if (n > 0) { if (n > 0) {
git_oid_fmt(str, oid); git_oid_fmt(str, oid);
......
...@@ -52,7 +52,7 @@ static void pack_index_free(struct git_pack_file *p) ...@@ -52,7 +52,7 @@ static void pack_index_free(struct git_pack_file *p)
} }
} }
static int pack_index_check(const char *path, struct git_pack_file *p) static int pack_index_check(const char *path, struct git_pack_file *p)
{ {
struct git_pack_idx_header *hdr; struct git_pack_idx_header *hdr;
uint32_t version, nr, i, *index; uint32_t version, nr, i, *index;
...@@ -108,7 +108,7 @@ static int pack_index_check(const char *path, struct git_pack_file *p) ...@@ -108,7 +108,7 @@ static int pack_index_check(const char *path, struct git_pack_file *p)
index = idx_map; index = idx_map;
if (version > 1) if (version > 1)
index += 2; /* skip index header */ index += 2; /* skip index header */
for (i = 0; i < 256; i++) { for (i = 0; i < 256; i++) {
uint32_t n = ntohl(index[i]); uint32_t n = ntohl(index[i]);
...@@ -122,10 +122,10 @@ static int pack_index_check(const char *path, struct git_pack_file *p) ...@@ -122,10 +122,10 @@ static int pack_index_check(const char *path, struct git_pack_file *p)
if (version == 1) { if (version == 1) {
/* /*
* Total size: * Total size:
* - 256 index entries 4 bytes each * - 256 index entries 4 bytes each
* - 24-byte entries * nr (20-byte sha1 + 4-byte offset) * - 24-byte entries * nr (20-byte sha1 + 4-byte offset)
* - 20-byte SHA1 of the packfile * - 20-byte SHA1 of the packfile
* - 20-byte SHA1 file checksum * - 20-byte SHA1 file checksum
*/ */
if (idx_size != 4*256 + nr * 24 + 20 + 20) { if (idx_size != 4*256 + nr * 24 + 20 + 20) {
git_futils_mmap_free(&p->index_map); git_futils_mmap_free(&p->index_map);
...@@ -134,13 +134,13 @@ static int pack_index_check(const char *path, struct git_pack_file *p) ...@@ -134,13 +134,13 @@ static int pack_index_check(const char *path, struct git_pack_file *p)
} else if (version == 2) { } else if (version == 2) {
/* /*
* Minimum size: * Minimum size:
* - 8 bytes of header * - 8 bytes of header
* - 256 index entries 4 bytes each * - 256 index entries 4 bytes each
* - 20-byte sha1 entry * nr * - 20-byte sha1 entry * nr
* - 4-byte crc entry * nr * - 4-byte crc entry * nr
* - 4-byte offset entry * nr * - 4-byte offset entry * nr
* - 20-byte SHA1 of the packfile * - 20-byte SHA1 of the packfile
* - 20-byte SHA1 file checksum * - 20-byte SHA1 file checksum
* And after the 4-byte offset table might be a * And after the 4-byte offset table might be a
* variable sized table containing 8-byte entries * variable sized table containing 8-byte entries
* for offsets larger than 2^31. * for offsets larger than 2^31.
...@@ -245,8 +245,8 @@ int git_packfile_unpack_header( ...@@ -245,8 +245,8 @@ int git_packfile_unpack_header(
unsigned long used; unsigned long used;
/* pack_window_open() assures us we have [base, base + 20) available /* pack_window_open() assures us we have [base, base + 20) available
* as a range that we can look at at. (Its actually the hash * as a range that we can look at at. (Its actually the hash
* size that is assured.) With our object header encoding * size that is assured.) With our object header encoding
* the maximum deflated object size is 2^137, which is just * the maximum deflated object size is 2^137, which is just
* insane, so we know won't exceed what we have been given. * insane, so we know won't exceed what we have been given.
*/ */
...@@ -435,8 +435,8 @@ off_t get_delta_base( ...@@ -435,8 +435,8 @@ off_t get_delta_base(
/* pack_window_open() assured us we have [base_info, base_info + 20) /* pack_window_open() assured us we have [base_info, base_info + 20)
* as a range that we can look at without walking off the * as a range that we can look at without walking off the
* end of the mapped window. Its actually the hash size * end of the mapped window. Its actually the hash size
* that is assured. An OFS_DELTA longer than the hash size * that is assured. An OFS_DELTA longer than the hash size
* is stupid, as then a REF_DELTA would be smaller to store. * is stupid, as then a REF_DELTA would be smaller to store.
*/ */
if (type == GIT_OBJ_OFS_DELTA) { if (type == GIT_OBJ_OFS_DELTA) {
...@@ -446,13 +446,13 @@ off_t get_delta_base( ...@@ -446,13 +446,13 @@ off_t get_delta_base(
while (c & 128) { while (c & 128) {
base_offset += 1; base_offset += 1;
if (!base_offset || MSB(base_offset, 7)) if (!base_offset || MSB(base_offset, 7))
return 0; /* overflow */ return 0; /* overflow */
c = base_info[used++]; c = base_info[used++];
base_offset = (base_offset << 7) + (c & 127); base_offset = (base_offset << 7) + (c & 127);
} }
base_offset = delta_obj_offset - base_offset; base_offset = delta_obj_offset - base_offset;
if (base_offset <= 0 || base_offset >= delta_obj_offset) if (base_offset <= 0 || base_offset >= delta_obj_offset)
return 0; /* out of bound */ return 0; /* out of bound */
*curpos += used; *curpos += used;
} else if (type == GIT_OBJ_REF_DELTA) { } else if (type == GIT_OBJ_REF_DELTA) {
/* If we have the cooperative cache, search in it first */ /* If we have the cooperative cache, search in it first */
...@@ -650,7 +650,7 @@ static off_t nth_packed_object_offset(const struct git_pack_file *p, uint32_t n) ...@@ -650,7 +650,7 @@ static off_t nth_packed_object_offset(const struct git_pack_file *p, uint32_t n)
return off; return off;
index += p->num_objects * 4 + (off & 0x7fffffff) * 8; index += p->num_objects * 4 + (off & 0x7fffffff) * 8;
return (((uint64_t)ntohl(*((uint32_t *)(index + 0)))) << 32) | return (((uint64_t)ntohl(*((uint32_t *)(index + 0)))) << 32) |
ntohl(*((uint32_t *)(index + 4))); ntohl(*((uint32_t *)(index + 4)));
} }
} }
...@@ -703,7 +703,7 @@ static int pack_entry_find_offset( ...@@ -703,7 +703,7 @@ static int pack_entry_find_offset(
#endif #endif
/* Use git.git lookup code */ /* Use git.git lookup code */
pos = sha1_entry_pos(index, stride, 0, lo, hi, p->num_objects, short_oid->id); pos = sha1_entry_pos(index, stride, 0, lo, hi, p->num_objects, short_oid->id);
if (pos >= 0) { if (pos >= 0) {
/* An object matching exactly the oid was found */ /* An object matching exactly the oid was found */
......
...@@ -38,7 +38,7 @@ struct git_pack_header { ...@@ -38,7 +38,7 @@ struct git_pack_header {
* Very old git binaries will also compare the first 4 bytes to the * Very old git binaries will also compare the first 4 bytes to the
* next 4 bytes in the index and abort with a "non-monotonic index" * next 4 bytes in the index and abort with a "non-monotonic index"
* error if the second 4 byte word is smaller than the first 4 * error if the second 4 byte word is smaller than the first 4
* byte word. This would be true in the proposed future index * byte word. This would be true in the proposed future index
* format as idx_signature would be greater than idx_version. * format as idx_signature would be greater than idx_version.
*/ */
......
...@@ -23,8 +23,8 @@ int git_path_basename_r(char *buffer, size_t bufflen, const char *path) ...@@ -23,8 +23,8 @@ int git_path_basename_r(char *buffer, size_t bufflen, const char *path)
/* Empty or NULL string gets treated as "." */ /* Empty or NULL string gets treated as "." */
if (path == NULL || *path == '\0') { if (path == NULL || *path == '\0') {
startp = "."; startp = ".";
len = 1; len = 1;
goto Exit; goto Exit;
} }
...@@ -36,7 +36,7 @@ int git_path_basename_r(char *buffer, size_t bufflen, const char *path) ...@@ -36,7 +36,7 @@ int git_path_basename_r(char *buffer, size_t bufflen, const char *path)
/* All slashes becomes "/" */ /* All slashes becomes "/" */
if (endp == path && *endp == '/') { if (endp == path && *endp == '/') {
startp = "/"; startp = "/";
len = 1; len = 1;
goto Exit; goto Exit;
} }
...@@ -53,7 +53,7 @@ Exit: ...@@ -53,7 +53,7 @@ Exit:
return result; return result;
} }
if (len > (int)bufflen-1) { if (len > (int)bufflen-1) {
len = (int)bufflen-1; len = (int)bufflen-1;
result = GIT_ENOMEM; result = GIT_ENOMEM;
} }
...@@ -70,103 +70,103 @@ Exit: ...@@ -70,103 +70,103 @@ Exit:
*/ */
int git_path_dirname_r(char *buffer, size_t bufflen, const char *path) int git_path_dirname_r(char *buffer, size_t bufflen, const char *path)
{ {
const char *endp; const char *endp;
int result, len; int result, len;
/* Empty or NULL string gets treated as "." */ /* Empty or NULL string gets treated as "." */
if (path == NULL || *path == '\0') { if (path == NULL || *path == '\0') {
path = "."; path = ".";
len = 1; len = 1;
goto Exit; goto Exit;
} }
/* Strip trailing slashes */ /* Strip trailing slashes */
endp = path + strlen(path) - 1; endp = path + strlen(path) - 1;
while (endp > path && *endp == '/') while (endp > path && *endp == '/')
endp--; endp--;
/* Find the start of the dir */ /* Find the start of the dir */
while (endp > path && *endp != '/') while (endp > path && *endp != '/')
endp--; endp--;
/* Either the dir is "/" or there are no slashes */ /* Either the dir is "/" or there are no slashes */
if (endp == path) { if (endp == path) {
path = (*endp == '/') ? "/" : "."; path = (*endp == '/') ? "/" : ".";
len = 1; len = 1;
goto Exit; goto Exit;
} }
do { do {
endp--; endp--;
} while (endp > path && *endp == '/'); } while (endp > path && *endp == '/');
len = endp - path +1; len = endp - path +1;
#ifdef GIT_WIN32 #ifdef GIT_WIN32
/* Mimic unix behavior where '/.git' returns '/': 'C:/.git' will return /* Mimic unix behavior where '/.git' returns '/': 'C:/.git' will return
'C:/' here */ 'C:/' here */
if (len == 2 && isalpha(path[0]) && path[1] == ':') { if (len == 2 && isalpha(path[0]) && path[1] == ':') {
len = 3; len = 3;
goto Exit; goto Exit;
} }
#endif #endif
Exit: Exit:
result = len; result = len;
if (len+1 > GIT_PATH_MAX) { if (len+1 > GIT_PATH_MAX) {
return GIT_ENOMEM; return GIT_ENOMEM;
} }
if (buffer == NULL) if (buffer == NULL)
return result; return result;
if (len > (int)bufflen-1) { if (len > (int)bufflen-1) {
len = (int)bufflen-1; len = (int)bufflen-1;
result = GIT_ENOMEM; result = GIT_ENOMEM;
} }
if (len >= 0) { if (len >= 0) {
memmove(buffer, path, len); memmove(buffer, path, len);
buffer[len] = 0; buffer[len] = 0;
} }
return result; return result;
} }
char *git_path_dirname(const char *path) char *git_path_dirname(const char *path)
{ {
char *dname = NULL; char *dname = NULL;
int len; int len;
len = (path ? strlen(path) : 0) + 2; len = (path ? strlen(path) : 0) + 2;
dname = (char *)git__malloc(len); dname = (char *)git__malloc(len);
if (dname == NULL) if (dname == NULL)
return NULL; return NULL;
if (git_path_dirname_r(dname, len, path) < GIT_SUCCESS) { if (git_path_dirname_r(dname, len, path) < GIT_SUCCESS) {
free(dname); free(dname);
return NULL; return NULL;
} }
return dname; return dname;
} }
char *git_path_basename(const char *path) char *git_path_basename(const char *path)
{ {
char *bname = NULL; char *bname = NULL;
int len; int len;
len = (path ? strlen(path) : 0) + 2; len = (path ? strlen(path) : 0) + 2;
bname = (char *)git__malloc(len); bname = (char *)git__malloc(len);
if (bname == NULL) if (bname == NULL)
return NULL; return NULL;
if (git_path_basename_r(bname, len, path) < GIT_SUCCESS) { if (git_path_basename_r(bname, len, path) < GIT_SUCCESS) {
free(bname); free(bname);
return NULL; return NULL;
} }
return bname; return bname;
} }
......
...@@ -163,11 +163,11 @@ static ssize_t parse_len(const char *line) ...@@ -163,11 +163,11 @@ static ssize_t parse_len(const char *line)
/* /*
* As per the documentation, the syntax is: * As per the documentation, the syntax is:
* *
* pkt-line = data-pkt / flush-pkt * pkt-line = data-pkt / flush-pkt
* data-pkt = pkt-len pkt-payload * data-pkt = pkt-len pkt-payload
* pkt-len = 4*(HEXDIG) * pkt-len = 4*(HEXDIG)
* pkt-payload = (pkt-len -4)*(OCTET) * pkt-payload = (pkt-len -4)*(OCTET)
* flush-pkt = "0000" * flush-pkt = "0000"
* *
* Which means that the first four bytes are the length of the line, * Which means that the first four bytes are the length of the line,
* in ASCII hexadecimal (including itself) * in ASCII hexadecimal (including itself)
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "sha1.h" #include "sha1.h"
extern void ppc_sha1_core(uint32_t *hash, const unsigned char *p, extern void ppc_sha1_core(uint32_t *hash, const unsigned char *p,
unsigned int nblocks); unsigned int nblocks);
int ppc_SHA1_Init(ppc_SHA_CTX *c) int ppc_SHA1_Init(ppc_SHA_CTX *c)
{ {
......
...@@ -8,29 +8,29 @@ ...@@ -8,29 +8,29 @@
#include "common.h" #include "common.h"
#include "pqueue.h" #include "pqueue.h"
#define left(i) ((i) << 1) #define left(i) ((i) << 1)
#define right(i) (((i) << 1) + 1) #define right(i) (((i) << 1) + 1)
#define parent(i) ((i) >> 1) #define parent(i) ((i) >> 1)
int git_pqueue_init(git_pqueue *q, size_t n, git_pqueue_cmp cmppri) int git_pqueue_init(git_pqueue *q, size_t n, git_pqueue_cmp cmppri)
{ {
assert(q); assert(q);
/* Need to allocate n+1 elements since element 0 isn't used. */ /* Need to allocate n+1 elements since element 0 isn't used. */
if ((q->d = malloc((n + 1) * sizeof(void *))) == NULL) if ((q->d = malloc((n + 1) * sizeof(void *))) == NULL)
return GIT_ENOMEM; return GIT_ENOMEM;
q->size = 1; q->size = 1;
q->avail = q->step = (n + 1); /* see comment above about n+1 */ q->avail = q->step = (n + 1); /* see comment above about n+1 */
q->cmppri = cmppri; q->cmppri = cmppri;
return GIT_SUCCESS; return GIT_SUCCESS;
} }
void git_pqueue_free(git_pqueue *q) void git_pqueue_free(git_pqueue *q)
{ {
free(q->d); free(q->d);
q->d = NULL; q->d = NULL;
} }
...@@ -41,101 +41,101 @@ void git_pqueue_clear(git_pqueue *q) ...@@ -41,101 +41,101 @@ void git_pqueue_clear(git_pqueue *q)
size_t git_pqueue_size(git_pqueue *q) size_t git_pqueue_size(git_pqueue *q)
{ {
/* queue element 0 exists but doesn't count since it isn't used. */ /* queue element 0 exists but doesn't count since it isn't used. */
return (q->size - 1); return (q->size - 1);
} }
static void bubble_up(git_pqueue *q, size_t i) static void bubble_up(git_pqueue *q, size_t i)
{ {
size_t parent_node; size_t parent_node;
void *moving_node = q->d[i]; void *moving_node = q->d[i];
for (parent_node = parent(i); for (parent_node = parent(i);
((i > 1) && q->cmppri(q->d[parent_node], moving_node)); ((i > 1) && q->cmppri(q->d[parent_node], moving_node));
i = parent_node, parent_node = parent(i)) { i = parent_node, parent_node = parent(i)) {
q->d[i] = q->d[parent_node]; q->d[i] = q->d[parent_node];
} }
q->d[i] = moving_node; q->d[i] = moving_node;
} }
static size_t maxchild(git_pqueue *q, size_t i) static size_t maxchild(git_pqueue *q, size_t i)
{ {
size_t child_node = left(i); size_t child_node = left(i);
if (child_node >= q->size) if (child_node >= q->size)
return 0; return 0;
if ((child_node + 1) < q->size && if ((child_node + 1) < q->size &&
q->cmppri(q->d[child_node], q->d[child_node + 1])) q->cmppri(q->d[child_node], q->d[child_node + 1]))
child_node++; /* use right child instead of left */ child_node++; /* use right child instead of left */
return child_node; return child_node;
} }
static void percolate_down(git_pqueue *q, size_t i) static void percolate_down(git_pqueue *q, size_t i)
{ {
size_t child_node; size_t child_node;
void *moving_node = q->d[i]; void *moving_node = q->d[i];
while ((child_node = maxchild(q, i)) != 0 && while ((child_node = maxchild(q, i)) != 0 &&
q->cmppri(moving_node, q->d[child_node])) { q->cmppri(moving_node, q->d[child_node])) {
q->d[i] = q->d[child_node]; q->d[i] = q->d[child_node];
i = child_node; i = child_node;
} }
q->d[i] = moving_node; q->d[i] = moving_node;
} }
int git_pqueue_insert(git_pqueue *q, void *d) int git_pqueue_insert(git_pqueue *q, void *d)
{ {
void *tmp; void *tmp;
size_t i; size_t i;
size_t newsize; size_t newsize;
if (!q) return 1; if (!q) return 1;
/* allocate more memory if necessary */ /* allocate more memory if necessary */
if (q->size >= q->avail) { if (q->size >= q->avail) {
newsize = q->size + q->step; newsize = q->size + q->step;
if ((tmp = realloc(q->d, sizeof(void *) * newsize)) == NULL) if ((tmp = realloc(q->d, sizeof(void *) * newsize)) == NULL)
return GIT_ENOMEM; return GIT_ENOMEM;
q->d = tmp; q->d = tmp;
q->avail = newsize; q->avail = newsize;
} }
/* insert item */ /* insert item */
i = q->size++; i = q->size++;
q->d[i] = d; q->d[i] = d;
bubble_up(q, i); bubble_up(q, i);
return GIT_SUCCESS; return GIT_SUCCESS;
} }
void *git_pqueue_pop(git_pqueue *q) void *git_pqueue_pop(git_pqueue *q)
{ {
void *head; void *head;
if (!q || q->size == 1) if (!q || q->size == 1)
return NULL; return NULL;
head = q->d[1]; head = q->d[1];
q->d[1] = q->d[--q->size]; q->d[1] = q->d[--q->size];
percolate_down(q, 1); percolate_down(q, 1);
return head; return head;
} }
void *git_pqueue_peek(git_pqueue *q) void *git_pqueue_peek(git_pqueue *q)
{ {
if (!q || q->size == 1) if (!q || q->size == 1)
return NULL; return NULL;
return q->d[1]; return q->d[1];
} }
...@@ -13,9 +13,9 @@ typedef int (*git_pqueue_cmp)(void *a, void *b); ...@@ -13,9 +13,9 @@ typedef int (*git_pqueue_cmp)(void *a, void *b);
/** the priority queue handle */ /** the priority queue handle */
typedef struct { typedef struct {
size_t size, avail, step; size_t size, avail, step;
git_pqueue_cmp cmppri; git_pqueue_cmp cmppri;
void **d; void **d;
} git_pqueue; } git_pqueue;
...@@ -23,7 +23,7 @@ typedef struct { ...@@ -23,7 +23,7 @@ typedef struct {
* initialize the queue * initialize the queue
* *
* @param n the initial estimate of the number of queue items for which memory * @param n the initial estimate of the number of queue items for which memory
* should be preallocated * should be preallocated
* @param cmppri the callback function to compare two nodes of the queue * @param cmppri the callback function to compare two nodes of the queue
* *
* @Return the handle or NULL for insufficent memory * @Return the handle or NULL for insufficent memory
......
...@@ -205,7 +205,7 @@ int git_reflog_read(git_reflog **reflog, git_reference *ref) ...@@ -205,7 +205,7 @@ int git_reflog_read(git_reflog **reflog, git_reference *ref)
} }
int git_reflog_write(git_reference *ref, const git_oid *oid_old, int git_reflog_write(git_reference *ref, const git_oid *oid_old,
const git_signature *committer, const char *msg) const git_signature *committer, const char *msg)
{ {
int error; int error;
char old[GIT_OID_HEXSZ+1]; char old[GIT_OID_HEXSZ+1];
......
...@@ -494,7 +494,7 @@ static int packed_load(git_repository *repo) ...@@ -494,7 +494,7 @@ static int packed_load(git_repository *repo)
} }
error = reference_read(&packfile, &ref_cache->packfile_time, error = reference_read(&packfile, &ref_cache->packfile_time,
repo->path_repository, GIT_PACKEDREFS_FILE, &updated); repo->path_repository, GIT_PACKEDREFS_FILE, &updated);
/* /*
* If we couldn't find the file, we need to clear the table and * If we couldn't find the file, we need to clear the table and
...@@ -827,7 +827,7 @@ static int packed_write(git_repository *repo) ...@@ -827,7 +827,7 @@ static int packed_write(git_repository *repo)
const void *GIT_UNUSED(_unused); const void *GIT_UNUSED(_unused);
GIT_HASHTABLE_FOREACH(repo->references.packfile, _unused, reference, GIT_HASHTABLE_FOREACH(repo->references.packfile, _unused, reference,
git_vector_insert(&packing_list, reference); /* cannot fail: vector already has the right size */ git_vector_insert(&packing_list, reference); /* cannot fail: vector already has the right size */
); );
} }
...@@ -905,7 +905,7 @@ static int _reference_available_cb(const char *ref, void *data) ...@@ -905,7 +905,7 @@ static int _reference_available_cb(const char *ref, void *data)
const char *lead = reflen < newlen ? new : ref; const char *lead = reflen < newlen ? new : ref;
if (!strncmp(new, ref, cmplen) && if (!strncmp(new, ref, cmplen) &&
lead[cmplen] == '/') lead[cmplen] == '/')
return GIT_EEXISTS; return GIT_EEXISTS;
} }
...@@ -1054,7 +1054,7 @@ int git_reference_create_symbolic(git_reference **ref_out, git_repository *repo, ...@@ -1054,7 +1054,7 @@ int git_reference_create_symbolic(git_reference **ref_out, git_repository *repo,
* need a new reference because we can't make a symbolic ref out * need a new reference because we can't make a symbolic ref out
* of an oid one. * of an oid one.
* If if didn't exist, then we need to create a new one anyway. * If if didn't exist, then we need to create a new one anyway.
*/ */
if (ref && ref->type & GIT_REF_SYMBOLIC){ if (ref && ref->type & GIT_REF_SYMBOLIC){
updated = 1; updated = 1;
} else { } else {
...@@ -1113,7 +1113,7 @@ int git_reference_create_oid(git_reference **ref_out, git_repository *repo, cons ...@@ -1113,7 +1113,7 @@ int git_reference_create_oid(git_reference **ref_out, git_repository *repo, cons
* need a new reference because we can't make a symbolic ref out * need a new reference because we can't make a symbolic ref out
* of an oid one. * of an oid one.
* If if didn't exist, then we need to create a new one anyway. * If if didn't exist, then we need to create a new one anyway.
*/ */
if (ref && ref-> type & GIT_REF_OID){ if (ref && ref-> type & GIT_REF_OID){
updated = 1; updated = 1;
} else { } else {
...@@ -1344,10 +1344,10 @@ int git_reference_rename(git_reference *ref, const char *new_name, int force) ...@@ -1344,10 +1344,10 @@ int git_reference_rename(git_reference *ref, const char *new_name, int force)
* writes reflogs by default in any repo with a working directory: * writes reflogs by default in any repo with a working directory:
* *
* "We only enable reflogs in repositories that have a working directory * "We only enable reflogs in repositories that have a working directory
* associated with them, as shared/bare repositories do not have * associated with them, as shared/bare repositories do not have
* an easy means to prune away old log entries, or may fail logging * an easy means to prune away old log entries, or may fail logging
* entirely if the user's gecos information is not valid during a push. * entirely if the user's gecos information is not valid during a push.
* This heuristic was suggested on the mailing list by Junio." * This heuristic was suggested on the mailing list by Junio."
* *
* Shawn O. Pearce - 0bee59186976b1d9e6b2dd77332480c9480131d5 * Shawn O. Pearce - 0bee59186976b1d9e6b2dd77332480c9480131d5
* *
......
...@@ -55,7 +55,7 @@ int git_refspec_src_match(const git_refspec *refspec, const char *refname) ...@@ -55,7 +55,7 @@ int git_refspec_src_match(const git_refspec *refspec, const char *refname)
return git__fnmatch(refspec->src, refname, 0); return git__fnmatch(refspec->src, refname, 0);
} }
int git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, const char *name) int git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, const char *name)
{ {
size_t baselen, namelen; size_t baselen, namelen;
......
...@@ -110,7 +110,7 @@ int git_remote_get(git_remote **out, git_config *cfg, const char *name) ...@@ -110,7 +110,7 @@ int git_remote_get(git_remote **out, git_config *cfg, const char *name)
error = git_config_get_string(cfg, buf, &val); error = git_config_get_string(cfg, buf, &val);
if (error < GIT_SUCCESS) { if (error < GIT_SUCCESS) {
error = git__rethrow(error, "Remote's url doesn't exist"); error = git__rethrow(error, "Remote's url doesn't exist");
goto cleanup; goto cleanup;
} }
......
...@@ -52,11 +52,11 @@ ...@@ -52,11 +52,11 @@
*/ */
#if defined(__i386__) || defined(__x86_64__) #if defined(__i386__) || defined(__x86_64__)
#define setW(x, val) (*(volatile unsigned int *)&W(x) = (val)) #define setW(x, val) (*(volatile unsigned int *)&W(x) = (val))
#elif defined(__GNUC__) && defined(__arm__) #elif defined(__GNUC__) && defined(__arm__)
#define setW(x, val) do { W(x) = (val); __asm__("":::"memory"); } while (0) #define setW(x, val) do { W(x) = (val); __asm__("":::"memory"); } while (0)
#else #else
#define setW(x, val) (W(x) = (val)) #define setW(x, val) (W(x) = (val))
#endif #endif
/* /*
...@@ -67,10 +67,10 @@ ...@@ -67,10 +67,10 @@
*/ */
#if defined(__i386__) || defined(__x86_64__) || \ #if defined(__i386__) || defined(__x86_64__) || \
defined(_M_IX86) || defined(_M_X64) || \ defined(_M_IX86) || defined(_M_X64) || \
defined(__ppc__) || defined(__ppc64__) || \ defined(__ppc__) || defined(__ppc64__) || \
defined(__powerpc__) || defined(__powerpc64__) || \ defined(__powerpc__) || defined(__powerpc64__) || \
defined(__s390__) || defined(__s390x__) defined(__s390__) || defined(__s390x__)
#define get_be32(p) ntohl(*(const unsigned int *)(p)) #define get_be32(p) ntohl(*(const unsigned int *)(p))
#define put_be32(p, v) do { *(unsigned int *)(p) = htonl(v); } while (0) #define put_be32(p, v) do { *(unsigned int *)(p) = htonl(v); } while (0)
...@@ -80,14 +80,14 @@ ...@@ -80,14 +80,14 @@
#define get_be32(p) ( \ #define get_be32(p) ( \
(*((const unsigned char *)(p) + 0) << 24) | \ (*((const unsigned char *)(p) + 0) << 24) | \
(*((const unsigned char *)(p) + 1) << 16) | \ (*((const unsigned char *)(p) + 1) << 16) | \
(*((const unsigned char *)(p) + 2) << 8) | \ (*((const unsigned char *)(p) + 2) << 8) | \
(*((const unsigned char *)(p) + 3) << 0) ) (*((const unsigned char *)(p) + 3) << 0) )
#define put_be32(p, v) do { \ #define put_be32(p, v) do { \
unsigned int __v = (v); \ unsigned int __v = (v); \
*((unsigned char *)(p) + 0) = __v >> 24; \ *((unsigned char *)(p) + 0) = __v >> 24; \
*((unsigned char *)(p) + 1) = __v >> 16; \ *((unsigned char *)(p) + 1) = __v >> 16; \
*((unsigned char *)(p) + 2) = __v >> 8; \ *((unsigned char *)(p) + 2) = __v >> 8; \
*((unsigned char *)(p) + 3) = __v >> 0; } while (0) *((unsigned char *)(p) + 3) = __v >> 0; } while (0)
#endif #endif
...@@ -106,11 +106,11 @@ ...@@ -106,11 +106,11 @@
E += TEMP + SHA_ROL(A,5) + (fn) + (constant); \ E += TEMP + SHA_ROL(A,5) + (fn) + (constant); \
B = SHA_ROR(B, 2); } while (0) B = SHA_ROR(B, 2); } while (0)
#define T_0_15(t, A, B, C, D, E) SHA_ROUND(t, SHA_SRC, (((C^D)&B)^D) , 0x5a827999, A, B, C, D, E ) #define T_0_15(t, A, B, C, D, E) SHA_ROUND(t, SHA_SRC, (((C^D)&B)^D) , 0x5a827999, A, B, C, D, E )
#define T_16_19(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (((C^D)&B)^D) , 0x5a827999, A, B, C, D, E ) #define T_16_19(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (((C^D)&B)^D) , 0x5a827999, A, B, C, D, E )
#define T_20_39(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (B^C^D) , 0x6ed9eba1, A, B, C, D, E ) #define T_20_39(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (B^C^D) , 0x6ed9eba1, A, B, C, D, E )
#define T_40_59(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, ((B&C)+(D&(B^C))) , 0x8f1bbcdc, A, B, C, D, E ) #define T_40_59(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, ((B&C)+(D&(B^C))) , 0x8f1bbcdc, A, B, C, D, E )
#define T_60_79(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (B^C^D) , 0xca62c1d6, A, B, C, D, E ) #define T_60_79(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (B^C^D) , 0xca62c1d6, A, B, C, D, E )
static void blk_SHA1_Block(blk_SHA_CTX *ctx, const unsigned int *data) static void blk_SHA1_Block(blk_SHA_CTX *ctx, const unsigned int *data)
{ {
......
...@@ -14,69 +14,69 @@ ...@@ -14,69 +14,69 @@
* Conventional binary search loop looks like this: * Conventional binary search loop looks like this:
* *
* unsigned lo, hi; * unsigned lo, hi;
* do { * do {
* unsigned mi = (lo + hi) / 2; * unsigned mi = (lo + hi) / 2;
* int cmp = "entry pointed at by mi" minus "target"; * int cmp = "entry pointed at by mi" minus "target";
* if (!cmp) * if (!cmp)
* return (mi is the wanted one) * return (mi is the wanted one)
* if (cmp > 0) * if (cmp > 0)
* hi = mi; "mi is larger than target" * hi = mi; "mi is larger than target"
* else * else
* lo = mi+1; "mi is smaller than target" * lo = mi+1; "mi is smaller than target"
* } while (lo < hi); * } while (lo < hi);
* *
* The invariants are: * The invariants are:
* *
* - When entering the loop, lo points at a slot that is never * - When entering the loop, lo points at a slot that is never
* above the target (it could be at the target), hi points at a * above the target (it could be at the target), hi points at a
* slot that is guaranteed to be above the target (it can never * slot that is guaranteed to be above the target (it can never
* be at the target). * be at the target).
* *
* - We find a point 'mi' between lo and hi (mi could be the same * - We find a point 'mi' between lo and hi (mi could be the same
* as lo, but never can be as same as hi), and check if it hits * as lo, but never can be as same as hi), and check if it hits
* the target. There are three cases: * the target. There are three cases:
* *
* - if it is a hit, we are happy. * - if it is a hit, we are happy.
* *
* - if it is strictly higher than the target, we set it to hi, * - if it is strictly higher than the target, we set it to hi,
* and repeat the search. * and repeat the search.
* *
* - if it is strictly lower than the target, we update lo to * - if it is strictly lower than the target, we update lo to
* one slot after it, because we allow lo to be at the target. * one slot after it, because we allow lo to be at the target.
* *
* If the loop exits, there is no matching entry. * If the loop exits, there is no matching entry.
* *
* When choosing 'mi', we do not have to take the "middle" but * When choosing 'mi', we do not have to take the "middle" but
* anywhere in between lo and hi, as long as lo <= mi < hi is * anywhere in between lo and hi, as long as lo <= mi < hi is
* satisfied. When we somehow know that the distance between the * satisfied. When we somehow know that the distance between the
* target and lo is much shorter than the target and hi, we could * target and lo is much shorter than the target and hi, we could
* pick mi that is much closer to lo than the midway. * pick mi that is much closer to lo than the midway.
* *
* Now, we can take advantage of the fact that SHA-1 is a good hash * Now, we can take advantage of the fact that SHA-1 is a good hash
* function, and as long as there are enough entries in the table, we * function, and as long as there are enough entries in the table, we
* can expect uniform distribution. An entry that begins with for * can expect uniform distribution. An entry that begins with for
* example "deadbeef..." is much likely to appear much later than in * example "deadbeef..." is much likely to appear much later than in
* the midway of the table. It can reasonably be expected to be near * the midway of the table. It can reasonably be expected to be near
* 87% (222/256) from the top of the table. * 87% (222/256) from the top of the table.
* *
* However, we do not want to pick "mi" too precisely. If the entry at * However, we do not want to pick "mi" too precisely. If the entry at
* the 87% in the above example turns out to be higher than the target * the 87% in the above example turns out to be higher than the target
* we are looking for, we would end up narrowing the search space down * we are looking for, we would end up narrowing the search space down
* only by 13%, instead of 50% we would get if we did a simple binary * only by 13%, instead of 50% we would get if we did a simple binary
* search. So we would want to hedge our bets by being less aggressive. * search. So we would want to hedge our bets by being less aggressive.
* *
* The table at "table" holds at least "nr" entries of "elem_size" * The table at "table" holds at least "nr" entries of "elem_size"
* bytes each. Each entry has the SHA-1 key at "key_offset". The * bytes each. Each entry has the SHA-1 key at "key_offset". The
* table is sorted by the SHA-1 key of the entries. The caller wants * table is sorted by the SHA-1 key of the entries. The caller wants
* to find the entry with "key", and knows that the entry at "lo" is * to find the entry with "key", and knows that the entry at "lo" is
* not higher than the entry it is looking for, and that the entry at * not higher than the entry it is looking for, and that the entry at
* "hi" is higher than the entry it is looking for. * "hi" is higher than the entry it is looking for.
*/ */
int sha1_entry_pos(const void *table, int sha1_entry_pos(const void *table,
size_t elem_size, size_t elem_size,
size_t key_offset, size_t key_offset,
unsigned lo, unsigned hi, unsigned nr, unsigned lo, unsigned hi, unsigned nr,
const unsigned char *key) const unsigned char *key)
{ {
const unsigned char *base = (const unsigned char*)table; const unsigned char *base = (const unsigned char*)table;
const unsigned char *hi_key, *lo_key; const unsigned char *hi_key, *lo_key;
...@@ -138,7 +138,7 @@ int sha1_entry_pos(const void *table, ...@@ -138,7 +138,7 @@ int sha1_entry_pos(const void *table,
* end up narrowing the search space by a smaller * end up narrowing the search space by a smaller
* amount (i.e. the distance between 'mi' and 'hi') * amount (i.e. the distance between 'mi' and 'hi')
* than what we would have (i.e. about half of 'lo' * than what we would have (i.e. about half of 'lo'
* and 'hi'). Hedge our bets to pick 'mi' less * and 'hi'). Hedge our bets to pick 'mi' less
* aggressively, i.e. make 'mi' a bit closer to the * aggressively, i.e. make 'mi' a bit closer to the
* middle than we would otherwise pick. * middle than we would otherwise pick.
*/ */
...@@ -154,7 +154,7 @@ int sha1_entry_pos(const void *table, ...@@ -154,7 +154,7 @@ int sha1_entry_pos(const void *table,
#ifdef INDEX_DEBUG_LOOKUP #ifdef INDEX_DEBUG_LOOKUP
printf("lo %u hi %u rg %u mi %u ", lo, hi, range, mi); printf("lo %u hi %u rg %u mi %u ", lo, hi, range, mi);
printf("ofs %u lov %x, hiv %x, kyv %x\n", printf("ofs %u lov %x, hiv %x, kyv %x\n",
ofs_0, lov, hiv, kyv); ofs_0, lov, hiv, kyv);
#endif #endif
if (!(lo <= mi && mi < hi)) { if (!(lo <= mi && mi < hi)) {
......
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
#include <stdlib.h> #include <stdlib.h>
int sha1_entry_pos(const void *table, int sha1_entry_pos(const void *table,
size_t elem_size, size_t elem_size,
size_t key_offset, size_t key_offset,
unsigned lo, unsigned hi, unsigned nr, unsigned lo, unsigned hi, unsigned nr,
const unsigned char *key); const unsigned char *key);
#endif #endif
...@@ -227,7 +227,7 @@ static int git_tag_create__internal( ...@@ -227,7 +227,7 @@ static int git_tag_create__internal(
} }
/** Ensure the tag name doesn't conflict with an already existing /** Ensure the tag name doesn't conflict with an already existing
* reference unless overwriting has explictly been requested **/ * reference unless overwriting has explictly been requested **/
if (new_ref != NULL) { if (new_ref != NULL) {
if (!allow_ref_overwrite) { if (!allow_ref_overwrite) {
git_oid_cpy(oid, git_reference_oid(new_ref)); git_oid_cpy(oid, git_reference_oid(new_ref));
...@@ -312,7 +312,7 @@ int git_tag_create_frombuffer(git_oid *oid, git_repository *repo, const char *bu ...@@ -312,7 +312,7 @@ int git_tag_create_frombuffer(git_oid *oid, git_repository *repo, const char *bu
} }
/** Ensure the tag name doesn't conflict with an already existing /** Ensure the tag name doesn't conflict with an already existing
* reference unless overwriting has explictly been requested **/ * reference unless overwriting has explictly been requested **/
if (new_ref != NULL) { if (new_ref != NULL) {
if (!allow_ref_overwrite) { if (!allow_ref_overwrite) {
git_oid_cpy(oid, git_reference_oid(new_ref)); git_oid_cpy(oid, git_reference_oid(new_ref));
...@@ -366,8 +366,8 @@ int git_tag__parse(git_tag *tag, git_odb_object *obj) ...@@ -366,8 +366,8 @@ int git_tag__parse(git_tag *tag, git_odb_object *obj)
} }
typedef struct { typedef struct {
git_vector *taglist; git_vector *taglist;
const char *pattern; const char *pattern;
} tag_filter_data; } tag_filter_data;
#define GIT_REFS_TAGS_DIR_LEN strlen(GIT_REFS_TAGS_DIR) #define GIT_REFS_TAGS_DIR_LEN strlen(GIT_REFS_TAGS_DIR)
......
...@@ -8,10 +8,10 @@ ...@@ -8,10 +8,10 @@
#include "thread-utils.h" #include "thread-utils.h"
#ifdef _WIN32 #ifdef _WIN32
# define WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN
# include <windows.h> # include <windows.h>
#elif defined(hpux) || defined(__hpux) || defined(_hpux) #elif defined(hpux) || defined(__hpux) || defined(_hpux)
# include <sys/pstat.h> # include <sys/pstat.h>
#endif #endif
/* /*
...@@ -20,11 +20,11 @@ ...@@ -20,11 +20,11 @@
* with this disgusting nest of #ifdefs. * with this disgusting nest of #ifdefs.
*/ */
#ifndef _SC_NPROCESSORS_ONLN #ifndef _SC_NPROCESSORS_ONLN
# ifdef _SC_NPROC_ONLN # ifdef _SC_NPROC_ONLN
# define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN # define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN
# elif defined _SC_CRAY_NCPU # elif defined _SC_CRAY_NCPU
# define _SC_NPROCESSORS_ONLN _SC_CRAY_NCPU # define _SC_NPROCESSORS_ONLN _SC_CRAY_NCPU
# endif # endif
#endif #endif
int git_online_cpus(void) int git_online_cpus(void)
......
...@@ -33,10 +33,10 @@ GIT_INLINE(void) git_atomic_set(git_atomic *a, int val) ...@@ -33,10 +33,10 @@ GIT_INLINE(void) git_atomic_set(git_atomic *a, int val)
/* Pthreads Mutex */ /* Pthreads Mutex */
#define git_mutex pthread_mutex_t #define git_mutex pthread_mutex_t
#define git_mutex_init(a) pthread_mutex_init(a, NULL) #define git_mutex_init(a) pthread_mutex_init(a, NULL)
#define git_mutex_lock(a) pthread_mutex_lock(a) #define git_mutex_lock(a) pthread_mutex_lock(a)
#define git_mutex_unlock(a) pthread_mutex_unlock(a) #define git_mutex_unlock(a) pthread_mutex_unlock(a)
#define git_mutex_free(a) pthread_mutex_destroy(a) #define git_mutex_free(a) pthread_mutex_destroy(a)
/* Pthreads condition vars -- disabled by now */ /* Pthreads condition vars -- disabled by now */
#define git_cond unsigned int //pthread_cond_t #define git_cond unsigned int //pthread_cond_t
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
typedef struct git_transport_caps { typedef struct git_transport_caps {
int common:1, int common:1,
ofs_delta:1; ofs_delta:1;
} git_transport_caps; } git_transport_caps;
/* /*
......
...@@ -387,8 +387,8 @@ static int git_negotiate_fetch(git_transport *transport, git_repository *repo, g ...@@ -387,8 +387,8 @@ static int git_negotiate_fetch(git_transport *transport, git_repository *repo, g
error = gitno_recv(&buf); error = gitno_recv(&buf);
if (error < GIT_SUCCESS) { if (error < GIT_SUCCESS) {
error = git__rethrow(error, "Error receiving data"); error = git__rethrow(error, "Error receiving data");
goto cleanup; goto cleanup;
} }
error = git_pkt_parse_line(&pkt, ptr, &line_end, buf.offset); error = git_pkt_parse_line(&pkt, ptr, &line_end, buf.offset);
if (error == GIT_ESHORTBUFFER) if (error == GIT_ESHORTBUFFER)
...@@ -535,7 +535,7 @@ static int git_close(git_transport *transport) ...@@ -535,7 +535,7 @@ static int git_close(git_transport *transport)
int s = t->socket; int s = t->socket;
int error; int error;
/* Can't do anything if there's an error, so don't bother checking */ /* Can't do anything if there's an error, so don't bother checking */
git_pkt_send_flush(s); git_pkt_send_flush(s);
error = close(s); error = close(s);
if (error < 0) if (error < 0)
......
...@@ -68,7 +68,7 @@ static int binsearch(void **dst, const void *x, size_t size, cmp_ptr_t cmp) ...@@ -68,7 +68,7 @@ static int binsearch(void **dst, const void *x, size_t size, cmp_ptr_t cmp)
} }
} }
/* Binary insertion sort, but knowing that the first "start" entries are sorted. Used in timsort. */ /* Binary insertion sort, but knowing that the first "start" entries are sorted. Used in timsort. */
static void bisort(void **dst, size_t start, size_t size, cmp_ptr_t cmp) static void bisort(void **dst, size_t start, size_t size, cmp_ptr_t cmp)
{ {
size_t i; size_t i;
...@@ -207,7 +207,7 @@ static void merge(void **dst, const struct tsort_run *stack, int stack_curr, str ...@@ -207,7 +207,7 @@ static void merge(void **dst, const struct tsort_run *stack, int stack_curr, str
if (resize(store, MIN(A, B)) < 0) if (resize(store, MIN(A, B)) < 0)
return; return;
storage = store->storage; storage = store->storage;
/* left merge */ /* left merge */
if (A < B) { if (A < B) {
......
...@@ -214,7 +214,7 @@ void git__hexdump(const char *buffer, size_t len) ...@@ -214,7 +214,7 @@ void git__hexdump(const char *buffer, size_t len)
printf("%02X ", (unsigned char)*line & 0xFF); printf("%02X ", (unsigned char)*line & 0xFF);
for (j = 0; j < (LINE_WIDTH - last_line); ++j) for (j = 0; j < (LINE_WIDTH - last_line); ++j)
printf(" "); printf(" ");
printf("| "); printf("| ");
...@@ -255,7 +255,7 @@ uint32_t git__hash(const void *key, int len, unsigned int seed) ...@@ -255,7 +255,7 @@ uint32_t git__hash(const void *key, int len, unsigned int seed)
case 3: h ^= data[2] << 16; case 3: h ^= data[2] << 16;
case 2: h ^= data[1] << 8; case 2: h ^= data[1] << 8;
case 1: h ^= data[0]; case 1: h ^= data[0];
h *= m; h *= m;
}; };
h ^= h >> 13; h ^= h >> 13;
...@@ -276,13 +276,13 @@ uint32_t git__hash(const void *key, int len, uint32_t seed) ...@@ -276,13 +276,13 @@ uint32_t git__hash(const void *key, int len, uint32_t seed)
{ {
#define MURMUR_BLOCK() {\ #define MURMUR_BLOCK() {\
k1 *= c1; \ k1 *= c1; \
k1 = git__rotl(k1,11);\ k1 = git__rotl(k1,11);\
k1 *= c2;\ k1 *= c2;\
h1 ^= k1;\ h1 ^= k1;\
h1 = h1*3 + 0x52dce729;\ h1 = h1*3 + 0x52dce729;\
c1 = c1*5 + 0x7b7d159c;\ c1 = c1*5 + 0x7b7d159c;\
c2 = c2*5 + 0x6bce6396;\ c2 = c2*5 + 0x6bce6396;\
} }
const uint8_t *data = (const uint8_t*)key; const uint8_t *data = (const uint8_t*)key;
...@@ -332,20 +332,20 @@ uint32_t git__hash(const void *key, int len, uint32_t seed) ...@@ -332,20 +332,20 @@ uint32_t git__hash(const void *key, int len, uint32_t seed)
*/ */
void **git__bsearch(const void *key, void **base, size_t nmemb, int (*compar)(const void *, const void *)) void **git__bsearch(const void *key, void **base, size_t nmemb, int (*compar)(const void *, const void *))
{ {
int lim, cmp; int lim, cmp;
void **p; void **p;
for (lim = nmemb; lim != 0; lim >>= 1) { for (lim = nmemb; lim != 0; lim >>= 1) {
p = base + (lim >> 1); p = base + (lim >> 1);
cmp = (*compar)(key, *p); cmp = (*compar)(key, *p);
if (cmp > 0) { /* key > p: move right */ if (cmp > 0) { /* key > p: move right */
base = p + 1; base = p + 1;
lim--; lim--;
} else if (cmp == 0) { } else if (cmp == 0) {
return (void **)p; return (void **)p;
} /* else move left */ } /* else move left */
} }
return NULL; return NULL;
} }
/** /**
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#define INCLUDE_util_h__ #define INCLUDE_util_h__
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
#define bitsizeof(x) (CHAR_BIT * sizeof(x)) #define bitsizeof(x) (CHAR_BIT * sizeof(x))
#define MSB(x, bits) ((x) & (~0ULL << (bitsizeof(x) - (bits)))) #define MSB(x, bits) ((x) & (~0ULL << (bitsizeof(x) - (bits))))
#ifndef min #ifndef min
# define min(a,b) ((a) < (b) ? (a) : (b)) # define min(a,b) ((a) < (b) ? (a) : (b))
......
...@@ -9,17 +9,17 @@ ...@@ -9,17 +9,17 @@
#include "common.h" #include "common.h"
#define FNM_NOMATCH 1 /* Match failed. */ #define FNM_NOMATCH 1 /* Match failed. */
#define FNM_NOSYS 2 /* Function not supported (unused). */ #define FNM_NOSYS 2 /* Function not supported (unused). */
#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */ #define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */
#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */ #define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */
#define FNM_PERIOD 0x04 /* Period must be matched by period. */ #define FNM_PERIOD 0x04 /* Period must be matched by period. */
#define FNM_LEADING_DIR 0x08 /* Ignore /<tail> after Imatch. */ #define FNM_LEADING_DIR 0x08 /* Ignore /<tail> after Imatch. */
#define FNM_CASEFOLD 0x10 /* Case insensitive search. */ #define FNM_CASEFOLD 0x10 /* Case insensitive search. */
#define FNM_IGNORECASE FNM_CASEFOLD #define FNM_IGNORECASE FNM_CASEFOLD
#define FNM_FILE_NAME FNM_PATHNAME #define FNM_FILE_NAME FNM_PATHNAME
extern int p_fnmatch(const char *pattern, const char *string, int flags); extern int p_fnmatch(const char *pattern, const char *string, int flags);
......
...@@ -29,7 +29,7 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs ...@@ -29,7 +29,7 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs
DWORD fmap_prot = 0; DWORD fmap_prot = 0;
DWORD view_prot = 0; DWORD view_prot = 0;
DWORD off_low = 0; DWORD off_low = 0;
DWORD off_hi = 0; DWORD off_hi = 0;
git_off_t page_start; git_off_t page_start;
git_off_t page_offset; git_off_t page_offset;
...@@ -71,7 +71,7 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs ...@@ -71,7 +71,7 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs
page_start = (offset / page_size) * page_size; page_start = (offset / page_size) * page_size;
page_offset = offset - page_start; page_offset = offset - page_start;
if (page_offset != 0) { /* offset must be multiple of page size */ if (page_offset != 0) { /* offset must be multiple of page size */
errno = EINVAL; errno = EINVAL;
return git__throw(GIT_ERROR, "Failed to mmap. Offset must be multiple of page size"); return git__throw(GIT_ERROR, "Failed to mmap. Offset must be multiple of page size");
} }
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
/* stat: file mode type testing macros */ /* stat: file mode type testing macros */
# define _S_IFLNK 0120000 # define _S_IFLNK 0120000
# define S_IFLNK _S_IFLNK # define S_IFLNK _S_IFLNK
# define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK) # define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK)
#endif #endif
......
...@@ -9,10 +9,10 @@ ...@@ -9,10 +9,10 @@
#if defined(_MSC_VER) #if defined(_MSC_VER)
/* access() mode parameter #defines */ /* access() mode parameter #defines */
# define F_OK 0 /* existence check */ # define F_OK 0 /* existence check */
# define W_OK 2 /* write mode check */ # define W_OK 2 /* write mode check */
# define R_OK 4 /* read mode check */ # define R_OK 4 /* read mode check */
# define lseek _lseeki64 # define lseek _lseeki64
# define stat _stat64 # define stat _stat64
...@@ -22,16 +22,16 @@ ...@@ -22,16 +22,16 @@
# define _S_IFLNK 0120000 # define _S_IFLNK 0120000
# define S_IFLNK _S_IFLNK # define S_IFLNK _S_IFLNK
# define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) # define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
# define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO) # define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO)
# define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK) # define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK)
# define mode_t unsigned short # define mode_t unsigned short
/* case-insensitive string comparison */ /* case-insensitive string comparison */
# define strcasecmp _stricmp # define strcasecmp _stricmp
# define strncasecmp _strnicmp # define strncasecmp _strnicmp
#if (_MSC_VER >= 1600) #if (_MSC_VER >= 1600)
# include <stdint.h> # include <stdint.h>
......
...@@ -144,13 +144,13 @@ int p_readlink(const char *link, char *target, size_t target_len) ...@@ -144,13 +144,13 @@ int p_readlink(const char *link, char *target, size_t target_len)
"'GetFinalPathNameByHandleA' is not available in this platform"); "'GetFinalPathNameByHandleA' is not available in this platform");
} }
hFile = CreateFile(link, // file to open hFile = CreateFile(link, // file to open
GENERIC_READ, // open for reading GENERIC_READ, // open for reading
FILE_SHARE_READ, // share for reading FILE_SHARE_READ, // share for reading
NULL, // default security NULL, // default security
OPEN_EXISTING, // existing file only OPEN_EXISTING, // existing file only
FILE_FLAG_BACKUP_SEMANTICS, // normal file FILE_FLAG_BACKUP_SEMANTICS, // normal file
NULL); // no attr. template NULL); // no attr. template
if (hFile == INVALID_HANDLE_VALUE) if (hFile == INVALID_HANDLE_VALUE)
return GIT_EOSERR; return GIT_EOSERR;
...@@ -163,7 +163,7 @@ int p_readlink(const char *link, char *target, size_t target_len) ...@@ -163,7 +163,7 @@ int p_readlink(const char *link, char *target, size_t target_len)
if (dwRet > 4) { if (dwRet > 4) {
/* Skip first 4 characters if they are "\\?\" */ /* Skip first 4 characters if they are "\\?\" */
if (target[0] == '\\' && target[1] == '\\' && target[2] == '?' && target[3] == '\\') { if (target[0] == '\\' && target[1] == '\\' && target[2] == '?' && target[3] == '\\') {
char tmp[GIT_PATH_MAX]; char tmp[GIT_PATH_MAX];
unsigned int offset = 4; unsigned int offset = 4;
dwRet -= 4; dwRet -= 4;
...@@ -189,7 +189,7 @@ int p_hide_directory__w32(const char *path) ...@@ -189,7 +189,7 @@ int p_hide_directory__w32(const char *path)
int error; int error;
error = SetFileAttributes(path, FILE_ATTRIBUTE_HIDDEN) != 0 ? error = SetFileAttributes(path, FILE_ATTRIBUTE_HIDDEN) != 0 ?
GIT_SUCCESS : GIT_ERROR; /* MSDN states a "non zero" value indicates a success */ GIT_SUCCESS : GIT_ERROR; /* MSDN states a "non zero" value indicates a success */
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
error = git__throw(GIT_EOSERR, "Failed to hide directory '%s'", path); error = git__throw(GIT_EOSERR, "Failed to hide directory '%s'", path);
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
#include "pthread.h" #include "pthread.h"
int pthread_create(pthread_t *GIT_RESTRICT thread, int pthread_create(pthread_t *GIT_RESTRICT thread,
const pthread_attr_t *GIT_RESTRICT GIT_UNUSED(attr), const pthread_attr_t *GIT_RESTRICT GIT_UNUSED(attr),
void *(*start_routine)(void*), void *GIT_RESTRICT arg) void *(*start_routine)(void*), void *GIT_RESTRICT arg)
{ {
GIT_UNUSED_ARG(attr); GIT_UNUSED_ARG(attr);
*thread = (pthread_t) CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)start_routine, arg, 0, NULL); *thread = (pthread_t) CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)start_routine, arg, 0, NULL);
...@@ -18,48 +18,48 @@ int pthread_create(pthread_t *GIT_RESTRICT thread, ...@@ -18,48 +18,48 @@ int pthread_create(pthread_t *GIT_RESTRICT thread,
int pthread_join(pthread_t thread, void **value_ptr) int pthread_join(pthread_t thread, void **value_ptr)
{ {
int ret; int ret;
ret = WaitForSingleObject(thread, INFINITE); ret = WaitForSingleObject(thread, INFINITE);
if (ret && value_ptr) if (ret && value_ptr)
GetExitCodeThread(thread, (void*) value_ptr); GetExitCodeThread(thread, (void*) value_ptr);
return -(!!ret); return -(!!ret);
} }
int pthread_mutex_init(pthread_mutex_t *GIT_RESTRICT mutex, int pthread_mutex_init(pthread_mutex_t *GIT_RESTRICT mutex,
const pthread_mutexattr_t *GIT_RESTRICT GIT_UNUSED(mutexattr)) const pthread_mutexattr_t *GIT_RESTRICT GIT_UNUSED(mutexattr))
{ {
GIT_UNUSED_ARG(mutexattr); GIT_UNUSED_ARG(mutexattr);
InitializeCriticalSection(mutex); InitializeCriticalSection(mutex);
return 0; return 0;
} }
int pthread_mutex_destroy(pthread_mutex_t *mutex) int pthread_mutex_destroy(pthread_mutex_t *mutex)
{ {
DeleteCriticalSection(mutex); DeleteCriticalSection(mutex);
return 0; return 0;
} }
int pthread_mutex_lock(pthread_mutex_t *mutex) int pthread_mutex_lock(pthread_mutex_t *mutex)
{ {
EnterCriticalSection(mutex); EnterCriticalSection(mutex);
return 0; return 0;
} }
int pthread_mutex_unlock(pthread_mutex_t *mutex) int pthread_mutex_unlock(pthread_mutex_t *mutex)
{ {
LeaveCriticalSection(mutex); LeaveCriticalSection(mutex);
return 0; return 0;
} }
int pthread_num_processors_np(void) int pthread_num_processors_np(void)
{ {
DWORD_PTR p, s; DWORD_PTR p, s;
int n = 0; int n = 0;
if (GetProcessAffinityMask(GetCurrentProcess(), &p, &s)) if (GetProcessAffinityMask(GetCurrentProcess(), &p, &s))
for (; p; p >>= 1) for (; p; p >>= 1)
n += p&1; n += p&1;
return n ? n : 1; return n ? n : 1;
} }
...@@ -25,8 +25,8 @@ typedef HANDLE pthread_t; ...@@ -25,8 +25,8 @@ typedef HANDLE pthread_t;
#define PTHREAD_MUTEX_INITIALIZER {(void*)-1}; #define PTHREAD_MUTEX_INITIALIZER {(void*)-1};
int pthread_create(pthread_t *GIT_RESTRICT, int pthread_create(pthread_t *GIT_RESTRICT,
const pthread_attr_t *GIT_RESTRICT, const pthread_attr_t *GIT_RESTRICT,
void *(*start_routine)(void*), void *__restrict); void *(*start_routine)(void*), void *__restrict);
int pthread_join(pthread_t, void **); int pthread_join(pthread_t, void **);
......
...@@ -139,7 +139,7 @@ clay_run_test( ...@@ -139,7 +139,7 @@ clay_run_test(
static void static void
clay_print_error(int num, const struct clay_error *error) clay_print_error(int num, const struct clay_error *error)
{ {
clay_print(" %d) Failure:\n", num); clay_print(" %d) Failure:\n", num);
clay_print("%s::%s (%s) [%s:%d] [-t%d]\n", clay_print("%s::%s (%s) [%s:%d] [-t%d]\n",
error->suite, error->suite,
...@@ -149,10 +149,10 @@ clay_print_error(int num, const struct clay_error *error) ...@@ -149,10 +149,10 @@ clay_print_error(int num, const struct clay_error *error)
error->line_number, error->line_number,
error->test_number); error->test_number);
clay_print(" %s\n", error->error_msg); clay_print(" %s\n", error->error_msg);
if (error->description != NULL) if (error->description != NULL)
clay_print(" %s\n", error->description); clay_print(" %s\n", error->description);
clay_print("\n"); clay_print("\n");
} }
...@@ -204,8 +204,8 @@ clay_usage(const char *arg) ...@@ -204,8 +204,8 @@ clay_usage(const char *arg)
{ {
printf("Usage: %s [options]\n\n", arg); printf("Usage: %s [options]\n\n", arg);
printf("Options:\n"); printf("Options:\n");
printf(" -tXX\t\tRun only the test number XX\n"); printf(" -tXX\t\tRun only the test number XX\n");
printf(" -sXX\t\tRun only the suite number XX\n"); printf(" -sXX\t\tRun only the suite number XX\n");
exit(-1); exit(-1);
} }
...@@ -691,7 +691,7 @@ extern void test_status_worktree__whole_repository(void); ...@@ -691,7 +691,7 @@ extern void test_status_worktree__whole_repository(void);
extern void test_status_worktree__empty_repository(void); extern void test_status_worktree__empty_repository(void);
static const struct clay_func _all_callbacks[] = { static const struct clay_func _all_callbacks[] = {
{"dont_traverse_dot", &test_core_dirent__dont_traverse_dot, 0}, {"dont_traverse_dot", &test_core_dirent__dont_traverse_dot, 0},
{"traverse_subfolder", &test_core_dirent__traverse_subfolder, 0}, {"traverse_subfolder", &test_core_dirent__traverse_subfolder, 0},
{"traverse_slash_terminated_folder", &test_core_dirent__traverse_slash_terminated_folder, 0}, {"traverse_slash_terminated_folder", &test_core_dirent__traverse_slash_terminated_folder, 0},
{"dont_traverse_empty_folders", &test_core_dirent__dont_traverse_empty_folders, 0}, {"dont_traverse_empty_folders", &test_core_dirent__dont_traverse_empty_folders, 0},
...@@ -717,63 +717,63 @@ static const struct clay_func _all_callbacks[] = { ...@@ -717,63 +717,63 @@ static const struct clay_func _all_callbacks[] = {
}; };
static const struct clay_suite _all_suites[] = { static const struct clay_suite _all_suites[] = {
{
"core::dirent",
{NULL, NULL, 0},
{NULL, NULL, 0},
&_all_callbacks[0], 5
},
{ {
"core::filebuf", "core::dirent",
{NULL, NULL, 0}, {NULL, NULL, 0},
{NULL, NULL, 0}, {NULL, NULL, 0},
&_all_callbacks[5], 3 &_all_callbacks[0], 5
}, },
{ {
"core::path", "core::filebuf",
{NULL, NULL, 0}, {NULL, NULL, 0},
{NULL, NULL, 0}, {NULL, NULL, 0},
&_all_callbacks[8], 5 &_all_callbacks[5], 3
}, },
{ {
"core::rmdir", "core::path",
{"initialize", &test_core_rmdir__initialize, 3}, {NULL, NULL, 0},
{NULL, NULL, 0}, {NULL, NULL, 0},
&_all_callbacks[13], 2 &_all_callbacks[8], 5
}, },
{ {
"core::string", "core::rmdir",
{NULL, NULL, 0}, {"initialize", &test_core_rmdir__initialize, 3},
{NULL, NULL, 0}, {NULL, NULL, 0},
&_all_callbacks[15], 2 &_all_callbacks[13], 2
}, },
{ {
"core::vector", "core::string",
{NULL, NULL, 0}, {NULL, NULL, 0},
{NULL, NULL, 0}, {NULL, NULL, 0},
&_all_callbacks[17], 3 &_all_callbacks[15], 2
}, },
{ {
"status::single", "core::vector",
{NULL, NULL, 0}, {NULL, NULL, 0},
{NULL, NULL, 0}, {NULL, NULL, 0},
&_all_callbacks[20], 1 &_all_callbacks[17], 3
}, },
{ {
"status::worktree", "status::single",
{"initialize", &test_status_worktree__initialize, 7}, {NULL, NULL, 0},
{"cleanup", &test_status_worktree__cleanup, 7}, {NULL, NULL, 0},
&_all_callbacks[21], 2 &_all_callbacks[20], 1
} },
{
"status::worktree",
{"initialize", &test_status_worktree__initialize, 7},
{"cleanup", &test_status_worktree__cleanup, 7},
&_all_callbacks[21], 2
}
}; };
static const char _suites_str[] = "core::dirent, core::filebuf, core::path, core::rmdir, core::string, core::vector, status::single, status::worktree"; static const char _suites_str[] = "core::dirent, core::filebuf, core::path, core::rmdir, core::string, core::vector, status::single, status::worktree";
int _CC main(int argc, char *argv[]) int _CC main(int argc, char *argv[])
{ {
return clay_test( return clay_test(
argc, argv, _suites_str, argc, argv, _suites_str,
_all_callbacks, 23, _all_callbacks, 23,
_all_suites, 8 _all_suites, 8
); );
} }
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
#include "fileops.h" #include "fileops.h"
typedef struct name_data { typedef struct name_data {
int count; /* return count */ int count; /* return count */
char *name; /* filename */ char *name; /* filename */
} name_data; } name_data;
typedef struct walk_data { typedef struct walk_data {
char *sub; /* sub-directory name */ char *sub; /* sub-directory name */
name_data *names; /* name state data */ name_data *names; /* name state data */
} walk_data; } walk_data;
...@@ -112,9 +112,9 @@ void test_core_dirent__dont_traverse_dot(void) ...@@ -112,9 +112,9 @@ void test_core_dirent__dont_traverse_dot(void)
setup(&dot); setup(&dot);
cl_git_pass(git_futils_direach(path_buffer, cl_git_pass(git_futils_direach(path_buffer,
sizeof(path_buffer), sizeof(path_buffer),
one_entry, one_entry,
&dot)); &dot));
check_counts(&dot); check_counts(&dot);
} }
...@@ -138,9 +138,9 @@ void test_core_dirent__traverse_subfolder(void) ...@@ -138,9 +138,9 @@ void test_core_dirent__traverse_subfolder(void)
setup(&sub); setup(&sub);
cl_git_pass(git_futils_direach(path_buffer, cl_git_pass(git_futils_direach(path_buffer,
sizeof(path_buffer), sizeof(path_buffer),
one_entry, one_entry,
&sub)); &sub));
check_counts(&sub); check_counts(&sub);
} }
...@@ -158,9 +158,9 @@ void test_core_dirent__traverse_slash_terminated_folder(void) ...@@ -158,9 +158,9 @@ void test_core_dirent__traverse_slash_terminated_folder(void)
setup(&sub_slash); setup(&sub_slash);
cl_git_pass(git_futils_direach(path_buffer, cl_git_pass(git_futils_direach(path_buffer,
sizeof(path_buffer), sizeof(path_buffer),
one_entry, one_entry,
&sub_slash)); &sub_slash));
check_counts(&sub_slash); check_counts(&sub_slash);
} }
...@@ -181,17 +181,17 @@ void test_core_dirent__dont_traverse_empty_folders(void) ...@@ -181,17 +181,17 @@ void test_core_dirent__dont_traverse_empty_folders(void)
setup(&empty); setup(&empty);
cl_git_pass(git_futils_direach(path_buffer, cl_git_pass(git_futils_direach(path_buffer,
sizeof(path_buffer), sizeof(path_buffer),
one_entry, one_entry,
&empty)); &empty));
check_counts(&empty); check_counts(&empty);
/* make sure callback not called */ /* make sure callback not called */
cl_git_pass(git_futils_direach(path_buffer, cl_git_pass(git_futils_direach(path_buffer,
sizeof(path_buffer), sizeof(path_buffer),
dont_call_me, dont_call_me,
&empty)); &empty));
} }
static name_data odd_names[] = { static name_data odd_names[] = {
...@@ -199,7 +199,7 @@ static name_data odd_names[] = { ...@@ -199,7 +199,7 @@ static name_data odd_names[] = {
{ 0, "odd/..c" }, { 0, "odd/..c" },
/* the following don't work on cygwin/win32 */ /* the following don't work on cygwin/win32 */
/* { 0, "odd/.b." }, */ /* { 0, "odd/.b." }, */
/* { 0, "odd/..d.." }, */ /* { 0, "odd/..d.." }, */
{ 0, NULL } { 0, NULL }
}; };
static walk_data odd = { static walk_data odd = {
...@@ -214,9 +214,9 @@ void test_core_dirent__traverse_weird_filenames(void) ...@@ -214,9 +214,9 @@ void test_core_dirent__traverse_weird_filenames(void)
setup(&odd); setup(&odd);
cl_git_pass(git_futils_direach(path_buffer, cl_git_pass(git_futils_direach(path_buffer,
sizeof(path_buffer), sizeof(path_buffer),
one_entry, one_entry,
&odd)); &odd));
check_counts(&odd); check_counts(&odd);
} }
...@@ -24,7 +24,7 @@ void test_core_vector__1(void) ...@@ -24,7 +24,7 @@ void test_core_vector__1(void)
git_vector_insert(&x, (void*) 0xdef); git_vector_insert(&x, (void*) 0xdef);
git_vector_insert(&x, (void*) 0x123); git_vector_insert(&x, (void*) 0x123);
git_vector_remove(&x, 0); // used to read past array bounds. git_vector_remove(&x, 0); // used to read past array bounds.
git_vector_free(&x); git_vector_free(&x);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment