Author: ivan
Date: Sun Jun 7 18:11:00 2015
New Revision: 1684054
URL: http://svn.apache.org/r1684054
Log:
Refactor svndiff encoding code.
* subversion/libsvn_delta/svndiff.c
(SVNDIFF_V0, SVNDIFF_V1, SVNDIFF_HEADER_SIZE): Move to top of the
file.
(get_svndiff_header): New helper, returns SVNDIFF_V0 or SVNDIFF_V1
depending of svndiff version requested.
(send_simple_insertion_window, window_handler): Use
get_svndiff_header() helper and use SVNDIFF_HEADER_SIZE constant.
Modified:
subversion/trunk/subversion/libsvn_delta/svndiff.c
Modified: subversion/trunk/subversion/libsvn_delta/svndiff.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_delta/svndiff.c?rev=1684054&r1=1684053&r2=1684054&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_delta/svndiff.c (original)
+++ subversion/trunk/subversion/libsvn_delta/svndiff.c Sun Jun 7 18:11:00 2015
@@ -36,6 +36,20 @@
#include "private/svn_string_private.h"
#include "private/svn_dep_compat.h"
+static const char SVNDIFF_V0[] = { 'S', 'V', 'N', 0 };
+static const char SVNDIFF_V1[] = { 'S', 'V', 'N', 1 };
+
+#define SVNDIFF_HEADER_SIZE (sizeof(SVNDIFF_V0))
+
+static const char *
+get_svndiff_header(int version)
+{
+ if (version == 1)
+ return SVNDIFF_V1;
+ else
+ return SVNDIFF_V0;
+}
+
/* ----- Text delta to svndiff ----- */
/* We make one of these and get it passed back to us in calls to the
@@ -72,7 +86,7 @@ static svn_error_t *
send_simple_insertion_window(svn_txdelta_window_t *window,
struct encoder_baton *eb)
{
- unsigned char headers[4 + 5 * SVN__MAX_ENCODED_UINT_LEN
+ unsigned char headers[SVNDIFF_HEADER_SIZE + 5 * SVN__MAX_ENCODED_UINT_LEN
+ MAX_INSTRUCTION_LEN];
unsigned char ibuf[MAX_INSTRUCTION_LEN];
unsigned char *header_current;
@@ -89,11 +103,8 @@ send_simple_insertion_window(svn_txdelta
if (!eb->header_done)
{
eb->header_done = TRUE;
- headers[0] = 'S';
- headers[1] = 'V';
- headers[2] = 'N';
- headers[3] = (unsigned char)eb->version;
- header_current = headers + 4;
+ memcpy(headers, get_svndiff_header(eb->version), SVNDIFF_HEADER_SIZE);
+ header_current = headers + SVNDIFF_HEADER_SIZE;
}
else
{
@@ -155,10 +166,9 @@ window_handler(svn_txdelta_window_t *win
/* Make sure we write the header. */
if (!eb->header_done)
{
- char svnver[4] = {'S','V','N','\0'};
- len = 4;
- svnver[3] = (char)eb->version;
- SVN_ERR(svn_stream_write(eb->output, svnver, &len));
+ len = SVNDIFF_HEADER_SIZE;
+ SVN_ERR(svn_stream_write(eb->output, get_svndiff_header(eb->version),
+ &len));
eb->header_done = TRUE;
}
@@ -555,10 +565,6 @@ decode_window(svn_txdelta_window_t *wind
return SVN_NO_ERROR;
}
-static const char SVNDIFF_V0[] = { 'S', 'V', 'N', 0 };
-static const char SVNDIFF_V1[] = { 'S', 'V', 'N', 1 };
-#define SVNDIFF_HEADER_SIZE (sizeof(SVNDIFF_V0))
-
static svn_error_t *
write_handler(void *baton,
const char *buffer,