Commit Graph

68 Commits

Author SHA1 Message Date
Alex Riesen
d9e08be9d5 fix potential deadlock in create_one_file
It can happen if the temporary file already exists (i.e. after a panic
and reboot).

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-01-05 17:22:49 -08:00
Alex Riesen
781411ed46 trivial: O_EXCL makes O_TRUNC redundant
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-01-05 17:22:47 -08:00
Junio C Hamano
1c15afb934 xread/xwrite: do not worry about EINTR at calling sites.
We had errno==EINTR check after read(2)/write(2) sprinkled all
over the places, always doing continue.  Consolidate them into
xread()/xwrite() wrapper routines.

Credits for suggestion goes to HPA -- bugs are mine.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-12-19 18:28:16 -08:00
Junio C Hamano
edf2e37002 git-apply: work from subdirectory.
When applying a patch to index file, we need to know where GIT_DIR is;
use setup_git_directory() to find it out.  This also allows us to work
from a subdirectory if we wanted to.

When git-apply is run from a subdirectory, it applies the given patch
only to the files under the current directory and below.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-11-28 23:13:01 -08:00
Junio C Hamano
3200d1aee0 Deal with binary diff output from GNU diff 2.8.7
Some vintage of diff says just "Files X and Y differ\n", instead
of "Binary files X and Y differ\n", so catch both patterns.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-11-17 21:14:29 -08:00
Junio C Hamano
011f4274bb apply: allow-binary-replacement.
A new option, --allow-binary-replacement, is introduced.

When you feed a diff that records full SHA1 name of pre- and
post-image blob on its index line to git-apply with this option,
the post-image blob replaces the path if what you have in the
working tree matches the pre-image _and_ post-image blob is
already available in the object directory.

Later we _might_ want to enhance the diff output to also include
the full binary data of the post-image, to make this more
useful, but this is good enough for local rebasing application.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-11-16 16:20:40 -08:00
Junio C Hamano
92927ed0aa git-apply: fail if a patch cannot be applied.
Recently we fixed 'git-apply --stat' not to barf on a binary
differences.  But it accidentally broke the error detection when
we actually attempt to apply them.

This commit fixes the problem and adds test cases.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-11-16 14:12:56 -08:00
Junio C Hamano
9add69b1b1 apply: fix binary patch detection.
The comparison to find "Binary files " string was looking at a
wrong place when offset != 0.

Also, we may have the full 40-byte textual sha1 on the index
line; two off-by-one errors prevented it.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-11-14 17:15:07 -08:00
Junio C Hamano
e433705dd4 Documentation: git-apply --no-add
This is a specialized hack to help no-base merges, but other
people might find it useful, so let's document it.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-11-11 21:18:18 -08:00
Junio C Hamano
cb93c19365 merge-one-file: use common as base, instead of emptiness.
Unlike the previous round that merged the path added differently
in each branches using emptiness as the base, compute a common
version and use it as input to 'merge' program.

This would show the resulting (still conflicting) file left in
the working tree as:

	common file contents...
	<<<<<< FILENAME
	version from our branch...
	======
	version from their branch...
	>>>>>> .merge_file_XXXXXX
	more common file contents...

when both sides added similar contents.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-11-11 21:18:17 -08:00
Junio C Hamano
ff36de0847 git-apply: do not fail on binary diff when not applying nor checking.
We run git-apply with --stat and --summary at the end of the pull
by default, which causes it to barf when the pull brought in changes
to binary files.  Just mark them as binary patch and proceed when
not applying nor checking.

