summaryrefslogtreecommitdiff
path: root/src/util.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix warnings on 64-bit windows buildsRussell Belfer2012-04-171-2/+3
| | | | | This fixes all the warnings on win64 except those in deps, which come from the regex code.
* Add support for pathspec to diff and statusRussell Belfer2012-04-131-0/+29
| | | | | | | This adds preliminary support for pathspecs to diff and status. The implementation is not very optimized (it still looks at every single file and evaluated the the pathspec match against them), but it works.
* Migrate index, oid, and utils to new errorsRussell Belfer2012-03-191-10/+16
| | | | | | | | | | | | This includes a few cleanups that came up while converting these files. This commit introduces a could new git error classes, including the catchall class: GITERR_INVALID which I'm using as the class for invalid and out of range values which are detected at too low a level of library to use a higher level classification. For example, an overflow error in parsing an integer or a bad letter in parsing an OID string would generate an error in this class.
* Convert attr, ignore, mwindow, status to new errorsRussell Belfer2012-03-161-2/+3
| | | | | Also cleaned up some previously converted code that still had little things to polish.
* Migrating diff to new error handlingRussell Belfer2012-03-061-6/+9
| | | | | | Ended up migrating a bunch of upstream functions as well including vector, attr_file, and odb in order to get this to work right.
* Update Copyright headerschu2012-02-131-1/+1
| | | | Signed-off-by: schu <schu-github@schulog.org>
* Improved gitattributes macro implementationRussell Belfer2011-12-301-15/+23
| | | | | | | | | | | | | This updates to implementation of gitattribute macros to be much more similar to core git (albeit not 100%) and to handle expansion of macros within macros, etc. It also cleans up the refcounting usage with macros to be much cleaner. Also, this adds a new vector function `git_vector_insert_sorted()` which allows you to maintain a sorted list as you go. In order to write that function, this changes the function `git__bsearch()` to take a somewhat different set of parameters, although the core functionality is still the same.
* global: Properly use `git__` memory wrappersVicent Marti2011-10-281-2/+2
| | | | | Ensure that all memory related functions (malloc, calloc, strdup, free, etc) are using their respective `git__` wrappers.
* config: Proper type declarations for 64 bit intsVicent Marti2011-09-301-5/+6
|
* config: make git_config_[get|set]_long() able to properly deal with 8 bytes ↵nulltoken2011-09-221-2/+19
| | | | | | | | wide values Should fix issue #419. Signed-off-by: nulltoken <emeric.fermas@gmail.com>
* Tabify everythingVicent Marti2011-09-191-23/+23
| | | | | | 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.
* Cleanup legal dataVicent Marti2011-09-191-0/+6
| | | | | | | | | | 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.
* Fix some random size_t vs. int conversion warningsSebastian Schuberth2011-09-081-2/+2
|
* posix: Properly handle `snprintf` in all platformsVicent Marti2011-08-181-14/+1
|
* util: Add git__strcmp_cb() wrappernulltoken2011-08-091-0/+13
| | | | We don't want direct pointers to the CRT on Windows, we may get stdcall conflicts.
* win32: replace usage of _MSV_VER with _MSC_VERnulltoken2011-07-091-1/+1
|
* vector: Timsort all of the thingsVicent Marti2011-07-071-59/+20
| | | | | | | | | | | | | | | | | | | | | | | | Drop the GLibc implementation of Merge Sort and replace it with Timsort. The algorithm has been tuned to work on arrays of pointers (void **), so there's no longer a need to abstract the byte-width of each element in the array. All the comparison callbacks now take pointers-to-elements, not pointers-to-pointers, so there's now one less level of dereferencing. E.g. int index_cmp(const void *a, const void *b) { - const git_index_entry *entry_a = *(const git_index_entry **)(a); + const git_index_entry *entry_a = (const git_index_entry *)(a); The result is up to a 40% speed-up when sorting vectors. Memory usage remains lineal. A new `bsearch` implementation has been added, whose callback also supplies pointer-to-elements, to uniform the Vector API again.
* Merge pull request #296 from kiryl/index-optimizationVicent Martí2011-07-061-0/+64
|\ | | | | Index optimization
| * util: introduce merge sort routineKirill A. Shutemov2011-07-051-0/+64
| | | | | | | | | | | | | | | | | | | | | | | | In some cases it's important to preserve order of elements with equal keys (stable sort). qsort(3) doesn't define order of elements with equal keys. git__msort() implements merge sort which is stable sort. Implementation taken from git. Function renamed git_qsort() -> git__msort(). Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
* | fnmatch: Use native on Unix, emulate on Win32Vicent Marti2011-07-061-4/+2
|/
* Merge pull request #300 from carlosmn/gsoc2011/masterVicent Martí2011-07-051-0/+22
|\ | | | | A bit of networking
| * Add git.git's fnmatch, which is really GNU's and the git__fnmatch wrapperCarlos Martín Nieto2011-06-261-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | If the strings match, git__fnmatch returns GIT_SUCCESS and GIT_ENOMATCH on failure to match. MSVC fixes: Added a test for _MSC_VER and (in that case) defined HAVE_STRING_H to 1 so it doesn't try to include <strings.h> which doesn't exist in the MSVC world. Moved the function declarations to use the modern inline ones so MSVC doesn't have a fit. Added casts everywhere so MSVC doesn't crap its pants. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
* | fileops: CleanupVicent Marti2011-07-051-200/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Cleaned up the structure of the whole OS-abstraction layer. fileops.c now contains a set of utility methods for file management used by the library. These are abstractions on top of the original POSIX calls. There's a new file called `posix.c` that contains emulations/reimplementations of all the POSIX calls the library uses. These are prefixed with `p_`. There's a specific posix file for each platform (win32 and unix). All the path-related methods have been moved from `utils.c` to `path.c` and have their own prefix.
* | cleanup: remove trailing spacesKirill A. Shutemov2011-07-011-8/+8
|/ | | | Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
* Add method to get the compiled version of the libVicent Marti2011-06-161-0/+8
|
* odb: Fix loading ODB alternatesVicent Marti2011-06-031-16/+18
| | | | | Fixed an issue with the `strtokz implementation and added support for comments and relative paths in the alternates file.
* Fix compilation warnings in MSVCnulltoken2011-05-241-1/+1
| | | | This allows to successfully build libgit2 with waf on Windows.
* util.c: Move to new error handling mechanismJakob Pfender2011-05-231-3/+3
|
* utils: Move git__str[n]tolowerVicent Marti2011-05-171-0/+14
|
* Properly check `strtol` for errorsVicent Marti2011-04-091-0/+79
| | | | | We are now using a custom `strtol` implementation to make sure we're not missing any overflow errors.
* Add detection of incorrect usage to git__joinpath()nulltoken2011-03-231-0/+3
|
* Export `git_strarray_free` instead of inliningVicent Marti2011-03-161-0/+9
| | | | That way non-C bindings can use it.
* Use memmove() in git__dirname and git__basenameVicent Marti2011-03-051-2/+2
| | | | | | | We cannot make sure that the user doesn't use the same buffer as source and destination, so write to it using memmove. Signed-off-by: Vicent Marti <tanoku@gmail.com>
* Use memmove() in git__joinpath for overlapping copiesVicent Marti2011-03-051-1/+1
| | | | Signed-off-by: Vicent Marti <tanoku@gmail.com>
* Slightly changed the behavior of git__joinpath() and git__joinpath_n().nulltoken2011-03-031-1/+5
|
* Use the new git__joinpath to build paths in methodsVicent Marti2011-02-091-18/+18
| | | | | | | | | | | | | | | | | The `git__joinpath` function has been changed to use a statically allocated buffer; we assume the buffer to be 4096 bytes, because fuck you. The new method also supports an arbritrary number of paths to join, which may come in handy in the future. Some methods which were manually joining paths with `strcpy` now use the new function, namely those in `index.c` and `refs.c`. Based on Emeric Fermas' original patch, which was using the old `git__joinpath` because I'm stupid. Thanks! Signed-off-by: Vicent Marti <tanoku@gmail.com>
* Fixed a small issue in git__join_path(). Added tests to exercise ↵nulltoken2011-02-051-1/+3
| | | | git__join_path().
* Add new utility method `git__joinpath`Vicent Marti2011-02-051-0/+24
| | | | Signed-off-by: Vicent Marti <tanoku@gmail.com>
* Fix directory/path manipulation methodsVicent Marti2011-02-051-38/+166
| | | | | | | | | | | | | | | | | | | | | | | | | The `dirname` and `dirbase` methods have been replaced with the Android implementation, which is actually compilant to some kind of standard. A new method `topdir` has been added, which returns the topmost directory in a path. These changes fix issue #49: `gitfo_prettify_dir_path` converts "./.git/" to ".git/", so the code at src/repository.c:190 goes out of bounds when trying to find the topmost directory. The new `git__topdir` method handles this gracefully, and the fixed `git__dirname` now returns the proper value for the repository's working dir. E.g. /repo/.git/ ==> working dir '/repo/' .git/ ==> working dir '.' Signed-off-by: Vicent Marti <tanoku@gmail.com>
* Add generic hash function to util.cVicent Marti2010-12-301-0/+96
| | | | | | | | | | | | It's MurmurHash3 slightly edited to make it cross-platform. Fast and neat. Use this for hashing strings on hash tables instead of a full SHA1 hash. It's very fast and well distributed. Obviously not crypto-secure. Signed-off-by: Vicent Marti <tanoku@gmail.com>
* Remove git_errnoVicent Marti2010-12-231-24/+0
| | | | | | | | | 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>
* Fix wrong pointer check in git__strdupVicent Marti2010-11-191-1/+1
| | | | Signed-off-by: Vicent Marti <tanoku@gmail.com>
* Add auxiliary method git__hexdumpVicent Marti2010-08-121-0/+44
| | | | | | | New function in util.c to do a dump of a buffer's contents in hexadecimal to stdout. Signed-off-by: Vicent Marti <tanoku@gmail.com>
* Fix some "signed v unsigned comparison" warnings with -WextraRamsay Jones2010-01-201-1/+1
| | | | Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
* Fix some "signed/unsigned mismatch" (msvc) compiler warningsRamsay Jones2009-06-051-2/+2
| | | | | Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Andreas Ericsson <ae@op5.se>
* Fix some (digital-mars) compiler warningsRamsay Jones2009-03-171-2/+2
| | | | | | | | | | | In particular, conditional expressions which contain an assignment statement, where the expression type is not explicitly made to be boolean, elicits the following message: warning 2: possible unintended assignment Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* Add git__dirname and git__basename utility routinesRamsay Jones2009-01-281-0/+62
| | | | | | | | | | These routines are intended to extract the directory and base name from a path string. Note that these routines do not interact with any filesystem and work only on the text of the path. Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* Add git__fmt as an easier to use snprintfShawn O. Pearce2008-12-311-0/+15
| | | | | | | | 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>
* Add string utility functions for prefix and suffix comparesShawn O. Pearce2008-12-311-0/+20
| | | | Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* Wrap malloc and friends and report out of memory as GIT_ENOMEMShawn O. Pearce2008-12-301-0/+26
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>