summaryrefslogtreecommitdiff
path: root/src/diff_output.c
Commit message (Collapse)AuthorAgeFilesLines
* Move crlf conversion into buf_textautocrlf-fixesRussell Belfer2013-03-251-0/+1
| | | | | | | | | | | | | | This adds crlf/lf conversion functions into buf_text with more efficient implementations that bypass the high level buffer functions. They attempt to minimize the number of reallocations done and they directly write the buffer data as needed if they know that there is enough memory allocated to memcpy data. Tests are added for these new functions. The crlf.c code is updated to use the new functions. Removed the include of buf_text.h from filter.h and just include it more narrowly in the places that need it.
* Three submodule status bug fixesRussell Belfer2013-03-181-0/+5
| | | | | | | | | | | | | | | | 1. Fix sort order problem with submodules where "mod" was sorting after "mod-plus" because they were being sorted as "mod/" and "mod-plus/". This involved pushing the "contains a .git entry" test significantly lower in the stack. 2. Reinstate behavior that a directory which contains a .git entry will be treated as a submodule during iteration even if it is not yet added to the .gitmodules. 3. Now that any directory containing .git is reported as submodule, we have to be more careful checking for GIT_EEXISTS when we do a submodule lookup, because that is the error code that is returned by git_submodule_lookup when you try to look up a directory containing .git that has no record in gitmodules or the index.
* Several warnings detected by static code analyzer fixedArkadiy Shapkin2013-03-181-1/+1
| | | | | | | Implicit type conversion argument of function to size_t type Suspicious sequence of types castings: size_t -> int -> size_t Consider reviewing the expression of the 'A = B == C' kind. The expression is calculated as following: 'A = (B == C)' Unsigned type is never < 0
* Fix valgrind issues (and mmap fallback for diff)Russell Belfer2013-03-141-20/+33
| | | | | | | | | | This fixes a number of issues identified by valgrind - mostly missed free calls. Inside valgrind, mmap() may fail which causes some of the diff tests to fail. This adds a fallback code path to diff_output.c:get_workdir_content() where is the mmap() fails the code will now try to read the file data directly into allocated memory (which is what it would do if the data needed to be filtered anyhow).
* 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.
* Fix a few leaksCarlos Martín Nieto2013-03-041-0/+4
| | | | | | | | | `git_diff_get_patch()` would unconditionally load the patch object and then simply leak it if the user hadn't requested it. Short-circuit loading the object if the user doesn't want it. The rest of the plugs are simply calling the free functions of objects allocated during the tests.
* Initial integration of similarity metric to diffRussell Belfer2013-02-211-12/+44
| | | | | | | | | | | | | | | | 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.
* Replace diff delta binary with flagsRussell Belfer2013-02-201-75/+72
| | | | | | | | | | | | | | | | | | | | | | | | Previously the git_diff_delta recorded if the delta was binary. This replaces that (with no net change in structure size) with a full set of flags. The flag values that were already in use for individual git_diff_file objects are reused for the delta flags, too (along with renaming those flags to make it clear that they are used more generally). This (a) makes things somewhat more consistent (because I was using a -1 value in the "boolean" binary field to indicate unset, whereas now I can just use the flags that are easier to understand), and (b) will make it easier for me to add some additional flags to the delta object in the future, such as marking the results of a copy/rename detection or other deltas that might want a special indicator. While making this change, I officially moved some of the flags that were internal only into the private diff header. This also allowed me to remove a gross hack in rename/copy detect code where I was overwriting the status field with an internal value.
* Clear up warnings from cppcheckRussell Belfer2013-02-151-5/+6
| | | | | | | | | | | | 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.
* Reorganize FORCE_TEXT diff flag checksRussell Belfer2013-02-111-14/+24
|
* Add FORCE_TEXT check into git_diff_blobs code pathRussell Belfer2013-02-111-3/+10
| | | | | | | | | `git_diff_blobs` and `git_diff_blob_to_buffer` skip the step where we check file attributes because they don't have a filename associated with the data. Unfortunately, this meant they were also skipping the check for the GIT_DIFF_FORCE_TEXT option and so you could not force a diff of an apparent binary file. This adds the force text check into their code path.
* Fix MSVC compilation warningsnulltoken2013-02-051-2/+2
| | | | Fix #1308
* Add helper for diff line statsRussell Belfer2013-01-301-1/+33
| | | | | | | | | | | | This adds a `git_diff_patch_line_stats()` API that gets the total number of adds, deletes, and context lines in a patch. This will make it a little easier to emulate `git diff --stat` and the like. Right now, this relies on generating the `git_diff_patch` object, which is a pretty heavyweight way to get stat information. At some future point, it would probably be nice to be able to get this information without allocating the entire `git_diff_patch`, but that's a much larger project.
* Update iterator API with flags for ignore_caseRussell Belfer2013-01-151-5/+5
| | | | | | | | | | | | This changes the iterator API so that flags can be passed in to the constructor functions to control the ignore_case behavior. At this point, the flags are not supported on tree iterators (i.e. there is no functional change over the old API), but the API changes are all made to accomodate this. By the way, I went with a flags parameter because in the future I have a couple of other ideas for iterator flags that will make it easier to fix some diff/status/checkout bugs.
* Simplify git_diff__paired_foreach icase handlingRussell Belfer2013-01-151-16/+12
|
* Fix Travis compilation warningsnulltoken2013-01-131-3/+1
|
* Merge pull request #1230 from arrbee/match-core-git-diff-binary-detectionVicent Martí2013-01-111-1/+6
|\ | | | | Match binary file check of core git in diff
| * Match binary file check of core git in diffRussell Belfer2013-01-111-1/+6
| | | | | | | | | | | | | | | | | | Core git just looks for NUL bytes in files when deciding about is-binary inside diff (although it uses a better algorithm in checkout, when deciding if CRLF conversion should be done). Libgit2 was using the better algorithm in both places, but that is causing some confusion. For now, this makes diff just look for NUL bytes to decide if a file is binary by content in diff.
* | Fix diff patch line number calculationRussell Belfer2013-01-111-18/+20
|/ | | | | | | | This was just wrong. Added a test that verifying patch line numbers even for hunks further into a file and then fixed the algorithm. I needed to add a little extra state into the patch so that I could track old and new file numbers independently, but it should be okay.
* Resolve crash with diff against empty fileRussell Belfer2013-01-081-0/+3
| | | | | | | | | | | It is not legal inside our `p_mmap` function to mmap a zero length file. This adds a test that exercises that case inside diff and fixes the code path where we would try to do that. The fix turns out not to be a lot of code since our default file content is already initialized to "" which works in this case. Fixes #1210
* update copyrightsEdward Thomson2013-01-081-1/+1
|
* Share git_diff_blobs/git_diff_blob_to_buffer codeRussell Belfer2013-01-071-119/+103
| | | | | | | This moves the implementation of these two APIs into common code that will be shared between the two. Also, this adds tests for the `git_diff_blob_to_buffer` API. Lastly, this adds some extra `const` to a few places that can use it.
* Introduce git_diff_blob_to_bufferIgnacio Casal Quinteiro2013-01-071-1/+85
|
* Deploy GITERR_CHECK_VERSIONBen Straub2012-11-301-2/+1
|
* Deploy GIT_DIFF_OPTIONS_INITBen Straub2012-11-301-0/+3
|
* Consolidate text buffer functionsRussell Belfer2012-11-281-1/+1
| | | | | | | | | | | | | There are many scattered functions that look into the contents of buffers to do various text manipulations (such as escaping or unescaping data, calculating text stats, guessing if content is binary, etc). This groups all those functions together into a new file and converts the code to use that. This has two enhancements to existing functionality. The old text stats function is significantly rewritten and the BOM detection code was extended (although largely we can't deal with anything other than a UTF8 BOM).
* Fix warnings on Win64 buildRussell Belfer2012-11-271-5/+9
|
* API updates for submodule.hRussell Belfer2012-11-271-2/+2
|
* Update diff callback param orderRussell Belfer2012-11-271-78/+79
| | | | | | | | This makes the diff functions that take callbacks both take the payload parameter after the callback function pointers and pass the payload as the last argument to the callback function instead of the first. This should make them consistent with other callbacks across the API.
* More external API cleanupVicent Marti2012-11-271-13/+13
| | | | | | Conflicts: src/branch.c tests-clar/refs/branches/create.c
* Fix various cross-platform build issuesRussell Belfer2012-11-091-2/+2
| | | | | | This fixes a number of warnings and problems with cross-platform builds. Among other things, it's not safe to name a member of a structure "strcmp" because that may be #defined.
* Some diff refactorings to help code reuseRussell Belfer2012-11-091-0/+55
| | | | | | | | | | | | | | | | | There are some diff functions that are useful in a rewritten checkout and this lays some groundwork for that. This contains three main things: 1. Share the function diff uses to calculate the OID for a file in the working directory (now named `git_diff__oid_for_file` 2. Add a `git_diff__paired_foreach` function to iterator over two diff lists concurrently. Convert status to use it. 3. Move all the string/prefix/index entry comparisons into function pointers inside the `git_diff_list` object so they can be switched between case sensitive and insensitive versions. This makes them easier to reuse in various functions without replicating logic. As part of this, move a couple of index functions out of diff.c and into index.c.
* Add git_diff_patch_printRussell Belfer2012-10-251-13/+23
| | | | | | | | | This adds a `git_diff_patch_print()` API which is more like the existing API to "print" a patch from an entire `git_diff_list` but operates on a single `git_diff_patch` object. Also, it rewrites the `git_diff_patch_to_str()` API to use that function (making it very small).
* Check errors while generating diff patch stringRussell Belfer2012-10-251-4/+11
|
* Add git_diff_patch_to_str APIRussell Belfer2012-10-241-0/+54
| | | | | This adds an API to generate a complete single-file patch text from a git_diff_patch object.
* 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.