summaryrefslogtreecommitdiff
path: root/src/notes.c
Commit message (Collapse)AuthorAgeFilesLines
* str: introduce `git_str` for internal, `git_buf` is externalethomson/gitstrEdward Thomson2021-10-171-29/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Merge pull request #6045 from punkymaniac/qa-fix-coding-style-pointerEdward Thomson2021-09-141-3/+3
|\ | | | | Fix coding style for pointer
| * Fix coding style for pointerpunkymaniac2021-09-091-3/+3
| | | | | | | | Make some syntax change to follow coding style.
* | notes: use a buffer internallyethomson/notes_cleanupEdward Thomson2021-09-101-28/+28
|/ | | | Code cleanup to use `git_buf`s instead of simple c strings.
* notes: use GIT_ASSERTEdward Thomson2020-11-271-7/+8
|
* buffer: git_buf_sanitize should return a valueEdward Thomson2020-11-251-3/+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.
* notes: check error code returned by `git_iterator_advance`Patrick Steinhardt2020-02-071-3/+6
| | | | | | | | | | | | When calling `git_note_next`, we end up calling `git_iterator_advance` but ignore its error code. The intent is that we do not want to return an error if it returns `GIT_ITEROVER`, as we want to return that value on the next invocation of `git_note_next`. We should still check for any other error codes returned by `git_iterator_advance` to catch unexpected internal errors. Fix this by checking the function's return value, ignoring `GIT_ITEROVER`.
* blob: use `git_object_size_t` for object sizeEdward Thomson2019-11-221-1/+1
| | | | | Instead of using a signed type (`off_t`) use a new `git_object_size_t` for the sizes of objects.
* blob: add underscore to `from` functionsEdward Thomson2019-06-161-1/+1
| | | | | | The majority of functions are named `from_something` (with an underscore) instead of `fromsomething`. Update the blob functions for consistency with the rest of the library.
* blob: validate that blob sizes fit in a size_tEdward Thomson2019-01-251-1/+6
| | | | | | Our blob size is a `git_off_t`, which is a signed 64 bit int. This may be erroneously negative or larger than `SIZE_MAX`. Ensure that the blob size fits into a `size_t` before casting.
* git_error: use new names in internal APIs and usageEdward Thomson2019-01-221-7/+7
| | | | | Move to the `git_error` name in the internal API for error-related functions.
* treewide: remove use of C++ style commentsPatrick Steinhardt2018-07-131-1/+1
| | | | | | | | | C++ style comment ("//") are not specified by the ISO C90 standard and thus do not conform to it. While libgit2 aims to conform to C90, we did not enforce it until now, which is why quite a lot of these non-conforming comments have snuck into our codebase. Do a tree-wide conversion of all C++ style comments to the supported C style comments to allow us enforcing strict C90 compliance in a later commit.
* Convert usage of `git_buf_free` to new `git_buf_dispose`Patrick Steinhardt2018-06-101-1/+1
|
* notes: Rewrite funcs in terms of note_commit funcsRichard Ipsum2017-12-021-81/+86
|
* notes: Add git_note_commit_iterator_newRichard Ipsum2017-10-071-0/+19
| | | | This also adds tests for this function.
* notes: Add git_note_commit_removeRichard Ipsum2017-10-071-2/+35
| | | | This also adds tests for this function.
* notes: Add git_note_commit_readRichard Ipsum2017-10-071-0/+22
| | | | This also adds tests for this function.
* notes: Add git_note_commit_createRichard Ipsum2017-10-071-0/+31
| | | | | | | | | | This adds a new function that will allow creation of notes without necessarily updating a particular ref, the notes tree is obtained from the git_commit object parameter, a new commit object pointing to the current tip of the notes tree is optionally returned via the 'note_commit_out' parameter, optionally the blob id for the note is returned through the 'note_blob_out' object.
* notes: Make note_write return commit oidRichard Ipsum2017-09-231-4/+10
| | | | | For the new 'commit' API it will be necessary to know the OID of the notes commit that was written as well as the OID of the notes blob.
* giterr_set: consistent error messagesEdward Thomson2016-12-291-3/+3
| | | | | | | | 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
* iterator: use an options struct instead of argsEdward Thomson2015-08-281-1/+1
|
* note: use a git_buf to return the default namespacecmn/notes-bufCarlos Martín Nieto2015-03-171-21/+40
| | | | | | | The caller has otherwise no way to know how long the string will be allocated or ability to free it. This fixes #2944.
* allocations: test for overflow of requested sizeEdward Thomson2015-02-121-1/+1
| | | | | Introduce some helper macros to test integer overflow from arithmetic and set error message appropriately.
* treebuilder: rename _create() to _new()cmn/treebuilder-newCarlos Martín Nieto2014-12-271-1/+1
| | | | | | This function is a constructor, so let's name it like one and leave _create() for the reference functions, which do create/write the reference.
* treebuilder: take a repository for path validationEdward Thomson2014-12-171-2/+2
| | | | | | Path validation may be influenced by `core.protectHFS` and `core.protectNTFS` configuration settings, thus treebuilders can take a repository to influence their configuration.
* notes: move the notes name argumentCarlos Martín Nieto2014-12-061-1/+1
| | | | | Make it consistent between git_note_create() and git_note_remote() by putting it after the repository.
* notes: Use `git__strndup`Vicent Marti2014-11-211-3/+2
|
* notes: Do not assume blob contents are NULL-terminatedVicent Marti2014-11-211-3/+3
|
* Introduce `git_note_author`, `git_note_committer`Edward Thomson2014-10-261-4/+31
|
* index: rename an entry's id to 'id'Carlos Martín Nieto2014-01-251-1/+1
| | | | This was not converted when we converted the rest, so do it now.
* note: rename the id getter to git_note_id()Carlos Martín Nieto2014-01-241-3/+3
| | | | This was left over when we did the general switch.
* One more rename/cleanup for callback err functionsRussell Belfer2013-12-111-1/+1
|
* Further callback error check style fixesRussell Belfer2013-12-111-4/+6
| | | | | Okay, I've decided I like the readability of this style much better so I used it everywhere.
* Remove converting user error to GIT_EUSERRussell Belfer2013-12-111-6/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Further EUSER and error propagation fixesRussell Belfer2013-12-111-1/+1
| | | | | | | | | | | | | This continues auditing all the places where GIT_EUSER is being returned and making sure to clear any existing error using the new giterr_user_cancel helper. As a result, places that relied on intercepting GIT_EUSER but having the old error preserved also needed to be cleaned up to correctly stash and then retrieve the actual error. Additionally, as I encountered places where error codes were not being propagated correctly, I tried to fix them up. A number of those fixes are included in the this commit as well.
* Add config read fns with controlled error behaviorRussell Belfer2013-12-111-12/+3
| | | | | | | | | | | | | | | | | | | | | | | | This adds `git_config__lookup_entry` which will look up a key in a config and return either the entry or NULL if the key was not present. Optionally, it can either suppress all errors or can return them (although not finding the key is not an error for this function). Unlike other accessors, this does not normalize the config key string, so it must only be used when the key is known to be in normalized form (i.e. all lower-case before the first dot and after the last dot, with no invalid characters). This also adds three high-level helper functions to look up config values with no errors and a fallback value. The three functions are for string, bool, and int values, and will resort to the fallback value for any error that arises. They are: * `git_config__get_string_force` * `git_config__get_bool_force` * `git_config__get_int_force` None of them normalize the config `key` either, so they can only be used for internal cases where the key is known to be in normal format.
* Make iterators use GIT_ITEROVER & smart advanceRussell Belfer2013-05-311-10/+4
| | | | | | | | | | | | | | | 1. internal iterators now return GIT_ITEROVER when you go past the last item in the iteration. 2. git_iterator_advance will "advance" to the first item in the iteration if it is called immediately after creating the iterator, which allows a simpler idiom for basic iteration. 3. if git_iterator_advance encounters an error reading data (e.g. a missing tree or an unreadable file), it returns the error but also attempts to advance past the invalid data to prevent an infinite loop. Updated all tests and internal usage of iterators to account for these new behaviors.
* Unify whitespaces to tabsLinquize2013-05-151-19/+19
|
* Report errors finding notesRussell Belfer2013-05-011-19/+22
|
* Make iterator APIs consistent with standardsRussell Belfer2013-03-061-3/+3
| | | | | | | | | | | | The iterator APIs are not currently consistent with the parameter ordering of the rest of the codebase. This rearranges the order of parameters, simplifies the naming of a number of functions, and makes somewhat better use of macros internally to clean up the iterator code. This also expands the test coverage of iterator functionality, making sure that case sensitive range-limited iteration works correctly.
* added missing free for git_note in clar testsNico von Geyso2013-03-061-1/+1
|
* fixed minor issues with new note iteratorNico von Geyso2013-03-061-49/+37
| | | | | * fixed style issues * use new iterator functions for git_note_foreach()
* use git_note_iterator type instead of non-public git_iterator oneNico von Geyso2013-03-061-4/+13
|
* basic note iterator implementationNico von Geyso2013-03-061-9/+59
| | | | | * git_note_iterator_new() - create a new note iterator * git_note_next() - retrieves the next item of the iterator
* Clear up warnings from cppcheckRussell Belfer2013-02-151-1/+1
| | | | | | | | | | | | The cppcheck static analyzer generates warnings for a bunch of places in the libgit2 code base. All the ones fixed in this commit are actually false positives, but I've reorganized the code to hopefully make it easier for static analysis tools to correctly understand the structure. I wouldn't do this if I felt like it was making the code harder to read or worse for humans, but in this case, these fixes don't seem too bad and will hopefully make it easier for better analysis tools to get at any real issues.
* update copyrightsEdward Thomson2013-01-081-1/+1
|
* add option to allow git note overwriteNikolai Vladimirov2013-01-031-4/+7
|
* notes.c - whitespace fixNikolai Vladimirov2013-01-031-6/+6
|
* Clean up iterator APIsRussell Belfer2012-12-101-1/+1
| | | | | | | | This removes the need to explicitly pass the repo into iterators where the repo is implied by the other parameters. This moves the repo to be owned by the parent struct. Also, this has some iterator related updates to the internal diff API to lay the groundwork for checkout improvements.
* Remove GIT_SIGNATURE_VERSION and friendsBen Straub2012-12-031-6/+0
|