src/common.h


Log

Author Commit Date CI Message
Edward Thomson f0e693b1 2021-09-07T17:53:49 str: introduce `git_str` for internal, `git_buf` is external libgit2 has two distinct requirements that were previously solved by `git_buf`. We require: 1. A general purpose string class that provides a number of utility APIs for manipulating data (eg, concatenating, truncating, etc). 2. A structure that we can use to return strings to callers that they can take ownership of. By using a single class (`git_buf`) for both of these purposes, we have confused the API to the point that refactorings are difficult and reasoning about correctness is also difficult. Move the utility class `git_buf` to be called `git_str`: this represents its general purpose, as an internal string buffer class. The name also is an homage to Junio Hamano ("gitstr"). The public API remains `git_buf`, and has a much smaller footprint. It is generally only used as an "out" param with strict requirements that follow the documentation. (Exceptions exist for some legacy APIs to avoid breaking callers unnecessarily.) Utility functions exist to convert a user-specified `git_buf` to a `git_str` so that we can call internal functions, then converting it back again.
lhchavez b060080e 2021-07-30T06:53:49 Get Win32 builds to build Previously, the location of `GIT_WARN_UNUSED_RESULT` was causing it to be included _after_ a bunch of other headers (namely `src/vector.h`), which broke the build. This change does two things: * Moves the `GIT_WARN_UNUSED_RESULT` above most of the `$include`s in `src/common.h`. * Stops including `vector.h` from `src/win32/path_w32.c` since the header itself does not use it.
lhchavez 4e8376a9 2021-07-30T06:34:15 Move GIT_WARN_UNUSED_RESULT from the public to the private API
Peter Pettersson 88a3b8e1 2021-07-26T23:12:12 common.h: use inline when compiling for c99 and later
Edward Thomson 1d95b59b 2021-04-14T15:47:27 utf8: refactor utf8 functions Move the utf8 functions into a proper namespace `git_utf8` instead of being in the namespaceless `git__` function group. Update them to have out-params first and use `char *` instead of `uint8_t *` to match our API treating strings as `char *` (even if they truly contain `uchar`s inside).
Edward Thomson 42d5f110 2020-12-08T14:33:31 win32: provide macros for calling conventions Provide more clarity for Win32 calling conventions - now that we always compile to __cdecl on Win32, we'll define that as the the libgit2 calling convention. Also offer NTAPI (__stdcall) calling conventions for things that need callbacks from NTAPI code (eg fiber-local storage).
Edward Thomson 404dd024 2020-12-05T15:57:48 threads: rename thread files to thread.[ch]
Edward Thomson a95096ba 2020-01-12T10:31:07 assert: optionally fall-back to assert(3) Fall back to the system assert(3) in debug builds, which may aide in debugging. "Safe" assertions can be enabled in debug builds by setting GIT_ASSERT_HARD=0. Similarly, hard assertions can be enabled in release builds by setting GIT_ASSERT_HARD to nonzero.
Edward Thomson abe2efe1 2019-12-09T12:37:34 Introduce GIT_ASSERT macros Provide macros to replace usages of `assert`. A true `assert` is punishing as a library. Instead we should do our best to not crash. GIT_ASSERT_ARG(x) will now assert that the given argument complies to some format and sets an error message and returns `-1` if it does not. GIT_ASSERT(x) is for internal usage, and available as an internal consistency check. It will set an error message and return `-1` in the event of failure.
Patrick Steinhardt f585b129 2019-09-12T14:29:28 posix: remove superseded POSIX regex wrappers The old POSIX regex wrappers have been superseded by our own regexp API that provides a higher-level abstraction. Remove the POSIX wrappers in favor of the new one.
Edward Thomson fe1fb36e 2019-01-13T21:10:50 win32: move type definitions for improved inclusion Move some win32 type definitions to a standalone file so that they can be included before other header files try to use the definitions.
Edward Thomson 02683b20 2019-01-12T23:06:39 regexec: prefix all regexec function calls with p_ Prefix all the calls to the the regexec family of functions with `p_`. This allows us to swap out all the regular expression functions with our own implementation. Move the declarations to `posix_regex.h` for simpler inclusion.
Edward Thomson 24ac9e0c 2019-02-13T23:26:54 deprecation: ensure we GIT_EXTERN deprecated funcs Although the error functions were deprecated, we did not properly mark them as deprecated. We need to include the `deprecated.h` file in order to ensure that the functions get their export attributes. Similarly, do not define `GIT_DEPRECATE_HARD` within the library, or those functions will also not get their export attributes. Define that only on the tests and examples.
Edward Thomson f673e232 2018-12-27T13:47:34 git_error: use new names in internal APIs and usage Move to the `git_error` name in the internal API for error-related functions.
Patrick Steinhardt f347a441 2018-06-25T11:55:13 treewide: avoid use of `inline` attribute ISO C90 does not specify the `inline` attribute, and as such we cannot use it in our code. While we already use `__inline` when building in Microsoft Visual Studio, we should also be using the `__inline__` attribute from GCC/Clang. Otherwise, if we're using neither MSVC nor GCC/Clang, we should simply avoid using `inline` at all and just define functions as static. This commit adjusts our own `GIT_INLINE` macro as well as the inline macros specified by khash and xdiff. This allows us to enable strict C90 mode in a later commit.
Edward Thomson 26f5d36d 2018-02-04T10:27:39 Merge pull request #4489 from libgit2/ethomson/conflicts_crlf Conflict markers should match EOL style in conflicting files
Edward Thomson abb04caa 2018-02-01T15:55:48 consistent header guards use consistent names for the #include / #define header guard pattern.
Edward Thomson 7f52bc5a 2018-01-20T18:19:26 xdiff: upgrade to git's included xdiff Upgrade xdiff to git's most recent version, which includes changes to CR/LF handling. Now CR/LF included in the input files will be detected and conflict markers will be emitted with CR/LF when appropriate.
Patrick Steinhardt 26f531d3 2017-09-12T13:35:18 features.h: allow building without CMake-generated feature header In commit a390a8464 (cmake: move defines into "features.h" header, 2017-07-01), we have introduced a new "features.h" header. This file is being generated by the CMake build system based on how the libgit2 build has been configured, replacing the preexisting method of simply setting the defines inside of the CMake build system. This was done to help splitting up the build instructions into multiple separate subdirectories. An overlooked shortcoming of this approach is that some projects making use of libgit2 build the library with custom build systems, without making use of CMake. For those users, the introduction of the "features.h" file makes their life harder as they would have to also generate this file. Fix this issue by guarding all inclusions of the generated header file by the `LIBGIT2_NO_FEATURES_H` define. Like this, other build systems can skip the feature header and simply define all used features by specifying `-D` flags for the compiler again.
Patrick Steinhardt a390a846 2017-07-01T13:06:00 cmake: move defines into "features.h" header In a future commit, we will split out the build instructions for our library directory and move them into a subdirectory. One of the benefits is fixing scoping issues, where e.g. defines do not leak to build targets where they do not belong to. But unfortunately, this does also pose the problem of how to propagate some defines which are required by both the library and the test suite. One way would be to create another variable keeping track of all added defines and declare it inside of the parent scope. While this is the most obvious and simplest way of going ahead, it is kind of unfortunate. The main reason to not use this is that these defines become implicit dependencies between the build targets. By simply observing a define inside of the CMakeLists.txt file, one cannot reason whether this define is only required by the current target or whether it is required by different targets, as well. Another approach would be to use an internal header file keeping track of all defines shared between targets. While configuring the library, we will set various variables and let CMake configure the file, adding or removing defines based on what has been configured. Like this, one can easily keep track of the current environment by simply inspecting the header file. Furthermore, these dependencies are becoming clear inside the CMakeLists.txt, as instead of simply adding a define, we now call e.g. `SET(GIT_THREADSAFE 1)`. Having this header file though requires us to make sure it is always included before any "#ifdef"-preprocessor checks are executed. As we have already refactored code to always include the "common.h" header file before any statement inside of a file, this becomes easy: just make sure "common.h" includes the new "features.h" header file first.
Patrick Steinhardt 459fb8fe 2017-06-30T15:35:46 win32: fix circular include deps with w32_crtdbg The current order of declarations and includes between "common.h" and "w32_crtdbg_stacktrace.h" is rather complicated. Both header files make use of things defined in the other one and are thus circularly dependent on each other. This makes it currently impossible to compile the "w32_crtdbg_stacktrace.c" file when including "common.h" inside of "w32_crtdbg_stacktrace.h". We can disentangle the mess by moving declaration of the inline crtdbg functions into the "w32_crtdbg_stacktrace.h" file and adding additional includes inside of it, such that all required functions are available to it. This allows us to break the dependency cycle.
Edward Thomson 909d5494 2016-12-29T12:25:15 giterr_set: consistent error messages Error messages should be sentence fragments, and therefore: 1. Should not begin with a capital letter, 2. Should not conclude with punctuation, and 3. Should not end a sentence and begin a new one
Patrick Steinhardt 8effd26f 2016-11-14T09:54:08 common: mark printf-style formatting for `giterr_set`
Patrick Steinhardt 8aaa9fb6 2016-06-20T18:21:42 win32: rename pthread.{c,h} to thread.{c,h} The old pthread-file did re-implement the pthreads API with exact symbol matching. As the thread-abstraction has now been split up between Unix- and Windows-specific files within the `git_` namespace to avoid symbol-clashes between libgit2 and pthreads, the rewritten wrappers have nothing to do with pthreads anymore. Rename the Windows-specific pthread-files to honor this change.
Patrick Steinhardt 859ed5dd 2016-02-23T09:54:26 common: introduce GITERR_CHECK_ALLOC_BUF We commonly have to check if a git_buf has been allocated correctly or if we ran out of memory. Introduce a new macro similar to `GITERR_CHECK_ALLOC` which checks if we ran OOM and if so returns an error. Provide a `#nodef` for Coverity to mark the error case as an abort path.
Edward Thomson 9447b9e5 2016-02-09T10:40:33 xplat: use st_mtimespec everywhere on mac
Carlos Martín Nieto 75a0ccf5 2015-11-12T19:53:09 Merge pull request #3170 from CmdrMoozy/nsec_fix git_index_entry__init_from_stat: set nsec fields in entry stats
Edward Thomson 4bc9b74c 2015-09-28T16:24:50 GITERR_CHECK_ALLOC_ADDn: multi-arg adders
Axel Rasmussen 360dd4da 2015-06-23T10:02:48 win32: define our own POSIX struct stat, and support USE_NSEC
Edward Thomson ef4857c2 2015-08-03T16:50:27 errors: tighten up git_error_state OOMs a bit more When an error state is an OOM, make sure that we treat is specially and do not try to free it.
Jeff Hostetler 93b42728 2015-06-09T14:38:30 Include stacktrace summary in memory leak output.
J Wyman 7dd22538 2015-05-11T10:19:25 centralizing all IO buffer size values
Aki Koskinen 45df2237 2015-02-27T10:53:39 Include ws2tcpip.h in order to get in6_addr It's currently required in src/openssl_stream.c only.
Edward Thomson 16942c6f 2015-02-12T17:36:48 integer overflow: use compiler intrinsics if supported gcc and clang support __builtin_add_overflow, use it whenever possible, falling back to our naive routines.
Edward Thomson f1453c59 2015-02-12T12:19:37 Make our overflow check look more like gcc/clang's Make our overflow checking look more like gcc and clang's, so that we can substitute it out with the compiler instrinsics on platforms that support it. This means dropping the ability to pass `NULL` as an out parameter. As a result, the macros also get updated to reflect this as well.
Edward Thomson 190b76a6 2015-02-11T14:52:08 Introduce git__add_sizet_overflow and friends Add some helper functions to check for overflow in a type-specific manner.
Edward Thomson 2884cc42 2015-02-11T09:39:38 overflow checking: don't make callers set oom Have the ALLOC_OVERFLOW testing macros also simply set_oom in the case where a computation would overflow, so that callers don't need to.
Edward Thomson 392702ee 2015-02-09T23:41:13 allocations: test for overflow of requested size Introduce some helper macros to test integer overflow from arithmetic and set error message appropriately.
Edward Thomson 710f66af 2015-02-03T18:41:15 bswap: remove unused bswap
Will Stamper b874629b 2014-12-04T21:06:59 Spelling fixes
Russell Belfer 702efc89 2014-04-30T10:57:42 Make init_options fns use unsigned ints and macro Use an unsigned int for the version and add a helper macro so the code is simplified (and so the error message is a common string).
Jacques Germishuys 6b05240c 2014-04-27T19:44:20 strcasecmp is in <strings.h>
Russell Belfer 8a2834d3 2014-03-14T13:20:51 Index locking and entry allocation changes This makes the lock management on the index a little bit broader, having a number of routines hold the lock across looking up the item to be modified and actually making the modification. Still not true thread safety, but more pure index modifications are now safe which allows the simple cases (such as starting up a diff while index modifications are underway) safe enough to get the snapshot without hitting allocation problems. As part of this, I simplified the allocation of index entries to use a flex array and just put the path at the end of the index entry. This makes every entry self-contained and makes it a little easier to feel sure that pointers to strings aren't being accidentally copied and freed while other references are still being held.
Russell Belfer 72556cc6 2014-02-20T14:27:10 Address PR comments * Make GIT_INLINE an internal definition so it cannot be used in public headers * Fix language in CONTRIBUTING * Make index caps API use signed instead of unsigned values
Russell Belfer 26c1cb91 2013-12-09T09:44:03 One more rename/cleanup for callback err functions
Russell Belfer 60058018 2013-12-06T15:20:41 Fix C99 __func__ for MSVC
Russell Belfer 25e0b157 2013-12-06T15:07:57 Remove converting user error to GIT_EUSER This changes the behavior of callbacks so that the callback error code is not converted into GIT_EUSER and instead we propagate the return value through to the caller. Instead of using the giterr_capture and giterr_restore functions, we now rely on all functions to pass back the return value from a callback. To avoid having a return value with no error message, the user can call the public giterr_set_str or some such function to set an error message. There is a new helper 'giterr_set_callback' that functions can invoke after making a callback which ensures that some error message was set in case the callback did not set one. In places where the sign of the callback return value is meaningful (e.g. positive to skip, negative to abort), only the negative values are returned back to the caller, obviously, since the other values allow for continuing the loop. The hardest parts of this were in the checkout code where positive return values were overloaded as meaningful values for checkout. I fixed this by adding an output parameter to many of the internal checkout functions and removing the overload. This added some code, but it is probably a better implementation. There is some funkiness in the network code where user provided callbacks could be returning a positive or a negative value and we want to rely on that to cancel the loop. There are still a couple places where an user error might get turned into GIT_EUSER there, I think, though none exercised by the tests.
Russell Belfer 96869a4e 2013-12-03T16:45:39 Improve GIT_EUSER handling This adds giterr_user_cancel to return GIT_EUSER and clear any error message that is sitting around. As a result of using that in places, we need to be more thorough with capturing errors that happen inside a callback when used internally. To help with that, this also adds giterr_capture and giterr_restore so that when we internally use a foreach-type function that clears errors and converts them to GIT_EUSER, it is easier to restore not just the return value, but the actual error message text.
Edward Thomson 5588f073 2013-12-09T10:25:36 Clean up warnings
Edward Thomson c2408a69 2013-11-01T17:03:01 preserve windows error numbers as well
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.