summaryrefslogtreecommitdiff
path: root/builtin-apply.c
AgeCommit message (Collapse)Author
2007-08-16git-apply: apply submodule changesSven Verdoolaege
Apply "Subproject commit HEX" changes produced by git-diff. As usual in the current git, only the superproject itself is actually modified (possibly creating empty directories for new submodules). Any checked-out submodule is left untouched and is not required to be up-to-date. With clean-ups from Junio C Hamano. Signed-off-by: Sven Verdoolaege <skimo@kotnet.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-08-06Merge branch 'maint'Junio C Hamano
* maint: apply: remove directory that becomes empty by renaming the last file away setup.c:verify_non_filename(): don't die unnecessarily while disambiguating
2007-08-06apply: remove directory that becomes empty by renaming the last file awayLinus Torvalds
We attempt to remove directory that becomes empty after removal of a file. We should do the same when we rename an existing file away. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-07-07Merge branch 'maint'Junio C Hamano
* maint: Fix "apply --reverse" with regard to whitespace
2007-07-07Fix "apply --reverse" with regard to whitespaceJohannes Schindelin
"git apply" used to take check the whitespace in the wrong direction. Noticed by Daniel Barkalow. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-06-03git-apply: what is detected and fixed is not just trailing spaces.Junio C Hamano
But we kept saying "trailing whitespace" all the same. Reword the error messages a bit. Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-05-21git-apply: Fix removal of new trailing blank lines.Junio C Hamano
The earlier code removed one newline too many from the hunk that adds new lines at the end of the file. Also the way the code counted the added blank lines was somewhat roundabout; I think the way updated code does it is more direct and easier to follow: * We keep track of the number of blank lines added; * While processing each line, we notice if it adds a blank line, and increment the counter, or reset it to zero otherwise; * When actually we apply the data, we remove the empty lines we counted earlier if we are applying it at the end of the file. Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-05-21Teach 'git-apply --whitespace=strip' to remove empty lines at the end of fileMarco Costalba
[jc: with an obvious microfix to avoid doing this unless --whitespace=strip] Signed-off-by: Marco Costalba <mcostalba@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-05-16Ensure return value from xread() is always stored into an ssize_tJohan Herland
This patch fixes all calls to xread() where the return value is not stored into an ssize_t. The patch should not have any effect whatsoever, other than putting better/more appropriate type names on variables. Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-05-12apply: do not get confused by symlinks in the middleJunio C Hamano
HPA noticed that git-rebase fails when changes involve symlinks in the middle of the hierarchy. Consider: * The tree state before the patch is applied has arch/x86_64/boot as a symlink pointing at ../i386/boot/ * The patch tries to remove arch/x86_64/boot symlink, and create bunch of files there: .gitignore, Makefile, etc. git-apply tries to be careful while applying patches; it never touches the working tree until it is convinced that the patch would apply cleanly. One of the check it does is that when it knows a path is going to be created by the patch, it runs lstat() on the path to make sure it does not exist. This leads to a false alarm. Because we do not touch the working tree before all the check passes, when we try to make sure that arch/x86_64/boot/.gitignore does not exist yet, we haven't removed the arch/x86_64/boot symlink. The lstat() check ends up seeing arch/i386/boot/.gitignore through the yet-to-be-removed symlink, and says "Hey, you already have a file there, but what you fed me is a patch to create a new file. I am not going to clobber what you have in the working tree." We have similar checks to see a file we are going to modify does exist and match the preimage of the diff, which is done by directly opening and reading the file. For a file we are going to delete, we make sure that it does exist and matches what is going to be removed (a removal patch records the full preimage, so we check what you have in your working tree matches it in full -- otherwise we would risk losing your local changes), which again is done by directly opening and reading the file. These checks need to be adjusted so that they are not fooled by symlinks in the middle. - To make sure something does not exist, first lstat(). If it does not exist, it does not, so be happy. If it _does_, we might be getting fooled by a symlink in the middle, so break leading paths and see if there are symlinks involved. When we are checking for a path a/b/c/d, if any of a, a/b, a/b/c is a symlink, then a/b/c/d does _NOT_ exist, for the purpose of our test. This would fix this particular case you saw, and would not add extra overhead in the usual case. - To make sure something already exists, first lstat(). If it does not exist, barf (up to this, we already do). Even if it does seem to exist, we might be getting fooled by a symlink in the middle, so make sure leading paths are not symlinks. This would make the normal codepath much more expensive for deep trees, which is a bit worrisome. This patch implements the first side of the check "making sure it does not exist". The latter "making sure it exists" check is not done yet, so applying the patch in reverse would still fail, but we have to start from somewhere. Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-22Merge branch 'jc/attr'Junio C Hamano
* 'jc/attr': (28 commits) lockfile: record the primary process. convert.c: restructure the attribute checking part. Fix bogus linked-list management for user defined merge drivers. Simplify calling of CR/LF conversion routines Document gitattributes(5) Update 'crlf' attribute semantics. Documentation: support manual section (5) - file formats. Simplify code to find recursive merge driver. Counto-fix in merge-recursive Fix funny types used in attribute value representation Allow low-level driver to specify different behaviour during internal merge. Custom low-level merge driver: change the configuration scheme. Allow the default low-level merge driver to be configured. Custom low-level merge driver support. Add a demonstration/test of customized merge. Allow specifying specialized merge-backend per path. merge-recursive: separate out xdl_merge() interface. Allow more than true/false to attributes. Document git-check-attr Change attribute negation marker from '!' to '-'. ...
2007-04-21Simplify calling of CR/LF conversion routinesAlex Riesen
Signed-off-by: Alex Riesen <raa.lkml@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-18Merge branch 'maint'Junio C Hamano
* maint: git-shortlog: Fix two formatting errors in asciidoc documentation Fix overwriting of files when applying contextually independent diffs git-svn: don't allow globs to match regular files
2007-04-18Fix overwriting of files when applying contextually independent diffsAlex Riesen
Noticed by applying two diffs of different contexts to the same file. The check for existence of a file was wrong: the test assumed it was a directory and reset the errno (twice: directly and by calling lstat). So if an entry existed and was _not_ a directory no attempt was made to rename into it, because the errno (expected by renaming code) was already reset to 0. This resulted in error: fatal: unable to write file file mode 100644 For Linux, removing "errno = 0" is enough, as lstat wont modify errno if it was successful. The behavior should not be depended upon, though, so modify the "if" as well. The test simulates this situation. Signed-off-by: Alex Riesen <raa.lkml@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-07Merge branch 'jc/index-output'Junio C Hamano
* jc/index-output: git-read-tree --index-output=<file> _GIT_INDEX_OUTPUT: allow plumbing to output to an alternative index file. Conflicts: builtin-apply.c
2007-04-05Merge branch 'maint'Junio C Hamano
* maint: Fix lseek(2) calls with args 2 and 3 swapped Honor -p<n> when applying git diffs Fix dependency of common-cmds.h Fix renaming branch without config file DESTDIR support for git/contrib/emacs gitweb: Fix bug in "blobdiff" view for split (e.g. file to symlink) patches Document --left-right option to rev-list. Revert "builtin-archive: use RUN_SETUP" rename contrib/hooks/post-receieve-email to contrib/hooks/post-receive-email. rerere: make sorting really stable. Fix t4200-rerere for white-space from "wc -l"
2007-04-05Rename static variable write_index to update_index in builtin-apply.cJunio C Hamano
This is an internal variable used to tell if we need to write out the resulting index. I'll be introducing write_index() function which would collide with it. Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-05Honor -p<n> when applying git diffsShawn O. Pearce
If the user is trying to apply a Git generated diff file and they have specified a -p<n> option, where <n> is not 1, the user probably has a good reason for doing this. Such as they are me, trying to apply a patch generated in git.git for the git-gui subdirectory to the git-gui.git repository, where there is no git-gui subdirectory present. Users shouldn't supply -p2 unless they mean it. But if they are supplying it, they probably have thought about how to make this patch apply to their working directory, and want to risk whatever results may come from that. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-04_GIT_INDEX_OUTPUT: allow plumbing to output to an alternative index file.Junio C Hamano
When defined, this allows plumbing commands that update the index (add, apply, checkout-index, merge-recursive, mv, read-tree, rm, update-index, and write-tree) to write their resulting index to an alternative index file while holding a lock to the original index file. With this, git-commit that jumps the index does not have to make an extra copy of the index file, and more importantly, it can do the update while holding the lock on the index. However, I think the interface to let an environment variable specify the output is a mistake, as shown in the documentation. If a curious user has the environment variable set to something other than the file GIT_INDEX_FILE points at, almost everything will break. This should instead be a command line parameter to tell these plumbing commands to write the result in the named file, to prevent stupid mistakes. Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-03-23git-apply: Do not free the wrong buffer when we convert the data for writeoutJunio C Hamano
When we write out the result of patch application, we sometimes need to munge the data (e.g. under core.autocrlf). After doing so, what we should free is the temporary buffer that holds the converted data returned from convert_to_working_tree(), not the original one. This patch also moves the call to open() up in the function, as the caller expects us to fail cheaply if leading directories need to be created (and then the caller creates them and calls us again). For that calling pattern, attempting conversion before opening the file adds unnecessary overhead. Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-03-07Cast 64 bit off_t to 32 bit size_tShawn O. Pearce
Some systems have sizeof(off_t) == 8 while sizeof(size_t) == 4. This implies that we are able to access and work on files whose maximum length is around 2^63-1 bytes, but we can only malloc or mmap somewhat less than 2^32-1 bytes of memory. On such a system an implicit conversion of off_t to size_t can cause the size_t to wrap, resulting in unexpected and exciting behavior. Right now we are working around all gcc warnings generated by the -Wshorten-64-to-32 option by passing the off_t through xsize_t(). In the future we should make xsize_t on such problematic platforms detect the wrapping and die if such a file is accessed. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-03-03Add core.symlinks to mark filesystems that do not support symbolic links.Johannes Sixt
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>
2007-02-27convert object type handling from a string to a numberNicolas Pitre
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>
2007-02-27Merge branch 'maint'Junio C Hamano
* 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.
2007-02-27git-apply: do not fix whitespaces on context lines.Junio C Hamano
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>
2007-02-24Merge branch 'js/apply'Junio C Hamano
* js/apply: apply: make --verbose a little more useful
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-23apply: make --verbose a little more usefulJohannes Schindelin
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>
2007-02-22git-apply: guess correct -p<n> value for non-git patches.Junio C Hamano
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>
2007-02-21git-apply: notice "diff --git" patch againJunio C Hamano
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>
2007-02-21Fix botched "leak fix"Junio C Hamano
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>
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-20apply: fix memory leak in prefix_one()Johannes Schindelin
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-20git-apply: require -p<n> when working in a subdirectory.Junio C Hamano
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>
2007-02-20git-apply: do not lose cwd when run from a subdirectory.Junio C Hamano
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>
2007-02-18Teach 'git apply' to look at $HOME/.gitconfig even outside of a repositoryJunio C Hamano
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-17Teach core.autocrlf to 'git apply'Junio C Hamano
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>
2007-02-17Teach 'git apply' to look at $GIT_DIR/configJunio C Hamano
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>
2007-02-17Do not take mode bits from index after type change.Junio C Hamano
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>
2007-01-21apply --cached: fix crash in subdirectoryJohannes Schindelin
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>
2007-01-10git-apply: Remove directories that have become empty after deleting a file.Alexandre Julliard
Signed-off-by: Alexandre Julliard <julliard@winehq.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-01-09Merge branch 'maint'Junio C Hamano
* maint: Fix "Do not ignore a detected patchfile brokenness." Do not ignore a detected patchfile brokenness.
2007-01-09Fix "Do not ignore a detected patchfile brokenness."Junio C Hamano
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>
2007-01-09Do not ignore a detected patchfile brokenness.Junio C Hamano
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>
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-11-24Merge branch 'jc/numstat'Junio C Hamano
* jc/numstat: apply --numstat: mark binary diffstat with - -, not 0 0
2006-11-18git-apply: slightly clean up bitfield usageRene Scharfe
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>
2006-11-15apply --numstat: mark binary diffstat with - -, not 0 0Junio C Hamano
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>
2006-11-05Merge branch 'maint'Junio C Hamano
* 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.
2006-11-05Use ULONG_MAX rather than implicit cast of -1.Shawn O. Pearce
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>