summaryrefslogtreecommitdiff
path: root/diff.c
AgeCommit message (Collapse)AuthorFilesLines
2013-07-11Merge branch 'jc/maint-diff-core-safecrlf'Libravatar Junio C Hamano1-1/+9
"git diff" refused to even show difference when core.safecrlf is set to true (i.e. error out) and there are offending lines in the working tree files. * jc/maint-diff-core-safecrlf: diff: demote core.safecrlf=true to core.safecrlf=warn
2013-06-25diff: demote core.safecrlf=true to core.safecrlf=warnLibravatar Junio C Hamano1-1/+9
Otherwise the user will not be able to start to guess where in the contents in the working tree the offending unsafe CR lies. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-06-19diff: add --ignore-blank-lines optionLibravatar Antoine Pelisse1-0/+2
The goal of the patch is to introduce the GNU diff -B/--ignore-blank-lines as closely as possible. The short option is not available because it's already used for "break-rewrites". When this option is used, git-diff will not create hunks that simply add or remove empty lines, but will still show empty lines addition/suppression if they are close enough to "valuable" changes. There are two differences between this option and GNU diff -B option: - GNU diff doesn't have "--inter-hunk-context", so this must be handled - The following sequence looks like a bug (context is displayed twice): $ seq 5 >file1 $ cat <<EOF >file2 change 1 2 3 4 5 change EOF $ diff -u -B file1 file2 --- file1 2013-06-08 22:13:04.471517834 +0200 +++ file2 2013-06-08 22:13:23.275517855 +0200 @@ -1,5 +1,7 @@ +change 1 2 + 3 4 5 @@ -3,3 +5,4 @@ 3 4 5 +change So here is a more thorough description of the option: - real changes are interesting - blank lines that are close enough (less than context size) to interesting changes are considered interesting (recursive definition) - "context" lines are used around each hunk of interesting changes - If two hunks are separated by less than "inter-hunk-context", they will be merged into one. The implementation does the "interesting changes selection" in a single pass. Signed-off-by: Antoine Pelisse <apelisse@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-04-15Merge branch 'jk/diff-graph-submodule-summary'Libravatar Junio C Hamano1-0/+1
Make "git diff --graph" work better with submodule log output. * jk/diff-graph-submodule-summary: submodule: print graph output next to submodule log
2013-04-15Merge branch 'jk/diff-algo-finishing-touches'Libravatar Junio C Hamano1-2/+3
"git diff --diff-algorithm algo" is also understood as "git diff --diff-algorithm=algo". * jk/diff-algo-finishing-touches: diff: allow unstuck arguments with --diff-algorithm git-merge(1): document diff-algorithm option to merge-recursive
2013-04-12Correct common spelling mistakes in comments and testsLibravatar Stefano Lattarini1-1/+1
Most of these were found using Lucas De Marchi's codespell tool. Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Acked-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-04-05submodule: print graph output next to submodule logLibravatar John Keeping1-0/+1
When running "git log -p --submodule=log", the submodule log is not indented by the graph output, although all other lines are. Fix this by prepending the current line prefix to each line of the submodule log. Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-04-05diff: allow unstuck arguments with --diff-algorithmLibravatar John Keeping1-2/+3
The argument to --diff-algorithm is mandatory, so there is no reason to require the argument to be stuck to the option with '='. Change this for consistency with other Git commands. Note that this does not change the handling of diff-algorithm in merge-recursive.c since the primary interface to that is via the -X option to 'git merge' where the unstuck form does not make sense. Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-04-01Merge branch 'ap/maint-diff-rename-avoid-overlap' into maintLibravatar Junio C Hamano1-1/+13
* ap/maint-diff-rename-avoid-overlap: tests: make sure rename pretty print works diff: prevent pprint_rename from underrunning input diff: Fix rename pretty-print when suffix and prefix overlap
2013-03-25Merge branch 'ap/maint-diff-rename-avoid-overlap'Libravatar Junio C Hamano1-1/+13
The logic used by "git diff -M --stat" to shorten the names of files before and after a rename did not work correctly when the common prefix and suffix between the two filenames overlapped. * ap/maint-diff-rename-avoid-overlap: tests: make sure rename pretty print works diff: prevent pprint_rename from underrunning input diff: Fix rename pretty-print when suffix and prefix overlap
2013-03-21diff.c: diff.renamelimit => diff.renameLimit in messageLibravatar Max Nanasy1-1/+1
In the warning message printed when rename or unmodified copy detection was skipped due to too many files, change "diff.renamelimit" to "diff.renameLimit", in order to make it consistent with git documentation, which consistently uses "diff.renameLimit". Signed-off-by: Max Nanasy <max.nanasy@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-02-26diff: prevent pprint_rename from underrunning inputLibravatar Thomas Rast1-7/+10
The logic described in d020e27 (diff: Fix rename pretty-print when suffix and prefix overlap, 2013-02-23) is wrong: The proof in the comment is valid only if both strings are the same length. *One* of old/new can reach a-1 (b-1, resp.) if 'a' is a suffix of 'b' (or vice versa). Since the intent was to let the loop run down to the '/' at the end of the common prefix, fix it by making that distinction explicit: if there is no prefix, allow no underrun. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-02-23diff: Fix rename pretty-print when suffix and prefix overlapLibravatar Antoine Pelisse1-1/+10
When considering a rename for two files that have a suffix and a prefix that can overlap, a confusing line is shown. As an example, renaming "a/b/b/c" to "a/b/c" shows "a/b/{ => }/b/c". Currently, what we do is calculate the common prefix ("a/b/"), and the common suffix ("/b/c"), but the same "/b/" is actually counted both in prefix and suffix. Then when calculating the size of the non-common part, we end-up with a negative value which is reset to 0, thus the "{ => }". Do not allow the common suffix to overlap the common prefix and stop when reaching a "/" that would be in both. Signed-off-by: Antoine Pelisse <apelisse@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-02-17Merge branch 'mp/diff-algo-config'Libravatar Junio C Hamano1-0/+34
Add diff.algorithm configuration so that the user does not type "diff --histogram". * mp/diff-algo-config: diff: Introduce --diff-algorithm command line option config: Introduce diff.algorithm variable git-completion.bash: Autocomplete --minimal and --histogram for git-diff
2013-02-14Merge branch 'jk/diff-graph-cleanup'Libravatar Junio C Hamano1-97/+34
Refactors a lot of repetitive code sequence from the graph drawing code and adds it to the combined diff output. * jk/diff-graph-cleanup: combine-diff.c: teach combined diffs about line prefix diff.c: use diff_line_prefix() where applicable diff: add diff_line_prefix function diff.c: make constant string arguments const diff: write prefix to the correct file graph: output padding for merge subsequent parents
2013-02-12diff.c: use diff_line_prefix() where applicableLibravatar John Keeping1-95/+20
Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-02-12diff: add diff_line_prefix functionLibravatar John Keeping1-0/+10
This is a helper function to call the diff output_prefix function and return its value as a C string, allowing us to greatly simplify everywhere that needs to get the output prefix. Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-02-12diff.c: make constant string arguments constLibravatar John Keeping1-2/+4
Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-02-12diff: write prefix to the correct fileLibravatar John Keeping1-1/+1
Write the prefix for an output line to the same file as the actual content. Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-01-16diff: Introduce --diff-algorithm command line optionLibravatar Michal Privoznik1-1/+11
Since command line options have higher priority than config file variables and taking previous commit into account, we need a way how to specify myers algorithm on command line. However, inventing `--myers` is not the right answer. We need far more general option, and that is `--diff-algorithm`. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-01-16config: Introduce diff.algorithm variableLibravatar Michal Privoznik1-0/+24
Some users or projects prefer different algorithms over others, e.g. patience over myers or similar. However, specifying appropriate argument every time diff is to be used is impractical. Moreover, creating an alias doesn't play nicely with other tools based on diff (git-show for instance). Hence, a configuration variable which is able to set specific algorithm is needed. For now, these four values are accepted: 'myers' (which has the same effect as not setting the config variable at all), 'minimal', 'patience' and 'histogram'. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-01-14Merge branch 'jc/blame-no-follow'Libravatar Junio C Hamano1-0/+2
Teaches "--no-follow" option to "git blame" to disable its whole-file rename detection. * jc/blame-no-follow: blame: pay attention to --no-follow diff: accept --no-follow option
2012-11-29Merge branch 'lt/diff-stat-show-0-lines'Libravatar Junio C Hamano1-25/+29
"git diff --stat" miscounted the total number of changed lines when binary files were involved and hidden beyond --stat-count. It also miscounted the total number of changed files when there were unmerged paths. * lt/diff-stat-show-0-lines: t4049: refocus tests diff --shortstat: do not count "unmerged" entries diff --stat: do not count "unmerged" entries diff --stat: move the "total count" logic to the last loop diff --stat: use "file" temporary variable to refer to data->files[i] diff --stat: status of unmodified pair in diff-q is not zero test: add failing tests for "diff --stat" to t4049
2012-11-27diff --shortstat: do not count "unmerged" entriesLibravatar Junio C Hamano1-3/+2
Fix the same issue as the previous one for "git diff --stat"; unmerged entries was doubly-counted. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-27diff --stat: do not count "unmerged" entriesLibravatar Junio C Hamano1-2/+4
Even though we show a separate *UNMERGED* entry in the patch and diffstat output (or in the --raw format, for that matter) in addition to and separately from the diff against the specified stage (defaulting to #2) for unmerged paths, they should not be counted in the total number of files affected---that would lead to counting the same path twice. The separation done by the previous step makes this fix simple and straightforward. Among the filepairs in diff_queue, paths that weren't modified, and the extra "unmerged" entries do not count as total number of files. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-27diff --stat: move the "total count" logic to the last loopLibravatar Junio C Hamano1-9/+12
The diffstat generation logic, with --stat-count limit, is implemented as three loops. - The first counts the width necessary to show stats up to specified number of entries, and notes up to how many entries in the data we need to iterate to show the graph; - The second iterates that many times to draw the graph, adjusts the number of "total modified files", and counts the total added/deleted lines for the part that was shown in the graph; - The third iterates over the remainder and only does the part to count "total added/deleted lines" and to adjust "total modified files" without drawing anything. Move the logic to count added/deleted lines and modified files from the second loop to the third loop. This incidentally fixes a bug. The third loop was not filtering binary changes (counted in bytes) from the total added/deleted as it should. The second loop implemented this correctly, so if a binary change appeared earlier than the --stat-count cutoff, the code counted number of added/deleted lines correctly, but if it appeared beyond the cutoff, the number of lines would have mixed with the byte count in the buggy third loop. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-27diff --stat: use "file" temporary variable to refer to data->files[i]Libravatar Junio C Hamano1-13/+13
The generated code shouldn't change but it is easier to read. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-27diff --stat: status of unmodified pair in diff-q is not zeroLibravatar Junio C Hamano1-1/+1
It is spelled DIFF_STATUS_UNKNOWN these days, and is different from zero. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-25Merge branch 'rr/submodule-diff-config'Libravatar Junio C Hamano1-11/+35
Allow "git diff --submodule=log" to set to be the default via configuration. * rr/submodule-diff-config: submodule: display summary header in bold diff: rename "set" variable diff: introduce diff.submodule configuration variable Documentation: move diff.wordRegex from config.txt to diff-config.txt
2012-11-25Merge branch 'lt/diff-stat-show-0-lines'Libravatar Junio C Hamano1-10/+15
We failed to mention a file without any content change but whose permission bit was modified, or (worse yet) a new file without any content in the "git diff --stat" output. * lt/diff-stat-show-0-lines: Fix "git diff --stat" for interesting - but empty - file changes
2012-11-18submodule: display summary header in boldLibravatar Ramkumar Ramachandra1-1/+1
Currently, 'git diff --submodule' displays output with a bold diff header for non-submodules. So this part is in bold: diff --git a/file1 b/file1 index 30b2f6c..2638038 100644 --- a/file1 +++ b/file1 For submodules, the header looks like this: Submodule submodule1 012b072..248d0fd: Unfortunately, it's easy to miss in the output because it's not bold. Change this. Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-18diff: rename "set" variableLibravatar Jeff King1-6/+6
Once upon a time the builtin_diff function used one color, and the color variables were called "set" and "reset". Nowadays it is a much longer function and we use several colors (e.g., "add", "del"). Rename "set" to "meta" to show that it is the color for showing diff meta-info (it still does not indicate that it is a "color", but at least it matches the scheme of the other color variables). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-18diff: introduce diff.submodule configuration variableLibravatar Ramkumar Ramachandra1-4/+28
Introduce a diff.submodule configuration variable corresponding to the '--submodule' command-line option of 'git diff'. Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-09Merge branch 'nd/builtin-to-libgit'Libravatar Jeff King1-0/+16
Code cleanups so that libgit.a does not depend on anything in the builtin/ directory. * nd/builtin-to-libgit: fetch-pack: move core code to libgit.a fetch-pack: remove global (static) configuration variable "args" send-pack: move core code to libgit.a Move setup_diff_pager to libgit.a Move print_commit_list to libgit.a Move estimate_bisect_steps to libgit.a Move try_merge_command and checkout_fast_forward to libgit.a
2012-11-09Merge branch 'mh/maint-parse-dirstat-fix'Libravatar Jeff King1-19/+21
Cleans up some code and avoids a potential bug. * mh/maint-parse-dirstat-fix: parse_dirstat_params(): use string_list to split comma-separated string
2012-10-29Move setup_diff_pager to libgit.aLibravatar Nguyễn Thái Ngọc Duy1-0/+16
This is used by diff-no-index.c, part of libgit.a while it stays in builtin/diff.c. Move it to diff.c so that we won't get undefined reference if a program that uses libgit.a happens to pull it in. While at it, move check_pager from git.c to pager.c. It makes more sense there and pager.c is also part of libgit.a Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Jeff King <peff@peff.net>
2012-10-29parse_dirstat_params(): use string_list to split comma-separated stringLibravatar Michael Haggerty1-19/+21
Use string_list_split_in_place() to split the comma-separated parameters string. This simplifies the code and also fixes a bug: the old code made calls like memcmp(p, "lines", p_len) which needn't work if p_len is different than the length of the constant string (and could illegally access memory if p_len is larger than the length of the constant string). When p_len was less than the length of the constant string, the old code would have allowed some abbreviations to be accepted (e.g., "cha" for "changes") but this seems to have been a bug rather than a feature, because (1) it is not documented; (2) no attempt was made to handle ambiguous abbreviations, like "c" for "changes" vs "cumulative". Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Jeff King <peff@peff.net>
2012-10-17Fix "git diff --stat" for interesting - but empty - file changesLibravatar Linus Torvalds1-10/+15
The behavior of "git diff --stat" is rather odd for files that have zero lines of changes: it will discount them entirely unless they were renames. Which means that the stat output will simply not show files that only had "other" changes: they were created or deleted, or their mode was changed. Now, those changes do show up in the summary, but so do renames, so the diffstat logic is inconsistent. Why does it show renames with zero lines changed, but not mode changes or added files with zero lines changed? So change the logic to not check for "is_renamed", but for "is_interesting" instead, where "interesting" is judged to be any action but a pure data change (because a pure data change with zero data changed really isn't worth showing, if we ever get one in our diffpairs). So if you did chmod +x Makefile git diff --stat before, it would show empty (" 0 files changed"), with this it shows Makefile | 0 1 file changed, 0 insertions(+), 0 deletions(-) which I think is a more correct diffstat (and then with "--summary" it shows *what* the metadata change to Makefile was - this is completely consistent with our handling of renamed files). Side note: the old behavior was *really* odd. With no changes at all, "git diff --stat" output was empty. With just a chmod, it said "0 files changed". No way is our legacy behavior sane. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-30diff: diff.context configuration gives default to -ULibravatar Jeff Muizelaar1-1/+8
Introduce a configuration variable diff.context that tells Porcelain commands to use a non-default number of context lines instead of 3 (the default). With this variable, users do not have to keep repeating "git log -U8" from the command line; instead, it becomes sufficient to say "git config diff.context 8" just once. Signed-off-by: Jeff Muizelaar <jmuizelaar@mozilla.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-21diff: accept --no-follow optionLibravatar Junio C Hamano1-0/+2
Once you do $ alias glogone git log --follow there is no way to say $ glogone --no-follow ... Not that "log --follow" is all that useful, but it is cheap to support the common "you can defeat an undesirable option with a 'no-' variant of it later on the command line" pattern. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-20Merge branch 'nd/maint-diffstat-summary' into maintLibravatar Junio C Hamano1-6/+4
* nd/maint-diffstat-summary: Revert diffstat back to English
2012-09-18Merge branch 'jc/make-static'Libravatar Junio C Hamano1-1/+1
Turn many file-scope private symbols to static to reduce the global namespace contamination. * jc/make-static: sequencer.c: mark a private file-scope symbol as static ident.c: mark private file-scope symbols as static trace.c: mark a private file-scope symbol as static wt-status.c: mark a private file-scope symbol as static read-cache.c: mark a private file-scope symbol as static strbuf.c: mark a private file-scope symbol as static sha1-array.c: mark a private file-scope symbol as static symlinks.c: mark private file-scope symbols as static notes.c: mark a private file-scope symbol as static rerere.c: mark private file-scope symbols as static graph.c: mark private file-scope symbols as static diff.c: mark a private file-scope symbol as static commit.c: mark a file-scope private symbol as static builtin/notes.c: mark file-scope private symbols as static
2012-09-17Merge branch 'nd/maint-diffstat-summary'Libravatar Junio C Hamano1-6/+4
Earlier we made the diffstat summary line that shows the number of lines added/deleted localizable, but it was found irritating having to see them in various languages on a list whose discussion language is English. The original had trivial thinko in reverting Q_(), which has been fixed. * nd/maint-diffstat-summary: Revert diffstat back to English
2012-09-15diff.c: mark a private file-scope symbol as staticLibravatar Junio C Hamano1-1/+1
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-14Revert diffstat back to EnglishLibravatar Nguyễn Thái Ngọc Duy1-6/+4
This reverts the i18n part of 7f81463 (Use correct grammar in diffstat summary line - 2012-02-01) but still keeps the grammar correctness for English. It also reverts b354f11 (Fix tests under GETTEXT_POISON on diffstat - 2012-08-27). The result is diffstat always in English for all commands. This helps stop users from accidentally sending localized format-patch'd patches. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-11Sync with 1.7.11.6Libravatar Junio C Hamano1-3/+2
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-11Merge branch 'ab/diff-write-incomplete-line' into maint-1.7.11Libravatar Junio C Hamano1-0/+1
* ab/diff-write-incomplete-line: Fix '\ No newline...' annotation in rewrite diffs
2012-09-11Merge branch 'tr/void-diff-setup-done' into maint-1.7.11Libravatar Junio C Hamano1-3/+1
* tr/void-diff-setup-done: diff_setup_done(): return void
2012-09-10Merge branch 'maint-1.7.11' into maintLibravatar Junio C Hamano1-6/+10
* maint-1.7.11: Almost 1.7.11.6 gitweb: URL-decode $my_url/$my_uri when stripping PATH_INFO rebase -i: use full onto sha1 in reflog sh-setup: protect from exported IFS receive-pack: do not leak output from auto-gc to standard output t/t5400: demonstrate breakage caused by informational message from prune setup: clarify error messages for file/revisions ambiguity send-email: improve RFC2047 quote parsing fsck: detect null sha1 in tree entries do not write null sha1s to on-disk index diff: do not use null sha1 as a sentinel value
2012-09-10Merge branch 'jk/maint-null-in-trees' into maint-1.7.11Libravatar Junio C Hamano1-6/+10
"git diff" had a confusion between taking data from a path in the working tree and taking data from an object that happens to have name 0{40} recorded in a tree. * jk/maint-null-in-trees: fsck: detect null sha1 in tree entries do not write null sha1s to on-disk index diff: do not use null sha1 as a sentinel value