fix(diff): myers now also strdups the line of the file on insert action when taking the diff

This commit is contained in:
lisk77 2025-09-07 04:22:30 +02:00
parent 252bdc281e
commit 1e3934cf20

View file

@ -78,12 +78,14 @@ ActionList* myers_diff(File* old_version, File* new_version, uint64_t old_offset
temp_actions[temp_count].type = INSERT;
temp_actions[temp_count].line_original = old_offset + i;
temp_actions[temp_count].line_changed = new_offset + j - 1;
temp_actions[temp_count].content = strdup(new_version->content[j - 1]); // Copy the content for INSERT action
temp_count++;
j--;
} else if (i > 0) {
temp_actions[temp_count].type = DELETE;
temp_actions[temp_count].line_original = old_offset + i - 1;
temp_actions[temp_count].line_changed = 0;
temp_actions[temp_count].content = NULL; // No content for DELETE action
temp_count++;
i--;
}
@ -99,4 +101,4 @@ ActionList* myers_diff(File* old_version, File* new_version, uint64_t old_offset
free(lcs_table);
return result;
}
}