Commit 72556cc63ba93a187589921c6008caf92686ea9c

Russell Belfer 2014-02-20T14:27:10

Address PR comments * Make GIT_INLINE an internal definition so it cannot be used in public headers * Fix language in CONTRIBUTING * Make index caps API use signed instead of unsigned values

diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 0ae75c7..06aa4c1 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -89,7 +89,7 @@ code snippet.
 
 The public API of `libgit2` is [ANSI C](http://en.wikipedia.org/wiki/ANSI_C)
 (a.k.a. C89) compatible.  Internally, `libgit2` is written using a portable
-subset of C99 - in order to compiler with GCC, Clang, MSVC, etc., we keep
+subset of C99 - in order to compile with GCC, Clang, MSVC, etc., we keep
 local variable declarations at the tops of blocks only and avoid `//` style
 comments.  Additionally, `libgit2` follows some extra conventions for
 function and type naming, code formatting, and testing.
@@ -109,14 +109,15 @@ are any unresolved issues to jump in on.  Also, here is a list of some
 smaller project ideas that could help you become familiar with the code
 base and make a nice first step:
 
-* Convert a `git_*modulename*_foreach()` callback-based iteration API
-  into a `git_*modulename*_iterator` object with a create/advance style
-  of API.  This helps folks writing language bindings and usually isn't
-  too complicated.
-* Write a new `examples/` program that mirrors a particular core git
-  command.  (See `examples/diff.c` for example.)  This lets you (and us)
-  easily exercise a particular facet of the API and measure compatability
-  and feature parity with core git.
+* Look at the `examples/` programs, find an existing one that mirrors a
+  core Git command and add a missing command-line option.  There are many
+  gaps right now and this helps demonstrate how to use the library.
+* Pick a Git command that is not emulates in `examples/` and write a new
+  example that mirrors the behavior.  Examples don't have to be perfect
+  emulations, but should demonstrate how to use the libgit2 APIs to get
+  results that are similar to Git commands.  This lets you (and us) easily
+  exercise a particular facet of the API and measure compatability and
+  feature parity with core git.
 * Submit a PR to clarify documentation! While we do try to document all of
   the APIs, your fresh eyes on the documentation will find areas that are
   confusing much more easily.
diff --git a/include/git2/common.h b/include/git2/common.h
index dca0c9c..4927154 100644
--- a/include/git2/common.h
+++ b/include/git2/common.h
@@ -37,13 +37,6 @@
 # define GIT_EXTERN(type) extern type
 #endif
 
-/** Declare a function as always inlined. */
-#if defined(_MSC_VER)
-# define GIT_INLINE(type) static __inline type
-#else
-# define GIT_INLINE(type) static inline type
-#endif
-
 /** Declare a function's takes printf style arguments. */
 #ifdef __GNUC__
 # define GIT_FORMAT_PRINTF(a,b) __attribute__((format (printf, a, b)))
diff --git a/include/git2/index.h b/include/git2/index.h
index 4363a3b..ae919e1 100644
--- a/include/git2/index.h
+++ b/include/git2/index.h
@@ -120,10 +120,10 @@ typedef struct git_index_entry {
 
 /** Capabilities of system that affect index actions. */
 typedef enum {
-	GIT_INDEXCAP_IGNORE_CASE = 1u,
-	GIT_INDEXCAP_NO_FILEMODE = 2u,
-	GIT_INDEXCAP_NO_SYMLINKS = 4u,
-	GIT_INDEXCAP_FROM_OWNER  = ~0u
+	GIT_INDEXCAP_IGNORE_CASE = 1,
+	GIT_INDEXCAP_NO_FILEMODE = 2,
+	GIT_INDEXCAP_NO_SYMLINKS = 4,
+	GIT_INDEXCAP_FROM_OWNER  = -1,
 } git_indexcap_t;
 
 /** Callback for APIs that add/remove/update files matching pathspec */
@@ -206,7 +206,7 @@ GIT_EXTERN(git_repository *) git_index_owner(const git_index *index);
  * @param index An existing index object
  * @return A combination of GIT_INDEXCAP values
  */
-GIT_EXTERN(unsigned int) git_index_caps(const git_index *index);
+GIT_EXTERN(int) git_index_caps(const git_index *index);
 
 /**
  * Set index capabilities flags.
@@ -219,7 +219,7 @@ GIT_EXTERN(unsigned int) git_index_caps(const git_index *index);
  * @param caps A combination of GIT_INDEXCAP values
  * @return 0 on success, -1 on failure
  */
-GIT_EXTERN(int) git_index_set_caps(git_index *index, unsigned int caps);
+GIT_EXTERN(int) git_index_set_caps(git_index *index, int caps);
 
 /**
  * Update the contents of an existing index object in memory by reading
diff --git a/src/array.h b/src/array.h
index 1d4e1c2..f8a4872 100644
--- a/src/array.h
+++ b/src/array.h
@@ -7,7 +7,7 @@
 #ifndef INCLUDE_array_h__
 #define INCLUDE_array_h__
 
-#include "util.h"
+#include "common.h"
 
 /*
  * Use this to declare a typesafe resizable array of items, a la:
diff --git a/src/bitvec.h b/src/bitvec.h
index fd6f0cc..544832d 100644
--- a/src/bitvec.h
+++ b/src/bitvec.h
@@ -7,7 +7,7 @@
 #ifndef INCLUDE_bitvec_h__
 #define INCLUDE_bitvec_h__
 
-#include "util.h"
+#include "common.h"
 
 /*
  * This is a silly little fixed length bit vector type that will store
diff --git a/src/common.h b/src/common.h
index e315b59..d389cf8 100644
--- a/src/common.h
+++ b/src/common.h
@@ -10,6 +10,13 @@
 #include "git2/common.h"
 #include "cc-compat.h"
 
+/** Declare a function as always inlined. */
+#if defined(_MSC_VER)
+# define GIT_INLINE(type) static __inline type
+#else
+# define GIT_INLINE(type) static inline type
+#endif
+
 #include <assert.h>
 #include <errno.h>
 #include <limits.h>
diff --git a/src/index.c b/src/index.c
index aa1aebf..e0c0022 100644
--- a/src/index.c
+++ b/src/index.c
@@ -438,7 +438,7 @@ static int create_index_error(int error, const char *msg)
 	return error;
 }
 
-int git_index_set_caps(git_index *index, unsigned int caps)
+int git_index_set_caps(git_index *index, int caps)
 {
 	unsigned int old_ignore_case;
 
@@ -474,7 +474,7 @@ int git_index_set_caps(git_index *index, unsigned int caps)
 	return 0;
 }
 
-unsigned int git_index_caps(const git_index *index)
+int git_index_caps(const git_index *index)
 {
 	return ((index->ignore_case ? GIT_INDEXCAP_IGNORE_CASE : 0) |
 			(index->distrust_filemode ? GIT_INDEXCAP_NO_FILEMODE : 0) |
diff --git a/src/merge.c b/src/merge.c
index 97c1479..12ff1c9 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -2364,7 +2364,7 @@ done:
 int git_merge__indexes(git_repository *repo, git_index *index_new)
 {
 	git_index *index_repo = NULL;
-	unsigned int index_repo_caps = 0;
+	int index_repo_caps = 0;
 	git_vector paths = GIT_VECTOR_INIT;
 	size_t index_conflicts = 0, wd_conflicts = 0, conflicts, i;
 	char *path;
diff --git a/src/vector.h b/src/vector.h
index f825685..682b6ad 100644
--- a/src/vector.h
+++ b/src/vector.h
@@ -7,7 +7,7 @@
 #ifndef INCLUDE_vector_h__
 #define INCLUDE_vector_h__
 
-#include "git2/common.h"
+#include "common.h"
 
 typedef int (*git_vector_cmp)(const void *, const void *);
 
diff --git a/tests/repo/iterator.c b/tests/repo/iterator.c
index 56b5185..fb70a9e 100644
--- a/tests/repo/iterator.c
+++ b/tests/repo/iterator.c
@@ -156,7 +156,7 @@ void test_repo_iterator__index_icase(void)
 {
 	git_iterator *i;
 	git_index *index;
-	unsigned int caps;
+	int caps;
 
 	g_repo = cl_git_sandbox_init("icase");