summaryrefslogtreecommitdiff
path: root/builtin/apply.c
AgeCommit message (Collapse)AuthorFilesLines
2012-06-01i18n: apply: split to fix a partial i18n messageLibravatar Jiang Xin1-4/+12
The 4th arg of "new mode (%o) of %s does not match old mode (%o)%s%s" is blank string or string " of ". Even mark the string " of " for a complete i18n, this message is still hard to translate right. Split it into two slight different messages would make l10n teams happy. Signed-off-by: Jiang Xin <worldhello.net@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-17Merge branch 'nd/i18n-parseopt'Libravatar Junio C Hamano1-31/+31
Text from "git cmd --help" are getting prepared for i18n. By Nguyễn Thái Ngọc Duy * nd/i18n-parseopt: i18n: apply: mark parseopt strings for translation i18n: parseopt: lookup help and argument translations when showing usage
2012-05-08i18n: apply: mark parseopt strings for translationLibravatar Nguyễn Thái Ngọc Duy1-31/+31
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-08apply: remove lego in i18n string in gitdiff_verify_nameLibravatar Nguyễn Thái Ngọc Duy1-4/+11
It marks the string "...inconsistent %s filename..." where %s is either "old" or "new" from caller. Make it two strings "...inconsistent new filename..." and "...inconsistent old filename...". Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-02Merge branch 'nd/i18n'Libravatar Junio C Hamano1-95/+111
More message strings marked for i18n. By Nguyễn Thái Ngọc Duy (10) and Jonathan Nieder (1) * nd/i18n: help: replace underlining "help -a" headers using hyphens with a blank line i18n: bundle: mark strings for translation i18n: index-pack: mark strings for translation i18n: apply: update say_patch_name to give translators complete sentence i18n: apply: mark strings for translation i18n: remote: mark strings for translation i18n: make warn_dangling_symref() automatically append \n i18n: help: mark strings for translation i18n: mark relative dates for translation strbuf: convenience format functions with \n automatically appended Makefile: feed all header files to xgettext
2012-04-24i18n: apply: update say_patch_name to give translators complete sentenceLibravatar Nguyễn Thái Ngọc Duy1-12/+20
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-04-24i18n: apply: mark strings for translationLibravatar Nguyễn Thái Ngọc Duy1-83/+91
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-04-23Merge branch 'jh/apply-free-patch'Libravatar Junio C Hamano1-41/+133
Valgrind reports quite a lot of discarded memory inside apply. Fix them, audit and document the buffer ownership rules. By Junio C Hamano (8) and Jared Hance (1) * jh/apply-free-patch: apply: document buffer ownership rules across functions apply: tighten constness of line buffer apply: drop unused macro apply: free unused fragments for submodule patch apply: free patch->result apply: release memory for fn_table apply: free patch->{def,old,new}_name fields apply: rename free_patch() to free_patch_list() apply: do not leak patches and fragments
2012-04-11apply: document buffer ownership rules across functionsLibravatar Junio C Hamano1-2/+51
In general, the private functions in this file were not very much documented; even though what each of them do is reasonably self explanatory, the ownership rules for various buffers and data structures were not very obvious. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-04-11apply: tighten constness of line bufferLibravatar Junio C Hamano1-7/+7
These point into a single line in the patch text we read from the input, and they are not used to modify it. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-04-11apply: drop unused macroLibravatar Junio C Hamano1-1/+0
CHUNKSIZE is no longer used. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-28apply: free unused fragments for submodule patchLibravatar Junio C Hamano1-9/+15
We simply discarded the fragments that we are not going to use upon seeing a patch to update the submodule commit bound at path that we have not checked out. Free these fragments, not to leak them. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-27apply: free patch->resultLibravatar Junio C Hamano1-0/+1
This is by far the largest piece of data, much larger than the patch and fragment structures or the three name fields in the patch structure. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-27apply: release memory for fn_tableLibravatar Junio C Hamano1-1/+1
The fn_table is used to record the result of earlier patch application in case a hand-crafted input file contains multiple patches to the same file. Both its string key (filename) and the contents are borrowed from "struct patch" that represents the previous application in the same apply_patch() call, and they do not leak, but the table itself was not freed properly. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-27apply: free patch->{def,old,new}_name fieldsLibravatar Junio C Hamano1-26/+39
These were all allocated in the heap by parsing the header parts of the patch, but we did not bother to free them. Some used to share the memory (e.g. copying def_name to old_name) so this is not just the matter of adding three calls to free(). Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-27apply: rename free_patch() to free_patch_list()Libravatar Junio C Hamano1-14/+19
As that is the only logical name for a function that walks a list and frees each element on it. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-07apply: do not leak patches and fragmentsLibravatar Jared Hance1-4/+23
In the while loop inside apply_patch, patch and fragments are dynamically allocated with a calloc. However, only unused patches are actually freed and the rest are left to leak. Since a list is actively built up consisting of the used patches, they can simply be iterated and freed at the end of the function. In addition, the text in fragments were not freed, primarily because they mostly point into a patch text that is freed as a whole. But there are some cases where new piece of memory is allocated and pointed by a fragment (namely, when handling a binary patch). Introduce a free_patch bitfield to mark each fragment if its text needs to be freed, and free patches, fragments and fragment text that need to be freed when we are done with the input. Signed-off-by: Jared Hance <jaredhance@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-02-03Use correct grammar in diffstat summary lineLibravatar Nguyễn Thái Ngọc Duy1-1/+2
"git diff --stat" and "git apply --stat" now learn to print the line "%d files changed, %d insertions(+), %d deletions(-)" in singular form whenever applicable. "0 insertions" and "0 deletions" are also omitted unless they are both zero. This matches how versions of "diffstat" that are not prehistoric produced their output, and also makes this line translatable. [jc: with help from Thomas Dickey in archaeology of "diffstat"] [jc: squashed Jonathan's updates to illustrations in tutorials and a test] Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-12-21Merge branch 'bc/maint-apply-check-no-patch' into maintLibravatar Junio C Hamano1-5/+5
* bc/maint-apply-check-no-patch: builtin/apply.c: report error on failure to recognize input t/t4131-apply-fake-ancestor.sh: fix broken test
2011-12-13Merge branch 'bc/maint-apply-check-no-patch'Libravatar Junio C Hamano1-5/+5
* bc/maint-apply-check-no-patch: builtin/apply.c: report error on failure to recognize input t/t4131-apply-fake-ancestor.sh: fix broken test
2011-12-13Merge branch 'maint-1.7.7' into maintLibravatar Junio C Hamano1-3/+0
* maint-1.7.7: Git 1.7.7.5 Git 1.7.6.5 blame: don't overflow time buffer fetch: create status table using strbuf checkout,merge: loosen overwriting untracked file check based on info/exclude cast variable in call to free() in builtin/diff.c and submodule.c apply: get rid of useless x < 0 comparison on a size_t type Conflicts: Documentation/git.txt GIT-VERSION-GEN RelNotes builtin/fetch.c
2011-12-13Merge branch 'ab/clang-lints' into maint-1.7.7Libravatar Junio C Hamano1-3/+0
* ab/clang-lints: cast variable in call to free() in builtin/diff.c and submodule.c apply: get rid of useless x < 0 comparison on a size_t type
2011-12-05Merge branch 'ab/clang-lints'Libravatar Junio C Hamano1-3/+0
* ab/clang-lints: cast variable in call to free() in builtin/diff.c and submodule.c apply: get rid of useless x < 0 comparison on a size_t type
2011-12-05builtin/apply.c: report error on failure to recognize inputLibravatar Brandon Casey1-5/+5
When git apply is passed something that is not a patch, it does not produce an error message or exit with a non-zero status if it was not actually "applying" the patch i.e. --check or --numstat etc were supplied on the command line. Fix this by producing an error when apply fails to find any hunks whatsoever while parsing the patch. This will cause some of the output formats (--numstat, --diffstat, etc) to produce an error when they formerly would have reported zero changes and exited successfully. That seems like the correct behavior though. Failure to recognize the input as a patch should be an error. Plus, add a test. Reported-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: Brandon Casey <drafnel@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-11-06apply: get rid of useless x < 0 comparison on a size_t typeLibravatar Ævar Arnfjörð Bjarmason1-3/+0
According to the C standard size_t is always unsigned, therefore the comparison "n1 < 0 || n2 < 0" when n1 and n2 are size_t will always be false. This was raised by clang 2.9 which throws this warning when compiling apply.c: builtin/apply.c:253:9: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare] if (n1 < 0 || n2 < 0) ~~ ^ ~ builtin/apply.c:253:19: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare] if (n1 < 0 || n2 < 0) ~~ ^ ~ This check was originally added in v1.6.5-rc0~53^2 by Giuseppe Bilotta while adding an option to git-apply to ignore whitespace differences. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-10-21Merge branch 'jc/apply-blank-at-eof-fix' into maintLibravatar Junio C Hamano1-2/+9
* jc/apply-blank-at-eof-fix: apply --whitespace=error: correctly report new blank lines at end
2011-10-21Merge branch 'jm/maint-apply-detects-corrupt-patch-header' into maintLibravatar Junio C Hamano1-0/+3
* jm/maint-apply-detects-corrupt-patch-header: fix "git apply --index ..." not to deref NULL
2011-10-19Merge branch 'jm/maint-apply-detects-corrupt-patch-header'Libravatar Junio C Hamano1-0/+3
* jm/maint-apply-detects-corrupt-patch-header: fix "git apply --index ..." not to deref NULL
2011-10-13Merge branch 'jc/apply-blank-at-eof-fix'Libravatar Junio C Hamano1-2/+9
* jc/apply-blank-at-eof-fix: apply --whitespace=error: correctly report new blank lines at end
2011-10-12fix "git apply --index ..." not to deref NULLLibravatar Jim Meyering1-0/+3
I noticed this when "git am CORRUPTED" unexpectedly failed with an odd diagnostic, and even removed one of the files it was supposed to have patched. Reproduce with any valid old/new patch from which you have removed the "+++ b/FILE" line. You'll see a diagnostic like this fatal: unable to write file '(null)' mode 100644: Bad address and you'll find that FILE has been removed. The above is on glibc-based systems. On other systems, rather than getting "null", you may provoke a segfault as git tries to dereference the NULL file name. Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-09-28apply: use OPT_NOOP_NOARGLibravatar René Scharfe1-7/+2
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-06-10zlib: zlib can only process 4GB at a timeLibravatar Junio C Hamano1-1/+1
The size of objects we read from the repository and data we try to put into the repository are represented in "unsigned long", so that on larger architectures we can handle objects that weigh more than 4GB. But the interface defined in zlib.h to communicate with inflate/deflate limits avail_in (how many bytes of input are we calling zlib with) and avail_out (how many bytes of output from zlib are we ready to accept) fields effectively to 4GB by defining their type to be uInt. In many places in our code, we allocate a large buffer (e.g. mmap'ing a large loose object file) and tell zlib its size by assigning the size to avail_in field of the stream, but that will truncate the high octets of the real size. The worst part of this story is that we often pass around z_stream (the state object used by zlib) to keep track of the number of used bytes in input/output buffer by inspecting these two fields, which practically limits our callchain to the same 4GB limit. Wrap z_stream in another structure git_zstream that can express avail_in and avail_out in unsigned long. For now, just die() when the caller gives a size that cannot be given to a single zlib call. In later patches in the series, we would make git_inflate() and git_deflate() internally loop to give callers an illusion that our "improved" version of zlib interface can operate on a buffer larger than 4GB in one go. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-05-16Merge branch 'jc/maint-add-p-overlapping-hunks' into maintLibravatar Junio C Hamano1-3/+6
* jc/maint-add-p-overlapping-hunks: t3701: add-p-fix makes the last test to pass "add -p": work-around an old laziness that does not coalesce hunks add--interactive.perl: factor out repeated --recount option t3701: Editing a split hunk in an "add -p" session add -p: 'q' should really quit
2011-04-29"add -p": work-around an old laziness that does not coalesce hunksLibravatar Junio C Hamano1-3/+6
Since 0beee4c (git-add--interactive: remove hunk coalescing, 2008-07-02), "git add--interactive" behaves lazily and passes overlapping hunks to the underlying "git apply" without coalescing. This was partially corrected by 7a26e65 (its partial revert, 2009-05-16), but overlapping hunks are still passed when the patch is edited. Teach "git apply" the --allow-overlap option that disables a safety feature that avoids misapplication of patches by not applying patches to overlapping hunks, and pass this option form "add -p" codepath. Do not even advertise the option, as this is merely a workaround, and the correct fix is to make "add -p" correctly coalesce adjacent patch hunks. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-15Merge branch 'jc/maint-apply-report-offset'Libravatar Junio C Hamano1-2/+14
* jc/maint-apply-report-offset: apply -v: show offset count when patch did not apply exactly
2011-03-06apply -v: show offset count when patch did not apply exactlyLibravatar Junio C Hamano1-2/+14
When the line number the patch intended to touch does not match the line in the version being patched, GNU patch reports that it applied the hunk at a different line number, with how big an offset. Teach "git apply" to do the same under --verbose option. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-04apply: do not patch lines that were already patchedLibravatar Junio C Hamano1-1/+6
When looking for a place to apply a hunk, we used to check lines that match the preimage of it, starting from the line that the patch wants to apply the hunk at, looking forward and backward with increasing offsets until we find a match. Colin Guthrie found an interesting case where this misapplied a patch that wanted to touch a preimage that consists of } } return 0; } which is a rather unfortunately common pattern. The target version of the file originally had only one such location, but the hunk immediately before that created another instance of such block of lines, and find_pos() happily reported that the preimage of the hunk matched what it wanted to modify. Oops. By marking the lines application of earlier hunks touched and preventing match_fragment() from considering them as a match with preimage of other hunks, we can reduce such an accident. I also considered to teach apply_one_fragment() to take the offset we have found while applying the previous hunk into account when looking for a match with find_pos(), but dismissed that approach, because it would sometimes work better but sometimes worse, depending on the difference between the version the patch was created against and the version the patch is being applied. This does _not_ prevent misapplication of patches to a file that has many similar looking blocks of lines and a preimage cannot identify which one of them should be applied. For that, we would need to scan beyond the first match in find_pos(), and issue a warning (or error out). That will be a separate topic. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-29Merge branch 'fc/apply-p2-get-header-name'Libravatar Junio C Hamano1-14/+14
* fc/apply-p2-get-header-name: test: git-apply -p2 rename/chmod only Fix git-apply with -p greater than 1
2010-11-29Merge branch 'ak/apply-non-git-epoch'Libravatar Junio C Hamano1-6/+29
* ak/apply-non-git-epoch: apply: handle patches with funny filename and colon in timezone apply: Recognize epoch timestamps with : in the timezone
2010-11-24Merge branch 'rs/opt-help-text'Libravatar Junio C Hamano1-1/+1
* rs/opt-help-text: verify-tag: document --verbose branch: improve --verbose description archive: improve --verbose description Describe various forms of "be quiet" using OPT__QUIET add OPT__FORCE add description parameter to OPT__QUIET add description parameter to OPT__DRY_RUN add description parameter to OPT__VERBOSE
2010-11-15add description parameter to OPT__VERBOSELibravatar René Scharfe1-1/+1
Allows better help text to be defined than "be verbose". Also make use of the macro in places that already had a different description. No object code changes intended. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10apply: handle patches with funny filename and colon in timezoneLibravatar Jonathan Nieder1-2/+22
Some patches have a timezone formatted like '-08:00' instead of '-0800' in their ---/+++ lines (e.g. http://lwn.net/Articles/131729/). Take this into account when searching for the start of the timezone (which is the end of the filename). This does not actually affect the outcome of patching unless (1) a file being patched has a non-' ' whitespace character (e.g., tab) in its filename, or (2) the patch is whitespace-damaged, so the tab between filename and timestamp has been replaced with spaces. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-05Fix git-apply with -p greater than 1Libravatar Federico Cuello1-14/+14
Fix the case when the patch is a rename or mode-change only and -p is used with a value greater than one. The git_header_name function did not remove more than one path component. Signed-off-by: Federico Cuello <fedux@lugmen.org.ar> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-10-29apply: don't segfault on binary files with missing dataLibravatar Jeff King1-0/+6
Usually when applying a binary diff generated without --binary, it will be rejected early, as we don't even have the full sha1 of the pre- and post-images. However, if the diff is generated with --full-index (but not --binary), then we will actually try to apply it. If we have the postimage blob, then we can take a shortcut and never even look at the binary diff at all (e.g., this can happen when rebasing changes within a repository). If we don't have the postimage blob, though, we try to look at the actual fragments, of which there are none, and get a segfault. This patch checks explicitly for that case and complains to the user instead of segfaulting. We need to keep the check at a low level so that the "shortcut" case above continues to work. We also add a test that demonstrates the segfault. While we're at it, let's also explicitly test the shortcut case. Reported-by: Rafaël Carré <rafael.carre@gmail.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-10-13apply: Recognize epoch timestamps with : in the timezoneLibravatar Anders Kaseorg1-4/+7
Some patches have a timezone formatted like ‘-08:00’ instead of ‘-0800’ (e.g. http://lwn.net/Articles/131729/), so git apply would fail to recognize the epoch timestamp of deleted files and would create empty files instead. Teach it to support both formats, and add a test case. Signed-off-by: Anders Kaseorg <andersk@mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-09-03Merge branch 'jn/apply-filename-with-sp'Libravatar Junio C Hamano1-38/+211
* jn/apply-filename-with-sp: apply: handle traditional patches with space in filename tests: exercise "git apply" with weird filenames apply: split quoted filename handling into new function
2010-08-31Merge branch 'jn/paginate-fix'Libravatar Junio C Hamano1-3/+3
* jn/paginate-fix: t7006 (pager): add missing TTY prerequisites merge-file: run setup_git_directory_gently() sooner var: run setup_git_directory_gently() sooner ls-remote: run setup_git_directory_gently() sooner index-pack: run setup_git_directory_gently() sooner config: run setup_git_directory_gently() sooner bundle: run setup_git_directory_gently() sooner apply: run setup_git_directory_gently() sooner grep: run setup_git_directory_gently() sooner shortlog: run setup_git_directory_gently() sooner git wrapper: allow setup_git_directory_gently() be called earlier setup: remember whether repository was found git wrapper: introduce startup_info struct Conflicts: builtin/index-pack.c
2010-08-21apply: handle traditional patches with space in filenameLibravatar Jonathan Nieder1-14/+179
To discover filenames from the --- and +++ lines in a traditional unified diff, currently "git apply" scans forward for a whitespace character on each line and stops there. It can't use the whole line because "diff -u" likes to include timestamps, like so: --- foo 2000-07-12 16:56:50.020000414 -0500 +++ bar 2010-07-12 16:56:50.020000414 -0500 The whitespace-seeking heuristic works great, even when the tab has been converted to spaces by some email + copy-and-paste related corruption. Except for one problem: if the filename itself contains whitespace, the inferred filename will be too short. When Giuseppe ran into this problem, it was for a file creation patch (for debian/licenses/LICENSE.global BSD-style Chromium). So one can't use the list of files present in the index to deduce an appropriate filename (not to mention that way lies madness; see v0.99~402, 2005-05-31). Instead, look for a timestamp and use that if present to mark the end of the filename. If no timestamp is present, the old heuristic is used, with one exception: the space character \040 is not considered terminating whitespace any more unless it is followed by a timestamp. Reported-by: Giuseppe Iuculano <iuculano@debian.org> Acked-by: Guido Günther <agx@sigxcpu.org> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-08-21apply: split quoted filename handling into new functionLibravatar Jonathan Nieder1-30/+38
The new find_name_gnu() function handles new-style '--- "a/foo"' patch header lines, leaving find_name() itself a bit less daunting. Functional change: do not clobber the p-value when there are not enough path components in a quoted file name to honor it. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-08-15apply: run setup_git_directory_gently() soonerLibravatar Nguyễn Thái Ngọc Duy1-3/+3
As v1.7.2~16^2 (2010-07-14) explains, without this change, “git --paginate apply” can ignore the repository-local “[core] pager” configuration. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>