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/03/18 14:17:24 UTC
svn commit: r924760 - in /subversion/trunk/subversion:
include/private/svn_diff_private.h include/svn_diff.h libsvn_client/patch.c
libsvn_diff/parse-diff.c tests/libsvn_diff/parse-diff-test.c
Author: stsp
Date: Thu Mar 18 13:17:23 2010
New Revision: 924760
URL: http://svn.apache.org/viewvc?rev=924760&view=rev
Log:
Make the diff parsing API public so third party clients can use it.
See this message for details:
From: Stefan Küng
To: Stefan Sperling
CC: Julian Foad, dev@subversion.apache.org
Subject: Re: svn commit: r919460 - filtering svn patch targets
Message-ID: <4B...@gmail.com>
http://svn.haxx.se/dev/archive-2010-03/0253.shtml
* subversion/include/private/svn_diff_private.h: Remove.
* subversion/include/svn_diff.h
(svn_hunk_t, svn_patch_t, svn_diff_parse_next_patch,
svn_diff_close_patch): Move declarations from above removed header
file to this one. Declare as public API.
* subversion/libsvn_client/patch.c
(): Include svn_diff.h instead of private/svn_diff_private.h
(apply_patches): Track function renames.
* subversion/libsvn_diff/parse-diff.c
(): Include svn_diff.h instead of private/svn_diff_private.h
(svn_diff__parse_next_patch, svn_diff__close_patch): Rename to ...
(svn_diff_parse_next_patch, svn_diff_close_patch): ... these.
* subversion/tests/libsvn_diff/parse-diff-test.c
(): Don't include private/svn_diff_private.h.
(test_parse_unidiff): Track function renames.
Removed:
subversion/trunk/subversion/include/private/svn_diff_private.h
Modified:
subversion/trunk/subversion/include/svn_diff.h
subversion/trunk/subversion/libsvn_client/patch.c
subversion/trunk/subversion/libsvn_diff/parse-diff.c
subversion/trunk/subversion/tests/libsvn_diff/parse-diff-test.c
Modified: subversion/trunk/subversion/include/svn_diff.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_diff.h?rev=924760&r1=924759&r2=924760&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_diff.h (original)
+++ subversion/trunk/subversion/include/svn_diff.h Thu Mar 18 13:17:23 2010
@@ -765,6 +765,110 @@ svn_diff_mem_string_output_merge(svn_str
apr_pool_t *pool);
+
+
+/* Diff parsing. If you want to apply a patch to a working copy
+ * rather than parse it, see svn_client_patch(). */
+
+/* A single hunk inside a patch
+ *
+ * @since New in 1.7. */
+typedef struct svn_hunk_t {
+ /* The hunk's unidiff text as it appeared in the patch file,
+ * without range information. */
+ svn_stream_t *diff_text;
+
+ /* The original and modified texts in the hunk range.
+ * Derived from the diff text.
+ *
+ * For example, consider a hunk such as:
+ * @@ -1,5 +1,5 @@
+ * #include <stdio.h>
+ * int main(int argc, char *argv[])
+ * {
+ * - printf("Hello World!\n");
+ * + printf("I like Subversion!\n");
+ * }
+ *
+ * Then, the original text described by the hunk is:
+ * #include <stdio.h>
+ * int main(int argc, char *argv[])
+ * {
+ * printf("Hello World!\n");
+ * }
+ *
+ * And the modified text described by the hunk is:
+ * #include <stdio.h>
+ * int main(int argc, char *argv[])
+ * {
+ * printf("I like Subversion!\n");
+ * }
+ *
+ * Because these streams make use of line filtering and transformation,
+ * they should only be read line-by-line with svn_stream_readline().
+ * Reading them with svn_stream_read() will not yield the expected result,
+ * because it will return the unidiff text from the patch file unmodified.
+ * The streams support resetting.
+ */
+ svn_stream_t *original_text;
+ svn_stream_t *modified_text;
+
+ /* Hunk ranges as they appeared in the patch file.
+ * All numbers are lines, not bytes. */
+ svn_linenum_t original_start;
+ svn_linenum_t original_length;
+ svn_linenum_t modified_start;
+ svn_linenum_t modified_length;
+
+ /* Number of lines starting with ' ' before first '+' or '-'. */
+ svn_linenum_t leading_context;
+
+ /* Number of lines starting with ' ' after last '+' or '-'. */
+ svn_linenum_t trailing_context;
+} svn_hunk_t;
+
+/* Data type to manage parsing of patches.
+ *
+ * @since New in 1.7. */
+typedef struct svn_patch_t {
+ /* Path to the patch file. */
+ const char *path;
+
+ /* The patch file itself. */
+ apr_file_t *patch_file;
+
+ /* The old and new file names as retrieved from the patch file.
+ * These paths are UTF-8 encoded and canonicalized, but otherwise
+ * left unchanged from how they appeared in the patch file. */
+ const char *old_filename;
+ const char *new_filename;
+
+ /* An array containing an svn_hunk_t object for each hunk parsed
+ * from the patch. */
+ apr_array_header_t *hunks;
+} svn_patch_t;
+
+/* Return the next @a *patch in @a patch_file.
+ * If no patch can be found, set @a *patch to NULL.
+ * If @a reverse is TRUE, invert the patch while parsing it.
+ * Allocate results in @a result_pool.
+ * Use @a scratch_pool for all other allocations.
+ *
+ * @since New in 1.7. */
+svn_error_t *
+svn_diff_parse_next_patch(svn_patch_t **patch,
+ apr_file_t *patch_file,
+ svn_boolean_t reverse,
+ apr_pool_t *result_pool,
+ apr_pool_t *scratch_pool);
+
+/* Dispose of @a patch, closing any streams used by it.
+ *
+ * @since New in 1.7.
+ */
+svn_error_t *
+svn_diff_close_patch(const svn_patch_t *patch);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
Modified: subversion/trunk/subversion/libsvn_client/patch.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/patch.c?rev=924760&r1=924759&r2=924760&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/patch.c (original)
+++ subversion/trunk/subversion/libsvn_client/patch.c Thu Mar 18 13:17:23 2010
@@ -31,6 +31,7 @@
#include <apr_fnmatch.h>
#include "svn_client.h"
#include "svn_dirent_uri.h"
+#include "svn_diff.h"
#include "svn_io.h"
#include "svn_path.h"
#include "svn_pools.h"
@@ -40,7 +41,6 @@
#include "client.h"
#include "svn_private_config.h"
-#include "private/svn_diff_private.h"
#include "private/svn_eol_private.h"
#include "private/svn_wc_private.h"
@@ -1457,8 +1457,8 @@ apply_patches(void *baton,
if (btn->ctx->cancel_func)
SVN_ERR(btn->ctx->cancel_func(btn->ctx->cancel_baton));
- SVN_ERR(svn_diff__parse_next_patch(&patch, patch_file,
- btn->reverse, scratch_pool, iterpool));
+ SVN_ERR(svn_diff_parse_next_patch(&patch, patch_file,
+ btn->reverse, scratch_pool, iterpool));
if (patch)
{
patch_target_t *target;
@@ -1468,7 +1468,7 @@ apply_patches(void *baton,
btn->include_patterns, btn->exclude_patterns,
scratch_pool, iterpool));
if (target->filtered)
- SVN_ERR(svn_diff__close_patch(patch));
+ SVN_ERR(svn_diff_close_patch(patch));
else
APR_ARRAY_PUSH(targets, patch_target_t *) = target;
}
@@ -1490,7 +1490,7 @@ apply_patches(void *baton,
SVN_ERR(install_patched_target(target, btn->abs_wc_path,
btn->ctx, btn->dry_run, iterpool));
SVN_ERR(send_patch_notification(target, btn->ctx, iterpool));
- SVN_ERR(svn_diff__close_patch(target->patch));
+ SVN_ERR(svn_diff_close_patch(target->patch));
}
SVN_ERR(svn_io_file_close(patch_file, iterpool));
Modified: subversion/trunk/subversion/libsvn_diff/parse-diff.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_diff/parse-diff.c?rev=924760&r1=924759&r2=924760&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_diff/parse-diff.c (original)
+++ subversion/trunk/subversion/libsvn_diff/parse-diff.c Thu Mar 18 13:17:23 2010
@@ -31,9 +31,7 @@
#include "svn_pools.h"
#include "svn_utf.h"
#include "svn_dirent_uri.h"
-
-#include "private/svn_diff_private.h"
-
+#include "svn_diff.h"
/* Helper macro for readability */
#define starts_with(str, start) \
@@ -411,7 +409,7 @@ parse_next_hunk(svn_hunk_t **hunk,
if (! eof)
/* Rewind to the start of the line just read, so subsequent calls
- * to this function or svn_diff__parse_next_patch() don't end
+ * to this function or svn_diff_parse_next_patch() don't end
* up skipping the line -- it may contain a patch or hunk header. */
SVN_ERR(svn_io_file_seek(patch->patch_file, APR_SET, &last_line,
scratch_pool));
@@ -499,11 +497,11 @@ close_hunk(const svn_hunk_t *hunk)
}
svn_error_t *
-svn_diff__parse_next_patch(svn_patch_t **patch,
- apr_file_t *patch_file,
- svn_boolean_t reverse,
- apr_pool_t *result_pool,
- apr_pool_t *scratch_pool)
+svn_diff_parse_next_patch(svn_patch_t **patch,
+ apr_file_t *patch_file,
+ svn_boolean_t reverse,
+ apr_pool_t *result_pool,
+ apr_pool_t *scratch_pool)
{
static const char * const minus = "--- ";
static const char * const plus = "+++ ";
@@ -633,7 +631,7 @@ svn_diff__parse_next_patch(svn_patch_t *
}
svn_error_t *
-svn_diff__close_patch(const svn_patch_t *patch)
+svn_diff_close_patch(const svn_patch_t *patch)
{
int i;
Modified: subversion/trunk/subversion/tests/libsvn_diff/parse-diff-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_diff/parse-diff-test.c?rev=924760&r1=924759&r2=924760&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_diff/parse-diff-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_diff/parse-diff-test.c Thu Mar 18 13:17:23 2010
@@ -25,7 +25,6 @@
#include "../svn_test.h"
#include "svn_diff.h"
-#include "private/svn_diff_private.h"
#include "svn_pools.h"
#include "svn_utf.h"
@@ -101,8 +100,8 @@ test_parse_unidiff(apr_pool_t *pool)
/* We have two patches with one hunk each.
* Parse the first patch. */
- SVN_ERR(svn_diff__parse_next_patch(&patch, patch_file, reverse,
- iterpool, iterpool));
+ SVN_ERR(svn_diff_parse_next_patch(&patch, patch_file, reverse,
+ iterpool, iterpool));
SVN_ERR_ASSERT(patch);
SVN_ERR_ASSERT(! strcmp(patch->old_filename, "A/C/gamma"));
SVN_ERR_ASSERT(! strcmp(patch->new_filename, "A/C/gamma"));
@@ -144,7 +143,7 @@ test_parse_unidiff(apr_pool_t *pool)
SVN_ERR_ASSERT(buf->len == 0);
/* Parse the second patch. */
- SVN_ERR(svn_diff__parse_next_patch(&patch, patch_file, reverse, pool, pool));
+ SVN_ERR(svn_diff_parse_next_patch(&patch, patch_file, reverse, pool, pool));
SVN_ERR_ASSERT(patch);
if (reverse)
{