Commit Graph

193 Commits

Author SHA1 Message Date
Johannes Schindelin
5fda48d67c Fix "apply --reverse" with regard to whitespace
"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-07-07 11:54:51 -07:00
Junio C Hamano
c94bf41c9a git-apply: what is detected and fixed is not just trailing spaces.
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-06-02 20:02:19 -07:00
Junio C Hamano
077e1af598 git-apply: Fix removal of new trailing blank lines.
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-20 23:51:06 -07:00
Marco Costalba
efe7f35861 Teach 'git-apply --whitespace=strip' to remove empty lines at the end of file
[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-20 20:36:24 -07:00
Johan Herland
8a912bcb25 Ensure return value from xread() is always stored into an ssize_t
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-15 21:16:03 -07:00
Junio C Hamano
64cab59159 apply: do not get confused by symlinks in the middle
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-05-11 22:26:08 -07:00
Junio C Hamano
a2d7c6c620 Merge branch 'jc/attr'
* '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-21 17:38:00 -07:00
Alex Riesen
ac78e54804 Simplify calling of CR/LF conversion routines
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-20 23:24:34 -07:00
Junio C Hamano
6fb8e8f401 Merge branch 'maint'
* 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-18 16:17:28 -07:00
Alex Riesen
0afa7644f2 Fix overwriting of files when applying contextually independent diffs
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-18 15:33:01 -07:00
Junio C Hamano
ee9693e246 Merge branch 'jc/index-output'
* 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-07 02:26:24 -07:00
Junio C Hamano
77e6f5bc10 Merge branch 'maint'
* 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-05 16:34:51 -07:00
Junio C Hamano
7da3bf372c Rename static variable write_index to update_index in builtin-apply.c
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-05 15:07:16 -07:00
Shawn O. Pearce
79ee194e52 Honor -p<n> when applying git diffs
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-05 15:06:58 -07:00
Junio C Hamano
30ca07a249 _GIT_INDEX_OUTPUT: allow plumbing to output to an alternative index file.
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-04-03 23:44:32 -07:00
Junio C Hamano
cc96fd092a git-apply: Do not free the wrong buffer when we convert the data for writeout
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-22 17:32:51 -07:00
Shawn O. Pearce
dc49cd769b Cast 64 bit off_t to 32 bit size_t
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-07 11:15:26 -08:00
Johannes Sixt
78a8d641c1 Add core.symlinks to mark filesystems that do not support symbolic links.
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-03-02 16:58:05 -08:00
Nicolas Pitre
21666f1aae convert object type handling from a string to a number
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-27 01:34:21 -08:00
Junio C Hamano
4e4b55dd0f Merge branch 'maint'
* 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-27 01:33:52 -08:00
Junio C Hamano
63e50d492c git-apply: do not fix whitespaces on context lines.
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-27 01:33:14 -08:00
Junio C Hamano
7bd59dee5b Merge branch 'js/apply'
* js/apply:
  apply: make --verbose a little more useful
2007-02-24 02:00:32 -08:00
Junio C Hamano
ef1a5c2fa8 Merge branches 'lt/crlf' and 'jc/apply-config'
* 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-22 21:34:36 -08:00
Johannes Schindelin
aeabfa0725 apply: make --verbose a little more useful
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-22 20:58:36 -08:00
Junio C Hamano
3e8a5db966 git-apply: guess correct -p<n> value for non-git patches.
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-21 16:05:56 -08:00
Junio C Hamano
9987d7c58a git-apply: notice "diff --git" patch again
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-21 14:42:15 -08:00
Junio C Hamano
6c912f5b04 Fix botched "leak fix"
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-21 01:14:34 -08:00
Junio C Hamano
cc44c7655f Mechanical conversion to use prefixcmp()
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-20 22:03:15 -08:00
Johannes Schindelin
eac70c4f64 apply: fix memory leak in prefix_one()
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-19 19:02:12 -08:00
Junio C Hamano
56185f49d0 git-apply: require -p<n> when working in a subdirectory.
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-19 18:44:59 -08:00
Junio C Hamano
aea1945744 git-apply: do not lose cwd when run from a subdirectory.
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-19 18:44:21 -08:00
Junio C Hamano
700ea47936 Teach 'git apply' to look at $HOME/.gitconfig even outside of a repository
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-18 00:54:04 -08:00
Junio C Hamano
6716027108 Teach core.autocrlf to 'git apply'
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-17 15:27:47 -08:00
Junio C Hamano
dc7b24364d Teach 'git apply' to look at $GIT_DIR/config
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-17 13:13:32 -08:00
Junio C Hamano
185c975faa Do not take mode bits from index after type change.
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-02-16 22:56:06 -08:00
Johannes Schindelin
cd554bb173 apply --cached: fix crash in subdirectory
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-20 19:05:20 -08:00
Alexandre Julliard
d234b21c69 git-apply: Remove directories that have become empty after deleting a file.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-01-09 16:05:00 -08:00
Junio C Hamano
240897e908 Merge branch 'maint'
* maint:
  Fix "Do not ignore a detected patchfile brokenness."
  Do not ignore a detected patchfile brokenness.
2007-01-09 12:04:30 -08:00
Junio C Hamano
6534141151 Fix "Do not ignore a detected patchfile brokenness."
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-09 11:50:53 -08:00
Junio C Hamano
5a17b54ad5 Do not ignore a detected patchfile brokenness.
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>
2007-01-09 02:56:43 -08:00
Junio C Hamano
85023577a8 simplify inclusion of system header files.
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-20 09:51:35 -08:00
Junio C Hamano
54acddce99 Merge branch 'jc/numstat'
* jc/numstat:
  apply --numstat: mark binary diffstat with - -, not 0 0
2006-11-24 03:46:40 -08:00
Rene Scharfe
3dad11bfdb git-apply: slightly clean up bitfield usage
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-18 11:40:11 -08:00
Junio C Hamano
ef58d9587e apply --numstat: mark binary diffstat with - -, not 0 0
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-14 22:23:18 -08:00
Junio C Hamano
82cc8d839b Merge branch 'maint'
* 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-04 23:52:32 -08:00
Shawn O. Pearce
bf8675d314 Use ULONG_MAX rather than implicit cast of -1.
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>
2006-11-04 23:41:02 -08:00
Junio C Hamano
a622f6b35e Merge branch 'maint'
* maint:
  apply: handle "traditional" creation/deletion diff correctly.
2006-11-04 03:54:20 -08:00
Junio C Hamano
6f9f3b263b apply: handle "traditional" creation/deletion diff correctly.
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>
2006-11-04 02:35:17 -08:00
Junio C Hamano
e19343ad54 Merge branch 'maint'
* maint:
  git-apply: prepare for upcoming GNU diff -u format change.
2006-10-19 21:28:12 -07:00
Linus Torvalds
b507b465f7 git-apply: prepare for upcoming GNU diff -u format change.
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>
2006-10-19 21:28:06 -07:00
Junio C Hamano
17250ac172 Merge early part of branch 'jc/diff-apply-patch' 2006-10-18 22:08:46 -07:00
Rene Scharfe
abdc3fc842 Add hash_sha1_file()
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>
2006-10-14 11:49:52 -07:00
Junio C Hamano
854de5a534 apply --numstat -z: line termination fix.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-10-12 02:57:39 -07:00
Junio C Hamano
ce74618d95 git-diff/git-apply: make diff output a bit friendlier to GNU patch (part 1)
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>
2006-09-29 19:20:27 -07:00
Junio C Hamano
d0c25035df git-apply: second war on whitespace.
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>
2006-09-24 00:12:44 -07:00
Junio C Hamano
4be609625e apply --unidiff-zero: loosen sanity checks for --unidiff=0 patches
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>
2006-09-17 01:12:37 -07:00
Junio C Hamano
2b6eef943f Make apply --binary a no-op.
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>
2006-09-07 02:44:40 -07:00
Shawn Pearce
9befac470b Replace uses of strdup with xstrdup.
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-09-02 03:24:37 -07:00
Junio C Hamano
4cac42b132 free(NULL) is perfectly valid.
Jonas noticed some places say "if (X) free(X)" which is totally
unnecessary.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-27 21:19:39 -07:00
Junio C Hamano
b32d37a3a6 Merge branch 'jc/apply'
* 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-27 17:51:05 -07:00
Junio C Hamano
8938045a4e git-apply --reject: finishing touches.
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>
2006-08-27 15:53:20 -07:00
Pierre Habouzit
dd305c8462 use name[len] in switch directly, instead of creating a shadowed variable.
builtin-apply.c defines a local variable 'c' which is used only
once and then later gets shadowed by another instance of 'c'.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-23 18:47:39 -07:00
Pierre Habouzit
60b7f38e0e avoid to use error that shadows the function name, use err instead.
builtin-apply.c and builtin-push.c uses a local variable called 'error'
which shadows the error() function.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-23 18:47:38 -07:00
Junio C Hamano
0e9ee32358 apply --reject: count hunks starting from 1, not 0
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-22 15:49:28 -07:00
Junio C Hamano
a2bf404e28 git-apply --verbose
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-18 03:14:48 -07:00
Junio C Hamano
82e2765f59 git-apply --reject: send rejects to .rej files.
... 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>
2006-08-18 03:10:19 -07:00
Junio C Hamano
57dc397cff git-apply --reject
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>
2006-08-17 01:23:08 -07:00
Junio C Hamano
2cda1a214e apply --reverse: tie it all together.
Add a few tests, usage string, and documentation.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-16 21:08:45 -07:00
Junio C Hamano
03eb8f8aeb builtin-apply --reverse: two bugfixes.
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>
2006-08-16 21:08:45 -07:00
David Rientjes
96f1e58f52 remove unnecessary initializations
[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>
2006-08-15 21:22:20 -07:00
David Rientjes
0bef57ee44 make inline is_null_sha1 global
Replace sha1 comparisons to null_sha1 with a global inline (which previously an
unused static inline in builtin-apply.c)

[jc: with a fix from Jonas Fonseca.]

Signed-off-by: David Rientjes <rientjes@google.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-15 15:06:03 -07:00
Junio C Hamano
3cd4f5e8eb git-apply --binary: clean up and prepare for --reverse
This cleans up the implementation of "git-apply --binary", and
implements reverse application of binary patches (when git-diff
is converted to emit reversible binary patches).

Earlier, the types of encoding (either deflated literal or
deflated delta) were stored in is_binary field in struct patch,
which meant that we cannot store more than one fragment that
differ in the encoding for a patch.  This moves the information
to a field in struct fragment that is otherwise unused for
binary patches, and makes it possible to hang two (or more, but
two is enough) hunks for a binary patch.

The original "binary patch" output from git-diff is internally
parsed into an "is_binary" patch with one fragment.  Upcoming
reversible binary patch output will have two fragments, the
first one being the forward patch and the second one the reverse
patch.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-15 03:11:52 -07:00
Junio C Hamano
f686d03034 git-apply --reverse: simplify reverse option.
Having is_reverse in each patch did not make sense.  This will hopefully
simplify the work needed to introduce reversible binary diff format.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-14 23:26:51 -07:00
Junio C Hamano
40aaae88ad Better error message when we are unable to lock the index file
Most of the callers except the one in refs.c use the function to
update the index file.  Among the index writers, everybody
except write-tree dies if they cannot open it for writing.

This gives the function an extra argument, to tell it to die
when it cannot create a new file as the lockfile.

The only caller that does not have to die is write-tree, because
updating the index for the cache-tree part is optional and not
being able to do so does not affect the correctness.  I think we
do not have to be so careful and make the failure into die() the
same way as other callers, but that would be a different patch.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-12 17:08:25 -07:00
Junio C Hamano
242abf106c builtin-apply: remove unused increment
We do not use desc.alloc after assigning desc.buffer to patch->result;
do not bother to increment it.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-10 00:56:40 -07:00
Junio C Hamano
2c71810b90 git-apply: applying a patch to make a symlink shorter.
The internal representation of the result is counted string
(i.e. char *buf and ulong size), which is fine for writing out
to regular file, but throwing the buf at symlink(2) was a
no-no.

Reported by Willy Tarreau.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-08-09 22:47:25 -07:00
Linus Torvalds
a633fca0c0 Call setup_git_directory() much earlier
This changes the calling convention of built-in commands and
passes the "prefix" (i.e. pathname of $PWD relative to the
project root level) down to them.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-29 01:34:07 -07:00
Junio C Hamano
ab9f30fd75 git-apply -R: binary patches are irreversible for now.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-28 12:21:17 -07:00
Johannes Schindelin
e5a94313c0 Teach git-apply about '-R'
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-28 11:18:02 -07:00
Johannes Schindelin
56ac168f6f Fix t4114 on cygwin
On cygwin, when you try to create a symlink over a directory, you do
not get EEXIST, but EACCES.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-23 23:27:41 -07:00
Junio C Hamano
7f95aef28f apply: handle type-changing patch correctly.
A type-change diff is always split into a patch to delete old,
immediately followed by a patch to create new.  check_patch()
routine noticed that the path to be created already exists in
the working tree and/or in the index when looking at the
creation patch and mistakenly thought it to be an error.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-17 00:10:47 -07:00
Junio C Hamano
eed46644ca apply: split out removal and creation into different phases.
This reworks write_out_result() loop so we first remove the paths that
are to go away and then create them after finishing all the removal.

This is necessary when a patch creates a file "foo" and removes a file
"foo/bar".

Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-16 23:52:09 -07:00
Junio C Hamano
c28c571c14 apply: check D/F conflicts more carefully.
When creating a new file where a directory used to be (or the user had
an empty directory) the code did not check the result from lstat() closely
enough, and mistakenly thought the path already existed in the working tree.

This does not fix the problem where you have a patch that creates a file
at "foo" and removes a file at "foo/bar" (which presumably is the last file
in "foo/" directory in the original).  For that, we would need to restructure
write_out_results() loop.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-16 23:28:36 -07:00
Pavel Roskin
a9486b02ec Avoid C99 comments, use old-style C comments instead.
This doesn't make the code uglier or harder to read, yet it makes the
code more portable.  This also simplifies checking for other potential
incompatibilities.  "gcc -std=c89 -pedantic" can flag many incompatible
constructs as warnings, but C99 comments will cause it to emit an error.

Signed-off-by: Pavel Roskin <proski@gnu.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-10 00:47:13 -07:00
Pavel Roskin
82e5a82fd7 Fix more typos, primarily in the code
The only visible change is that git-blame doesn't understand
"--compability" anymore, but it does accept "--compatibility" instead,
which is already documented.

Signed-off-by: Pavel Roskin <proski@gnu.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-10 00:36:44 -07:00
Johannes Schindelin
6244b24906 Close the index file between writing and committing
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-08 03:28:19 -07:00
Johannes Schindelin
3eaa38da94 apply: replace NO_ACCURATE_DIFF with --inaccurate-eof runtime flag.
It does not make much sense to build git whose behaviour is
different depending on the brokenness of diff implementation of
the platform because the brokenness of the patch that is applied
with the tool depends on brokenness of the diff the person who
generates the patch uses.  So we do not use NO_ACCURATE_DIFF
anymore, but help people to apply patches that do not record
incomplete lines correctly with a runtime flag.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-06-24 22:18:44 -07:00
Florian Forster
1d7f171c3a Remove all void-pointer arithmetic.
ANSI C99 doesn't allow void-pointer arithmetic. This patch fixes this in
various ways. Usually the strategy that required the least changes was used.

Signed-off-by: Florian Forster <octo@verplant.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-06-20 01:59:46 -07:00
Junio C Hamano
021b6e4549 Make index file locking code reusable to others.
The framework to create lockfiles that are removed at exit is
first used to reliably write the index file, but it is
applicable to other things, so stop calling it "cache_file".

This also rewords a few remaining error message that called the
index file "cache file".

Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-06-06 14:30:58 -07:00
Junio C Hamano
cd01d9445d Merge branch 'lt/apply'
* lt/apply:
  apply: force matching at the beginning.
  Add a test-case for git-apply trying to add an ending line
  apply: treat EOF as proper context.
2006-05-28 23:00:50 -07:00
Junio C Hamano
3f69d405d7 Merge branch 'jc/cache-tree'
* jc/cache-tree: (26 commits)
  builtin-rm: squelch compiler warnings.
  git-write-tree writes garbage on sparc64
  Fix crash when reading the empty tree
  fsck-objects: do not segfault on missing tree in cache-tree
  cache-tree: a bit more debugging support.
  read-tree: invalidate cache-tree entry when a new index entry is added.
  Fix test-dump-cache-tree in one-tree disappeared case.
  fsck-objects: mark objects reachable from cache-tree
  cache-tree: replace a sscanf() by two strtol() calls
  cache-tree.c: typefix
  test-dump-cache-tree: validate the cached data as well.
  cache_tree_update: give an option to update cache-tree only.
  read-tree: teach 1-way merege and plain read to prime cache-tree.
  read-tree: teach 1 and 2 way merges about cache-tree.
  update-index: when --unresolve, smudge the relevant cache-tree entries.
  test-dump-cache-tree: report number of subtrees.
  cache-tree: sort the subtree entries.
  Teach fsck-objects about cache-tree.
  index: make the index file format extensible.
  cache-tree: protect against "git prune".
  ...

Conflicts:

	Makefile, builtin.h, git.c: resolved the same way as in next.
2006-05-28 22:57:47 -07:00
Junio C Hamano
4868f3729a Merge branch 'master' into lt/apply
* master: (40 commits)
  Clean up sha1 file writing
  Builtin git-cat-file
  builtin format-patch: squelch content-type for 7-bit ASCII
  CMIT_FMT_EMAIL: Q-encode Subject: and display-name part of From: fields.
  add more informative error messages to git-mktag
  remove the artificial restriction tagsize < 8kb
  git-rebase: use canonical A..B syntax to format-patch
  git-format-patch: now built-in.
  fmt-patch: Support --attach
  fmt-patch: understand old <his> notation
  Teach fmt-patch about --keep-subject
  Teach fmt-patch about --numbered
  fmt-patch: implement -o <dir>
  fmt-patch: output file names to stdout
  Teach fmt-patch to write individual files.
  Use RFC2822 dates from "git fmt-patch".
  git-fmt-patch: thinkofix to show [PATCH] properly.
  rename internal format-patch wip
  Minor tweak on subject line in --pretty=email
  Tentative built-in format-patch.
  ...
2006-05-24 14:08:30 -07:00
Peter Eriksen
ac6245e31a Builtin git-apply.
Signed-off-by: Peter Eriksen <s022018@student.dtu.dk>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-05-23 13:11:13 -07:00