[jc: I almost missed --check until I saw Linus did something similar.]

Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-11-09 15:19:50 -08:00
Junio C Hamano
7d8b7c21c9 git-apply --numstat
The new option, --numstat, shows number of inserted and deleted
lines for each path.  It is similar to --stat output but is
meant to be more machine friendly by giving number of added and
deleted lines and unabbreviated paths.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-10-28 22:28:57 -07:00
Junio C Hamano
58452f9442 git-apply: remove unused --show-files flag.
Linus says he does not use it (and the thinking behind its initial
introduction), and neither Cogito nor StGIT uses it.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-10-17 17:41:58 -07:00
Junio C Hamano
22943f1a52 Update git-apply to use C-style quoting for funny pathnames.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-10-17 17:41:54 -07:00
Linus Torvalds
4546738b58 Unlocalized isspace and friends
Do our own ctype.h, just to get the sane semantics: we want
locale-independence, _and_ we want the right signed behaviour. Plus we
only use a very small subset of ctype.h anyway (isspace, isalpha,
isdigit and isalnum).

Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-10-14 17:17:27 -07:00
Junio C Hamano
2cf67f1e35 git-apply: parse index information
Add an new option --show-index-info to git-apply command to
summarize the index information new git-diff outputs.  The
command shows something similar to git-ls-files --stage output
for the pre-change image:

    100644 7be5041...	apply.c
    100644 ec2a161...	cache.h
    ...

Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-10-07 03:42:00 -07:00
Junio C Hamano
c2d5036de5 git-apply: retire unused/unimplemented --no-merge flag.
The original plan was to do 3-way merge between local working tree,
index and the patch being applied, but that was never implemented.
Retire the flag to control its behaviour.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-10-04 17:04:44 -07:00
Junio C Hamano
56d33b1105 git-apply: allow operating in sparsely populated working tree.
This patch teaches 'git-apply --index' to automatically check
out a file being patched.  This happens only when the working
tree does not have it checked out.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-10-04 17:04:44 -07:00
Linus Torvalds
1fea629f79 [PATCH] Flag empty patches as errors
A patch that contains no actual diff, and that doesn't change any
meta-data is bad. It shouldn't be a patch at all, and git-apply shouldn't
just accept it.

This caused a corrupted patch to be silently applied as an empty change in
the kernel, because the corruption ended up making the patch look empty.

An example of such a patch is one that contains the patch header, but
where the initial fragment header (the "@@ -nr,.." line) is missing,
causing us to not parse any fragments.

The real "patch" program will also flag such patches as bad, with the
message

	patch: **** Only garbage was found in the patch input.

and we should do likewise.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-09-30 23:52:48 -07:00
Fredrik Kuivinen
433ef8a2fb [PATCH] Make git-apply understand incomplete lines in non-C locales
The message "\ No newline at end of file" used by diff(1) to mark
an incomplete line is locale dependent. We can't assume more than
that it begins with "\ ".

For example, given two files, "foo" and "bar", with appropriate
contents, 'diff -u foo bar' will produce the following output on
my system:

    --- foo 2005-09-04 18:59:38.000000000 +0200
    +++ bar 2005-09-04 18:59:16.000000000 +0200
    @@ -1 +1 @@
    -foobar
    +foo
    \ Ingen nyrad vid filslut

[jc: the check for the marker still uses the line length being no less
than 12 bytes for a sanity check, but I think it is safe to assume
that in other locales. I haven't checked the .po files from diff, tho'.]

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-09-04 11:00:28 -07:00
Junio C Hamano
10d781b9ca Merge refs/heads/portable from http://www.cs.berkeley.edu/~ejr/gits/git.git 2005-08-28 23:02:01 -07:00
Robert Fitzsimons
e70a165d3d [PATCH] Fix git patch header processing in git-apply.
Stop processing and return NULL if we encounter a '\n' character
before we have two matching names in the git header.

Signed-off-by: Robert Fitzsimons <robfitz@273k.net>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-08-28 14:24:01 -07:00
Jason Riedy
c7c81b3a51 Fix ?: statements.
Omitting the first branch in ?: is a GNU extension.  Cute,
but not supported by other compilers.  Replaced mostly
by explicit tests.  Calls to getenv() simply are repeated
on non-GNU compilers.

Signed-off-by: Jason Riedy <ejr@cs.berkeley.edu>
2005-08-23 20:41:12 -07:00
Johannes Schindelin
35cc4bcd10 [PATCH] When copying or renaming, keep the mode, please
Without this patch, git-apply does not retain the mode when renaming or
copying files.

