From 1e3934cf206b7360ee1a2bcb346ca189465e6176 Mon Sep 17 00:00:00 2001 From: lisk77 Date: Sun, 7 Sep 2025 04:22:30 +0200 Subject: [PATCH] fix(diff): myers now also strdups the line of the file on insert action when taking the diff --- src/myers.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/myers.c b/src/myers.c index 7ba3a3d..e6f4068 100644 --- a/src/myers.c +++ b/src/myers.c @@ -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; -} +} \ No newline at end of file