You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by ph...@apache.org on 2014/12/11 12:00:27 UTC
svn commit: r1644595 - in /subversion/trunk/subversion:
libsvn_client/patch.c tests/cmdline/patch_tests.py
Author: philip
Date: Thu Dec 11 11:00:27 2014
New Revision: 1644595
URL: http://svn.apache.org/r1644595
Log:
Fix part of issue 4533, apply hunks in matched order.
* subversion/libsvn_client/patch.c
(sort_matched_hunks): New.
(apply_one_patch): Sort hunks.
* subversion/tests/cmdline/patch_tests.py
(patch_hunk_reorder): Remove XFAIL, swap order of output lines.
Modified:
subversion/trunk/subversion/libsvn_client/patch.c
subversion/trunk/subversion/tests/cmdline/patch_tests.py
Modified: subversion/trunk/subversion/libsvn_client/patch.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/patch.c?rev=1644595&r1=1644594&r2=1644595&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/patch.c (original)
+++ subversion/trunk/subversion/libsvn_client/patch.c Thu Dec 11 11:00:27 2014
@@ -48,6 +48,7 @@
#include "private/svn_dep_compat.h"
#include "private/svn_string_private.h"
#include "private/svn_subr_private.h"
+#include "private/svn_sorts_private.h"
typedef struct hunk_info_t {
/* The hunk. */
@@ -2139,6 +2140,30 @@ send_patch_notification(const patch_targ
return SVN_NO_ERROR;
}
+/* Implements the callback for svn_sort__array. Puts hunks that match
+ before hunks that do not match, and puts hunks that match in order
+ based on postion matched. */
+static int
+sort_matched_hunks(const void *a, const void *b)
+{
+ const hunk_info_t *item1 = *((const hunk_info_t * const *)a);
+ const hunk_info_t *item2 = *((const hunk_info_t * const *)b);
+ svn_boolean_t matched1 = !item1->rejected && !item1->already_applied;
+ svn_boolean_t matched2 = !item2->rejected && !item2->already_applied;
+
+ if (matched1 && matched2)
+ {
+ /* Both match so use order matched in file. */
+ if (item1->matched_line > item2->matched_line)
+ return 1;
+ }
+ else if (matched2)
+ /* Only second matches, put it before first. */
+ return 1;
+
+ return -1;
+}
+
/* Apply a PATCH to a working copy at ABS_WC_PATH and put the result
* into temporary files, to be installed in the working copy later.
* Return information about the patch target in *PATCH_TARGET, allocated
@@ -2220,6 +2245,10 @@ apply_one_patch(patch_target_t **patch_t
APR_ARRAY_PUSH(target->content->hunks, hunk_info_t *) = hi;
}
+ /* Hunks are applied in the order determined by the matched line and
+ this may be different from the order of the original lines. */
+ svn_sort__array(target->content->hunks, sort_matched_hunks);
+
/* Apply or reject hunks. */
for (i = 0; i < target->content->hunks->nelts; i++)
{
Modified: subversion/trunk/subversion/tests/cmdline/patch_tests.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/patch_tests.py?rev=1644595&r1=1644594&r2=1644595&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/patch_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/patch_tests.py Thu Dec 11 11:00:27 2014
@@ -4870,7 +4870,6 @@ def patch_hunk_avoid_reorder(sbox):
expected_output, expected_disk,
expected_status, expected_skip)
-@XFail()
@Issue(4533)
def patch_hunk_reorder(sbox):
"""hunks that reorder"""
@@ -4913,8 +4912,8 @@ def patch_hunk_reorder(sbox):
expected_output = [
'U %s\n' % sbox.ospath('A/mu'),
+ '> applied hunk @@ -9,6 +10,7 @@ with offset -7\n',
'> applied hunk @@ -2,6 +2,7 @@ with offset 7\n',
- '> applied hunk @@ -9,6 +10,7 @@ with offset -7\n'
]
expected_disk = svntest.main.greek_state.copy()
expected_disk.tweak('A/mu', contents=