summaryrefslogtreecommitdiff
path: root/src/diff_output.c
Commit message (Collapse)AuthorAgeFilesLines
* Reorganize diff and add basic diff driverRussell Belfer2013-06-101-1526/+0
| | | | | | | | | | | | | | | | | | This is a significant reorganization of the diff code to break it into a set of more clearly distinct files and to document the new organization. Hopefully this will make the diff code easier to understand and to extend. This adds a new `git_diff_driver` object that looks of diff driver information from the attributes and the config so that things like function content in diff headers can be provided. The full driver spec is not implemented in the commit - this is focused on the reorganization of the code and putting the driver hooks in place. This also removes a few #includes from src/repository.h that were overbroad, but as a result required extra #includes in a variety of places since including src/repository.h no longer results in pulling in the whole world.
* Move some diff helpers into separate fileRussell Belfer2013-06-051-422/+2
|
* Basic function context headerRussell Belfer2013-06-051-16/+67
| | | | | | | This implements a basic callback to extract function context for a diff. It always uses the same search heuristic right now with no regular expressions or language-specific variants. Those will come next, I think.
* Move core.abbrev lookup out of diff print loopRussell Belfer2013-05-231-43/+48
| | | | | | This moves the GIT_CVAR_ABBREV lookup out of the loop. Also, this fixes git_diff_print_raw to actually use that constant instead of hardcoding 7 characters.
* Add git_diff_print_raw printing helperRussell Belfer2013-05-171-6/+62
| | | | Makes it easier to emulate the --raw option
* Unify whitespaces to tabsLinquize2013-05-151-15/+15
|
* Fix diff output for renames and copiesRussell Belfer2013-05-101-0/+2
| | | | | | | | | | If you use rename detection, the renamed and copied files would not show any text diffs because the function that decides if data should be loaded didn't know which sides of the diff to load for those cases. This adds a test that looks at the patch generated for diff entries that are COPIED or RENAMED.
* Fix line numbering for patches with eofnlRussell Belfer2013-05-071-0/+2
| | | | | | | When a patch contained an eofnl change (i.e. the last line either gained or lost a newline), the oldno and newno line number values for the lines in the last hunk of the patch were not useful. This makes them behave in a more expected manner.
* Add GIT_DIFF_LINE_CONTEXT_EOFNLRussell Belfer2013-05-071-1/+1
| | | | | | | | | | | | | | | | | | 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.
* More care reporting diff patch iteration errorsRussell Belfer2013-05-011-5/+17
|
* Fix some formatting inconsistencyRussell Belfer2013-04-301-30/+20
|
* Make git_oid_cmp public and add git_oid__cmpRussell Belfer2013-04-291-2/+2
|
* Improve diff config options handlingRussell Belfer2013-04-231-4/+13
| | | | | | | | | | | | | | This makes diff use the cvar cache for config options where possible, and also adds support for a number of other config options to diff including "diff.context", "diff.ignoreSubmodules", "diff.noprefix", "diff.mnemonicprefix", and "core.abbrev". To make this natural, this involved a rearrangement of the code that allocates the diff object vs. the code that initializes it based on the combination of options passed in by the user and read from the config. This commit includes tests for most of these new options as well.
* Tests and more fixes for submodule diffsRussell Belfer2013-04-091-3/+10
| | | | | | | | | | | | | This adds tests for diffs with submodules in them and (perhaps unsurprisingly) requires further fixes to be made. Specifically, this fixes: - when considering if a submodule is dirty in the workdir, it was being treated as dirty even if only the index was dirty. - git_diff_patch_to_str (and git_diff_patch_print) were "printing" the headers for files (and submodules) that were unmodified or had no meaningful content. - added comment to previous fix and removed unneeded parens.
* Fix submodule dirty states not showing if submodules comes before files, or ↵Linquize2013-04-091-1/+2
| | | | | | | | | | there are only dirty submodules but no changed files GIT_DIFF_PATCH_DIFFABLE was not set, so the diff content was not shown When submodule is dirty, the hash may be the same, but the length is different because -dirty is appended We can therefore compare the length or hash
* 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.