Update libgit2 version from 0.20.0 to 0.21.1

It seems that couple of our patches are now upstream.

Also, set EXECUTABLES= in the build.sh file so the test
binary gets validated and translated.

Also, fix compiler warnings (mostly adding ll to
integer constants).

R=binji@chromium.org

Review URL: https://codereview.chromium.org/544893003

git-svn-id: https://naclports.googlecode.com/svn/trunk/src@1648 7dad1e8b-422e-d2af-fbf5-8013b78bd812
diff --git a/build_tools/XCompile-nacl.cmake b/build_tools/XCompile-nacl.cmake
index 6c4b48f..059ad64 100644
--- a/build_tools/XCompile-nacl.cmake
+++ b/build_tools/XCompile-nacl.cmake
@@ -5,6 +5,8 @@
 # If you already have a toolchain file setup, you may use that instead of this
 # file.
 
+SET(NACL 1)
+
 # the name of the target operating system
 SET(CMAKE_SYSTEM_NAME Linux)
 
diff --git a/ports/libgit2/build.sh b/ports/libgit2/build.sh
index 8adccde..fa20232 100644
--- a/ports/libgit2/build.sh
+++ b/ports/libgit2/build.sh
@@ -2,7 +2,20 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-if [ "${NACL_LIBC}" = "newlib" ]; then
+EXECUTABLES="libgit2_clar"
+
+if [ "${NACL_SHARED}" != "1" ]; then
   EXTRA_CMAKE_ARGS="-DBUILD_SHARED_LIBS=OFF"
-  NACLPORTS_CPPFLAGS+=" -I${NACLPORTS_INCLUDE}/glibc-compat"
+fi
+
+if [ "${NACL_LIBC}" = "newlib" ]; then
+  NACLPORTS_CPPFLAGS="-I${NACLPORTS_INCLUDE}/glibc-compat"
+  # newlib headers generate a lot of char-subscript warnings
+  # for macros such as tolower()
+  NACLPORTS_CPPFLAGS+=" -Wno-char-subscripts"
+  if [ "$NACL_ARCH" != "arm" ]; then
+    # Our x86 version of gcc generates a lot of strict aliasing
+    # warnings.
+    NACLPORTS_CPPFLAGS+=" -fno-strict-aliasing"
+  fi
 fi
diff --git a/ports/libgit2/nacl.patch b/ports/libgit2/nacl.patch
index 01e516e..13387b7 100644
--- a/ports/libgit2/nacl.patch
+++ b/ports/libgit2/nacl.patch
@@ -1,36 +1,32 @@
 diff --git a/CMakeLists.txt b/CMakeLists.txt
-index ac1032a..a238fbb 100644
+index 6f1a97e..664d3f4 100644
 --- a/CMakeLists.txt
 +++ b/CMakeLists.txt
