summaryrefslogtreecommitdiff
path: root/diff.c
AgeCommit message (Collapse)Author
2007-02-24diff-patch: Avoid emitting double-slashes in textual patch.Junio C Hamano
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-23Merge branches 'lt/crlf' and 'jc/apply-config'Junio C Hamano
* lt/crlf: Teach core.autocrlf to 'git apply' t0020: add test for auto-crlf Make AutoCRLF ternary variable. Lazy man's auto-CRLF * jc/apply-config: t4119: test autocomputing -p<n> for traditional diff input. git-apply: guess correct -p<n> value for non-git patches. git-apply: notice "diff --git" patch again Fix botched "leak fix" t4119: add test for traditional patch and different p_value apply: fix memory leak in prefix_one() git-apply: require -p<n> when working in a subdirectory. git-apply: do not lose cwd when run from a subdirectory. Teach 'git apply' to look at $HOME/.gitconfig even outside of a repository Teach 'git apply' to look at $GIT_DIR/config
2007-02-23Teach git-diff-files the new option `--no-index`Johannes Schindelin
With this flag and given two paths, git-diff-files behaves as a GNU diff lookalike (plus the git goodies like --check, colour, etc.). This flag is also available in git-diff. It also works outside of a git repository. In addition, if git-diff{,-files} is called without revision or stage parameter, and with exactly two paths at least one of which is not tracked, the default is --no-index. So, you can now say git diff /etc/inittab /etc/fstab and it actually works! This also unifies the duplicated argument parsing between cmd_diff_files() and builtin_diff_files(). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-21Teach diff -B about coloursJohannes Schindelin
Matthias Lederhofer noticed that `diff -B` did not pick up on diff colournig. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-21prefixcmp(): fix-up leftover strncmp().Junio C Hamano
There were instances of strncmp() that were formatted improperly (e.g. whitespace around parameter before closing parenthesis) that caused the earlier mechanical conversion step to miss them. This step cleans them up. Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-21Mechanical conversion to use prefixcmp()Junio C Hamano
This mechanically converts strncmp() to use prefixcmp(), but only when the parameters match specific patterns, so that they can be verified easily. Leftover from this will be fixed in a separate step, including idiotic conversions like if (!strncmp("foo", arg, 3)) => if (!(-prefixcmp(arg, "foo"))) This was done by using this script in px.perl #!/usr/bin/perl -i.bak -p if (/strncmp\(([^,]+), "([^\\"]*)", (\d+)\)/ && (length($2) == $3)) { s|strncmp\(([^,]+), "([^\\"]*)", (\d+)\)|prefixcmp($1, "$2")|; } if (/strncmp\("([^\\"]*)", ([^,]+), (\d+)\)/ && (length($1) == $3)) { s|strncmp\("([^\\"]*)", ([^,]+), (\d+)\)|(-prefixcmp($2, "$1"))|; } and running: $ git grep -l strncmp -- '*.c' | xargs perl px.perl Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-20Merge branch 'js/diff-color-check'Junio C Hamano
* js/diff-color-check: diff --check: use colour
2007-02-18diff --check: use colourJohannes Schindelin
Reuse the colour handling of the regular diff. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-14Lazy man's auto-CRLFLinus Torvalds
It currently does NOT know about file attributes, so it does its conversion purely based on content. Maybe that is more in the "git philosophy" anyway, since content is king, but I think we should try to do the file attributes to turn it off on demand. Anyway, BY DEFAULT it is off regardless, because it requires a [core] AutoCRLF = true in your config file to be enabled. We could make that the default for Windows, of course, the same way we do some other things (filemode etc). But you can actually enable it on UNIX, and it will cause: - "git update-index" will write blobs without CRLF - "git diff" will diff working tree files without CRLF - "git checkout" will write files to the working tree _with_ CRLF and things work fine. Funnily, it actually shows an odd file in git itself: git clone -n git test-crlf cd test-crlf git config core.autocrlf true git checkout git diff shows a diff for "Documentation/docbook-xsl.css". Why? Because we have actually checked in that file *with* CRLF! So when "core.autocrlf" is true, we'll always generate a *different* hash for it in the index, because the index hash will be for the content _without_ CRLF. Is this complete? I dunno. It seems to work for me. It doesn't use the filename at all right now, and that's probably a deficiency (we could certainly make the "is_binary()" heuristics also take standard filename heuristics into account). I don't pass in the filename at all for the "index_fd()" case (git-update-index), so that would need to be passed around, but this actually works fine. NOTE NOTE NOTE! The "is_binary()" heuristics are totally made-up by yours truly. I will not guarantee that they work at all reasonable. Caveat emptor. But it _is_ simple, and it _is_ safe, since it's all off by default. The patch is pretty simple - the biggest part is the new "convert.c" file, but even that is really just basic stuff that anybody can write in "Teaching C 101" as a final project for their first class in programming. Not to say that it's bug-free, of course - but at least we're not talking about rocket surgery here. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-14teach diff machinery about --ignore-space-at-eolJohannes Schindelin
`git diff --ignore-space-at-eol` will ignore whitespace at the line ends. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-14Merge branch 'jc/diff-apply-patch'Junio C Hamano
* jc/diff-apply-patch: git-diff/git-apply: make diff output a bit friendlier to GNU patch (part 2)
2007-02-13Mark places that need blob munging later for CRLF conversion.Linus Torvalds
Here's a patch that I think we can merge right now. There may be other places that need this, but this at least points out the three places that read/write working tree files for git update-index, checkout and diff respectively. That should cover a lot of it [jc: git-apply uses an entirely different codepath both for reading and writing]. Some day we can actually implement it. In the meantime, this points out a place for people to start. We *can* even start with a really simple "we do CRLF conversion automatically, regardless of filename" kind of approach, that just look at the data (all three cases have the _full_ file data already in memory) and says "ok, this is text, so let's convert to/from DOS format directly". THAT somebody can write in ten minutes, and it would already make git much nicer on a DOS/Windows platform, I suspect. And it would be totally zero-cost if you just make it a config option (but please make it dynamic with the _default_ just being 0/1 depending on whether it's UNIX/Windows, just so that UNIX people can _test_ it easily). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-11diff.c: More logical file name quoting for renames in diffstat.Alexandre Julliard
Quote both file names separately when printing a rename, yielding something like "foo" => "bar" instead of the current "foo => bar" Signed-off-by: Alexandre Julliard <julliard@winehq.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-11diff.c: Properly quote file names in diff --summary output.Alexandre Julliard
Signed-off-by: Alexandre Julliard <julliard@winehq.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-11diff.c: Reuse the pprint_rename function for diff --summary output.Alexandre Julliard
This avoids some code duplication, and yields more readable results for directory renames. Signed-off-by: Alexandre Julliard <julliard@winehq.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-10diff_flush_name(): take struct diff_options parameter.Junio C Hamano
Among the low-level output functions called from flush_one_pair(), this was the only function that did not take (filepair, options) as arguments. Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-01-08short i/o: fix calls to write to use xwrite or write_in_fullAndy Whitcroft
We have a number of badly checked write() calls. Often we are expecting write() to write exactly the size we requested or fail, this fails to handle interrupts or short writes. Switch to using the new write_in_full(). Otherwise we at a minimum need to check for EINTR and EAGAIN, where this is appropriate use xwrite(). Note, the changes to config handling are much larger and handled in the next patch in the sequence. Signed-off-by: Andy Whitcroft <apw@shadowen.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-01-07Merge branch 'sp/mmap'Junio C Hamano
* sp/mmap: (27 commits) Spell default packedgitlimit slightly differently Increase packedGit{Limit,WindowSize} on 64 bit systems. Update packedGit config option documentation. mmap: set FD_CLOEXEC for file descriptors we keep open for mmap() pack-objects: fix use of use_pack(). Fix random segfaults in pack-objects. Cleanup read_cache_from error handling. Replace mmap with xmmap, better handling MAP_FAILED. Release pack windows before reporting out of memory. Default core.packdGitWindowSize to 1 MiB if NO_MMAP. Test suite for sliding window mmap implementation. Create pack_report() as a debugging aid. Support unmapping windows on 'temporary' packfiles. Improve error message when packfile mmap fails. Ensure core.packedGitWindowSize cannot be less than 2 pages. Load core configuration in git-verify-pack. Fully activate the sliding window pack access. Unmap individual windows rather than entire files. Document why header parsing won't exceed a window. Loop over pack_windows when inflating/accessing data. ... Conflicts: cache.h pack-check.c
2007-01-07diff-index --cached --raw: show tree entry on the LHS for unmerged entries.Junio C Hamano
This updates the way diffcore represents an unmerged pair somewhat. It used to be that entries with mode=0 on both sides were used to represent an unmerged pair, but now it has an explicit flag. This is to allow diff-index --cached to report the entry from the tree when the path is unmerged in the index. This is used in updating "git reset <tree> -- <path>" to restore absense of the path in the index from the tree. Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-12-29Replace mmap with xmmap, better handling MAP_FAILED.Shawn O. Pearce
In some cases we did not even bother to check the return value of mmap() and just assume it worked. This is bad, because if we are out of virtual address space the kernel returned MAP_FAILED and we would attempt to dereference that address, segfaulting without any real error output to the user. We are replacing all calls to mmap() with xmmap() and moving all MAP_FAILED checking into that single location. If a mmap call fails we try to release enough least-recently-used pack windows to possibly succeed, then retry the mmap() attempt. If we cannot mmap even after releasing pack memory then we die() as none of our callers have any reasonable recovery strategy for a failed mmap. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-12-22Merge branch 'maint'Junio C Hamano
* maint: diff --check: fix off by one error spurious .sp in manpages
2006-12-22diff --check: fix off by one errorJohannes Schindelin
When parsing the diff line starting with '@@', the line number of the '+' file is parsed. For the subsequent line parses, the line number should therefore be incremented after the parse, not before it. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-12-20simplify inclusion of system header files.Junio C Hamano
This is a mechanical clean-up of the way *.c files include system header files. (1) sources under compat/, platform sha-1 implementations, and xdelta code are exempt from the following rules; (2) the first #include must be "git-compat-util.h" or one of our own header file that includes it first (e.g. config.h, builtin.h, pkt-line.h); (3) system headers that are included in "git-compat-util.h" need not be included in individual C source files. (4) "git-compat-util.h" does not have to include subsystem specific header files (e.g. expat.h). Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-12-20fix populate-filespecJunio C Hamano
I hand munged the original patch when committing 1510fea78, and screwed up the conversion. Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-12-16make commit message a little more consistent and confortingNicolas Pitre
It is nicer to let the user know when a commit succeeded all the time, not only the first time. Also the commit sha1 is much more useful than the tree sha1 in this case. This patch also introduces a -q switch to supress this message as well as the summary of created/deleted files. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-12-16Avoid accessing a slow working copy during diffcore operations.Shawn O. Pearce
The Cygwin folks have done a fine job at creating a POSIX layer on Windows That Just Works(tm). However it comes with a penalty; accessing files in the working tree by way of stat/open/mmap can be slower for diffcore than inflating the data from a blob which is stored in a packfile. This performance problem is especially an issue in merge-recursive when dealing with nearly 7000 added files, as we are loading each file's content from the working directory to perform rename detection. I have literally seen (and sadly watched) paint dry in less time than it takes for merge-recursive to finish such a merge. On the other hand this very same merge runs very fast on Solaris. If Git is compiled with NO_FAST_WORKING_DIRECTORY set then we will avoid looking at the working directory when the blob in question is available within a packfile and the caller doesn't need the data unpacked into a temporary file. We don't use loose objects as they have the same open/mmap/close costs as the working directory file access, but have the additional CPU overhead of needing to inflate the content before use. So it is still faster to use the working tree file over the loose object. If the caller needs the file data unpacked into a temporary file its likely because they are going to call an external diff program, passing the file as a parameter. In this case reusing the working tree file will be faster as we don't need to inflate the data and write it out to a temporary file. The NO_FAST_WORKING_DIRECTORY feature is enabled by default on Cygwin, as that is the platform which currently appears to benefit the most from this option. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-12-13Merge branch 'jc/numstat'Junio C Hamano
* jc/numstat: diff --numstat: show binary with '-' to match "apply --numstat"
2006-12-13Allow subcommand.color and color.subcommand color configurationAndy Parkins
While adding colour to the branch command it was pointed out that a config option like "branch.color" conflicts with the pre-existing "branch.something" namespace used for specifying default merge urls and branches. The suggested solution was to flip the order of the components to "color.branch", which I did for colourising branch. This patch does the same thing for - git-log (color.diff) - git-status (color.status) - git-diff (color.diff) - pager (color.pager) I haven't removed the old config options; but they should probably be deprecated and eventually removed to prevent future namespace collisions. I've done this deprecation by changing the documentation for the config file to match the new names; and adding the "color.XXX" options to contrib/completion/git-completion.bash. Unfortunately git-svn reads "diff.color" and "pager.color"; which I don't like to change unilaterally. Signed-off-by: Andy Parkins <andyparkins@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-12-11diff --numstat: show binary with '-' to match "apply --numstat"Junio C Hamano
This changes the --numstat output for binary files from "0 0" to "- -" to match what "apply --numstat" does. Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-11-22git-diff/git-apply: make diff output a bit friendlier to GNU patch (part 2)Junio C Hamano
Somebody was wondering on #git channel why a git generated diff does not apply with GNU patch when the filename contains a SP. It is because GNU patch expects to find TAB (and trailing timestamp) on ---/+++ (old_name and new_name) lines after the filenames. The "diff --git" output format was carefully designed to be compatible with GNU patch where it can, but whitespace characters were always a pain. This adds an extra TAB (but not trailing timestamp) to old_name and new_name lines of git-diff output when the filename has a SP in it. An earlier patch updated git-apply to prepare for this. Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-10-19Merge branch 'js/diff'Junio C Hamano
* js/diff: Turn on recursive with --summary
2006-10-14diff --numstatJunio C Hamano
[jc: with documentation from Jakub] Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-10-05Turn on recursive with --summaryJohannes Schindelin
This makes "git log/diff --summary" imply recursive behaviour, whose effect is summarized in one test output: --- a/t/t4013/diff.diff-tree_--pretty_--root_--summary_initial +++ b/t/t4013/diff.diff-tree_--pretty_--root_--summary_initial @@ -5,7 +5,7 @@ Date: Mon Jun 26 00:00:00 2006 +0000 Initial - create mode 040000 dir + create mode 100644 dir/sub create mode 100644 file0 create mode 100644 file2 $ When a file is created in a subdirectory, we used to say just the directory name only when that directory also was created, which did not make sense from two reasons. It is not any more significant to create a new file in a new directory than to create a new file in an existing directory, and even if it were, reportinging the new directory name without saying the actual filename is not useful. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-10-01Merge branch 'jc/diff-stat'Junio C Hamano
* jc/diff-stat: diff --stat: ensure at least one '-' for deletions, and one '+' for additions diff --stat=width[,name-width]: allow custom diffstat output width. diff --stat: color output. diff --stat: allow custom diffstat output width.
2006-09-29git-diff -B output fix.Junio C Hamano
Geert noticed that complete rewrite diff missed the usual a/ and b/ leading paths. Pickaxe says it never worked, ever. Embarrassing. Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-29diff --stat: ensure at least one '-' for deletions, and one '+' for additionsJohannes Schindelin
The number of '-' and '+' is still linear. The idea is that scaled-length := floor(a * length + b) with the following constraints: if length == 1, scaled-length == 1, and the combined length of plusses and minusses should not be larger than the width by a small margin. Thus, a + b == 1 and a * max_plusses + b + a * max_minusses + b = width + 1 The solution is a * x + b = ((width - 1) * (x - 1) + max_change - 1) / (max_change - 1) Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-29diff --stat=width[,name-width]: allow custom diffstat output width.Linus Torvalds
Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-27diff --stat: color output.Junio C Hamano
Under --color option, diffstat shows '+' and '-' in the graph the same color as added and deleted lines. Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-27diff --stat: allow custom diffstat output width.Junio C Hamano
This adds two parameters to "diff --stat". . --stat-width=72 tells that the page should fit on 72-column output. . --stat-name-width=30 tells that the filename part is limited to 30 columns. Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-24diff.c: second war on whitespace.Junio C Hamano
This adds DIFF_WHITESPACE color class (default = reverse red) to colored diff output to let you catch common whitespace errors. - trailing whitespaces at the end of line - a space followed by a tab in the indent Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-18Merge branch 'jk/diff'Junio C Hamano
* jk/diff: wt-status: remove extraneous newline from 'deleted:' output git-status: document colorization config options Teach runstatus about --untracked git-commit.sh: convert run_status to a C builtin Move color option parsing out of diff.c and into color.[ch] diff: support custom callbacks for output
2006-09-08Move color option parsing out of diff.c and into color.[ch]Jeff King
The intent is to lib-ify colorizing code so it can be reused. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-07diff: support custom callbacks for outputJeff King
Users can request the DIFF_FORMAT_CALLBACK output format to get a callback consisting of the whole diff_queue_struct. Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-07diff --binary generates full index on binary files.Junio C Hamano
... without --full-index. Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-09-02Replace uses of strdup with xstrdup.Shawn Pearce
Like xmalloc and xrealloc xstrdup dies with a useful message if the native strdup() implementation returns NULL rather than a valid pointer. I just tried to use xstrdup in new code and found it to be missing. However I expected it to be present as xmalloc and xrealloc are already commonly used throughout the code. [jc: removed the part that deals with last_XXX, which I am finding more and more dubious these days.] Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-28Merge branch 'jc/apply'Junio C Hamano
* jc/apply: git-apply --reject: finishing touches. apply --reject: count hunks starting from 1, not 0 git-apply --verbose git-apply --reject: send rejects to .rej files. git-apply --reject apply --reverse: tie it all together. diff.c: make binary patch reversible. builtin-apply --reverse: two bugfixes.
2006-08-23Convert memcpy(a,b,20) to hashcpy(a,b).Shawn Pearce
This abstracts away the size of the hash values when copying them from memory location to memory location, much as the introduction of hashcmp abstracted away hash value comparsion. A few call sites were using char* rather than unsigned char* so I added the cast rather than open hashcpy to be void*. This is a reasonable tradeoff as most call sites already use unsigned char* and the existing hashcmp is also declared to be unsigned char*. [jc: Splitted the patch to "master" part, to be followed by a patch for merge-recursive.c which is not in "master" yet. Fixed the cast in the latter hunk to combine-diff.c which was wrong in the original. Also converted ones left-over in combine-diff.c, diff-lib.c and upload-pack.c ] Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-17Do not use memcmp(sha1_1, sha1_2, 20) with hardcoded length.David Rientjes
Introduces global inline: hashcmp(const unsigned char *sha1, const unsigned char *sha2) Uses memcmp for comparison and returns the result based on the length of the hash name (a future runtime decision). Acked-by: Alex Riesen <raa.lkml@gmail.com> Signed-off-by: David Rientjes <rientjes@google.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-17diff.c: make binary patch reversible.Junio C Hamano
This matches the format previous "git-apply --reverse" update expects. Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-16remove unnecessary initializationsDavid Rientjes
[jc: I needed to hand merge the changes to the updated codebase, so the result needs to be checked.] Signed-off-by: David Rientjes <rientjes@google.com> Signed-off-by: Junio C Hamano <junkio@cox.net>