summaryrefslogtreecommitdiff
path: root/include/git2/diff.h
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #2291 from ethomson/patch_binaryVicent Marti2014-04-231-0/+4
|\ | | | | patch: emit deflated binary patches (optionally)
| * patch: emit binary patches (optionally)Edward Thomson2014-04-221-0/+4
| |
* | Use git_diff_get_stats in example/diff + refactorRussell Belfer2014-04-221-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This takes the `--stat` and related example options in the example diff.c program and converts them to use the `git_diff_get_stats` API which nicely formats stats for you. I went to add bar-graph scaling to the stats formatter and noticed that the `git_diff_stats` structure was holding on to all of the `git_patch` objects. Unfortunately, each of these objects keeps the full text of the diff in memory, so this is very expensive. I ended up modifying `git_diff_stats` to keep just the data that it needs to keep and allowed it to release the patches. Then, I added width scaling to the output on top of that. In making the diff example program match 'git diff' output, I ended up removing an newline from the sumamry output which I then had to compensate for in the email formatting to match the expectations. Lastly, I went through and refactored the tests to use a couple of helper functions and reduce the overall amount of code there.
* | Some doc and examples/diff.c changesRussell Belfer2014-04-221-18/+11
|/ | | | | | | | | | | | | | 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.
* Introduce git_diff_format_email and git_diff_commit_as_emailJacques Germishuys2014-04-151-0/+88
|
* Introduce git_diff_get_stats, git_diff_stats_files_changed, ↵Jacques Germishuys2014-04-151-0/+85
| | | | git_diff_stats_insertions, git_diff_stats_deletions and git_diff_stats_to_buf
* Added function-based initializers for every options struct.Matthew Bowen2014-03-051-0/+26
| | | | The basic structure of each function is courtesy of arrbee.
* Add buffer to buffer diff and patch APIsRussell Belfer2014-02-271-0/+33
| | | | | | | | This adds `git_diff_buffers` and `git_patch_from_buffers`. This also includes a bunch of internal refactoring to increase the shared code between these functions and the blob-to-blob and blob-to-buffer APIs, as well as some higher level assert helpers in the tests to also remove redundancy.
* diff: change id abbrev option's name to id_abbrevCarlos Martín Nieto2014-01-251-1/+1
| | | | | 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-2/+2
| | | | In the same vein as the previous commits in this series.
* Update docs for new callback return value behaviorRussell Belfer2013-12-111-6/+6
|
* Add config read fns with controlled error behaviorRussell Belfer2013-12-111-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* Clarify docsBen Straub2013-12-061-3/+3
|
* Clarify default value and behaviorBen Straub2013-12-061-1/+5
|
* Introduce GIT_DIFF_FIND_BY_CONFIGBen Straub2013-12-051-0/+3
|
* GIT_DIFF_FIND_REMOVE_UNMODIFIED sounds betterRussell Belfer2013-12-021-2/+2
|
* Add GIT_DIFF_FIND_DELETE_UNMODIFIED flagRussell Belfer2013-12-021-14/+44
| | | | | | | | | | When doing copy detection, it is often necessary to include UNMODIFIED records in the git_diff so they are available as source records for GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED. Yet in the final diff, often you will not want to have these UNMODIFIED records. This adds a flag which marks these UNMODIFIED records for deletion from the diff list so they will be removed after the rename detect phase is over.
* Add content offset to git_diff_lineNick Hengeveld2013-11-181-0/+1
| | | | | | For additions and deletions, external consumers like subversion can make use of the content offset to generate diffs in their proprietary formats.
* Add git_diff_options_init helperRussell Belfer2013-11-011-4/+26
| | | | | | | | | Sometimes the static initializer for git_diff_options cannot be used and since setting them to all zeroes doesn't actually work quite right, this adds a new helper for that situation. This also adds an explicit new value to the submodule settings options to be used when those enums need static initialization.
* Make diff and status perform soft index reloadRussell Belfer2013-11-011-0/+8
| | | | | | | | | | | | | | | | | | | | | This changes `git_index_read` to have two modes - a hard index reload that always resets the index to match the on-disk data (which was the old behavior) and a soft index reload that uses the timestamp / file size information and only replaces the index data if the file on disk has been modified. This then updates the git_status code to do a soft reload unless the new GIT_STATUS_OPT_NO_REFRESH flag is passed in. This also changes the behavior of the git_diff functions that use the index so that when an index is not explicitly passed in (i.e. when the functions call git_repository_index for you), they will also do a soft reload for you. This intentionally breaks the file signature of git_index_read because there has been some confusion about the behavior previously and it seems like all existing uses of the API should probably be examined to select the desired behavior.
* Fix typoRussell Belfer2013-10-221-1/+1
|
* Implement patience and minimal diff flagsRussell Belfer2013-10-211-1/+4
| | | | | | It seems that to implement these options, we just have to pass the appropriate flags through to the libxdiff code taken from core git. So let's do it (and add a test).
* Create git_diff_line and extend git_diff_hunkRussell Belfer2013-10-211-10/+21
| | | | | | | | | | | | | 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.
* Tweak to git_diff_delta structure for nfilesRussell Belfer2013-10-211-2/+3
| | | | | | While the base git_diff_delta structure always contains two files, when we introduce conflict data, it will be helpful to have an indicator when an additional file is involved.
* Diff API cleanupRussell Belfer2013-10-151-183/+225
| | | | | | | | 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-309/+71
| | | | | | 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.
* Split rewrites, status doesn't return rewritesEdward Thomson2013-08-281-0/+3
| | | | | | | | Ensure that we apply splits to rewrites, even if we're not interested in examining it closely for rename/copy detection. In keeping with core git, status should not display rewrites, it should simply show files as "modified".
* Restore GIT_DIFF_LINE_BINARY usageRussell Belfer2013-07-231-1/+1
| | | | | | 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.
* Add hunk/file headers to git_diff_patch_sizeRussell Belfer2013-07-231-2/+6
| | | | | | | | | | | 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.
* Add git_diff_patch_size() APIRussell Belfer2013-07-221-0/+18
| | | | | This adds a new API to get the size in bytes of the diffs in a git_diff_patch object.
* Add ignore_submodules to diff optionsRussell Belfer2013-07-101-1/+4
| | | | | | | | | | | | | | | | | | | | This adds correct support for an equivalent to --ignore-submodules in diff, where an actual ignore value can be passed to diff to override the per submodule settings in the configuration. This required tweaking the constants for ignore values so that zero would not be used and could represent an unset option to the diff. This was an opportunity to move the submodule values into include/git2/types.h and to rename the poorly named DEFAULT values for ignore and update constants to RESET instead. Now the GIT_DIFF_IGNORE_SUBMODULES flag is exactly the same as setting the ignore_submodules option to GIT_SUBMODULE_IGNORE_ALL (which is actually a minor change from the old behavior in that submodules will now be treated as UNMODIFIED deltas instead of being left out totally - if you set GIT_DIFF_INCLUDE_UNMODIFIED). This includes tests for the various new settings.
* Add git_pathspec_match_diff APIRussell Belfer2013-07-101-0/+8
| | | | | | | | | | | | | | | | | | This adds an additional pathspec API that will match a pathspec against a diff object. This is convenient if you want to handle renames (so you need the whole diff and can't use the pathspec constraint built into the diff API) but still want to tell if the diff had any files that matched the pathspec. When the pathspec is matched against a diff, instead of keeping a list of filenames that matched, instead the API keeps the list of git_diff_deltas that matched and they can be retrieved via a new API git_pathspec_match_list_diff_entry. There are a couple of other minor API extensions here that were mostly for the sake of convenience and to reduce dependencies on knowing the internal data structure between files inside the library.
* Fixed most documentation header bugsAndreas Linde2013-06-241-5/+5
| | | | | | | | | | | Fixed a few header @param and @return typos with the help of -Wdocumentation in Xcode. The following warnings have not been fixed: common.h:213 - Not sure how the documentation format is for '...' notes.h:102 - Correct @param name but empty text notes.h:111 - Correct @param name but empty text pack.h:140 - @return missing text pack.h:148 - @return missing text
* Add "as_path" parameters to blob and buffer diffsRussell Belfer2013-06-171-2/+18
| | | | | | | | | | | | | | | | | | | | | | | | This adds parameters to the four functions that allow for blob-to- blob and blob-to-buffer differencing (either via callbacks or by making a git_diff_patch object). These parameters let you say that filename we should pretend the blob has while doing the diff. If you pass NULL, there should be no change from the existing behavior, which is to skip using attributes for file type checks and just look at content. With the parameters, you can plug into the new diff driver functionality and get binary or non-binary behavior, plus function context regular expressions, etc. This commit also fixes things so that the git_diff_delta that is generated by these functions will actually be populated with the data that we know about the blobs (or buffers) so you can use it appropriately. It also fixes a bug in generating patches from the git_diff_patch objects created via these functions. Lastly, there is one other behavior change that may matter. If there is no difference between the two blobs, these functions no longer generate any diff callbacks / patches unless you have passed in GIT_DIFF_INCLUDE_UNMODIFIED. This is pretty natural, but could potentially change the behavior of existing usage.
* Add patch from blobs APIRussell Belfer2013-06-121-2/+45
| | | | | | | | This adds two new public APIs: git_diff_patch_from_blobs and git_diff_patch_from_blob_and_buffer, plus it refactors the code for git_diff_blobs and git_diff_blob_to_buffer so that they code is almost entirely shared between these APIs, and adds tests for the new APIs.
* Implement regex pattern diff driverRussell Belfer2013-06-111-0/+3
| | | | | | | This implements the loading of regular expression pattern lists for diff drivers that search for function context in that way. This also changes the way that diff drivers update options and interface with xdiff APIs to make them a little more flexible.
* Clarify GIT_DIFF_INCLUDE_UNTRACKED_CONTENT optionRussell Belfer2013-05-241-5/+10
| | | | | | | | This improves the docs for GIT_DIFF_INCLUDE_UNTRACKED_CONTENT as well as the other flags related to UNTRACKED items in diff, plus it makes that flag now automatically turn on GIT_DIFF_INCLUDE_UNTRACKED which seems like a reasonable dwim type of change.
* More diff rename tests; better split swap handlingRussell Belfer2013-05-231-1/+1
| | | | | | | | | | | | | This adds a couple more tests of different rename scenarios. Also, this fixes a problem with the case where you have two "split" deltas and the left half of one matches the right half of the other. That case was already being handled, but in the wrong order in a way that could result in bad output. Also, if the swap also happened to put the other two halves into the correct place (i.e. two files exchanged places with each other), then the second delta was left with the SPLIT flag set when it really should be cleared.
* Significant rename detection rewriteRussell Belfer2013-05-221-6/+9
| | | | | | | | | | | | | | | | | | | | This flips rename detection around so instead of creating a forward mapping from deltas to possible rename targets, instead it creates a reverse mapping, looking at possible targets and trying to find a source that they could have been renamed or copied from. This is important because each output can only have a single source, but a given source could map to multiple outputs (in the form of COPIED records). Additionally, this makes a couple of tweaks to the public rename detection APIs, mostly renaming a couple of options that control the behavior to make more sense and to be more like core Git. I walked through the tests looking at the exact results and updated the expectations based on what I saw. The new code is different from the old because it cannot give some nonsense results (like A was renamed to both B and C) which were part of the outputs previously.
* More git_diff_find_similar improvementsRussell Belfer2013-05-201-0/+2
| | | | | | | | | | | | | | - Add new GIT_DIFF_FIND_EXACT_MATCH_ONLY flag to do similarity matching without using the similarity metric (i.e. only compare the SHA). - Clean up the similarity measurement code to more rigorously distinguish between files that are not similar and files that are not comparable (previously, a 0 could either mean that the files could not be compared or that they were totally different) - When splitting a MODIFIED file into a DELETE/ADD pair, actually make a DELETED/UNTRACKED pair if the right side of the diff is from the working directory. This prevents an odd mix of ADDED and UNTRACKED files on workdir diffs.
* Fix issues with git_diff_find_similarRussell Belfer2013-05-171-11/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are a number of bugs in the rename code that only were obvious when I started testing it against large old repos with more complex patterns. (The code to do that testing is not ready to merge with libgit2, but I do plan to add more thorough tests.) This contains a significant number of changes and also tweaks the public API slightly to make emulating core git easier. Most notably, this separates the GIT_DIFF_FIND_AND_BREAK_REWRITES flag into FIND_REWRITES (which adds a self-similarity score to every modified file) and BREAK_REWRITES (which splits the modified deltas into add/remove pairs in the diff list). When you do a raw output of core git, rewrites show up as M090 or such, not at A and D output, so I wanted to be able to emulate that. Publicly, this also changes the flags to be uint16_t since we don't need values out of that range. Internally, this contains significant changes from a number of small bug fixes (like using the wrong side of the diff to decide if the object could be found in the ODB vs the workdir) to larger issues about which files can and should be compared and how the various edge cases of similarity scores should be treated. Honestly, I don't think this is the last update that will have to be made to this code, but I think this moves us closer to correct behavior and I tried to document the code so it would be easier to follow..
* Add git_diff_print_raw printing helperRussell Belfer2013-05-171-0/+16
| | | | Makes it easier to emulate the --raw option
* Improve diff function docsRussell Belfer2013-05-071-7/+26
|
* Add GIT_DIFF_LINE_CONTEXT_EOFNLRussell Belfer2013-05-071-2/+4
| | | | | | | | | | | | | | | | | | This adds a new line origin constant for the special line that is used when both files end without a newline. In the course of writing the tests for this, I was having problems with modifying a file but not having diff notice because it was the same size and modified less than one second from the start of the test, so I decided to start working on nanosecond timestamp support. This commit doesn't contain the nanosecond support, but it contains the reorganization of maybe_modified and the hooks so that if the nanosecond data were being read by stat() (or rather being copied by git_index_entry__init_from_stat), then the nsec would be taken into account. This new stuff could probably use some more tests, although there is some amount of it here.
* Update comment for clarityRussell Belfer2013-04-301-5/+17
|
* Update diff handling of untracked directoriesRussell Belfer2013-04-301-0/+7
| | | | | | | | | | When diff encounters an untracked directory, there was a shortcut that it took which is not compatible with core git. This makes the default behavior no longer take that shortcut and instead look inside the untracked directory to see if there are any untracked files within it. If there are not, then the directory is treated as an ignore directory instead of an untracked directory. This has implications for the git_status APIs.
* Recursing into ignored dirs for diff and statusRussell Belfer2013-03-251-1/+1
| | | | | | | | This implements working versions of GIT_DIFF_RECURSE_IGNORED_DIRS and GIT_STATUS_OPT_RECURSE_IGNORED_DIRS along with some tests for the newly available behaviors. This is not turned on by default for status, but can be accessed via the options to the extended version of the command.
* diff: allow asking for diffs with no contextCarlos Martín Nieto2013-03-091-1/+1
| | | | | | | | | Previously, 0 meant default. This is problematic, as asking for 0 context lines is a valid thing to do. Change GIT_DIFF_OPTIONS_INIT to default to three and stop treating 0 as a magic value. In case no options are provided, make sure the options in the diff object default to 3.
* Add diff rename tests with partial similarityRussell Belfer2013-02-211-0/+3
| | | | | | | | | | | | | | This adds some new tests that actually exercise the similarity metric between files to detect renames, copies, and split modified files that are too heavily modified. There is still more testing to do - these tests are just partially covering the cases. There is also one bug fix in this where a change set with only MODIFY being broken into ADD/DELETE (due to low self-similarity) without any additional RENAMED entries would end up not processing the split requests (because the num_rewrites counter got reset).
* Initial integration of similarity metric to diffRussell Belfer2013-02-211-5/+11
| | | | | | | | | | | | | | | | This is the initial integration of the similarity metric into the `git_diff_find_similar()` code path. The existing tests all pass, but the new functionality isn't currently well tested. The integration does go through the pluggable metric interface, so it should be possible to drop in an alternative to the internal metric that libgit2 implements. This comes along with a behavior change for an existing interface; namely, passing two NULLs to git_diff_blobs (or passing NULLs to git_diff_blob_to_buffer) will now call the file_cb parameter zero times instead of one time. I know it's strange that that change is paired with this other change, but it emerged from some initialization changes that I ended up making.