From 3aeedafe311168a8d9a585330a3d3fb391111af667c71c6e868142e706a92314 Mon Sep 17 00:00:00 2001 From: OBS User unknown Date: Fri, 2 Nov 2007 09:40:24 +0000 Subject: [PATCH] OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/patch?expand=0&rev=2 --- fix-partial-context.diff | 87 ++++++++++++++++++++++++++++++++++++++++ patch.changes | 5 +++ patch.spec | 45 +++++++++++---------- 3 files changed, 116 insertions(+), 21 deletions(-) create mode 100644 fix-partial-context.diff diff --git a/fix-partial-context.diff b/fix-partial-context.diff new file mode 100644 index 0000000..f543820 --- /dev/null +++ b/fix-partial-context.diff @@ -0,0 +1,87 @@ +From: Andreas Gruenbacher +Subject: Patch fails to apply hunks with asymmetric context correctly + +Patch assumes that hunks with fewer context lines at the top than at the bottom +can only match at the beginning of the file, and hunks with fewer lines at the +bottom can only match at the end. The result is that patches with such hunks +will only apply with fuzz N if the prefix context is N lines longer or shorter +than the suffix context. This makes no sense; hunks with asymmetric context +are perfectly valid. + +--- + ChangeLog | 7 +++++++ + patch.c | 43 ++++--------------------------------------- + 2 files changed, 11 insertions(+), 39 deletions(-) + +--- a/ChangeLog ++++ b/ChangeLog +@@ -1,3 +1,10 @@ ++2007-11-02 Andreas Gruenbacher ++ ++ * patch.c (locate_hunk): Hunks that have fewer or more lines of ++ context at the beginning than at the end can match anywhere; the ++ assumption that this can only occur at the beginning or end of the ++ file is wrong. ++ + 2003-05-20 Paul Eggert + + * NEWS, configure.ac (AC_INIT): Version 2.5.9 released. +--- a/patch.c ++++ b/patch.c +@@ -849,10 +849,10 @@ locate_hunk (LINENUM fuzz) + LINENUM pat_lines = pch_ptrn_lines(); + LINENUM prefix_context = pch_prefix_context (); + LINENUM suffix_context = pch_suffix_context (); +- LINENUM context = (prefix_context < suffix_context +- ? suffix_context : prefix_context); +- LINENUM prefix_fuzz = fuzz + prefix_context - context; +- LINENUM suffix_fuzz = fuzz + suffix_context - context; ++ LINENUM prefix_fuzz = (prefix_context < fuzz ++ ? prefix_context : fuzz); ++ LINENUM suffix_fuzz = (suffix_context < fuzz ++ ? suffix_context : fuzz); + LINENUM max_where = input_lines - (pat_lines - suffix_fuzz) + 1; + LINENUM min_where = last_frozen_line + 1 - (prefix_context - prefix_fuzz); + LINENUM max_pos_offset = max_where - first_guess; +@@ -867,41 +867,6 @@ locate_hunk (LINENUM fuzz) + if (first_guess <= max_neg_offset) + max_neg_offset = first_guess - 1; + +- if (prefix_fuzz < 0) +- { +- /* Can only match start of file. */ +- +- if (suffix_fuzz < 0) +- /* Can only match entire file. */ +- if (pat_lines != input_lines || prefix_context < last_frozen_line) +- return 0; +- +- offset = 1 - first_guess; +- if (last_frozen_line <= prefix_context +- && offset <= max_pos_offset +- && patch_match (first_guess, offset, (LINENUM) 0, suffix_fuzz)) +- { +- last_offset += offset; +- return first_guess + offset; +- } +- else +- return 0; +- } +- +- if (suffix_fuzz < 0) +- { +- /* Can only match end of file. */ +- offset = first_guess - (input_lines - pat_lines + 1); +- if (offset <= max_neg_offset +- && patch_match (first_guess, -offset, prefix_fuzz, (LINENUM) 0)) +- { +- last_offset -= offset; +- return first_guess - offset; +- } +- else +- return 0; +- } +- + for (offset = 0; offset <= max_offset; offset++) { + char numbuf0[LINENUM_LENGTH_BOUND + 1]; + char numbuf1[LINENUM_LENGTH_BOUND + 1]; diff --git a/patch.changes b/patch.changes index c0244a8..dd2cbda 100644 --- a/patch.changes +++ b/patch.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Fri Nov 2 01:57:03 CET 2007 - agruen@suse.de + +- Patch fails to apply hunks with asymmetric context correctly. + ------------------------------------------------------------------- Wed Jan 25 21:30:47 CET 2006 - mls@suse.de diff --git a/patch.spec b/patch.spec index dacac16..019c177 100644 --- a/patch.spec +++ b/patch.spec @@ -1,32 +1,33 @@ # # spec file for package patch (Version 2.5.9) # -# Copyright (c) 2006 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2007 SUSE LINUX Products GmbH, Nuernberg, Germany. # This file and all modifications and additions to the pristine # package are under the same license as the package itself. # -# Please submit bugfixes or comments via http://bugs.opensuse.org +# Please submit bugfixes or comments via http://bugs.opensuse.org/ # # norootforbuild -Name: patch -License: GPL -Group: Productivity/Text/Utilities -Autoreqprov: on -Version: 2.5.9 -Release: 149 -Summary: GNU patch -Source: ftp://prep.ai.mit.edu/pub/gnu/patch/%{name}-%{version}.tar.bz2 -URL: http://www.gnu.org/software/patch/patch.html -Patch: trailing-cr-fix.diff -Patch1: remember-backup-files.diff -Patch2: unified-reject-files.diff -Patch3: global-reject-file.diff -Patch4: if_else_endif_comments.diff -Patch5: patch-2.5.9-cat_if_device.diff -Patch6: patch-man-unified-reject.diff -BuildRoot: %{_tmppath}/%{name}-%{version}-build +Name: patch +License: GPL v2 or later +Group: Productivity/Text/Utilities +AutoReqProv: on +Version: 2.5.9 +Release: 223 +Summary: GNU patch +Source: ftp://prep.ai.mit.edu/pub/gnu/patch/%{name}-%{version}.tar.bz2 +Url: http://www.gnu.org/software/patch/patch.html +Patch: trailing-cr-fix.diff +Patch1: remember-backup-files.diff +Patch2: unified-reject-files.diff +Patch3: global-reject-file.diff +Patch4: if_else_endif_comments.diff +Patch5: patch-2.5.9-cat_if_device.diff +Patch6: patch-man-unified-reject.diff +Patch7: fix-partial-context.diff +BuildRoot: %{_tmppath}/%{name}-%{version}-build %description The GNU patch program is used to apply diffs between original and @@ -48,6 +49,7 @@ Authors: %patch3 -p1 %patch5 -p1 %patch6 -p1 +%patch7 -p1 %build aclocal --acdir=m4 @@ -71,8 +73,9 @@ make install \ %doc NEWS README /usr/bin/patch %doc %{_mandir}/man1/patch.1.gz - -%changelog -n patch +%changelog +* Fri Nov 02 2007 - agruen@suse.de +- Patch fails to apply hunks with asymmetric context correctly. * Wed Jan 25 2006 - mls@suse.de - converted neededforbuild to BuildRequires * Thu Jan 12 2006 - agruen@suse.de