summaryrefslogtreecommitdiff
path: root/src/diff.c
Commit message (Collapse)AuthorAgeFilesLines
* diff: preserve original mode in the indexEdward Thomson2015-06-201-10/+14
| | | | | | | When updating the index during a diff, preserve the original mode, which prevents us from dropping the mode to what we have interpreted as on our system (eg, what the working directory claims it to be, which may be a lie on some systems.)
* Introduce `GIT_DIFF_FLAG_EXISTS`Edward Thomson2015-05-281-1/+6
| | | | | | | | | | Mark the `old_file` and `new_file` sides of a delta with a new bit, `GIT_DIFF_FLAG_EXISTS`, that introduces that a particular side of the delta exists in the diff. This is useful for indicating whether a working directory item exists or not, in the presence of a conflict. Diff users may have previously used DELETED to determine this information.
* diff: prettify `maybe_modified` a littleEdward Thomson2015-05-281-12/+15
|
* introduce `git_index_entry_is_conflict`Edward Thomson2015-05-281-7/+8
| | | | | | | | | It's not always obvious the mapping between stage level and conflict-ness. More importantly, this can lead otherwise sane people to write constructs like `if (!git_index_entry_stage(entry))`, which (while technically correct) is unreadable. Provide a nice method to help avoid such messy thinking.
* diff conflicts: don't include incorrect IDEdward Thomson2015-05-281-16/+21
| | | | | | | | | Since a diff entry only concerns a single entry, zero the information for the index side of a conflict. (The index entry would otherwise erroneously include the lowest-stage index entry - generally the ancestor of a conflict.) Test that during status, the index side of the conflict is empty.
* diff: for conflicts w/o workdir, blank nitem sideEdward Thomson2015-05-281-13/+26
| | | | | Make sure that we provide a blanked nitem side when the item does not exist in the working directory.
* diff/status: introduce conflictsEdward Thomson2015-05-281-13/+64
| | | | | | | | | | | When diffing against an index, return a new `GIT_DELTA_CONFLICTED` delta type for items that are conflicted. For a single file path, only one delta will be produced (despite the fact that there are multiple entries in the index). Index iterators now have the (optional) ability to return conflicts in the index. Prior to this change, they would be omitted, and callers (like diff) would omit conflicted index entries entirely.
* diff: wrap the iterator functionsEdward Thomson2015-05-281-25/+73
| | | | | | Wrap the iterator current / advance functions so that we can extend them, but also handle GIT_ITEROVER cases in the iterator funcs instead of the callers.
* checkout: break case-changes into delete/addEdward Thomson2015-05-041-0/+13
| | | | | | | When checking out with a case-insensitive working directory, we want to change the case of items in the working directory to reflect changes that occured in the checkout target. Diff now has an option to break case-changing renames into delete/add.
* Fixed GIT_DIFF_UPDATE_INDEX not being aware of executable bit changesPierre-Olivier Latour2015-04-151-1/+1
| | | | | | | | | | | | In the prior implementation, enabling GIT_DIFF_UPDATE_INDEX would overwrite entries in the index with the ones generated from scanning the working if the OID was the same. Because this OID comparison ignores file modes, this means an file in the workdir with only an exec bit difference with the one in the index would end up being overwritten, resulting in the exec bit being loss. There might be other related bugs but the fix of comparing OIDs and file modes should address them all.
* Removed unnecessary conditionPierre-Olivier Latour2015-04-151-9/+6
| | | | The variable noid is guaranteed to be zero at this point of the code path.
* Use git_oid_cpy() instead of memcpy()Pierre-Olivier Latour2015-04-151-1/+1
|
* Avoid retaining / releasing the index more than necessary when ↵Pierre-Olivier Latour2015-03-111-2/+1
| | | | GIT_DIFF_UPDATE_INDEX is enabled
* config: borrow refcounted referencescmn/config-borrow-entryCarlos Martín Nieto2015-03-031-1/+2
| | | | | | | | | | | | | | | This changes the get_entry() method to return a refcounted version of the config entry, which you have to free when you're done. This allows us to avoid freeing the memory in which the entry is stored on a refresh, which may happen at any time for a live config. For this reason, get_string() has been forbidden on live configs and a new function get_string_buf() has been added, which stores the string in a git_buf which the user then owns. The functions which parse the string value takea advantage of the borrowing to parse safely and then release the entry.
* git_filter_opt_t -> git_filter_flag_tEdward Thomson2015-02-191-1/+1
| | | | | For consistency with the rest of the library, where an opt is an options *structure*.
* Make our overflow check look more like gcc/clang'sEdward Thomson2015-02-131-2/+3
| | | | | | | | | Make our overflow checking look more like gcc and clang's, so that we can substitute it out with the compiler instrinsics on platforms that support it. This means dropping the ability to pass `NULL` as an out parameter. As a result, the macros also get updated to reflect this as well.
* allocations: test for overflow of requested sizeEdward Thomson2015-02-121-0/+2
| | | | | Introduce some helper macros to test integer overflow from arithmetic and set error message appropriately.
* Added missing error handling pathJacques Germishuys2014-12-301-0/+1
|
* Plug leaksCarlos Martín Nieto2014-11-231-2/+1
| | | | Valgrind is now clean except for libssl and libgcrypt.
* iterator: submodules are determined by an index or treecmn/submodule-and-dirCarlos Martín Nieto2014-11-071-2/+7
| | | | | | | | | | | | We cannot know from looking at .gitmodules whether a directory is a submodule or not. We need the index or tree we are comparing against to tell us. Otherwise we have to assume the entry in .gitmodules is stale or otherwise invalid. Thus we pass the index of the repository into the workdir iterator, even if we do not want to compare against it. This follows what git does, which even for `git diff <tree>`, it will consider staged submodules as such.
* Changed context_lines and interhunk_lines to uint32_t to match struct ↵Pierre-Olivier Latour2014-10-271-1/+1
| | | | s_xdemitconf
* Merge remote-tracking branch 'origin/development' into ↵Alan Rogers2014-06-041-44/+15
|\ | | | | | | | | | | | | fix-git-status-list-new-unreadable-folder Conflicts: include/git2/diff.h
| * Increase use of config snapshotsrb/coverity-fixesRussell Belfer2014-05-131-9/+10
| | | | | | | | And decrease extra reload checks of config data.
| * Merge pull request #2328 from libgit2/rb/how-broken-can-ignores-beVicent Marti2014-05-131-35/+5
| |\ | | | | | | Improve checks for ignore containment
| | * Improve checks for ignore containmentrb/how-broken-can-ignores-beRussell Belfer2014-05-061-35/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The diff code was using an "ignored_prefix" directory to track if a parent directory was ignored that contained untracked files alongside tracked files. Unfortunately, when negative ignore rules were used for directories inside ignored parents, the wrong rules were applied to untracked files inside the negatively ignored child directories. This commit moves the logic for ignore containment into the workdir iterator (which is a better place for it), so the ignored-ness of a directory is contained in the frame stack during traversal. This allows a child directory to override with a negative ignore and yet still restore the ignored state of the parent when we traverse out of the child. Along with this, there are some problems with "directory only" ignore rules on container directories. Given "a/*" and "!a/b/c/" (where the second rule is a directory rule but the first rule is just a generic prefix rule), then the directory only constraint was having "a/b/c/d/file" match the first rule and not the second. This was fixed by having ignore directory-only rules test a rule against the prefix of a file with LEADINGDIR enabled. Lastly, spot checks for ignores using `git_ignore_path_is_ignored` were tested from the top directory down to the bottom to deal with the containment problem, but this is wrong. We have to test bottom to top so that negative subdirectory rules will be checked before parent ignore rules. This does change the behavior of some existing tests, but it seems only to bring us more in line with core Git, so I think those changes are acceptable.
* | | Implement GIT_DIFF_INCLUDE_UNREADABLE_AS_UNTRACKEDAlan Rogers2014-06-041-1/+4
| | |
* | | Don't need to duplicate this code.Alan Rogers2014-05-231-5/+1
| | |
* | | Return GIT_DELTA_UNREADABLE for a file with a mode changeAlan Rogers2014-05-221-0/+5
| | |
* | | Remove errant whitespace.Alan Rogers2014-05-211-1/+1
| | |
* | | Return GIT_FILEMODE_UNREADABLE for files that fail to stat.Alan Rogers2014-05-211-16/+15
| | |
* | | Start adding GIT_DELTA_UNREADABLE and GIT_STATUS_WT_UNREADABLE.Alan Rogers2014-05-201-10/+28
| | |
* | | Skip unreadable files for now.Alan Rogers2014-05-201-3/+3
|/ /
* | Add filter options and ALLOW_UNSAFERussell Belfer2014-05-061-1/+2
|/ | | | | | | | | Diff and status do not want core.safecrlf to actually raise an error regardless of the setting, so this extends the filter API with an additional options flags parameter and adds a flag so that filters can be applied with GIT_FILTER_OPT_ALLOW_UNSAFE, indicating that unsafe filter application should be downgraded from a failure to a warning.
* Fix remaining init_options inconsistenciesRussell Belfer2014-05-021-9/+2
| | | | | There were a couple of "init_opts()" functions a few more cases of structure initialization that I somehow missed.
* Make init_options fns use unsigned ints and macroRussell Belfer2014-05-021-15/+12
| | | | | Use an unsigned int for the version and add a helper macro so the code is simplified (and so the error message is a common string).
* Remove trace / add git_diff_perfdata struct + apiRussell Belfer2014-05-021-36/+40
|
* Get rid of redundant git_diff_options_init fnRussell Belfer2014-05-021-14/+0
| | | | Since git_diff_init_options was introduced, remove this old fn.
* Add payloads, bitmaps to trace APIRussell Belfer2014-05-021-6/+6
| | | | | | | | | This is a proposed adjustment to the trace APIs. This makes the trace levels into a bitmask so that they can be selectively enabled and adds a callback-level payload, plus a message-level payload. This makes it easier for me to a GIT_TRACE_PERF callbacks that are simply bypassed if the PERF level is not set.
* Add GIT_STATUS_OPT_UPDATE_INDEX and use trace APIRussell Belfer2014-05-021-13/+7
| | | | | | This adds an option to refresh the stat cache while generating status. It also rips out the GIT_PERF stuff I had an makes use of the trace API to keep statistics about what happens during diff.
* Add diff option to update index stat cacheRussell Belfer2014-05-021-4/+32
| | | | | | | | | | When diff is scanning the working directory, if it finds a file where it is not sure if the index entry matches the working dir, it will recalculate the OID (which is pretty expensive). This adds a new flag to diff so that if the OID calculation finds that the file actually has not changed (i.e. just the modified time was altered or such), then it will refresh the stat cache in the index so that future calls to diff will not have to check the oid again.
* Lay groundwork for updating stat cache in diffRussell Belfer2014-05-021-14/+30
| | | | | | | | | | | This reorganized the diff OID calculation to make it easier to correctly update the stat cache during a diff once the flags to do so are enabled. This includes marking the path of a git_index_entry as const so we can make a "fake" git_index_entry with a "const char *" path and not get warnings. I was a little surprised at how unobtrusive this change was, but I think it's probably a good thing.
* Skip diff oid calc when size definitely changedRussell Belfer2014-05-021-4/+11
| | | | | | | | | | | | | When we think the stat cache in the index seems valid and the size or mode of a file has definitely changed, then don't bother trying to recalculate the OID of the workdir bits to confirm that it is modified - just accept that it is modified. This can result in files that show as modified with no actual diff, but the behavior actually appears to match Git on the command line. This also includes a minor optimization to not perform a submodule lookup on the ".git" directory itself.
* Add build option for diff internal statisticsRussell Belfer2014-05-021-34/+45
|
* Merge pull request #2241 from libgit2/rb/stash-skip-submodulesVicent Marti2014-04-251-70/+8
|\ | | | | Improve stash and checkout for ignored + untracked items
| * Treat ignored, empty, and untracked dirs differentRussell Belfer2014-04-231-5/+6
| | | | | | | | | | | | In the iterator, distinguish between ignores and empty directories so that diff and status can ignore empty directories, but checkout and stash can treat them as untracked items.
| * Make checkout match diff for untracked/ignored dirRussell Belfer2014-04-221-70/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When diff finds an untracked directory, it emulates Git behavior by looking inside the directory to see if there are any untracked items inside it. If there are only ignored items inside the dir, then diff considers it ignored, even if there is no direct ignore rule for it. Checkout was not copying this behavior - when it found an untracked directory, it just treated it as untracked. Unfortunately, when combined with GIT_CHECKOUT_REMOVE_UNTRACKED, this made is seem that checkout (and stash, which uses checkout) was removing ignored items when you had only asked it to remove untracked ones. This commit moves the logic for advancing past an untracked dir while scanning for non-ignored items into an iterator helper fn, and uses that for both diff and checkout.
* | Use git_diff_get_stats in example/diff + refactorRussell Belfer2014-04-221-1/+2
|/ | | | | | | | | | | | | | | | | | | | | 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.
* Decouple index iterator sort from indexRussell Belfer2014-04-171-41/+38
| | | | | | | | This makes the index iterator honor the GIT_ITERATOR_IGNORE_CASE and GIT_ITERATOR_DONT_IGNORE_CASE flags without modifying the index data itself. To take advantage of this, I had to export a number of the internal index entry comparison functions. I also wrote some new tests to exercise the capability.
* Sanitize git_diff_format_email_options' summary parameterJacques Germishuys2014-04-151-1/+19
| | | | It will form part of the subject line and should thus be one line.
* Introduce git_diff_format_email and git_diff_commit_as_emailJacques Germishuys2014-04-151-0/+204
|