summaryrefslogtreecommitdiff
path: root/src/describe.c
Commit message (Collapse)AuthorAgeFilesLines
* str: introduce `git_str` for internal, `git_buf` is externalethomson/gitstrEdward Thomson2021-10-171-19/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Fix coding style for pointerpunkymaniac2021-09-091-1/+1
| | | | Make some syntax change to follow coding style.
* describe: use GIT_ASSERTEdward Thomson2020-11-271-2/+4
|
* buffer: git_buf_sanitize should return a valueEdward Thomson2020-11-251-1/+2
| | | | | | `git_buf_sanitize` is called with user-input, and wants to sanity-check that input. Allow it to return a value if the input was malformed in a way that we cannot cope.
* Fix crash in git_describe_commit when opts are NULL.Christoph Thelen2020-08-271-1/+1
| | | | | The argument "opts" can be NULL, which selects default options. Do not access "opts" directly but only the normalized copy.
* tree-wide: do not compile deprecated functions with hard deprecationPatrick Steinhardt2020-06-091-0/+4
| | | | | | | | | | | | | | | | | | | | | | When compiling libgit2 with -DDEPRECATE_HARD, we add a preprocessor definition `GIT_DEPRECATE_HARD` which causes the "git2/deprecated.h" header to be empty. As a result, no function declarations are made available to callers, but the implementations are still available to link against. This has the problem that function declarations also aren't visible to the implementations, meaning that the symbol's visibility will not be set up correctly. As a result, the resulting library may not expose those deprecated symbols at all on some platforms and thus cause linking errors. Fix the issue by conditionally compiling deprecated functions, only. While it becomes impossible to link against such a library in case one uses deprecated functions, distributors of libgit2 aren't expected to pass -DDEPRECATE_HARD anyway. Instead, users of libgit2 should manually define GIT_DEPRECATE_HARD to hide deprecated functions. Using "real" hard deprecation still makes sense in the context of CI to test we don't use deprecated symbols ourselves and in case a dependant uses libgit2 in a vendored way and knows it won't ever use any of the deprecated symbols anyway.
* global: convert trivial `fnmatch` users to use `wildcard`Patrick Steinhardt2019-06-151-2/+2
| | | | | | | | | | Upstream git.git has converted its codebase to use wildcard in favor of fnmatch in commit 70a8fc999d (stop using fnmatch (either native or compat), 2014-02-15). To keep our own regex-matching in line with what git does, convert all trivial instances of `fnmatch` usage to use `wildcard`, instead. Trivial usage is defined to be use of `fnmatch` with either no flags or flags that have a 1:1 equivalent in wildmatch (PATHNAME, IGNORECASE).
* posix: remove implicit include of "fnmatch.h"Patrick Steinhardt2019-06-151-1/+2
| | | | | | | | We're about to phase out our bundled fnmatch implementation as git.git has moved to wildmatch long ago in 2014. To make it easier to spot which files are stilll using fnmatch, remove the implicit "fnmatch.h" include in "posix.h" and instead include it explicitly.
* Rename opt init functions to `options_init`Edward Thomson2019-06-141-3/+13
| | | | | | | | | | | | | In libgit2 nomenclature, when we need to verb a direct object, we name a function `git_directobject_verb`. Thus, if we need to init an options structure named `git_foo_options`, then the name of the function that does that should be `git_foo_options_init`. The previous names of `git_foo_init_options` is close - it _sounds_ as if it's initializing the options of a `foo`, but in fact `git_foo_options` is its own noun that should be respected. Deprecate the old names; they'll now call directly to the new ones.
* oidmap: introduce high-level setter for key/value pairsPatrick Steinhardt2019-02-151-7/+2
| | | | | | | | | | | | | | | Currently, one would use either `git_oidmap_insert` to insert key/value pairs into a map or `git_oidmap_put` to insert a key only. These function have historically been macros, which is why their syntax is kind of weird: instead of returning an error code directly, they instead have to be passed a pointer to where the return value shall be stored. This does not match libgit2's common idiom of directly returning error codes.Furthermore, `git_oidmap_put` is tightly coupled with implementation details of the map as it exposes the index of inserted entries. Introduce a new function `git_oidmap_set`, which takes as parameters the map, key and value and directly returns an error code. Convert all trivial callers of `git_oidmap_insert` and `git_oidmap_put` to make use of it.
* oidmap: introduce high-level getter for valuesPatrick Steinhardt2019-02-151-6/+1
| | | | | | | | | | | | | | The current way of looking up an entry from a map is tightly coupled with the map implementation, as one first has to look up the index of the key and then retrieve the associated value by using the index. As a caller, you usually do not care about any indices at all, though, so this is more complicated than really necessary. Furthermore, it invites for errors to happen if the correct error checking sequence is not being followed. Introduce a new high-level function `git_oidmap_get` that takes a map and a key and returns a pointer to the associated value if such a key exists. Otherwise, a `NULL` pointer is returned. Adjust all callers that can trivially be converted.
* maps: use uniform lifecycle management functionsPatrick Steinhardt2019-02-151-2/+2
| | | | | | | | | | | | | | | | Currently, the lifecycle functions for maps (allocation, deallocation, resize) are not named in a uniform way and do not have a uniform function signature. Rename the functions to fix that, and stick to libgit2's naming scheme of saying `git_foo_new`. This results in the following new interface for allocation: - `int git_<t>map_new(git_<t>map **out)` to allocate a new map, returning an error code if we ran out of memory - `void git_<t>map_free(git_<t>map *map)` to free a map - `void git_<t>map_clear(git<t>map *map)` to remove all entries from a map This commit also fixes all existing callers.
* describe: don't mix and match abbreviated size typesEdward Thomson2019-01-251-2/+2
| | | | | The git_describe_format_options.abbreviated_size type is an unsigned int. There's no need for it to be anything else; keep it what it is.
* git_error: use new names in internal APIs and usageEdward Thomson2019-01-221-14/+14
| | | | | Move to the `git_error` name in the internal API for error-related functions.
* object_type: use new enumeration namesethomson/index_fixesEdward Thomson2018-12-011-6/+6
| | | | Use the new object_type enumeration names within the codebase.
* khash: remove intricate knowledge of khash typesPatrick Steinhardt2018-11-281-1/+1
| | | | | | | Instead of using the `khiter_t`, `git_strmap_iter` and `khint_t` types, simply use `size_t` instead. This decouples code from the khash stuff and makes it possible to move the khash includes into the implementation files.
* Make sure to always include "common.h" firstPatrick Steinhardt2017-07-031-1/+3
| | | | | | | | | | | | | | | | | | | | | | Next to including several files, our "common.h" header also declares various macros which are then used throughout the project. As such, we have to make sure to always include this file first in all implementation files. Otherwise, we might encounter problems or even silent behavioural differences due to macros or defines not being defined as they should be. So in fact, our header and implementation files should make sure to always include "common.h" first. This commit does so by establishing a common include pattern. Header files inside of "src" will now always include "common.h" as its first other file, separated by a newline from all the other includes to make it stand out as special. There are two cases for the implementation files. If they do have a matching header file, they will always include this one first, leading to "common.h" being transitively included as first file. If they do not have a matching header file, they instead include "common.h" as first file themselves. This fixes the outlined problems and will become our standard practice for header and source files inside of the "src/" from now on.
* oidmap: remove GIT__USE_OIDMAP macroPatrick Steinhardt2017-02-171-2/+0
|
* khash: avoid using macro magic to get return addressPatrick Steinhardt2017-02-171-1/+1
|
* giterr_set: consistent error messagesEdward Thomson2016-12-291-11/+11
| | | | | | | | 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
* git_object_dup: introduce typesafe versionsEdward Thomson2016-03-231-1/+1
|
* describe: handle error code returned by git_pqueue_insertPatrick Steinhardt2016-03-101-1/+2
|
* Remove extra semicolon outside of a functionStefan Widgren2015-07-311-1/+1
| | | | | Without this change, compiling with gcc and pedantic generates warning: ISO C does not allow extra ‘;’ outside of a function.
* describe: only abort without tags if fallback is not allowed.Patrick Steinhardt2015-04-071-1/+1
| | | | | | When no reference names could be found we did error out when trying to describe a commit. This is wrong, though, when the option to fall back to a commit's object ID is set.
* Reorder some khash declarationsCarlos Martín Nieto2015-03-111-0/+2
| | | | | | Keep the definitions in the headers, while putting the declarations in the C files. Putting the function definitions in headers causes them to be duplicated if you include two headers with them.
* Plug some leaksJacques Germishuys2014-12-291-2/+6
|
* describe: check error codesEdward Thomson2014-11-291-2/+2
|
* Fixed potential crash with uninitialized variablesPierre-Olivier Latour2014-10-271-1/+1
|
* Removed some useless variable assignmentsPierre-Olivier Latour2014-10-271-2/+0
|
* Clean up various compiler warningsEdward Thomson2014-10-261-2/+3
|
* Merge pull request #2609 from linquize/describe-optsEdward Thomson2014-10-131-15/+31
|\ | | | | Handle describe options better
| * describe: Initialize options for git_describe_format() if nullLinquize2014-10-111-14/+30
| |
| * describe: Do not crash if pass null option to git_describe_commit()Linquize2014-10-111-1/+1
| |
* | Don't use cl_git_pass for POSIX functionsrb/minor-cleanupsRussell Belfer2014-10-101-1/+1
|/ | | | | | | If there is a failure then cl_git_pass tries to get the libgit2 error, but p_... functions don't set that. Also - trailing whitespace cleanup.
* describe: make mingw happyCarlos Martín Nieto2014-09-301-2/+2
| | | | The MinGW compiler does not like it when we declare a typedef twice.
* describe: rename git_describe_opts to git_describe_optionsCarlos Martín Nieto2014-09-301-14/+24
| | | | And implement the option init functions for this and the format options.
* describe: implement abbreviated idsCarlos Martín Nieto2014-09-301-6/+27
|
* describe: implement describing the workdirCarlos Martín Nieto2014-09-301-6/+49
| | | | | | When we describe the workdir, we perform a describe on HEAD and then check to see if the worktree is dirty. If it is and we have a suffix string, we append that to the buffer.
* describe: split into gather and format stepsCarlos Martín Nieto2014-09-301-66/+173
| | | | | | | | Instead of printing out to the buffer inside the information-gathering phase, write the data to a intermediate result structure. This allows us to split the options into gathering options and formatting options, simplifying the gathering code.
* describe: rename _object() to _commit()Carlos Martín Nieto2014-09-301-1/+1
| | | | | We don't describe arbitrary object, so let's give it the name of the one object type we accept.
* object: introduce git_describe_object()nulltoken2014-04-301-0/+690