aboutsummaryrefslogtreecommitdiff
path: root/builtin-apply.c
Commit message (Collapse)AuthorAge
* Add core.symlinks to mark filesystems that do not support symbolic links.Johannes Sixt2007-03-02
| | | | | | | | | | | | | | | | | | | | | Some file systems that can host git repositories and their working copies do not support symbolic links. But then if the repository contains a symbolic link, it is impossible to check out the working copy. This patch enables partial support of symbolic links so that it is possible to check out a working copy on such a file system. A new flag core.symlinks (which is true by default) can be set to false to indicate that the filesystem does not support symbolic links. In this case, symbolic links that exist in the trees are checked out as small plain files, and checking in modifications of these files preserve the symlink property in the database (as long as an entry exists in the index). Of course, this does not magically make symbolic links work on such defective file systems; hence, this solution does not help if the working copy relies on that an entry is a real symbolic link. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <junkio@cox.net>
* convert object type handling from a string to a numberNicolas Pitre2007-02-27
| | | | | | | | | | | | | | | We currently have two parallel notation for dealing with object types in the code: a string and a numerical value. One of them is obviously redundent, and the most used one requires more stack space and a bunch of strcmp() all over the place. This is an initial step for the removal of the version using a char array found in object reading code paths. The patch is unfortunately large but there is no sane way to split it in smaller parts without breaking the system. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
* Merge branch 'maint'Junio C Hamano2007-02-27
|\ | | | | | | | | | | | | * maint: git-apply: do not fix whitespaces on context lines. diff --cc: integer overflow given a 2GB-or-larger file mailinfo: do not get confused with logical lines that are too long.
| * git-apply: do not fix whitespaces on context lines.Junio C Hamano2007-02-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Internal function apply_line() is called to copy both context lines and added lines to the output buffer, while possibly fixing the whitespace breakages depending on --whitespace=strip settings. However, it did its fix-up on both context lines and added lines. This resulted in two symptoms: (1) The number of lines reported to have been fixed up included these context lines. (2) However, the lines actually shown were limited to the added lines that had whitespace breakages. Signed-off-by: Junio C Hamano <junkio@cox.net>
* | Merge branch 'js/apply'Junio C Hamano2007-02-24
|\ \ | | | | | | | | | | | | * js/apply: apply: make --verbose a little more useful
| * | apply: make --verbose a little more usefulJohannes Schindelin2007-02-22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When a patch fails, I automatically add '-v' to the command line to see what fails. This patch makes -v a synonym to --verbose, and actually tells the user which text was not found. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
| | |
| \ \
*-. \ \ Merge branches 'lt/crlf' and 'jc/apply-config'Junio C Hamano2007-02-22
|\ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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
| | * | | git-apply: guess correct -p<n> value for non-git patches.Junio C Hamano2007-02-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This enhances the third point in the previous commit. When applying a non-git patch that begins like this: --- 2.6.orig/mm/slab.c +++ 2.6/mm/slab.c @@ -N,M +L,K @@@ ... and if you are in 'mm' subdirectory, we notice that -p2 is the right option to use to apply the patch in file slab.c in the current directory (i.e. mm/slab.c) The guess function also knows about this pattern, where you would need to use -p0 if applying from the top-level: --- mm/slab.c +++ mm/slab.c @@ -N,M +L,K @@@ ... Signed-off-by: Junio C Hamano <junkio@cox.net>
| | * | | git-apply: notice "diff --git" patch againJunio C Hamano2007-02-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Earlier one that tried to be too consistent with GNU patch by not stripping the leading path when we _know_ we are in a subdirectory and the patch is relative to the toplevel was a mistake. This fixes it. - No change to behaviour when it is run from the toplevel of the repository. - When run from a subdirectory to apply a git-generated patch, it uses the right -p<n> value automatically, with or without --index nor --cached option. - When run from a subdirectory to apply a randomly generated patch, it wants the right -p<n> value to be given by the user. The second one is a pure improvement to correct inconsistency between --index and non --index case, compared with 1.5.0. The third point could be further improved to guess what the right value for -p<n> should be by looking at the patch, but should be a topic of a separate patch. Signed-off-by: Junio C Hamano <junkio@cox.net>
| | * | | Fix botched "leak fix"Junio C Hamano2007-02-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When (new_name == old_name), the previous one prefixed old_name alone, leaving new_name untouched, and worse yet, left it dangling pointing at an already freed memory location. Signed-off-by: Junio C Hamano <junkio@cox.net>
| | * | | apply: fix memory leak in prefix_one()Johannes Schindelin2007-02-19
| | | | | | | | | | | | | | | | | | | | | | | | | Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
| | * | | git-apply: require -p<n> when working in a subdirectory.Junio C Hamano2007-02-19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | git-apply running inside a subdirectory, with or without --index, used to always assume that the patch is formatted in such a way to apply with -p1 from the toplevel, but it is more useful and consistent with the use of "GNU patch -p1" if it defaulted to assume that its input is meant to apply at the level it is invoked in. This changes the behaviour. It used to be that the patch generated this way would apply without any trick: edit Documentation/Makefile git diff >patch.file cd Documentation git apply ../patch.file You need to give an explicit -p2 to git-apply now. On the other hand, if you got a patch from somebody else who did not follow "patch is to apply from the top with -p1" convention, the input patch would start with: diff -u Makefile.old Makefile --- Makefile.old +++ Makefile and in such a case, you can apply it with: git apply -p0 patch.file Signed-off-by: Junio C Hamano <junkio@cox.net>
| | * | | git-apply: do not lose cwd when run from a subdirectory.Junio C Hamano2007-02-19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When a patch modifies (not deletes) the last file in a directory, because we treat a modification just as deletion followed by creation, and deleting the last file in a directory automatically rmdir(2)'s that directory, we ended up removing the directory, which can potentially be the cwd, and then recreating the same directory to create the patch result. Avoid the rmdir step when remove_file() is called only because we are replacing it with the result by later calling create_file(). Signed-off-by: Junio C Hamano <junkio@cox.net>
| | * | | Teach 'git apply' to look at $HOME/.gitconfig even outside of a repositoryJunio C Hamano2007-02-18
| | | | | | | | | | | | | | | | | | | | Signed-off-by: Junio C Hamano <junkio@cox.net>
| | * | | Teach 'git apply' to look at $GIT_DIR/configJunio C Hamano2007-02-17
| | |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When neither --index nor --cached was used, git-apply did not try calling setup_git_directory(), which means it did not look at configuration files at all. This fixes it to call the setup function but still allow the command to be run in a directory not controlled by git. The bug probably meant that 'git apply', not moving up to the toplevel, did not apply properly formatted diffs from the toplevel when you are inside a subdirectory, even though 'git apply --index' would. As a side effect, this patch fixes it as well. Signed-off-by: Junio C Hamano <junkio@cox.net>
| * | | Teach core.autocrlf to 'git apply'Junio C Hamano2007-02-17
| |/ / | | | | | | | | | | | | | | | | | | | | | This teaches git-apply that the data read from and written to the filesystem might need to get converted to adjust for local line-ending convention. Signed-off-by: Junio C Hamano <junkio@cox.net>
* | | Mechanical conversion to use prefixcmp()Junio C Hamano2007-02-20
| |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Do not take mode bits from index after type change.Junio C Hamano2007-02-16
|/ | | | | | | | | | | | | When we do not trust executable bit from lstat(2), we copied existing ce_mode bits without checking if the filesystem object is a regular file (which is the only thing we apply the "trust executable bit" business) nor if the blob in the index is a regular file (otherwise, we should do the same as registering a new regular file, which is to default non-executable). Noticed by Johannes Sixt. Signed-off-by: Junio C Hamano <junkio@cox.net>
* apply --cached: fix crash in subdirectoryJohannes Schindelin2007-01-20
| | | | | | | | The static variable "prefix" was shadowed by an unused parameter of the same name. In case of execution in a subdirectory, the static variable was accessed, leading to a crash. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
* git-apply: Remove directories that have become empty after deleting a file.Alexandre Julliard2007-01-09
| | | | | Signed-off-by: Alexandre Julliard <julliard@winehq.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
* Merge branch 'maint'Junio C Hamano2007-01-09
|\ | | | | | | | | | | * maint: Fix "Do not ignore a detected patchfile brokenness." Do not ignore a detected patchfile brokenness.
| * Fix "Do not ignore a detected patchfile brokenness."Junio C Hamano2007-01-09
| | | | | | | | | | | | | | | | | | Returning negative value from there does not stop the caller from using the earlier part. Noticed by Linus. Signed-off-by: Junio C Hamano <junkio@cox.net>
| * Do not ignore a detected patchfile brokenness.Junio C Hamano2007-01-09
| | | | | | | | | | | | | | | | | | | | find_header() function is used to read and parse the patchfile and it detects errors in the patch, but one place ignored the error and went ahead, which was quite bad. Noticed by Jeff Garzik. Signed-off-by: Junio C Hamano <junkio@cox.net>
* | simplify inclusion of system header files.Junio C Hamano2006-12-20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Merge branch 'jc/numstat'Junio C Hamano2006-11-24
|\ \ | |/ |/| | | | | * jc/numstat: apply --numstat: mark binary diffstat with - -, not 0 0
| * apply --numstat: mark binary diffstat with - -, not 0 0Junio C Hamano2006-11-14
| | | | | | | | | | | | | | We do not even know number of lines so showing it as 0 0 is lying. This would also help Porcelains like cvsexportcommit. Signed-off-by: Junio C Hamano <junkio@cox.net>
* | git-apply: slightly clean up bitfield usageRene Scharfe2006-11-18
|/ | | | | | | | | | This patch fixes a sparse warning about inaccurate_eof being a "dubious one-bit signed bitfield", makes three more binary variables members of this (now unsigned) bitfield and adds a short comment to indicate the nature of two ternary variables. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <junkio@cox.net>
* Merge branch 'maint'Junio C Hamano2006-11-04
|\ | | | | | | | | | | | | * maint: Remove unsupported C99 style struct initializers in git-archive. Remove SIMPLE_PROGRAMS and make git-daemon a normal program. Use ULONG_MAX rather than implicit cast of -1.
| * Use ULONG_MAX rather than implicit cast of -1.Shawn O. Pearce2006-11-04
| | | | | | | | | | | | | | | | | | | | At least one (older) version of the Solaris C compiler won't allow 'unsigned long x = -1' without explicitly casting -1 to a type of unsigned long. So instead use ULONG_MAX, which is really the correct constant anyway. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
* | Merge branch 'maint'Junio C Hamano2006-11-04
|\ \ | |/ | | | | | | * maint: apply: handle "traditional" creation/deletion diff correctly.
| * apply: handle "traditional" creation/deletion diff correctly.Junio C Hamano2006-11-04
| | | | | | | | | | | | | | | | | | | | | | We deduced a GNU diff output that does not use /dev/null convention as creation (deletion) diff correctly by looking at the lack of context and deleted lines (added lines), but forgot to reset the new (old) name field properly. This was a regression when we added a workaround for --unified=0 insanity. Signed-off-by: Junio C Hamano <junkio@cox.net>
* | Merge branch 'maint'Junio C Hamano2006-10-19
|\ \ | |/ | | | | | | * maint: git-apply: prepare for upcoming GNU diff -u format change.
| * git-apply: prepare for upcoming GNU diff -u format change.Linus Torvalds2006-10-19
| | | | | | | | | | | | | | | | | | The latest GNU diff from CVS emits an empty line to express an empty context line, instead of more traditional "single white space followed by a newline". Do not get broken by it. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
* | Merge early part of branch 'jc/diff-apply-patch'Junio C Hamano2006-10-18
|\ \ | |/ |/|
| * git-diff/git-apply: make diff output a bit friendlier to GNU patch (part 1)Junio C Hamano2006-09-29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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. We can make our output a bit more GNU patch friendly by adding an extra TAB (but not trailing timestamp) to old/new name lines when the filename as a SP in it. This updates git-apply to prepare ourselves to accept such a patch, but we still do not generate output that is patch friendly yet. That change needs to wait until everybody has this change. When a filename contains a real tab, "diff --git" format always c-quotes it as discussed on the list with GNU patch maintainer previously: http://marc.theaimsgroup.com/?l=git&m=112927316408690&w=2 so there should be no downside. Signed-off-by: Junio C Hamano <junkio@cox.net>
* | Add hash_sha1_file()Rene Scharfe2006-10-14
| | | | | | | | | | | | | | | | | | | | Most callers of write_sha1_file_prepare() are only interested in the resulting hash but don't care about the returned file name or the header. This patch adds a simple wrapper named hash_sha1_file() which does just that, and converts potential callers. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <junkio@cox.net>
* | apply --numstat -z: line termination fix.Junio C Hamano2006-10-12
|/ | | | Signed-off-by: Junio C Hamano <junkio@cox.net>
* git-apply: second war on whitespace.Junio C Hamano2006-09-24
| | | | | | | | | This makes --whitespace={warn,error,strip} option to also notice the leading whitespace errors in addition to the trailing whitespace errors. Spaces that are followed by a tab in indent are detected as errors, and --whitespace=strip option fixes them. Signed-off-by: Junio C Hamano <junkio@cox.net>
* apply --unidiff-zero: loosen sanity checks for --unidiff=0 patchesJunio C Hamano2006-09-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In "git-apply", we have a few sanity checks and heuristics that expects that the patch fed to us is a unified diff with at least one line of context. * When there is no leading context line in a hunk, the hunk must apply at the beginning of the preimage. Similarly, no trailing context means that the hunk is anchored at the end. * We learn a patch deletes the file from a hunk that has no resulting line (i.e. all lines are prefixed with '-') if it has not otherwise been known if the patch deletes the file. Similarly, no old line means the file is being created. And we declare an error condition when the file created by a creation patch already exists, and/or when a deletion patch still leaves content in the file. These sanity checks are good safety measures, but breaks down when people feed a diff generated with --unified=0. This was recently noticed first by Matthew Wilcox and Gerrit Pape. This adds a new flag, --unified-zero, to allow bypassing these checks. If you are in control of the patch generation process, you should not use --unified=0 patch and fix it up with this flag; rather you should try work with a patch with context. But if all you have to work with is a patch without context, this flag may come handy as the last resort. Signed-off-by: Junio C Hamano <junkio@cox.net>
* Make apply --binary a no-op.Junio C Hamano2006-09-07
| | | | | | | | | Historically we did not allow binary patch applied without an explicit permission from the user, and this flag was the way to do so. This makes the flag a no-op by always allowing binary patch application. Signed-off-by: Junio C Hamano <junkio@cox.net>
* Replace uses of strdup with xstrdup.Shawn Pearce2006-09-02
| | | | | | | | | | | | | | | | 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>
* free(NULL) is perfectly valid.Junio C Hamano2006-08-27
| | | | | | | Jonas noticed some places say "if (X) free(X)" which is totally unnecessary. Signed-off-by: Junio C Hamano <junkio@cox.net>
* Merge branch 'jc/apply'Junio C Hamano2006-08-27
|\ | | | | | | | | | | | | | | | | | | | | | | * 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.
| * git-apply --reject: finishing touches.Junio C Hamano2006-08-27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | After a failed "git am" attempt: git apply --reject --verbose .dotest/patch applies hunks that are applicable and leaves *.rej files the rejected hunks, and it reports what it is doing. With --index, files with a rejected hunk do not get their index entries updated at all, so "git diff" will show the hunks that successfully got applied. Without --verbose to remind the user that the patch updated some other paths cleanly, it is very easy to lose track of the status of the working tree, so --reject implies --verbose. Signed-off-by: Junio C Hamano <junkio@cox.net>
| * apply --reject: count hunks starting from 1, not 0Junio C Hamano2006-08-22
| | | | | | | | Signed-off-by: Junio C Hamano <junkio@cox.net>
| * git-apply --verboseJunio C Hamano2006-08-18
| | | | | | | | Signed-off-by: Junio C Hamano <junkio@cox.net>
| * git-apply --reject: send rejects to .rej files.Junio C Hamano2006-08-18
| | | | | | | | | | | | | | ... just like everybody else does, instead of sending it to the standard output, which was just silly. Signed-off-by: Junio C Hamano <junkio@cox.net>
| * git-apply --rejectJunio C Hamano2006-08-17
| | | | | | | | | | | | | | | | | | With the new flag "--reject", hunks that do not apply are sent to the standard output, and the usable hunks are applied. The command itself exits with non-zero status when this happens, so that the user or wrapper can take notice and sort the remaining mess out. Signed-off-by: Junio C Hamano <junkio@cox.net>
| * apply --reverse: tie it all together.Junio C Hamano2006-08-16
| | | | | | | | | | | | Add a few tests, usage string, and documentation. Signed-off-by: Junio C Hamano <junkio@cox.net>
| * builtin-apply --reverse: two bugfixes.Junio C Hamano2006-08-16
| | | | | | | | | | | | | | | | Parsing of a binary hunk did not consume the terminating blank line. When applying in reverse, it did not use the second, reverse binary hunk. Signed-off-by: Junio C Hamano <junkio@cox.net>