summaryrefslogtreecommitdiff
path: root/src/diff_output.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Add complex checkout test and then fix checkoutRussell Belfer2012-10-091-3/+12
| | | | | | | | | | | | | | | | This started as a complex new test for checkout going through the "typechanges" test repository, but that revealed numerous issues with checkout, including: * complete failure with submodules * failure to create blobs with exec bits * problems when replacing a tree with a blob because the tree "example/" sorts after the blob "example" so the delete was being processed after the single file blob was created This fixes most of those problems and includes a number of other minor changes that made it easier to do that, including improving the TYPECHANGE support in diff/status, etc.
* Add test for diffs with submodules and bug fixesRussell Belfer2012-10-081-15/+19
| | | | | | | | The adds a test for the submodule diff capabilities and then fixes a few bugs with how the output is generated. It improves the accuracy of OIDs in the diff delta object and makes the submodule output more closely mirror the OIDs that will be used by core git.
* Fix a few diff bugs with directory contentRussell Belfer2012-10-081-0/+17
| | | | | | | | | | | | | | | There are a few cases where diff should leave directories in the diff list if we want to match core git, such as when the directory contains a .git dir. That feature was lost when I introduced some of the new submodule handling. This restores that and then fixes a couple of related to diff output that are triggered by having diffs with directories in them. Also, this adds a new flag that can be passed to diff if you want diff output to actually include the file content of any untracked files.
* Extract submodule logic out of diff_output.c:get_workdir_contentSascha Cunz2012-10-051-33/+40
|
* Diff: teach get_workdir_content to show a submodule as textSascha Cunz2012-10-051-0/+38
| | | | | | | | | | | | | | | | 1. teach diff.c:maybe_modified to query git_submodule_status for the modification state of a submodule. According to the git_submodule_status docs, it will filter for to-ignore states already. 2. teach diff_output.c:get_workdir_content to check the submodule status again and create a line like: Subproject commit <SHA-1>\n or Subproject comimt <SHA-1>-dirty\n like git.git does.
* Diff: teach get_blob_content to show a submodule as textSascha Cunz2012-10-051-0/+16
| | | | | | | | | | | | | | diff_output.c:get_blob_content used to try to read the submodule commit as a blob in the superproject's odb. Of course it cannot find it and errors out with GIT_ENOTFOUND, implcitly terminating the whole diff output. This patch teaches it to create a text that describes the submodule instead. The text looks like: Subproject commit <SHA1>\n which is what git.git does, too.
* Fix minor whitespace issueSascha Cunz2012-10-051-3/+3
|
* Clean up Win64 warningsRussell Belfer2012-09-281-1/+1
|
* Add const to all shared pointers in diff APIRussell Belfer2012-09-251-16/+18
| | | | | | | | | | There are a lot of places where the diff API gives the user access to internal data structures and many of these were being exposed through non-const pointers. This replaces them all with const pointers for any object that the user can access but is still owned internally to the git_diff_list or git_diff_patch objects. This will probably break some bindings... Sorry!
* Fix bugs in new diff patch codeRussell Belfer2012-09-251-46/+41
| | | | | | | | | This fixes all the bugs in the new diff patch code. The only really interesting one is that when we merge two diffs, we now have to actually exclude diff delta records that are not supposed to be tracked, as opposed to before where they could be included because they would be skipped silently by `git_diff_foreach()`. Other than that, there are just minor errors.
* Initial implementation of new diff patch APIRussell Belfer2012-09-251-574/+492
| | | | | | | | Replacing the `git_iterator` object, this creates a simple API for accessing the "patch" for any file pair in a diff list and then gives indexed access to the hunks in the patch and the lines in the hunk. This is the initial implementation of this revised API - it is still broken, but at least builds cleanly.
* Fix MSVC amd64 compilation warningsnulltoken2012-09-201-2/+2
|
* Forgot to reset hunk & line between filesRussell Belfer2012-09-131-1/+2
| | | | | | The last change tweaked the way we use the hunk_curr pointer during iteration, but failed to reset the value back to NULL when switching files.
* Fix problems in diff iterator record chainingRussell Belfer2012-09-131-13/+31
| | | | | | | There is a bug in building the linked list of line records in the diff iterator and also an off by one element error in the hunk counts. This fixes both of these, adds some test data with more complex sets of hunk and line diffs to exercise this code better.
* Fix diff binary file detectionRussell Belfer2012-09-111-16/+40
| | | | | | | | | | | In the process of adding tests for the max file size threshold (which treats files over a certain size as binary) there seem to be a number of problems in the new code with detecting binaries. This should fix those up, as well as add a test for the file size threshold stuff. Also, this un-deprecates `GIT_DIFF_LINE_ADD_EOFNL`, since I finally found a legitimate situation where it would be returned.
* Reorg internal odb read header and object lookupRussell Belfer2012-09-101-2/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | Often `git_odb_read_header` will "fail" and have to read the entire object into memory instead of just the header. When this happens, the object is loaded and then disposed of immediately, which makes it difficult to efficiently use the header information to decide if the object should be loaded (since attempting to do so will often result in loading the object twice). This commit takes the existing code and reorganizes it to have two new functions: - `git_odb__read_header_or_object` which acts just like the old read header function except that it returns the object, too, if it was forced to load the whole thing. It then becomes the callers responsibility to free the `git_odb_object`. - `git_object__from_odb_object` which was extracted from the old `git_object_lookup` and creates a subclass of `git_object` from an existing `git_odb_object` (separating the ODB lookup from the `git_object` creation). This allows you to use the first header reading function efficiently without instantiating the `git_odb_object` twice. There is no net change to the behavior of any of the existing functions, but this allows internal code to tap into the ODB lookup and object creation to be more efficient.
* Move diff max_size to public APIRussell Belfer2012-09-101-65/+83
| | | | | | | | | | | This commit adds a max_size value in the public `git_diff_options` structure so that the user can automatically flag blobs over a certain size as binary regardless of other properties. Also, and perhaps more importantly, this moves binary detection to be as early as possible in the diff traversal inner loop and makes sure that we stop loading objects as soon as we decide that they are binary.
* Replace git_diff_iterator_num_files with progressRussell Belfer2012-09-101-11/+7
| | | | | | | | | The `git_diff_iterator_num_files` API was problematic, since we don't actually know the exact number of files to be iterated over until we load those files into memory. This replaces it with a new `git_diff_iterator_progress` API that goes from 0 to 1, and moves and renamed the old API for the internal places that can tolerate a max value instead of an exact value.
* Clean up blob diff pathRussell Belfer2012-09-061-2/+11
| | | | | | | | Previously when diffing blobs, the diff code just ran with a NULL repository object. Of course, that's not necessary and the test for a NULL repo was confusing. This makes the blob diff run with the repo that contains the blobs and clarifies the test that it is possible to be diffing data where the path is unknown.
* Implement filters for status/diff blobsRussell Belfer2012-09-061-62/+152
| | | | | | | | | | | | | This adds support to diff and status for running filters (a la crlf) on blobs in the workdir before computing SHAs and before generating text diffs. This ended up being a bit more code change than I had thought since I had to reorganize some of the diff logic to minimize peak memory use when filtering blobs in a diff. This also adds a cap on the maximum size of data that will be loaded to diff. I set it at 512Mb which should match core git. Right now it is a #define in src/diff.h but it could be moved into the public API if desired.
* diff: Cleanup documentation and printf compatVicent Marti2012-09-061-4/+4
|
* Fix comments and a minor bugRussell Belfer2012-09-051-4/+3
| | | | | This adds better header comments and also fixes a bug in one of simple APIs that tells the number of lines in the current hunk.
* Diff iteratorsRussell Belfer2012-09-051-256/+760
| | | | | | | | | | | This refactors the diff output code so that an iterator object can be used to traverse and generate the diffs, instead of just the `foreach()` style with callbacks. The code has been rearranged so that the two styles can still share most functions. This also replaces `GIT_REVWALKOVER` with `GIT_ITEROVER` and uses that as a common error code for marking the end of iteration when using a iterator style of object.
* Fix MSVC compilation warningsnulltoken2012-09-041-1/+1
|
* Working implementation of git_submodule_statusRussell Belfer2012-08-241-0/+19
| | | | | | | | | | | | | This is a big redesign of the git_submodule_status API and the implementation of the redesigned API. It also fixes a number of bugs that I found in other parts of the submodule API while writing the tests for the status part. This also fixes a couple of bugs in the iterators that had not been noticed before - one with iterating when there is a gitlink (i.e. separate-work-dir) and one where I was treating anything even vaguely submodule-like as a submodule, more aggressively than core git does.
* Minor bug fixes in diff codeRussell Belfer2012-08-221-1/+2
| | | | | | | In looking at PR #878, I found a few small bugs in the diff code, mostly related to work that can be avoided when processing tree- to-tree diffs that was always being carried out. This commit has some small fixes in it.
* oid: Explicitly include `oid.h` for the inlined CMPVicent Marti2012-08-091-0/+1
|
* Update iterators for consistency across libraryRussell Belfer2012-08-031-44/+59
| | | | | | | | | | | | | | | | | This updates all the `foreach()` type functions across the library that take callbacks from the user to have a consistent behavior. The rules are: * A callback terminates the loop by returning any non-zero value * Once the callback returns non-zero, it will not be called again (i.e. the loop stops all iteration regardless of state) * If the callback returns non-zero, the parent fn returns GIT_EUSER * Although the parent returns GIT_EUSER, no error will be set in the library and `giterr_last()` will return NULL if called. This commit makes those changes across the library and adds tests for most of the iteration APIs to make sure that they follow the above rules.
* diff: make inter-hunk-context default value git-compliantyorah2012-07-021-1/+1
| | | | Default in git core is 0, not 3
* Minor fixes, cleanups, and clarificationsRussell Belfer2012-06-081-5/+6
| | | | | | | | | | | | | | | | | | | | | | | There are three actual changes in this commit: 1. When the trailing newline of a file is removed in a diff, the change will now be reported with `GIT_DIFF_LINE_DEL_EOFNL` passed to the callback. Previously, the `ADD_EOFNL` constant was given which was just an error in my understanding of when the various circumstances arose. `GIT_DIFF_LINE_ADD_EOFNL` is deprecated and should never be generated. A new newline is simply an `ADD`. 2. Rewrote the `diff_delta__merge_like_cgit` function that contains the core logic of the `git_diff_merge` implementation. The new version doesn't actually have significantly different behavior, but the logic should be much more obvious, I think. 3. Fixed a bug in `git_diff_merge` where it freed a string pool while some of the string data was still in use. This led to `git_diff_print_patch` accessing memory that had been freed. The rest of this commit contains improved documentation in `diff.h` to make the behavior and the equivalencies with core git clearer, and a bunch of new tests to cover the various cases, oh and a minor simplification of `examples/diff.c`.
* Fix filemode comparison in diffsRussell Belfer2012-06-081-3/+10
| | | | | | | | | | | | | | | File modes were both not being ignored properly on platforms where they should be ignored, nor be diffed consistently on platforms where they are supported. This change adds a number of diff and status filemode change tests. This also makes sure that filemode-only changes are included in the diff output when they occur and that filemode changes are ignored successfully when core.filemode is false. There is no code that automatically toggles core.filemode based on the capabilities of the current platform, so the user still needs to be careful in their .git/config file.
* misc: Fix warnings from PVS Studio trialVicent Martí2012-06-071-1/+1
|
* Fix checking for the presence of a flagGarrett Regier2012-05-271-1/+1
|
* global: Change parameter ordering in APIVicent Martí2012-05-181-1/+1
| | | | Consistency is good.
* Optimize away git_text_gather_stats in diffRussell Belfer2012-05-171-7/+2
| | | | | | | | GProf shows `git_text_gather_stats` as the most expensive call in large diffs. The function calculates a lot of information that is not actually used and does not do so in a optimal order. This introduces a tuned `git_buf_is_binary` function that executes the same algorithm in a fraction of the time.
* diff: fix the diffing of two identical blobsnulltoken2012-05-071-0/+8
|
* diff: make git_diff_blobs() able to detect binary blobsnulltoken2012-05-071-0/+28
|
* diff: fix the diffing of a concrete blob against a null onenulltoken2012-05-071-22/+20
|
* diff: When diffing two blobs, ensure the delta callback parameter is filled ↵nulltoken2012-05-071-2/+6
| | | | with relevant information
* diff: remove unused parameternulltoken2012-05-071-4/+1
|
* Support reading attributes from indexRussell Belfer2012-05-031-1/+1
| | | | | | | | | | | | | | Depending on the operation, we need to consider gitattributes in both the work dir and the index. This adds a parameter to all of the gitattributes related functions that allows user control of attribute reading behavior (i.e. prefer workdir, prefer index, only use index). This fix also covers allowing us to check attributes (and hence do diff and status) on bare repositories. This was a somewhat larger change that I hoped because it had to change the cache key used for gitattributes files.
* Merge branch 'new-error-handling' into developmentVicent Martí2012-05-021-111/+131
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: .travis.yml include/git2/diff.h src/config_file.c src/diff.c src/diff_output.c src/mwindow.c src/path.c tests-clar/clar_helpers.c tests-clar/object/tree/frompath.c tests/t00-core.c tests/t03-objwrite.c tests/t08-tag.c tests/t10-refs.c tests/t12-repo.c tests/t18-status.c tests/test_helpers.c tests/test_main.c
| * Convert from strnlen to git_text_is_binaryRussell Belfer2012-05-021-4/+16
| | | | | | | | | | | | Since strnlen is not supported on all platforms and since we now have the shiny new git_text_is_binary in the filtering code, let's convert diff binary detection to use the new stuff.
| * Copy values to avoid strict aliasing warningRussell Belfer2012-05-021-1/+6
| | | | | | | | | | | | To make this code more resilient to future changes, we'll explicitly translate the libgit2 structure to the libxdiff structure.
| * Fix usage of "new" for fieldname in public headerRussell Belfer2012-05-021-79/+79
| | | | | | | | | | | | | | | | This should restore the ability to include libgit2 headers in C++ projects. Cherry picked 2de60205dfea2c4a422b2108a5e8605f97c2e895 from development into new-error-handling.
| * diff: provide more context to the consumer of the callbacksnulltoken2012-04-301-18/+17
| | | | | | | | Update the callback to provide some information related to the file change being processed and the range of the hunk, when applicable.
| * diff: fix generation of the header of a removal patchnulltoken2012-04-251-5/+15
| |
| * New status fixesRussell Belfer2012-03-221-2/+4
| | | | | | | | | | | | | | This adds support for roughly-right tracking of submodules (although it does not recurse into submodules to detect internal modifications a la core git), and it adds support for including unmodified files in diff iteration if requested.
| * Migrating diff to new error handlingRussell Belfer2012-03-061-89/+92
| | | | | | | | | | | | Ended up migrating a bunch of upstream functions as well including vector, attr_file, and odb in order to get this to work right.
| * error-handling: RepositoryVicent Martí2012-03-071-10/+13
| | | | | | | | | | | | | | | | This also includes droping `git_buf_lasterror` because it makes no sense in the new system. Note that in most of the places were it has been dropped, the code needs cleanup. I.e. GIT_ENOMEM is going away, so instead it should return a generic `-1` and obviously not throw anything.