diff options
151 files changed, 4382 insertions, 2701 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b4a9dba4e..61eb799a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,9 +43,10 @@ SET(INSTALL_INC include CACHE PATH "Where to install headers to.") # Build options OPTION (BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON) -OPTION (BUILD_TESTS "Build Tests" ON) OPTION (THREADSAFE "Build libgit2 as threadsafe" OFF) OPTION (STDCALL "Buildl libgit2 with the __stdcall convention (Windows)" ON) +OPTION (BUILD_TESTS "Build Tests" OFF) +OPTION (BUILD_CLAY "Build Tests using the Clay suite" ON) # Platform specific compilation flags IF (MSVC) @@ -116,7 +117,7 @@ INSTALL(FILES include/git2.h DESTINATION ${INSTALL_INC} ) # Tests IF (BUILD_TESTS) SET(TEST_RESOURCES "${CMAKE_CURRENT_SOURCE_DIR}/tests/resources" CACHE PATH "Path to test resources.") - ADD_DEFINITIONS(-DTEST_RESOURCES=\"${TEST_RESOURCES}\") + ADD_DEFINITIONS(-DTEST_RESOURCES=\"${TEST_RESOURCES}\") INCLUDE_DIRECTORIES(tests) FILE(GLOB SRC_TEST tests/t??-*.c) @@ -132,3 +133,22 @@ IF (BUILD_TESTS) ENABLE_TESTING() ADD_TEST(libgit2_test libgit2_test) ENDIF () + +IF (BUILD_CLAY) + SET(CLAY_FIXTURES "${CMAKE_CURRENT_SOURCE_DIR}/tests/resources/") + ADD_DEFINITIONS(-DCLAY_FIXTURE_PATH=\"${CLAY_FIXTURES}\") + + INCLUDE_DIRECTORIES(tests-clay) + FILE(GLOB_RECURSE SRC_TEST tests-clay/*.c) + + ADD_EXECUTABLE(libgit2_clay ${SRC} ${SRC_TEST} ${SRC_ZLIB}) + TARGET_LINK_LIBRARIES(libgit2_clay ${CMAKE_THREAD_LIBS_INIT}) + IF (WIN32) + TARGET_LINK_LIBRARIES(libgit2_clay ws2_32) + ELSEIF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") + TARGET_LINK_LIBRARIES(libgit2_clay socket nsl) + ENDIF () + + ENABLE_TESTING() + ADD_TEST(libgit2_clay libgit2_clay) +ENDIF () @@ -1,11 +1,17 @@ + libgit2 is Copyright (C) 2009-2011 the libgit2 contributors, + unless otherwise stated. See the AUTHORS file for details. Note that the only valid version of the GPL as far as this project is concerned is _this_ particular version of the license (ie v2, not v2.2 or v3.x or whatever), unless explicitly otherwise stated. +---------------------------------------------------------------------- + + LINKING EXCEPTION + In addition to the permissions in the GNU General Public License, the authors give you unlimited permission to link the compiled - version of this file into combinations with other programs, + version of this library into combinations with other programs, and to distribute those combinations without any restriction coming from the use of this file. (The General Public License restrictions do apply in other respects; for example, they cover @@ -354,3 +360,66 @@ proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. + +---------------------------------------------------------------------- + +The bundled ZLib code is licensed under the ZLib license: + +Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + +---------------------------------------------------------------------- + +The priority queue implementation is based on code licensed under the +Apache 2.0 license: + + Copyright 2010 Volkan Yazıcı <volkan.yazici@gmail.com> + Copyright 2006-2010 The Apache Software Foundation + +The full text of the Apache 2.0 license is available at: + + http://www.apache.org/licenses/LICENSE-2.0 + +---------------------------------------------------------------------- + +The Clay framework is licensed under the MIT license: + +Copyright (C) 2011 by Vicent Marti + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + diff --git a/examples/Makefile b/examples/Makefile index f7bf469a5..efb55547b 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -1,10 +1,13 @@ -all: general showindex +.PHONY: all + +CC = gcc +CFLAGS = -g -I../include +LFLAGS = -L../build -lgit2 -lz -general : general.c - gcc -lgit2 -o general general.c +all: general showindex -showindex : showindex.c - gcc -lgit2 -o showindex showindex.c +% : %.c + $(CC) -o $@ $(CFLAGS) $< $(LFLAGS) clean: - rm general showindex + $(RM) general showindex diff --git a/examples/general.c b/examples/general.c index 91b6ee859..9bfbc4083 100644 --- a/examples/general.c +++ b/examples/general.c @@ -38,7 +38,11 @@ int main (int argc, char** argv) // // [me]: http://libgit2.github.com/libgit2/#HEAD/group/repository git_repository *repo; - git_repository_open(&repo, "/opt/libgit2-test/.git"); + if (argc > 1) { + git_repository_open(&repo, argv[1]); + } else { + git_repository_open(&repo, "/opt/libgit2-test/.git"); + } // ### SHA-1 Value Conversions @@ -52,7 +56,7 @@ int main (int argc, char** argv) git_oid_fromstr(&oid, hex); // Once we've converted the string into the oid value, we can get the raw value of the SHA. - printf("Raw 20 bytes: [%s]\n", (&oid)->id); + printf("Raw 20 bytes: [%.20s]\n", (&oid)->id); // Next we will convert the 20 byte raw SHA1 value to a human readable 40 char hex value. printf("\n*Raw to Hex*\n"); @@ -138,15 +142,14 @@ int main (int argc, char** argv) error = git_commit_lookup(&commit, repo, &oid); const git_signature *author, *cmtter; - const char *message, *message_short; + const char *message; time_t ctime; unsigned int parents, p; // Each of the properties of the commit object are accessible via methods, including commonly - // needed variations, such as `git_commit_time` which returns the author time and `_message_short` - // which gives you just the first line of the commit message. + // needed variations, such as `git_commit_time` which returns the author time and `_message` + // which gives you the commit message. message = git_commit_message(commit); - message_short = git_commit_message_short(commit); author = git_commit_author(commit); cmtter = git_commit_committer(commit); ctime = git_commit_time(commit); @@ -187,9 +190,9 @@ int main (int argc, char** argv) // this to create a commit in order to specify who created it and when. Default values for the name // and email should be found in the `user.name` and `user.email` configuration options. See the `config` // section of this example file to see how to access config values. - author = git_signature_new("Scott Chacon", "schacon@gmail.com", + git_signature_new((git_signature **)&author, "Scott Chacon", "schacon@gmail.com", 123456789, 60); - cmtter = git_signature_new("Scott A Chacon", "scott@github.com", + git_signature_new((git_signature **)&cmtter, "Scott A Chacon", "scott@github.com", 987654321, 90); // Commit objects need a tree to point to and optionally one or more parents. Here we're creating oid @@ -207,6 +210,7 @@ int main (int argc, char** argv) NULL, /* do not update the HEAD */ author, cmtter, + NULL, /* use default message encoding */ "example commit", tree, 1, parent); @@ -294,7 +298,7 @@ int main (int argc, char** argv) // Note that this buffer may not be contain ASCII data for certain blobs (e.g. binary files): // do not consider the buffer a NULL-terminated string, and use the `git_blob_rawsize` attribute to // find out its exact size in bytes - printf("Blob Size: %d\n", git_blob_rawsize(blob)); // 8 + printf("Blob Size: %ld\n", git_blob_rawsize(blob)); // 8 git_blob_rawcontent(blob); // "content" // ### Revwalking @@ -333,7 +337,7 @@ int main (int argc, char** argv) // be cached in memory while ((git_revwalk_next(&oid, walk)) == GIT_SUCCESS) { error = git_commit_lookup(&wcommit, repo, &oid); - cmsg = git_commit_message_short(wcommit); + cmsg = git_commit_message(wcommit); cauth = git_commit_author(wcommit); printf("%s (%s)\n", cmsg, cauth->email); git_commit_close(wcommit); diff --git a/git.git-authors b/git.git-authors index 086ab3e18..026b35fa8 100644 --- a/git.git-authors +++ b/git.git-authors @@ -61,6 +61,7 @@ ok Pierre Habouzit <madcoder@debian.org> ok Pieter de Bie <pdebie@ai.rug.nl> ok René Scharfe <rene.scharfe@lsrfire.ath.cx> ign Robert Shearman <rob@codeweavers.com> (imap-send) +ok Sebastian Schuberth <sschuberth@gmail.com> ok Shawn O. Pearce <spearce@spearce.org> ok Steffen Prohaska <prohaska@zib.de> ok Sven Verdoolaege <skimo@kotnet.org> diff --git a/include/git2.h b/include/git2.h index 96de524e7..886a659c8 100644 --- a/include/git2.h +++ b/include/git2.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_git_h__ diff --git a/include/git2/blob.h b/include/git2/blob.h index e366ce880..b2a2b034a 100644 --- a/include/git2/blob.h +++ b/include/git2/blob.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_blob_h__ #define INCLUDE_git_blob_h__ @@ -45,7 +27,7 @@ GIT_BEGIN_DECL * @param blob pointer to the looked up blob * @param repo the repo to use when locating the blob. * @param id identity of the blob to locate. - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_INLINE(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git_oid *id) { @@ -62,7 +44,7 @@ GIT_INLINE(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git * @param repo the repo to use when locating the blob. * @param id identity of the blob to locate. * @param len the length of the short identifier - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_INLINE(int) git_blob_lookup_prefix(git_blob **blob, git_repository *repo, const git_oid *id, unsigned int len) { @@ -106,7 +88,7 @@ GIT_EXTERN(const void *) git_blob_rawcontent(git_blob *blob); * @param blob pointer to the blob * @return size on bytes */ -GIT_EXTERN(int) git_blob_rawsize(git_blob *blob); +GIT_EXTERN(size_t) git_blob_rawsize(git_blob *blob); /** * Read a file from the working folder of a repository @@ -117,7 +99,7 @@ GIT_EXTERN(int) git_blob_rawsize(git_blob *blob); * this repository cannot be bare * @param path file from which the blob will be created, * relative to the repository's working dir - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *path); @@ -129,7 +111,7 @@ GIT_EXTERN(int) git_blob_create_fromfile(git_oid *oid, git_repository *repo, con * @param repo repository where to blob will be written * @param buffer data to be written into the blob * @param len length of the data - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_blob_create_frombuffer(git_oid *oid, git_repository *repo, const void *buffer, size_t len); diff --git a/include/git2/branch.h b/include/git2/branch.h index 456b7d1ac..5a92cf570 100644 --- a/include/git2/branch.h +++ b/include/git2/branch.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_branch_h__ #define INCLUDE_branch_h__ diff --git a/include/git2/commit.h b/include/git2/commit.h index 12646cf58..3c90e8007 100644 --- a/include/git2/commit.h +++ b/include/git2/commit.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_commit_h__ #define INCLUDE_git_commit_h__ @@ -44,9 +26,9 @@ GIT_BEGIN_DECL * * @param commit pointer to the looked up commit * @param repo the repo to use when locating the commit. - * @param id identity of the commit to locate. If the object is - * an annotated tag it will be peeled back to the commit. - * @return 0 on success; error code otherwise + * @param id identity of the commit to locate. If the object is + * an annotated tag it will be peeled back to the commit. + * @return GIT_SUCCESS or an error code */ GIT_INLINE(int) git_commit_lookup(git_commit **commit, git_repository *repo, const git_oid *id) { @@ -61,10 +43,10 @@ GIT_INLINE(int) git_commit_lookup(git_commit **commit, git_repository *repo, con * * @param commit pointer to the looked up commit * @param repo the repo to use when locating the commit. - * @param id identity of the commit to locate. If the object is - * an annotated tag it will be peeled back to the commit. + * @param id identity of the commit to locate. If the object is + * an annotated tag it will be peeled back to the commit. * @param len the length of the short identifier - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_INLINE(int) git_commit_lookup_prefix(git_commit **commit, git_repository *repo, const git_oid *id, unsigned len) { @@ -153,7 +135,7 @@ GIT_EXTERN(const git_signature *) git_commit_author(git_commit *commit); * * @param tree_out pointer where to store the tree object * @param commit a previously loaded commit. - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_commit_tree(git_tree **tree_out, git_commit *commit); @@ -181,7 +163,7 @@ GIT_EXTERN(unsigned int) git_commit_parentcount(git_commit *commit); * @param parent Pointer where to store the parent commit * @param commit a previously loaded commit. * @param n the position of the parent (from 0 to `parentcount`) - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_commit_parent(git_commit **parent, git_commit *commit, unsigned int n); @@ -215,7 +197,7 @@ GIT_EXTERN(const git_oid *) git_commit_parent_oid(git_commit *commit, unsigned i * time of this commit * * @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 * commit, represented with a standard encoding name. @@ -235,7 +217,7 @@ GIT_EXTERN(const git_oid *) git_commit_parent_oid(git_commit *commit, unsigned i * array may be NULL if `parent_count` is 0 (root commit). All the * given commits must be owned by the `repo`. * - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code * The created commit will be written to the Object Database and * the given reference will be updated to point to it */ diff --git a/include/git2/common.h b/include/git2/common.h index 58cb1f200..084981674 100644 --- a/include/git2/common.h +++ b/include/git2/common.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_common_h__ #define INCLUDE_git_common_h__ @@ -30,20 +12,20 @@ #include <stdlib.h> #ifdef __cplusplus -# define GIT_BEGIN_DECL extern "C" { -# define GIT_END_DECL } +# define GIT_BEGIN_DECL extern "C" { +# define GIT_END_DECL } #else - /** Start declarations in C mode */ -# define GIT_BEGIN_DECL /* empty */ - /** End declarations in C mode */ -# define GIT_END_DECL /* empty */ + /** Start declarations in C mode */ +# define GIT_BEGIN_DECL /* empty */ + /** End declarations in C mode */ +# define GIT_END_DECL /* empty */ #endif /** Declare a public function exported for application use. */ -#ifdef __GNUC__ +#if __GNUC__ >= 4 # define GIT_EXTERN(type) extern \ - __attribute__((visibility("default"))) \ - type + __attribute__((visibility("default"))) \ + type #elif defined(_MSC_VER) # define GIT_EXTERN(type) __declspec(dllexport) type #else @@ -51,11 +33,11 @@ #endif /** Declare a public TLS symbol exported for application use. */ -#ifdef __GNUC__ +#if __GNUC__ >= 4 # define GIT_EXTERN_TLS(type) extern \ - __attribute__((visibility("default"))) \ - GIT_TLS \ - type + __attribute__((visibility("default"))) \ + GIT_TLS \ + type #elif defined(_MSC_VER) # define GIT_EXTERN_TLS(type) __declspec(dllexport) GIT_TLS type #else diff --git a/include/git2/config.h b/include/git2/config.h index e05d23694..74ee96bde 100644 --- a/include/git2/config.h +++ b/include/git2/config.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_config_h__ #define INCLUDE_git_config_h__ @@ -76,7 +58,7 @@ GIT_EXTERN(int) git_config_find_global(char *global_config_path); * and opens the located file, if it exists. * * @param out Pointer to store the config instance - * @return GIT_SUCCESS on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_config_open_global(git_config **out); @@ -100,7 +82,7 @@ GIT_EXTERN(int) git_config_file__ondisk(struct git_config_file **out, const char * can do anything with it. * * @param out pointer to the new configuration - * @return GIT_SUCCESS on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_config_new(git_config **out); @@ -117,7 +99,7 @@ GIT_EXTERN(int) git_config_new(git_config **out); * @param cfg the configuration to add the file to * @param file the configuration file (backend) to add * @param priority the priority the backend should have - * @return GIT_SUCCESS on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_config_add_file(git_config *cfg, git_config_file *file, int priority); @@ -138,7 +120,7 @@ GIT_EXTERN(int) git_config_add_file(git_config *cfg, git_config_file *file, int * @param cfg the configuration to add the file to * @param path path to the configuration file (backend) to add * @param priority the priority the backend should have - * @return GIT_SUCCESS on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_config_add_file_ondisk(git_config *cfg, const char *path, int priority); @@ -153,7 +135,7 @@ GIT_EXTERN(int) git_config_add_file_ondisk(git_config *cfg, const char *path, in * * @param cfg The configuration instance to create * @param path Path to the on-disk file to open - * @return GIT_SUCCESS on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_config_open_ondisk(git_config **cfg, const char *path); @@ -170,7 +152,7 @@ GIT_EXTERN(void) git_config_free(git_config *cfg); * @param cfg where to look for the variable * @param name the variable's name * @param out pointer to the variable where the value should be stored - * @return GIT_SUCCESS on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_config_get_int(git_config *cfg, const char *name, int *out); @@ -180,7 +162,7 @@ GIT_EXTERN(int) git_config_get_int(git_config *cfg, const char *name, int *out); * @param cfg where to look for the variable * @param name the variable's name * @param out pointer to the variable where the value should be stored - * @return GIT_SUCCESS on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_config_get_long(git_config *cfg, const char *name, long int *out); @@ -193,7 +175,7 @@ GIT_EXTERN(int) git_config_get_long(git_config *cfg, const char *name, long int * @param cfg where to look for the variable * @param name the variable's name * @param out pointer to the variable where the value should be stored - * @return GIT_SUCCESS on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_config_get_bool(git_config *cfg, const char *name, int *out); @@ -206,7 +188,7 @@ GIT_EXTERN(int) git_config_get_bool(git_config *cfg, const char *name, int *out) * @param cfg where to look for the variable * @param name the variable's name * @param out pointer to the variable's value - * @return GIT_SUCCESS on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_config_get_string(git_config *cfg, const char *name, const char **out); @@ -216,7 +198,7 @@ GIT_EXTERN(int) git_config_get_string(git_config *cfg, const char *name, const c * @param cfg where to look for the variable * @param name the variable's name * @param value Integer value for the variable - * @return GIT_SUCCESS on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_config_set_int(git_config *cfg, const char *name, int value); @@ -226,7 +208,7 @@ GIT_EXTERN(int) git_config_set_int(git_config *cfg, const char *name, int value) * @param cfg where to look for the variable * @param name the variable's name * @param value Long integer value for the variable - * @return GIT_SUCCESS on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_config_set_long(git_config *cfg, const char *name, long int value); @@ -236,7 +218,7 @@ GIT_EXTERN(int) git_config_set_long(git_config *cfg, const char *name, long int * @param cfg where to look for the variable * @param name the variable's name * @param value the value to store - * @return GIT_SUCCESS on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_config_set_bool(git_config *cfg, const char *name, int value); @@ -249,7 +231,7 @@ GIT_EXTERN(int) git_config_set_bool(git_config *cfg, const char *name, int value * @param cfg where to look for the variable * @param name the variable's name * @param value the string to store. - * @return GIT_SUCCESS on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_config_set_string(git_config *cfg, const char *name, const char *value); diff --git a/include/git2/errors.h b/include/git2/errors.h index 710ac244b..5ac0d5b27 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_errors_h__ #define INCLUDE_git_errors_h__ @@ -82,7 +64,7 @@ typedef enum { GIT_EINVALIDREFNAME = -15, /** The specified reference has its data corrupted */ - GIT_EREFCORRUPTED = -16, + GIT_EREFCORRUPTED = -16, /** The specified symbolic reference is too deeply nested */ GIT_ETOONESTEDSYMREF = -17, @@ -129,7 +111,7 @@ typedef enum { /** The path pattern and string did not match */ 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_error; diff --git a/include/git2/index.h b/include/git2/index.h index 18ab9b858..5e9c34d4b 100644 --- a/include/git2/index.h +++ b/include/git2/index.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_index_h__ #define INCLUDE_git_index_h__ @@ -38,10 +20,10 @@ */ GIT_BEGIN_DECL -#define GIT_IDXENTRY_NAMEMASK (0x0fff) +#define GIT_IDXENTRY_NAMEMASK (0x0fff) #define GIT_IDXENTRY_STAGEMASK (0x3000) -#define GIT_IDXENTRY_EXTENDED (0x4000) -#define GIT_IDXENTRY_VALID (0x8000) +#define GIT_IDXENTRY_EXTENDED (0x4000) +#define GIT_IDXENTRY_VALID (0x8000) #define GIT_IDXENTRY_STAGESHIFT 12 /* @@ -51,26 +33,26 @@ GIT_BEGIN_DECL * * In-memory only flags: */ -#define GIT_IDXENTRY_UPDATE (1 << 0) -#define GIT_IDXENTRY_REMOVE (1 << 1) -#define GIT_IDXENTRY_UPTODATE (1 << 2) -#define GIT_IDXENTRY_ADDED (1 << 3) +#define GIT_IDXENTRY_UPDATE (1 << 0) +#define GIT_IDXENTRY_REMOVE (1 << 1) +#define GIT_IDXENTRY_UPTODATE (1 << 2) +#define GIT_IDXENTRY_ADDED (1 << 3) -#define GIT_IDXENTRY_HASHED (1 << 4) -#define GIT_IDXENTRY_UNHASHED (1 << 5) -#define GIT_IDXENTRY_WT_REMOVE (1 << 6) /* remove in work directory */ -#define GIT_IDXENTRY_CONFLICTED (1 << 7) +#define GIT_IDXENTRY_HASHED (1 << 4) +#define GIT_IDXENTRY_UNHASHED (1 << 5) +#define GIT_IDXENTRY_WT_REMOVE (1 << 6) /* remove in work directory */ +#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) /* * Extended on-disk flags: */ -#define GIT_IDXENTRY_INTENT_TO_ADD (1 << 13) -#define GIT_IDXENTRY_SKIP_WORKTREE (1 << 14) +#define GIT_IDXENTRY_INTENT_TO_ADD (1 << 13) +#define GIT_IDXENTRY_SKIP_WORKTREE (1 << 14) /* 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) @@ -124,7 +106,7 @@ typedef struct git_index_entry_unmerged { * * @param index the pointer for the new index * @param index_path the path to the index file in disk - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_index_open(git_index **index, const char *index_path); @@ -149,7 +131,7 @@ GIT_EXTERN(void) git_index_free(git_index *index); * by reading from the hard disk. * * @param index an existing index object - * @return 0 on success, otherwise an error code + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_index_read(git_index *index); @@ -158,7 +140,7 @@ GIT_EXTERN(int) git_index_read(git_index *index); * using an atomic file lock. * * @param index an existing index object - * @return 0 on success, otherwise an error code + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_index_write(git_index *index); @@ -190,7 +172,7 @@ GIT_EXTERN(void) git_index_uniq(git_index *index); * @param index an existing index object * @param path filename to add * @param stage stage for the entry - * @return 0 on success, otherwise an error code + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_index_add(git_index *index, const char *path, int stage); @@ -202,7 +184,7 @@ GIT_EXTERN(int) git_index_add(git_index *index, const char *path, int stage); * * @param index an existing index object * @param source_entry new entry object - * @return 0 on success, otherwise an error code + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_index_add2(git_index *index, const git_index_entry *source_entry); @@ -221,7 +203,7 @@ GIT_EXTERN(int) git_index_add2(git_index *index, const git_index_entry *source_e * @param index an existing index object * @param path filename to add * @param stage stage for the entry - * @return 0 on success, otherwise an error code + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_index_append(git_index *index, const char *path, int stage); @@ -238,7 +220,7 @@ GIT_EXTERN(int) git_index_append(git_index *index, const char *path, int stage); * * @param index an existing index object * @param source_entry new entry object - * @return 0 on success, otherwise an error code + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_index_append2(git_index *index, const git_index_entry *source_entry); @@ -247,7 +229,7 @@ GIT_EXTERN(int) git_index_append2(git_index *index, const git_index_entry *sourc * * @param index an existing index object * @param position position of the entry to remove - * @return 0 on success, otherwise an error code + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_index_remove(git_index *index, int position); diff --git a/include/git2/indexer.h b/include/git2/indexer.h index 2852d7e6f..bd9b9b6ab 100644 --- a/include/git2/indexer.h +++ b/include/git2/indexer.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef _INCLUDE_git_indexer_h__ #define _INCLUDE_git_indexer_h__ diff --git a/include/git2/net.h b/include/git2/net.h index d4f475527..5fb918599 100644 --- a/include/git2/net.h +++ b/include/git2/net.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_net_h__ #define INCLUDE_net_h__ diff --git a/include/git2/object.h b/include/git2/object.h index 07ba1a1c7..d82a71c3c 100644 --- a/include/git2/object.h +++ b/include/git2/object.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_object_h__ #define INCLUDE_git_object_h__ @@ -87,7 +69,7 @@ GIT_EXTERN(int) git_object_lookup( * @param id a short identifier for the object * @param len the length of the short identifier * @param type the type of the object - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_object_lookup_prefix( git_object **object_out, diff --git a/include/git2/odb.h b/include/git2/odb.h index d0c369055..27837418b 100644 --- a/include/git2/odb.h +++ b/include/git2/odb.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_odb_h__ #define INCLUDE_git_odb_h__ @@ -46,9 +28,8 @@ GIT_BEGIN_DECL * backend must be manually added using `git_odb_add_backend()` * * @param out location to store the database pointer, if opened. - * Set to NULL if the open failed. - * @return GIT_SUCCESS if the database was created; otherwise an error - * code describing why the open was not possible. + * Set to NULL if the open failed. + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_odb_new(git_odb **out); @@ -64,10 +45,9 @@ GIT_EXTERN(int) git_odb_new(git_odb **out); * contains a 'pack/' folder with the corresponding data * * @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. - * @return GIT_SUCCESS if the database opened; otherwise an error - * code describing why the open was not possible. + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_odb_open(git_odb **out, const char *objects_dir); @@ -110,7 +90,7 @@ GIT_EXTERN(int) git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, in /** * 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); @@ -208,7 +188,7 @@ GIT_EXTERN(int) git_odb_exists(git_odb *db, const git_oid *id); * @param data buffer with the data to storr * @param len size of the buffer * @param type type of the data to store - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_odb_write(git_oid *oid, git_odb *odb, const void *data, size_t len, git_otype type); @@ -277,7 +257,7 @@ GIT_EXTERN(int) git_odb_open_rstream(git_odb_stream **stream, git_odb *db, const * @param data data to hash * @param len size of the data * @param type of the data to hash - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_odb_hash(git_oid *id, const void *data, size_t len, git_otype type); @@ -290,7 +270,7 @@ GIT_EXTERN(int) git_odb_hash(git_oid *id, const void *data, size_t len, git_otyp * @param out oid structure the result is written into. * @param path file to read and determine object id for * @param type the type of the object that will be hashed - * @return GIT_SUCCESS if valid; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_odb_hashfile(git_oid *out, const char *path, git_otype type); diff --git a/include/git2/odb_backend.h b/include/git2/odb_backend.h index 43a1c2d21..9d0bfdd47 100644 --- a/include/git2/odb_backend.h +++ b/include/git2/odb_backend.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_odb_backend_h__ #define INCLUDE_git_odb_backend_h__ diff --git a/include/git2/oid.h b/include/git2/oid.h index 8a0f134b9..f9636d1fc 100644 --- a/include/git2/oid.h +++ b/include/git2/oid.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_oid_h__ #define INCLUDE_git_oid_h__ @@ -59,9 +41,9 @@ struct _git_oid { * * @param out oid structure the result is written into. * @param str input hex string; must be pointing at the start of - * the hex sequence and have at least the number of bytes - * needed for an oid encoded in hex (40 bytes). - * @return GIT_SUCCESS if valid; GIT_ENOTOID on failure. + * the hex sequence and have at least the number of bytes + * needed for an oid encoded in hex (40 bytes). + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_oid_fromstr(git_oid *out, const char *str); @@ -74,7 +56,7 @@ GIT_EXTERN(int) git_oid_fromstr(git_oid *out, const char *str); * @param out oid structure the result is written into. * @param str input hex string of at least size `length` * @param length length of the input string - * @return GIT_SUCCESS if valid; GIT_ENOTOID on failure. + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_oid_fromstrn(git_oid *out, const char *str, size_t length); @@ -90,10 +72,10 @@ GIT_EXTERN(void) git_oid_fromraw(git_oid *out, const unsigned char *raw); * Format a git_oid into a hex string. * * @param str output hex string; must be pointing at the start of - * the hex sequence and have at least the number of bytes - * needed for an oid encoded in hex (40 bytes). Only the - * oid digits are written; a '\\0' terminator must be added - * by the caller if it is required. + * the hex sequence and have at least the number of bytes + * needed for an oid encoded in hex (40 bytes). Only the + * oid digits are written; a '\\0' terminator must be added + * by the caller if it is required. * @param oid oid structure to format. */ GIT_EXTERN(void) git_oid_fmt(char *str, const git_oid *oid); @@ -105,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. * * @param str output hex string; must be pointing at the start of - * the hex sequence and have at least the number of bytes - * needed for an oid encoded in hex (41 bytes). Only the - * oid digits are written; a '\\0' terminator must be added - * by the caller if it is required. + * the hex sequence and have at least the number of bytes + * needed for an oid encoded in hex (41 bytes). Only the + * oid digits are written; a '\\0' terminator must be added + * by the caller if it is required. * @param oid oid structure to format. */ GIT_EXTERN(void) git_oid_pathfmt(char *str, const git_oid *oid); @@ -117,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. * * @param oid the oid structure to format - * @return the c-string; NULL if memory is exhausted. Caller must - * deallocate the string with free(). + * @return the c-string; NULL if memory is exhausted. Caller must + * deallocate the string with free(). */ GIT_EXTERN(char *) git_oid_allocfmt(const git_oid *oid); @@ -135,7 +117,7 @@ GIT_EXTERN(char *) git_oid_allocfmt(const git_oid *oid); * @param n the size of the out buffer. * @param oid the oid structure to format. * @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); diff --git a/include/git2/reflog.h b/include/git2/reflog.h index 53b344733..9ad42b73b 100644 --- a/include/git2/reflog.h +++ b/include/git2/reflog.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_reflog_h__ #define INCLUDE_git_reflog_h__ @@ -46,7 +28,7 @@ GIT_BEGIN_DECL * * @param reflog pointer to reflog * @param ref reference to read the reflog for - * @return GIT_SUCCESS on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_reflog_read(git_reflog **reflog, git_reference *ref); @@ -64,7 +46,7 @@ GIT_EXTERN(int) git_reflog_read(git_reflog **reflog, git_reference *ref); * @param oid_old the OID the reference was pointing to * @param committer the signature of the committer * @param msg the reflog message - * @return GIT_SUCCESS on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_reflog_write(git_reference *ref, const git_oid *oid_old, const git_signature *committer, const char *msg); diff --git a/include/git2/refs.h b/include/git2/refs.h index ff2bc9d87..c319bfb3d 100644 --- a/include/git2/refs.h +++ b/include/git2/refs.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_refs_h__ #define INCLUDE_git_refs_h__ @@ -47,7 +29,7 @@ GIT_BEGIN_DECL * @param reference_out pointer to the looked-up reference * @param repo the repository to look up the reference * @param name the long name for the reference (e.g. HEAD, ref/heads/master, refs/tags/v0.1.0, ...) - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_reference_lookup(git_reference **reference_out, git_repository *repo, const char *name); @@ -68,7 +50,7 @@ GIT_EXTERN(int) git_reference_lookup(git_reference **reference_out, git_reposito * @param name The name of the reference * @param target The target of the reference * @param force Overwrite existing references - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_reference_create_symbolic(git_reference **ref_out, git_repository *repo, const char *name, const char *target, int force); @@ -89,7 +71,7 @@ GIT_EXTERN(int) git_reference_create_symbolic(git_reference **ref_out, git_repos * @param name The name of the reference * @param id The object id pointed to by the reference. * @param force Overwrite existing references - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_reference_create_oid(git_reference **ref_out, git_repository *repo, const char *name, const git_oid *id, int force); @@ -142,7 +124,7 @@ GIT_EXTERN(const char *) git_reference_name(git_reference *ref); * * @param resolved_ref Pointer to the peeled reference * @param ref The reference - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_reference_resolve(git_reference **resolved_ref, git_reference *ref); @@ -165,7 +147,7 @@ GIT_EXTERN(git_repository *) git_reference_owner(git_reference *ref); * * @param ref The reference * @param target The new target for the reference - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_reference_set_target(git_reference *ref, const char *target); @@ -180,7 +162,7 @@ GIT_EXTERN(int) git_reference_set_target(git_reference *ref, const char *target) * * @param ref The reference * @param id The new target OID for the reference - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_reference_set_oid(git_reference *ref, const git_oid *id); @@ -222,7 +204,7 @@ GIT_EXTERN(int) git_reference_delete(git_reference *ref); * references previously loaded on the cache. * * @param repo Repository where the loose refs will be packed - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_reference_packall(git_repository *repo); @@ -245,7 +227,7 @@ GIT_EXTERN(int) git_reference_packall(git_repository *repo); * @param repo Repository where to find the refs * @param list_flags Filtering flags for the reference * listing. - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_reference_listall(git_strarray *array, git_repository *repo, unsigned int list_flags); @@ -267,7 +249,7 @@ GIT_EXTERN(int) git_reference_listall(git_strarray *array, git_repository *repo, * listing. * @param callback Function which will be called for every listed ref * @param payload Additional data to pass to the callback - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_reference_foreach(git_repository *repo, unsigned int list_flags, int (*callback)(const char *, void *), void *payload); diff --git a/include/git2/refspec.h b/include/git2/refspec.h index dd0dc5873..eccbeaa7c 100644 --- a/include/git2/refspec.h +++ b/include/git2/refspec.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_refspec_h__ #define INCLUDE_git_refspec_h__ @@ -69,7 +51,7 @@ int git_refspec_src_match(const git_refspec *refspec, const char *refname); * @param outlen the size ouf the `out` buffer * @param spec the refspec * @param name the name of the reference to transform - * @preturn GIT_SUCCESS, GIT_ESHORTBUFFER or another error + * @return GIT_SUCCESS, GIT_ESHORTBUFFER or another error */ int git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, const char *name); diff --git a/include/git2/remote.h b/include/git2/remote.h index 651e41075..e0be93757 100644 --- a/include/git2/remote.h +++ b/include/git2/remote.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_remote_h__ #define INCLUDE_git_remote_h__ @@ -53,7 +35,7 @@ GIT_BEGIN_DECL * @param out pointer to the new remote object * @param repo the associtated repository * @param url the remote repository's URL - * @return GIT_SUCCESS or an error message + * @return GIT_SUCCESS or an error code */ int git_remote_new(git_remote **out, git_repository *repo, const char *url); @@ -63,7 +45,7 @@ int git_remote_new(git_remote **out, git_repository *repo, const char *url); * @param out pointer to the new remote object * @param cfg the repository's configuration * @param name the remote's name - * @return 0 on success; error value otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_remote_get(struct git_remote **out, struct git_config *cfg, const char *name); diff --git a/include/git2/repository.h b/include/git2/repository.h index 4088ff7f9..d12cfbec7 100644 --- a/include/git2/repository.h +++ b/include/git2/repository.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_repository_h__ #define INCLUDE_git_repository_h__ @@ -59,7 +41,7 @@ GIT_BEGIN_DECL * * @param repository pointer to the repo which will be opened * @param path the path to the repository - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_repository_open(git_repository **repository, const char *path); @@ -88,7 +70,7 @@ GIT_EXTERN(int) git_repository_open(git_repository **repository, const char *pat * Equivalent to $GIT_WORK_TREE. * If NULL, the repository is assumed to be bare. * - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_repository_open2(git_repository **repository, const char *git_dir, @@ -123,7 +105,7 @@ GIT_EXTERN(int) git_repository_open2(git_repository **repository, * Equivalent to $GIT_WORK_TREE. * If NULL, the repository is assumed to be bare. * - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_repository_open3(git_repository **repository, @@ -156,7 +138,7 @@ GIT_EXTERN(int) git_repository_open3(git_repository **repository, * lookup always performs on start_path no matter start_path appears in ceiling_dirs * ceiling_dirs might be NULL (which is equivalent to an empty string) * - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_repository_discover(char *repository_path, size_t size, const char *start_path, int across_fs, const char *ceiling_dirs); @@ -184,7 +166,7 @@ GIT_EXTERN(git_odb *) git_repository_database(git_repository *repo); * * @param index Pointer where to store the index * @param repo a repository object - * @return 0 on success; error code if the index could not be opened + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_repository_index(git_index **index, git_repository *repo); @@ -214,11 +196,21 @@ GIT_EXTERN(void) git_repository_free(git_repository *repo); * at the pointed path. If false, provided path will be considered as the working * directory into which the .git directory will be created. * - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_repository_init(git_repository **repo_out, const char *path, unsigned is_bare); /** + * Retrieve and resolve the reference pointed at by HEAD. + * + * @param head_out pointer to the reference which will be retrieved + * @param repo a repository object + * + * @return 0 on success; error code otherwise + */ +GIT_EXTERN(int) git_repository_head(git_reference **head_out, git_repository *repo); + +/** * Check if a repository's HEAD is detached * * A repository's HEAD is detached when it points directly to a commit @@ -292,13 +284,10 @@ GIT_EXTERN(int) git_repository_is_bare(git_repository *repo); /** * Retrieve the relevant configuration for a repository * - * By default he returned `git_config` instance contains a single - * configuration file, the `.gitconfig' file that may be found - * inside the repository. - * - * If the `user_config_path` variable is not NULL, the given config - * file will be also included in the configuration set. On most UNIX - * systems, this file may be found on `$HOME/.gitconfig`. + * By default he returned `git_config` instance contains the two most + * common configuration files, the `config' file that may be found + * inside the repository, and the `$HOME/.gitconfig' "global" + * configuration file. * * If the `system_config_path` variable is not NULL, the given config * file will be also included in the configuration set. On most UNIX @@ -308,23 +297,21 @@ GIT_EXTERN(int) git_repository_is_bare(git_repository *repo); * order: * * - Repository configuration file - * - User configuration file + * - Global configuration file * - System configuration file * - * The method will fail if any of the passed config files cannot be - * found or accessed. + * The method will fail if any of the passed system config file found + * or accessed. * * The returned `git_config` instance is owned by the caller and must * be manually free'd once it's no longer on use. * * @param out the repository's configuration * @param repo the repository for which to get the config - * @param user_config_path Path to the user config file * @param system_config_path Path to the system-wide config file */ GIT_EXTERN(int) git_repository_config(git_config **out, git_repository *repo, - const char *user_config_path, const char *system_config_path); /** @} */ diff --git a/include/git2/revwalk.h b/include/git2/revwalk.h index b37a16c83..c84c5d301 100644 --- a/include/git2/revwalk.h +++ b/include/git2/revwalk.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_revwalk_h__ #define INCLUDE_git_revwalk_h__ @@ -44,28 +26,28 @@ GIT_BEGIN_DECL * and subject to change at any time. * 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 * (parents before children); this sorting mode * 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; * this sorting mode can be combined with * topological sorting. */ -#define GIT_SORT_TIME (1 << 1) +#define GIT_SORT_TIME (1 << 1) /** * Iterate through the repository contents in reverse * order; this sorting mode can be combined with * 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. @@ -83,7 +65,7 @@ GIT_BEGIN_DECL * * @param walker pointer to the new revision walker * @param repo the repo to walk through - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_revwalk_new(git_revwalk **walker, git_repository *repo); @@ -115,7 +97,7 @@ GIT_EXTERN(void) git_revwalk_reset(git_revwalk *walker); * * @param walk the walker being used for the traversal. * @param oid the oid of the commit to start from. - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_revwalk_push(git_revwalk *walk, const git_oid *oid); @@ -131,7 +113,7 @@ GIT_EXTERN(int) git_revwalk_push(git_revwalk *walk, const git_oid *oid); * * @param walk the walker being used for the traversal. * @param oid the oid of commit that will be ignored during the traversal - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_revwalk_hide(git_revwalk *walk, const git_oid *oid); @@ -169,7 +151,7 @@ GIT_EXTERN(void) git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode); /** * 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); diff --git a/include/git2/signature.h b/include/git2/signature.h index f5d03ac77..228929943 100644 --- a/include/git2/signature.h +++ b/include/git2/signature.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_signature_h__ #define INCLUDE_git_signature_h__ @@ -46,7 +28,7 @@ GIT_BEGIN_DECL * @param email email of the person * @param time time when the action happened * @param offset timezone offset in minutes for the time - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_signature_new(git_signature **sig_out, const char *name, const char *email, git_time_t time, int offset); @@ -57,7 +39,7 @@ GIT_EXTERN(int) git_signature_new(git_signature **sig_out, const char *name, con * @param sig_out new signature, in case of error NULL * @param name name of the person * @param email email of the person - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_signature_now(git_signature **sig_out, const char *name, const char *email); diff --git a/include/git2/status.h b/include/git2/status.h index 7946cc1f3..42b2dd197 100644 --- a/include/git2/status.h +++ b/include/git2/status.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_status_h__ #define INCLUDE_git_status_h__ @@ -37,19 +19,19 @@ */ GIT_BEGIN_DECL -#define GIT_STATUS_CURRENT 0 +#define GIT_STATUS_CURRENT 0 /** 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_DELETED (1 << 2) +#define GIT_STATUS_INDEX_DELETED (1 << 2) /** Flags for worktree status */ -#define GIT_STATUS_WT_NEW (1 << 3) -#define GIT_STATUS_WT_MODIFIED (1 << 4) -#define GIT_STATUS_WT_DELETED (1 << 5) +#define GIT_STATUS_WT_NEW (1 << 3) +#define GIT_STATUS_WT_MODIFIED (1 << 4) +#define GIT_STATUS_WT_DELETED (1 << 5) // 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. @@ -60,7 +42,7 @@ GIT_BEGIN_DECL * * @param repo a repository object * @param callback the function to call on each file - * @return GIT_SUCCESS or the return value of the callback which did not return 0; + * @return GIT_SUCCESS or the return value of the callback which did not return GIT_SUCCESS */ GIT_EXTERN(int) git_status_foreach(git_repository *repo, int (*callback)(const char *, unsigned int, void *), void *payload); @@ -70,7 +52,9 @@ GIT_EXTERN(int) git_status_foreach(git_repository *repo, int (*callback)(const c * @param status_flags the status value * @param repo a repository object * @param path the file to retrieve status for, rooted at the repo's workdir - * @return GIT_SUCCESS + * @return GIT_EINVALIDPATH when `path` points at a folder, GIT_ENOTFOUND when + * the file doesn't exist in any of HEAD, the index or the worktree, + * GIT_SUCCESS otherwise */ GIT_EXTERN(int) git_status_file(unsigned int *status_flags, git_repository *repo, const char *path); diff --git a/include/git2/tag.h b/include/git2/tag.h index 2b10d4525..63a522882 100644 --- a/include/git2/tag.h +++ b/include/git2/tag.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_tag_h__ #define INCLUDE_git_tag_h__ @@ -45,7 +27,7 @@ GIT_BEGIN_DECL * @param tag pointer to the looked up tag * @param repo the repo to use when locating the tag. * @param id identity of the tag to locate. - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_INLINE(int) git_tag_lookup(git_tag **tag, git_repository *repo, const git_oid *id) { @@ -62,7 +44,7 @@ GIT_INLINE(int) git_tag_lookup(git_tag **tag, git_repository *repo, const git_oi * @param repo the repo to use when locating the tag. * @param id identity of the tag to locate. * @param len the length of the short identifier - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_INLINE(int) git_tag_lookup_prefix(git_tag **tag, git_repository *repo, const git_oid *id, unsigned int len) { @@ -103,7 +85,7 @@ GIT_EXTERN(const git_oid *) git_tag_id(git_tag *tag); * * @param target pointer where to store the target * @param tag a previously loaded tag. - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_tag_target(git_object **target, git_tag *tag); @@ -170,13 +152,13 @@ GIT_EXTERN(const char *) git_tag_message(git_tag *tag); * must belong to the given `repo`. * * @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 force Overwrite existing references * - * @return 0 on success; error code otherwise. + * @return GIT_SUCCESS or an error code * A tag object is written to the ODB, and a proper reference * is written in the /refs/tags folder, pointing to it */ @@ -227,9 +209,9 @@ GIT_EXTERN(int) git_tag_create_frombuffer( * * @param force Overwrite existing references * - * @return 0 on success; error code otherwise. + * @return GIT_SUCCESS or an error code * 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_oid *oid, @@ -246,7 +228,7 @@ GIT_EXTERN(int) git_tag_create_lightweight( * @param tag_name Name of the tag to be deleted; * this name is validated for consistency. * - * @return 0 on success; error code otherwise. + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_tag_delete( git_repository *repo, @@ -263,7 +245,7 @@ GIT_EXTERN(int) git_tag_delete( * @param tag_names Pointer to a git_strarray structure where * the tag names will be stored * @param repo Repository where to find the tags - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_tag_list( git_strarray *tag_names, @@ -285,7 +267,7 @@ GIT_EXTERN(int) git_tag_list( * the tag names will be stored * @param pattern Standard fnmatch pattern * @param repo Repository where to find the tags - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_tag_list_match( git_strarray *tag_names, diff --git a/include/git2/thread-utils.h b/include/git2/thread-utils.h index 62e6199a4..81c62d135 100644 --- a/include/git2/thread-utils.h +++ b/include/git2/thread-utils.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_thread_utils_h__ #define INCLUDE_git_thread_utils_h__ @@ -28,51 +10,51 @@ /* * How TLS works is compiler+platform dependant * Sources: http://en.wikipedia.org/wiki/Thread-Specific_Storage - * http://predef.sourceforge.net/precomp.html + * http://predef.sourceforge.net/precomp.html */ #ifdef GIT_THREADS -# define GIT_HAS_TLS 1 +# define GIT_HAS_TLS 1 /* No TLS in Cygwin */ -# if defined(__CHECKER__) || defined(__CYGWIN__) -# undef GIT_HAS_TLS -# define GIT_TLS +# if defined(__CHECKER__) || defined(__CYGWIN__) +# undef GIT_HAS_TLS +# define GIT_TLS /* No TLS in Mach binaries for Mac OS X */ -# elif defined(__APPLE__) && defined(__MACH__) -# undef GIT_TLS -# define GIT_TLS +# elif defined(__APPLE__) && defined(__MACH__) +# undef GIT_TLS +# define GIT_TLS /* Normal TLS for GCC */ -# elif defined(__GNUC__) || \ - defined(__SUNPRO_C) || \ - defined(__SUNPRO_CC) || \ - defined(__xlc__) || \ - defined(__xlC__) -# define GIT_TLS __thread +# elif defined(__GNUC__) || \ + defined(__SUNPRO_C) || \ + defined(__SUNPRO_CC) || \ + defined(__xlc__) || \ + defined(__xlC__) +# define GIT_TLS __thread /* ICC may run on Windows or Linux */ -# elif defined(__INTEL_COMPILER) -# if defined(_WIN32) || defined(_WIN32_CE) -# define GIT_TLS __declspec(thread) -# else -# define GIT_TLS __thread -# endif +# elif defined(__INTEL_COMPILER) +# if defined(_WIN32) || defined(_WIN32_CE) +# define GIT_TLS __declspec(thread) +# else +# define GIT_TLS __thread +# endif /* Declspec for MSVC in Win32 */ -# elif defined(_WIN32) || \ - defined(_WIN32_CE) || \ - defined(__BORLANDC__) -# define GIT_TLS __declspec(thread) +# elif defined(_WIN32) || \ + defined(_WIN32_CE) || \ + defined(__BORLANDC__) +# define GIT_TLS __declspec(thread) /* Other platform; no TLS */ -# else -# undef GIT_HAS_TLS -# define GIT_TLS /* nothing: tls vars are thread-global */ -# endif +# else +# undef GIT_HAS_TLS +# define GIT_TLS /* nothing: tls vars are thread-global */ +# endif #else /* Disable TLS if libgit2 is not threadsafe */ -# define GIT_TLS +# define GIT_TLS #endif /* GIT_THREADS */ #endif /* INCLUDE_git_thread_utils_h__ */ diff --git a/include/git2/transport.h b/include/git2/transport.h index d19eb8a88..ddae32d40 100644 --- a/include/git2/transport.h +++ b/include/git2/transport.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_transport_h__ #define INCLUDE_git_transport_h__ diff --git a/include/git2/tree.h b/include/git2/tree.h index 5656f48f3..d781ea136 100644 --- a/include/git2/tree.h +++ b/include/git2/tree.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_tree_h__ #define INCLUDE_git_tree_h__ @@ -45,7 +27,7 @@ GIT_BEGIN_DECL * @param tree pointer to the looked up tree * @param repo the repo to use when locating the tree. * @param id identity of the tree to locate. - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_INLINE(int) git_tree_lookup(git_tree **tree, git_repository *repo, const git_oid *id) { @@ -62,7 +44,7 @@ GIT_INLINE(int) git_tree_lookup(git_tree **tree, git_repository *repo, const git * @param repo the repo to use when locating the tree. * @param id identity of the tree to locate. * @param len the length of the short identifier - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_INLINE(int) git_tree_lookup_prefix(git_tree **tree, git_repository *repo, const git_oid *id, unsigned int len) { @@ -159,7 +141,7 @@ GIT_EXTERN(git_otype) git_tree_entry_type(const git_tree_entry *entry); * @param object pointer to the converted object * @param repo repository where to lookup the pointed object * @param entry a tree entry - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_tree_entry_2object(git_object **object_out, git_repository *repo, const git_tree_entry *entry); @@ -177,7 +159,7 @@ GIT_EXTERN(int) git_tree_entry_2object(git_object **object_out, git_repository * * * @param oid Pointer where to store the written tree * @param index Index to write - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_tree_create_fromindex(git_oid *oid, git_index *index); @@ -247,7 +229,7 @@ GIT_EXTERN(const git_tree_entry *) git_treebuilder_get(git_treebuilder *bld, con * @param filename Filename of the entry * @param id SHA1 oid of the entry * @param attributes Folder attributes of the entry - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_treebuilder_insert(git_tree_entry **entry_out, git_treebuilder *bld, const char *filename, const git_oid *id, unsigned int attributes); @@ -282,7 +264,7 @@ GIT_EXTERN(void) git_treebuilder_filter(git_treebuilder *bld, int (*filter)(cons * @param oid Pointer where to store the written OID * @param repo Repository where to store the object * @param bld Tree builder to write - * @return 0 on success; error code otherwise + * @return GIT_SUCCESS or an error code */ GIT_EXTERN(int) git_treebuilder_write(git_oid *oid, git_repository *repo, git_treebuilder *bld); diff --git a/include/git2/types.h b/include/git2/types.h index b9db4e529..1df18974a 100644 --- a/include/git2/types.h +++ b/include/git2/types.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_types_h__ #define INCLUDE_git_types_h__ @@ -54,7 +36,7 @@ GIT_BEGIN_DECL #if defined(_MSC_VER) typedef __int64 git_off_t; -typedef __time64_t git_time_t; +typedef __time64_t git_time_t; #elif defined(__MINGW32__) @@ -66,7 +48,7 @@ typedef __time64_t git_time_t; typedef __haiku_std_int64 git_off_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> @@ -81,15 +63,15 @@ typedef int64_t git_time_t; /** Basic type (loose or packed) of any Git object. */ typedef enum { GIT_OBJ_ANY = -2, /**< Object can be any of the following */ - GIT_OBJ_BAD = -1, /**< Object is invalid. */ - GIT_OBJ__EXT1 = 0, /**< Reserved for future use. */ - GIT_OBJ_COMMIT = 1, /**< A commit object. */ - GIT_OBJ_TREE = 2, /**< A tree (directory listing) object. */ - GIT_OBJ_BLOB = 3, /**< A file revision object. */ - GIT_OBJ_TAG = 4, /**< An annotated tag object. */ - GIT_OBJ__EXT2 = 5, /**< Reserved for future use. */ - GIT_OBJ_OFS_DELTA = 6, /**< A delta, base is given by an offset. */ - GIT_OBJ_REF_DELTA = 7, /**< A delta, base is given by object id. */ + GIT_OBJ_BAD = -1, /**< Object is invalid. */ + GIT_OBJ__EXT1 = 0, /**< Reserved for future use. */ + GIT_OBJ_COMMIT = 1, /**< A commit object. */ + GIT_OBJ_TREE = 2, /**< A tree (directory listing) object. */ + GIT_OBJ_BLOB = 3, /**< A file revision object. */ + GIT_OBJ_TAG = 4, /**< An annotated tag object. */ + GIT_OBJ__EXT2 = 5, /**< Reserved for future use. */ + GIT_OBJ_OFS_DELTA = 6, /**< A delta, base is given by an offset. */ + GIT_OBJ_REF_DELTA = 7, /**< A delta, base is given by object id. */ } git_otype; /** An open object database handle. */ diff --git a/include/git2/zlib.h b/include/git2/zlib.h index 493566340..e3dd23f96 100644 --- a/include/git2/zlib.h +++ b/include/git2/zlib.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_git_zlib_h__ #define INCLUDE_git_zlib_h__ diff --git a/src/blob.c b/src/blob.c index b8282e505..42564ab50 100644 --- a/src/blob.c +++ b/src/blob.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "git2/common.h" @@ -36,7 +18,7 @@ const void *git_blob_rawcontent(git_blob *blob) return blob->odb_object->raw.data; } -int git_blob_rawsize(git_blob *blob) +size_t git_blob_rawsize(git_blob *blob) { assert(blob); return blob->odb_object->raw.len; diff --git a/src/blob.h b/src/blob.h index 4300d7e54..0cc9900c9 100644 --- a/src/blob.h +++ b/src/blob.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_blob_h__ #define INCLUDE_blob_h__ diff --git a/src/bswap.h b/src/bswap.h index b9211c3c8..0914906ff 100644 --- a/src/bswap.h +++ b/src/bswap.h @@ -1,8 +1,8 @@ /* - * Let's make sure we always have a sane definition for ntohl()/htonl(). - * Some libraries define those as a function call, just to perform byte - * shifting, bringing significant overhead to what should be a simple - * operation. + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" @@ -14,8 +14,8 @@ GIT_INLINE(uint32_t) default_swab32(uint32_t val) { return (((val & 0xff000000) >> 24) | - ((val & 0x00ff0000) >> 8) | - ((val & 0x0000ff00) << 8) | + ((val & 0x00ff0000) >> 8) | + ((val & 0x0000ff00) << 8) | ((val & 0x000000ff) << 24)); } diff --git a/src/buffer.c b/src/buffer.c index 6af4c9195..b1be29241 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #include "buffer.h" #include "posix.h" #include <stdarg.h> diff --git a/src/buffer.h b/src/buffer.h index 1209340a1..14233b82b 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_buffer_h__ #define INCLUDE_buffer_h__ diff --git a/src/cache.c b/src/cache.c index fca7e1236..79f3eaea2 100644 --- a/src/cache.c +++ b/src/cache.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" diff --git a/src/cache.h b/src/cache.h index 4794dea3a..8c885d9a5 100644 --- a/src/cache.h +++ b/src/cache.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_cache_h__ #define INCLUDE_cache_h__ diff --git a/src/cc-compat.h b/src/cc-compat.h index cf6cccf12..cce4ca9b1 100644 --- a/src/cc-compat.h +++ b/src/cc-compat.h @@ -1,5 +1,8 @@ /* - * cc-compat.h - C compiler compat macros for internal use + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_compat_h__ #define INCLUDE_compat_h__ @@ -9,18 +12,18 @@ */ #ifndef GIT_FLEX_ARRAY # if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) -# define GIT_FLEX_ARRAY /* empty */ +# define GIT_FLEX_ARRAY /* empty */ # elif defined(__GNUC__) -# if (__GNUC__ >= 3) -# define GIT_FLEX_ARRAY /* empty */ -# else -# define GIT_FLEX_ARRAY 0 /* older GNU extension */ -# endif +# if (__GNUC__ >= 3) +# define GIT_FLEX_ARRAY /* empty */ +# else +# define GIT_FLEX_ARRAY 0 /* older GNU extension */ +# endif # endif /* Default to safer but a bit wasteful traditional style */ # ifndef GIT_FLEX_ARRAY -# define GIT_FLEX_ARRAY 1 +# define GIT_FLEX_ARRAY 1 # endif #endif @@ -34,9 +37,9 @@ # define GIT_UNUSED(x) #else # ifdef __GNUC__ -# define GIT_UNUSED(x) x __attribute__ ((__unused__)) +# define GIT_UNUSED(x) x __attribute__ ((__unused__)) # else -# define GIT_UNUSED(x) x +# define GIT_UNUSED(x) x # endif #endif diff --git a/src/commit.c b/src/commit.c index d9cc11078..0ee3854c4 100644 --- a/src/commit.c +++ b/src/commit.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "git2/common.h" diff --git a/src/commit.h b/src/commit.h index 6d1caeeeb..bfc4bba19 100644 --- a/src/commit.h +++ b/src/commit.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_commit_h__ #define INCLUDE_commit_h__ diff --git a/src/common.h b/src/common.h index 5986a6568..f4ea1ebf7 100644 --- a/src/common.h +++ b/src/common.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_common_h__ #define INCLUDE_common_h__ @@ -26,18 +32,20 @@ # include "win32/msvc-compat.h" # include "win32/mingw-compat.h" # ifdef GIT_THREADS -# include "win32/pthread.h" +# include "win32/pthread.h" #endif # define snprintf _snprintf +#ifndef _SSIZE_T_DEFINED typedef SSIZE_T ssize_t; +#endif #else # include <unistd.h> # ifdef GIT_THREADS -# include <pthread.h> +# include <pthread.h> # endif #endif diff --git a/src/config.c b/src/config.c index 771250731..f233e76fd 100644 --- a/src/config.c +++ b/src/config.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" @@ -43,6 +25,9 @@ void git_config_free(git_config *cfg) git_config_file *file; file_internal *internal; + if (cfg == NULL) + return; + for(i = 0; i < cfg->files.length; ++i){ internal = git_vector_get(&cfg->files, i); file = internal->file; @@ -169,7 +154,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) { - return git_config_set_string(cfg, name, NULL); + return git_config_set_string(cfg, name, NULL); } /************** diff --git a/src/config.h b/src/config.h index e2f301bf1..7749a9c1a 100644 --- a/src/config.h +++ b/src/config.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_config_h__ #define INCLUDE_config_h__ diff --git a/src/config_file.c b/src/config_file.c index fc41590f6..f76efed97 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" @@ -135,7 +117,7 @@ static int cvar_match_section(const char *local, const char *input) { char *first_dot; char *local_sp = strchr(local, ' '); - int comparison_len; + size_t comparison_len; /* * If the local section name doesn't contain a space, then we can @@ -198,7 +180,8 @@ static int cvar_normalize_name(cvar_t *var, char **output) { char *section_sp = strchr(var->section, ' '); char *quote, *name; - int len, ret; + size_t len; + int ret; /* * The final string is going to be at most one char longer than @@ -245,7 +228,7 @@ static int cvar_normalize_name(cvar_t *var, char **output) static char *interiorize_section(const char *orig) { char *dot, *last_dot, *section, *ret; - int len; + size_t len; dot = strchr(orig, '.'); last_dot = strrchr(orig, '.'); @@ -530,7 +513,7 @@ static char *cfg_readline(diskfile_backend *cfg) { char *line = NULL; char *line_src, *line_end; - int line_len; + size_t line_len; line_src = cfg->reader.read_ptr; @@ -538,9 +521,9 @@ static char *cfg_readline(diskfile_backend *cfg) while (isspace(*line_src)) ++line_src; - line_end = strchr(line_src, '\n'); + line_end = strchr(line_src, '\n'); - /* no newline at EOF */ + /* no newline at EOF */ if (line_end == NULL) line_end = strchr(line_src, 0); @@ -552,10 +535,8 @@ static char *cfg_readline(diskfile_backend *cfg) memcpy(line, line_src, line_len); - line[line_len] = '\0'; - - while (--line_len >= 0 && isspace(line[line_len])) - line[line_len] = '\0'; + do line[line_len] = '\0'; + while (line_len-- > 0 && isspace(line[line_len])); if (*line_end == '\n') line_end++; @@ -600,7 +581,8 @@ GIT_INLINE(int) config_keychar(int c) static int parse_section_header_ext(const char *line, const char *base_name, char **section_name) { - int buf_len, total_len, pos, rpos; + size_t buf_len, total_len; + int pos, rpos; int c, ret; char *subsection, *first_quote, *last_quote; int error = GIT_SUCCESS; @@ -764,7 +746,7 @@ static int skip_bom(diskfile_backend *cfg) if (memcmp(cfg->reader.read_ptr, utf8_bom, sizeof(utf8_bom)) == 0) 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 */ @@ -1035,7 +1017,7 @@ static int config_write(diskfile_backend *cfg, cvar_t *var) /* And then the write out rest of the file */ 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) { git__rethrow(error, "Failed to write the rest of the file"); @@ -1100,7 +1082,8 @@ static int is_multiline_var(const char *str) static int parse_multiline_variable(diskfile_backend *cfg, const char *first, char **out) { char *line = NULL, *end; - int error = GIT_SUCCESS, len, ret; + int error = GIT_SUCCESS, ret; + size_t len; char *buf; /* Check that the next line exists */ diff --git a/src/delta-apply.c b/src/delta-apply.c index a6b711436..e1fb15b9b 100644 --- a/src/delta-apply.c +++ b/src/delta-apply.c @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #include "common.h" #include "git2/odb.h" #include "delta-apply.h" @@ -5,7 +11,7 @@ /* * This file was heavily cribbed from BinaryDelta.java in JGit, which * 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>. */ @@ -64,15 +70,15 @@ int git__delta_apply( */ size_t off = 0, len = 0; - if (cmd & 0x01) off = *delta++; - if (cmd & 0x02) off |= *delta++ << 8; + if (cmd & 0x01) off = *delta++; + if (cmd & 0x02) off |= *delta++ << 8; if (cmd & 0x04) off |= *delta++ << 16; if (cmd & 0x08) off |= *delta++ << 24; - if (cmd & 0x10) len = *delta++; - if (cmd & 0x20) len |= *delta++ << 8; + if (cmd & 0x10) len = *delta++; + if (cmd & 0x20) len |= *delta++ << 8; if (cmd & 0x40) len |= *delta++ << 16; - if (!len) len = 0x10000; + if (!len) len = 0x10000; if (base_len < off + len || res_sz < len) goto fail; @@ -87,7 +93,7 @@ int git__delta_apply( if (delta_end - delta < cmd || res_sz < cmd) goto fail; memcpy(res_dp, delta, cmd); - delta += cmd; + delta += cmd; res_dp += cmd; res_sz -= cmd; diff --git a/src/delta-apply.h b/src/delta-apply.h index 36c5cc60d..42ded3e0b 100644 --- a/src/delta-apply.h +++ b/src/delta-apply.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_delta_apply_h__ #define INCLUDE_delta_apply_h__ @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_dir_h__ #define INCLUDE_dir_h__ @@ -10,7 +16,7 @@ #ifdef GIT_WIN32 struct git__dirent { - int d_ino; + int d_ino; char d_name[261]; }; @@ -28,12 +34,12 @@ extern void git__rewinddir(git__DIR *); extern int git__closedir(git__DIR *); # ifndef GIT__WIN32_NO_WRAP_DIR -# define dirent git__dirent -# define DIR git__DIR -# define opendir git__opendir -# define readdir git__readdir -# define rewinddir git__rewinddir -# define closedir git__closedir +# define dirent git__dirent +# define DIR git__DIR +# define opendir git__opendir +# define readdir git__readdir +# define rewinddir git__rewinddir +# define closedir git__closedir # endif #endif diff --git a/src/errors.c b/src/errors.c index 5031245de..60d774636 100644 --- a/src/errors.c +++ b/src/errors.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" #include "git2/thread-utils.h" /* for GIT_TLS */ @@ -89,7 +71,7 @@ void git___rethrow(const char *msg, ...) va_end(va); 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); } diff --git a/src/fetch.c b/src/fetch.c index 74c93da8d..1bb896870 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "git2/remote.h" diff --git a/src/fetch.h b/src/fetch.h index ad4451ffe..6ca21d5b4 100644 --- a/src/fetch.h +++ b/src/fetch.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_fetch_h__ #define INCLUDE_fetch_h__ diff --git a/src/filebuf.c b/src/filebuf.c index 6d398a7db..bc1a8dceb 100644 --- a/src/filebuf.c +++ b/src/filebuf.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include <stdarg.h> @@ -116,24 +98,25 @@ static int write_deflate(git_filebuf *file, void *source, size_t len) z_stream *zs = &file->zs; if (len > 0 || file->flush_mode == Z_FINISH) { - zs->next_in = (void *)source; - zs->avail_in = len; + zs->next_in = source; + zs->avail_in = (uInt)len; do { - int have; + size_t have; zs->next_out = file->z_buf; - zs->avail_out = file->buf_size; + zs->avail_out = (uInt)file->buf_size; - result = deflate(zs, file->flush_mode); - assert(result != Z_STREAM_ERROR); + result = deflate(zs, file->flush_mode); + if (result == Z_STREAM_ERROR) + return git__throw(GIT_ERROR, "Failed to deflate input"); - have = file->buf_size - zs->avail_out; + have = file->buf_size - (size_t)zs->avail_out; if (p_write(file->fd, file->z_buf, have) < GIT_SUCCESS) return git__throw(GIT_EOSERR, "Failed to write to file"); - } while (zs->avail_out == 0); + } while (zs->avail_out == 0); assert(zs->avail_in == 0); diff --git a/src/filebuf.h b/src/filebuf.h index 9154cabcd..d20881e9f 100644 --- a/src/filebuf.h +++ b/src/filebuf.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_filebuf_h__ #define INCLUDE_filebuf_h__ diff --git a/src/fileops.c b/src/fileops.c index d7413a138..bfd63f584 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #include "common.h" #include "fileops.h" #include <ctype.h> @@ -188,7 +194,7 @@ int git_futils_readbuffer_updated(git_fbuffer *obj, const char *path, time_t *mt *updated = 1; obj->data = buff; - obj->len = len; + obj->len = len; return GIT_SUCCESS; } @@ -287,7 +293,7 @@ int git_futils_mkdir_r(const char *path, int mode) { int error, root_path_offset; char *pp, *sp; - char *path_copy = git__strdup(path); + char *path_copy = git__strdup(path); if (path_copy == NULL) return GIT_ENOMEM; @@ -299,7 +305,7 @@ int git_futils_mkdir_r(const char *path, int mode) if (root_path_offset > 0) 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) { *sp = 0; error = p_mkdir(path_copy, mode); @@ -353,7 +359,7 @@ int git_futils_rmdir_r(const char *path, int force) { char p[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, @@ -367,10 +373,10 @@ int git_futils_cmp_path(const char *name1, int len1, int isdir1, return cmp; if (len1 < len2) return ((!isdir1 && !isdir2) ? -1 : - (isdir1 ? '/' - name2[len1] : name2[len1] - '/')); + (isdir1 ? '/' - name2[len1] : name2[len1] - '/')); if (len1 > len2) return ((!isdir1 && !isdir2) ? 1 : - (isdir2 ? name1[len2] - '/' : '/' - name1[len2])); + (isdir2 ? name1[len2] - '/' : '/' - name1[len2])); return 0; } diff --git a/src/fileops.h b/src/fileops.h index 84c35e41b..5b69199d2 100644 --- a/src/fileops.h +++ b/src/fileops.h @@ -1,7 +1,8 @@ /* - * fileops.h - OS agnostic disk io operations + * Copyright (C) 2009-2011 the libgit2 contributors * - * This header describes the strictly internal part of the api + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_fileops_h__ #define INCLUDE_fileops_h__ @@ -19,9 +20,9 @@ */ #define GIT_FBUFFER_INIT {NULL, 0} -typedef struct { /* file io buffer */ - void *data; /* data bytes */ - size_t len; /* data length */ +typedef struct { /* file io buffer */ + void *data; /* data bytes */ + size_t len; /* data length */ } git_fbuffer; extern int git_futils_readbuffer(git_fbuffer *obj, const char *path); @@ -138,8 +139,8 @@ extern void git_futils_mmap_free(git_map *map); * @param pathbuf buffer the function reads the initial directory * path from, and updates with each successive entry's name. * @param pathmax maximum allocation of pathbuf. - * @param fn function to invoke with each entry. The first arg is - * the input state and the second arg is pathbuf. The function + * @param fn function to invoke with each entry. The first arg is + * the input state and the second arg is pathbuf. The function * may modify the pathbuf, but only by appending new text. * @param state to pass to fn as the first arg. */ diff --git a/src/hash.c b/src/hash.c index b8b311bcb..ff85ca957 100644 --- a/src/hash.c +++ b/src/hash.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" diff --git a/src/hash.h b/src/hash.h index 2b769a4c9..fe1ba5d46 100644 --- a/src/hash.h +++ b/src/hash.h @@ -1,5 +1,8 @@ /* - * hash.h + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_hash_h__ #define INCLUDE_hash_h__ diff --git a/src/hashtable.c b/src/hashtable.c index 86e5a113a..1382eabaa 100644 --- a/src/hashtable.c +++ b/src/hashtable.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" diff --git a/src/hashtable.h b/src/hashtable.h index be21be2b1..f0ca3ebd2 100644 --- a/src/hashtable.h +++ b/src/hashtable.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_hashtable_h__ #define INCLUDE_hashtable_h__ diff --git a/src/index.c b/src/index.c index f20c2a7ab..e6a181979 100644 --- a/src/index.c +++ b/src/index.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include <stddef.h> @@ -706,7 +688,7 @@ static int read_unmerged(git_index *index, const char *buffer, size_t size) long tmp; if (git__strtol32(&tmp, buffer, &endptr, 8) < GIT_SUCCESS || - !endptr || endptr == buffer || *endptr || tmp > UINT_MAX) + !endptr || endptr == buffer || *endptr || (unsigned)tmp > UINT_MAX) return GIT_ERROR; lost->mode[i] = tmp; @@ -981,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->ctime.nanoseconds = htonl(entry->ctime.nanoseconds); ondisk->mtime.nanoseconds = htonl(entry->mtime.nanoseconds); - ondisk->dev = htonl(entry->dev); - ondisk->ino = htonl(entry->ino); + ondisk->dev = htonl(entry->dev); + ondisk->ino = htonl(entry->ino); ondisk->mode = htonl(entry->mode); - ondisk->uid = htonl(entry->uid); - ondisk->gid = htonl(entry->gid); + ondisk->uid = htonl(entry->uid); + ondisk->gid = htonl(entry->gid); ondisk->file_size = htonl((uint32_t)entry->file_size); git_oid_cpy(&ondisk->oid, &entry->oid); diff --git a/src/index.h b/src/index.h index f2402fd71..76633a96a 100644 --- a/src/index.h +++ b/src/index.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_index_h__ #define INCLUDE_index_h__ diff --git a/src/indexer.c b/src/indexer.c index 3934250e2..07803355e 100644 --- a/src/indexer.c +++ b/src/indexer.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "git2/indexer.h" @@ -99,7 +81,7 @@ static int cache_cmp(const void *a, const void *b) int git_indexer_new(git_indexer **out, const char *packname) { git_indexer *idx; - unsigned int namelen; + size_t namelen; int ret, error; assert(out && packname); @@ -186,7 +168,8 @@ static void index_path(char *path, git_indexer *idx) int git_indexer_write(git_indexer *idx) { git_mwindow *w = NULL; - int error, namelen; + int error; + size_t namelen; unsigned int i, long_offsets = 0, left; struct git_pack_idx_header hdr; char filename[GIT_PATH_MAX]; @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_map_h__ #define INCLUDE_map_h__ @@ -5,23 +11,23 @@ /* p_mmap() prot values */ -#define GIT_PROT_NONE 0x0 -#define GIT_PROT_READ 0x1 +#define GIT_PROT_NONE 0x0 +#define GIT_PROT_READ 0x1 #define GIT_PROT_WRITE 0x2 -#define GIT_PROT_EXEC 0x4 +#define GIT_PROT_EXEC 0x4 /* git__mmmap() flags values */ -#define GIT_MAP_FILE 0 -#define GIT_MAP_SHARED 1 +#define GIT_MAP_FILE 0 +#define GIT_MAP_SHARED 1 #define GIT_MAP_PRIVATE 2 -#define GIT_MAP_TYPE 0xf -#define GIT_MAP_FIXED 0x10 +#define GIT_MAP_TYPE 0xf +#define GIT_MAP_FIXED 0x10 -typedef struct { /* memory mapped buffer */ - void *data; /* data bytes */ - size_t len; /* data length */ +typedef struct { /* memory mapped buffer */ + void *data; /* data bytes */ + size_t len; /* data length */ #ifdef GIT_WIN32 - HANDLE fmh; /* file mapping handle */ + HANDLE fmh; /* file mapping handle */ #endif } git_map; diff --git a/src/mwindow.c b/src/mwindow.c index cf2427349..c126fa2bd 100644 --- a/src/mwindow.c +++ b/src/mwindow.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" @@ -31,11 +13,11 @@ #define DEFAULT_WINDOW_SIZE \ (sizeof(void*) >= 8 \ - ? 1 * 1024 * 1024 * 1024 \ + ? 1 * 1024 * 1024 * 1024 \ : 32 * 1024 * 1024) #define DEFAULT_MAPPED_LIMIT \ - ((1024L * 1024L) * (sizeof(void*) >= 8 ? 8192 : 256)) + ((1024 * 1024) * (sizeof(void*) >= 8 ? 8192ULL : 256UL)) /* * We need this because each process is only allowed a specific amount @@ -183,7 +165,7 @@ static git_mwindow *new_window(git_mwindow_file *mwf, git_file fd, git_off_t siz ctl.mapped += (size_t)len; 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? */ @@ -211,7 +193,7 @@ cleanup: * enough space. Don't forget to add it to your list */ 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; @@ -259,7 +241,7 @@ int git_mwindow_file_register(git_mwindow_file *mwf) int error; 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 git_vector_insert(&ctl.windowfiles, mwf); diff --git a/src/mwindow.h b/src/mwindow.h index 1d4a58453..ec75f901f 100644 --- a/src/mwindow.h +++ b/src/mwindow.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_mwindow__ diff --git a/src/netops.c b/src/netops.c index b5251925e..a237fae73 100644 --- a/src/netops.c +++ b/src/netops.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef _WIN32 diff --git a/src/netops.h b/src/netops.h index c259ed2d6..1aa7aebac 100644 --- a/src/netops.h +++ b/src/netops.h @@ -1,5 +1,8 @@ /* - * netops.h - convencience functions for networking + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_netops_h__ #define INCLUDE_netops_h__ diff --git a/src/object.c b/src/object.c index 8b07197f1..edc2d80fa 100644 --- a/src/object.c +++ b/src/object.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include <stdarg.h> @@ -37,8 +19,8 @@ static const int OBJECT_BASE_SIZE = 4096; static struct { - const char *str; /* type name string */ - int loose; /* valid loose object type flag */ + const char *str; /* type name string */ + int loose; /* valid loose object type flag */ size_t size; /* size in bytes of the object structure */ } git_objects_table[] = { /* 0 = GIT_OBJ__EXT1 */ @@ -110,7 +92,7 @@ int git_object_lookup_prefix(git_object **object_out, git_repository *repo, cons if (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, * since there is no need to check for non ambiguousity */ @@ -144,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 * 2 options : * - 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 - * 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 - * the cache) + * 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, + * or to check that oid is not ambiguous if we have found 1 match in + * the cache) * - We never explore the cache, go right to exploring the backends * We chose the latter : we explore directly the backends. */ @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" @@ -75,9 +57,9 @@ int git_odb__hash_obj(git_oid *id, git_rawobj *obj) return git__rethrow(hdrlen, "Failed to hash object"); vec[0].data = header; - vec[0].len = hdrlen; + vec[0].len = hdrlen; vec[1].data = obj->data; - vec[1].len = obj->len; + vec[1].len = obj->len; git_hash_vec(id, vec, 2); @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_odb_h__ #define INCLUDE_odb_h__ @@ -10,9 +16,9 @@ /* DO NOT EXPORT */ typedef struct { - void *data; /**< Raw, decompressed object data. */ - size_t len; /**< Total number of bytes in data. */ - git_otype type; /**< Type of this object. */ + void *data; /**< Raw, decompressed object data. */ + size_t len; /**< Total number of bytes in data. */ + git_otype type; /**< Type of this object. */ } git_rawobj; /* EXPORT */ diff --git a/src/odb_loose.c b/src/odb_loose.c index f78750899..3ca46d1b5 100644 --- a/src/odb_loose.c +++ b/src/odb_loose.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" @@ -36,9 +18,9 @@ #include "git2/odb_backend.h" #include "git2/types.h" -typedef struct { /* object header data */ - git_otype type; /* object type */ - size_t size; /* object size */ +typedef struct { /* object header data */ + git_otype type; /* object type */ + size_t size; /* object size */ } obj_hdr; typedef struct { @@ -142,7 +124,7 @@ static size_t get_object_header(obj_hdr *hdr, unsigned char *data) if (used == 0) return 0; hdr->type = git_object_string2type(typename); - used++; /* consume the space */ + used++; /* consume the space */ /* * length follows immediately in decimal (without @@ -182,20 +164,20 @@ static size_t get_object_header(obj_hdr *hdr, unsigned char *data) static void init_stream(z_stream *s, void *out, size_t len) { memset(s, 0, sizeof(*s)); - s->next_out = out; - s->avail_out = len; + s->next_out = out; + s->avail_out = (uInt)len; } static void set_stream_input(z_stream *s, void *in, size_t len) { - s->next_in = in; - s->avail_in = len; + s->next_in = in; + s->avail_in = (uInt)len; } static void set_stream_output(z_stream *s, void *out, size_t len) { - s->next_out = out; - s->avail_out = len; + s->next_out = out; + s->avail_out = (uInt)len; } @@ -242,11 +224,11 @@ static int inflate_buffer(void *in, size_t inlen, void *out, size_t outlen) memset(&zs, 0x0, sizeof(zs)); - zs.next_out = out; - zs.avail_out = outlen; + zs.next_out = out; + zs.avail_out = (uInt)outlen; - zs.next_in = in; - zs.avail_in = inlen; + zs.next_in = in; + zs.avail_in = (uInt)inlen; if (inflateInit(&zs) < Z_OK) return git__throw(GIT_ERROR, "Failed to inflate buffer"); @@ -332,7 +314,7 @@ static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_fbuffer *obj) if (!buf) return GIT_ENOMEM; - in = ((unsigned char *)obj->data) + used; + in = ((unsigned char *)obj->data) + used; len = obj->len - used; if (inflate_buffer(in, len, buf, hdr.size)) { free(buf); @@ -341,7 +323,7 @@ static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_fbuffer *obj) buf[hdr.size] = '\0'; out->data = buf; - out->len = hdr.size; + out->len = hdr.size; out->type = hdr.type; return GIT_SUCCESS; @@ -382,7 +364,7 @@ static int inflate_disk_obj(git_rawobj *out, git_fbuffer *obj) buf[hdr.size] = '\0'; out->data = buf; - out->len = hdr.size; + out->len = hdr.size; out->type = hdr.type; return GIT_SUCCESS; @@ -410,7 +392,7 @@ static int read_loose(git_rawobj *out, const char *loc) assert(out && loc); out->data = NULL; - out->len = 0; + out->len = 0; out->type = GIT_OBJ_BAD; if (git_futils_readbuffer(&obj, loc) < 0) @@ -461,7 +443,7 @@ static int read_header_loose(git_rawobj *out, const char *loc) goto cleanup; } - out->len = header_obj.size; + out->len = header_obj.size; out->type = header_obj.type; cleanup: @@ -712,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); int len = snprintf(hdr, n, "%s %"PRIuZ, type_str, obj_len); - assert(len > 0); /* otherwise snprintf() is broken */ - assert(((size_t) len) < n); /* otherwise the caller is broken! */ + assert(len > 0); /* otherwise snprintf() is broken */ + assert(((size_t) len) < n); /* otherwise the caller is broken! */ if (len < 0 || ((size_t) len) >= n) return git__throw(GIT_ERROR, "Failed to format object header. Length is out of bounds"); @@ -726,7 +708,7 @@ static int loose_backend__stream(git_odb_stream **stream_out, git_odb_backend *_ loose_writestream *stream; char hdr[64], tmp_path[GIT_PATH_MAX]; - int hdrlen; + int hdrlen; int error; assert(_backend); diff --git a/src/odb_pack.c b/src/odb_pack.c index b3db27280..4607fb74a 100644 --- a/src/odb_pack.c +++ b/src/odb_pack.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" @@ -48,9 +30,9 @@ struct pack_backend { /** * The wonderful tale of a Packed Object lookup query * =================================================== - * A riveting and epic story of epicness and ASCII - * art, presented by yours truly, - * Sir Vicent of Marti + * A riveting and epic story of epicness and ASCII + * art, presented by yours truly, + * Sir Vicent of Marti * * * Chapter 1: Once upon a time... @@ -61,32 +43,32 @@ struct pack_backend { * | Creates the pack backend structure, initializes the * | callback pointers to our default read() and exist() methods, * | and tries to preload all the known packfiles in the ODB. - * | + * | * |-# packfile_load_all - * | Tries to find the `pack` folder, if it exists. ODBs without - * | a pack folder are ignored altogether. If there's a `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 a sorting callback. - * | - * |-# packfile_load__cb - * | | This callback is called from `dirent` with every single file - * | | inside the pack folder. We find the packs by actually locating - * | | their index (ends in ".idx"). From that index, we verify that - * | | the corresponding packfile exists and is valid, and if so, we - * | | add it to the pack list. - * | | - * | |-# packfile_check - * | Make sure that there's a packfile to back this index, and store - * | some very basic information regarding the packfile itself, - * | such as the full path, the size, and the modification time. - * | We don't actually open the packfile to check for internal consistency. - * | - * |-# packfile_sort__cb - * Sort all the preloaded packs according to some specific criteria: - * we prioritize the "newer" packs because it's more likely they - * contain the objects we are looking for, and we prioritize local - * packs over remote ones. + * | Tries to find the `pack` folder, if it exists. ODBs without + * | a pack folder are ignored altogether. If there's a `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 a sorting callback. + * | + * |-# packfile_load__cb + * | | This callback is called from `dirent` with every single file + * | | inside the pack folder. We find the packs by actually locating + * | | their index (ends in ".idx"). From that index, we verify that + * | | the corresponding packfile exists and is valid, and if so, we + * | | add it to the pack list. + * | | + * | |-# packfile_check + * | Make sure that there's a packfile to back this index, and store + * | some very basic information regarding the packfile itself, + * | such as the full path, the size, and the modification time. + * | We don't actually open the packfile to check for internal consistency. + * | + * |-# packfile_sort__cb + * Sort all the preloaded packs according to some specific criteria: + * we prioritize the "newer" packs because it's more likely they + * contain the objects we are looking for, and we prioritize local + * packs over remote ones. * * * @@ -94,41 +76,41 @@ struct pack_backend { * A standard packed `exist` query for an OID * -------------------------------------------------- * - * # pack_backend__exists - * | Check if the given SHA1 oid exists in any of the packs - * | that have been loaded for our ODB. - * | - * |-# pack_entry_find - * | Iterate through all the packs that have been preloaded - * | (starting by the pack where the latest object was found) - * | to try to find the OID in one of them. - * | - * |-# pack_entry_find1 - * | 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 - * | inside of the index, that means the object is contained - * | inside of the packfile and we can stop searching. - * | Before returning, we verify that the packfile behing the - * | index we are searching still exists on disk. - * | - * |-# pack_entry_find_offset - * | | 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. - * | | 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. - * | | - * | |-# pack_index_open - * | | Guess the name of the index based on the full path to the - * | | packfile, open it and verify its contents. Only if the index - * | | has not been opened already. - * | | - * | |-# pack_index_check - * | Mmap the index file and do a quick run through the header - * | to guess the index version (right now we support v1 and v2), - * | and to verify that the size of the index makes sense. - * | - * |-# packfile_open - * See `packfile_open` in Chapter 3 + * # pack_backend__exists + * | Check if the given SHA1 oid exists in any of the packs + * | that have been loaded for our ODB. + * | + * |-# pack_entry_find + * | Iterate through all the packs that have been preloaded + * | (starting by the pack where the latest object was found) + * | to try to find the OID in one of them. + * | + * |-# pack_entry_find1 + * | 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 + * | inside of the index, that means the object is contained + * | inside of the packfile and we can stop searching. + * | Before returning, we verify that the packfile behing the + * | index we are searching still exists on disk. + * | + * |-# pack_entry_find_offset + * | | 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. + * | | 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. + * | | + * | |-# pack_index_open + * | | Guess the name of the index based on the full path to the + * | | packfile, open it and verify its contents. Only if the index + * | | has not been opened already. + * | | + * | |-# pack_index_check + * | Mmap the index file and do a quick run through the header + * | to guess the index version (right now we support v1 and v2), + * | and to verify that the size of the index makes sense. + * | + * |-# packfile_open + * See `packfile_open` in Chapter 3 * * * @@ -188,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 * offset is available from this window, otherwise the offset * 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. */ return git_mwindow_contains(win, offset + 20); @@ -202,7 +184,7 @@ static int packfile_sort__cb(const void *a_, const void *b_) /* * 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. * Favor local ones for these reasons. */ @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" @@ -33,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, /* 10 */ -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, -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 */ @@ -61,7 +43,7 @@ int git_oid_fromstrn(git_oid *out, const char *str, size_t length) for (p = 0; p < length; p += 2) { 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) return git__throw(GIT_ENOTOID, "Failed to generate sha1. Given string is not a valid sha1 hash"); @@ -122,7 +104,7 @@ char *git_oid_to_string(char *out, size_t n, const git_oid *oid) if (!out || n == 0 || !oid) return ""; - n--; /* allow room for terminating NUL */ + n--; /* allow room for terminating NUL */ if (n > 0) { git_oid_fmt(str, oid); diff --git a/src/pack.c b/src/pack.c index d882516be..8de2d7814 100644 --- a/src/pack.c +++ b/src/pack.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "mwindow.h" @@ -70,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; uint32_t version, nr, i, *index; @@ -126,7 +108,7 @@ static int pack_index_check(const char *path, struct git_pack_file *p) index = idx_map; if (version > 1) - index += 2; /* skip index header */ + index += 2; /* skip index header */ for (i = 0; i < 256; i++) { uint32_t n = ntohl(index[i]); @@ -140,10 +122,10 @@ static int pack_index_check(const char *path, struct git_pack_file *p) if (version == 1) { /* * Total size: - * - 256 index entries 4 bytes each - * - 24-byte entries * nr (20-byte sha1 + 4-byte offset) - * - 20-byte SHA1 of the packfile - * - 20-byte SHA1 file checksum + * - 256 index entries 4 bytes each + * - 24-byte entries * nr (20-byte sha1 + 4-byte offset) + * - 20-byte SHA1 of the packfile + * - 20-byte SHA1 file checksum */ if (idx_size != 4*256 + nr * 24 + 20 + 20) { git_futils_mmap_free(&p->index_map); @@ -152,13 +134,13 @@ static int pack_index_check(const char *path, struct git_pack_file *p) } else if (version == 2) { /* * Minimum size: - * - 8 bytes of header - * - 256 index entries 4 bytes each - * - 20-byte sha1 entry * nr - * - 4-byte crc entry * nr - * - 4-byte offset entry * nr - * - 20-byte SHA1 of the packfile - * - 20-byte SHA1 file checksum + * - 8 bytes of header + * - 256 index entries 4 bytes each + * - 20-byte sha1 entry * nr + * - 4-byte crc entry * nr + * - 4-byte offset entry * nr + * - 20-byte SHA1 of the packfile + * - 20-byte SHA1 file checksum * And after the 4-byte offset table might be a * variable sized table containing 8-byte entries * for offsets larger than 2^31. @@ -263,8 +245,8 @@ int git_packfile_unpack_header( unsigned long used; /* pack_window_open() assures us we have [base, base + 20) available - * as a range that we can look at at. (Its actually the hash - * size that is assured.) With our object header encoding + * as a range that we can look at at. (Its actually the hash + * size that is assured.) With our object header encoding * the maximum deflated object size is 2^137, which is just * insane, so we know won't exceed what we have been given. */ @@ -404,7 +386,7 @@ int packfile_unpack_compressed( memset(&stream, 0, sizeof(stream)); stream.next_out = buffer; - stream.avail_out = size + 1; + stream.avail_out = (uInt)size + 1; st = inflateInit(&stream); if (st != Z_OK) { @@ -453,8 +435,8 @@ off_t get_delta_base( /* pack_window_open() assured us we have [base_info, base_info + 20) * as a range that we can look at without walking off the - * end of the mapped window. Its actually the hash size - * that is assured. An OFS_DELTA longer than the hash size + * end of the mapped window. Its actually 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. */ if (type == GIT_OBJ_OFS_DELTA) { @@ -464,13 +446,13 @@ off_t get_delta_base( while (c & 128) { base_offset += 1; if (!base_offset || MSB(base_offset, 7)) - return 0; /* overflow */ + return 0; /* overflow */ c = base_info[used++]; base_offset = (base_offset << 7) + (c & 127); } base_offset = delta_obj_offset - base_offset; if (base_offset <= 0 || base_offset >= delta_obj_offset) - return 0; /* out of bound */ + return 0; /* out of bound */ *curpos += used; } else if (type == GIT_OBJ_REF_DELTA) { /* If we have the cooperative cache, search in it first */ @@ -668,7 +650,7 @@ static off_t nth_packed_object_offset(const struct git_pack_file *p, uint32_t n) return off; index += p->num_objects * 4 + (off & 0x7fffffff) * 8; return (((uint64_t)ntohl(*((uint32_t *)(index + 0)))) << 32) | - ntohl(*((uint32_t *)(index + 4))); + ntohl(*((uint32_t *)(index + 4))); } } @@ -721,7 +703,7 @@ static int pack_entry_find_offset( #endif /* 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) { /* An object matching exactly the oid was found */ diff --git a/src/pack.h b/src/pack.h index 164086fdf..0fddd9dc8 100644 --- a/src/pack.h +++ b/src/pack.h @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_pack_h__ @@ -56,7 +38,7 @@ struct git_pack_header { * 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" * 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. */ diff --git a/src/path.c b/src/path.c index 1f7a16679..2c6b76dd0 100644 --- a/src/path.c +++ b/src/path.c @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #include "common.h" #include "path.h" #include "posix.h" @@ -17,8 +23,8 @@ int git_path_basename_r(char *buffer, size_t bufflen, const char *path) /* Empty or NULL string gets treated as "." */ if (path == NULL || *path == '\0') { - startp = "."; - len = 1; + startp = "."; + len = 1; goto Exit; } @@ -30,7 +36,7 @@ int git_path_basename_r(char *buffer, size_t bufflen, const char *path) /* All slashes becomes "/" */ if (endp == path && *endp == '/') { startp = "/"; - len = 1; + len = 1; goto Exit; } @@ -47,7 +53,7 @@ Exit: return result; } if (len > (int)bufflen-1) { - len = (int)bufflen-1; + len = (int)bufflen-1; result = GIT_ENOMEM; } @@ -64,93 +70,103 @@ Exit: */ int git_path_dirname_r(char *buffer, size_t bufflen, const char *path) { - const char *endp; - int result, len; - - /* Empty or NULL string gets treated as "." */ - if (path == NULL || *path == '\0') { - path = "."; - len = 1; - goto Exit; - } - - /* Strip trailing slashes */ - endp = path + strlen(path) - 1; - while (endp > path && *endp == '/') - endp--; - - /* Find the start of the dir */ - while (endp > path && *endp != '/') - endp--; - - /* Either the dir is "/" or there are no slashes */ - if (endp == path) { - path = (*endp == '/') ? "/" : "."; - len = 1; - goto Exit; - } - - do { - endp--; - } while (endp > path && *endp == '/'); - - len = endp - path +1; + const char *endp; + int result, len; + + /* Empty or NULL string gets treated as "." */ + if (path == NULL || *path == '\0') { + path = "."; + len = 1; + goto Exit; + } + + /* Strip trailing slashes */ + endp = path + strlen(path) - 1; + while (endp > path && *endp == '/') + endp--; + + /* Find the start of the dir */ + while (endp > path && *endp != '/') + endp--; + + /* Either the dir is "/" or there are no slashes */ + if (endp == path) { + path = (*endp == '/') ? "/" : "."; + len = 1; + goto Exit; + } + + do { + endp--; + } while (endp > path && *endp == '/'); + + len = endp - path +1; + +#ifdef GIT_WIN32 + /* Mimic unix behavior where '/.git' returns '/': 'C:/.git' will return + 'C:/' here */ + + if (len == 2 && isalpha(path[0]) && path[1] == ':') { + len = 3; + goto Exit; + } +#endif Exit: - result = len; - if (len+1 > GIT_PATH_MAX) { - return GIT_ENOMEM; - } - if (buffer == NULL) - return result; - - if (len > (int)bufflen-1) { - len = (int)bufflen-1; - result = GIT_ENOMEM; - } - - if (len >= 0) { - memmove(buffer, path, len); - buffer[len] = 0; - } - return result; + result = len; + if (len+1 > GIT_PATH_MAX) { + return GIT_ENOMEM; + } + if (buffer == NULL) + return result; + + if (len > (int)bufflen-1) { + len = (int)bufflen-1; + result = GIT_ENOMEM; + } + + if (len >= 0) { + memmove(buffer, path, len); + buffer[len] = 0; + } + return result; } char *git_path_dirname(const char *path) { - char *dname = NULL; - int len; + char *dname = NULL; + int len; len = (path ? strlen(path) : 0) + 2; dname = (char *)git__malloc(len); if (dname == 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); return NULL; } - return dname; + return dname; } char *git_path_basename(const char *path) { - char *bname = NULL; - int len; + char *bname = NULL; + int len; len = (path ? strlen(path) : 0) + 2; bname = (char *)git__malloc(len); if (bname == 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); return NULL; } - return bname; + return bname; } diff --git a/src/path.h b/src/path.h index 36e22a768..51bedeed7 100644 --- a/src/path.h +++ b/src/path.h @@ -1,5 +1,8 @@ /* - * posix.h - Path management methods + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_path_h__ #define INCLUDE_path_h__ @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" @@ -181,11 +163,11 @@ static ssize_t parse_len(const char *line) /* * As per the documentation, the syntax is: * - * pkt-line = data-pkt / flush-pkt - * data-pkt = pkt-len pkt-payload - * pkt-len = 4*(HEXDIG) + * pkt-line = data-pkt / flush-pkt + * data-pkt = pkt-len pkt-payload + * pkt-len = 4*(HEXDIG) * 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, * in ASCII hexadecimal (including itself) @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_pkt_h__ diff --git a/src/posix.c b/src/posix.c index 4bb8c3246..61c79b071 100644 --- a/src/posix.c +++ b/src/posix.c @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #include "common.h" #include "posix.h" #include "path.h" diff --git a/src/posix.h b/src/posix.h index f1424f8d3..7c1ac66c5 100644 --- a/src/posix.h +++ b/src/posix.h @@ -1,5 +1,8 @@ /* - * posix.h - OS agnostic POSIX calls + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_posix_h__ #define INCLUDE_posix_h__ diff --git a/src/ppc/sha1.c b/src/ppc/sha1.c index ec6a1926d..a34bf2557 100644 --- a/src/ppc/sha1.c +++ b/src/ppc/sha1.c @@ -1,17 +1,15 @@ /* - * SHA-1 implementation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * Copyright (C) 2005 Paul Mackerras <paulus@samba.org> - * - * This version assumes we are running on a big-endian machine. - * It calls an external sha1_core() to process blocks of 64 bytes. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include <stdio.h> #include <string.h> #include "sha1.h" 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) { diff --git a/src/ppc/sha1.h b/src/ppc/sha1.h index 70957110c..7448381ab 100644 --- a/src/ppc/sha1.h +++ b/src/ppc/sha1.h @@ -1,7 +1,8 @@ /* - * SHA-1 implementation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * Copyright (C) 2005 Paul Mackerras <paulus@samba.org> + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include <stdint.h> diff --git a/src/pqueue.c b/src/pqueue.c index 9883a35d8..b5ddab835 100644 --- a/src/pqueue.c +++ b/src/pqueue.c @@ -1,52 +1,36 @@ /* - * BORING COPYRIGHT NOTICE: + * Copyright (C) 2009-2011 the libgit2 contributors * - * This file is a heavily modified version of the priority queue found - * in the Apache project and the libpqueue library. - * - * https://github.com/vy/libpqueue - * - * These are the original authors: - * - * Copyright 2010 Volkan Yazıcı <volkan.yazici@gmail.com> - * Copyright 2006-2010 The Apache Software Foundation - * - * This file is licensed under the Apache 2.0 license, which - * supposedly makes it compatible with the GPLv2 that libgit2 uses. - * - * Check the Apache license at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * So much licensing trouble for a binary heap. Oh well. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" #include "pqueue.h" -#define left(i) ((i) << 1) -#define right(i) (((i) << 1) + 1) +#define left(i) ((i) << 1) +#define right(i) (((i) << 1) + 1) #define parent(i) ((i) >> 1) int git_pqueue_init(git_pqueue *q, size_t n, git_pqueue_cmp cmppri) { assert(q); - /* Need to allocate n+1 elements since element 0 isn't used. */ - if ((q->d = malloc((n + 1) * sizeof(void *))) == NULL) + /* Need to allocate n+1 elements since element 0 isn't used. */ + if ((q->d = malloc((n + 1) * sizeof(void *))) == NULL) return GIT_ENOMEM; - q->size = 1; - q->avail = q->step = (n + 1); /* see comment above about n+1 */ - q->cmppri = cmppri; + q->size = 1; + q->avail = q->step = (n + 1); /* see comment above about n+1 */ + q->cmppri = cmppri; - return GIT_SUCCESS; + return GIT_SUCCESS; } void git_pqueue_free(git_pqueue *q) { - free(q->d); + free(q->d); q->d = NULL; } @@ -57,101 +41,101 @@ void git_pqueue_clear(git_pqueue *q) size_t git_pqueue_size(git_pqueue *q) { - /* queue element 0 exists but doesn't count since it isn't used. */ - return (q->size - 1); + /* queue element 0 exists but doesn't count since it isn't used. */ + return (q->size - 1); } static void bubble_up(git_pqueue *q, size_t i) { - size_t parent_node; - void *moving_node = q->d[i]; + size_t parent_node; + void *moving_node = q->d[i]; - for (parent_node = parent(i); - ((i > 1) && q->cmppri(q->d[parent_node], moving_node)); - i = parent_node, parent_node = parent(i)) { - q->d[i] = q->d[parent_node]; - } + for (parent_node = parent(i); + ((i > 1) && q->cmppri(q->d[parent_node], moving_node)); + i = parent_node, parent_node = parent(i)) { + 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) { - size_t child_node = left(i); + size_t child_node = left(i); - if (child_node >= q->size) - return 0; + if (child_node >= q->size) + return 0; - if ((child_node + 1) < q->size && - q->cmppri(q->d[child_node], q->d[child_node + 1])) - child_node++; /* use right child instead of left */ + if ((child_node + 1) < q->size && + q->cmppri(q->d[child_node], q->d[child_node + 1])) + child_node++; /* use right child instead of left */ - return child_node; + return child_node; } static void percolate_down(git_pqueue *q, size_t i) { - size_t child_node; - void *moving_node = q->d[i]; + size_t child_node; + void *moving_node = q->d[i]; - while ((child_node = maxchild(q, i)) != 0 && - q->cmppri(moving_node, q->d[child_node])) { - q->d[i] = q->d[child_node]; - i = child_node; - } + while ((child_node = maxchild(q, i)) != 0 && + q->cmppri(moving_node, q->d[child_node])) { + q->d[i] = q->d[child_node]; + i = child_node; + } - q->d[i] = moving_node; + q->d[i] = moving_node; } int git_pqueue_insert(git_pqueue *q, void *d) { - void *tmp; - size_t i; - size_t newsize; + void *tmp; + size_t i; + size_t newsize; - if (!q) return 1; + if (!q) return 1; - /* allocate more memory if necessary */ - if (q->size >= q->avail) { - newsize = q->size + q->step; - if ((tmp = realloc(q->d, sizeof(void *) * newsize)) == NULL) - return GIT_ENOMEM; + /* allocate more memory if necessary */ + if (q->size >= q->avail) { + newsize = q->size + q->step; + if ((tmp = realloc(q->d, sizeof(void *) * newsize)) == NULL) + return GIT_ENOMEM; - q->d = tmp; - q->avail = newsize; - } + q->d = tmp; + q->avail = newsize; + } - /* insert item */ - i = q->size++; - q->d[i] = d; - bubble_up(q, i); + /* insert item */ + i = q->size++; + q->d[i] = d; + bubble_up(q, i); - return GIT_SUCCESS; + return GIT_SUCCESS; } void *git_pqueue_pop(git_pqueue *q) { - void *head; + void *head; - if (!q || q->size == 1) - return NULL; + if (!q || q->size == 1) + return NULL; - head = q->d[1]; - q->d[1] = q->d[--q->size]; - percolate_down(q, 1); + head = q->d[1]; + q->d[1] = q->d[--q->size]; + percolate_down(q, 1); - return head; + return head; } void *git_pqueue_peek(git_pqueue *q) { - if (!q || q->size == 1) - return NULL; - return q->d[1]; + if (!q || q->size == 1) + return NULL; + return q->d[1]; } diff --git a/src/pqueue.h b/src/pqueue.h index ef8362c33..6826055e5 100644 --- a/src/pqueue.h +++ b/src/pqueue.h @@ -1,24 +1,8 @@ /* - * BORING COPYRIGHT NOTICE: + * Copyright (C) 2009-2011 the libgit2 contributors * - * This file is a heavily modified version of the priority queue found - * in the Apache project and the libpqueue library. - * - * https://github.com/vy/libpqueue - * - * These are the original authors: - * - * Copyright 2010 Volkan Yazıcı <volkan.yazici@gmail.com> - * Copyright 2006-2010 The Apache Software Foundation - * - * This file is licensed under the Apache 2.0 license, which - * supposedly makes it compatible with the GPLv2 that libgit2 uses. - * - * Check the Apache license at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * So much licensing trouble for a binary heap. Oh well. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_pqueue_h__ @@ -29,9 +13,9 @@ typedef int (*git_pqueue_cmp)(void *a, void *b); /** the priority queue handle */ typedef struct { - size_t size, avail, step; - git_pqueue_cmp cmppri; - void **d; + size_t size, avail, step; + git_pqueue_cmp cmppri; + void **d; } git_pqueue; @@ -39,7 +23,7 @@ typedef struct { * initialize the queue * * @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 * * @Return the handle or NULL for insufficent memory diff --git a/src/reflog.c b/src/reflog.c index d28e5cba1..594963c03 100644 --- a/src/reflog.c +++ b/src/reflog.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "reflog.h" @@ -223,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, - const git_signature *committer, const char *msg) + const git_signature *committer, const char *msg) { int error; char old[GIT_OID_HEXSZ+1]; diff --git a/src/reflog.h b/src/reflog.h index b6daf2a76..093874e51 100644 --- a/src/reflog.h +++ b/src/reflog.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_reflog_h__ #define INCLUDE_reflog_h__ diff --git a/src/refs.c b/src/refs.c index 04347d221..bc8827b46 100644 --- a/src/refs.c +++ b/src/refs.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "refs.h" @@ -512,7 +494,7 @@ static int packed_load(git_repository *repo) } 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 @@ -845,7 +827,7 @@ static int packed_write(git_repository *repo) const void *GIT_UNUSED(_unused); 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 */ ); } @@ -923,7 +905,7 @@ static int _reference_available_cb(const char *ref, void *data) const char *lead = reflen < newlen ? new : ref; if (!strncmp(new, ref, cmplen) && - lead[cmplen] == '/') + lead[cmplen] == '/') return GIT_EEXISTS; } @@ -1072,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 * of an oid one. * If if didn't exist, then we need to create a new one anyway. - */ + */ if (ref && ref->type & GIT_REF_SYMBOLIC){ updated = 1; } else { @@ -1131,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 * of an oid one. * If if didn't exist, then we need to create a new one anyway. - */ + */ if (ref && ref-> type & GIT_REF_OID){ updated = 1; } else { @@ -1362,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: * * "We only enable reflogs in repositories that have a working directory - * associated with them, as shared/bare repositories do not have - * 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. - * This heuristic was suggested on the mailing list by Junio." + * associated with them, as shared/bare repositories do not have + * 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. + * This heuristic was suggested on the mailing list by Junio." * * Shawn O. Pearce - 0bee59186976b1d9e6b2dd77332480c9480131d5 * diff --git a/src/refs.h b/src/refs.h index dfac455e0..979af2ee2 100644 --- a/src/refs.h +++ b/src/refs.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_refs_h__ #define INCLUDE_refs_h__ diff --git a/src/refspec.c b/src/refspec.c index 8500e07ea..9de273071 100644 --- a/src/refspec.c +++ b/src/refspec.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "git2/errors.h" @@ -73,7 +55,7 @@ int git_refspec_src_match(const git_refspec *refspec, const char *refname) 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; diff --git a/src/refspec.h b/src/refspec.h index 230135a4a..58f3fe472 100644 --- a/src/refspec.h +++ b/src/refspec.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_refspec_h__ #define INCLUDE_refspec_h__ diff --git a/src/remote.c b/src/remote.c index 0cd1d9994..f581b973f 100644 --- a/src/remote.c +++ b/src/remote.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "git2/remote.h" @@ -128,7 +110,7 @@ int git_remote_get(git_remote **out, git_config *cfg, const char *name) error = git_config_get_string(cfg, buf, &val); 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; } @@ -262,6 +244,9 @@ int git_remote_update_tips(struct git_remote *remote) void git_remote_free(git_remote *remote) { + if (remote == NULL) + return; + free(remote->fetch.src); free(remote->fetch.dst); free(remote->push.src); diff --git a/src/remote.h b/src/remote.h index 21313acd4..66b9dd8f8 100644 --- a/src/remote.h +++ b/src/remote.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_remote_h__ #define INCLUDE_remote_h__ diff --git a/src/repository.c b/src/repository.c index 7d243398b..bb7ef396d 100644 --- a/src/repository.c +++ b/src/repository.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include <stdarg.h> @@ -288,7 +270,6 @@ cleanup: int git_repository_config( git_config **out, git_repository *repo, - const char *user_config_path, const char *system_config_path) { char config_path[GIT_PATH_MAX]; @@ -305,10 +286,9 @@ int git_repository_config( if (error < GIT_SUCCESS) goto cleanup; - if (user_config_path != NULL) { - error = git_config_add_file_ondisk(*out, user_config_path, 2); - if (error < GIT_SUCCESS) - goto cleanup; + error = git_config_find_global(config_path); + if (error == GIT_SUCCESS) { + error = git_config_add_file_ondisk(*out, config_path, 2); } if (system_config_path != NULL) { @@ -729,19 +709,31 @@ int git_repository_head_detached(git_repository *repo) return 1; } -int git_repository_head_orphan(git_repository *repo) +int git_repository_head(git_reference **head_out, git_repository *repo) { git_reference *ref; int error; + *head_out = NULL; + error = git_reference_lookup(&ref, repo, GIT_HEAD_FILE); if (error < GIT_SUCCESS) - return error; - - if (git_reference_type(ref) == GIT_REF_OID) - return 0; + return git__rethrow(GIT_ENOTAREPO, "Failed to locate the HEAD"); error = git_reference_resolve(&ref, ref); + if (error < GIT_SUCCESS) + return git__rethrow(error, "Failed to resolve the HEAD"); + + *head_out = ref; + return GIT_SUCCESS; +} + +int git_repository_head_orphan(git_repository *repo) +{ + git_reference *ref; + int error; + + error = git_repository_head(&ref, repo); return error == GIT_ENOTFOUND ? 1 : error; } diff --git a/src/repository.h b/src/repository.h index 2e0b9e352..99217e5a4 100644 --- a/src/repository.h +++ b/src/repository.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_repository_h__ #define INCLUDE_repository_h__ diff --git a/src/revwalk.c b/src/revwalk.c index 667291899..72eb69aba 100644 --- a/src/revwalk.c +++ b/src/revwalk.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" diff --git a/src/sha1.c b/src/sha1.c index 0bccb4953..4043fb168 100644 --- a/src/sha1.c +++ b/src/sha1.c @@ -1,9 +1,8 @@ /* - * SHA1 routine optimized to do word accesses rather than byte accesses, - * and to avoid unnecessary copies into the context array. + * Copyright (C) 2009-2011 the libgit2 contributors * - * This was initially based on the Mozilla SHA1 implementation, although - * none of the original Mozilla code remains. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" @@ -53,11 +52,11 @@ */ #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__) - #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 - #define setW(x, val) (W(x) = (val)) + #define setW(x, val) (W(x) = (val)) #endif /* @@ -68,10 +67,10 @@ */ #if defined(__i386__) || defined(__x86_64__) || \ - defined(_M_IX86) || defined(_M_X64) || \ - defined(__ppc__) || defined(__ppc64__) || \ - defined(__powerpc__) || defined(__powerpc64__) || \ - defined(__s390__) || defined(__s390x__) + defined(_M_IX86) || defined(_M_X64) || \ + defined(__ppc__) || defined(__ppc64__) || \ + defined(__powerpc__) || defined(__powerpc64__) || \ + defined(__s390__) || defined(__s390x__) #define get_be32(p) ntohl(*(const unsigned int *)(p)) #define put_be32(p, v) do { *(unsigned int *)(p) = htonl(v); } while (0) @@ -81,14 +80,14 @@ #define get_be32(p) ( \ (*((const unsigned char *)(p) + 0) << 24) | \ (*((const unsigned char *)(p) + 1) << 16) | \ - (*((const unsigned char *)(p) + 2) << 8) | \ - (*((const unsigned char *)(p) + 3) << 0) ) + (*((const unsigned char *)(p) + 2) << 8) | \ + (*((const unsigned char *)(p) + 3) << 0) ) #define put_be32(p, v) do { \ unsigned int __v = (v); \ *((unsigned char *)(p) + 0) = __v >> 24; \ *((unsigned char *)(p) + 1) = __v >> 16; \ - *((unsigned char *)(p) + 2) = __v >> 8; \ - *((unsigned char *)(p) + 3) = __v >> 0; } while (0) + *((unsigned char *)(p) + 2) = __v >> 8; \ + *((unsigned char *)(p) + 3) = __v >> 0; } while (0) #endif @@ -107,11 +106,11 @@ E += TEMP + SHA_ROL(A,5) + (fn) + (constant); \ 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_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_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) { diff --git a/src/sha1.h b/src/sha1.h index 558d6aece..f1e905e76 100644 --- a/src/sha1.h +++ b/src/sha1.h @@ -1,9 +1,8 @@ /* - * SHA1 routine optimized to do word accesses rather than byte accesses, - * and to avoid unnecessary copies into the context array. + * Copyright (C) 2009-2011 the libgit2 contributors * - * This was initially based on the Mozilla SHA1 implementation, although - * none of the original Mozilla code remains. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ typedef struct { diff --git a/src/sha1_lookup.c b/src/sha1_lookup.c index 6ac00c5aa..3051568a3 100644 --- a/src/sha1_lookup.c +++ b/src/sha1_lookup.c @@ -1,27 +1,8 @@ /* - * This file is basically taken from git code. - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include <stdio.h> @@ -33,69 +14,69 @@ * Conventional binary search loop looks like this: * * unsigned lo, hi; - * do { - * unsigned mi = (lo + hi) / 2; - * int cmp = "entry pointed at by mi" minus "target"; - * if (!cmp) - * return (mi is the wanted one) - * if (cmp > 0) - * hi = mi; "mi is larger than target" - * else - * lo = mi+1; "mi is smaller than target" - * } while (lo < hi); + * do { + * unsigned mi = (lo + hi) / 2; + * int cmp = "entry pointed at by mi" minus "target"; + * if (!cmp) + * return (mi is the wanted one) + * if (cmp > 0) + * hi = mi; "mi is larger than target" + * else + * lo = mi+1; "mi is smaller than target" + * } while (lo < hi); * * The invariants are: * * - 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 - * slot that is guaranteed to be above the target (it can never - * be at the target). + * 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 + * be at the target). * * - 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 - * the target. There are three cases: + * as lo, but never can be as same as hi), and check if it hits + * 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, - * and repeat the search. + * - if it is strictly higher than the target, we set it to hi, + * and repeat the search. * - * - 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. + * - 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. * - * 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 * 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 * 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 * 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 - * 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. * - * 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 * 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 - * 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" - * 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 + * 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 * 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 * "hi" is higher than the entry it is looking for. */ int sha1_entry_pos(const void *table, - size_t elem_size, - size_t key_offset, - unsigned lo, unsigned hi, unsigned nr, - const unsigned char *key) + size_t elem_size, + size_t key_offset, + unsigned lo, unsigned hi, unsigned nr, + const unsigned char *key) { const unsigned char *base = (const unsigned char*)table; const unsigned char *hi_key, *lo_key; @@ -157,7 +138,7 @@ int sha1_entry_pos(const void *table, * end up narrowing the search space by a smaller * amount (i.e. the distance between 'mi' and 'hi') * 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 * middle than we would otherwise pick. */ @@ -173,7 +154,7 @@ int sha1_entry_pos(const void *table, #ifdef INDEX_DEBUG_LOOKUP printf("lo %u hi %u rg %u mi %u ", lo, hi, range, mi); printf("ofs %u lov %x, hiv %x, kyv %x\n", - ofs_0, lov, hiv, kyv); + ofs_0, lov, hiv, kyv); #endif if (!(lo <= mi && mi < hi)) { diff --git a/src/sha1_lookup.h b/src/sha1_lookup.h index 5caa2f5ed..52282e672 100644 --- a/src/sha1_lookup.h +++ b/src/sha1_lookup.h @@ -1,12 +1,18 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_sha1_lookup_h__ #define INCLUDE_sha1_lookup_h__ #include <stdlib.h> int sha1_entry_pos(const void *table, - size_t elem_size, - size_t key_offset, - unsigned lo, unsigned hi, unsigned nr, - const unsigned char *key); + size_t elem_size, + size_t key_offset, + unsigned lo, unsigned hi, unsigned nr, + const unsigned char *key); #endif diff --git a/src/signature.c b/src/signature.c index 1890581fa..7cc3733bc 100644 --- a/src/signature.c +++ b/src/signature.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" diff --git a/src/signature.h b/src/signature.h index 2fe6cd7c9..a66060661 100644 --- a/src/signature.h +++ b/src/signature.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_signature_h__ #define INCLUDE_signature_h__ diff --git a/src/status.c b/src/status.c index d9613c129..66fe8cbd6 100644 --- a/src/status.c +++ b/src/status.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" @@ -30,10 +12,9 @@ #include "vector.h" #include "tree.h" #include "git2/status.h" +#include "repository.h" struct status_entry { - char path[GIT_PATH_MAX]; - git_index_time mtime; git_oid head_oid; @@ -41,321 +22,646 @@ struct status_entry { git_oid wt_oid; unsigned int status_flags:6; + + char path[GIT_FLEX_ARRAY]; /* more */ }; -static int status_cmp(const void *a, const void *b) +static struct status_entry *status_entry_new(git_vector *entries, const char *path) { - const struct status_entry *entry_a = (const struct status_entry *)(a); - const struct status_entry *entry_b = (const struct status_entry *)(b); + struct status_entry *e = git__malloc(sizeof(*e) + strlen(path) + 1); + if (e == NULL) + return NULL; - return strcmp(entry_a->path, entry_b->path); + memset(e, 0x0, sizeof(*e)); + + if (entries != NULL) + git_vector_insert(entries, e); + + strcpy(e->path, path); + + return e; } -static int status_srch(const void *key, const void *array_member) +GIT_INLINE(void) status_entry_update_from_tree_entry(struct status_entry *e, const git_tree_entry *tree_entry) { - const char *path = (const char *)key; - const struct status_entry *entry = (const struct status_entry *)(array_member); + assert(e && tree_entry); - return strcmp(path, entry->path); + git_oid_cpy(&e->head_oid, &tree_entry->oid); } -static int find_status_entry(git_vector *entries, const char *path) +GIT_INLINE(void) status_entry_update_from_index_entry(struct status_entry *e, const git_index_entry *index_entry) { - return git_vector_bsearch2(entries, status_srch, path); + assert(e && index_entry); + + git_oid_cpy(&e->index_oid, &index_entry->oid); + e->mtime = index_entry->mtime; } -static struct status_entry *new_status_entry(git_vector *entries, const char *path) +static void status_entry_update_from_index(struct status_entry *e, git_index *index) { - struct status_entry *e = git__malloc(sizeof(struct status_entry)); - memset(e, 0x0, sizeof(struct status_entry)); - if (entries != NULL) - git_vector_insert(entries, e); - strcpy(e->path, path); - return e; + int idx; + git_index_entry *index_entry; + + assert(e && index); + + idx = git_index_find(index, e->path); + if (idx < 0) + return; + + index_entry = git_index_get(index, idx); + + status_entry_update_from_index_entry(e, index_entry); } -static void recurse_tree_entries(git_tree *tree, git_vector *entries, char *path) +static int status_entry_update_from_workdir(struct status_entry *e, char* full_path) { - int i, cnt, idx; - struct status_entry *e; - char file_path[GIT_PATH_MAX]; - git_tree *subtree; + struct stat filest; - cnt = git_tree_entrycount(tree); - for (i = 0; i < cnt; ++i) { - const git_tree_entry *tree_entry = git_tree_entry_byindex(tree, i); + if (p_stat(full_path, &filest) < GIT_SUCCESS) + return git__throw(GIT_EOSERR, "Failed to determine status of file '%s'. Can't read file", full_path); - git_path_join(file_path, path, tree_entry->filename); + if (e->mtime.seconds == (git_time_t)filest.st_mtime) + git_oid_cpy(&e->wt_oid, &e->index_oid); + else + git_odb_hashfile(&e->wt_oid, full_path, GIT_OBJ_BLOB); - if (git_tree_lookup(&subtree, tree->object.repo, &tree_entry->oid) == GIT_SUCCESS) { - recurse_tree_entries(subtree, entries, file_path); - git_tree_close(subtree); - continue; - } + return GIT_SUCCESS; +} - if ((idx = find_status_entry(entries, file_path)) != GIT_ENOTFOUND) - e = (struct status_entry *)git_vector_get(entries, idx); - else - e = new_status_entry(entries, file_path); +static int status_entry_update_flags(struct status_entry *e) +{ + git_oid zero; + int head_zero, index_zero, wt_zero; - git_oid_cpy(&e->head_oid, &tree_entry->oid); - } + memset(&zero, 0x0, sizeof(git_oid)); + + head_zero = git_oid_cmp(&zero, &e->head_oid); + index_zero = git_oid_cmp(&zero, &e->index_oid); + wt_zero = git_oid_cmp(&zero, &e->wt_oid); + + if (head_zero == 0 && index_zero == 0 && wt_zero == 0) + return GIT_ENOTFOUND; + + if (head_zero == 0 && index_zero != 0) + e->status_flags |= GIT_STATUS_INDEX_NEW; + else if (index_zero == 0 && head_zero != 0) + e->status_flags |= GIT_STATUS_INDEX_DELETED; + else if (git_oid_cmp(&e->head_oid, &e->index_oid) != 0) + e->status_flags |= GIT_STATUS_INDEX_MODIFIED; + + if (index_zero == 0 && wt_zero != 0) + e->status_flags |= GIT_STATUS_WT_NEW; + else if (wt_zero == 0 && index_zero != 0) + e->status_flags |= GIT_STATUS_WT_DELETED; + else if (git_oid_cmp(&e->index_oid, &e->wt_oid) != 0) + e->status_flags |= GIT_STATUS_WT_MODIFIED; + + return GIT_SUCCESS; } -static void recurse_tree_entry(git_tree *tree, struct status_entry *e, const char *path) +struct status_st { + git_vector *vector; + git_index *index; + git_tree *tree; + + int workdir_path_len; + char* head_tree_relative_path; + int head_tree_relative_path_len; + unsigned int tree_position; + unsigned int index_position; + int is_dir:1; +}; + +static int retrieve_head_tree(git_tree **tree_out, git_repository *repo) { - char *dir_sep; - char buffer[GIT_PATH_MAX]; - const git_tree_entry *tree_entry; - git_tree *subtree; + git_reference *resolved_head_ref; + git_commit *head_commit = NULL; + git_tree *tree; + int error = GIT_SUCCESS; - strcpy(buffer, path); + *tree_out = NULL; - dir_sep = strchr(buffer, '/'); - if (dir_sep) { - *dir_sep = '\0'; + error = git_repository_head(&resolved_head_ref, repo); + if (error != GIT_SUCCESS && error != GIT_ENOTFOUND) + return git__rethrow(error, "HEAD can't be resolved"); - tree_entry = git_tree_entry_byname(tree, buffer); - if (tree_entry != NULL) { - if (git_tree_lookup(&subtree, tree->object.repo, &tree_entry->oid) == GIT_SUCCESS) { - recurse_tree_entry(subtree, e, dir_sep+1); - git_tree_close(subtree); - return; - } - } + /* + * We assume that a situation where HEAD exists but can not be resolved is valid. + * A new repository fits this description for instance. + */ + + if (error == GIT_ENOTFOUND) + return GIT_SUCCESS; + + if ((error = git_commit_lookup(&head_commit, repo, git_reference_oid(resolved_head_ref))) < GIT_SUCCESS) + return git__rethrow(error, "The tip of HEAD can't be retrieved"); + + if ((error = git_commit_tree(&tree, head_commit)) < GIT_SUCCESS) { + error = git__rethrow(error, "The tree of HEAD can't be retrieved"); + goto exit; } - tree_entry = git_tree_entry_byname(tree, path); - if (tree_entry != NULL) { - git_oid_cpy(&e->head_oid, &tree_entry->oid); + *tree_out = tree; + +exit: + git_commit_close(head_commit); + return error; +} + +#define GIT_STATUS_PATH_NULL -2 +#define GIT_STATUS_PATH_IGNORE -1 +#define GIT_STATUS_PATH_FILE 0 +#define GIT_STATUS_PATH_FOLDER 1 + +static int dirent_cb(void *state, char *full_path); +static int alphasorted_futils_direach( + char *path, size_t path_sz, + int (*fn)(void *, char *), void *arg); + +static int process_folder(struct status_st *st, const git_tree_entry *tree_entry, char *full_path, int path_type) +{ + git_object *subtree = NULL; + git_tree *pushed_tree = NULL; + int error, pushed_tree_position = 0; + git_otype tree_entry_type; + + tree_entry_type = git_tree_entry_type(tree_entry); + + switch (tree_entry_type) { + case GIT_OBJ_TREE: + error = git_tree_entry_2object(&subtree, ((git_object *)(st->tree))->repo, tree_entry); + pushed_tree = st->tree; + pushed_tree_position = st->tree_position; + st->tree = (git_tree *)subtree; + st->tree_position = 0; + st->head_tree_relative_path_len += 1 + tree_entry->filename_len; /* path + '/' + name */ + break; + + case GIT_OBJ_BLOB: + /* No op */ + break; + + default: + error = git__throw(GIT_EINVALIDTYPE, "Unexpected tree entry type"); /* TODO: How should we deal with submodules? */ } + + if (full_path != NULL && path_type == GIT_STATUS_PATH_FOLDER) + error = alphasorted_futils_direach(full_path, GIT_PATH_MAX, dirent_cb, st); + else { + error = dirent_cb(st, NULL); + } + + if (tree_entry_type == GIT_OBJ_TREE) { + git_object_close(subtree); + st->head_tree_relative_path_len -= 1 + tree_entry->filename_len; + st->tree = pushed_tree; + st->tree_position = pushed_tree_position; + st->tree_position++; + } + + return error; } -struct status_st { - union { - git_vector *vector; - struct status_entry *e; - } entry; +static int store_if_changed(struct status_st *st, struct status_entry *e) +{ + int error; + if ((error = status_entry_update_flags(e)) < GIT_SUCCESS) + return git__throw(error, "Failed to process the file '%s'. It doesn't exist in the workdir, in the HEAD nor in the index", e->path); - int workdir_path_len; -}; + if (e->status_flags == GIT_STATUS_CURRENT) { + free(e); + return GIT_SUCCESS; + } + + return git_vector_insert(st->vector, e); +} -static int dirent_cb(void *state, char *full_path) +static int determine_status(struct status_st *st, + int in_head, int in_index, int in_workdir, + const git_tree_entry *tree_entry, + const git_index_entry *index_entry, + char *full_path, + const char *status_path, + int path_type) { - int idx; struct status_entry *e; - struct status_st *st = (struct status_st *)state; - char *file_path = full_path + st->workdir_path_len; - struct stat filest; - git_oid oid; + int error = GIT_SUCCESS; + git_otype tree_entry_type = GIT_OBJ_BAD; - if ((git_futils_isdir(full_path) == GIT_SUCCESS) && (!strcmp(".git", file_path))) - return 0; + if (tree_entry != NULL) + tree_entry_type = git_tree_entry_type(tree_entry); - if (git_futils_isdir(full_path) == GIT_SUCCESS) - return git_futils_direach(full_path, GIT_PATH_MAX, dirent_cb, state); + /* If we're dealing with a directory in the workdir, let's recursively tackle it first */ + if (path_type == GIT_STATUS_PATH_FOLDER) + return process_folder(st, tree_entry, full_path, path_type); - if ((idx = find_status_entry(st->entry.vector, file_path)) != GIT_ENOTFOUND) { - e = (struct status_entry *)git_vector_get(st->entry.vector, idx); + /* Are we dealing with a file somewhere? */ + if (in_workdir || in_index || (in_head && tree_entry_type == GIT_OBJ_BLOB)) { + e = status_entry_new(NULL, status_path); - if (p_stat(full_path, &filest) < 0) - return git__throw(GIT_EOSERR, "Failed to read file %s", full_path); + if (in_head && tree_entry_type == GIT_OBJ_BLOB) { + status_entry_update_from_tree_entry(e, tree_entry); + st->tree_position++; + } - if (e->mtime.seconds == (git_time_t)filest.st_mtime) { - git_oid_cpy(&e->wt_oid, &e->index_oid); - return 0; + if (in_index) { + status_entry_update_from_index_entry(e, index_entry); + st->index_position++; } - } else { - e = new_status_entry(st->entry.vector, file_path); + + if (in_workdir) + if ((error = status_entry_update_from_workdir(e, full_path)) < GIT_SUCCESS) + return error; /* The callee has already set the error message */ + + return store_if_changed(st, e); } - git_odb_hashfile(&oid, full_path, GIT_OBJ_BLOB); - git_oid_cpy(&e->wt_oid, &oid); + /* Last option, we're dealing with a leftover folder tree entry */ + assert(in_head && !in_index && !in_workdir && (tree_entry_type == GIT_OBJ_TREE)); + return process_folder(st, tree_entry, full_path, path_type); +} + +static int path_type_from(char *full_path, int is_dir) +{ + if (full_path == NULL) + return GIT_STATUS_PATH_NULL; + + if (!is_dir) + return GIT_STATUS_PATH_FILE; + + if (!git__suffixcmp(full_path, "/" DOT_GIT)) + return GIT_STATUS_PATH_IGNORE; - return 0; + return GIT_STATUS_PATH_FOLDER; } -static int single_dirent_cb(void *state, char *full_path) +static const char *status_path(const char *first, const char *second, const char *third) { - struct status_st *st = (struct status_st *)state; - struct status_entry *e = st->entry.e; + /* At least one of them can not be NULL */ + assert(first != NULL || second != NULL || third != NULL); - char *file_path = full_path + st->workdir_path_len; - struct stat filest; - git_oid oid; + /* TODO: Fixme. Ensure that when non null, they're all equal */ + if (first != NULL) + return first; + + if (second != NULL) + return second; + + return third; +} - if ((git_futils_isdir(full_path) == GIT_SUCCESS) && (!strcmp(".git", file_path))) +static int compare(const char *left, const char *right) +{ + if (left == NULL && right == NULL) return 0; - if (git_futils_isdir(full_path) == GIT_SUCCESS) - return git_futils_direach(full_path, GIT_PATH_MAX, single_dirent_cb, state); + if (left == NULL) + return 1; - if (!strcmp(file_path, e->path)) { - if (p_stat(full_path, &filest) < 0) - return git__throw(GIT_EOSERR, "Failed to read file %s", full_path); + if (right == NULL) + return -1; - if (e->mtime.seconds == (git_time_t)filest.st_mtime) { - git_oid_cpy(&e->wt_oid, &e->index_oid); - return 1; - } + return strcmp(left, right); +} - git_odb_hashfile(&oid, full_path, GIT_OBJ_BLOB); - git_oid_cpy(&e->wt_oid, &oid); - return 1; - } +/* + * Convenience method to enumerate a tree. Contrarily to the git_tree_entry_byindex() + * method, it allows the tree to be enumerated to be NULL. In this case, every returned + * tree entry will be NULL as well. + */ +static const git_tree_entry *git_tree_entry_bypos(git_tree *tree, unsigned int idx) +{ + if (tree == NULL) + return NULL; - return 0; + return git_vector_get(&tree->entries, idx); } -static int set_status_flags(struct status_entry *e) +/* + * Convenience method to enumerate the index. This method is not supposed to be exposed + * as part of the index API because it precludes that the index will not be altered + * while the enumeration is being processed. Which wouldn't be very API friendly :) + */ +static const git_index_entry *git_index_entry_bypos(git_index *index, unsigned int idx) { - git_oid zero; - int head_zero, index_zero, wt_zero; + assert(index); + return git_vector_get(&index->entries, idx); +} - memset(&zero, 0x0, sizeof(git_oid)); +/* Greatly inspired from JGit IndexTreeWalker */ +/* https://github.com/spearce/jgit/blob/ed47e29c777accfa78c6f50685a5df2b8f5b8ff5/org.spearce.jgit/src/org/spearce/jgit/lib/IndexTreeWalker.java#L88 */ - head_zero = git_oid_cmp(&zero, &e->head_oid); - index_zero = git_oid_cmp(&zero, &e->index_oid); - wt_zero = git_oid_cmp(&zero, &e->wt_oid); +static int dirent_cb(void *state, char *a) +{ + const git_tree_entry *m; + const git_index_entry *entry; + int path_type; + int cmpma, cmpmi, cmpai, error; + const char *pm, *pa, *pi; + const char *m_name, *i_name, *a_name; - if (head_zero == 0 && index_zero == 0 && wt_zero == 0) - return GIT_ENOTFOUND; + struct status_st *st = (struct status_st *)state; - if (head_zero == 0 && index_zero != 0) - e->status_flags |= GIT_STATUS_INDEX_NEW; - else if (index_zero == 0 && head_zero != 0) - e->status_flags |= GIT_STATUS_INDEX_DELETED; - else if (git_oid_cmp(&e->head_oid, &e->index_oid) != 0) - e->status_flags |= GIT_STATUS_INDEX_MODIFIED; + path_type = path_type_from(a, st->is_dir); - if (index_zero == 0 && wt_zero != 0) - e->status_flags |= GIT_STATUS_WT_NEW; - else if (wt_zero == 0 && index_zero != 0) - e->status_flags |= GIT_STATUS_WT_DELETED; - else if (git_oid_cmp(&e->index_oid, &e->wt_oid) != 0) - e->status_flags |= GIT_STATUS_WT_MODIFIED; + if (path_type == GIT_STATUS_PATH_IGNORE) + return GIT_SUCCESS; /* Let's skip the ".git" directory */ - return GIT_SUCCESS; + a_name = (path_type != GIT_STATUS_PATH_NULL) ? a + st->workdir_path_len : NULL; + + while (1) { + m = git_tree_entry_bypos(st->tree, st->tree_position); + entry = git_index_entry_bypos(st->index, st->index_position); + + if ((m == NULL) && (a == NULL) && (entry == NULL)) + return GIT_SUCCESS; + + if (m != NULL) { + st->head_tree_relative_path[st->head_tree_relative_path_len] = '\0'; + git_path_join(st->head_tree_relative_path, st->head_tree_relative_path, m->filename); + m_name = st->head_tree_relative_path; + } else + m_name = NULL; + + i_name = (entry != NULL) ? entry->path : NULL; + + cmpma = compare(m_name, a_name); + cmpmi = compare(m_name, i_name); + cmpai = compare(a_name, i_name); + + pm = ((cmpma <= 0) && (cmpmi <= 0)) ? m_name : NULL; + pa = ((cmpma >= 0) && (cmpai <= 0)) ? a_name : NULL; + pi = ((cmpmi >= 0) && (cmpai >= 0)) ? i_name : NULL; + + if((error = determine_status(st, pm != NULL, pi != NULL, pa != NULL, m, entry, a, status_path(pm, pi, pa), path_type)) < GIT_SUCCESS) + return git__rethrow(error, "An error occured while determining the status of '%s'", a); + + if (pa != NULL) + return GIT_SUCCESS; + } +} + +static int status_cmp(const void *a, const void *b) +{ + const struct status_entry *entry_a = (const struct status_entry *)(a); + const struct status_entry *entry_b = (const struct status_entry *)(b); + + return strcmp(entry_a->path, entry_b->path); } +#define DEFAULT_SIZE 16 + int git_status_foreach(git_repository *repo, int (*callback)(const char *, unsigned int, void *), void *payload) { git_vector entries; - struct status_entry *e; - git_index *index; - unsigned int i, cnt; - git_index_entry *index_entry; + git_index *index = NULL; char temp_path[GIT_PATH_MAX]; - int error; - git_tree *tree; + char tree_path[GIT_PATH_MAX] = ""; struct status_st dirent_st; + int error = GIT_SUCCESS; + unsigned int i; + git_tree *tree; + struct status_entry *e; - git_reference *head_ref, *resolved_head_ref; - git_commit *head_commit; - - git_repository_index(&index, repo); - - cnt = git_index_entrycount(index); - git_vector_init(&entries, cnt, status_cmp); - for (i = 0; i < cnt; ++i) { - index_entry = git_index_get(index, i); - - e = new_status_entry(&entries, index_entry->path); - git_oid_cpy(&e->index_oid, &index_entry->oid); - e->mtime = index_entry->mtime; + if ((error = git_repository_index(&index, repo)) < GIT_SUCCESS) { + return git__rethrow(error, "Failed to determine statuses. Index can't be opened"); } - git_index_free(index); - - git_reference_lookup(&head_ref, repo, GIT_HEAD_FILE); - git_reference_resolve(&resolved_head_ref, head_ref); - git_commit_lookup(&head_commit, repo, git_reference_oid(resolved_head_ref)); + if ((error = retrieve_head_tree(&tree, repo)) < GIT_SUCCESS) { + error = git__rethrow(error, "Failed to determine statuses"); + goto exit; + } - // recurse through tree entries - git_commit_tree(&tree, head_commit); - recurse_tree_entries(tree, &entries, ""); - git_tree_close(tree); - git_commit_close(head_commit); + git_vector_init(&entries, DEFAULT_SIZE, status_cmp); dirent_st.workdir_path_len = strlen(repo->path_workdir); - dirent_st.entry.vector = &entries; - strcpy(temp_path, repo->path_workdir); - git_futils_direach(temp_path, GIT_PATH_MAX, dirent_cb, &dirent_st); + dirent_st.tree_position = 0; + dirent_st.index_position = 0; + dirent_st.tree = tree; + dirent_st.index = index; + dirent_st.vector = &entries; + dirent_st.head_tree_relative_path = tree_path; + dirent_st.head_tree_relative_path_len = 0; + dirent_st.is_dir = 1; - for (i = 0; i < entries.length; ++i) { - e = (struct status_entry *)git_vector_get(&entries, i); + strcpy(temp_path, repo->path_workdir); - set_status_flags(e); + if (git_futils_isdir(temp_path)) { + error = git__throw(GIT_EINVALIDPATH, "Failed to determine status of file '%s'. Provided path doesn't lead to a folder", temp_path); + goto exit; } + if ((error = alphasorted_futils_direach(temp_path, sizeof(temp_path), dirent_cb, &dirent_st)) < GIT_SUCCESS) + error = git__rethrow(error, "Failed to determine statuses. An error occured while processing the working directory"); + + if ((error == GIT_SUCCESS) && ((error = dirent_cb(&dirent_st, NULL)) < GIT_SUCCESS)) + error = git__rethrow(error, "Failed to determine statuses. An error occured while post-processing the HEAD tree and the index"); for (i = 0; i < entries.length; ++i) { e = (struct status_entry *)git_vector_get(&entries, i); - if ((error = callback(e->path, e->status_flags, payload)) < GIT_SUCCESS) - return git__throw(error, "Failed to list statuses. User callback failed"); - } + if (error == GIT_SUCCESS) { + error = callback(e->path, e->status_flags, payload); + if (error < GIT_SUCCESS) + error = git__rethrow(error, "Failed to determine statuses. User callback failed"); + } - for (i = 0; i < entries.length; ++i) { - e = (struct status_entry *)git_vector_get(&entries, i); free(e); } + +exit: git_vector_free(&entries); + git_tree_close(tree); + git_index_free(index); + return error; +} - return GIT_SUCCESS; +static int recurse_tree_entry(git_tree *tree, struct status_entry *e, const char *path) +{ + char *dir_sep; + const git_tree_entry *tree_entry; + git_tree *subtree; + int error = GIT_SUCCESS; + + dir_sep = strchr(path, '/'); + if (!dir_sep) { + tree_entry = git_tree_entry_byname(tree, path); + if (tree_entry == NULL) + return GIT_SUCCESS; /* The leaf doesn't exist in the tree*/ + + status_entry_update_from_tree_entry(e, tree_entry); + return GIT_SUCCESS; + } + + /* Retrieve subtree name */ + *dir_sep = '\0'; + + tree_entry = git_tree_entry_byname(tree, path); + if (tree_entry == NULL) + return GIT_SUCCESS; /* The subtree doesn't exist in the tree*/ + + *dir_sep = '/'; + + /* Retreive subtree */ + if ((error = git_tree_lookup(&subtree, tree->object.repo, &tree_entry->oid)) < GIT_SUCCESS) + return git__throw(GIT_EOBJCORRUPTED, "Can't find tree object '%s'", tree_entry->filename); + + error = recurse_tree_entry(subtree, e, dir_sep+1); + git_tree_close(subtree); + return error; } int git_status_file(unsigned int *status_flags, git_repository *repo, const char *path) { struct status_entry *e; - git_index *index; - git_index_entry *index_entry; + git_index *index = NULL; char temp_path[GIT_PATH_MAX]; - int idx, error; - git_tree *tree; - git_reference *head_ref, *resolved_head_ref; - git_commit *head_commit; - struct status_st dirent_st; + int error = GIT_SUCCESS; + git_tree *tree = NULL; + + assert(status_flags && repo && path); - assert(status_flags); + git_path_join(temp_path, repo->path_workdir, path); + if (git_futils_isdir(temp_path) == GIT_SUCCESS) + return git__throw(GIT_EINVALIDPATH, "Failed to determine status of file '%s'. Provided path leads to a folder, not a file", path); - e = new_status_entry(NULL, path); + e = status_entry_new(NULL, path); + if (e == NULL) + return GIT_ENOMEM; - // Find file in Index - git_repository_index(&index, repo); - idx = git_index_find(index, path); - if (idx >= 0) { - index_entry = git_index_get(index, idx); - git_oid_cpy(&e->index_oid, &index_entry->oid); - e->mtime = index_entry->mtime; + /* Find file in Workdir */ + if (git_futils_exists(temp_path) == GIT_SUCCESS) { + if ((error = status_entry_update_from_workdir(e, temp_path)) < GIT_SUCCESS) + goto exit; /* The callee has already set the error message */ } - git_index_free(index); - // Find file in HEAD - git_reference_lookup(&head_ref, repo, GIT_HEAD_FILE); - git_reference_resolve(&resolved_head_ref, head_ref); + /* Find file in Index */ + if ((error = git_repository_index(&index, repo)) < GIT_SUCCESS) { + error = git__rethrow(error, "Failed to determine status of file '%s'. Index can't be opened", path); + goto exit; + } - git_commit_lookup(&head_commit, repo, git_reference_oid(resolved_head_ref)); + status_entry_update_from_index(e, index); + git_index_free(index); - git_commit_tree(&tree, head_commit); - recurse_tree_entry(tree, e, path); - git_tree_close(tree); - git_commit_close(head_commit); + if ((error = retrieve_head_tree(&tree, repo)) < GIT_SUCCESS) { + error = git__rethrow(error, "Failed to determine status of file '%s'", path); + goto exit; + } - // Find file in Workdir - dirent_st.workdir_path_len = strlen(repo->path_workdir); - dirent_st.entry.e = e; - strcpy(temp_path, repo->path_workdir); - git_futils_direach(temp_path, GIT_PATH_MAX, single_dirent_cb, &dirent_st); + /* If the repository is not empty, try and locate the file in HEAD */ + if (tree != NULL) { + strcpy(temp_path, path); - if ((error = set_status_flags(e)) < GIT_SUCCESS) { - free(e); - return git__throw(error, "Nonexistent file"); + error = recurse_tree_entry(tree, e, temp_path); + if (error < GIT_SUCCESS) { + error = git__rethrow(error, "Failed to determine status of file '%s'. An error occured while processing the tree", path); + goto exit; + } + } + + /* Determine status */ + if ((error = status_entry_update_flags(e)) < GIT_SUCCESS) { + error = git__throw(error, "Nonexistent file"); + goto exit; } *status_flags = e->status_flags; +exit: + git_tree_close(tree); free(e); + return error; +} + +/* + * git_futils_direach is not supposed to return entries in an ordered manner. + * alphasorted_futils_direach wraps git_futils_direach and invokes the callback + * function by passing it alphabeticcally sorted paths parameters. + * + */ + +struct alphasorted_dirent_info { + int is_dir; + + char path[GIT_FLEX_ARRAY]; /* more */ +}; + +static struct alphasorted_dirent_info *alphasorted_dirent_info_new(const char *path) +{ + int is_dir; + struct alphasorted_dirent_info *di; + + is_dir = git_futils_isdir(path) == GIT_SUCCESS ? 1 : 0; + + di = git__malloc(sizeof(*di) + (is_dir ? GIT_PATH_MAX : strlen(path)) + 1); + if (di == NULL) + return NULL; + + memset(di, 0x0, sizeof(*di)); + + strcpy(di->path, path); + di->is_dir = is_dir; + + return di; +} + +int alphasorted_dirent_info_cmp(const void *a, const void *b) +{ + struct alphasorted_dirent_info *stra = (struct alphasorted_dirent_info *)a; + struct alphasorted_dirent_info *strb = (struct alphasorted_dirent_info *)b; + + return strcmp(stra->path, strb->path); +} + +static int alphasorted_dirent_cb(void *state, char *full_path) +{ + struct alphasorted_dirent_info *entry; + git_vector *entry_names; + + entry_names = (git_vector *)state; + entry = alphasorted_dirent_info_new(full_path); + + if (entry == NULL) + return GIT_ENOMEM; + + if (git_vector_insert(entry_names, entry) < GIT_SUCCESS) { + free(entry); + return GIT_ENOMEM; + } return GIT_SUCCESS; } + +static int alphasorted_futils_direach( + char *path, + size_t path_sz, + int (*fn)(void *, char *), + void *arg) +{ + struct alphasorted_dirent_info *entry; + git_vector entry_names; + unsigned int idx; + int error = GIT_SUCCESS; + + if (git_vector_init(&entry_names, 16, alphasorted_dirent_info_cmp) < GIT_SUCCESS) + return GIT_ENOMEM; + + error = git_futils_direach(path, path_sz, alphasorted_dirent_cb, &entry_names); + + git_vector_sort(&entry_names); + + for (idx = 0; idx < entry_names.length; ++idx) { + entry = (struct alphasorted_dirent_info *)git_vector_get(&entry_names, idx); + + if (error == GIT_SUCCESS) { + ((struct status_st *)arg)->is_dir = entry->is_dir; + error = fn(arg, entry->path); + } + + free(entry); + } + + git_vector_free(&entry_names); + return error; +} @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" @@ -245,7 +227,7 @@ static int git_tag_create__internal( } /** 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 (!allow_ref_overwrite) { git_oid_cpy(oid, git_reference_oid(new_ref)); @@ -330,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 - * reference unless overwriting has explictly been requested **/ + * reference unless overwriting has explictly been requested **/ if (new_ref != NULL) { if (!allow_ref_overwrite) { git_oid_cpy(oid, git_reference_oid(new_ref)); @@ -384,8 +366,8 @@ int git_tag__parse(git_tag *tag, git_odb_object *obj) } typedef struct { - git_vector *taglist; - const char *pattern; + git_vector *taglist; + const char *pattern; } tag_filter_data; #define GIT_REFS_TAGS_DIR_LEN strlen(GIT_REFS_TAGS_DIR) @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_tag_h__ #define INCLUDE_tag_h__ diff --git a/src/thread-utils.c b/src/thread-utils.c index 5e8220f46..f582f4311 100644 --- a/src/thread-utils.c +++ b/src/thread-utils.c @@ -1,11 +1,17 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #include "common.h" #include "thread-utils.h" #ifdef _WIN32 -# define WIN32_LEAN_AND_MEAN -# include <windows.h> +# define WIN32_LEAN_AND_MEAN +# include <windows.h> #elif defined(hpux) || defined(__hpux) || defined(_hpux) -# include <sys/pstat.h> +# include <sys/pstat.h> #endif /* @@ -14,11 +20,11 @@ * with this disgusting nest of #ifdefs. */ #ifndef _SC_NPROCESSORS_ONLN -# ifdef _SC_NPROC_ONLN -# define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN -# elif defined _SC_CRAY_NCPU -# define _SC_NPROCESSORS_ONLN _SC_CRAY_NCPU -# endif +# ifdef _SC_NPROC_ONLN +# define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN +# elif defined _SC_CRAY_NCPU +# define _SC_NPROCESSORS_ONLN _SC_CRAY_NCPU +# endif #endif int git_online_cpus(void) diff --git a/src/thread-utils.h b/src/thread-utils.h index 20d6022ea..3361ed8bc 100644 --- a/src/thread-utils.h +++ b/src/thread-utils.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_thread_utils_h__ #define INCLUDE_thread_utils_h__ @@ -27,10 +33,10 @@ GIT_INLINE(void) git_atomic_set(git_atomic *a, int val) /* Pthreads Mutex */ #define git_mutex pthread_mutex_t -#define git_mutex_init(a) pthread_mutex_init(a, NULL) -#define git_mutex_lock(a) pthread_mutex_lock(a) +#define git_mutex_init(a) pthread_mutex_init(a, NULL) +#define git_mutex_lock(a) pthread_mutex_lock(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 */ #define git_cond unsigned int //pthread_cond_t diff --git a/src/transport.c b/src/transport.c index 91f621c46..6be8f4058 100644 --- a/src/transport.c +++ b/src/transport.c @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #include "common.h" #include "git2/types.h" #include "git2/transport.h" diff --git a/src/transport.h b/src/transport.h index 9489ac803..233cfb1db 100644 --- a/src/transport.h +++ b/src/transport.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_transport_h__ #define INCLUDE_transport_h__ @@ -9,7 +15,7 @@ typedef struct git_transport_caps { int common:1, - ofs_delta:1; + ofs_delta:1; } git_transport_caps; /* diff --git a/src/transport_git.c b/src/transport_git.c index 7b0edcfef..ac268cd43 100644 --- a/src/transport_git.c +++ b/src/transport_git.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "git2/net.h" @@ -405,8 +387,8 @@ static int git_negotiate_fetch(git_transport *transport, git_repository *repo, g error = gitno_recv(&buf); if (error < GIT_SUCCESS) { - error = git__rethrow(error, "Error receiving data"); - goto cleanup; + error = git__rethrow(error, "Error receiving data"); + goto cleanup; } error = git_pkt_parse_line(&pkt, ptr, &line_end, buf.offset); if (error == GIT_ESHORTBUFFER) @@ -553,7 +535,7 @@ static int git_close(git_transport *transport) int s = t->socket; 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); error = close(s); if (error < 0) diff --git a/src/transport_local.c b/src/transport_local.c index ab0922cf2..4975af9ad 100644 --- a/src/transport_local.c +++ b/src/transport_local.c @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #include "common.h" #include "git2/types.h" #include "git2/transport.h" diff --git a/src/tree.c b/src/tree.c index e0225f90b..ce399a66a 100644 --- a/src/tree.c +++ b/src/tree.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" @@ -222,89 +204,101 @@ int git_tree__parse(git_tree *tree, git_odb_object *obj) return tree_parse_buffer(tree, (char *)obj->raw.data, (char *)obj->raw.data + obj->raw.len); } -static int write_index_entry(char *buffer, int mode, const char *path, size_t path_len, const git_oid *oid) +static int write_tree(git_oid *oid, git_index *index, const char *dirname, unsigned int start) { - int written; - written = sprintf(buffer, "%o %.*s%c", mode, (int)path_len, path, 0); - memcpy(buffer + written, &oid->id, GIT_OID_RAWSZ); - return written + GIT_OID_RAWSZ; -} + git_treebuilder *bld = NULL; + unsigned int i, entries = git_index_entrycount(index); + int error; + size_t dirname_len = strlen(dirname); -static int write_index(git_oid *oid, git_index *index, const char *base, int baselen, int entry_no, int maxentries) -{ - size_t size, offset; - char *buffer; - int nr, error; - - /* Guess at some random initial size */ - size = maxentries * 40; - buffer = git__malloc(size); - if (buffer == NULL) + error = git_treebuilder_create(&bld, NULL); + if (bld == NULL) { return GIT_ENOMEM; + } - offset = 0; - - for (nr = entry_no; nr < maxentries; ++nr) { - git_index_entry *entry = git_index_get(index, nr); - - const char *pathname = entry->path, *filename, *dirname; - int pathlen = strlen(pathname), entrylen; - - unsigned int write_mode; - git_oid subtree_oid; - git_oid *write_oid; - - /* Did we hit the end of the directory? Return how many we wrote */ - if (baselen >= pathlen || memcmp(base, pathname, baselen) != 0) + /* + * This loop is unfortunate, but necessary. The index doesn't have + * any directores, so we need to handle that manually, and we + * need to keep track of the current position. + */ + for (i = start; i < entries; ++i) { + git_index_entry *entry = git_index_get(index, i); + char *filename, *next_slash; + + /* + * If we've left our (sub)tree, exit the loop and return. The + * first check is an early out (and security for the + * third). The second check is a simple prefix comparison. The + * third check catches situations where there is a directory + * win32/sys and a file win32mmap.c. Without it, the following + * code believes there is a file win32/mmap.c + */ + if (strlen(entry->path) < dirname_len || + memcmp(entry->path, dirname, dirname_len) || + (dirname_len > 0 && entry->path[dirname_len] != '/')) { break; + } - /* Do we have _further_ subdirectories? */ - filename = pathname + baselen; - dirname = strchr(filename, '/'); - - write_oid = &entry->oid; - write_mode = entry->mode; - - if (dirname) { - int subdir_written; - -#if 0 - if (entry->mode != S_IFDIR) { - free(buffer); - return GIT_EOBJCORRUPTED; + filename = entry->path + dirname_len; + if (*filename == '/') + filename++; + next_slash = strchr(filename, '/'); + if (next_slash) { + git_oid sub_oid; + int written; + char *subdir, *last_comp; + + subdir = git__strndup(entry->path, next_slash - entry->path); + if (subdir == NULL) { + error = GIT_ENOMEM; + goto cleanup; } -#endif - subdir_written = write_index(&subtree_oid, index, pathname, dirname - pathname + 1, nr, maxentries); - if (subdir_written < GIT_SUCCESS) { - free(buffer); - return subdir_written; + /* Write out the subtree */ + written = write_tree(&sub_oid, index, subdir, i); + if (written < 0) { + error = git__rethrow(written, "Failed to write subtree %s", subdir); + } else { + i = written - 1; /* -1 because of the loop increment */ } - nr = subdir_written - 1; - - /* Now we need to write out the directory entry into this tree.. */ - pathlen = dirname - pathname; - write_oid = &subtree_oid; - write_mode = S_IFDIR; - } - - entrylen = pathlen - baselen; - if (offset + entrylen + 32 > size) { - size = alloc_nr(offset + entrylen + 32); - buffer = git__realloc(buffer, size); - - if (buffer == NULL) - return GIT_ENOMEM; + /* + * We need to figure out what we want toinsert + * into this tree. If we're traversing + * deps/zlib/, then we only want to write + * 'zlib' into the tree. + */ + last_comp = strrchr(subdir, '/'); + if (last_comp) { + last_comp++; /* Get rid of the '/' */ + } else { + last_comp = subdir; + } + error = git_treebuilder_insert(NULL, bld, last_comp, &sub_oid, S_IFDIR); + free(subdir); + if (error < GIT_SUCCESS) { + error = git__rethrow(error, "Failed to insert dir"); + goto cleanup; + } + } else { + error = git_treebuilder_insert(NULL, bld, filename, &entry->oid, entry->mode); + if (error < GIT_SUCCESS) { + error = git__rethrow(error, "Failed to insert file"); + } } - - offset += write_index_entry(buffer + offset, write_mode, filename, entrylen, write_oid); } - error = git_odb_write(oid, index->repository->db, buffer, offset, GIT_OBJ_TREE); - free(buffer); + error = git_treebuilder_write(oid, index->repository, bld); + if (error < GIT_SUCCESS) + error = git__rethrow(error, "Failed to write tree to db"); + + cleanup: + git_treebuilder_free(bld); - return (error == GIT_SUCCESS) ? nr : git__rethrow(error, "Failed to write index"); + if (error < GIT_SUCCESS) + return error; + else + return i; } int git_tree_create_fromindex(git_oid *oid, git_index *index) @@ -314,7 +308,8 @@ int git_tree_create_fromindex(git_oid *oid, git_index *index) if (index->repository == NULL) return git__throw(GIT_EBAREINDEX, "Failed to create tree. The index file is not backed up by an existing repository"); - error = write_index(oid, index, "", 0, 0, git_index_entrycount(index)); + /* The tree cache didn't help us */ + error = write_tree(oid, index, "", 0); return (error < GIT_SUCCESS) ? git__rethrow(error, "Failed to create tree") : GIT_SUCCESS; } diff --git a/src/tree.h b/src/tree.h index bff3f8edb..4f8c07f08 100644 --- a/src/tree.h +++ b/src/tree.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_tree_h__ #define INCLUDE_tree_h__ diff --git a/src/tsort.c b/src/tsort.c index 14b15c232..5dd99cc6e 100644 --- a/src/tsort.c +++ b/src/tsort.c @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #include "common.h" @@ -62,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) { size_t i; @@ -201,7 +207,7 @@ static void merge(void **dst, const struct tsort_run *stack, int stack_curr, str if (resize(store, MIN(A, B)) < 0) return; - storage = store->storage; + storage = store->storage; /* left merge */ if (A < B) { diff --git a/src/unix/map.c b/src/unix/map.c index 5192c8e4c..2fb4be571 100644 --- a/src/unix/map.c +++ b/src/unix/map.c @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #include <git2/common.h> #ifndef GIT_WIN32 diff --git a/src/unix/posix.h b/src/unix/posix.h index a49a5cfe7..5c74f0779 100644 --- a/src/unix/posix.h +++ b/src/unix/posix.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_posix__w32_h__ #define INCLUDE_posix__w32_h__ diff --git a/src/util.c b/src/util.c index 29bf755f8..b46a2a15c 100644 --- a/src/util.c +++ b/src/util.c @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #include <git2.h> #include "common.h" #include <stdarg.h> @@ -118,9 +124,9 @@ Return: return GIT_SUCCESS; } -void git__strntolower(char *str, int len) +void git__strntolower(char *str, size_t len) { - int i; + size_t i; for (i = 0; i < len; ++i) { str[i] = (char) tolower(str[i]); @@ -208,7 +214,7 @@ void git__hexdump(const char *buffer, size_t len) printf("%02X ", (unsigned char)*line & 0xFF); for (j = 0; j < (LINE_WIDTH - last_line); ++j) - printf(" "); + printf(" "); printf("| "); @@ -249,7 +255,7 @@ uint32_t git__hash(const void *key, int len, unsigned int seed) case 3: h ^= data[2] << 16; case 2: h ^= data[1] << 8; case 1: h ^= data[0]; - h *= m; + h *= m; }; h ^= h >> 13; @@ -270,13 +276,13 @@ uint32_t git__hash(const void *key, int len, uint32_t seed) { #define MURMUR_BLOCK() {\ - k1 *= c1; \ - k1 = git__rotl(k1,11);\ - k1 *= c2;\ - h1 ^= k1;\ - h1 = h1*3 + 0x52dce729;\ - c1 = c1*5 + 0x7b7d159c;\ - c2 = c2*5 + 0x6bce6396;\ + k1 *= c1; \ + k1 = git__rotl(k1,11);\ + k1 *= c2;\ + h1 ^= k1;\ + h1 = h1*3 + 0x52dce729;\ + c1 = c1*5 + 0x7b7d159c;\ + c2 = c2*5 + 0x6bce6396;\ } const uint8_t *data = (const uint8_t*)key; @@ -326,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 *)) { - int lim, cmp; - void **p; - - for (lim = nmemb; lim != 0; lim >>= 1) { - p = base + (lim >> 1); - cmp = (*compar)(key, *p); - if (cmp > 0) { /* key > p: move right */ - base = p + 1; - lim--; - } else if (cmp == 0) { - return (void **)p; - } /* else move left */ - } - return NULL; + int lim, cmp; + void **p; + + for (lim = nmemb; lim != 0; lim >>= 1) { + p = base + (lim >> 1); + cmp = (*compar)(key, *p); + if (cmp > 0) { /* key > p: move right */ + base = p + 1; + lim--; + } else if (cmp == 0) { + return (void **)p; + } /* else move left */ + } + return NULL; } /** diff --git a/src/util.h b/src/util.h index 78f9f8276..f24afb3ad 100644 --- a/src/util.h +++ b/src/util.h @@ -1,8 +1,14 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_util_h__ #define INCLUDE_util_h__ #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)))) #ifndef min # define min(a,b) ((a) < (b) ? (a) : (b)) @@ -90,7 +96,7 @@ GIT_INLINE(int) git__is_sizet(git_off_t p) extern char *git__strtok(char **end, const char *sep); -extern void git__strntolower(char *str, int len); +extern void git__strntolower(char *str, size_t len); extern void git__strtolower(char *str); extern int git__fnmatch(const char *pattern, const char *name, int flags); diff --git a/src/vector.c b/src/vector.c index 0b83b8b0d..8b20bb8ef 100644 --- a/src/vector.c +++ b/src/vector.c @@ -1,26 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "common.h" diff --git a/src/vector.h b/src/vector.h index c43a7ce07..08f5a501c 100644 --- a/src/vector.h +++ b/src/vector.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_vector_h__ #define INCLUDE_vector_h__ diff --git a/src/win32/dir.c b/src/win32/dir.c index 069a41c3a..01339577b 100644 --- a/src/win32/dir.c +++ b/src/win32/dir.c @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #define GIT__WIN32_NO_WRAP_DIR #include "dir.h" diff --git a/src/win32/fnmatch.c b/src/win32/fnmatch.c index de2f3e74f..7d7c77d48 100644 --- a/src/win32/fnmatch.c +++ b/src/win32/fnmatch.c @@ -1,33 +1,8 @@ /* - * Copyright (c) 1989, 1993, 1994 - * The Regents of the University of California. All rights reserved. + * Copyright (C) 2009-2011 the libgit2 contributors * - * This code is derived from software contributed to Berkeley by - * Guido van Rossum. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ /* @@ -41,165 +16,165 @@ #include "fnmatch.h" -#define EOS '\0' +#define EOS '\0' -#define RANGE_MATCH 1 -#define RANGE_NOMATCH 0 -#define RANGE_ERROR (-1) +#define RANGE_MATCH 1 +#define RANGE_NOMATCH 0 +#define RANGE_ERROR (-1) static int rangematch(const char *, char, int, char **); int p_fnmatch(const char *pattern, const char *string, int flags) { - const char *stringstart; - char *newp; - char c, test; - - for (stringstart = string;;) - switch (c = *pattern++) { - case EOS: - if ((flags & FNM_LEADING_DIR) && *string == '/') - return (0); - return (*string == EOS ? 0 : FNM_NOMATCH); - case '?': - if (*string == EOS) - return (FNM_NOMATCH); - if (*string == '/' && (flags & FNM_PATHNAME)) - return (FNM_NOMATCH); - if (*string == '.' && (flags & FNM_PERIOD) && - (string == stringstart || - ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) - return (FNM_NOMATCH); - ++string; - break; - case '*': - c = *pattern; - /* Collapse multiple stars. */ - while (c == '*') - c = *++pattern; - - if (*string == '.' && (flags & FNM_PERIOD) && - (string == stringstart || - ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) - return (FNM_NOMATCH); - - /* Optimize for pattern with * at end or before /. */ - if (c == EOS) { - if (flags & FNM_PATHNAME) - return ((flags & FNM_LEADING_DIR) || - strchr(string, '/') == NULL ? - 0 : FNM_NOMATCH); - else - return (0); - } else if (c == '/' && (flags & FNM_PATHNAME)) { - if ((string = strchr(string, '/')) == NULL) - return (FNM_NOMATCH); - break; - } - - /* General case, use recursion. */ - while ((test = *string) != EOS) { - if (!p_fnmatch(pattern, string, flags & ~FNM_PERIOD)) - return (0); - if (test == '/' && (flags & FNM_PATHNAME)) - break; - ++string; - } - return (FNM_NOMATCH); - case '[': - if (*string == EOS) - return (FNM_NOMATCH); - if (*string == '/' && (flags & FNM_PATHNAME)) - return (FNM_NOMATCH); - if (*string == '.' && (flags & FNM_PERIOD) && - (string == stringstart || - ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) - return (FNM_NOMATCH); - - switch (rangematch(pattern, *string, flags, &newp)) { - case RANGE_ERROR: - /* not a good range, treat as normal text */ - goto normal; - case RANGE_MATCH: - pattern = newp; - break; - case RANGE_NOMATCH: - return (FNM_NOMATCH); - } - ++string; - break; - case '\\': - if (!(flags & FNM_NOESCAPE)) { - if ((c = *pattern++) == EOS) { - c = '\\'; - --pattern; - } - } - /* FALLTHROUGH */ - default: - normal: - if (c != *string && !((flags & FNM_CASEFOLD) && - (tolower((unsigned char)c) == - tolower((unsigned char)*string)))) - return (FNM_NOMATCH); - ++string; - break; - } - /* NOTREACHED */ + const char *stringstart; + char *newp; + char c, test; + + for (stringstart = string;;) + switch (c = *pattern++) { + case EOS: + if ((flags & FNM_LEADING_DIR) && *string == '/') + return (0); + return (*string == EOS ? 0 : FNM_NOMATCH); + case '?': + if (*string == EOS) + return (FNM_NOMATCH); + if (*string == '/' && (flags & FNM_PATHNAME)) + return (FNM_NOMATCH); + if (*string == '.' && (flags & FNM_PERIOD) && + (string == stringstart || + ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) + return (FNM_NOMATCH); + ++string; + break; + case '*': + c = *pattern; + /* Collapse multiple stars. */ + while (c == '*') + c = *++pattern; + + if (*string == '.' && (flags & FNM_PERIOD) && + (string == stringstart || + ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) + return (FNM_NOMATCH); + + /* Optimize for pattern with * at end or before /. */ + if (c == EOS) { + if (flags & FNM_PATHNAME) + return ((flags & FNM_LEADING_DIR) || + strchr(string, '/') == NULL ? + 0 : FNM_NOMATCH); + else + return (0); + } else if (c == '/' && (flags & FNM_PATHNAME)) { + if ((string = strchr(string, '/')) == NULL) + return (FNM_NOMATCH); + break; + } + + /* General case, use recursion. */ + while ((test = *string) != EOS) { + if (!p_fnmatch(pattern, string, flags & ~FNM_PERIOD)) + return (0); + if (test == '/' && (flags & FNM_PATHNAME)) + break; + ++string; + } + return (FNM_NOMATCH); + case '[': + if (*string == EOS) + return (FNM_NOMATCH); + if (*string == '/' && (flags & FNM_PATHNAME)) + return (FNM_NOMATCH); + if (*string == '.' && (flags & FNM_PERIOD) && + (string == stringstart || + ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) + return (FNM_NOMATCH); + + switch (rangematch(pattern, *string, flags, &newp)) { + case RANGE_ERROR: + /* not a good range, treat as normal text */ + goto normal; + case RANGE_MATCH: + pattern = newp; + break; + case RANGE_NOMATCH: + return (FNM_NOMATCH); + } + ++string; + break; + case '\\': + if (!(flags & FNM_NOESCAPE)) { + if ((c = *pattern++) == EOS) { + c = '\\'; + --pattern; + } + } + /* FALLTHROUGH */ + default: + normal: + if (c != *string && !((flags & FNM_CASEFOLD) && + (tolower((unsigned char)c) == + tolower((unsigned char)*string)))) + return (FNM_NOMATCH); + ++string; + break; + } + /* NOTREACHED */ } static int rangematch(const char *pattern, char test, int flags, char **newp) { - int negate, ok; - char c, c2; - - /* - * A bracket expression starting with an unquoted circumflex - * character produces unspecified results (IEEE 1003.2-1992, - * 3.13.2). This implementation treats it like '!', for - * consistency with the regular expression syntax. - * J.T. Conklin (conklin@ngai.kaleida.com) - */ - if ((negate = (*pattern == '!' || *pattern == '^')) != 0) - ++pattern; - - if (flags & FNM_CASEFOLD) - test = (char)tolower((unsigned char)test); - - /* - * A right bracket shall lose its special meaning and represent - * itself in a bracket expression if it occurs first in the list. - * -- POSIX.2 2.8.3.2 - */ - ok = 0; - c = *pattern++; - do { - if (c == '\\' && !(flags & FNM_NOESCAPE)) - c = *pattern++; - if (c == EOS) - return (RANGE_ERROR); - if (c == '/' && (flags & FNM_PATHNAME)) - return (RANGE_NOMATCH); - if ((flags & FNM_CASEFOLD)) - c = (char)tolower((unsigned char)c); - if (*pattern == '-' - && (c2 = *(pattern+1)) != EOS && c2 != ']') { - pattern += 2; - if (c2 == '\\' && !(flags & FNM_NOESCAPE)) - c2 = *pattern++; - if (c2 == EOS) - return (RANGE_ERROR); - if (flags & FNM_CASEFOLD) - c2 = (char)tolower((unsigned char)c2); - if (c <= test && test <= c2) - ok = 1; - } else if (c == test) - ok = 1; - } while ((c = *pattern++) != ']'); - - *newp = (char *)pattern; - return (ok == negate ? RANGE_NOMATCH : RANGE_MATCH); + int negate, ok; + char c, c2; + + /* + * A bracket expression starting with an unquoted circumflex + * character produces unspecified results (IEEE 1003.2-1992, + * 3.13.2). This implementation treats it like '!', for + * consistency with the regular expression syntax. + * J.T. Conklin (conklin@ngai.kaleida.com) + */ + if ((negate = (*pattern == '!' || *pattern == '^')) != 0) + ++pattern; + + if (flags & FNM_CASEFOLD) + test = (char)tolower((unsigned char)test); + + /* + * A right bracket shall lose its special meaning and represent + * itself in a bracket expression if it occurs first in the list. + * -- POSIX.2 2.8.3.2 + */ + ok = 0; + c = *pattern++; + do { + if (c == '\\' && !(flags & FNM_NOESCAPE)) + c = *pattern++; + if (c == EOS) + return (RANGE_ERROR); + if (c == '/' && (flags & FNM_PATHNAME)) + return (RANGE_NOMATCH); + if ((flags & FNM_CASEFOLD)) + c = (char)tolower((unsigned char)c); + if (*pattern == '-' + && (c2 = *(pattern+1)) != EOS && c2 != ']') { + pattern += 2; + if (c2 == '\\' && !(flags & FNM_NOESCAPE)) + c2 = *pattern++; + if (c2 == EOS) + return (RANGE_ERROR); + if (flags & FNM_CASEFOLD) + c2 = (char)tolower((unsigned char)c2); + if (c <= test && test <= c2) + ok = 1; + } else if (c == test) + ok = 1; + } while ((c = *pattern++) != ']'); + + *newp = (char *)pattern; + return (ok == negate ? RANGE_NOMATCH : RANGE_MATCH); } diff --git a/src/win32/fnmatch.h b/src/win32/fnmatch.h index 1309c6e9a..1caac37fe 100644 --- a/src/win32/fnmatch.h +++ b/src/win32/fnmatch.h @@ -1,46 +1,25 @@ /* - * Copyright (C) 2008 The Android Open Source Project - * All rights reserved. + * Copyright (C) 2009-2011 the libgit2 contributors * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef INCLUDE_fnmatch__w32_h__ #define INCLUDE_fnmatch__w32_h__ #include "common.h" -#define FNM_NOMATCH 1 /* Match failed. */ -#define FNM_NOSYS 2 /* Function not supported (unused). */ +#define FNM_NOMATCH 1 /* Match failed. */ +#define FNM_NOSYS 2 /* Function not supported (unused). */ -#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */ -#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */ -#define FNM_PERIOD 0x04 /* Period must be matched by period. */ -#define FNM_LEADING_DIR 0x08 /* Ignore /<tail> after Imatch. */ -#define FNM_CASEFOLD 0x10 /* Case insensitive search. */ +#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */ +#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */ +#define FNM_PERIOD 0x04 /* Period must be matched by period. */ +#define FNM_LEADING_DIR 0x08 /* Ignore /<tail> after Imatch. */ +#define FNM_CASEFOLD 0x10 /* Case insensitive search. */ -#define FNM_IGNORECASE FNM_CASEFOLD -#define FNM_FILE_NAME FNM_PATHNAME +#define FNM_IGNORECASE FNM_CASEFOLD +#define FNM_FILE_NAME FNM_PATHNAME extern int p_fnmatch(const char *pattern, const char *string, int flags); diff --git a/src/win32/map.c b/src/win32/map.c index 76b926490..3e6b3d878 100644 --- a/src/win32/map.c +++ b/src/win32/map.c @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #include "map.h" #include <errno.h> @@ -23,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 view_prot = 0; DWORD off_low = 0; - DWORD off_hi = 0; + DWORD off_hi = 0; git_off_t page_start; git_off_t page_offset; @@ -65,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_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; return git__throw(GIT_ERROR, "Failed to mmap. Offset must be multiple of page size"); } diff --git a/src/win32/mingw-compat.h b/src/win32/mingw-compat.h index 64d780b16..7207d882f 100644 --- a/src/win32/mingw-compat.h +++ b/src/win32/mingw-compat.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_mingw_compat__ #define INCLUDE_mingw_compat__ @@ -11,7 +17,7 @@ /* stat: file mode type testing macros */ # define _S_IFLNK 0120000 # define S_IFLNK _S_IFLNK -# define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK) +# define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK) #endif diff --git a/src/win32/msvc-compat.h b/src/win32/msvc-compat.h index df3e62d11..64ed18476 100644 --- a/src/win32/msvc-compat.h +++ b/src/win32/msvc-compat.h @@ -1,12 +1,18 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_msvc_compat__ #define INCLUDE_msvc_compat__ #if defined(_MSC_VER) -/* access() mode parameter #defines */ -# define F_OK 0 /* existence check */ -# define W_OK 2 /* write mode check */ -# define R_OK 4 /* read mode check */ +/* access() mode parameter #defines */ +# define F_OK 0 /* existence check */ +# define W_OK 2 /* write mode check */ +# define R_OK 4 /* read mode check */ # define lseek _lseeki64 # define stat _stat64 @@ -16,16 +22,16 @@ # define _S_IFLNK 0120000 # define S_IFLNK _S_IFLNK -# define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) -# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) -# define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO) -# define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK) +# define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) +# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) +# define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO) +# define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK) # define mode_t unsigned short /* case-insensitive string comparison */ -# define strcasecmp _stricmp -# define strncasecmp _strnicmp +# define strcasecmp _stricmp +# define strncasecmp _strnicmp #if (_MSC_VER >= 1600) # include <stdint.h> diff --git a/src/win32/posix.c b/src/win32/posix.c index 2d7b8390d..38e505e20 100644 --- a/src/win32/posix.c +++ b/src/win32/posix.c @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #include "posix.h" #include "path.h" #include <errno.h> @@ -138,13 +144,13 @@ int p_readlink(const char *link, char *target, size_t target_len) "'GetFinalPathNameByHandleA' is not available in this platform"); } - hFile = CreateFile(link, // file to open - GENERIC_READ, // open for reading - FILE_SHARE_READ, // share for reading - NULL, // default security - OPEN_EXISTING, // existing file only + hFile = CreateFile(link, // file to open + GENERIC_READ, // open for reading + FILE_SHARE_READ, // share for reading + NULL, // default security + OPEN_EXISTING, // existing file only FILE_FLAG_BACKUP_SEMANTICS, // normal file - NULL); // no attr. template + NULL); // no attr. template if (hFile == INVALID_HANDLE_VALUE) return GIT_EOSERR; @@ -157,7 +163,7 @@ int p_readlink(const char *link, char *target, size_t target_len) if (dwRet > 4) { /* 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]; unsigned int offset = 4; dwRet -= 4; @@ -183,7 +189,7 @@ int p_hide_directory__w32(const char *path) int error; 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) error = git__throw(GIT_EOSERR, "Failed to hide directory '%s'", path); @@ -236,16 +242,13 @@ extern int p_creat(const char *path, int mode); int p_mkstemp(char *tmp_path) { - int r; - #if defined(_MSC_VER) - r = _mktemp_s(tmp_path, GIT_PATH_MAX); + if (_mktemp_s(tmp_path, GIT_PATH_MAX) != 0) + return GIT_EOSERR; #else - r = _mktemp(tmp_path); -#endif - - if (r != 0) + if (_mktemp(tmp_path) == NULL) return GIT_EOSERR; +#endif return p_creat(tmp_path, 0744); } diff --git a/src/win32/posix.h b/src/win32/posix.h index 28d978959..db4ec19ec 100644 --- a/src/win32/posix.h +++ b/src/win32/posix.h @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2009-2011 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ #ifndef INCLUDE_posix__w32_h__ #define INCLUDE_posix__w32_h__ diff --git a/src/win32/pthread.c b/src/win32/pthread.c index 41cf5b35b..e0f6c14a8 100644 --- a/src/win32/pthread.c +++ b/src/win32/pthread.c @@ -1,35 +1,15 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Original code by Ramiro Polla (Public Domain) + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #include "pthread.h" int pthread_create(pthread_t *GIT_RESTRICT thread, - const pthread_attr_t *GIT_RESTRICT GIT_UNUSED(attr), - void *(*start_routine)(void*), void *GIT_RESTRICT arg) + const pthread_attr_t *GIT_RESTRICT GIT_UNUSED(attr), + void *(*start_routine)(void*), void *GIT_RESTRICT arg) { GIT_UNUSED_ARG(attr); *thread = (pthread_t) CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)start_routine, arg, 0, NULL); @@ -38,48 +18,48 @@ int pthread_create(pthread_t *GIT_RESTRICT thread, int pthread_join(pthread_t thread, void **value_ptr) { - int ret; - ret = WaitForSingleObject(thread, INFINITE); - if (ret && value_ptr) - GetExitCodeThread(thread, (void*) value_ptr); - return -(!!ret); + int ret; + ret = WaitForSingleObject(thread, INFINITE); + if (ret && value_ptr) + GetExitCodeThread(thread, (void*) value_ptr); + return -(!!ret); } 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); - InitializeCriticalSection(mutex); - return 0; + GIT_UNUSED_ARG(mutexattr); + InitializeCriticalSection(mutex); + return 0; } int pthread_mutex_destroy(pthread_mutex_t *mutex) { - DeleteCriticalSection(mutex); - return 0; + DeleteCriticalSection(mutex); + return 0; } int pthread_mutex_lock(pthread_mutex_t *mutex) { - EnterCriticalSection(mutex); - return 0; + EnterCriticalSection(mutex); + return 0; } int pthread_mutex_unlock(pthread_mutex_t *mutex) { - LeaveCriticalSection(mutex); - return 0; + LeaveCriticalSection(mutex); + return 0; } int pthread_num_processors_np(void) { - DWORD_PTR p, s; - int n = 0; + DWORD_PTR p, s; + int n = 0; - if (GetProcessAffinityMask(GetCurrentProcess(), &p, &s)) - for (; p; p >>= 1) - n += p&1; + if (GetProcessAffinityMask(GetCurrentProcess(), &p, &s)) + for (; p; p >>= 1) + n += p&1; - return n ? n : 1; + return n ? n : 1; } diff --git a/src/win32/pthread.h b/src/win32/pthread.h index 10949f1eb..3ea8c7ac1 100644 --- a/src/win32/pthread.h +++ b/src/win32/pthread.h @@ -1,28 +1,8 @@ /* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. + * Copyright (C) 2009-2011 the libgit2 contributors * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Original code by Ramiro Polla (Public Domain) + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. */ #ifndef GIT_PTHREAD_H @@ -45,8 +25,8 @@ typedef HANDLE pthread_t; #define PTHREAD_MUTEX_INITIALIZER {(void*)-1}; int pthread_create(pthread_t *GIT_RESTRICT, - const pthread_attr_t *GIT_RESTRICT, - void *(*start_routine)(void*), void *__restrict); + const pthread_attr_t *GIT_RESTRICT, + void *(*start_routine)(void*), void *__restrict); int pthread_join(pthread_t, void **); diff --git a/tests-clay/clay b/tests-clay/clay new file mode 100755 index 000000000..a45205e9f --- /dev/null +++ b/tests-clay/clay @@ -0,0 +1,228 @@ +#!/usr/bin/env python + +from __future__ import with_statement +from string import Template +import re, fnmatch, os + +VERSION = "0.7.0" + +TEST_FUNC_REGEX = r"^(void\s+(test_%s__(\w+))\(\s*(void)?\s*\))\s*\{" + +TEMPLATE_MAIN = Template( +r""" +/* + * Clay v${version} + * + * This is an autogenerated file. Do not modify. + * To add new unit tests or suites, regenerate the whole + * file with `./clay` + */ + +#define clay_print(...) ${clay_print} + +${clay_library} + +${extern_declarations} + +static const struct clay_func _all_callbacks[] = { + ${test_callbacks} +}; + +static const struct clay_suite _all_suites[] = { + ${test_suites} +}; + +static const char _suites_str[] = "${suites_str}"; + +int _CC main(int argc, char *argv[]) +{ + return clay_test( + argc, argv, _suites_str, + _all_callbacks, ${cb_count}, + _all_suites, ${suite_count} + ); +} +""") + +TEMPLATE_SUITE = Template( +r""" + { + "${clean_name}", + ${initialize}, + ${cleanup}, + ${cb_ptr}, ${cb_count} + } +""") + +def main(): + from optparse import OptionParser + + parser = OptionParser() + + parser.add_option('-c', '--clay-path', dest='clay_path') + parser.add_option('-o', '--output', dest='output') + parser.add_option('-v', '--report-to', dest='print_mode', default='stdout') + + options, args = parser.parse_args() + + for folder in args: + builder = ClayTestBuilder(folder, + clay_path = options.clay_path, + output_folder = options.output, + print_mode = options.print_mode) + + builder.render() + + +class ClayTestBuilder: + def __init__(self, folder_name, output_folder = None, clay_path = None, print_mode = 'stdout'): + self.declarations = [] + self.callbacks = [] + self.suites = [] + self.suite_list = [] + + self.clay_path = os.path.abspath(clay_path) if clay_path else None + self.print_mode = print_mode + + folder_name = os.path.abspath(folder_name) + if not output_folder: + output_folder = folder_name + + self.output = os.path.join(output_folder, "clay_main.c") + self.output_header = os.path.join(output_folder, "clay.h") + + self.modules = ["clay.c", "clay_sandbox.c", "clay_fixtures.c", "clay_fs.c"] + + print("Loading test suites...") + + for root, dirs, files in os.walk(folder_name): + module_root = root[len(folder_name):] + module_root = [c for c in module_root.split(os.sep) if c] + + tests_in_module = fnmatch.filter(files, "*.c") + + for test_file in tests_in_module: + full_path = os.path.join(root, test_file) + test_name = "_".join(module_root + [test_file[:-2]]) + + with open(full_path) as f: + self._process_test_file(test_name, f.read()) + + if not self.suites: + raise RuntimeError( + 'No tests found under "%s"' % folder_name) + + def render(self): + template = TEMPLATE_MAIN.substitute( + version = VERSION, + clay_print = self._get_print_method(), + clay_library = self._get_library(), + extern_declarations = "\n".join(self.declarations), + + suites_str = ", ".join(self.suite_list), + + test_callbacks = ",\n\t".join(self.callbacks), + cb_count = len(self.callbacks), + + test_suites = ",\n\t".join(self.suites), + suite_count = len(self.suites), + ) + + with open(self.output, "w") as out: + out.write(template) + + with open(self.output_header, "w") as out: + out.write(self._load_file('clay.h')) + + print ('Written test suite to "%s"' % self.output) + print ('Written header to "%s"' % self.output_header) + + ##################################################### + # Internal methods + ##################################################### + def _get_print_method(self): + return { + 'stdout' : 'printf(__VA_ARGS__)', + 'stderr' : 'fprintf(stderr, __VA_ARGS__)', + 'silent' : '' + }[self.print_mode] + + def _load_file(self, filename): + if self.clay_path: + filename = os.path.join(self.clay_path, filename) + with open(filename) as cfile: + return cfile.read() + + else: + import zlib, base64, sys + content = CLAY_FILES[filename] + + if sys.version_info >= (3, 0): + content = bytearray(content, 'utf_8') + content = base64.b64decode(content) + content = zlib.decompress(content) + return str(content) + else: + content = base64.b64decode(content) + return zlib.decompress(content) + + def _get_library(self): + return "\n".join(self._load_file(f) for f in self.modules) + + def _parse_comment(self, comment): + comment = comment[2:-2] + comment = comment.splitlines() + comment = [line.strip() for line in comment] + comment = "\n".join(comment) + + return comment + + def _process_test_file(self, test_name, contents): + regex_string = TEST_FUNC_REGEX % test_name + regex = re.compile(regex_string, re.MULTILINE) + + callbacks = [] + initialize = cleanup = "{NULL, NULL, 0}" + + for (declaration, symbol, short_name, _) in regex.findall(contents): + self.declarations.append("extern %s;" % declaration) + func_ptr = '{"%s", &%s, %d}' % ( + short_name, symbol, len(self.suites) + ) + + if short_name == 'initialize': + initialize = func_ptr + elif short_name == 'cleanup': + cleanup = func_ptr + else: + callbacks.append(func_ptr) + + if not callbacks: + return + + clean_name = test_name.replace("_", "::") + + suite = TEMPLATE_SUITE.substitute( + clean_name = clean_name, + initialize = initialize, + cleanup = cleanup, + cb_ptr = "&_all_callbacks[%d]" % len(self.callbacks), + cb_count = len(callbacks) + ).strip() + + self.callbacks += callbacks + self.suites.append(suite) + self.suite_list.append(clean_name) + + print(" %s (%d tests)" % (clean_name, len(callbacks))) + +CLAY_FILES = { +"clay.c" : r"""eJy9GF1v2zbwWf4VrIPEUqK4SfdmLxmGbgWKFS3QpGiBJBBoiY61yqIrUk2yLf99d/wS9eXtYdiTrePd8b7veAd5mRZ1xsiPVAhWyfnmcnLgYILJ37e7DkxmRb7qwXLeBVV5ed+GbancIGTy8phU7FudVywja14RQctsxR+BgBy/9Jk8iZfyacdEhzeAhaRKWACvM7Ymyee37394NTkIHNZDXmb8QZM2UCNnAxAbVhR0l3fAGQiXanMEu4rebylJ+XbLShmC+jGZKrofXk0jECEACfKSkeT1a5IkacbSwoOiqOEOdI/hb0SS9neDt/0Kl5qDLc8YoDYgDy/dOCBJvI8Gg6YpE6LNqg/zJayyehfCjxLPfbQwynT3FEoek3XFtzGRPBH5H8DZHCVCHRqwxUquP356//rn6199M31OPvxGzl41gKvk7dUvbz+GjxEJw0dyRBKAvAFIRF5ckLNoEmAUoJvhsjqV2obk6vrn6+R6OTlghWC+8+oyh5DUzmtc0+PSYVJm+XrShNk0LejTfDOdTBAvT8l3nkO4iqTahikvhQRH0IocJ4LXVcqiZRcv5WCwAcyY+MCMQRAs3SX+0WSdP8q6Ygk6rcVpRUWHjUUt6ZZpdkpF1CFhVQVJ9uck8Akk3LucgM0kwb9JWW9XrFq2kUSdS9aBrfOCGcICLDtMqK5MtuIe4VbPtMp3MucliBf05Tsu2SNI9NzYwuB0BKepzL+zxMg/cGKE1iKqD32DsOpySQsH8kyQ8rqUI8I5DgNnBQVi9R+JlfvD44KncEtaMFrWuyhU0GPwjD5vH4ODnwpOMySHgpus6jWRFd3uOFrYiu0ACSvpqmCA/gwFAATp+Htdl2nXahgXSyfcDpJbiYQCYb4m1lKl9UDDTh2M8Otdm5e5zGkBLIdOjb7Obz0EFZaiEcr3C8oFneMNFBYjmG4b8xS7hp986rQuzblV1GCgLX1ye+xzmCiEqi5VmIX7xY3Hjxtr7EGyMTL5Uzta5w6gXmjvztsxPAk0tB8PQHCuAnpNQt26wy5qRC6woKI3FVoj4OklBAWW2/ef3r2Digvn7bMQbRQEqLH7Dp73i3NmxdE4raD37xo4HiKxeRJZtgbek92Ha7mNkC6cTk4QqgaRLf8OLbN8IuquU7CcjVOyZXLDM4HxNSQj0TcuBw+tsA4JIgCdvoPBSIbTw3QaW7v4DiaXLgAi8hOZvZmRBZnNZ6DF80CMKm6aNMTggWpsG8NYFVOB5otCyGEWkTc0L6CDLG5LEAzYRD2JxWJxKEh4KCJyAx+H2R25OZXwgyRgdcX99FJp432bHAmmJSdeF/BJsKd4n15f6fAx0J5soIJQghtc139cqJgDT4B2wIzz8kh69wLeiGMqtuOV8YzQNcYmeK4TdbTNxLYXTrTqrhC4JvSwAYMZnZwaKqmREPCN6JqNr54NlZMTox9mcbCuGBuwUOdMfVqJDOvnYeWhcqowCPuhqNuJHi10KO6prXCRQtTe9xpD3iS13/YbfNOgBhLMlCV8eIS5+gKP/OjfYzoOOTnJtVVbFxm58Ocmv5ubi4J2yzgyxzE5Moy9XuBgtvTvNyS8i4ohS/5DC+oZeswW/96OfQtYhElHfyXVv9R9SPFa0HvWmnlpda+0UGG8DqefEGMBuUpuuIpWAXVI5S1iLhvED/p0oXPVgQk5lV++3Mpb+bEuCS+LJyI3TClFdJUhcNyjEQM02mRdIvaYy/D0fKxw00qwBEQVoa4K8DeNja6o7Pd9IwMtihVNv4rYJUS60lH7j6Hg0ehQUGRNcWrlxrnODZTNSwfnkBofxICG4kKwL+0ZxgnO+UFgepIaHbAMW6KbszssXLPTmZo1PJ8rXmd3etrQjPQNmu5c3QIsMURlJXnheJIT8griy37G5Pwschc34uK1t2cz8tdfKBlod7ZXBPGQy3QDkitRjAHg/UVmcrZQcxJwD7VFI2R4eeGcobGhhpoAglcpJF5MptdelB1mJONMkJLD7PcIL9e514KRugkk+MCJq92vriStJIxboW7QkenGILly940LlhtgeWfyv9SFSyN2MOwbMvCKmilCR21Um82jl2iZVxWjXxVDbTgxajg/Isdsd+Vn239qvGNlO2JU8m3RMoVqbEceVlfLjK1pXcjFaFihJK2KD7LosmDeG/sLgvc4F7iv+f8rhW/CdzDkggXBE5pqYecnHEgjj9JaFkX2RnjvKRapbFSO77gdTTnFERVuktxuDJuKDY4pWYXOV5iYX7hOfMiLguwqnjKgg0Te8Fp668a5KdXPRhg0OQzg5ybLO3VaO8R4wsuauDGp0TBuGQxVfSa4pFJsmwlmMBS1SGiBoQGlN5rs8SGQ2ijVtbkbw6IJxe5YawwzMMo2M3DzwkbUism6Ks2k2t6xAPum8SV602yCHKTPciyscX/LFDdbpnhkvdSBe7OrIRbg8SJL6Ao0UJE7NnS7eLQCYVPQOvmDODqdp+E5eBjcyDE+O/yiqP3otZNW97XrJrDW9eYh6TZKA69kd6bne59Dj9o7815R7kHR3qX131kO0d/DtN55XVZ2Y+g97ADF7Az7zzs4Myuu7sPNiq6XiNo4I4+3gafdhd1pdx9v/RkYNwFBP2r1gkCtUvwQcpuTF2NrD5OWA/ULCxhcoPVaENpZM5CK5gLKFC2hk6VMyTyf6t7idzHVxApe3g8teGKisZ5t0sEliWDSrVXMBrC7mIz15uyY7+i32n8udBcezQpv/85DM8Lc/xst5aw7""", +"clay_sandbox.c" : r"""eJyNVe9v2jAQ/Zz8FVcqlaTQkm7Vpon1w6R2ExorCKhaqUVRmjjFauIg27DRiv99ZzuQH9BuCIkod7577909I2QgaQjhLODgh0mw8ueBnN2fe18+Tbu2LUyYMmlT4S+DhEa+TOc6yQkzJqQ5eqxeuParbY0n3yb+BITE0xaNwVElHBVuw5GQLhxcgOfalsWJXHAG3ibvYOz3xpe9ER44FdJPs4i49bz82QnCkAiRV731Bz9duFBlu/a6gjmmrIxXI31cxDHhbRD0hfgSEsKecuj5QUMrDy8D7ofZgkm4gPNuLccUJGyJynBxP8UcLGM1Jr+GSKTRBvWkf67M7834ajQcDb73+lcNG6w1cjqkcURi8G971x8/GCV+EDkh6XyoMDuXt4PRpWtQtsGAr+lySBJBsFwOmSql4oyDQxGQ1wUKXwseXWi1qKtx1khg8hOR+OBsGdEpSmqZ8eBL1VadkpQtiOqiI7uLoVJNC9SLs3C+cjaqY6i90VyVLtGwrLWNX9vqHEMvBjkjKpvyjKUE9Y8yIlgTBxOsIGArOaPsqQ2Sr0BmsBAEOtgfjjv2G6AaKt7IcdVhmWAFWQnYGiVmEY0NtsmMChArIUm6BZXQZ4IgKngUgXDBuQZPOQllhsF3AJ6+ie70HWhbV5ycldd/mdEItKEXTAQsesz+OOqd3nQFoOR2b6rs03zwmsVi7a5mOEMWiBJhdgtBYuHztFSs7kFcWZpEfg7BMN3iKG2gCvgyoIm2UUPXU9Lc6U9DWW9r2M2VUbV3gcGYO4vLsFw0QfneUWrZFhbDbqg3PlRJ1Nm/Ao6eZTzFob0QDVcNejgY9+4A3fY74BGIJBAzIvSQS3a0duyoSBRGrM+D5vN40POwrFoImp3m1i7bQdRqKGYncDZV9y3mm0bVeKtVFFN7tFm7IgtaCmm7GM4+ZbENJu2RTCNKn9Enc1/8czy1/wU1H3Ox6TqmTKUtSnR90+/vnMn1KExS3Udd4f8dAUdH+1Z4/zoZpMomZbbeZ8/by88cML4qM9ubWuHzF4WiW5U=""", +"clay_fixtures.c" : r"""eJyFUV1LwzAUfW5+xZU9rLUVJ4ggZQ9DFAUfRCZMRglZmrBAl5Qkk03xv9v0a82U+Zabc+45595rLLGCAlXSWKBrouEccbGzW81wSew6HCIrYljicTuqJBsWoS8UmFbPobXA8npye5OlFSI+GbaglbK4YDJFKOjeMAVjdfUInUPkyFZLWu7DWiKBxtgpKN78RZETEByactlLXcBVBmdTGF+OIxQEPhrHGdRQ1zzMv5xUYN84ROLY8b1MEPeTJEdsV3tRq0wdt06tWcWVzXpS9I3QSPCccbh7nr3jh6fF/O31Hr/M5o9ouGpa4NYlPHmBVt074i/lBLy+OsWHEjkcXLAhMl+p3Wk3bjBV1VIG6TxOApgWZN8s4k8bWjAit+W/NnoTejMddI+GqW1GTOaCox8pOffr""", +"clay_fs.c" : r"""eJylVdtu20YQfSa/YkAD8TKWY8dJX6L0wXDEVqgsBhINN7UFhiGX1qIkl9hd+dLG/57ZCynJUWEkfZE0s7NnZufMGe2xsqAlpJfj6ZsT399DgzUUojhKo8npb3Mg+ud8PBlNE/hq/NP4LJ5G49n5aTKOp71zNJvFs4vx06DzPz6MZ6HvS5UplkO+zAS89EtWUd7KtM3UkuS8kcqdGE/o/+t71tYm/ArTi8lk6HuS/UNTBRVtbtRyAGzo+x4rgaQ2zMaFvucJqlaicdd8z15AHKkE/rbxIQI6+DqrKp4TF3YAJ2GH/AxwTeu8fTBRA0jtl0Xp0K+sucAsx9suzPPauX2v5AIIMxYweO9AhnBwwELAbvTFXLGFrmf/aF+X4/Uu2L++3scEjwjmitRnQ/+x7/0tZ0XXecIaBTUv6AC22i/5SuRPnQWVynAy/z3CSYg/zpPZxVkCJQLp4m2YvYqVbJHrEHU7bJgG+y7IZNBQf1HBz2nNxQN5oeEHoDnnJdlOHYa2aa18dRetmlxziI8ZOl8bCV5ruk3u3ptw9OlUnaeMquxGorOfd/OcKs2kpEKlBFuMibHUuKUCm8gbW1aoOTge4HFwyZqC30l4EgdlhmYR+J4tVVBK1q0wpnv0U4JkKmqygxTDQEdfFKcfRpNRMsKx6zgzM7oLL+c4oz9A80aSs/jjp40U6bpmA46t0vgVzZpVS7TLApg3lOwe55A6ivMqe3AKCV4GoQXZo5WkXbk4kr5c0qpK+UoRW5SrMBM3t1cLg60HV19YSS0nVuA+wE/dY/zSg8XF32StX/S9h2OrobIVeLskUhVUCM2eF8wfpKI1oM3FO/hsb3+GHDeCo/DVdRNozjx6zxQ5fB06lXXwehIsPr2n+S0xtR4vBqboLvguYwqD9YUBvLD1D/DesFfr5ejPcTJPTpOLObHn/4PLnkprmpJ+WQy3pbpeqNZOcenovvVCxm1ZIK0bEl4Hrpdpf2pbYs2rjchDs+f6nfVfAXYRuu6hGRx9Yc1R3gZD5zVBweGsd5wsNjVuXG+0y81O6KRuDt4u+r8Ro/B6JRWOo5RG5OuxM6QZYUeGfVAcdM9B6b3lRlpqr8ya4gu/363wZ0W9oekNjt4udvVA1N/1oNxuQvfiHc342TdbTYNa0u2XPiN9I/NV464Qs/e1a8PxiLJvClb63wD3Q6FA""", +"clay.h" : r"""eJy9VF1v2jAUfW5+xR15IVFU2GvXVkIVqEiomjaqbU+WcW6KtWBntrOyfz/bCR8JpFn3wBPmxsfn3HuOHfJMpJgBIQ+LyQ+ynH5dkkdCgtAWucCTehBywfIyRbjVJs356np9HwS/JU+B5fQPIVRrVGYYXHFhgEmRcsOlSIIru9a2sqYK4oznmFRbcsvS+opKSdWqpaiZ4kV9lgPqtSzzlNCVVCb6tNdANBrCcqSiLIa+Nozrv1H1P44SqBayoL9KtOAdNtMNqDs25Jmbj5/CbP59+fxlSj5Plo/BsToH5VtTKhw22/Q1IuimwVKXNRXpSm7fA9mpewMSop15FgSjOA4ghon3w44NNpQpqeGVmzXgtsg54wb8rGGDWtMXtPtHe+ct66bUhhTWUTK0AJWAcyFqGu2/RHB/B+PEpmU2X0wJcavF/MmvBrNSMC+A0TyHjFrv0xsYQHg4M4GP0Qmx29lPfNvJO90WyAymkDUEGOk19CioSPrpP3T3bfmVnasj5hqENGBUied4d149rJH9/A+fmMNdyKhxdMp8YafOSbiAUeOo51IJ+Y/XqZbUvGFVMYGn58Xi/GVowaqpd8Lq9veYXaKbgO7o9XVzCN2B4ziIncIOmWkDezrym9qYdj+7hmZSMZcoe6R9HEevVAkuXtpNeBVnQtMVlSXaZ7e6GdeD8y9HzfSeU79VEEhL5X6MI8EtstJF7GZwHMD6df8LLiKMPg==""" +} + +if __name__ == '__main__': + main() diff --git a/tests-clay/clay.h b/tests-clay/clay.h new file mode 100644 index 000000000..db6f05425 --- /dev/null +++ b/tests-clay/clay.h @@ -0,0 +1,58 @@ +#ifndef __CLAY_TEST_H__ +#define __CLAY_TEST_H__ + +#include <stdlib.h> + +void clay__assert( + int condition, + const char *file, + int line, + const char *error, + const char *description, + int should_abort); + +void cl_set_cleanup(void (*cleanup)(void *), void *opaque); +void cl_fs_cleanup(void); + +#ifdef CLAY_FIXTURE_PATH +const char *cl_fixture(const char *fixture_name); +void cl_fixture_sandbox(const char *fixture_name); +void cl_fixture_cleanup(const char *fixture_name); +#endif + +/** + * Assertion macros with explicit error message + */ +#define cl_must_pass_(expr, desc) clay__assert((expr) >= 0, __FILE__, __LINE__, "Function call failed: " #expr, desc, 1) +#define cl_must_fail_(expr, desc) clay__assert((expr) < 0, __FILE__, __LINE__, "Expected function call to fail: " #expr, desc, 1) +#define cl_assert_(expr, desc) clay__assert((expr) != 0, __FILE__, __LINE__, "Expression is not true: " #expr, desc, 1) + +/** + * Check macros with explicit error message + */ +#define cl_check_pass_(expr, desc) clay__assert((expr) >= 0, __FILE__, __LINE__, "Function call failed: " #expr, desc, 0) +#define cl_check_fail_(expr, desc) clay__assert((expr) < 0, __FILE__, __LINE__, "Expected function call to fail: " #expr, desc, 0) +#define cl_check_(expr, desc) clay__assert((expr) != 0, __FILE__, __LINE__, "Expression is not true: " #expr, desc, 0) + +/** + * Assertion macros with no error message + */ +#define cl_must_pass(expr) cl_must_pass_((expr), NULL) +#define cl_must_fail(expr) cl_must_fail_((expr), NULL) +#define cl_assert(expr) cl_assert_((expr), NULL) + +/** + * Check macros with no error message + */ +#define cl_check_pass(expr) cl_check_pass_((expr), NULL) +#define cl_check_fail(expr) cl_check_fail_((expr), NULL) +#define cl_check(expr) cl_check_((expr), NULL) + + +/** + * Forced failure/warning + */ +#define cl_fail(desc) clay__assert(0, __FILE__, __LINE__, "Test failed.", desc, 1) +#define cl_warning(desc) clay__assert(0, __FILE__, __LINE__, "Warning during test execution:", desc, 0) + +#endif diff --git a/tests-clay/clay_libgit2.h b/tests-clay/clay_libgit2.h new file mode 100644 index 000000000..ab3cf67ec --- /dev/null +++ b/tests-clay/clay_libgit2.h @@ -0,0 +1,28 @@ +#ifndef __CLAY_LIBGIT2__ +#define __CLAY_LIBGIT2__ + +#include "clay.h" +#include <git2.h> +#include "common.h" + +/** + * Special wrapper for `clay_must_pass` that passes + * the last library error as the test failure message. + * + * Use this wrapper around all `git_` library calls that + * return error codes! + */ +#define cl_git_pass(expr) do { \ + git_clearerror(); \ + if ((expr) != GIT_SUCCESS) \ + clay__assert(0, __FILE__, __LINE__, "Function call failed: " #expr, git_lasterror(), 1); \ + } while(0); + +/** + * Wrapper for `clay_must_fail` -- this one is + * just for consistency. Use with `git_` library + * calls that are supposed to fail! + */ +#define cl_git_fail(expr) cl_must_fail((expr)) + +#endif diff --git a/tests-clay/clay_main.c b/tests-clay/clay_main.c new file mode 100644 index 000000000..b536b6a97 --- /dev/null +++ b/tests-clay/clay_main.c @@ -0,0 +1,779 @@ + +/* + * Clay v0.7.0 + * + * This is an autogenerated file. Do not modify. + * To add new unit tests or suites, regenerate the whole + * file with `./clay` + */ + +#define clay_print(...) printf(__VA_ARGS__) + +#include <assert.h> +#include <setjmp.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <math.h> + +/* required for sandboxing */ +#include <sys/types.h> +#include <sys/stat.h> + +#ifdef _WIN32 +# include <windows.h> +# include <io.h> +# include <shellapi.h> +# include <direct.h> +# pragma comment(lib, "shell32") + +# define _CC __cdecl + +# define stat(path, st) _stat(path, st) +# define mkdir(path, mode) _mkdir(path) +# define chdir(path) _chdir(path) +# define access(path, mode) _access(path, mode) +# define strdup(str) _strdup(str) +# define strncpy(to, from, to_size) strncpy_s(to, to_size, from, _TRUNCATE) + +# define W_OK 02 +# define S_ISDIR(x) ((x & _S_IFDIR) != 0) + typedef struct _stat STAT_T; +#else +# include <unistd.h> +# define _CC + typedef struct stat STAT_T; +#endif + +#include "clay.h" + +static void fs_rm(const char *_source); +static void fs_copy(const char *_source, const char *dest); + +static const char * +fixture_path(const char *base, const char *fixture_name); + +struct clay_error { + const char *test; + int test_number; + const char *suite; + const char *file; + int line_number; + const char *error_msg; + char *description; + + struct clay_error *next; +}; + +static struct { + const char *active_test; + const char *active_suite; + + int suite_errors; + int total_errors; + + int test_count; + + struct clay_error *errors; + struct clay_error *last_error; + + void (*local_cleanup)(void *); + void *local_cleanup_payload; + + jmp_buf trampoline; + int trampoline_enabled; +} _clay; + +struct clay_func { + const char *name; + void (*ptr)(void); + size_t suite_n; +}; + +struct clay_suite { + const char *name; + struct clay_func initialize; + struct clay_func cleanup; + const struct clay_func *tests; + size_t test_count; +}; + +/* From clay_sandbox.c */ +static void clay_unsandbox(void); +static int clay_sandbox(void); + +static void +clay_run_test( + const struct clay_func *test, + const struct clay_func *initialize, + const struct clay_func *cleanup) +{ + int error_st = _clay.suite_errors; + + _clay.trampoline_enabled = 1; + + if (setjmp(_clay.trampoline) == 0) { + if (initialize->ptr != NULL) + initialize->ptr(); + + test->ptr(); + } + + _clay.trampoline_enabled = 0; + + if (_clay.local_cleanup != NULL) + _clay.local_cleanup(_clay.local_cleanup_payload); + + if (cleanup->ptr != NULL) + cleanup->ptr(); + + _clay.test_count++; + + /* remove any local-set cleanup methods */ + _clay.local_cleanup = NULL; + _clay.local_cleanup_payload = NULL; + + clay_print("%c", (_clay.suite_errors > error_st) ? 'F' : '.'); +} + +static void +clay_print_error(int num, const struct clay_error *error) +{ + clay_print(" %d) Failure:\n", num); + + clay_print("%s::%s (%s) [%s:%d] [-t%d]\n", + error->suite, + error->test, + "no description", + error->file, + error->line_number, + error->test_number); + + clay_print(" %s\n", error->error_msg); + + if (error->description != NULL) + clay_print(" %s\n", error->description); + + clay_print("\n"); +} + +static void +clay_report_errors(void) +{ + int i = 1; + struct clay_error *error, *next; + + error = _clay.errors; + while (error != NULL) { + next = error->next; + clay_print_error(i++, error); + free(error->description); + free(error); + error = next; + } +} + +static void +clay_run_suite(const struct clay_suite *suite) +{ + const struct clay_func *test = suite->tests; + size_t i; + + _clay.active_suite = suite->name; + _clay.suite_errors = 0; + + for (i = 0; i < suite->test_count; ++i) { + _clay.active_test = test[i].name; + clay_run_test(&test[i], &suite->initialize, &suite->cleanup); + } +} + +static void +clay_run_single(const struct clay_func *test, + const struct clay_suite *suite) +{ + _clay.suite_errors = 0; + _clay.active_suite = suite->name; + _clay.active_test = test->name; + + clay_run_test(test, &suite->initialize, &suite->cleanup); +} + +static void +clay_usage(const char *arg) +{ + printf("Usage: %s [options]\n\n", arg); + printf("Options:\n"); + printf(" -tXX\t\tRun only the test number XX\n"); + printf(" -sXX\t\tRun only the suite number XX\n"); + exit(-1); +} + +static void +clay_parse_args( + int argc, char **argv, + const struct clay_func *callbacks, + size_t cb_count, + const struct clay_suite *suites, + size_t suite_count) +{ + int i; + + for (i = 1; i < argc; ++i) { + char *argument = argv[i]; + char action; + int num; + + if (argument[0] != '-') + clay_usage(argv[0]); + + action = argument[1]; + num = strtol(argument + 2, &argument, 10); + + if (*argument != '\0' || num < 0) + clay_usage(argv[0]); + + switch (action) { + case 't': + if ((size_t)num >= cb_count) { + fprintf(stderr, "Test number %d does not exist.\n", num); + exit(-1); + } + + clay_print("Started (%s::%s)\n", + suites[callbacks[num].suite_n].name, + callbacks[num].name); + + clay_run_single(&callbacks[num], &suites[callbacks[num].suite_n]); + break; + + case 's': + if ((size_t)num >= suite_count) { + fprintf(stderr, "Suite number %d does not exist.\n", num); + exit(-1); + } + + clay_print("Started (%s::*)\n", suites[num].name); + clay_run_suite(&suites[num]); + break; + + default: + clay_usage(argv[0]); + } + } +} + +static int +clay_test( + int argc, char **argv, + const char *suites_str, + const struct clay_func *callbacks, + size_t cb_count, + const struct clay_suite *suites, + size_t suite_count) +{ + clay_print("Loaded %d suites: %s\n", (int)suite_count, suites_str); + + if (clay_sandbox() < 0) { + fprintf(stderr, + "Failed to sandbox the test runner.\n" + "Testing will proceed without sandboxing.\n"); + } + + if (argc > 1) { + clay_parse_args(argc, argv, + callbacks, cb_count, suites, suite_count); + + } else { + size_t i; + clay_print("Started\n"); + + for (i = 0; i < suite_count; ++i) { + const struct clay_suite *s = &suites[i]; + clay_run_suite(s); + } + } + + clay_print("\n\n"); + clay_report_errors(); + + clay_unsandbox(); + return _clay.total_errors; +} + +void +clay__assert( + int condition, + const char *file, + int line, + const char *error_msg, + const char *description, + int should_abort) +{ + struct clay_error *error; + + if (condition) + return; + + error = calloc(1, sizeof(struct clay_error)); + + if (_clay.errors == NULL) + _clay.errors = error; + + if (_clay.last_error != NULL) + _clay.last_error->next = error; + + _clay.last_error = error; + + error->test = _clay.active_test; + error->test_number = _clay.test_count; + error->suite = _clay.active_suite; + error->file = file; + error->line_number = line; + error->error_msg = error_msg; + + if (description != NULL) + error->description = strdup(description); + + _clay.suite_errors++; + _clay.total_errors++; + + if (should_abort) { + if (!_clay.trampoline_enabled) { + fprintf(stderr, + "Fatal error: a cleanup method raised an exception."); + exit(-1); + } + + longjmp(_clay.trampoline, -1); + } +} + +void cl_set_cleanup(void (*cleanup)(void *), void *opaque) +{ + _clay.local_cleanup = cleanup; + _clay.local_cleanup_payload = opaque; +} + +static char _clay_path[4096]; + +static int +is_valid_tmp_path(const char *path) +{ + STAT_T st; + + if (stat(path, &st) != 0) + return 0; + + if (!S_ISDIR(st.st_mode)) + return 0; + + return (access(path, W_OK) == 0); +} + +static int +find_tmp_path(char *buffer, size_t length) +{ + static const size_t var_count = 4; + static const char *env_vars[] = { + "TMPDIR", "TMP", "TEMP", "USERPROFILE" + }; + +#ifdef _WIN32 + if (GetTempPath((DWORD)length, buffer)) + return 0; +#else + size_t i; + + for (i = 0; i < var_count; ++i) { + const char *env = getenv(env_vars[i]); + if (!env) + continue; + + if (is_valid_tmp_path(env)) { + strncpy(buffer, env, length); + return 0; + } + } + + /* If the environment doesn't say anything, try to use /tmp */ + if (is_valid_tmp_path("/tmp")) { + strncpy(buffer, "/tmp", length); + return 0; + } +#endif + + /* This system doesn't like us, try to use the current directory */ + if (is_valid_tmp_path(".")) { + strncpy(buffer, ".", length); + return 0; + } + + return -1; +} + +static void clay_unsandbox(void) +{ + if (_clay_path[0] == '\0') + return; + +#ifdef _WIN32 + chdir(".."); +#endif + + fs_rm(_clay_path); +} + +static int build_sandbox_path(void) +{ + const char path_tail[] = "clay_tmp_XXXXXX"; + size_t len; + + if (find_tmp_path(_clay_path, sizeof(_clay_path)) < 0) + return -1; + + len = strlen(_clay_path); + +#ifdef _WIN32 + { /* normalize path to POSIX forward slashes */ + size_t i; + for (i = 0; i < len; ++i) { + if (_clay_path[i] == '\\') + _clay_path[i] = '/'; + } + } +#endif + + if (_clay_path[len - 1] != '/') { + _clay_path[len++] = '/'; + } + + strncpy(_clay_path + len, path_tail, sizeof(_clay_path) - len); + +#ifdef _WIN32 + if (_mktemp_s(_clay_path, sizeof(_clay_path)) != 0) + return -1; +#else + if (mktemp(_clay_path) == NULL) + return -1; +#endif + + return 0; +} + +static int clay_sandbox(void) +{ + if (_clay_path[0] == '\0' && build_sandbox_path() < 0) + return -1; + + if (mkdir(_clay_path, 0700) != 0) + return -1; + + if (chdir(_clay_path) != 0) + return -1; + + return 0; +} + + +static const char * +fixture_path(const char *base, const char *fixture_name) +{ + static char _path[4096]; + size_t root_len; + + root_len = strlen(base); + strncpy(_path, base, sizeof(_path)); + + if (_path[root_len - 1] != '/') + _path[root_len++] = '/'; + + if (fixture_name[0] == '/') + fixture_name++; + + strncpy(_path + root_len, + fixture_name, + sizeof(_path) - root_len); + + return _path; +} + +#ifdef CLAY_FIXTURE_PATH +const char *cl_fixture(const char *fixture_name) +{ + return fixture_path(CLAY_FIXTURE_PATH, fixture_name); +} + +void cl_fixture_sandbox(const char *fixture_name) +{ + fs_copy(cl_fixture(fixture_name), _clay_path); +} + +void cl_fixture_cleanup(const char *fixture_name) +{ + fs_rm(fixture_path(_clay_path, fixture_name)); +} +#endif + +#ifdef _WIN32 + +#define FOF_FLAGS (FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR) + +static char * +fileops_path(const char *_path) +{ + char *path = NULL; + size_t length, i; + + if (_path == NULL) + return NULL; + + length = strlen(_path); + path = malloc(length + 2); + + if (path == NULL) + return NULL; + + memcpy(path, _path, length); + path[length] = 0; + path[length + 1] = 0; + + for (i = 0; i < length; ++i) { + if (path[i] == '/') + path[i] = '\\'; + } + + return path; +} + +static void +fileops(int mode, const char *_source, const char *_dest) +{ + SHFILEOPSTRUCT fops; + + char *source = fileops_path(_source); + char *dest = fileops_path(_dest); + + ZeroMemory(&fops, sizeof(SHFILEOPSTRUCT)); + + fops.wFunc = mode; + fops.pFrom = source; + fops.pTo = dest; + fops.fFlags = FOF_FLAGS; + + cl_assert_( + SHFileOperation(&fops) == 0, + "Windows SHFileOperation failed" + ); + + free(source); + free(dest); +} + +static void +fs_rm(const char *_source) +{ + fileops(FO_DELETE, _source, NULL); +} + +static void +fs_copy(const char *_source, const char *_dest) +{ + fileops(FO_COPY, _source, _dest); +} + +void +cl_fs_cleanup(void) +{ + fs_rm(fixture_path(_clay_path, "*")); +} + +#else +static int +shell_out(char * const argv[]) +{ + int status; + pid_t pid; + + pid = fork(); + + if (pid < 0) { + fprintf(stderr, + "System error: `fork()` call failed.\n"); + exit(-1); + } + + if (pid == 0) { + execv(argv[0], argv); + } + + waitpid(pid, &status, 0); + return WEXITSTATUS(status); +} + +static void +fs_copy(const char *_source, const char *dest) +{ + char *argv[5]; + char *source; + size_t source_len; + + source = strdup(_source); + source_len = strlen(source); + + if (source[source_len - 1] == '/') + source[source_len - 1] = 0; + + argv[0] = "/bin/cp"; + argv[1] = "-R"; + argv[2] = source; + argv[3] = (char *)dest; + argv[4] = NULL; + + cl_must_pass_( + shell_out(argv), + "Failed to copy test fixtures to sandbox" + ); + + free(source); +} + +static void +fs_rm(const char *source) +{ + char *argv[4]; + + argv[0] = "/bin/rm"; + argv[1] = "-Rf"; + argv[2] = (char *)source; + argv[3] = NULL; + + cl_must_pass_( + shell_out(argv), + "Failed to cleanup the sandbox" + ); +} + +void +cl_fs_cleanup(void) +{ + clay_unsandbox(); + clay_sandbox(); +} +#endif + + +extern void test_core_dirent__dont_traverse_dot(void); +extern void test_core_dirent__traverse_subfolder(void); +extern void test_core_dirent__traverse_slash_terminated_folder(void); +extern void test_core_dirent__dont_traverse_empty_folders(void); +extern void test_core_dirent__traverse_weird_filenames(void); +extern void test_core_filebuf__0(void); +extern void test_core_filebuf__1(void); +extern void test_core_filebuf__2(void); +extern void test_core_path__0(void); +extern void test_core_path__1(void); +extern void test_core_path__2(void); +extern void test_core_path__5(void); +extern void test_core_path__6(void); +extern void test_core_rmdir__initialize(void); +extern void test_core_rmdir__delete_recursive(void); +extern void test_core_rmdir__fail_to_delete_non_empty_dir(void); +extern void test_core_string__0(void); +extern void test_core_string__1(void); +extern void test_core_vector__0(void); +extern void test_core_vector__1(void); +extern void test_core_vector__2(void); +extern void test_status_single__hash_single_file(void); +extern void test_status_worktree__initialize(void); +extern void test_status_worktree__cleanup(void); +extern void test_status_worktree__whole_repository(void); +extern void test_status_worktree__empty_repository(void); + +static const struct clay_func _all_callbacks[] = { + {"dont_traverse_dot", &test_core_dirent__dont_traverse_dot, 0}, + {"traverse_subfolder", &test_core_dirent__traverse_subfolder, 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}, + {"traverse_weird_filenames", &test_core_dirent__traverse_weird_filenames, 0}, + {"0", &test_core_filebuf__0, 1}, + {"1", &test_core_filebuf__1, 1}, + {"2", &test_core_filebuf__2, 1}, + {"0", &test_core_path__0, 2}, + {"1", &test_core_path__1, 2}, + {"2", &test_core_path__2, 2}, + {"5", &test_core_path__5, 2}, + {"6", &test_core_path__6, 2}, + {"delete_recursive", &test_core_rmdir__delete_recursive, 3}, + {"fail_to_delete_non_empty_dir", &test_core_rmdir__fail_to_delete_non_empty_dir, 3}, + {"0", &test_core_string__0, 4}, + {"1", &test_core_string__1, 4}, + {"0", &test_core_vector__0, 5}, + {"1", &test_core_vector__1, 5}, + {"2", &test_core_vector__2, 5}, + {"hash_single_file", &test_status_single__hash_single_file, 6}, + {"whole_repository", &test_status_worktree__whole_repository, 7}, + {"empty_repository", &test_status_worktree__empty_repository, 7} +}; + +static const struct clay_suite _all_suites[] = { + { + "core::dirent", + {NULL, NULL, 0}, + {NULL, NULL, 0}, + &_all_callbacks[0], 5 + }, + { + "core::filebuf", + {NULL, NULL, 0}, + {NULL, NULL, 0}, + &_all_callbacks[5], 3 + }, + { + "core::path", + {NULL, NULL, 0}, + {NULL, NULL, 0}, + &_all_callbacks[8], 5 + }, + { + "core::rmdir", + {"initialize", &test_core_rmdir__initialize, 3}, + {NULL, NULL, 0}, + &_all_callbacks[13], 2 + }, + { + "core::string", + {NULL, NULL, 0}, + {NULL, NULL, 0}, + &_all_callbacks[15], 2 + }, + { + "core::vector", + {NULL, NULL, 0}, + {NULL, NULL, 0}, + &_all_callbacks[17], 3 + }, + { + "status::single", + {NULL, NULL, 0}, + {NULL, NULL, 0}, + &_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"; + +int _CC main(int argc, char *argv[]) +{ + return clay_test( + argc, argv, _suites_str, + _all_callbacks, 23, + _all_suites, 8 + ); +} diff --git a/tests-clay/core/dirent.c b/tests-clay/core/dirent.c new file mode 100644 index 000000000..73f571595 --- /dev/null +++ b/tests-clay/core/dirent.c @@ -0,0 +1,222 @@ +#include "clay_libgit2.h" +#include "fileops.h" + +typedef struct name_data { + int count; /* return count */ + char *name; /* filename */ +} name_data; + +typedef struct walk_data { + char *sub; /* sub-directory name */ + name_data *names; /* name state data */ +} walk_data; + + +static char path_buffer[GIT_PATH_MAX]; +static char *top_dir = "dir-walk"; +static walk_data *state_loc; + +static void setup(walk_data *d) +{ + name_data *n; + + cl_must_pass(p_mkdir(top_dir, 0755)); + + cl_must_pass(p_chdir(top_dir)); + + if (strcmp(d->sub, ".") != 0) + cl_must_pass(p_mkdir(d->sub, 0755)); + + strcpy(path_buffer, d->sub); + state_loc = d; + + for (n = d->names; n->name; n++) { + git_file fd = p_creat(n->name, 0600); + cl_assert(fd >= 0); + p_close(fd); + n->count = 0; + } +} + +static void dirent_cleanup__cb(void *_d) +{ + walk_data *d = _d; + name_data *n; + + for (n = d->names; n->name; n++) { + cl_must_pass(p_unlink(n->name)); + } + + if (strcmp(d->sub, ".") != 0) + cl_must_pass(p_rmdir(d->sub)); + + cl_must_pass(p_chdir("..")); + + cl_must_pass(p_rmdir(top_dir)); +} + +static void check_counts(walk_data *d) +{ + name_data *n; + + for (n = d->names; n->name; n++) { + cl_assert(n->count == 1); + } +} + +static int one_entry(void *state, char *path) +{ + walk_data *d = (walk_data *) state; + name_data *n; + + if (state != state_loc) + return GIT_ERROR; + + if (path != path_buffer) + return GIT_ERROR; + + for (n = d->names; n->name; n++) { + if (!strcmp(n->name, path)) { + n->count++; + return 0; + } + } + + return GIT_ERROR; +} + +static int dont_call_me(void *GIT_UNUSED(state), char *GIT_UNUSED(path)) +{ + GIT_UNUSED_ARG(state) + GIT_UNUSED_ARG(path) + return GIT_ERROR; +} + + + +static name_data dot_names[] = { + { 0, "./a" }, + { 0, "./asdf" }, + { 0, "./pack-foo.pack" }, + { 0, NULL } +}; +static walk_data dot = { + ".", + dot_names +}; + +/* make sure that the '.' folder is not traversed */ +void test_core_dirent__dont_traverse_dot(void) +{ + cl_set_cleanup(&dirent_cleanup__cb, &dot); + setup(&dot); + + cl_git_pass(git_futils_direach(path_buffer, + sizeof(path_buffer), + one_entry, + &dot)); + + check_counts(&dot); +} + + +static name_data sub_names[] = { + { 0, "sub/a" }, + { 0, "sub/asdf" }, + { 0, "sub/pack-foo.pack" }, + { 0, NULL } +}; +static walk_data sub = { + "sub", + sub_names +}; + +/* traverse a subfolder */ +void test_core_dirent__traverse_subfolder(void) +{ + cl_set_cleanup(&dirent_cleanup__cb, &sub); + setup(&sub); + + cl_git_pass(git_futils_direach(path_buffer, + sizeof(path_buffer), + one_entry, + &sub)); + + check_counts(&sub); +} + + +static walk_data sub_slash = { + "sub/", + sub_names +}; + +/* traverse a slash-terminated subfolder */ +void test_core_dirent__traverse_slash_terminated_folder(void) +{ + cl_set_cleanup(&dirent_cleanup__cb, &sub_slash); + setup(&sub_slash); + + cl_git_pass(git_futils_direach(path_buffer, + sizeof(path_buffer), + one_entry, + &sub_slash)); + + check_counts(&sub_slash); +} + + +static name_data empty_names[] = { + { 0, NULL } +}; +static walk_data empty = { + "empty", + empty_names +}; + +/* make sure that empty folders are not traversed */ +void test_core_dirent__dont_traverse_empty_folders(void) +{ + cl_set_cleanup(&dirent_cleanup__cb, &empty); + setup(&empty); + + cl_git_pass(git_futils_direach(path_buffer, + sizeof(path_buffer), + one_entry, + &empty)); + + check_counts(&empty); + + /* make sure callback not called */ + cl_git_pass(git_futils_direach(path_buffer, + sizeof(path_buffer), + dont_call_me, + &empty)); +} + +static name_data odd_names[] = { + { 0, "odd/.a" }, + { 0, "odd/..c" }, + /* the following don't work on cygwin/win32 */ + /* { 0, "odd/.b." }, */ + /* { 0, "odd/..d.." }, */ + { 0, NULL } +}; +static walk_data odd = { + "odd", + odd_names +}; + +/* make sure that strange looking filenames ('..c') are traversed */ +void test_core_dirent__traverse_weird_filenames(void) +{ + cl_set_cleanup(&dirent_cleanup__cb, &odd); + setup(&odd); + + cl_git_pass(git_futils_direach(path_buffer, + sizeof(path_buffer), + one_entry, + &odd)); + + check_counts(&odd); +} diff --git a/tests-clay/core/filebuf.c b/tests-clay/core/filebuf.c new file mode 100644 index 000000000..e00e20497 --- /dev/null +++ b/tests-clay/core/filebuf.c @@ -0,0 +1,58 @@ +#include "clay_libgit2.h" +#include "filebuf.h" + +/* make sure git_filebuf_open doesn't delete an existing lock */ +void test_core_filebuf__0(void) +{ + git_filebuf file; + int fd; + char test[] = "test", testlock[] = "test.lock"; + + fd = p_creat(testlock, 0744); + + cl_must_pass(fd); + cl_must_pass(p_close(fd)); + + cl_git_fail(git_filebuf_open(&file, test, 0)); + cl_git_pass(git_futils_exists(testlock)); + + cl_must_pass(p_unlink(testlock)); +} + + +/* make sure GIT_FILEBUF_APPEND works as expected */ +void test_core_filebuf__1(void) +{ + git_filebuf file; + int fd; + char test[] = "test"; + + fd = p_creat(test, 0644); + cl_must_pass(fd); + cl_must_pass(p_write(fd, "libgit2 rocks\n", 14)); + cl_must_pass(p_close(fd)); + + cl_git_pass(git_filebuf_open(&file, test, GIT_FILEBUF_APPEND)); + cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks")); + cl_git_pass(git_filebuf_commit(&file)); + + cl_must_pass(p_unlink(test)); +} + + +/* make sure git_filebuf_write writes large buffer correctly */ +void test_core_filebuf__2(void) +{ + git_filebuf file; + char test[] = "test"; + unsigned char buf[4096 * 4]; /* 2 * WRITE_BUFFER_SIZE */ + + memset(buf, 0xfe, sizeof(buf)); + + cl_git_pass(git_filebuf_open(&file, test, 0)); + cl_git_pass(git_filebuf_write(&file, buf, sizeof(buf))); + cl_git_pass(git_filebuf_commit(&file)); + + cl_must_pass(p_unlink(test)); +} + diff --git a/tests-clay/core/path.c b/tests-clay/core/path.c new file mode 100644 index 000000000..db8f33d21 --- /dev/null +++ b/tests-clay/core/path.c @@ -0,0 +1,139 @@ +#include "clay_libgit2.h" +#include <fileops.h> + +static void +check_dirname(const char *A, const char *B) +{ + char dir[64], *dir2; + + cl_assert(git_path_dirname_r(dir, sizeof(dir), A) >= 0); + cl_assert(strcmp(dir, B) == 0); + cl_assert((dir2 = git_path_dirname(A)) != NULL); + cl_assert(strcmp(dir2, B) == 0); + + free(dir2); +} + +static void +check_basename(const char *A, const char *B) +{ + char base[64], *base2; + + cl_assert(git_path_basename_r(base, sizeof(base), A) >= 0); + cl_assert(strcmp(base, B) == 0); + cl_assert((base2 = git_path_basename(A)) != NULL); + cl_assert(strcmp(base2, B) == 0); + + free(base2); +} + +static void +check_topdir(const char *A, const char *B) +{ + const char *dir; + + cl_assert((dir = git_path_topdir(A)) != NULL); + cl_assert(strcmp(dir, B) == 0); +} + +static void +check_joinpath(const char *path_a, const char *path_b, const char *expected_path) +{ + char joined_path[GIT_PATH_MAX]; + + git_path_join(joined_path, path_a, path_b); + cl_assert(strcmp(joined_path, expected_path) == 0); +} + +static void +check_joinpath_n( + const char *path_a, + const char *path_b, + const char *path_c, + const char *path_d, + const char *expected_path) +{ + char joined_path[GIT_PATH_MAX]; + + git_path_join_n(joined_path, 4, path_a, path_b, path_c, path_d); + cl_assert(strcmp(joined_path, expected_path) == 0); +} + + +/* get the dirname of a path */ +void test_core_path__0(void) +{ + + check_dirname(NULL, "."); + check_dirname("", "."); + check_dirname("a", "."); + check_dirname("/", "/"); + check_dirname("/usr", "/"); + check_dirname("/usr/", "/"); + check_dirname("/usr/lib", "/usr"); + check_dirname("/usr/lib/", "/usr"); + check_dirname("/usr/lib//", "/usr"); + check_dirname("usr/lib", "usr"); + check_dirname("usr/lib/", "usr"); + check_dirname("usr/lib//", "usr"); + check_dirname(".git/", "."); +} + +/* get the base name of a path */ +void test_core_path__1(void) +{ + check_basename(NULL, "."); + check_basename("", "."); + check_basename("a", "a"); + check_basename("/", "/"); + check_basename("/usr", "usr"); + check_basename("/usr/", "usr"); + check_basename("/usr/lib", "lib"); + check_basename("/usr/lib//", "lib"); + check_basename("usr/lib", "lib"); +} + +/* get the latest component in a path */ +void test_core_path__2(void) +{ + check_topdir(".git/", ".git/"); + check_topdir("/.git/", ".git/"); + check_topdir("usr/local/.git/", ".git/"); + check_topdir("./.git/", ".git/"); + check_topdir("/usr/.git/", ".git/"); + check_topdir("/", "/"); + check_topdir("a/", "a/"); + + cl_assert(git_path_topdir("/usr/.git") == NULL); + cl_assert(git_path_topdir(".") == NULL); + cl_assert(git_path_topdir("") == NULL); + cl_assert(git_path_topdir("a") == NULL); +} + +/* properly join path components */ +void test_core_path__5(void) +{ + check_joinpath("", "", ""); + check_joinpath("", "a", "a"); + check_joinpath("", "/a", "/a"); + check_joinpath("a", "", "a/"); + check_joinpath("a", "/", "a/"); + check_joinpath("a", "b", "a/b"); + check_joinpath("/", "a", "/a"); + check_joinpath("/", "", "/"); + check_joinpath("/a", "/b", "/a/b"); + check_joinpath("/a", "/b/", "/a/b/"); + check_joinpath("/a/", "b/", "/a/b/"); + check_joinpath("/a/", "/b/", "/a/b/"); +} + +/* properly join path components for more than one path */ +void test_core_path__6(void) +{ + check_joinpath_n("", "", "", "", ""); + check_joinpath_n("", "a", "", "", "a/"); + check_joinpath_n("a", "", "", "", "a/"); + check_joinpath_n("", "", "", "a", "a"); + check_joinpath_n("a", "b", "", "/c/d/", "a/b/c/d/"); + check_joinpath_n("a", "b", "", "/c/d", "a/b/c/d"); +} diff --git a/tests-clay/core/rmdir.c b/tests-clay/core/rmdir.c new file mode 100644 index 000000000..aa21c6a3d --- /dev/null +++ b/tests-clay/core/rmdir.c @@ -0,0 +1,50 @@ +#include "clay_libgit2.h" +#include "fileops.h" + +static const char *empty_tmp_dir = "test_gitfo_rmdir_recurs_test"; + +void test_core_rmdir__initialize(void) +{ + char path[GIT_PATH_MAX]; + + cl_must_pass(p_mkdir(empty_tmp_dir, 0755)); + + git_path_join(path, empty_tmp_dir, "/one"); + cl_must_pass(p_mkdir(path, 0755)); + + git_path_join(path, empty_tmp_dir, "/one/two_one"); + cl_must_pass(p_mkdir(path, 0755)); + + git_path_join(path, empty_tmp_dir, "/one/two_two"); + cl_must_pass(p_mkdir(path, 0755)); + + git_path_join(path, empty_tmp_dir, "/one/two_two/three"); + cl_must_pass(p_mkdir(path, 0755)); + + git_path_join(path, empty_tmp_dir, "/two"); + cl_must_pass(p_mkdir(path, 0755)); +} + +/* make sure empty dir can be deleted recusively */ +void test_core_rmdir__delete_recursive(void) +{ + cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, 0)); +} + +/* make sure non-empty dir cannot be deleted recusively */ +void test_core_rmdir__fail_to_delete_non_empty_dir(void) +{ + char file[GIT_PATH_MAX]; + int fd; + + git_path_join(file, empty_tmp_dir, "/two/file.txt"); + + fd = p_creat(file, 0755); + cl_assert(fd >= 0); + + cl_must_pass(p_close(fd)); + cl_git_fail(git_futils_rmdir_r(empty_tmp_dir, 0)); + + cl_must_pass(p_unlink(file)); + cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, 0)); +} diff --git a/tests-clay/core/string.c b/tests-clay/core/string.c new file mode 100644 index 000000000..c154aaf18 --- /dev/null +++ b/tests-clay/core/string.c @@ -0,0 +1,28 @@ +#include "clay_libgit2.h" + +/* compare prefixes */ +void test_core_string__0(void) +{ + cl_assert(git__prefixcmp("", "") == 0); + cl_assert(git__prefixcmp("a", "") == 0); + cl_assert(git__prefixcmp("", "a") < 0); + cl_assert(git__prefixcmp("a", "b") < 0); + cl_assert(git__prefixcmp("b", "a") > 0); + cl_assert(git__prefixcmp("ab", "a") == 0); + cl_assert(git__prefixcmp("ab", "ac") < 0); + cl_assert(git__prefixcmp("ab", "aa") > 0); +} + +/* compare suffixes */ +void test_core_string__1(void) +{ + cl_assert(git__suffixcmp("", "") == 0); + cl_assert(git__suffixcmp("a", "") == 0); + cl_assert(git__suffixcmp("", "a") < 0); + cl_assert(git__suffixcmp("a", "b") < 0); + cl_assert(git__suffixcmp("b", "a") > 0); + cl_assert(git__suffixcmp("ba", "a") == 0); + cl_assert(git__suffixcmp("zaa", "ac") < 0); + cl_assert(git__suffixcmp("zaz", "ac") > 0); +} + diff --git a/tests-clay/core/vector.c b/tests-clay/core/vector.c new file mode 100644 index 000000000..44e6d873d --- /dev/null +++ b/tests-clay/core/vector.c @@ -0,0 +1,66 @@ +#include "clay_libgit2.h" +#include "vector.h" + +/* initial size of 1 would cause writing past array bounds */ +void test_core_vector__0(void) +{ + git_vector x; + int i; + git_vector_init(&x, 1, NULL); + for (i = 0; i < 10; ++i) { + git_vector_insert(&x, (void*) 0xabc); + } + git_vector_free(&x); +} + + +/* don't read past array bounds on remove() */ +void test_core_vector__1(void) +{ + git_vector x; + // make initial capacity exact for our insertions. + git_vector_init(&x, 3, NULL); + git_vector_insert(&x, (void*) 0xabc); + git_vector_insert(&x, (void*) 0xdef); + git_vector_insert(&x, (void*) 0x123); + + git_vector_remove(&x, 0); // used to read past array bounds. + git_vector_free(&x); +} + + +static int test_cmp(const void *a, const void *b) +{ + return *(const int *)a - *(const int *)b; +} + +/* remove duplicates */ +void test_core_vector__2(void) +{ + git_vector x; + int *ptrs[2]; + + ptrs[0] = git__malloc(sizeof(int)); + ptrs[1] = git__malloc(sizeof(int)); + + *ptrs[0] = 2; + *ptrs[1] = 1; + + cl_git_pass(git_vector_init(&x, 5, test_cmp)); + cl_git_pass(git_vector_insert(&x, ptrs[0])); + cl_git_pass(git_vector_insert(&x, ptrs[1])); + cl_git_pass(git_vector_insert(&x, ptrs[1])); + cl_git_pass(git_vector_insert(&x, ptrs[0])); + cl_git_pass(git_vector_insert(&x, ptrs[1])); + cl_assert(x.length == 5); + + git_vector_uniq(&x); + cl_assert(x.length == 2); + + git_vector_free(&x); + + free(ptrs[0]); + free(ptrs[1]); +} + + diff --git a/tests-clay/status/single.c b/tests-clay/status/single.c new file mode 100644 index 000000000..ea1c77fa0 --- /dev/null +++ b/tests-clay/status/single.c @@ -0,0 +1,38 @@ +#include "clay_libgit2.h" +#include "posix.h" + +static void +cleanup__remove_file(void *_file) +{ + cl_must_pass(p_unlink((char *)_file)); +} + +static void +file_create(const char *filename, const char *content) +{ + int fd = p_creat(filename, 0644); + cl_assert(fd >= 0); + cl_must_pass(p_write(fd, content, strlen(content))); + cl_must_pass(p_close(fd)); +} + +/* test retrieving OID from a file apart from the ODB */ +void test_status_single__hash_single_file(void) +{ + static const char file_name[] = "new_file"; + static const char file_contents[] = "new_file\n"; + static const char file_hash[] = "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a"; + + git_oid expected_id, actual_id; + + /* initialization */ + git_oid_fromstr(&expected_id, file_hash); + file_create(file_name, file_contents); + cl_set_cleanup(&cleanup__remove_file, (void *)file_name); + + cl_git_pass(git_odb_hashfile(&actual_id, file_name, GIT_OBJ_BLOB)); + cl_assert(git_oid_cmp(&expected_id, &actual_id) == 0); +} + + + diff --git a/tests-clay/status/status_data.h b/tests-clay/status/status_data.h new file mode 100644 index 000000000..ea903c602 --- /dev/null +++ b/tests-clay/status/status_data.h @@ -0,0 +1,48 @@ + +struct status_entry_counts { + int wrong_status_flags_count; + int wrong_sorted_path; + int entry_count; + const unsigned int* expected_statuses; + const char** expected_paths; + int expected_entry_count; +}; + +static const char *entry_paths0[] = { + "file_deleted", + "modified_file", + "new_file", + "staged_changes", + "staged_changes_file_deleted", + "staged_changes_modified_file", + "staged_delete_file_deleted", + "staged_delete_modified_file", + "staged_new_file", + "staged_new_file_deleted_file", + "staged_new_file_modified_file", + + "subdir/deleted_file", + "subdir/modified_file", + "subdir/new_file", +}; + +static const unsigned int entry_statuses0[] = { + GIT_STATUS_WT_DELETED, + GIT_STATUS_WT_MODIFIED, + GIT_STATUS_WT_NEW, + GIT_STATUS_INDEX_MODIFIED, + GIT_STATUS_INDEX_MODIFIED | GIT_STATUS_WT_DELETED, + GIT_STATUS_INDEX_MODIFIED | GIT_STATUS_WT_MODIFIED, + GIT_STATUS_INDEX_DELETED, + GIT_STATUS_INDEX_DELETED | GIT_STATUS_WT_NEW, + GIT_STATUS_INDEX_NEW, + GIT_STATUS_INDEX_NEW | GIT_STATUS_WT_DELETED, + GIT_STATUS_INDEX_NEW | GIT_STATUS_WT_MODIFIED, + + GIT_STATUS_WT_DELETED, + GIT_STATUS_WT_MODIFIED, + GIT_STATUS_WT_NEW, +}; + +static const size_t entry_count0 = 14; + diff --git a/tests-clay/status/worktree.c b/tests-clay/status/worktree.c new file mode 100644 index 000000000..7449c6de9 --- /dev/null +++ b/tests-clay/status/worktree.c @@ -0,0 +1,124 @@ +#include "clay_libgit2.h" +#include "fileops.h" +#include "status_data.h" + + +/** + * Test fixtures + */ +static git_repository *_repository = NULL; + + +/** + * Auxiliary methods + */ +static int +cb_status__normal( const char *path, unsigned int status_flags, void *payload) +{ + struct status_entry_counts *counts = payload; + + if (counts->entry_count >= counts->expected_entry_count) { + counts->wrong_status_flags_count++; + goto exit; + } + + if (strcmp(path, counts->expected_paths[counts->entry_count])) { + counts->wrong_sorted_path++; + goto exit; + } + + if (status_flags != counts->expected_statuses[counts->entry_count]) + counts->wrong_status_flags_count++; + +exit: + counts->entry_count++; + return GIT_SUCCESS; +} + +static int +cb_status__count(const char *GIT_UNUSED(p), unsigned int GIT_UNUSED(s), void *payload) +{ + volatile int *count = (int *)payload; + + GIT_UNUSED_ARG(p); + GIT_UNUSED_ARG(s); + + *count++; + + return GIT_SUCCESS; +} + + + +/** + * Initializer + * + * This method is called once before starting each + * test, and will load the required fixtures + */ +void test_status_worktree__initialize(void) +{ + /* + * Sandbox the `status/` repository from our Fixtures. + * This will copy the whole folder to our sandbox, + * so now it can be accessed with `./status` + */ + cl_fixture_sandbox("status"); + + /* + * Rename `status/.gitted` to `status/.git` + * We do this because we cannot store a folder named `.git` + * inside the fixtures folder in our libgit2 repo. + */ + cl_git_pass( + git_futils_mv_atomic("status/.gitted", "status/.git") + ); + + /* + * Open the sandboxed "status" repository + */ + cl_git_pass(git_repository_open(&_repository, "status/.git")); +} + +/** + * Cleanup + * + * This will be called once after each test finishes, even + * if the test failed + */ +void test_status_worktree__cleanup(void) +{ + git_repository_free(_repository); + _repository = NULL; + + cl_fixture_cleanup("status"); +} + +/** + * Tests - Status determination on a working tree + */ +void test_status_worktree__whole_repository(void) +{ + struct status_entry_counts counts; + + memset(&counts, 0x0, sizeof(struct status_entry_counts)); + counts.expected_entry_count = entry_count0; + counts.expected_paths = entry_paths0; + counts.expected_statuses = entry_statuses0; + + cl_git_pass( + git_status_foreach(_repository, cb_status__normal, &counts) + ); + + cl_assert(counts.entry_count == counts.expected_entry_count); + cl_assert(counts.wrong_status_flags_count == 0); + cl_assert(counts.wrong_sorted_path == 0); +} + +void test_status_worktree__empty_repository(void) +{ + int count = 0; + + git_status_foreach(_repository, cb_status__count, &count); + cl_assert(count == 0); +} diff --git a/tests/resources/.gitattributes b/tests/resources/.gitattributes new file mode 100644 index 000000000..556f8c827 --- /dev/null +++ b/tests/resources/.gitattributes @@ -0,0 +1 @@ +* binary diff --git a/tests/t12-repo.c b/tests/t12-repo.c index 61e96d685..de921f9ca 100644 --- a/tests/t12-repo.c +++ b/tests/t12-repo.c @@ -212,8 +212,6 @@ BEGIN_TEST(open0, "Open a bare repository that has just been initialized by git" must_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, 1)); END_TEST -#define EMPTY_REPOSITORY_FOLDER TEST_RESOURCES "/empty_standard_repo/.gitted/" - BEGIN_TEST(open1, "Open a standard repository that has just been initialized by git") git_repository *repo; diff --git a/tests/t15-config.c b/tests/t15-config.c index 05de25f8c..fdfa092ef 100644 --- a/tests/t15-config.c +++ b/tests/t15-config.c @@ -214,26 +214,40 @@ BEGIN_TEST(config10, "a repo's config overrides the global config") git_repository *repo; git_config *cfg; int version; + char *old_home; + + old_home = git__strdup(getenv("HOME")); + setenv("HOME", CONFIG_BASE, 1); must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - must_pass(git_repository_config(&cfg, repo, CONFIG_BASE "/.gitconfig", NULL)); + must_pass(git_repository_config(&cfg, repo, NULL)); must_pass(git_config_get_int(cfg, "core.repositoryformatversion", &version)); must_be_true(version == 0); git_config_free(cfg); git_repository_free(repo); + + setenv("HOME", old_home, 1); + free(old_home); END_TEST BEGIN_TEST(config11, "fall back to the global config") git_repository *repo; git_config *cfg; int num; + char *old_home; + + old_home = git__strdup(getenv("HOME")); + setenv("HOME", CONFIG_BASE, 1); must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - must_pass(git_repository_config(&cfg, repo, CONFIG_BASE "/.gitconfig", NULL)); + must_pass(git_repository_config(&cfg, repo, NULL)); must_pass(git_config_get_int(cfg, "core.something", &num)); must_be_true(num == 2); git_config_free(cfg); git_repository_free(repo); + + setenv("HOME", old_home, 1); + free(old_home); END_TEST BEGIN_TEST(config12, "delete a value") diff --git a/tests/t16-remotes.c b/tests/t16-remotes.c index 4bc2f55d7..6529f0ec4 100644 --- a/tests/t16-remotes.c +++ b/tests/t16-remotes.c @@ -31,9 +31,13 @@ BEGIN_TEST(remotes0, "remote parsing works") git_remote *remote; git_repository *repo; git_config *cfg; + char *old_home; + + old_home = git__strdup(getenv("HOME")); + setenv("HOME", "/dev/null", 1); must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - must_pass(git_repository_config(&cfg, repo, NULL, NULL)); + must_pass(git_repository_config(&cfg, repo, NULL)); must_pass(git_remote_get(&remote, cfg, "test")); must_be_true(!strcmp(git_remote_name(remote), "test")); must_be_true(!strcmp(git_remote_url(remote), "git://github.com/libgit2/libgit2")); @@ -41,6 +45,9 @@ BEGIN_TEST(remotes0, "remote parsing works") git_remote_free(remote); git_config_free(cfg); git_repository_free(repo); + + setenv("HOME", old_home, 1); + free(old_home); END_TEST BEGIN_TEST(refspec0, "remote with refspec works") @@ -48,9 +55,13 @@ BEGIN_TEST(refspec0, "remote with refspec works") git_repository *repo; git_config *cfg; const git_refspec *refspec = NULL; + char *old_home; + + old_home = git__strdup(getenv("HOME")); + setenv("HOME", "/dev/null", 1); must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - must_pass(git_repository_config(&cfg, repo, NULL, NULL)); + must_pass(git_repository_config(&cfg, repo, NULL)); must_pass(git_remote_get(&remote, cfg, "test")); refspec = git_remote_fetchspec(remote); must_be_true(refspec != NULL); @@ -59,6 +70,9 @@ BEGIN_TEST(refspec0, "remote with refspec works") git_remote_free(remote); git_config_free(cfg); git_repository_free(repo); + + setenv("HOME", old_home, 1); + free(old_home); END_TEST BEGIN_TEST(refspec1, "remote fnmatch works as expected") @@ -66,9 +80,13 @@ BEGIN_TEST(refspec1, "remote fnmatch works as expected") git_repository *repo; git_config *cfg; const git_refspec *refspec = NULL; + char *old_home; + + old_home = git__strdup(getenv("HOME")); + setenv("HOME", "/dev/null", 1); must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - must_pass(git_repository_config(&cfg, repo, NULL, NULL)); + must_pass(git_repository_config(&cfg, repo, NULL)); must_pass(git_remote_get(&remote, cfg, "test")); refspec = git_remote_fetchspec(remote); must_be_true(refspec != NULL); @@ -77,6 +95,9 @@ BEGIN_TEST(refspec1, "remote fnmatch works as expected") git_remote_free(remote); git_config_free(cfg); git_repository_free(repo); + + setenv("HOME", old_home, 1); + free(old_home); END_TEST BEGIN_TEST(refspec2, "refspec transform") @@ -85,9 +106,13 @@ BEGIN_TEST(refspec2, "refspec transform") git_config *cfg; const git_refspec *refspec = NULL; char ref[1024] = {0}; + char *old_home; + + old_home = git__strdup(getenv("HOME")); + setenv("HOME", "/dev/null", 1); must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - must_pass(git_repository_config(&cfg, repo, NULL, NULL)); + must_pass(git_repository_config(&cfg, repo, NULL)); must_pass(git_remote_get(&remote, cfg, "test")); refspec = git_remote_fetchspec(remote); must_be_true(refspec != NULL); @@ -96,6 +121,9 @@ BEGIN_TEST(refspec2, "refspec transform") git_remote_free(remote); git_config_free(cfg); git_repository_free(repo); + + setenv("HOME", old_home, 1); + free(old_home); END_TEST BEGIN_SUITE(remotes) diff --git a/tests/t18-status.c b/tests/t18-status.c index c30c541df..1659fcd1a 100644 --- a/tests/t18-status.c +++ b/tests/t18-status.c @@ -33,15 +33,26 @@ static const char *test_blob_oid = "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a"; #define STATUS_WORKDIR_FOLDER TEST_RESOURCES "/status/" #define STATUS_REPOSITORY_TEMP_FOLDER TEMP_REPO_FOLDER ".gitted/" +static int file_create(const char *filename, const char *content) +{ + int fd; + + fd = p_creat(filename, 0644); + if (fd == 0) + return GIT_ERROR; + if (p_write(fd, content, strlen(content)) != 0) + return GIT_ERROR; + if (p_close(fd) != 0) + return GIT_ERROR; + + return GIT_SUCCESS; +} + BEGIN_TEST(file0, "test retrieving OID from a file apart from the ODB") git_oid expected_id, actual_id; char filename[] = "new_file"; - int fd; - fd = p_creat(filename, 0644); - must_pass(fd); - must_pass(p_write(fd, "new_file\n", 9)); - must_pass(p_close(fd)); + must_pass(file_create(filename, "new_file\n\0")); must_pass(git_odb_hashfile(&actual_id, filename, GIT_OBJ_BLOB)); @@ -51,8 +62,7 @@ BEGIN_TEST(file0, "test retrieving OID from a file apart from the ODB") must_pass(p_unlink(filename)); END_TEST -static const char *entry_paths[] = { - "current_file", +static const char *entry_paths0[] = { "file_deleted", "modified_file", "new_file", @@ -65,13 +75,12 @@ static const char *entry_paths[] = { "staged_new_file_deleted_file", "staged_new_file_modified_file", - "subdir/current_file", "subdir/deleted_file", "subdir/modified_file", "subdir/new_file", }; -static const unsigned int entry_statuses[] = { - GIT_STATUS_CURRENT, + +static const unsigned int entry_statuses0[] = { GIT_STATUS_WT_DELETED, GIT_STATUS_WT_MODIFIED, GIT_STATUS_WT_NEW, @@ -84,38 +93,41 @@ static const unsigned int entry_statuses[] = { GIT_STATUS_INDEX_NEW | GIT_STATUS_WT_DELETED, GIT_STATUS_INDEX_NEW | GIT_STATUS_WT_MODIFIED, - GIT_STATUS_CURRENT, GIT_STATUS_WT_DELETED, GIT_STATUS_WT_MODIFIED, GIT_STATUS_WT_NEW, }; -#define ENTRY_COUNT 16 - -static unsigned int get_expected_entry_status(const char *path) -{ - int i; - - for (i = 0; i < ENTRY_COUNT; ++i) - if (!strcmp(path, entry_paths[i])) - return entry_statuses[i]; - return (unsigned int)-1; -} +#define ENTRY_COUNT0 14 struct status_entry_counts { int wrong_status_flags_count; + int wrong_sorted_path; int entry_count; + const unsigned int* expected_statuses; + const char** expected_paths; + int expected_entry_count; }; static int status_cb(const char *path, unsigned int status_flags, void *payload) { - unsigned int expected_status_flags = get_expected_entry_status(path); struct status_entry_counts *counts = (struct status_entry_counts *)payload; - counts->entry_count++; - if (status_flags != expected_status_flags) + if (counts->entry_count >= counts->expected_entry_count) { + counts->wrong_status_flags_count++; + goto exit; + } + + if (strcmp(path, counts->expected_paths[counts->entry_count])) { + counts->wrong_sorted_path++; + goto exit; + } + + if (status_flags != counts->expected_statuses[counts->entry_count]) counts->wrong_status_flags_count++; +exit: + counts->entry_count++; return GIT_SUCCESS; } @@ -128,9 +140,195 @@ BEGIN_TEST(statuscb0, "test retrieving status for worktree of repository") must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER)); memset(&counts, 0x0, sizeof(struct status_entry_counts)); - git_status_foreach(repo, status_cb, &counts); - must_be_true(counts.entry_count == ENTRY_COUNT); + counts.expected_entry_count = ENTRY_COUNT0; + counts.expected_paths = entry_paths0; + counts.expected_statuses = entry_statuses0; + + must_pass(git_status_foreach(repo, status_cb, &counts)); + must_be_true(counts.entry_count == counts.expected_entry_count); + must_be_true(counts.wrong_status_flags_count == 0); + must_be_true(counts.wrong_sorted_path == 0); + + git_repository_free(repo); + + git_futils_rmdir_r(TEMP_REPO_FOLDER, 1); +END_TEST + +static int status_cb1(const char *path, unsigned int status_flags, void *payload) +{ + int *count = (int *)payload;; + + GIT_UNUSED_ARG(path); + GIT_UNUSED_ARG(status_flags); + + *count++; + + return GIT_SUCCESS; +} + +BEGIN_TEST(statuscb1, "test retrieving status for a worktree of an empty repository") + git_repository *repo; + int count = 0; + + must_pass(copydir_recurs(EMPTY_REPOSITORY_FOLDER, TEST_STD_REPO_FOLDER)); + must_pass(remove_placeholders(TEST_STD_REPO_FOLDER, "dummy-marker.txt")); + must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER)); + + must_pass(git_status_foreach(repo, status_cb1, &count)); + must_be_true(count == 0); + + git_repository_free(repo); + + git_futils_rmdir_r(TEMP_REPO_FOLDER, 1); +END_TEST + +static const char *entry_paths2[] = { + "current_file", + "file_deleted", + "modified_file", + "staged_changes", + "staged_changes_file_deleted", + "staged_changes_modified_file", + "staged_delete_file_deleted", + "staged_delete_modified_file", + "staged_new_file", + "staged_new_file_deleted_file", + "staged_new_file_modified_file", + "subdir/current_file", + "subdir/deleted_file", + "subdir/modified_file", +}; + +static const unsigned int entry_statuses2[] = { + GIT_STATUS_WT_DELETED, + GIT_STATUS_WT_DELETED, + GIT_STATUS_WT_DELETED, + GIT_STATUS_WT_DELETED | GIT_STATUS_INDEX_MODIFIED, + GIT_STATUS_WT_DELETED | GIT_STATUS_INDEX_MODIFIED, + GIT_STATUS_WT_DELETED | GIT_STATUS_INDEX_MODIFIED, + GIT_STATUS_INDEX_DELETED, + GIT_STATUS_INDEX_DELETED, + GIT_STATUS_WT_DELETED | GIT_STATUS_INDEX_NEW, + GIT_STATUS_WT_DELETED | GIT_STATUS_INDEX_NEW, + GIT_STATUS_WT_DELETED | GIT_STATUS_INDEX_NEW, + GIT_STATUS_WT_DELETED, + GIT_STATUS_WT_DELETED, + GIT_STATUS_WT_DELETED, +}; + +#define ENTRY_COUNT2 14 + +BEGIN_TEST(statuscb2, "test retrieving status for a purged worktree of an valid repository") + git_repository *repo; + struct status_entry_counts counts; + + must_pass(copydir_recurs(STATUS_WORKDIR_FOLDER, TEMP_REPO_FOLDER)); + must_pass(git_futils_mv_atomic(STATUS_REPOSITORY_TEMP_FOLDER, TEST_STD_REPO_FOLDER)); + must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER)); + + /* Purging the working */ + must_pass(p_unlink(TEMP_REPO_FOLDER "current_file")); + must_pass(p_unlink(TEMP_REPO_FOLDER "modified_file")); + must_pass(p_unlink(TEMP_REPO_FOLDER "new_file")); + must_pass(p_unlink(TEMP_REPO_FOLDER "staged_changes")); + must_pass(p_unlink(TEMP_REPO_FOLDER "staged_changes_modified_file")); + must_pass(p_unlink(TEMP_REPO_FOLDER "staged_delete_modified_file")); + must_pass(p_unlink(TEMP_REPO_FOLDER "staged_new_file")); + must_pass(p_unlink(TEMP_REPO_FOLDER "staged_new_file_modified_file")); + must_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER "subdir", 1)); + + memset(&counts, 0x0, sizeof(struct status_entry_counts)); + counts.expected_entry_count = ENTRY_COUNT2; + counts.expected_paths = entry_paths2; + counts.expected_statuses = entry_statuses2; + + must_pass(git_status_foreach(repo, status_cb, &counts)); + must_be_true(counts.entry_count == counts.expected_entry_count); must_be_true(counts.wrong_status_flags_count == 0); + must_be_true(counts.wrong_sorted_path == 0); + + git_repository_free(repo); + + git_futils_rmdir_r(TEMP_REPO_FOLDER, 1); +END_TEST + +static const char *entry_paths3[] = { + ".HEADER", + "42-is-not-prime.sigh", + "README.md", + "current_file", + "current_file/current_file", + "current_file/modified_file", + "current_file/new_file", + "file_deleted", + "modified_file", + "new_file", + "staged_changes", + "staged_changes_file_deleted", + "staged_changes_modified_file", + "staged_delete_file_deleted", + "staged_delete_modified_file", + "staged_new_file", + "staged_new_file_deleted_file", + "staged_new_file_modified_file", + "subdir", + "subdir/current_file", + "subdir/deleted_file", + "subdir/modified_file", +}; + +static const unsigned int entry_statuses3[] = { + GIT_STATUS_WT_NEW, + GIT_STATUS_WT_NEW, + GIT_STATUS_WT_NEW, + GIT_STATUS_WT_DELETED, + GIT_STATUS_WT_NEW, + GIT_STATUS_WT_NEW, + GIT_STATUS_WT_NEW, + GIT_STATUS_WT_DELETED, + GIT_STATUS_WT_MODIFIED, + GIT_STATUS_WT_NEW, + GIT_STATUS_INDEX_MODIFIED, + GIT_STATUS_WT_DELETED | GIT_STATUS_INDEX_MODIFIED, + GIT_STATUS_WT_MODIFIED | GIT_STATUS_INDEX_MODIFIED, + GIT_STATUS_INDEX_DELETED, + GIT_STATUS_WT_NEW | GIT_STATUS_INDEX_DELETED, + GIT_STATUS_INDEX_NEW, + GIT_STATUS_WT_DELETED | GIT_STATUS_INDEX_NEW, + GIT_STATUS_WT_MODIFIED | GIT_STATUS_INDEX_NEW, + GIT_STATUS_WT_NEW, + GIT_STATUS_WT_DELETED, + GIT_STATUS_WT_DELETED, + GIT_STATUS_WT_DELETED, +}; + +#define ENTRY_COUNT3 22 + +BEGIN_TEST(statuscb3, "test retrieving status for a worktree where a file and a subdir have been renamed and some files have been added") + git_repository *repo; + struct status_entry_counts counts; + + must_pass(copydir_recurs(STATUS_WORKDIR_FOLDER, TEMP_REPO_FOLDER)); + must_pass(git_futils_mv_atomic(STATUS_REPOSITORY_TEMP_FOLDER, TEST_STD_REPO_FOLDER)); + must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER)); + + must_pass(git_futils_mv_atomic(TEMP_REPO_FOLDER "current_file", TEMP_REPO_FOLDER "swap")); + must_pass(git_futils_mv_atomic(TEMP_REPO_FOLDER "subdir", TEMP_REPO_FOLDER "current_file")); + must_pass(git_futils_mv_atomic(TEMP_REPO_FOLDER "swap", TEMP_REPO_FOLDER "subdir")); + + must_pass(file_create(TEMP_REPO_FOLDER ".HEADER", "dummy")); + must_pass(file_create(TEMP_REPO_FOLDER "42-is-not-prime.sigh", "dummy")); + must_pass(file_create(TEMP_REPO_FOLDER "README.md", "dummy")); + + memset(&counts, 0x0, sizeof(struct status_entry_counts)); + counts.expected_entry_count = ENTRY_COUNT3; + counts.expected_paths = entry_paths3; + counts.expected_statuses = entry_statuses3; + + must_pass(git_status_foreach(repo, status_cb, &counts)); + must_be_true(counts.entry_count == counts.expected_entry_count); + must_be_true(counts.wrong_status_flags_count == 0); + must_be_true(counts.wrong_sorted_path == 0); git_repository_free(repo); @@ -146,9 +344,9 @@ BEGIN_TEST(singlestatus0, "test retrieving status for single file") must_pass(git_futils_mv_atomic(STATUS_REPOSITORY_TEMP_FOLDER, TEST_STD_REPO_FOLDER)); must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER)); - for (i = 0; i < ENTRY_COUNT; ++i) { - must_pass(git_status_file(&status_flags, repo, entry_paths[i])); - must_be_true(status_flags == entry_statuses[i]); + for (i = 0; i < ENTRY_COUNT0; ++i) { + must_pass(git_status_file(&status_flags, repo, entry_paths0[i])); + must_be_true(status_flags == entry_statuses0[i]); } git_repository_free(repo); @@ -174,11 +372,77 @@ BEGIN_TEST(singlestatus1, "test retrieving status for nonexistent file") git_futils_rmdir_r(TEMP_REPO_FOLDER, 1); END_TEST +BEGIN_TEST(singlestatus2, "test retrieving status for a non existent file in an empty repository") + git_repository *repo; + unsigned int status_flags; + int error; + + must_pass(copydir_recurs(EMPTY_REPOSITORY_FOLDER, TEST_STD_REPO_FOLDER)); + must_pass(remove_placeholders(TEST_STD_REPO_FOLDER, "dummy-marker.txt")); + must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER)); + + error = git_status_file(&status_flags, repo, "nonexistent"); + must_be_true(error == GIT_ENOTFOUND); + + git_repository_free(repo); + + git_futils_rmdir_r(TEMP_REPO_FOLDER, 1); +END_TEST + +BEGIN_TEST(singlestatus3, "test retrieving status for a new file in an empty repository") + git_repository *repo; + unsigned int status_flags; + char file_path[GIT_PATH_MAX]; + char filename[] = "new_file"; + int fd; + + must_pass(copydir_recurs(EMPTY_REPOSITORY_FOLDER, TEST_STD_REPO_FOLDER)); + must_pass(remove_placeholders(TEST_STD_REPO_FOLDER, "dummy-marker.txt")); + + git_path_join(file_path, TEMP_REPO_FOLDER, filename); + fd = p_creat(file_path, 0644); + must_pass(fd); + must_pass(p_write(fd, "new_file\n", 9)); + must_pass(p_close(fd)); + + must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER)); + + must_pass(git_status_file(&status_flags, repo, filename)); + must_be_true(status_flags == GIT_STATUS_WT_NEW); + + git_repository_free(repo); + + git_futils_rmdir_r(TEMP_REPO_FOLDER, 1); +END_TEST + +BEGIN_TEST(singlestatus4, "can't determine the status for a folder") + git_repository *repo; + unsigned int status_flags; + int error; + + must_pass(copydir_recurs(STATUS_WORKDIR_FOLDER, TEMP_REPO_FOLDER)); + must_pass(git_futils_mv_atomic(STATUS_REPOSITORY_TEMP_FOLDER, TEST_STD_REPO_FOLDER)); + must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER)); + + error = git_status_file(&status_flags, repo, "subdir"); + must_be_true(error == GIT_EINVALIDPATH); + + git_repository_free(repo); + + git_futils_rmdir_r(TEMP_REPO_FOLDER, 1); +END_TEST + BEGIN_SUITE(status) ADD_TEST(file0); ADD_TEST(statuscb0); + ADD_TEST(statuscb1); + ADD_TEST(statuscb2); + ADD_TEST(statuscb3); ADD_TEST(singlestatus0); ADD_TEST(singlestatus1); + ADD_TEST(singlestatus2); + ADD_TEST(singlestatus3); + ADD_TEST(singlestatus4); END_SUITE
\ No newline at end of file diff --git a/tests/test_helpers.h b/tests/test_helpers.h index 75027dd6f..53361b7b1 100644 --- a/tests/test_helpers.h +++ b/tests/test_helpers.h @@ -37,6 +37,7 @@ #define TEST_INDEX_PATH (REPOSITORY_FOLDER "index") #define TEST_INDEX2_PATH (TEST_RESOURCES "/gitgit.index") #define TEST_INDEXBIG_PATH (TEST_RESOURCES "/big.index") +#define EMPTY_REPOSITORY_FOLDER TEST_RESOURCES "/empty_standard_repo/.gitted/" #define TEMP_FOLDER "" #define TEMP_REPO_FOLDER TEMP_FOLDER TEST_REPOSITORY_NAME "/" |