[jc: Good catch, Johannes.  I added a test case to demonstrate the
breackage in the original.]

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-08-17 12:13:12 -07:00
Timo Sirainen
4ec99bf080 [PATCH] -Werror fixes
GCC's format __attribute__ is good for checking errors, especially
with -Wformat=2 parameter. This fixes most of the reported problems
against 2005-08-09 snapshot.
2005-08-09 22:28:19 -07:00
Linus Torvalds
629170973d [PATCH] Make git-apply --stat less butt-ugly with long filenames
When git-apply was printing out long filenames, it used to just truncate
them to show the last "max_len" characters of the filename. Which can be
really quite ugly (note the two filenames that have just been silently
truncated from the beginning - it looks even worse when there are lots
of them, like there were in the current v2.6.13-rc4 cris arch update):

 Documentation/video4linux/README.saa7134           |    9
 Documentation/video4linux/bttv/Cards               |   74
 umentation/video4linux/hauppauge-wintv-cx88-ir.txt |   54
 Documentation/video4linux/lifeview.txt             |   42
 mentation/video4linux/not-in-cx2388x-datasheet.txt |   41
 Documentation/w1/w1.generic                        |  107

With this patch it now looks like so:

 Documentation/video4linux/README.saa7134           |    9
 Documentation/video4linux/bttv/Cards               |   74
 .../video4linux/hauppauge-wintv-cx88-ir.txt        |   54
 Documentation/video4linux/lifeview.txt             |   42
 .../video4linux/not-in-cx2388x-datasheet.txt       |   41
 Documentation/w1/w1.generic                        |  107

ie we've made it clear with an ellipsis that we've cut off something from
the beginning, and it also tries to do it cleanly at a subdirectory level.

Signed-off-by: Linus "good taste" Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-07-28 21:05:06 -07:00
Junio C Hamano
d854f783af [PATCH] apply.c: --exclude=fnmatch-pattern option.
Adds --exclude=pattern option to the "git-apply" command.  This
was useful while reimporting the BKCVS patchset dump of the
Linux kernel, starting at 2.4.0 and ending at 2.6.12-rc2 Ingo
announced some time ago to exclude BitKeeper directory.

Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-07-22 10:26:01 -07:00
Junio C Hamano
8b64647dd9 [PATCH] apply.c: handle incomplete lines correctly.
The parsing code had a bug that failed to recognize an
incomplete line at the end of a fragment, and the fragment
application code had a comparison bug to recognize such.  Fix
them to handle incomplete lines correctly.

Add a test script for patches with various combinations of
complete and incomplete lines to make sure the fix works.

Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-07-22 10:26:01 -07:00
Junio C Hamano
12dd6e8cb0 [PATCH] apply: match documentation, usage string and code.
The more recent --apply option was not described.

Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-07-13 20:53:33 -07:00
Linus Torvalds
1b668341db git-apply: be a lot more careful when writing files
We write them under another name and rename them to their destination,
so that if something bad happens in the middle, we won't have caused any
bigger harm.

