Dear MS./MS
I have a quesion in writing code with SVN API.
I have produce some delta files with SVN API(saved in svndiff format). But How Can I compose them together faster?
I know using "svn_txdelta_compose_windows" to compose ,But the Speed Is Slow. Especially when the revisions is many.
How Can I Make the speed faster?
thanks for your replay!
your sincerely
aseimic
Here are some codes.
static void
ComposeFile(svn_stream_t* ver1, svn_stream_t* ver2, svn_stream_t* target, apr_pool_t *pool)
{
svn_txdelta_window_handler_t handler;
void *handler_baton;
apr_pool_t *wpool = svn_pool_create(pool);
svn_txdelta_apply(ver1,
target,
NULL, NULL, wpool, &handler, &handler_baton);
svn_txdelta_window_t *window_A;
svn_txdelta_window_t *window_B;
svn_txdelta_window_t *composite;
char svnver1[4];
char svnver2[4];
apr_size_t len = 4;
svn_stream_read(ver1, svnver1, &len);
svn_stream_read(ver2, svnver2, &len);
do
{
window_A = NULL;
window_B = NULL;
svn_txdelta_read_svndiff_window(&window_A, ver1, 1, wpool);
svn_txdelta_read_svndiff_window(&window_B, ver2, 1, wpool);
if (!window_B)
break;
ASSERT(window_A != NULL || window_B->src_ops == 0);
if (window_B->src_ops == 0)
{
composite = window_B;
composite->sview_len = 0;
}
else
composite = svn_txdelta_compose_windows(window_A, window_B,
wpool);
if (composite && composite->sview_len == 0 && composite->src_ops > 0)
return;
handler(composite, handler_baton);
}
while (composite != NULL);
svn_pool_destroy(wpool);
}
BOOL CDDELTA_EXPORT ComposeDelta(CStringArray& verPaths, CString& preVerPath, CString& filePath)
{
if (verPaths.GetSize() == 0)
return FALSE;
if (preVerPath.IsEmpty())
return ComposeDelta(verPaths, filePath);
CArray<LPSTR, LPSTR> deltaPaths;
int nSize = verPaths.GetSize();
deltaPaths.SetSize(nSize);
LPSTR szTemp;
int i = 0;
for (i=0; i<nSize; i++)
{
szTemp = Ascii2UTF8Converter(verPaths[i], 936, CP_UTF8);
deltaPaths.SetAt(i, szTemp);
}
LPSTR szPreVerPath = Ascii2UTF8Converter(preVerPath, 936, CP_UTF8);
LPSTR szFilePath = Ascii2UTF8Converter(filePath, 936, CP_UTF8);
svn_error_t *err = NULL;
apr_pool_t *fpool = svn_pool_create(NULL);
apr_file_t *ver1File = NULL;
apr_file_t *ver2File = NULL;
apr_file_t *targetFile = NULL;
svn_stream_t * stream2 = NULL;
svn_stream_t * stream3 = NULL;
svn_stream_t * stream4 = NULL;
int nCount = deltaPaths.GetSize() - 1;
ver1File = OpenBinaryRead(szPreVerPath, fpool);
if (ver1File == NULL)
return FALSE;
stream3 = svn_stream_from_aprfile(ver1File, fpool);
targetFile = OpenBinaryWrite(szFilePath, fpool);
if (targetFile == NULL)
{
apr_file_close(ver1File);
return FALSE;
}
svn_txdelta_window_handler_t handler;
void *handler_baton;
svn_stringbuf_t * sBuf = svn_stringbuf_ncreate("t", 1, fpool);
svn_stringbuf_t * sBuf1 = svn_stringbuf_ncreate("t", 1, fpool);
for (i=0; i<=nCount; ++i)
{
/*if(i==0)
{
svn_stringbuf_setempty(sBuf1);
stream4 = svn_stream_from_stringbuf(sBuf1, fpool);
svn_txdelta_to_svndiff2(&handler, &handler_baton, stream4, 1,
fpool);
svn_txdelta_send_stream(stream3, handler, handler_baton, NULL, fpool);
}
else
{*/
svn_stringbuf_setempty(sBuf1);
stream4 = svn_stream_from_stringbuf(sBuf1, fpool);
svn_stream_copy(stream3,stream4,fpool);
//}
ver2File = OpenBinaryRead(deltaPaths[i], fpool);
if (ver2File == NULL)
{
break;
}
stream2 = svn_stream_from_aprfile(ver2File, fpool);
svn_stringbuf_setempty(sBuf);
if (i != nCount)
stream3 = svn_stream_from_stringbuf(sBuf, fpool);
else
stream3 = svn_stream_from_aprfile(targetFile, fpool);
ComposeFile(stream4, stream2, stream3, fpool);
apr_file_close(ver2File);
}
apr_file_close(ver1File);
apr_file_close(targetFile);
delete []szFilePath;
delete []szPreVerPath;
for (i=0; i<nSize; i++)
{
delete []deltaPaths[i];
}
svn_pool_destroy(fpool);
return TRUE;
}
Received on 2010-01-19 15:39:35 CET