commit 346d4986568ffbcfdc53cce45dd8a468535a68f2 from: Stefan Sperling date: Wed Oct 06 13:15:54 2021 UTC fix ed script diff output when lines are inserted at the top of a file commit - 9879b82a581a245e365fb159488c4294c318d8b3 commit + 346d4986568ffbcfdc53cce45dd8a468535a68f2 blob - 1c9b6d17294abf78edffde84b7937856f2620bb1 blob + 42d4d5b39ef5a587321d90c1b95ef4f616e882b3 --- lib/diff_output_edscript.c +++ lib/diff_output_edscript.c @@ -45,8 +45,10 @@ output_edscript_chunk(struct diff_output_info *outinfo left_start = 0; else if (left_len == 0 && cc->left.start > 0) left_start = cc->left.start; - else + else if (cc->left.end > 0) left_start = cc->left.start + 1; + else + left_start = cc->left.start; right_len = cc->right.end - cc->right.start; if (right_len < 0) @@ -55,8 +57,10 @@ output_edscript_chunk(struct diff_output_info *outinfo right_start = 0; else if (right_len == 0 && cc->right.start > 0) right_start = cc->right.start; - else + else if (cc->right.end > 0) right_start = cc->right.start + 1; + else + right_start = cc->right.start; if (left_len == 0) { /* addition */ blob - /dev/null blob + 77d05518ee95a1b8a5a547e7f5748832184a11a9 (mode 644) --- /dev/null +++ test/expect123.diff @@ -0,0 +1 @@ +0a1 blob - f63919e8521b511175d8086433d2fcee4164f4ad blob + d8d3aa95464f45b8a21779276ef6a7de72e4c09f --- test/verify_all.sh +++ test/verify_all.sh @@ -26,6 +26,13 @@ verify_diff_script() { else ignore_whitespace="" fi + + if echo -- $diff_opts | grep -q -- 'e'; then + is_edscript="true" + else + is_edscript="" + fi + verify_left="verify.$orig_left" verify_right="verify.$orig_right" @@ -36,7 +43,7 @@ verify_diff_script() { return 1 fi fi - if [ -z "$ignore_whitespace" -a "x$diff_type" = "xunidiff" ]; then + if [ -z "$ignore_whitespace" -a -z "$is_edscript" -a "x$diff_type" = "xunidiff" ]; then cp "$orig_left" "$verify_right" $patch_prog --quiet -u "$verify_right" "$the_diff" if ! cmp "$orig_right" "$verify_right" ; then @@ -50,7 +57,7 @@ verify_diff_script() { echo "FAIL: $orig_left != $verify_left" | tee -a errors return 1 fi - elif [ -z "$ignore_whitespace" ]; then + elif [ -z "$ignore_whitespace" -a -z "$is_edscript" ]; then tail -n +3 "$the_diff" | grep -v "^+" | sed 's/^.//' > "$verify_left" tail -n +3 "$the_diff" | grep -v "^-" | sed 's/^.//' > "$verify_right" blob - /dev/null blob + 4a58007052a65fbc2fc3f910f2855f45a4058e74 (mode 644) --- /dev/null +++ test/test123.left-e.txt @@ -0,0 +1 @@ +alpha blob - /dev/null blob + 177941793e94106ed9b6d2bb98b3edb506f6e987 (mode 644) --- /dev/null +++ test/test123.right-e.txt @@ -0,0 +1,2 @@ +first line +alpha