You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2010/01/04 00:16:44 UTC
svn commit: r895506 - /subversion/trunk/subversion/libsvn_diff/parse-diff.c
Author: stsp
Date: Sun Jan 3 23:16:42 2010
New Revision: 895506
URL: http://svn.apache.org/viewvc?rev=895506&view=rev
Log:
Make the diff parser return hunks in sorted order, regardless of the order
they appeared in the patch file.
* subversion/libsvn_diff/parse-diff.c
(compare_hunks): New.
(svn_diff__parse_next_patch): Sort hunks after parsing them.
Modified:
subversion/trunk/subversion/libsvn_diff/parse-diff.c
Modified: subversion/trunk/subversion/libsvn_diff/parse-diff.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_diff/parse-diff.c?rev=895506&r1=895505&r2=895506&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_diff/parse-diff.c (original)
+++ subversion/trunk/subversion/libsvn_diff/parse-diff.c Sun Jan 3 23:16:42 2010
@@ -22,6 +22,7 @@
*/
#include <limits.h> /* for ULONG_MAX */
+#include <stdlib.h>
#include <string.h>
#include "svn_types.h"
@@ -370,6 +371,21 @@
return SVN_NO_ERROR;
}
+/* Compare function for sorting hunks after parsing.
+ * We sort hunks by their original line offset. */
+static int
+compare_hunks(const void *a, const void *b)
+{
+ const svn_hunk_t *ha = *((const svn_hunk_t **)a);
+ const svn_hunk_t *hb = *((const svn_hunk_t **)b);
+
+ if (ha->original_start < hb->original_start)
+ return -1;
+ if (ha->original_start > hb->original_start)
+ return 1;
+ return 0;
+}
+
/*
* Ensure that all streams which were opened for HUNK are closed.
*/
@@ -496,6 +512,16 @@
svn_pool_destroy(iterpool);
SVN_ERR(svn_stream_close(stream));
+ if (*patch)
+ {
+ /* Usually, hunks appear in the patch sorted by their original line
+ * offset. But just in case they weren't parsed in this order for
+ * some reason, we sort them so that our caller can assume that hunks
+ * are sorted as if parsed from a usual patch. */
+ qsort((*patch)->hunks->elts, (*patch)->hunks->nelts,
+ (*patch)->hunks->elt_size, compare_hunks);
+ }
+
return SVN_NO_ERROR;
}