summaryrefslogtreecommitdiff
path: root/src/diff_print.c
Commit message (Collapse)AuthorAgeFilesLines
* refactor: `src` is now `src/libgit2`Edward Thomson2022-02-221-825/+0
|
* str: introduce `git_str` for internal, `git_buf` is externalethomson/gitstrEdward Thomson2021-10-171-95/+102
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* diff: use GIT_ASSERTEdward Thomson2020-11-271-4/+8
|
* buffer: git_buf_sanitize should return a valueEdward Thomson2020-11-251-2/+11
| | | | | | `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.
* diff_print: adjust code to match current coding stylePatrick Steinhardt2020-06-171-44/+32
|
* diff_print: return out-of-memory situation when printing binaryPatrick Steinhardt2020-06-171-0/+3
| | | | | | We currently don't check for out-of-memory situations on exiting `format_binary` and, as a result, may return a partially filled buffer. Fix this by checking the buffer via `git_buf_oom`.
* diff_print: do not call abort(3P)Patrick Steinhardt2020-06-171-3/+2
| | | | | | | | | | Calling abort(3P) in a library is rather rude and shouldn't happen, as we effectively prohibit any corrective actions made by the application linking to it. We thus shouldn't call it at all, but instead use our new `GIT_ASSERT` macros. Remove the call to abort(3P) in case a diff delta has an unexpected type to fix this.
* diff_print: handle errors when printing to filePatrick Steinhardt2020-06-171-5/+18
| | | | | | | | | | | When printing the diff to a `FILE *` handle, we neither check the return value of fputc(3P) nor the one of fwrite(3P). As a result, we'll silently return successful even if we didn't print anything at all. Futhermore, the arguments to fwrite(3P) are reversed: we have one item of length `content_len`, and not `content_len` items of one byte. Fix both issues by checking return values as well as reversing the arguments to fwrite(3P).
* tree-wide: mark local functions as staticPatrick Steinhardt2020-06-091-1/+1
| | | | | | | We've accumulated quite some functions which are never used outside of their respective code unit, but which are lacking the `static` keyword. Add it to reduce their linkage scope and allow the compiler to optimize better.
* patch: correctly handle mode changes for renamesPatrick Steinhardt2020-03-261-7/+7
| | | | | | | | | | | When generating a patch for a renamed file whose mode bits have changed in addition to the rename, then we currently fail to parse the generated patch. Furthermore, when generating a diff we output mode bits after the similarity metric, which is different to how upstream git handles it. Fix both issues by adding another state transition that allows similarity indices after mode changes and by printing mode changes before the similarity index.
* diff_print: add support for GIT_DIFF_FORMAT_PATCH_ID.Gregory Herrero2019-11-191-1/+6
| | | | | | | Git is generating patch-id using a stripped down version of a patch where hunk header and index information are not present. Signed-off-by: Gregory Herrero <gregory.herrero@oracle.com>
* diff_print: add a new 'print_index' flag when printing diff.Gregory Herrero2019-11-191-7/+14
| | | | | | | | | Add a new 'print_index' flag to let the caller decide whether or not 'index <oid>..<oid>' should be printed. Since patch id needs not to have index when hashing a patch, it will be useful soon. Signed-off-by: Gregory Herrero <gregory.herrero@oracle.com>
* fileops: rename to "futils.h" to match function signaturesPatrick Steinhardt2019-07-201-1/+1
| | | | | | | | | Our file utils functions all have a "futils" prefix, e.g. `git_futils_touch`. One would thus naturally guess that their definitions and implementation would live in files "futils.h" and "futils.c", respectively, but in fact they live in "fileops.h". Rename the files to match expectations.
* configuration: cvar -> configmapPatrick Steinhardt2019-07-181-1/+1
| | | | | `cvar` is an unhelpful name. Refactor its usage to `configmap` for more clarity.
* oid: `is_zero` instead of `iszero`Edward Thomson2019-06-161-4/+4
| | | | | | The only function that is named `issomething` (without underscore) was `git_oid_iszero`. Rename it to `git_oid_is_zero` for consistency with the rest of the library.
* git_error: use new names in internal APIs and usageEdward Thomson2019-01-221-9/+9
| | | | | Move to the `git_error` name in the internal API for error-related functions.
* Convert usage of `git_buf_free` to new `git_buf_dispose`Patrick Steinhardt2018-06-101-8/+8
|
* diff: Add missing GIT_DELTA_TYPECHANGE -> 'T' mapping.Erik van Zijst2018-04-051-0/+1
| | | | | This adds the 'T' status character to git_diff_status_char() for diff entries that change type.
* Make sure to always include "common.h" firstPatrick Steinhardt2017-07-031-0/+2
| | | | | | | | | | | | | | | | | | | | | | 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.
* giterr_set: consistent error messagesEdward Thomson2016-12-291-5/+5
| | | | | | | | 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
* diff: treat binary patches with no data specialethomson/diff-read-empty-binaryEdward Thomson2016-09-051-4/+6
| | | | | | When creating and printing diffs, deal with binary deltas that have binary data specially, versus diffs that have a binary file but lack the actual binary data.
* diff_print: change test for skipping binary printingEdward Thomson2016-09-021-3/+3
| | | | | | | | | | | | Instead of skipping printing a binary diff when there is no data, skip printing when we have a status of `UNMODIFIED`. This is more in-line with our internal data model and allows us to expand the notion of binary data. In the future, there may have no data because the files were unmodified (there was no data to produce) or it may have no data because there was no data given to us in a patch. We want to treat these cases separately.
* patch: show copy information for identical copiesEdward Thomson2016-06-251-11/+33
| | | | | | | When showing copy information because we are duplicating contents, for example, when performing a `diff --find-copies-harder -M100 -B100`, then show copy from/to lines in a patch, and do not show context. Ensure that we can also parse such patches.
* Introduce `git_diff_to_buf`Edward Thomson2016-05-261-0/+9
| | | | | Like `git_patch_to_buf`, provide a simple helper method that can print an entire diff directory to a `git_buf`.
* patch: `patch_diff` -> `patch_generated`Edward Thomson2016-05-261-1/+1
|
* patch: drop some warningsEdward Thomson2016-05-261-4/+3
|
* patch: use strlen to mean string lengthEdward Thomson2016-05-261-29/+27
| | | | | | | `oid_strlen` has meant one more than the length of the string. This is mighty confusing. Make it mean only the string length! Whomsoever needs to allocate a buffer to hold a string can null terminate it like normal.
* patch: show modes when only the mode has changedEdward Thomson2016-05-261-13/+21
|
* patch: quote filenames when necessaryEdward Thomson2016-05-261-33/+96
|
* patch: don't print some headers on pure renamesEdward Thomson2016-05-261-4/+13
|
* patch printing: include rename informationEdward Thomson2016-05-261-0/+23
|
* patch_parse: use names from `diff --git` headerEdward Thomson2016-05-261-1/+0
| | | | | | When a text file is added or deleted, use the file names from the `diff --git` header instead of the `---` or `+++` lines. This is for compatibility with git.
* diff: include oid length in deltasEdward Thomson2016-05-261-0/+27
| | | | | | Now that `git_diff_delta` data can be produced by reading patch file data, which may have an abbreviated oid, allow consumers to know that the id is abbreviated.
* patch: abstract patches into diff'ed and parsedEdward Thomson2016-05-261-96/+53
| | | | | | Patches can now come from a variety of sources - either internally generated (from diffing two commits) or as the results of parsing some external data.
* patch application: apply binary patchesEdward Thomson2016-05-261-0/+3
| | | | | | Handle the application of binary patches. Include tests that produce a binary patch (an in-memory `git_patch` object), then enusre that the patch applies correctly.
* diff_print: assert patch is non-NULLPatrick Steinhardt2016-02-231-1/+5
| | | | | | | | | | When invoking `diff_print_info_init_frompatch` it is obvious that the patch should be non-NULL. We explicitly check if the variable is set and continue afterwards, happily dereferencing the potential NULL-pointer. Fix this by instead asserting that patch is set. This also silences Coverity.
* Fix binary diffsGuille -bisho-2015-09-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | git expects an empty line after the binary data: literal X ...binary data... <empty_line> The last literal block of the generated patches were not containing the required empty line. Example: diff --git a/binary_file b/binary_file index 3f1b3f9098131cfecea4a50ff8afab349ea66d22..86e5c1008b5ce635d3e3fffa4434c5eccd8f00b6 100644 GIT binary patch literal 8 Pc${NM&PdElPvrst3ey5{ literal 6 Nc${NM%g@i}0ssZ|0lokL diff --git a/binary_file2 b/binary_file2 index 31be99be19470da4af5b28b21e27896a2f2f9ee2..86e5c1008b5ce635d3e3fffa4434c5eccd8f00b6 100644 GIT binary patch literal 8 Pc${NM&PdElPvrst3ey5{ literal 13 Sc${NMEKbZyOexL+Qd|HZV+4u- git apply of that diff results in: error: corrupt binary patch at line 9: diff --git a/binary_file2 b/binary_file2 fatal: patch with only garbage at line 10 The proper formating is: diff --git a/binary_file b/binary_file index 3f1b3f9098131cfecea4a50ff8afab349ea66d22..86e5c1008b5ce635d3e3fffa4434c5eccd8f00b6 100644 GIT binary patch literal 8 Pc${NM&PdElPvrst3ey5{ literal 6 Nc${NM%g@i}0ssZ|0lokL diff --git a/binary_file2 b/binary_file2 index 31be99be19470da4af5b28b21e27896a2f2f9ee2..86e5c1008b5ce635d3e3fffa4434c5eccd8f00b6 100644 GIT binary patch literal 8 Pc${NM&PdElPvrst3ey5{ literal 13 Sc${NMEKbZyOexL+Qd|HZV+4u-
* diff: use size_t formatEdward Thomson2015-06-301-1/+1
|
* diff: fix leaks in diff printingCarlos Martín Nieto2015-06-261-0/+3
|
* Fixed Xcode 6.1 build warningsPierre-Olivier Latour2015-06-151-1/+0
|
* diff: introduce binary diff callbacksEdward Thomson2015-06-121-126/+154
| | | | | | | Introduce a new binary diff callback to provide the actual binary delta contents to callers. Create this data from the diff contents (instead of directly from the ODB) to support binary diffs including the workdir, not just things coming out of the ODB.
* Introduce git_buf_decode_base64Edward Thomson2014-08-151-1/+1
| | | | Decode base64-encoded text into a git_buf
* undo indentation change in diff_print.cfix-git-status-list-new-unreadable-folderAlan Rogers2014-07-231-9/+9
|
* Merge remote-tracking branch 'origin/development' into ↵Alan Rogers2014-06-041-30/+57
|\ | | | | | | | | | | | | fix-git-status-list-new-unreadable-folder Conflicts: include/git2/diff.h
| * minor cleanupsRussell Belfer2014-05-311-5/+5
| |
| * Clean up the handling of large binary diffsRussell Belfer2014-05-311-38/+48
| |
| * Fix printf format string from previous commitPhilip Kelley2014-05-171-1/+1
| |
| * print_binary_hunk: Treat types with respectPhilip Kelley2014-05-171-7/+24
| |
* | Start adding GIT_DELTA_UNREADABLE and GIT_STATUS_WT_UNREADABLE.Alan Rogers2014-05-201-8/+10
|/
* Be more careful with user-supplied buffersrb/fix-2333Russell Belfer2014-05-081-3/+3
| | | | | | | | | | | This adds in missing calls to `git_buf_sanitize` and fixes a number of places where `git_buf` APIs could inadvertently write NUL terminator bytes into invalid buffers. This also changes the behavior of `git_buf_sanitize` to NUL terminate a buffer if it can and of `git_buf_shorten` to do nothing if it can. Adds tests of filtering code with zeroed (i.e. unsanitized) buffer which was previously triggering a segfault.