int ret = create_patch(info.old_file, info.new_file, TEMP_PATCH_NAME, 8);
#ifdef TIME_LIMIT_CHECK
- if (ret != 0) {
- printf("Trying with offset score 2\n");
- ret = create_patch(info.old_file, info.new_file, TEMP_PATCH_NAME, 2);
- }
- if (ret != 0) {
- printf("Trying with offset score 0\n");
- ret = create_patch(info.old_file, info.new_file, TEMP_PATCH_NAME, 0);
+ /*
+ * Creating a patch with an offset score equal to 8 may take too long. On
+ * the other hand for a value of 2 the resulting patch will consist of
+ * multiple blocks, which can significantly increase the application time.
+ * Therefore this commit adds two intermediate steps as a compromise
+ * solution.
+ */
+ for (int score = 6; score >= 0 && ret != 0; score-=2) {
+ printf("Trying with offset score %d\n", score);
+ ret = create_patch(info.old_file, info.new_file, TEMP_PATCH_NAME, score);
}
if (ret != 0)
err(1, "bsdiff fails to create delta within timelimit");