src/common.h


Log

Author Commit Date CI Message
Philip Kelley 5c5eeba6 2013-03-31T22:22:33 Add git_has_win32_version helper
Russell Belfer 5540d947 2013-03-15T16:39:00 Implement global/system file search paths The goal of this work is to expose the search logic for "global", "system", and "xdg" files through the git_libgit2_opts() interface. Behind the scenes, I changed the logic for finding files to have a notion of a git_strarray that represents a search path and to store a separate search path for each of the three tiers of config file. For each tier, I implemented a function to initialize it to default values (generally based on environment variables), and then general interfaces to get it, set it, reset it, and prepend new directories to it. Next, I exposed these interfaces through the git_libgit2_opts interface, reusing the GIT_CONFIG_LEVEL_SYSTEM, etc., constants for the user to control which search path they were modifying. There are alternative designs for the opts interface / argument ordering, so I'm putting this phase out for discussion. Additionally, I ended up doing a little bit of clean up regarding attr.h and attr_file.h, adding a new attrcache.h so the other two files wouldn't have to be included in so many places.
Russell Belfer f443a72d 2013-02-28T14:41:26 Fix some deprecation warnings on Windows This fixes some snprintf and vsnprintf related deprecation warnings we've been having on Windows with recent compilers.
Russell Belfer 97b71374 2013-02-28T14:14:45 Add GIT_STDLIB_CALL This removes the one-off GIT_CDECL and adds a new standard way of doing this named GIT_STDLIB_CALL with a src/win32 specific def when on the Windows platform.
Sven Strickroth c70455c7 2013-02-01T22:53:51 Deduplicate FormatMessage UTF-16 to UTF-8 conversion code Signed-off-by: Sven Strickroth <email@cs-ware.de>
Edward Thomson 359fc2d2 2013-01-08T17:07:25 update copyrights
Vicent Marti bf192cdb 2012-12-05T20:56:27 versions: MSVC build fixes
Vicent Marti 43efaabd 2012-12-05T20:54:03 common: Silly vmg.
Vicent Marti 8ff66112 2012-12-05T20:50:19 common: Silly MSVC
Vicent Martí e05ca13f 2012-12-05T11:47:19 Merge pull request #1115 from ben/struct-versions Version info for public structs
Ben Straub ee1c33b1 2012-12-03T12:45:15 Don't unconstify when casting
nulltoken cc146626 2012-11-19T19:00:46 revparse: Deploy EINVALIDSPEC usage
Ben Straub 0ab3a2ab 2012-11-30T20:34:50 Deploy GIT_INIT_STRUCTURE
Ben Straub c7231c45 2012-11-30T16:31:42 Deploy GITERR_CHECK_VERSION
Philip Kelley 41fb1ca0 2012-10-29T13:41:14 Reorganize transport architecture (squashed 3)
Russell Belfer 1a628100 2012-09-21T15:04:39 Make giterr_set_str public There has been discussion for a while about making some set of the `giterr_set` type functions part of the public API for code that is implementing new backends to libgit2. This makes the `giterr_set_str()` and `giterr_set_oom()` functions public.
Carlos Martín Nieto 64d01de8 2012-07-24T14:23:16 remote: start moving the protocol to a common area For the transition, http is going to keep its own logic until the git/common code catches up with the implied multi_ack that http has. This also has the side-effect of making the code cleaner and more correct regardingt he protocol.
Michael Schubert 6fc0bdc5 2012-07-17T10:52:16 Remove old error handling code
Tim Clem ac8eac2f 2012-06-15T11:25:52 Fix compile errors when building on windows Errors were due to not including winsock2 early enough.
Carlos Martín Nieto d3e1367f 2012-05-17T21:40:20 ssl: remove GnuTLS support It's too much work for now to redo everything. Move the ssl context struct to transport.h
Carlos Martín Nieto a6f24a5b 2012-05-01T01:50:26 https: make it work with OpenSSL as well Add specific functions that use OpenSSL instead of GnuTLS
Carlos Martín Nieto 66024c7c 2012-05-01T00:05:25 http: add https support when GnuTLS is available If it's not available, an error saying so will be returned when trying to use a https:// URL. This also unifies a lot of the network code to use git_transport in many places instead of an socket descriptor.
Vicent Martí dda708e7 2012-03-09T19:55:50 error-handling: On-disk config file backend Includes: - Proper error reporting when encountering syntax errors in a config file (file, line number, column). - Rewritten `config_write`, now with 99% less goto-spaghetti - Error state in `git_filebuf`: filebuf write functions no longer need to be checked for error returns. If any of the writes performed on a buffer fail, the last call to `git_filebuf_commit` or `git_filebuf_hash` will fail accordingly and set the appropiate error message. Baller!
schu 5e0de328 2012-02-13T17:10:24 Update Copyright header Signed-off-by: schu <schu-github@schulog.org>
Vicent Martí a53420e4 2012-01-26T17:53:46 msvc: Move `ssize_t` typedef to MSVC-only This is a MSVC-only issue. All other compilers we support work properly.
Vicent Marti 9462c471 2011-11-25T08:16:26 repository: Change ownership semantics The ownership semantics have been changed all over the library to be consistent. There are no more "borrowed" or duplicated references. Main changes: - `git_repository_open2` and `3` have been dropped. - Added setters and getters to hotswap all the repository owned objects: `git_repository_index` `git_repository_set_index` `git_repository_odb` `git_repository_set_odb` `git_repository_config` `git_repository_set_config` `git_repository_workdir` `git_repository_set_workdir` Now working directories/index files/ODBs and so on can be hot-swapped after creating a repository and between operations. - All these objects now have proper ownership semantics with refcounting: they all require freeing after they are no longer needed (the repository always keeps its internal reference). - Repository open and initialization has been updated to keep in mind the configuration files. Bare repositories are now always detected, and a default config file is created on init. - All the tests affected by these changes have been dropped from the old test suite and ported to the new one.
Vicent Marti a15c550d 2011-11-16T14:09:44 threads: Fix the shared global state with TLS See `global.c` for a description of what we're doing. When libgit2 is built with GIT_THREADS support, the threading system must be explicitly initialized with `git_threads_init()`.
Vicent Marti c060854e 2011-10-04T21:11:51 msvc: Properly handle inttypes.h/stdint.h
Vicent Martí a8076074 2011-09-18T20:00:19 Merge pull request #397 from lambourg/development Fix compilation issues with mingw64 headers
Vicent Marti 87d9869f 2011-09-19T03:34:49 Tabify everything There were quite a few places were spaces were being used instead of tabs. Try to catch them all. This should hopefully not break anything. Except for `git blame`. Oh well.
Vicent Marti bb742ede 2011-09-19T01:54:32 Cleanup legal data 1. The license header is technically not valid if it doesn't have a copyright signature. 2. The COPYING file has been updated with the different licenses used in the project. 3. The full GPLv2 header in each file annoys me.
Jerome Lambourg 22c30464 2011-09-12T11:06:54 Fix compilation issues with ming64 headers
Kirill A. Shutemov d7f0abab 2011-08-24T20:10:50 Fix false positive -Wuninitialized warnings GCC produces several -Wuninitialized warnings. Most of them can be fixed if we make visible for gcc that git__throw() and git__rethrow() always return first argument. Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
Vicent Marti 678e9e04 2011-07-03T13:33:43 build: Move OS-specific compat to their own folders
Vicent Marti b2cef77c 2011-06-30T21:29:42 common: Force 64 bit fileops at compile time
Vicent Martí ef9a6f4c 2011-06-15T13:47:41 Merge pull request #261 from Romain-Geissler/discovery-path-v2 Fix: GIT_PATH_PATH_SEPARATOR is now a semi-colon under Windows.
Romain Geissler 0657e46d 2011-06-15T12:36:08 Fix: GIT_PATH_PATH_SEPARATOR is now a semi-colon under Windows. GIT_PATH_LIST_SEPARATOR and GIT_PATH_MAX are made public so that it's can be used by a client.
Carlos Martín Nieto 2e18e29b 2011-06-14T16:35:57 Remove uneeded arpa/inet.h include This header isn't needed at all and it shows a lot of warnings on OpenBSD. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Jakob Pfender ee4912bf 2011-06-07T11:15:23 Revert "common: Include stat.h in include/git2/common.h instead of src/common.h" This reverts commit df1c98ab6d6171ed63729195bd190b54b67fe530. As 8a27b6b reverts the exposition of struct stat to the external API, we do not need - indeed, do not want - struct stat to be in the outer include layer.
Jakob Pfender cbf4f9f4 2011-05-25T16:31:14 common: Include stat.h in include/git2/common.h instead of src/common.h 00582bcb introduced a change to git_blob_create_fromfile() that required the caller to pass a stat struct. This means that we need to include stat.h higher in the hierarchy of includes.
Vicent Marti 6810bf28 2011-05-11T00:40:07 Move all error-related defines to `git2/errors.h`
Vicent Marti fa59f18d 2011-05-09T20:54:04 Change error handling mechanism once again Ok, this is the real deal. Hopefully. Here's how it's going to work: - One main method, called `git__throw`, that sets the error code and error message when an error happens. This method must be called in every single place where an error code was being returned previously, setting an error message instead. Example, instead of: return GIT_EOBJCORRUPTED; Use: return git__throw(GIT_EOBJCORRUPTED, "The object is missing a finalizing line feed"); And instead of: [...] { error = GIT_EOBJCORRUPTED; goto cleanup; } Use: [...] { error = git__throw(GIT_EOBJCORRUPTED, "What an error!"); goto cleanup; } The **only** exception to this are the allocation methods, which return NULL on failure but already set the message manually. /* only place where an error code can be returned directly, because the error message has already been set by the wrapper */ if (foo == NULL) return GIT_ENOMEM; - One secondary method, called `git__rethrow`, which can be used to fine-grain an error message and build an error stack. Example, instead of: if ((error = foobar(baz)) < GIT_SUCCESS) return error; You can now do: if ((error = foobar(baz)) < GIT_SUCCESS) return git__rethrow(error, "Failed to do a major operation"); The return of the `git_lasterror` method will be a string in the shape of: "Failed to do a major operation. (Failed to do an internal operation)" E.g. "Failed to open the index. (Not enough permissions to access '/path/to/index')." NOTE: do not abuse this method. Try to write all `git__throw` messages in a descriptive manner, to avoid having to rethrow them to clarify their meaning. This method should only be used in the places where the original error message set by a subroutine is not specific enough. It is encouraged to continue using this style as much possible to enforce error propagation: if ((error = foobar(baz)) < GIT_SUCCESS) return error; /* `foobar` has set an error message, and we are just propagating it */ The error handling revamp will take place in two phases: - Phase 1: Replace all pieces of code that return direct error codes with calls to `git__throw`. This can be done semi-automatically using `ack` to locate all the error codes that must be replaced. - Phase 2: Add some `git__rethrow` calls in those cases where the original error messages are not specific enough. Phase 1 is the main goal. A minor libgit2 release will be shipped once Phase 1 is ready, and the work will start on gradually improving the error handling mechanism by refining specific error messages. OTHER NOTES: - When writing error messages, please refrain from using weasel words. They add verbosity to the message without giving any real information. (<3 Emeric) E.g. "The reference file appears to be missing a carriage return" Nope. "The reference file is missing a carriage return" Yes. - When calling `git__throw`, please try to use more generic error codes so we can eventually reduce the list of error codes to something more reasonable. Feel free to add new, more generic error codes if these are going to replace several of the old ones. E.g. return GIT_EREFCORRUPTED; Can be turned into: return git__throw(GIT_EOBJCORRUPTED, "The reference is corrupted");
Vicent Marti 3f53c971 2011-05-05T01:20:27 errors: Set error messages on memory allocation
Vicent Marti 02f9e637 2011-05-05T01:12:17 errors: Add error handling function
Vicent Marti bb3de0c4 2011-03-16T21:35:51 Thread safe cache
Vicent Marti bbcc7ffc 2011-03-15T21:04:41 Add proper threading support to libgit2 We now depend on libpthread on all Unix platforms (should be installed by default) and use a simple wrapper for Windows threads under Win32. Signed-off-by: Vicent Marti <tanoku@gmail.com>
Vicent Marti 86194b24 2011-02-18T21:57:53 Split packed from unpacked references These two reference types are now stored separately to eventually allow the removal/renaming of loose references and rewriting of the refs packfile. Signed-off-by: Vicent Marti <tanoku@gmail.com>
nulltoken aa2120e9 2011-02-10T15:08:00 Added git_reference__normalize_name() along with tests.
Vicent Marti e52e38d3 2011-01-12T01:42:07 Move the compat definitions to types.h Don't need a brand new header for two typedefs when we already have a types.h header. Change comment style to ANSI C. Signed-off-by: Vicent Marti <tanoku@gmail.com>
Alex Budovski f0bde7fa 2011-01-11T16:07:45 Revised platform types to use 'best supported' size. This will allow graceful migration to 64 bit file sizes and timestamps should git's binary interface be extended to allow this.
Vicent Marti 9f54fe48 2010-12-23T00:15:09 Remove git_errno It was not being used by any methods (only by malloc and calloc), and since it needs to be TLS, it cannot be exported on DLLs on Windows. Burn it with fire. The API always returns error codes! Signed-off-by: Vicent Marti <tanoku@gmail.com>
Vicent Marti 44908fe7 2010-12-06T23:03:16 Change the library include file Libgit2 is now officially include as #include "<git2.h>" or indidividual files may be included as #include <git2/index.h> Signed-off-by: Vicent Marti <tanoku@gmail.com>
Andreas Ericsson fb799dfe 2010-04-23T09:59:22 Merge remote branch 'ramsay/dev' * ramsay/dev: Add a pack index 'virtual function' to fetch an index entry Add a pack index 'virtual function' to search by file offset Change the interface of the pack index search function Add an 64-bit offset table index bounds check for v2 pack index Add a minimum size check when opening an v2 pack index file win32: Add separate MinGW and MSVC compatability header files Makefile: Add support for custom build options in config.mak file Fix some coding style issues
Andreas Ericsson 5dddf7c8 2010-04-14T20:41:57 Add block-sha1 in favour of the mozilla routines Since block-sha1 from git.git has such excellent performance, we can also get rid of the openssl dependency. It's rather simple to add it back later as an optional extra, but we really needn't bother to pull in the entire ssl library and have to deal with linking issues now that we have the portable and, performance-wise, truly excellent block-sha1 code to fall back on. Since this requires a slight revamp of the build rules anyway, we take the opportunity to fix including EXTRA_OBJS in the final build as well. The block-sha1 code was originally implemented for git.git by Linus Torvalds <torvalds@linux-foundation.org> and was later polished by Nicolas Pitre <nico@cam.org>. Signed-off-by: Andreas Ericsson <ae@op5.se>
Ramsay Jones e8cc449f 2010-02-19T21:49:22 win32: Add separate MinGW and MSVC compatability header files Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Ramsay Jones 90d4d2f0 2010-01-11T19:27:50 win32: Use an 64-bit file offset type Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Ramsay Jones a1c0728d 2009-12-21T15:54:50 Add support for the MinGW platform Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Ramsay Jones cfe3a027 2010-01-15T22:07:44 Use a 64 bit off_t throughout the library and tests on POSIX Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Ramsay Jones 04e88240 2009-06-17T22:21:10 win32: Define the ssize_t type using SSIZE_T if supported Some win32 compilers define the SSIZE_T type, with the same meaning and intent as ssize_t. If available, make ssize_t a synonym of SSIZE_T. At present, the Digital-Mars compiler is known not to define SSIZE_T, so we provide an SSIZE_T macro to use in the typedef. Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Ramsay Jones 8a086f87 2009-06-14T22:12:20 win32: Add support for the MS Visual C/C++ compiler Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Ramsay Jones 502acd16 2009-03-23T18:37:51 win32: Add missing include for mkdir() and rmdir() Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Ramsay Jones 79ca2edc 2009-03-20T19:51:48 win32: Add routines to abstract memory-mapped file functions In particular, the git__mmap() and git__munmap() routines provide the interface to platform specific memory-mapped file facilities. We provide implementations for unix and win32, which can be found in their own sub-directories. Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Ramsay Jones 840fb8b7 2009-02-18T18:53:48 win32: fixup some headers to improve win32 compilation Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Ramsay Jones 3a33c7b3 2009-01-02T20:51:47 Fix snprintf compiler warning on cygwin As far as gcc is concerned, the "z size specifier" is available as an extension to the language, which is available with or without any -std= switch. (I think you have to go back to 2.95 for a version of gcc which doesn't work.) Many other compilers have this as an extension as well (ie without the equivalent of -std=c99). Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce 2c4b7707 2008-12-31T16:06:48 Add git__fmt as an easier to use snprintf Checking the return value of snprintf is a pain, as it must be >= 0 and < sizeof(buffer). git__fmt is a simple wrapper to perform these checks. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce 028ef0de 2008-12-31T13:20:21 Add a mutex and atomic counter abstraction and implementations These abstractions can be used to implement an efficient resource reference counter and simple mutual exclusion. On pthreads we use pthread_mutex_t, except when we are also on glibc and can directly use its asm/atomic.h definitions. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce d44cfd46 2008-12-31T13:16:31 Cleanup our header inclusion order to ensure pthread.h is early If we are using threads we need to make sure pthread.h comes in before just about anything else. Some platforms enable macros that alter what other headers define. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce 64a47c01 2008-12-30T23:21:36 Wrap malloc and friends and report out of memory as GIT_ENOMEM We now forbid direct use of malloc, strdup or calloc within the library and instead use wrapper functions git__malloc, etc. to invoke the underlying library malloc and set git_errno to a no memory error code if the allocation fails. In the future once we have pack objects in memory we are likely to enhance these routines with garbage collection logic to purge cached pack data when allocations fail. Because the size of the function will grow somewhat large, we don't want to mark them for inline as gcc tends to aggressively inline, creating larger than expected executables. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce 064301cc 2008-12-30T22:07:56 Fix size_t snprintf warning by using PRIuPTR format macro This is the correct C99 format code for the size_t type when passed as an argument to the *printf family. If the platform doesn't define it, we assume %lu and just cross our fingers that its the proper setting for a size_t on this system. On most sane platforms, "unsigned long" is the underlying type of "size_t". Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce a1d34bc0 2008-12-30T21:49:38 Support building on Mac OS X by using pthread_getspecific for TLS The Mach-O format does not permit gcc to implement the __thread TLS specification, so we must instead emulate it using a single int cell allocated from memory and stored inside of the thread specific data associated with the current pthread. What makes this tricky is git_errno must be a valid lvalue, so we really need to return a pointer to the caller and deference it as part of the git_errno macro. The GCC-specific __attribute__((constructor)) extension is used to ensure the pthread_key_t is allocated before any Git functions are executed in the library, as this is necessary to access our thread specific storage. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce b3039bee 2008-12-30T21:25:13 Cleanup formatting in our head files to be more consistent Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Ramsay Jones 75d58430 2008-12-18T22:56:14 Add a file reading routine along with an io buffer type In particular, the gitfo_read_file() routine can be used to slurp the complete file contents into an gitfo_buf structure. The buffer content will be allocated by malloc() and may be released by the gitfo_free_buf() routine. The io buffer type can be initialised on the stack with the GITFO_BUF_INIT macro. Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Ramsay Jones 5ee2fe77 2008-12-03T23:53:55 Add a GIT_PATH_MAX constant The PATH_MAX symbol is often, but not always, defined in the <limits.h> header. In particular, on cygwin you need to include this header to avoid a compilation error. However, some systems define PATH_MAX to be something as small as 256, which POSIX is happy to allow, while others allow much larger values. In general it can vary from one filesystem to another. In order to avoid the vagaries of different systems, define our own symbol. Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Andreas Ericsson 3a2aabdc 2008-11-22T14:44:47 Add util.h - utility macros ARRAY_SIZE() et al go in util.h, included from common.h Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Andreas Ericsson 76a8c447 2008-11-22T14:42:12 Add internal common.h file This one pulls in compiler compatibility macros, some common header files, and also the public common.h header. C source files are modified to use the private common.h in favour of the public one. Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Andreas Ericsson ae234862 2008-11-18T22:20:15 Add an embryo of a TLS-aware error handling system This adds the per-thread global variable git_errno to the system, which callers can examine to get information about an error. Two helper functions are added to reduce LoC-count for the library code itself. Also, some exceptions are made for running sparse on GIT_TLS definitions, since it doesn't grok thread-local variables at all. Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>