summaryrefslogtreecommitdiff
path: root/src/diff_print.c
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* Merge pull request #2291 from ethomson/patch_binaryVicent Marti2014-04-231-6/+125
|\ | | | | patch: emit deflated binary patches (optionally)
| * patch: emit binary patches (optionally)Edward Thomson2014-04-221-6/+125
| |
* | Some doc and examples/diff.c changesRussell Belfer2014-04-221-1/+2
|/ | | | | | | | | | | | | | I was playing with "git diff-index" and wanted to be able to emulate that behavior a little more closely with the diff example. Also, I wanted to play with running `git_diff_tree_to_workdir` directly even though core Git doesn't exactly have the equivalent, so I added a command line option for that and tweaked some other things in the example code. This changes a minor output thing in that the "raw" print helper function will no longer add ellipses (...) if the OID is not actually abbreviated.
* Add public diff print helpersRussell Belfer2014-04-171-2/+26
| | | | | | | The usefulness of these helpers came up for me while debugging some of the iterator changes that I was making, so since they have also been requested (albeit indirectly) I thought I'd include them.
* diff: change id abbrev option's name to id_abbrevCarlos Martín Nieto2014-01-251-2/+2
| | | | | Same as the other commits in the series, we use 'id' when talking about thing rather than the datatype.
* diff: rename the file's 'oid' to 'id'Carlos Martín Nieto2014-01-251-6/+6
| | | | In the same vein as the previous commits in this series.
* Drop git_patch_to_strNicolas Hake2014-01-221-18/+0
| | | | | | | It's hard or even impossible to correctly free the string buffer allocated by git_patch_to_str in some circumstances. Drop the function so people have to use git_patch_to_buf instead - git_buf has a dedicated destructor.
* Expose patch serialization to git_bufNicolas Hake2014-01-221-2/+10
| | | | | | | | | | | Returning library-allocated strings from libgit2 works fine on Linux, but may cause problems on Windows because there is no one C Runtime that everything links against. With libgit2 not exposing its own allocator, freeing the string is a gamble. git_patch_to_str already serializes to a buffer, then returns the underlying memory. Expose the functionality directly, so callers can use the git_buf_free function to free the memory later.
* One more rename/cleanup for callback err functionsRussell Belfer2013-12-111-2/+2
|
* Remove converting user error to GIT_EUSERRussell Belfer2013-12-111-61/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Improve GIT_EUSER handlingRussell Belfer2013-12-111-19/+27
| | | | | | | | | | | 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.
* Create git_diff_line and extend git_diff_hunkRussell Belfer2013-10-211-43/+50
| | | | | | | | | | | | | Instead of having functions with so very many parameters to pass hunk and line data, this takes the existing git_diff_hunk struct and extends it with more hunk data, plus adds a git_diff_line. Those structs are used to pass back hunk and line data instead of the old APIs that took tons of parameters. Some work that was previously only being done for git_diff_patch creation (scanning the diff content for exact line counts) is now done for all callbacks, but the performance difference should not be noticable.
* Diff API cleanupRussell Belfer2013-10-151-49/+77
| | | | | | | | This lays groundwork for separating formatting options from diff creation options. This groups the formatting flags separately from the diff list creation flags and reorders the options. This also tweaks some APIs to further separate code that uses patches from code that just looks at git_diffs.
* Rename diff objects and split patch.hRussell Belfer2013-10-111-25/+25
| | | | | | This makes no functional change to diff but renames a couple of the objects and splits the new git_patch (formerly git_diff_patch) into a new header file.
* Clean up unnecessary git_buf_printf callsRussell Belfer2013-09-231-4/+5
| | | | | | This replaces some git_buf_printf calls with simple calls to git_buf_put instead. Also, it fixes a missing va_end inside the git_buf_vprintf implementation.
* Better macro name for is-exec-bit-set testRussell Belfer2013-09-051-1/+1
|
* Add more file mode permissions macrosRussell Belfer2013-09-051-2/+2
| | | | | | This adds some more macros for some standard operations on file modes, particularly related to permissions, and then updates a number of places around the code base to use the new macros.
* Restore GIT_DIFF_LINE_BINARY usageRussell Belfer2013-07-231-22/+43
| | | | | | This restores the usage of GIT_DIFF_LINE_BINARY for the diff output line that reads "Binary files x and y differ" so that it can be optionally colorized independently of the file header.
* Make compact output more like core GitRussell Belfer2013-07-231-3/+3
|
* Add hunk/file headers to git_diff_patch_sizeRussell Belfer2013-07-231-37/+42
| | | | | | | | | | | This allows git_diff_patch_size to account for hunk headers and file headers in the returned size. This required some refactoring of the code that is used to print file headers so that it could be invoked by the git_diff_patch_size API. Also this increases the test coverage and fixes an off-by-one bug in the size calculation when newline changes happen at the end of the file.