-@@ -72,14 +72,21 @@ SET(LIB_INSTALL_DIR lib CACHE PATH "Where to install libraries to.")
- SET(INCLUDE_INSTALL_DIR include CACHE PATH "Where to install headers to.")
- 
- FUNCTION(TARGET_OS_LIBRARIES target)
-+	MESSAGE(">>>>>>> Libc = $ENV{NACL_LIBC}")
-+
- 	IF(WIN32)
- 		TARGET_LINK_LIBRARIES(${target} ws2_32)
- 	ELSEIF(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
- 		TARGET_LINK_LIBRARIES(${target} socket nsl)
- 		SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lsocket -lnsl" PARENT_SCOPE)
- 	ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Linux")
--		TARGET_LINK_LIBRARIES(${target} rt)
--		SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lrt" PARENT_SCOPE)
-+		IF($ENV{NACL_LIBC} STREQUAL "newlib")
-+			TARGET_LINK_LIBRARIES(${target} glibc-compat)
-+			SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lglibc-compat" PARENT_SCOPE)
-+		ELSE()
-+			TARGET_LINK_LIBRARIES(${target} rt)
-+			SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lrt" PARENT_SCOPE)
-+		ENDIF()
+@@ -91,6 +91,10 @@ FUNCTION(TARGET_OS_LIBRARIES target)
+ 		TARGET_LINK_LIBRARIES(${target} rt)
+ 		SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lrt" PARENT_SCOPE)
  	ENDIF()
++	IF("$ENV{NACL_LIBC}" STREQUAL "newlib")
++		TARGET_LINK_LIBRARIES(${target} glibc-compat)
++		SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lglibc-compat" PARENT_SCOPE)
++	ENDIF()
  
- 	IF(USE_ICONV)
+ 	IF(THREADSAFE)
+ 		TARGET_LINK_LIBRARIES(${target} ${CMAKE_THREAD_LIBS_INIT})
+@@ -364,6 +368,8 @@ FILE(GLOB SRC_H include/git2.h include/git2/*.h include/git2/sys/*.h)
+ IF (WIN32 AND NOT CYGWIN)
+ 	ADD_DEFINITIONS(-DWIN32 -D_WIN32_WINNT=0x0501)
+ 	FILE(GLOB SRC_OS src/win32/*.c src/win32/*.h)
++ELSEIF (NACL)
++	ADD_DEFINITIONS(-DNO_MMAP)
+ ELSEIF (AMIGA)
+ 	ADD_DEFINITIONS(-DNO_ADDRINFO -DNO_READDIR_R -DNO_MMAP)
+ ELSE()
 diff --git a/src/pool.c b/src/pool.c
-index d484769..287e08e 100644
+index a516ff9..b1c2bfe 100644
 --- a/src/pool.c
 +++ b/src/pool.c
-@@ -313,7 +313,7 @@ uint32_t git_pool__system_page_size(void)
+@@ -312,7 +312,7 @@ uint32_t git_pool__system_page_size(void)
  #elif defined(__amigaos4__)
  		size = (uint32_t)4096; /* 4K as there is no global value we can query */
  #else
@@ -39,25 +35,39 @@
  #endif
  
  		size -= 2 * sizeof(void *); /* allow space for malloc overhead */
-diff --git a/tests/blame/buffer.c b/tests/blame/buffer.c
-index 912ee98..340b1dc 100644
---- a/tests/blame/buffer.c
-+++ b/tests/blame/buffer.c
-@@ -1,7 +1,7 @@
- #include "blame_helpers.h"
+diff --git a/src/posix.h b/src/posix.h
+index 965cd98..eb93cde 100644
+--- a/src/posix.h
++++ b/src/posix.h
+@@ -12,6 +12,10 @@
+ #include <time.h>
+ #include "fnmatch.h"
  
--git_repository *g_repo;
--git_blame *g_fileblame, *g_bufferblame;
-+static git_repository *g_repo;
-+static git_blame *g_fileblame, *g_bufferblame;
- 
- void test_blame_buffer__initialize(void)
++#if defined(__native_client__) && defined(_NEWLIB_VERSION)
++mode_t umask(mode_t cmask);
++#endif
++
+ #ifndef S_IFGITLINK
+ #define S_IFGITLINK 0160000
+ #define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK)
+diff --git a/tests/clar.c b/tests/clar.c
+index 1546447..839f7f3 100644
+--- a/tests/clar.c
++++ b/tests/clar.c
+@@ -222,7 +222,7 @@ static void
+ clar_run_suite(const struct clar_suite *suite, const char *filter)
  {
+ 	const struct clar_func *test = suite->tests;
+-	size_t i, matchlen;
++	size_t i, matchlen = 0;
+ 
+ 	if (!suite->enabled)
+ 		return;
 diff --git a/tests/clar/fs.h b/tests/clar/fs.h
-index b7a1ff9..1d508a3 100644
+index 7c7dde6..e37aec1 100644
 --- a/tests/clar/fs.h
 +++ b/tests/clar/fs.h
-@@ -250,7 +250,250 @@ cl_fs_cleanup(void)
+@@ -250,6 +250,249 @@ cl_fs_cleanup(void)
  	fs_rm(fixture_path(_clar_path, "*"));
  }
  
@@ -133,6 +143,7 @@
 +  const size_t buffer_size = 8192;
 +  char buffer[buffer_size];
 +  int result = 1;
++  FILE* dst_file = NULL;
 +
 +  FILE* src_file = fopen(source, "r");
 +  if (src_file == NULL) {
@@ -141,7 +152,7 @@
 +    goto error;
 +  }
 +
-+  FILE* dst_file = fopen(dest, "w");
++  dst_file = fopen(dest, "w");
 +  if (dst_file == NULL) {
 +    fprintf(stderr, "Error opening file %s for writing: %s\n",
 +            dest, strerror(errno));
@@ -271,7 +282,7 @@
 +
 +static int fs_rm_helper(const char* source) {
 +  struct stat statbuf;
-+  if (stat(source, &statbuf) != 0) {
++  if (lstat(source, &statbuf) != 0) {
 +    fprintf(stderr, "Error stat'ing file %s: %s\n", source, strerror(errno));
 +    return 0;
 +  }
@@ -304,20 +315,81 @@
 +}
 +
  #else
-+
- static int
- shell_out(char * const argv[])
- {
-diff --git a/tests/index/addall.c b/tests/index/addall.c
-index 44c5127..abc84b2 100644
---- a/tests/index/addall.c
-+++ b/tests/index/addall.c
-@@ -3,7 +3,7 @@
- #include "posix.h"
- #include "fileops.h"
  
--git_repository *g_repo = NULL;
-+static git_repository *g_repo = NULL;
+ #include <errno.h>
+diff --git a/tests/clar/sandbox.h b/tests/clar/sandbox.h
+index a44e291..a6aea62 100644
+--- a/tests/clar/sandbox.h
++++ b/tests/clar/sandbox.h
+@@ -110,8 +110,21 @@ static int build_sandbox_path(void)
+ 		return -1;
+ #else
+ 	if (mkdtemp(_clar_path) == NULL)
++#if defined(__native_client__)
++	{
++		// Under sel_ldr mkdtemp currently always fails.  For now
++		// fake it.
++		struct stat buf;
++		strcpy(_clar_path + strlen(_clar_path) - 6, "123456");
++		if (stat(_clar_path, &buf) == 0)
++			fs_rm(_clar_path);
++		if (mkdir(_clar_path, 0700) != 0)
++			return -1;
++	}
++#else
+ 		return -1;
+ #endif
++#endif
  
- void test_index_addall__initialize(void)
+ 	return 0;
+ }
+diff --git a/tests/commit/parse.c b/tests/commit/parse.c
+index 41e1624..f27bada 100644
+--- a/tests/commit/parse.c
++++ b/tests/commit/parse.c
+@@ -119,8 +119,8 @@ passing_signature_test_case passing_signature_cases[] = {
+ 	{"author Vicent Marti <tanoku@gmail.com> 1234567890 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 1234567890, 0},
+ 	{"author Vicent Marti <tanoku@gmail.com> 2147483647 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 0x7fffffff, 0},
+ 	{"author Vicent Marti <tanoku@gmail.com> 4294967295 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 0xffffffff, 0},
+-	{"author Vicent Marti <tanoku@gmail.com> 4294967296 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 4294967296, 0},
+-	{"author Vicent Marti <tanoku@gmail.com> 8589934592 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 8589934592, 0},
++	{"author Vicent Marti <tanoku@gmail.com> 4294967296 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 4294967296ll, 0},
++	{"author Vicent Marti <tanoku@gmail.com> 8589934592 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 8589934592ll, 0},
+ 
+ 	{NULL,NULL,NULL,NULL,0,0}
+ };
+diff --git a/tests/config/read.c b/tests/config/read.c
+index 2567272..2db4b3d 100644
+--- a/tests/config/read.c
++++ b/tests/config/read.c
+@@ -477,7 +477,7 @@ void test_config_read__simple_read_from_specific_level(void)
  {
+ 	git_config *cfg, *cfg_specific;
+ 	int i;
+-	int64_t l, expected = +9223372036854775803;
++	int64_t l, expected = +9223372036854775803ll;
+ 	const char *s;
+ 
+ 	cl_git_pass(git_config_new(&cfg));
+diff --git a/tests/config/write.c b/tests/config/write.c
+index 0f11ae8..675f7f4 100644
+--- a/tests/config/write.c
++++ b/tests/config/write.c
+@@ -18,7 +18,7 @@ void test_config_write__replace_value(void)
+ {
+ 	git_config *cfg;
+ 	int i;
+-	int64_t l, expected = +9223372036854775803;
++	int64_t l, expected = +9223372036854775803ll;
+ 
+ 	/* By freeing the config, we make sure we flush the values  */
+ 	cl_git_pass(git_config_open_ondisk(&cfg, "config9"));
+@@ -179,7 +179,7 @@ void test_config_write__add_value_at_specific_level(void)
+ {
+ 	git_config *cfg, *cfg_specific;
+ 	int i;
+-	int64_t l, expected = +9223372036854775803;
++	int64_t l, expected = +9223372036854775803ll;
+ 	const char *s;
+ 
+ 	// open config15 as global level config file
diff --git a/ports/libgit2/pkg_info b/ports/libgit2/pkg_info
index a479923..a25ed76 100644
--- a/ports/libgit2/pkg_info
+++ b/ports/libgit2/pkg_info
@@ -1,8 +1,8 @@
 NAME=libgit2
-VERSION=0.20.0
-URL=https://github.com/libgit2/libgit2/archive/v0.20.0/libgit2-0.20.0.tar.gz
+VERSION=0.21.1
+URL=https://github.com/libgit2/libgit2/archive/v0.21.1/libgit2-0.21.1.tar.gz
 DEPENDS=(glibc-compat openssl libssh)
 # GPL2 with linking exemption.
 LICENSE=CUSTOM:COPYING
 DISABLED_LIBC=(bionic)
-SHA1=811bbe4fe4fc83236ba42d23e3b449f1b95b4bab
+SHA1=8975eb3fa6999e30b1fa01a84b7b09d0a2672ac5