Skip to content

Commit

Permalink
recode: define _singleDiffInfoToHDiffInfo() & _printDirDiffInfos()
Browse files Browse the repository at this point in the history
  • Loading branch information
housisong committed Nov 29, 2023
1 parent 78007e2 commit b8ffde5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
5 changes: 1 addition & 4 deletions dirDiffPatch/dir_patch/dir_patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,7 @@ static hpatch_BOOL _read_dirdiff_head(TDirDiffInfo* out_info,_TDirDiffHead* out_
memcpy(out_info->sdiffInfo.compressType,savedCompressType,savedCompressTypeLen+1); //with '\0'
else
check(0==strcmp(savedCompressType,out_info->sdiffInfo.compressType));
out_info->hdiffInfo.newDataSize=out_info->sdiffInfo.newDataSize;
out_info->hdiffInfo.oldDataSize=out_info->sdiffInfo.oldDataSize;
out_info->hdiffInfo.compressedCount=(out_info->sdiffInfo.compressedSize>0)?1:0;
memcpy(out_info->hdiffInfo.compressType,out_info->sdiffInfo.compressType,strlen(out_info->sdiffInfo.compressType)+1);
_singleDiffInfoToHDiffInfo(&out_info->hdiffInfo,&out_info->sdiffInfo);
}else
#endif
check(getCompressedDiffInfo(&out_info->hdiffInfo,&hdiffStream.base));
Expand Down
5 changes: 1 addition & 4 deletions hdiffz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1738,10 +1738,7 @@ int hdiff_resave(const char* diffFileName,const char* outDiffFileName,
#endif
if (getSingleCompressedDiffInfo(&singleDiffInfo,&diffData_in.base,0)){
isSingleDiff=hpatch_TRUE;
diffInfo.newDataSize=singleDiffInfo.newDataSize;
diffInfo.oldDataSize=singleDiffInfo.oldDataSize;
diffInfo.compressedCount=(singleDiffInfo.compressedSize>0)?1:0;
memcpy(diffInfo.compressType,singleDiffInfo.compressType,strlen(singleDiffInfo.compressType)+1);
_singleDiffInfoToHDiffInfo(&diffInfo,&singleDiffInfo);
printf(" resave as single stream diffFile \n");
}else if(getCompressedDiffInfo(&diffInfo,&diffData_in.base)){
//ok
Expand Down
42 changes: 24 additions & 18 deletions hpatchz.c
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,25 @@ static hpatch_BOOL findChecksum(hpatch_TChecksum** out_checksumPlugin,const char

#if (_IS_NEED_DIR_DIFF_PATCH)
#include "dirDiffPatch/dir_patch/dir_patch_private.h"

static _printDirDiffInfos(const TDirDiffInfo* dirDiffInfo,const _TDirDiffHead* head){
if (!dirDiffInfo->isDirDiff) return;
printf(" is dirDiffInfo: true\n");
printf(" checksumType: \"%s\"\n",dirDiffInfo->checksumType);
printf(" oldPathIsDir: %s\n",dirDiffInfo->oldPathIsDir?"true":"false");
printf(" newPathIsDir: %s\n",dirDiffInfo->newPathIsDir?"true":"false");
printf(" new path count: %" PRIu64 " (fileCount:%" PRIu64 ")\n",(hpatch_StreamPos_t)head->newPathCount,
(hpatch_StreamPos_t)(head->sameFilePairCount+head->newRefFileCount));
printf(" copy from old count: %" PRIu64 " (dataSize: %" PRIu64 ")\n",
(hpatch_StreamPos_t)head->sameFilePairCount,head->sameFileSize);
printf(" ref old file count: %" PRIu64 "\n",(hpatch_StreamPos_t)head->oldRefFileCount);
printf(" ref new file count: %" PRIu64 "\n",(hpatch_StreamPos_t)head->newRefFileCount);
printf(" oldRefSize : %" PRIu64 "\n",dirDiffInfo->hdiffInfo.oldDataSize);
printf(" newRefSize : %" PRIu64 " (all newSize: %" PRIu64 ")\n",
dirDiffInfo->hdiffInfo.newDataSize,dirDiffInfo->hdiffInfo.newDataSize+head->sameFileSize);
printf("\n");
}

#endif
static int _printFileInfos(const char* fileName){
int result=HPATCH_SUCCESS;
Expand Down Expand Up @@ -1066,14 +1085,11 @@ int hpatch(const char* oldFileName,const char* diffFileName,const char* outNewFi
check(!diffData.fileError,HPATCH_FILEREAD_ERROR,"read diffFile");
#if (_IS_NEED_SINGLE_STREAM_DIFF)
if (getSingleCompressedDiffInfo(&sdiffInfo,&diffData.base,0)){
memcpy(diffInfo.compressType,sdiffInfo.compressType,strlen(sdiffInfo.compressType)+1);
diffInfo.compressedCount=(sdiffInfo.compressType[0]!='\0')?1:0;
diffInfo.newDataSize=sdiffInfo.newDataSize;
diffInfo.oldDataSize=sdiffInfo.oldDataSize;
isSingleCompressedDiff=hpatch_TRUE;
_singleDiffInfoToHDiffInfo(&diffInfo,&sdiffInfo);
check(sdiffInfo.stepMemSize==(size_t)sdiffInfo.stepMemSize,HPATCH_MEM_ERROR,"stepMemSize too large");
if (patchCacheSize<hpatch_kStreamCacheSize*3)
patchCacheSize=hpatch_kStreamCacheSize*3;
isSingleCompressedDiff=hpatch_TRUE;
printf("patch single compressed diffData!\n");
}else
#endif
Expand Down Expand Up @@ -1283,7 +1299,7 @@ int hpatch_dir(const char* oldPath,const char* diffFileName,const char* outNewPa
if (wantChecksumCount>0){
if (strlen(dirDiffInfo->checksumType)==0){
memset(checksumSet,0,sizeof(*checksumSet));
printf(" NOTE: no checksum saved in diffFile,can not do checksum\n");
printf(" WARNING: no checksum saved in diffFile,can not do checksum\n");
}else{
if (!findChecksum(&checksumSet->checksumPlugin,dirDiffInfo->checksumType)){
LOG_ERR("not found checksumType \"%s\" ERROR!\n",dirDiffInfo->checksumType);
Expand All @@ -1299,18 +1315,8 @@ int hpatch_dir(const char* oldPath,const char* diffFileName,const char* outNewPa
}
}
}
{//info
const _TDirDiffHead* head=&dirPatcher.dirDiffHead;
printf("DirPatch new path count: %" PRIu64 " (fileCount:%" PRIu64 ")\n",(hpatch_StreamPos_t)head->newPathCount,
(hpatch_StreamPos_t)(head->sameFilePairCount+head->newRefFileCount));
printf(" copy from old count: %" PRIu64 " (dataSize: %" PRIu64 ")\n",
(hpatch_StreamPos_t)head->sameFilePairCount,head->sameFileSize);
printf(" ref old file count: %" PRIu64 "\n",(hpatch_StreamPos_t)head->oldRefFileCount);
printf(" ref new file count: %" PRIu64 "\n",(hpatch_StreamPos_t)head->newRefFileCount);
printf("oldRefSize : %" PRIu64 "\ndiffDataSize: %" PRIu64 "\nnewRefSize : %" PRIu64 " (all newSize: %" PRIu64 ")\n",
dirDiffInfo->hdiffInfo.oldDataSize,diffData.base.streamSize,dirDiffInfo->hdiffInfo.newDataSize,
dirDiffInfo->hdiffInfo.newDataSize+head->sameFileSize);
}
_printDirDiffInfos(dirDiffInfo,&dirPatcher.dirDiffHead);

{//mem cache
size_t mustAppendMemSize=0;
#if (_IS_NEED_SINGLE_STREAM_DIFF)
Expand Down
7 changes: 7 additions & 0 deletions libHDiffPatch/HPatch/patch_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ typedef hpatch_BOOL hpatch_FileError_t;// 0: no error; other: error;
hpatch_StreamPos_t stepMemSize;
char compressType[hpatch_kMaxPluginTypeLength+1]; //ascii cstring
} hpatch_singleCompressedDiffInfo;

hpatch_inline static void _singleDiffInfoToHDiffInfo(hpatch_compressedDiffInfo* out_diffInfo,const hpatch_singleCompressedDiffInfo* singleDiffInfo){
out_diffInfo->newDataSize=singleDiffInfo->newDataSize;
out_diffInfo->oldDataSize=singleDiffInfo->oldDataSize;
out_diffInfo->compressedCount=(singleDiffInfo->compressedSize>0)?1:0;
memcpy(out_diffInfo->compressType,singleDiffInfo->compressType,strlen(singleDiffInfo->compressType)+1);
}

typedef struct sspatch_listener_t{
void* import;
Expand Down

0 comments on commit b8ffde5

Please sign in to comment.