Also, this makes the writing be NFS "intr" safe, and as a side effects
makes sure that if the target is hardlinked (or symlinked) we will have
broken the link.
2005-07-13 17:25:53 -07:00
Tony Luck
e30e814dbf [PATCH] git: fix trivial warning from show_rename_copy()
apply.c: In function `show_rename_copy':
apply.c:1147: warning: field precision is not type int (arg 3)

Signed-off-by: Tony Luck <tony.luck@intel.com>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-07-12 13:04:31 -07:00
Junio C Hamano
f312de018b [PATCH] Let umask do its work upon filesystem object creation.
IIRC our strategy was to let the users' umask take care of the
final mode bits.  This patch fixes places that deviate from it.

Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-07-06 10:39:59 -07:00
Linus Torvalds
6da4016aea Fix sparse warnings.
Mainly making a lot of local functions and variables be marked "static",
but there was a "zero as NULL" warning in there too.
2005-07-03 10:10:45 -07:00
Linus Torvalds
aefa4a5b1c git-apply: take "--apply" flag to force an apply even if we also ask for a diffstat
Also, remove debugging statement about applying a fragment at an offset.
2005-06-23 09:00:01 -07:00
Junio C Hamano
96c912a484 [PATCH] git-apply: implement --summary option.
Typical expected usage is "git-apply --stat --summary" to show
diffstat plus dense description of information available in git
extended headers, such as creations, renames, and mode changes.

Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-22 10:23:48 -07:00
Junio C Hamano
03b4538bad [PATCH] git-apply --stat: show new filename for rename/copy patch.
When a patch is a git extended rename/copy patch, "git-apply
--stat" showed the old filename.  Change it to show the new
filename, because most of the time we are interested in looking
at the resulting tree.

Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-22 10:23:48 -07:00
Linus Torvalds
5c8af185cc git-apply: create subdirectories leading up to a new file
Applying Andrew's latest patch-bomb showed us failing miserably if a new
subdirectory needed to be created..  That said, it's uncommon enough
that it's worth optimistically assuming it won't be needed, and then
creating the subdirectories only on failure.
2005-06-21 19:10:21 -07:00
Sven Verdoolaege
69f956e104 [PATCH] git-apply: Don't barf when --stat'ing a diff with no line changes.
Diffs with only mode changes didn't pass through git-apply --stat.

[ Linus' note: they did for me, on my ppc64, where division by zero just
  silently returns zero.  Duh.  ]

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-21 08:41:56 -07:00
Linus Torvalds
b7e8039a6f git-apply: use default name for mode change patches
Pure mode changes won't have the file-name in the extended header lines,
so make sure we pick it up from the default name from the "diff --git"
line.
2005-06-17 15:23:40 -07:00
Linus Torvalds
de4971b500 git-apply: normalize file mode when comparing with expected value
Sine git only saves the 'x' bit, we shouldn't compare the stat contents
directly.
2005-06-13 20:41:38 -07:00
Linus Torvalds
84fb9a4dca git-apply: fix error handling for nonexistent files
Missing argument for error() function. We should really use the
gcc printf format checking capabilities.
2005-06-12 21:04:27 -07:00
Linus Torvalds
206de27efa git-apply: ignore empty git headers
A meaningful (ie non-empty) git patch always has more information in the
header than just the "diff --git" line itself: it needs to have either a
patch associated with it (which implies "---" and "+++" lines in the
header) or it needs to have rename/copy/delete/create information in it.

Just ignore git patches which have no change information. Otherwise we'll
end up with a patch that doesn't have filenames etc filled in, and we'll
be unhappy.
2005-06-12 09:37:49 -07:00
Linus Torvalds
af3f929f95 git-apply: creatign empty files is nonfatal
(but it will result in a warning)
2005-06-08 08:11:47 -07:00
Linus Torvalds
dc93841715 diff 'rename' format change.
Clearly even Junio felt git "rename" header lines should say "from/to"
instead of "old/new", since he wrote the documentation that way.

This way it also matches "copy".

git-apply will accept both versions, at least for a while.
2005-06-05 15:31:52 -07:00
Linus Torvalds
f7b797073c git-apply: consider it an error to apply no changes
A "--stat" or a "--check" will just be quiet, but if
you try to apply something with no changes, that's an
error.
2005-06-05 15:25:28 -07:00
Linus Torvalds
33f4d087a9 git-apply: fix rename header parsing
It's not "rename from" and "rename to", it's "rename old" and "rename new".

Which is illogical and doesn't match the "copy from/to" case, but that's
life. Maybe Junio will fix it up one of these days.
2005-06-05 14:26:50 -07:00
Linus Torvalds
5aa7d94cd6 git-apply: actually apply patches and update the index
We update the index only if the "--index" flag is given,
so you can actually use this as a strange kind of "patch"
program even for non-git usage. Not that you'd likely
want to, but it comes in handy for testing.

This _should_ more or less get everythign right, but as
usual I leave the testing to the usrs..
2005-06-05 14:05:43 -07:00
Linus Torvalds
30996652e7 git-apply: fix apply of a new file
(And fix name handling for when we have an implied
create or delete event from a traditional diff).
2005-06-05 12:43:56 -07:00
Linus Torvalds
6e7c92a91d git-apply: find offset fragments, and really apply them
This applies the fragments in memory, but doesn't actually
write the results out to the files yet. But we now do all the
difficult parts, the rest is just basically writing the
results out and updating the index.
2005-06-05 12:16:32 -07:00
Linus Torvalds
3cca928d4a git-apply: first cut at actually checking fragment data
Right now it requires that the fragment offsets be exact,
and it doesn't actually apply the fragment yet, but it
does find where it goes and verify the data.

Next step: actually applying the fragment changes.
2005-06-05 11:03:13 -07:00